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.
170 lines
6.7 KiB
170 lines
6.7 KiB
11 months ago
|
using SkiaSharp;
|
||
|
using SunlightCentralizedControlManagement_SCCM_.UserClass;
|
||
|
using SunlightCentralizedControlManagement_SCCM_.ViewModel;
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Data;
|
||
|
using System.Linq;
|
||
|
using System.Net;
|
||
|
using System.Net.NetworkInformation;
|
||
|
using System.Net.Sockets;
|
||
|
using System.Text;
|
||
|
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 System.Windows.Threading;
|
||
|
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
|
||
|
|
||
|
namespace SunlightCentralizedControlManagement_SCCM_.View
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// MachinesSet.xaml 的交互逻辑
|
||
|
/// </summary>
|
||
|
public partial class MachinesView : UserControl
|
||
|
{
|
||
|
public MachinesView()
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
CountDown();
|
||
|
}
|
||
|
|
||
|
private SQLiteHelper SQLiteHelpers = null; //定义数据库
|
||
|
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;
|
||
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||
|
{
|
||
|
Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView;
|
||
|
}
|
||
|
string machine;
|
||
|
private void Griddata_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||
|
{
|
||
|
int rownum = Griddata.SelectedIndex;//获取鼠标选中行并定义变量
|
||
|
if (rownum != -1)//判断鼠标定位是否有效
|
||
|
{
|
||
|
machine = (Griddata.Columns[1].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第1列,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void ListViewItem_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
private void Grid_D_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
private void Grid_A_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
private void Grid_M_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
private void Grid_D_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
|
||
|
{
|
||
|
string ID;
|
||
|
string newValue = (e.EditingElement as TextBox).Text;//获得输入单元格信息
|
||
|
|
||
|
int rownum = Grid_D.SelectedIndex;//获取鼠标选中行并定义变量
|
||
|
if (rownum != -1)//判断鼠标定位是否有效
|
||
|
{
|
||
|
ID = (Grid_D.Columns[0].GetCellContent(Grid_D.Items[rownum]) as TextBlock).Text;//定位第0列,
|
||
|
|
||
|
Dictionary<string, object> datagrid_v = new Dictionary<string, object>();//缓存函数
|
||
|
datagrid_v.Add("PLC", newValue);
|
||
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
||
|
SQLiteHelpers.Open(); //打开数据库
|
||
|
SQLiteHelpers.Update("IOName", datagrid_v, "ID ='" + ID + "'", null);//更新
|
||
|
SQLiteHelpers.Close();//关闭数据库
|
||
|
}
|
||
|
IO_data();//重新获得io表
|
||
|
MainWindowViewModel.D_view = true;
|
||
|
}
|
||
|
|
||
|
private void Grid_D_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
|
||
|
{
|
||
|
MainWindowViewModel.D_view = false;
|
||
|
}
|
||
|
|
||
|
private void Grid_A_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
|
||
|
{
|
||
|
string ID;
|
||
|
string newValue = (e.EditingElement as TextBox).Text;//获得输入单元格信息
|
||
|
|
||
|
int rownum = Grid_A.SelectedIndex;//获取鼠标选中行并定义变量
|
||
|
if (rownum != -1)//判断鼠标定位是否有效
|
||
|
{
|
||
|
ID = (Grid_A.Columns[0].GetCellContent(Grid_A.Items[rownum]) as TextBlock).Text;//定位第0列,
|
||
|
|
||
|
Dictionary<string, object> datagrid_v = new Dictionary<string, object>();//缓存函数
|
||
|
datagrid_v.Add("PLC", newValue);
|
||
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
||
|
SQLiteHelpers.Open(); //打开数据库
|
||
|
SQLiteHelpers.Update("IOName", datagrid_v, "ID ='" + ID + "'", null);//更新
|
||
|
SQLiteHelpers.Close();//关闭数据库
|
||
|
}
|
||
|
IO_data();//重新获得io表
|
||
|
MainWindowViewModel.A_view = true;
|
||
|
}
|
||
|
|
||
|
private void Grid_A_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
|
||
|
{
|
||
|
MainWindowViewModel.A_view = false;
|
||
|
}
|
||
|
|
||
|
private void IO_data()
|
||
|
{
|
||
|
if (!string.IsNullOrEmpty(machine))
|
||
|
{
|
||
|
DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First();
|
||
|
int State_ = Convert.ToInt16(drEmployee.Field<object>("State"));
|
||
|
int index = Convert.ToInt16(drEmployee.Field<object>("ID"));
|
||
|
if ((State_ == 101) || (State_ == 201) || (State_ == 202) || (State_ == 309))//获得细节信息
|
||
|
{
|
||
|
MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString
|
||
|
{
|
||
|
ID = index,
|
||
|
DAT = "SC851" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index)
|
||
|
});
|
||
|
MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString
|
||
|
{
|
||
|
ID = index,
|
||
|
DAT = "SC852" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index)
|
||
|
});
|
||
|
MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString
|
||
|
{
|
||
|
ID = index,
|
||
|
DAT = "SC853" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index)
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void CountDown()
|
||
|
{
|
||
|
DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick
|
||
|
{
|
||
|
Interval = TimeSpan.FromSeconds(1.5)//秒
|
||
|
};
|
||
|
timer1s.Tick += Tick_Event_1S;
|
||
|
timer1s.Start();
|
||
|
}//时间周期初始化
|
||
|
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
|
||
|
{ IO_data(); }
|
||
|
}
|
||
|
}
|