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.
315 lines
13 KiB
315 lines
13 KiB
using SunlightCentralizedControlManagement_SCCM_.UserClass;
|
|
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 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();
|
|
}
|
|
|
|
private SQLiteHelper SQLiteHelpers = null; //定义数据库
|
|
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
|
|
DataSet sql; //内存数据缓存
|
|
|
|
string ProgramID;
|
|
string ProgramNAME;
|
|
string Numder = null;
|
|
string ID = null;
|
|
string P1, P2, P3, P4, P5;
|
|
string StepTime = null;
|
|
public void Programgroup_sql()
|
|
{
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
|
|
string sql_script = "select * from ProgramSteps where ProgramID='" + ProgramID + "' order by Step asc";
|
|
|
|
if (sql != null) sql.Clear(); //清空缓存
|
|
sql = SQLiteHelpers.ExecuteDataSet(sql_script, null); //读取计划表写入缓存
|
|
//sql.Tables[0].Rows.Add(datatable_t);
|
|
DataRow dr = sql.Tables[0].NewRow();//添加表数据
|
|
dr["ProgramID"] = ProgramID;
|
|
dr["Program"] = ProgramNAME;
|
|
sql.Tables[0].Rows.Add(dr);
|
|
Dat();
|
|
if (sql != null) Grid.ItemsSource = sql.Tables[0].DefaultView; //转换显示计划表
|
|
SQLiteHelpers.Close(); //关闭连接
|
|
}
|
|
|
|
public void Dat()//行号刷新
|
|
{
|
|
int a = sql.Tables[0].Rows.Count;
|
|
for (int i = 0; i < a; i++)
|
|
{
|
|
DataRow dr = sql.Tables[0].Rows[i];
|
|
dr.BeginEdit();
|
|
dr["Step"] = i + 1;
|
|
dr.EndEdit();
|
|
}
|
|
}
|
|
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)//打开页面时的操作
|
|
{
|
|
if (ID == null) ID = sql.Tables[0].Rows.Count.ToString();
|
|
Grid.SelectedIndex = Convert.ToInt32(ID)-1;
|
|
}
|
|
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.IsEnabled = true;
|
|
Insert.IsEnabled = true;
|
|
Delete.IsEnabled = true;
|
|
int rownum = Grid.SelectedIndex;//获取鼠标选中行并定义变量
|
|
if (rownum != -1)//判断鼠标定位是否有效
|
|
{
|
|
ID = (Grid.Columns[2].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第0列,
|
|
Numder = (Grid.Columns[3].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第1列,
|
|
P1 = (Grid.Columns[6].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第6列,
|
|
P2 = (Grid.Columns[7].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第7列,
|
|
P3 = (Grid.Columns[8].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第8列,
|
|
P4 = (Grid.Columns[9].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第9列,
|
|
P5 = (Grid.Columns[10].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第10列,
|
|
StepTime = (Grid.Columns[16].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//
|
|
}
|
|
}
|
|
|
|
private void Grid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)//双击表格编辑事件
|
|
{
|
|
edit.IsEnabled = true;
|
|
Insert.IsEnabled = true;
|
|
Delete.IsEnabled = true;
|
|
int rownum = Grid.SelectedIndex;//获取鼠标选中行并定义变量
|
|
if (rownum != -1)//判断鼠标定位是否有效
|
|
{
|
|
ID = (Grid.Columns[2].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第0列,
|
|
Numder = (Grid.Columns[3].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第1列,
|
|
P1 = (Grid.Columns[6].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第6列,
|
|
P2 = (Grid.Columns[7].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第7列,
|
|
P3 = (Grid.Columns[8].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第8列,
|
|
P4 = (Grid.Columns[9].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第9列,
|
|
P5 = (Grid.Columns[10].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第10列,
|
|
StepTime = (Grid.Columns[16].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//
|
|
|
|
if (string.IsNullOrEmpty(Numder)) { Numder = null; P1 = "0"; P2 = "0"; P3 = "0"; P4 = "0"; P5 = "0"; }
|
|
if (ID == null) ID = sql.Tables[0].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 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.IsEnabled = false;
|
|
Insert.IsEnabled = false;
|
|
Delete.IsEnabled = false;
|
|
if (string.IsNullOrEmpty(Numder)) { Numder = null; P1 = "0"; P2 = "0"; P3 = "0"; P4 = "0"; P5 = "0"; }
|
|
if (ID == null) ID = sql.Tables[0].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 = sql.Tables[0].Rows.Count;
|
|
int n = StrToInt.To16Convert10(ID);
|
|
if (i == n)
|
|
{
|
|
DataRow dr_ = sql.Tables[0].NewRow();//添加表数据
|
|
dr_["ProgramID"] = ProgramID;
|
|
dr_["Program"] = ProgramNAME;
|
|
sql.Tables[0].Rows.Add(dr_);
|
|
Dat();
|
|
ID = (n + 1).ToString();
|
|
}
|
|
|
|
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.P3)*60;
|
|
}
|
|
}
|
|
foreach (var item in time_J)
|
|
{
|
|
if (item == e.StepID)
|
|
{
|
|
steptime = Convert.ToUInt16(e.P1) * 60;
|
|
}
|
|
}
|
|
foreach (var item in time_T)
|
|
{
|
|
if (item == e.StepID)
|
|
{
|
|
steptime = 5;
|
|
}
|
|
}
|
|
if (steptime==0)
|
|
{
|
|
steptime = 300;
|
|
}
|
|
|
|
DataRow dr = sql.Tables[0].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["StepTime"] =steptime;//
|
|
dr.EndEdit();
|
|
|
|
Grid.ItemsSource = sql.Tables[0].DefaultView;
|
|
}
|
|
|
|
private void ListViewItem_Insert(object sender, System.Windows.Input.MouseButtonEventArgs e)//插入事件
|
|
{
|
|
edit.IsEnabled = false;
|
|
Insert.IsEnabled = false;
|
|
Delete.IsEnabled = false; int d = 0;
|
|
if (ID != null) { d = Convert.ToInt32(ID); } else { return; }
|
|
DataRow dr = sql.Tables[0].NewRow();//添加表数据
|
|
dr["ProgramID"] = ProgramID;
|
|
dr["Program"] = ProgramNAME;
|
|
sql.Tables[0].Rows.InsertAt(dr, d - 1);
|
|
ID = null;
|
|
|
|
Dat();
|
|
Grid.ItemsSource = sql.Tables[0].DefaultView; //转换显示计划表
|
|
}
|
|
|
|
private void ListViewItem_Save(object sender, System.Windows.Input.MouseButtonEventArgs e)//保存事件
|
|
{
|
|
edit.IsEnabled = false;
|
|
Insert.IsEnabled = false;
|
|
Delete.IsEnabled = false;
|
|
int r = 0;
|
|
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
SQLiteHelpers.Delete("ProgramSteps", "ProgramID = '" + ProgramID + "'", null);
|
|
|
|
DataTable data_t = new DataTable();
|
|
data_t = sql.Tables[0].Clone();
|
|
|
|
int a = sql.Tables[0].Rows.Count;
|
|
for (int i = 0; i < a - 1; i++)
|
|
{
|
|
data_t.Clear();//清空
|
|
|
|
DataRow dt = sql.Tables[0].Rows[i];//行转换
|
|
DataRow dr = data_t.NewRow();
|
|
dr.ItemArray = dt.ItemArray;
|
|
data_t.Rows.InsertAt(dr, 0);
|
|
|
|
r = SQLiteHelpers.InsertData("ProgramSteps", SQLiteHelpers.DataTableToDictionary(data_t));//行插入
|
|
}
|
|
|
|
int time =Convert.ToUInt16( sql.Tables[0].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_);
|
|
SQLiteHelpers.Update("ProgramName", Program_Step, "ProgramID='" + ProgramID + "'", null);
|
|
|
|
SQLiteHelpers.Close(); //关闭连接
|
|
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.IsEnabled = false;
|
|
Insert.IsEnabled = false;
|
|
Delete.IsEnabled = false;
|
|
|
|
int d = 0;
|
|
int a = sql.Tables[0].Rows.Count;
|
|
|
|
if (ID != null) { d = Convert.ToInt32(ID); } else { return; }
|
|
if (a != d)//如果删除不是最后一行执行
|
|
{
|
|
sql.Tables[0].Rows.RemoveAt(d - 1);
|
|
|
|
Dat();
|
|
Grid.ItemsSource = sql.Tables[0].DefaultView; //转换显示计划表
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|