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.MachineSelection;
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;
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 Multi_Click(object sender, RoutedEventArgs e)//机台组
{
MachineSelection machineSelection = new MachineSelection();
machineSelection.AddressUpdated += new MachineSelection.AddressUpdateHandler(Address_ButtonClicked);
//machineSelection.data = "ID";
machineSelection.ShowDialog();
}
private void Address_ButtonClicked(object sender, AddressUpdateEventArgs e)//机台组返回结果
{
if(!string.IsNullOrEmpty(e.Groups)) comboBoxMachine.Text = e.Groups;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
private void Button_Quit(object sender, RoutedEventArgs e)
{
this.Visibility = Visibility.Collapsed;
}
private void comboBoxProgram_DropDownClosed(object sender, EventArgs e)//工艺选择事件
{
if (!string.IsNullOrEmpty(comboBoxProgram.Text))
{
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
DataTable dat = SQLiteHelpers.ExecuteDataSet(
"select * from ProgramSteps where Program='" + comboBoxProgram.SelectedValue + "' order by Step asc", null).Tables[0]; //读取计划表写入缓存
SQLiteHelpers.Close(); //关闭连接
Grid_data.ItemsSource = dat.DefaultView;
}
}
private void comboBoxProgram_TextChanged(object sender, TextChangedEventArgs e)
{
string text = comboBoxProgram.Text;
if (!string.IsNullOrEmpty(text))
{
// try
{
string[] sArray = Regex.Split(text, @"\+", RegexOptions.IgnoreCase);
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
DataTable dat = new DataTable();
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(); //关闭连接
Grid_data.ItemsSource = dat.DefaultView;
}
// catch (Exception) { }
}
}
}
}