using SunlightCentralizedControlManagement_SCCM_.UserClass; using SunlightCentralizedControlManagement_SCCM_.ViewModel; using SunlightCentralizedControlManagement_SCCM_.WindowsView; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using TouchSocket.Core; using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper; using static SunlightCentralizedControlManagement_SCCM_.WindowsView.ViewStep; namespace SunlightCentralizedControlManagement_SCCM_.View { /// /// ProductionPlanningEdit.xaml 的交互逻辑 /// public partial class ProductionPlanningEdit : UserControl { private SQLiteHelper SQLiteHelpers = null; //定义数据库 private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径 DataTable ProgramName; DataTable dat = new DataTable(); public ProductionPlanningEdit() { InitializeComponent(); SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 SQLiteHelpers.Open(); //打开数据库 ProgramName = SQLiteHelpers.ExecuteDataSet("select * from ProgramName order by ProgramID desc", null).Tables[0]; //读取计划表写入缓存 SQLiteHelpers.Close(); //关闭连接 comboBoxMachine.ItemsSource = MainWindowViewModel.Machines.AsEnumerable().Select(rowdata => rowdata.Field("name")).ToList();//转换机台 comboBoxProgram.ItemsSource = ProgramName.AsEnumerable().Select(rowdata => rowdata.Field("ProgramName")).ToList();//转换工艺代码 } private void comboBoxMachine_DropDownClosed(object sender, EventArgs e)//机台选择 { string[] sArray = Regex.Split(comboBoxMachine.Text, @"\+", RegexOptions.IgnoreCase); if (sArray.Length <= 1) { comboBoxDyelot.IsEnabled = true; SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 SQLiteHelpers.Open(); //打开数据库 DataTable DatDyelot = SQLiteHelpers.ExecuteDataSet("select * from Dyelot where Machine='" + comboBoxMachine.Text + "' order by Dyelot desc", null).Tables[0]; //读取计划表写入缓存 SQLiteHelpers.Close(); //关闭连接 comboBoxDyelot.ItemsSource = DatDyelot.AsEnumerable().Select(rowdata => rowdata.Field("Dyelot")).ToList();//转换代码 } } private void Multi_Click(object sender, RoutedEventArgs e)//机台组 { MachineSelection machineSelection = new MachineSelection(); machineSelection.AddressUpdated += new MachineSelection.AddressUpdateHandler(Address_Multi_Click); //machineSelection.data = "ID"; machineSelection.ShowDialog(); } private void Address_Multi_Click(object sender, MachineSelection.AddressUpdateEventArgs e)//机台组返回结果 { if(!string.IsNullOrEmpty(e.Groups)) comboBoxMachine.Text = e.Groups; comboBoxDyelot.Text = null; comboBoxDyelot.IsEnabled = false; } private void Button_Click(object sender, RoutedEventArgs e) { } private void Button_Quit(object sender, RoutedEventArgs e)//退出 { this.Visibility = Visibility.Collapsed; } 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["Step"] = i + 1; dr.EndEdit(); } } private void comboBoxProgram_DropDownClosed(object sender, EventArgs e)//工艺选择事件 { if (!string.IsNullOrEmpty(comboBoxProgram.Text)) { dat.Clear(); SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 SQLiteHelpers.Open(); //打开数据库 dat = SQLiteHelpers.ExecuteDataSet( "select * from ProgramSteps where Program='" + comboBoxProgram.SelectedValue + "' order by Step asc", null).Tables[0]; //读取计划表写入缓存 SQLiteHelpers.Close(); //关闭连接 DatSteps(dat); Grid_data.ItemsSource = dat.DefaultView; } } private void comboBoxProgram_TextChanged(object sender, TextChangedEventArgs e) { dat.Clear(); string text = comboBoxProgram.Text; if (!string.IsNullOrEmpty(text)) { try { string[] sArray = Regex.Split(text, @"\+", RegexOptions.IgnoreCase); SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 SQLiteHelpers.Open(); //打开数据库 for (int i = 0; i < sArray.Length; i++) { DataTable temp = SQLiteHelpers.ExecuteDataSet( "select * from ProgramSteps where Program='" + sArray[i] + "' order by Step asc", null).Tables[0]; //读取计划表写入缓存 if (dat.Columns.Count == 0) dat = temp.Clone(); foreach (DataRow dr in temp.Rows) { dat.Rows.Add(dr.ItemArray); } //dat = temp.Copy(); } SQLiteHelpers.Close(); //关闭连接 DatSteps(dat); Grid_data.ItemsSource = dat.DefaultView; } catch (Exception) { } } } string ProgramID; string ProgramNAME; string Numder = null; string ID = null; string P1, P2, P3, P4, P5; private void Grid_data_MouseDoubleClick(object sender, MouseButtonEventArgs e) { int rownum = Grid_data.SelectedIndex;//获取鼠标选中行并定义变量 if (rownum != -1)//判断鼠标定位是否有效 { ID = (Grid_data.Columns[2].GetCellContent(Grid_data.Items[rownum]) as TextBlock).Text;//定位第0列, Numder = (Grid_data.Columns[3].GetCellContent(Grid_data.Items[rownum]) as TextBlock).Text;//定位第1列, P1 = (Grid_data.Columns[6].GetCellContent(Grid_data.Items[rownum]) as TextBlock).Text;//定位第6列, P2 = (Grid_data.Columns[7].GetCellContent(Grid_data.Items[rownum]) as TextBlock).Text;//定位第7列, P3 = (Grid_data.Columns[8].GetCellContent(Grid_data.Items[rownum]) as TextBlock).Text;//定位第8列, P4 = (Grid_data.Columns[9].GetCellContent(Grid_data.Items[rownum]) as TextBlock).Text;//定位第9列, P5 = (Grid_data.Columns[10].GetCellContent(Grid_data.Items[rownum]) as TextBlock).Text;//定位第10列, if (string.IsNullOrEmpty(Numder)) { Numder = null; P1 = "0"; P2 = "0"; P3 = "0"; P4 = "0"; P5 = "0"; } if (ID == null) ID = dat.Rows.Count.ToString(); ViewStep viewstop = new ViewStep(Numder, P1, P2, P3, P4, P5); viewstop.AddressUpdated += new ViewStep.AddressUpdateHandler(Address_ButtonClicked); viewstop.data = ID; viewstop.ShowDialog(); } } private void Address_ButtonClicked(object sender, AddressUpdateEventArgs e)//编辑返回结果 { int i = dat.Rows.Count; int n = StrToInt.To16Convert10(ID); DataRow dr = dat.Rows[n - 1]; dr.BeginEdit(); dr["StepID"] = e.StepID; dr["StepName"] = e.StepNAME; dr["ParameterName"] = e.PNAME; dr["Parameter1"] = e.P1; dr["Parameter2"] = e.P2; dr["Parameter3"] = e.P3; dr["Parameter4"] = e.P4; dr["Parameter5"] = e.P5; dr.EndEdit(); Grid_data.ItemsSource = dat.DefaultView; } } }