Browse Source

输送设备连接设置页面

master
sc 7 months ago
parent
commit
ea95535612
  1. 5
      View/DispenseMachinesSet.xaml
  2. 94
      View/DispenseMachinesSet.xaml.cs

5
View/DispenseMachinesSet.xaml

@ -62,15 +62,14 @@
<DataGridTextColumn Header="{x:Static lang:Resources.Group}" Binding="{Binding Groups}" Width="210" IsReadOnly="True"/> <DataGridTextColumn Header="{x:Static lang:Resources.Group}" Binding="{Binding Groups}" Width="210" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding IP}" Width="0" IsReadOnly="True"/> <DataGridTextColumn Binding="{Binding IP}" Width="0" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding PORT}" Width="0" IsReadOnly="True"/> <DataGridTextColumn Binding="{Binding PORT}" Width="0" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Serial}" Width="0" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Baud}" Width="0" IsReadOnly="True"/>
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>
<Image HorizontalAlignment="Left" x:Name="IMAGE" VerticalAlignment="Top" Width="400" Height="400" Margin="10,200,0,0" /> <Image HorizontalAlignment="Left" x:Name="IMAGE" VerticalAlignment="Top" Width="400" Height="400" Margin="10,200,0,0" />
<TextBox HorizontalAlignment="Left" Height="30" Margin="150,10,0,0" x:Name="comboBoxMachine" VerticalAlignment="Top" Width="270" FontSize="20" /> <TextBox HorizontalAlignment="Left" Height="30" Margin="150,10,0,0" x:Name="comboBoxMachine" VerticalAlignment="Top" Width="270" FontSize="20" />
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,10,0,0" TextWrapping="Wrap" Text="{x:Static lang:Resources.Machine}" VerticalAlignment="Top" Width="120" FontSize="25"/> <TextBlock HorizontalAlignment="Left" Height="40" Margin="10,10,0,0" TextWrapping="Wrap" Text="{x:Static lang:Resources.Machine}" VerticalAlignment="Top" Width="120" FontSize="25"/>
<ComboBox HorizontalAlignment="Left" Height="30" Margin="150,50,0,0" x:Name="TextMachineGroup" VerticalAlignment="Top" Width="270" FontSize="20" DropDownClosed="TextMachineGroup_DropDownClosed"/> <ComboBox HorizontalAlignment="Left" Height="30" Margin="150,50,0,0" x:Name="TextMachineGroup" VerticalAlignment="Top" Width="270" FontSize="20"
DropDownClosed="TextMachineGroup_DropDownClosed" TextBoxBase.TextChanged="TextMachineGroup_DropDownClosed"/>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,50,0,0" TextWrapping="Wrap" Text="{x:Static lang:Resources.MachineGroup}" VerticalAlignment="Top" Width="120" FontSize="25"/> <TextBlock HorizontalAlignment="Left" Height="40" Margin="10,50,0,0" TextWrapping="Wrap" Text="{x:Static lang:Resources.MachineGroup}" VerticalAlignment="Top" Width="120" FontSize="25"/>
<TextBox HorizontalAlignment="Left" Height="30" Margin="150,100,0,0" x:Name="IP" VerticalAlignment="Top" Width="200" FontSize="20" MaxLines="1"/> <TextBox HorizontalAlignment="Left" Height="30" Margin="150,100,0,0" x:Name="IP" VerticalAlignment="Top" Width="200" FontSize="20" MaxLines="1"/>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="350,100,0,0" TextWrapping="Wrap" Text=":" VerticalAlignment="Top" Width="20" FontSize="25"/> <TextBlock HorizontalAlignment="Left" Height="40" Margin="350,100,0,0" TextWrapping="Wrap" Text=":" VerticalAlignment="Top" Width="20" FontSize="25"/>

94
View/DispenseMachinesSet.xaml.cs

