|
|
@ -9,6 +9,7 @@ using System.Linq; |
|
|
|
using System.Net; |
|
|
|
using System.Net.NetworkInformation; |
|
|
|
using System.Net.Sockets; |
|
|
|
using System.Runtime.Remoting.Metadata.W3cXsd2001; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Windows; |
|
|
@ -45,6 +46,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View |
|
|
|
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
|
|
|
|
private readonly UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "SCCM.ini"); |
|
|
|
//private string SYS_machines = null;
|
|
|
|
int ID_; |
|
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView; |
|
|
@ -55,6 +57,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View |
|
|
|
int rownum = Griddata.SelectedIndex;//获取鼠标选中行并定义变量
|
|
|
|
if (rownum != -1)//判断鼠标定位是否有效
|
|
|
|
{ |
|
|
|
ID_ = int.Parse((Griddata.Columns[7].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text); |
|
|
|
comboBoxMachine.Text = (Griddata.Columns[1].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第1列,
|
|
|
|
TextMachineGroup.Text = (Griddata.Columns[2].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列,
|
|
|
|
IP.Text = (Griddata.Columns[3].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列,
|
|
|
@ -67,7 +70,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.View |
|
|
|
private void Save_Click(object sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(comboBoxMachine.Text)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
Dictionary<string, object> Machines_DAT = new Dictionary<string, object>();//缓存函数
|
|
|
|
Dictionary<string, object> dr_new = new Dictionary<string, object>();//缓存函数
|
|
|
|
dr_new.Add("Name", comboBoxMachine.Text); |
|
|
|
dr_new.Add("Groups", TextMachineGroup.Text); |
|
|
@ -75,19 +80,57 @@ namespace SunlightCentralizedControlManagement_SCCM_.View |
|
|
|
dr_new.Add("PORT", PORT.Text); |
|
|
|
dr_new.Add("Serial", comboBoxCOM0.Text); |
|
|
|
dr_new.Add("Baud", BAUD.Text); |
|
|
|
|
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
|
|
|
|
|
if (SQLiteHelpers.ExecuteDataSet("select * from Machines where name ='" + comboBoxMachine.Text + "'", null).Tables[0].Rows.Count == 0) |
|
|
|
{ |
|
|
|
SQLiteHelpers.InsertData("Machines", dr_new); |
|
|
|
MainWindowViewModel.Machines.Rows.Add(dr_new); |
|
|
|
DatSteps(MainWindowViewModel.Machines); |
|
|
|
SQLiteHelpers.Delete("Machines", null, null);//
|
|
|
|
for (int x = 0; x < MainWindowViewModel.Machines.Rows.Count; x++) |
|
|
|
{ |
|
|
|
Machines_DAT.Add("ID", MainWindowViewModel.Machines.Rows[x]["ID"]); |
|
|
|
Machines_DAT.Add("Name", MainWindowViewModel.Machines.Rows[x]["Name"]); |
|
|
|
Machines_DAT.Add("IP", MainWindowViewModel.Machines.Rows[x]["IP"]); |
|
|
|
Machines_DAT.Add("PORT", MainWindowViewModel.Machines.Rows[x]["PORT"]); |
|
|
|
Machines_DAT.Add("Serial", MainWindowViewModel.Machines.Rows[x]["Serial"]); |
|
|
|
Machines_DAT.Add("Baud", MainWindowViewModel.Machines.Rows[x]["Baud"]); |
|
|
|
Machines_DAT.Add("Groups", MainWindowViewModel.Machines.Rows[x]["Groups"]); |
|
|
|
Machines_DAT.Add("Desktop", MainWindowViewModel.Machines.Rows[x]["Desktop"]); |
|
|
|
Machines_DAT.Add("Dispense", MainWindowViewModel.Machines.Rows[x]["Dispense"]); |
|
|
|
Machines_DAT.Add("LOCK", "FALSE"); |
|
|
|
SQLiteHelpers.InsertData("Machines", Machines_DAT);//行插入
|
|
|
|
Machines_DAT.Clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
SQLiteHelpers.Update("Machines",dr_new,"name='"+comboBoxMachine.Text+"'",null); |
|
|
|
DataRow dr = MainWindowViewModel.Machines.Rows[ID_-1]; |
|
|
|
dr.BeginEdit(); |
|
|
|
dr["Name"] = comboBoxMachine.Text; |
|
|
|
dr["Groups"] = TextMachineGroup.Text; |
|
|
|
dr["IP"] = IP.Text; |
|
|
|
dr["PORT"] = PORT.Text; |
|
|
|
dr["Serial"] = comboBoxCOM0.Text; |
|
|
|
dr["Baud"] = BAUD.Text; |
|
|
|
dr.EndEdit(); |
|
|
|
SQLiteHelpers.Delete("Machines", null, null);//
|
|
|
|
for (int x = 0; x < MainWindowViewModel.Machines.Rows.Count; x++) |
|
|
|
{ |
|
|
|
Machines_DAT.Add("ID", MainWindowViewModel.Machines.Rows[x]["ID"]); |
|
|
|
Machines_DAT.Add("Name", MainWindowViewModel.Machines.Rows[x]["Name"]); |
|
|
|
Machines_DAT.Add("IP", MainWindowViewModel.Machines.Rows[x]["IP"]); |
|
|
|
Machines_DAT.Add("PORT", MainWindowViewModel.Machines.Rows[x]["PORT"]); |
|
|
|
Machines_DAT.Add("Serial", MainWindowViewModel.Machines.Rows[x]["Serial"]); |
|
|
|
Machines_DAT.Add("Baud", MainWindowViewModel.Machines.Rows[x]["Baud"]); |
|
|
|
Machines_DAT.Add("Groups", MainWindowViewModel.Machines.Rows[x]["Groups"]); |
|
|
|
Machines_DAT.Add("Desktop", MainWindowViewModel.Machines.Rows[x]["Desktop"]); |
|
|
|
Machines_DAT.Add("Dispense", MainWindowViewModel.Machines.Rows[x]["Dispense"]); |
|
|
|
Machines_DAT.Add("LOCK", "FALSE"); |
|
|
|
SQLiteHelpers.InsertData("Machines", Machines_DAT);//行插入
|
|
|
|
Machines_DAT.Clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
MainWindowViewModel.Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines Order by id", null).Tables[0]; //读取表写入缓存
|
|
|
|
SQLiteHelpers.Close(); |
|
|
|
Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView; |
|
|
|
comboBoxMachine.Text = null; |
|
|
@ -103,18 +146,38 @@ namespace SunlightCentralizedControlManagement_SCCM_.View |
|
|
|
textlog.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0)); |
|
|
|
} |
|
|
|
} |
|
|
|
private void Delete_Click(object sender, RoutedEventArgs e) |
|
|
|
private void Delete_Click(object sender, RoutedEventArgs e)//删除
|
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(comboBoxMachine.Text)) |
|
|
|
{ |
|
|
|
MessageBoxResult vr = System.Windows.MessageBox.Show(Properties.Resources.Delete + comboBoxMachine.Text, "SCCM", MessageBoxButton.OKCancel, MessageBoxImage.Question); |
|
|
|
if (vr == MessageBoxResult.OK) // 如果是确定,就执行下面代码
|
|
|
|
{ |
|
|
|
MainWindowViewModel.Machines.Rows.RemoveAt(ID_); |
|
|
|
DatSteps(MainWindowViewModel.Machines); |
|
|
|
|
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
|
SQLiteHelpers.Delete("Machines", "Name='" + comboBoxMachine.Text + "'", null); |
|
|
|
MainWindowViewModel.Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines Order by id", null).Tables[0]; //读取表写入缓存
|
|
|
|
SQLiteHelpers.Close(); |
|
|
|
Dictionary<string, object> Machines_DAT = new Dictionary<string, object>();//缓存函数
|
|
|
|
|
|
|
|
SQLiteHelpers.Delete("Machines",null, null);//
|
|
|
|
for (int x = 0; x < MainWindowViewModel.Machines.Rows.Count; x++) |
|
|
|
{ |
|
|
|
Machines_DAT.Add("ID", MainWindowViewModel.Machines.Rows[x]["ID"]); |
|
|
|
Machines_DAT.Add("Name", MainWindowViewModel.Machines.Rows[x]["Name"]); |
|
|
|
Machines_DAT.Add("IP", MainWindowViewModel.Machines.Rows[x]["IP"]); |
|
|
|
Machines_DAT.Add("PORT", MainWindowViewModel.Machines.Rows[x]["PORT"]); |
|
|
|
Machines_DAT.Add("Serial", MainWindowViewModel.Machines.Rows[x]["Serial"]); |
|
|
|
Machines_DAT.Add("Baud", MainWindowViewModel.Machines.Rows[x]["Baud"]); |
|
|
|
Machines_DAT.Add("Groups", MainWindowViewModel.Machines.Rows[x]["Groups"]); |
|
|
|
Machines_DAT.Add("Desktop", MainWindowViewModel.Machines.Rows[x]["Desktop"]); |
|
|
|
Machines_DAT.Add("Dispense", MainWindowViewModel.Machines.Rows[x]["Dispense"]); |
|
|
|
Machines_DAT.Add("LOCK", "FALSE"); |
|
|
|
SQLiteHelpers.InsertData("Machines", Machines_DAT);//行插入
|
|
|
|
Machines_DAT.Clear(); |
|
|
|
} |
|
|
|
SQLiteHelpers.Close(); //关闭连接
|
|
|
|
|
|
|
|
Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView; |
|
|
|
comboBoxMachine.Text = null; |
|
|
|
} |
|
|
@ -125,6 +188,18 @@ namespace SunlightCentralizedControlManagement_SCCM_.View |
|
|
|
textlog.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void DatSteps(DataTable db)//行号刷新
|
|
|
|
{ |
|
|
|
int a = db.Rows.Count; |
|
|
|
for (int i = 0; i < a; i++) |
|
|
|
{ |
|
|
|
DataRow dr = db.Rows[i]; |
|
|
|
dr.BeginEdit(); |
|
|
|
dr["ID"] = i + 1; |
|
|
|
dr.EndEdit(); |
|
|
|
} |
|
|
|
} |
|
|
|
private void Test_Click(object sender, RoutedEventArgs e)//测试按钮
|
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(IP.Text) && !string.IsNullOrEmpty(PORT.Text)) |
|
|
|