You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

419 lines
18 KiB

using SunlightCentralizedControlManagement_SCCM_.UserClass;
using SunlightCentralizedControlManagement_SCCM_.ViewModel;
using SunlightCentralizedControlManagement_SCCM_.WindowsView;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.SQLite;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml.Linq;
using TouchSocket.Core;
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
using static SunlightCentralizedControlManagement_SCCM_.WindowsView.ViewStep;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace SunlightCentralizedControlManagement_SCCM_.View
{
/// <summary>
/// ProgramgroupView.xaml 的交互逻辑
/// </summary>
public partial class ProgramstepsView : UserControl
{
public ProgramstepsView()
{
InitializeComponent();
ProgramID = ProgramgroupView.Programgroup_ID;
ProgramNAME = ProgramgroupView.Programgroup_Numder;
this.p_title.Text = ProgramNAME;
Programgroup_sql();
}
// DataSet sql; //内存数据缓存
DataTable Step;
string ProgramID;
string ProgramNAME;
string Numder = null;
string ID = null;
string P1, P2, P3, P4, P5;
string StepTime = null;
public void Programgroup_sql()
{
string sql_script = "select * from ProgramSteps where ProgramID='" + ProgramID + "' order by Step asc";
Step = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet(sql_script, null).Tables[0]; //读取计划表写入缓存
Grid_step.ItemsSource = Step.DefaultView; //转换显示计划表
}
public void Dat(DataTable dat)//行号刷新
{
int a = dat.Rows.Count;
for (int i = 0; i < a; i++)
{
DataRow dr = dat.Rows[i];
dr.BeginEdit();
dr["Step"] = i + 1;
dr.EndEdit();
}
dat.AcceptChanges();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)//打开页面时的操作
{
}
public static T GetVisualChild<T>(Visual parent) where T : Visual
{
T child = default(T);
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
child = v as T;
if (child == null)
{
child = GetVisualChild<T>(v);
}
if (child != null)
{
break;
}
}
return child;
}
private void Grid_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)//表格选择事件
{
edit.IsHitTestVisible = true;
Insert.IsHitTestVisible = true;
Delete.IsHitTestVisible = true;
int rownum = Grid_step.SelectedIndex;//获取鼠标选中行并定义变量
if (rownum != -1)//判断鼠标定位是否有效
{
ID = (Grid_step.Columns[2].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//定位第0列,
Numder = (Grid_step.Columns[3].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//定位第1列,
P1 = (Grid_step.Columns[6].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//定位第6列,
P2 = (Grid_step.Columns[7].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//定位第7列,
P3 = (Grid_step.Columns[8].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//定位第8列,
P4 = (Grid_step.Columns[9].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//定位第9列,
P5 = (Grid_step.Columns[10].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//定位第10列,
StepTime = (Grid_step.Columns[16].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//
}
}
private void Grid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)//双击表格编辑事件
{
edit.IsHitTestVisible = true;
Insert.IsHitTestVisible = true;
Delete.IsHitTestVisible = true;
int rownum = Grid_step.SelectedIndex;//获取鼠标选中行并定义变量
if (rownum != -1)//判断鼠标定位是否有效
{
ID = (Grid_step.Columns[2].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//定位第0列,
Numder = (Grid_step.Columns[3].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//定位第1列,
P1 = (Grid_step.Columns[6].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//定位第6列,
P2 = (Grid_step.Columns[7].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//定位第7列,
P3 = (Grid_step.Columns[8].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//定位第8列,
P4 = (Grid_step.Columns[9].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//定位第9列,
P5 = (Grid_step.Columns[10].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//定位第10列,
StepTime = (Grid_step.Columns[16].GetCellContent(Grid_step.Items[rownum]) as TextBlock).Text;//
if (string.IsNullOrEmpty(Numder)) { Numder = null; P1 = "0"; P2 = "0"; P3 = "0"; P4 = "0"; P5 = "0"; }
if (string.IsNullOrEmpty(ID))
{
DataRow dr = Step.NewRow();//添加表数据
dr["ProgramID"] = ProgramID;
dr["Program"] = ProgramNAME;
dr["Parameter1"] = 0;
dr["Parameter2"] = 0;
dr["Parameter3"] = 0;
dr["Parameter4"] = 0;
dr["Parameter5"] = 0;
dr["Parameter6"] = 0;
dr["Parameter7"] = 0;
dr["Parameter8"] = 0;
dr["Parameter9"] = 0;
dr["Parameter10"] = 0;
dr["Parameter1_S1"] = 0;
dr["Parameter2_S1"] = 0;
dr["Parameter3_S1"] = 0;
dr["Parameter4_S1"] = 0;
dr["Parameter5_S1"] = 0;
dr["Parameter1_S2"] = 0;
dr["Parameter2_S2"] = 0;
dr["Parameter3_S2"] = 0;
dr["Parameter4_S2"] = 0;
dr["Parameter5_S2"] = 0;
dr["Parameter1_S3"] = 0;
dr["Parameter2_S3"] = 0;
dr["Parameter3_S3"] = 0;
dr["Parameter4_S3"] = 0;
dr["Parameter5_S3"] = 0;
dr["StepName_S1"] = " ";
dr["StepName_S2"] = " ";
dr["StepName_S3"] = " ";
dr["StepID_S1"] = "000";
dr["StepID_S2"] = "000";
dr["StepID_S3"] = "000";
Step.Rows.InsertAt(dr, Step.Rows.Count);
Dat(Step);
ID = (Step.Rows.Count).ToString();
}
ViewStep viewstop = new ViewStep(Numder, Step.Select("STEP = " + ID).First());
viewstop.AddressUpdated += new ViewStep.AddressUpdateHandler(Address_ButtonClicked);
viewstop.data = ID;
viewstop.ShowDialog();
}
}
private void ListViewItem_Quit(object sender, System.Windows.Input.MouseButtonEventArgs e)//退出事件
{
this.Visibility = Visibility.Collapsed;//隐藏控件
}
private void ListViewItem_edit(object sender, System.Windows.Input.MouseButtonEventArgs e)//编辑事件
{
edit.IsHitTestVisible = false;
Insert.IsHitTestVisible = false;
Delete.IsHitTestVisible = false;
if (string.IsNullOrEmpty(Numder)) { Numder = null; P1 = "0"; P2 = "0"; P3 = "0"; P4 = "0"; P5 = "0"; }
if (string.IsNullOrEmpty(ID))
{
DataRow dr = Step.NewRow();//添加表数据
dr["ProgramID"] = ProgramID;
dr["Program"] = ProgramNAME;
dr["Parameter1"] = 0;
dr["Parameter2"] = 0;
dr["Parameter3"] = 0;
dr["Parameter4"] = 0;
dr["Parameter5"] = 0;
dr["Parameter6"] = 0;
dr["Parameter7"] = 0;
dr["Parameter8"] = 0;
dr["Parameter9"] = 0;
dr["Parameter10"] = 0;
dr["Parameter1_S1"] = 0;
dr["Parameter2_S1"] = 0;
dr["Parameter3_S1"] = 0;
dr["Parameter4_S1"] = 0;
dr["Parameter5_S1"] = 0;
dr["Parameter1_S2"] = 0;
dr["Parameter2_S2"] = 0;
dr["Parameter3_S2"] = 0;
dr["Parameter4_S2"] = 0;
dr["Parameter5_S2"] = 0;
dr["Parameter1_S3"] = 0;
dr["Parameter2_S3"] = 0;
dr["Parameter3_S3"] = 0;
dr["Parameter4_S3"] = 0;
dr["Parameter5_S3"] = 0;
dr["StepName_S1"] = " ";
dr["StepName_S2"] = " ";
dr["StepName_S3"] = " ";
dr["StepID_S1"] = "000";
dr["StepID_S2"] = "000";
dr["StepID_S3"] = "000";
Step.Rows.InsertAt(dr, Step.Rows.Count);
Dat(Step);
ID = Step.Rows.Count.ToString();
}
ViewStep viewstop = new ViewStep(Numder, Step.Select("STEP = " + ID).First());
viewstop.AddressUpdated += new ViewStep.AddressUpdateHandler(Address_ButtonClicked);
viewstop.data = ID;
viewstop.ShowDialog();
}
private void Address_ButtonClicked(object sender, AddressUpdateEventArgs e)//编辑返回结果
{
int i = Step.Rows.Count;
int n = Convert.ToInt16(ID);
int steptime = 0;//时间秒
string[] time_D = { "001", "013", "015", "017", "065" };
string[] time_J = { "031", "093" };
string[] time_T = { "054", "055", "056" };
foreach (var item in time_D)
{
if (item == e.StepID)
{
steptime = Convert.ToUInt16(e.Row_DAT.Field<double>("Parameter3")) * 60;
}
}
foreach (var item in time_J)
{
if (item == e.StepID)
{
steptime = Convert.ToUInt16(e.Row_DAT.Field<double>("Parameter1")) * 60;
}
}
foreach (var item in time_T)
{
if (item == e.StepID)
{
steptime = 5;
}
}
if (steptime == 0)
{
steptime = 300;
}
DataRow dr = Step.Rows[n - 1];
dr.BeginEdit();
dr["StepID"] = e.StepID;
dr["StepName"] = e.StepNAME;
dr["ParameterName"] = e.PNAME;
dr["Parameter1"] = e.Row_DAT.Field<double>("Parameter1");
dr["Parameter2"] = e.Row_DAT.Field<double>("Parameter2");
dr["Parameter3"] = e.Row_DAT.Field<double>("Parameter3");
dr["Parameter4"] = e.Row_DAT.Field<double>("Parameter4");
dr["Parameter5"] = e.Row_DAT.Field<double>("Parameter5");
dr["Parameter1_S1"] = e.Row_DAT.Field<double>("Parameter1_S1");
dr["Parameter2_S1"] = e.Row_DAT.Field<double>("Parameter2_S1");
dr["Parameter3_S1"] = e.Row_DAT.Field<double>("Parameter3_S1");
dr["Parameter4_S1"] = e.Row_DAT.Field<double>("Parameter4_S1");
dr["Parameter5_S1"] = e.Row_DAT.Field<double>("Parameter5_S1");
dr["Parameter1_S2"] = e.Row_DAT.Field<double>("Parameter1_S2");
dr["Parameter2_S2"] = e.Row_DAT.Field<double>("Parameter2_S2");
dr["Parameter3_S2"] = e.Row_DAT.Field<double>("Parameter3_S2");
dr["Parameter4_S2"] = e.Row_DAT.Field<double>("Parameter4_S2");
dr["Parameter5_S2"] = e.Row_DAT.Field<double>("Parameter5_S2");
dr["Parameter1_S3"] = e.Row_DAT.Field<double>("Parameter1_S3");
dr["Parameter2_S3"] = e.Row_DAT.Field<double>("Parameter2_S3");
dr["Parameter3_S3"] = e.Row_DAT.Field<double>("Parameter3_S3");
dr["Parameter4_S3"] = e.Row_DAT.Field<double>("Parameter4_S3");
dr["Parameter5_S3"] = e.Row_DAT.Field<double>("Parameter5_S3");
dr["StepName_S1"] = e.Row_DAT.Field<string>("StepName_S1");
dr["StepName_S2"] = e.Row_DAT.Field<string>("StepName_S2");
dr["StepName_S3"] = e.Row_DAT.Field<string>("StepName_S3");
dr["StepID_S1"] = e.Row_DAT.Field<string>("StepID_S1");
dr["StepID_S2"] = e.Row_DAT.Field<string>("StepID_S2");
dr["StepID_S3"] = e.Row_DAT.Field<string>("StepID_S3");
dr["StepTime"] = steptime;//
dr.EndEdit();
Grid_step.ItemsSource = Step.DefaultView;
}
private void ListViewItem_Insert(object sender, System.Windows.Input.MouseButtonEventArgs e)//插入事件
{
edit.IsHitTestVisible = false;
Insert.IsHitTestVisible = false;
Delete.IsHitTestVisible = false;
int d = 0;
if (ID != null) { d = Convert.ToInt32(ID); } else { return; }
DataRow dr = Step.NewRow();//添加表数据
dr["ProgramID"] = ProgramID;
dr["Program"] = ProgramNAME;
dr["Parameter1"] = 0;
dr["Parameter2"] = 0;
dr["Parameter3"] = 0;
dr["Parameter4"] = 0;
dr["Parameter5"] = 0;
dr["Parameter6"] = 0;
dr["Parameter7"] = 0;
dr["Parameter8"] = 0;
dr["Parameter9"] = 0;
dr["Parameter10"] = 0;
dr["Parameter1_S1"] = 0;
dr["Parameter2_S1"] = 0;
dr["Parameter3_S1"] = 0;
dr["Parameter4_S1"] = 0;
dr["Parameter5_S1"] = 0;
dr["Parameter1_S2"] = 0;
dr["Parameter2_S2"] = 0;
dr["Parameter3_S2"] = 0;
dr["Parameter4_S2"] = 0;
dr["Parameter5_S2"] = 0;
dr["Parameter1_S3"] = 0;
dr["Parameter2_S3"] = 0;
dr["Parameter3_S3"] = 0;
dr["Parameter4_S3"] = 0;
dr["Parameter5_S3"] = 0;
dr["StepName_S1"] = " ";
dr["StepName_S2"] = " ";
dr["StepName_S3"] = " ";
dr["StepID_S1"] = "000";
dr["StepID_S2"] = "000";
dr["StepID_S3"] = "000";
Step.Rows.InsertAt(dr, d - 1);
ID = null;
Dat(Step);
Grid_step.ItemsSource = Step.DefaultView; //转换显示计划表
}
private void ListViewItem_Save(object sender, System.Windows.Input.MouseButtonEventArgs e)//保存事件
{
edit.IsHitTestVisible = false;
Insert.IsHitTestVisible = false;
Delete.IsHitTestVisible = false;
int r = 0;
MainWindowViewModel.SQLiteHelpers.Delete("ProgramSteps", "ProgramID = '" + ProgramID + "'", null);
DataTable data_t = new DataTable();
data_t = Step.Clone();
int a = Step.Rows.Count;
for (int i = 0; i < a ; i++)
{
data_t.Clear();//清空
DataRow dt = Step.Rows[i];//行转换
DataRow dr = data_t.NewRow();
dr.ItemArray = dt.ItemArray;
data_t.Rows.InsertAt(dr, 0);
r = MainWindowViewModel.SQLiteHelpers.InsertData("ProgramSteps", MainWindowViewModel.SQLiteHelpers.DataTableToDictionary(data_t));//行插入
}
int time =Convert.ToUInt16( Step.Compute("sum(StepTime)", ""))/60;
string time_ =DateTime.Parse( TimeSpan.FromMinutes(time).ToString()).ToString("HH:mm");// DateTime.Parse(time.ToString()).ToString("HH:mm");
Dictionary<string, object> Program_Step = new Dictionary<string, object>();//缓存函数
Program_Step.Add("Step", a - 1);
Program_Step.Add("Time", time_);
MainWindowViewModel.SQLiteHelpers.Update("ProgramName", Program_Step, "ProgramID='" + ProgramID + "'", null);
if (r != 0)
{
System.Windows.Forms.MessageBox.Show(ProgramNAME, Properties.Resources.Save);
this.Visibility = Visibility.Collapsed;//隐藏控件
}
}
private void ListViewItem_Delete(object sender, System.Windows.Input.MouseButtonEventArgs e)//删除事件
{
edit.IsHitTestVisible = false;
Insert.IsHitTestVisible = false;
Delete.IsHitTestVisible = false;
int a = Step.Rows.Count;
int rownum = Grid_step.SelectedIndex;
if (rownum >= 0 && rownum<a)
{
Step.Rows.RemoveAt(rownum);
Dat(Step);
Grid_step.ItemsSource = Step.DefaultView; //转换显示计划表
}
}
}
}