@ -5,6 +5,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
@ -45,7 +46,10 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
//private string SYS_machines = null; //private string SYS_machines = null;
private void UserControl_Loaded(object sender, RoutedEventArgs e) private void UserControl_Loaded(object sender, RoutedEventArgs e)
{ {
Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView; SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
Griddata.ItemsSource = SQLiteHelpers.ExecuteDataSet("select Name,Groups,IP,PORT,DATA from MachinesDispense Order by id", null).Tables[0].DefaultView;
SQLiteHelpers.Close();
} }
private void Griddata_MouseDoubleClick(object sender, MouseButtonEventArgs e) private void Griddata_MouseDoubleClick(object sender, MouseButtonEventArgs e)
@ -63,35 +67,37 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
private void Save_Click(object sender, RoutedEventArgs e) private void Save_Click(object sender, RoutedEventArgs e)
{ {
if (!string.IsNullOrEmpty(comboBoxMachine.Text)) if (!string.IsNullOrEmpty(comboBoxMachine.Text) && !string.IsNullOrEmpty(TextMachineGroup.Text) && !string.IsNullOrEmpty(IP .Text))
{ {
WriteableBitmap wb = new WriteableBitmap((BitmapSource)IMAGE.Source);
byte[] imageData = SourceToArray(wb);
Dictionary<string, object> dr_new = new Dictionary<string, object>();//缓存函数 Dictionary<string, object> dr_new = new Dictionary<string, object>();//缓存函数
dr_new.Add("Name", comboBoxMachine.Text); dr_new.Add("Name", comboBoxMachine.Text);
dr_new.Add("Groups", TextMachineGroup.Text); dr_new.Add("Groups", TextMachineGroup.Text);
dr_new.Add("IP", IP.Text); dr_new.Add("IP", IP.Text);
dr_new.Add("PORT", PORT.Text); dr_new.Add("PORT", PORT.Text);
dr_new.Add("DATA",imageData);
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库 SQLiteHelpers.Open(); //打开数据库
if (SQLiteHelpers.ExecuteDataSet("select * from Machines where name ='" + comboBoxMachine.Text + "'", null).Tables[0].Rows.Count == 0) if (SQLiteHelpers.ExecuteDataSet("select * from MachinesDispense where name ='" + comboBoxMachine.Text + "'", null).Tables[0].Rows.Count == 0)
{ {
SQLiteHelpers.InsertData("Machines", dr_new); SQLiteHelpers.InsertData("MachinesDispense", dr_new);
} }
else else
{ {
SQLiteHelpers.Update("Machines", dr_new, "name='" + comboBoxMachine.Text + "'", null); SQLiteHelpers.Update("MachinesDispense", dr_new, "name='" + comboBoxMachine.Text + "'", null);
} }
MainWindowViewModel.Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines Order by id", null).Tables[0]; //读取表写入缓存 Griddata.ItemsSource = SQLiteHelpers.ExecuteDataSet("select Name,Groups,IP,PORT,DATA from MachinesDispense Order by id", null).Tables[0].DefaultView;
SQLiteHelpers.Close(); SQLiteHelpers.Close();
Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView; MessageBox.Show(Properties.Resources.Save + comboBoxMachine.Text, "SCCM", MessageBoxButton.OK, MessageBoxImage.Information);
comboBoxMachine.Text = null;
TextMachineGroup.Text = null;
IP.Text = null;
PORT.Text = "7789";
} }
else else
{ {
MessageBox.Show(Properties.Resources.ERR , "SCCM", MessageBoxButton.OK, MessageBoxImage.Error);
} }
} }
private void Delete_Click(object sender, RoutedEventArgs e) private void Delete_Click(object sender, RoutedEventArgs e)
@ -103,10 +109,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
{ {
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库 SQLiteHelpers.Open(); //打开数据库
SQLiteHelpers.Delete("Machines", "Name='" + comboBoxMachine.Text + "'", null); SQLiteHelpers.Delete("MachinesDispense", "Name='" + comboBoxMachine.Text + "'", null);
MainWindowViewModel.Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines Order by id", null).Tables[0]; //读取表写入缓存 Griddata.ItemsSource = SQLiteHelpers.ExecuteDataSet("select Name,Groups,IP,PORT,DATA from MachinesDispense Order by id", null).Tables[0].DefaultView;
SQLiteHelpers.Close(); SQLiteHelpers.Close();
Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView;
comboBoxMachine.Text = null; comboBoxMachine.Text = null;
} }
} }
@ -171,42 +176,42 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
switch (TextMachineGroup.Text)//步骤用时计算 switch (TextMachineGroup.Text)//步骤用时计算
{ {
case "252": case "252":
uri = new Uri("pack://application:,,,/ReferencedAssembly;component/LOGO/252-2t.png"); uri = new Uri("pack://application:,,,/LOGO/252-2t.png");
bitmapImage = new BitmapImage(uri); bitmapImage = new BitmapImage(uri);
IMAGE.Source = bitmapImage; IMAGE.Source = bitmapImage;
break; break;
case "252-2T": case "252-2T":
uri = new Uri("pack://application:,,,/ReferencedAssembly;component/SunlightCentralizedControlManagement(SCCM)/LOGO/252-2t.png"); uri = new Uri("pack://application:,,,/LOGO/252-2t.png");
bitmapImage = new BitmapImage(uri); bitmapImage = new BitmapImage(uri);
IMAGE.Source = bitmapImage; IMAGE.Source = bitmapImage;
break; break;
case "252RB": case "252RB":
uri = new Uri("pack://application:,,,/ReferencedAssembly;component/SunlightCentralizedControlManagement(SCCM)/LOGO/252RB.png"); uri = new Uri("pack://application:,,,/LOGO/252RB.png");
bitmapImage = new BitmapImage(uri); bitmapImage = new BitmapImage(uri);
IMAGE.Source = bitmapImage; IMAGE.Source = bitmapImage;
break; break;
case "252RDRM": case "252RDRM":
uri = new Uri("pack://application:,,,/ReferencedAssembly;component/SunlightCentralizedControlManagement(SCCM)/LOGO/252RDRM.png"); uri = new Uri("pack://application:,,,/LOGO/252RMRD.png");
bitmapImage = new BitmapImage(uri); bitmapImage = new BitmapImage(uri);
IMAGE.Source = bitmapImage; IMAGE.Source = bitmapImage;
break; break;
case "242W": case "242W":
uri = new Uri("pack://application:,,,/SunlightCentralizedControlManagement_SCCM_;component/242w.png"); uri = new Uri("pack://application:,,,/LOGO/242w.png");
bitmapImage = new BitmapImage(uri); bitmapImage = new BitmapImage(uri);
IMAGE.Source = bitmapImage; IMAGE.Source = bitmapImage;
break; break;
case "302": case "302":
uri = new Uri("pack://application:,,,/ReferencedAssembly;component/SunlightCentralizedControlManagement(SCCM)/LOGO/302.png"); uri = new Uri("pack://application:,,,/LOGO/302.png");
bitmapImage = new BitmapImage(uri); bitmapImage = new BitmapImage(uri);
IMAGE.Source = bitmapImage; IMAGE.Source = bitmapImage;
break; break;
case "303": case "303":
uri = new Uri("pack://application:,,,/ReferencedAssembly;component/SunlightCentralizedControlManagement(SCCM)/LOGO/303.png"); uri = new Uri("pack://application:,,,/LOGO/303.png");
bitmapImage = new BitmapImage(uri); bitmapImage = new BitmapImage(uri);
IMAGE.Source = bitmapImage; IMAGE.Source = bitmapImage;
break; break;
case "303PDW": case "303PDW":
uri = new Uri("pack://application:,,,/ReferencedAssembly;component/SunlightCentralizedControlManagement(SCCM)/LOGO/303pdw.png"); uri = new Uri("pack://application:,,,/LOGO/303pdw.png");
bitmapImage = new BitmapImage(uri); bitmapImage = new BitmapImage(uri);
IMAGE.Source = bitmapImage; IMAGE.Source = bitmapImage;
break; break;
@ -214,5 +219,50 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
break; break;
} }
} }
public static byte[] BitmapImageToByteArray(BitmapImage bmp)
{
byte[] byteArray = null;
try
{
Stream sMarket = bmp.StreamSource;
if (sMarket != null && sMarket.Length > 0)
{
//很重要,因为Position经常位于Stream的末尾,导致下面读取到的长度为0。
sMarket.Position = 0;
using (BinaryReader br = new BinaryReader(sMarket))
{
byteArray = br.ReadBytes((int)sMarket.Length);
}
}
}
catch
{
//other exception handling
}
return byteArray;
}
public static byte[] SourceToArray(WriteableBitmap source)
{
byte[] byteArray = null;
try
{
using (MemoryStream ms = new MemoryStream())
{
JpegBitmapEncoder coder = new JpegBitmapEncoder();
coder.QualityLevel = 100;
coder.Frames.Add(BitmapFrame.Create(source));
coder.Save(ms);
byteArray = ms.ToArray();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
return byteArray;
}
} }
} }

Loading…
Cancel
Save