Browse Source

修改io表查改逻辑,降低i资源开销60=>10

master
sc 1 year ago
parent
commit
2db3bfd186
  1. 10
      MainWindow.xaml.cs
  2. 2
      View/TechnologicalProcessView.xaml
  3. 8
      View/TechnologicalProcessView.xaml.cs
  4. 1
      View/WorkOrderView.xaml.cs
  5. 152
      ViewModel/MainWindowViewModel.cs

10
MainWindow.xaml.cs

@ -124,33 +124,43 @@ namespace DyeingComputer
{ {
case "Work_Order": case "Work_Order":
container.Content = new WorkOrderView(); container.Content = new WorkOrderView();
MainWindowViewModel.ViewID = 0;
break; break;
case "Technological_Process": case "Technological_Process":
container.Content = new TechnologicalProcessView(); container.Content = new TechnologicalProcessView();
MainWindowViewModel.ViewID = 1;
break; break;
case "Curve_Diagram": case "Curve_Diagram":
container.Content = new CurveDiagramView(); container.Content = new CurveDiagramView();
MainWindowViewModel.ViewID = 2;
break; break;
case "Equipment_Simulation": case "Equipment_Simulation":
container.Content = new EquipmentSimulationView(); container.Content = new EquipmentSimulationView();
MainWindowViewModel.ViewID = 3;
break; break;
case "History_Records": case "History_Records":
container.Content = new HistoryRecordsView(); container.Content = new HistoryRecordsView();
MainWindowViewModel.ViewID = 4;
break; break;
case "In_Out": case "In_Out":
container.Content = new InOutView(); container.Content = new InOutView();
MainWindowViewModel.ViewID = 5;
break; break;
case "Sys_Set": case "Sys_Set":
container.Content = new SysSetView(); container.Content = new SysSetView();
MainWindowViewModel.ViewID = 6;
break; break;
case "Parameter_Set": case "Parameter_Set":
container.Content = new ParameterSetView(); container.Content = new ParameterSetView();
MainWindowViewModel.ViewID = 7;
break; break;
case "Program_group": case "Program_group":
container.Content = new ProgramgroupView(); container.Content = new ProgramgroupView();
MainWindowViewModel.ViewID = 8;
break; break;
case "Engineer_Set": case "Engineer_Set":
container.Content = new EngineerSetView(); container.Content = new EngineerSetView();
MainWindowViewModel.ViewID = 9;
break; break;
default: default:
break; break;

2
View/TechnologicalProcessView.xaml

@ -14,7 +14,7 @@
HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="Black" HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="Black"
BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2" AllowDrop="False" BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2" AllowDrop="False"
CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" CanUserResizeColumns="False" CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" CanUserResizeColumns="False"
CanUserAddRows="True" CanUserDeleteRows="False" HeadersVisibility ="Column" CanUserAddRows="True" CanUserDeleteRows="False" HeadersVisibility ="Column" SelectedIndex="{Binding Sys_workSTEPID}"
Background="White" SelectionMode="Single" FontSize="15" MinHeight="632" TabIndex="1" Focusable="True"> Background="White" SelectionMode="Single" FontSize="15" MinHeight="632" TabIndex="1" Focusable="True">
<DataGrid.RowStyle > <DataGrid.RowStyle >
<Style TargetType="{x:Type DataGridRow}"> <Style TargetType="{x:Type DataGridRow}">

8
View/TechnologicalProcessView.xaml.cs

@ -28,8 +28,9 @@ namespace DyeingComputer.View
public partial class TechnologicalProcessView : UserControl public partial class TechnologicalProcessView : UserControl
{ {
public TechnologicalProcessView() public TechnologicalProcessView()
{ {
InitializeComponent(); InitializeComponent();
DataContext = new MainWindowViewModel();
FocusManager.SetFocusedElement(Grid, Grid); FocusManager.SetFocusedElement(Grid, Grid);
if (workName != null) if (workName != null)
{ {
@ -38,7 +39,7 @@ namespace DyeingComputer.View
else else
{ {
TechnologicalProcess_sql(); TechnologicalProcess_sql();
} }
} }
public static object workName; public static object workName;
@ -94,7 +95,8 @@ namespace DyeingComputer.View
private void UserControl_Loaded(object sender, RoutedEventArgs e) private void UserControl_Loaded(object sender, RoutedEventArgs e)
{ {
// FocusManager.SetFocusedElement(Grid, Grid); // FocusManager.SetFocusedElement(Grid, Grid);
// Grid.DataContext = new MainWindowViewModel();
if (workName != null) if (workName != null)
{ {
Grid.SelectedIndex = 0; Grid.SelectedIndex = 0;

1
View/WorkOrderView.xaml.cs

@ -206,6 +206,7 @@ namespace DyeingComputer.View
MainWindowViewModel.WorkNumder = WorkOrder_Numder; MainWindowViewModel.WorkNumder = WorkOrder_Numder;
TechnologicalProcessView.workName = Process_id; TechnologicalProcessView.workName = Process_id;
MainWindowViewModel.ViewID = 1;
var _mainWindow = Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is MainWindow) as MainWindow;//跨页面 var _mainWindow = Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is MainWindow) as MainWindow;//跨页面
_mainWindow.container.Content = new TechnologicalProcessView();//获取控件 _mainWindow.container.Content = new TechnologicalProcessView();//获取控件
} }

152
ViewModel/MainWindowViewModel.cs

@ -24,6 +24,7 @@ using DyeingComputer.Properties;
using Microsoft.Win32; using Microsoft.Win32;
using static DyeingComputer.Windows.ViewStep; using static DyeingComputer.Windows.ViewStep;
using System.Windows.Media; using System.Windows.Media;
using System.Runtime.Remoting.Channels;
namespace DyeingComputer.ViewModel namespace DyeingComputer.ViewModel
@ -36,14 +37,17 @@ namespace DyeingComputer.ViewModel
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName) protected virtual void OnPropertyChanged(string propertyName)
{ {
if (this.PropertyChanged != null) if (PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
} }
public void RaisePropertyChanged(string propertyName) public void RaisePropertyChanged(string propertyName)
{ {
if (propertyName != null) if (PropertyChanged != null)
{ {
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); if (propertyName != null)
{
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
} }
} }
} }
@ -59,6 +63,7 @@ namespace DyeingComputer.ViewModel
public MainWindowViewModel() public MainWindowViewModel()
{ {
Sys_workSTEPID = -1;
WorkNumder = "----------"; WorkNumder = "----------";
SYS_SET(); //crbl SYS_SET(); //crbl
CountDown(); //启动循环任务 CountDown(); //启动循环任务
@ -132,6 +137,19 @@ namespace DyeingComputer.ViewModel
get { return sys_Time; } get { return sys_Time; }
set { sys_Time = value; OnPropertyChanged("Sys_Time"); } set { sys_Time = value; OnPropertyChanged("Sys_Time"); }
} }
public int sys_workSTEPID; //
public int Sys_workSTEPID //通知UI控件参数改变
{
get { return sys_workSTEPID; }
set { sys_workSTEPID = value; OnPropertyChanged("Sys_workSTEPID"); }
}
public static int ViewID = 0;//页面id
public static object Name_err = "";
public static object WorkNumder;
public static object Process_step;
public static Int32 DIDETime; //空闲计时器
bool ERR_JOG;//故障状态
public void CountDown() public void CountDown()
{ {
DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick
@ -156,12 +174,6 @@ namespace DyeingComputer.ViewModel
disTimer.Tick += new EventHandler(DisTimer_500MS);//每一秒执行的方法 disTimer.Tick += new EventHandler(DisTimer_500MS);//每一秒执行的方法
disTimer.Start();//计时开始 disTimer.Start();//计时开始
}//时间周期初始化 }//时间周期初始化
public static object Name_err = "";
public static object WorkNumder;
public static object Process_step;
public static Int32 DIDETime; //空闲计时器
bool ERR_JOG;//故障状态
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
{ {
Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
@ -789,6 +801,8 @@ namespace DyeingComputer.ViewModel
double T_P5 = Convert.ToDouble(arrRows[0]["Parameter5"].ToString()); double T_P5 = Convert.ToDouble(arrRows[0]["Parameter5"].ToString());
STEP_START(T_ID,T_P1,T_P2,T_P3,T_P4,T_P5); STEP_START(T_ID,T_P1,T_P2,T_P3,T_P4,T_P5);
if (ViewID == 1) { sys_workSTEPID = RUN_STEPID; } else { sys_workSTEPID = -1; }
} }
if (string.IsNullOrEmpty(Name_err.ToString())) if (string.IsNullOrEmpty(Name_err.ToString()))
@ -892,6 +906,15 @@ namespace DyeingComputer.ViewModel
dt_a = SQLiteHelpers.ExecuteDataSet("select * from IOName where type='AI' OR type='AO'", null).Tables[0]; dt_a = SQLiteHelpers.ExecuteDataSet("select * from IOName where type='AI' OR type='AO'", null).Tables[0];
dt_m = SQLiteHelpers.ExecuteDataSet("select * from IOName where type='M'", null).Tables[0]; dt_m = SQLiteHelpers.ExecuteDataSet("select * from IOName where type='M'", null).Tables[0];
SQLiteHelpers.Close(); SQLiteHelpers.Close();
//创建dt_d主建
DataColumn[] dt_dcols =new DataColumn[] { dt_d.Columns["ID"] };
dt_d.PrimaryKey = dt_dcols;
//创建dt_a主建
DataColumn[] dt_acols = new DataColumn[] { dt_a.Columns["ID"] };
dt_a.PrimaryKey = dt_acols;
//创建dt_m主建
DataColumn[] dt_mcols = new DataColumn[] { dt_m.Columns["ID"] };
dt_m.PrimaryKey = dt_mcols;
} }
private async void IO_data()//刷新 private async void IO_data()//刷新
@ -925,9 +948,14 @@ namespace DyeingComputer.ViewModel
{ {
try try
{ {
DataRow[] arrRows = dt_m.Select("ID='" + key+"'"); lock (dt_m)
double index = Convert.ToDouble(arrRows[0]["Value"].ToString()); {
return index; // DataRow[] arrRows = dt_m.Select("ID='" + key + "'");
// double index = Convert.ToDouble(arrRows[0]["Value"].ToString());
DataRow drEmployee = dt_m.Rows.Find(key);
double index = drEmployee.Field<double>("value");
return index;
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -939,9 +967,14 @@ namespace DyeingComputer.ViewModel
{ {
try try
{ {
DataRow[] arrRows = dt_d.Select("ID='" + key + "'"); lock (dt_d)
bool index = Convert.ToBoolean(arrRows[0]["DIO"].ToString()); {
return index; // DataRow[] arrRows = dt_d.Select("ID='" + key + "'");
// bool index = Convert.ToBoolean(arrRows[0]["DIO"].ToString());
DataRow drEmployee = dt_d.Rows.Find(key);
bool index = drEmployee.Field<bool>("DIO");
return index;
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -953,9 +986,14 @@ namespace DyeingComputer.ViewModel
{ {
try try
{ {
DataRow[] arrRows = dt_a.Select("ID='" + key + "'"); lock (dt_a)
int index = Convert.ToInt16(arrRows[0]["AIO"].ToString()); {
return index; // DataRow[] arrRows = dt_a.Select("ID='" + key + "'");
// int index = Convert.ToInt16(arrRows[0]["AIO"].ToString());
DataRow drEmployee = dt_a.Rows.Find(key);
int index = drEmployee.Field<int>("AIO");
return index;
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -969,15 +1007,21 @@ namespace DyeingComputer.ViewModel
{ {
lock (dt_m) lock (dt_m)
{ {
DataRow[] arrRows = dt_m.Select("ID='" + key + "'"); /* DataRow[] arrRows = dt_m.Select("ID='" + key + "'");
int index = dt_m.Rows.IndexOf(arrRows[0]); int index = dt_m.Rows.IndexOf(arrRows[0]);
if (index != -1) if (index != -1)
{ {
DataRow drEmployee = dt_m.Rows[index]; DataRow drEmployee = dt_m.Rows[index];
drEmployee.BeginEdit(); drEmployee.BeginEdit();
drEmployee["Value"] = Value; drEmployee["Value"] = Value;
drEmployee.EndEdit(); drEmployee.EndEdit();
} }*/
DataRow drEmployee = dt_m.Rows.Find(key);
drEmployee.BeginEdit();
drEmployee["Value"] = Value;
drEmployee.EndEdit();
drEmployee.AcceptChanges();
drEmployee.ClearErrors();
} }
} }
catch (Exception ex) catch (Exception ex)
@ -992,17 +1036,23 @@ namespace DyeingComputer.ViewModel
{ {
lock (dt_d)//锁 lock (dt_d)//锁
{ {
DataRow[] arrRows = dt_d.Select("ID='" + key + "'"); /* DataRow[] arrRows = dt_d.Rows.Find(key); //dt_d.Select("ID='" + key + "'");
int index = dt_d.Rows.IndexOf(arrRows[0]); int index = dt_d.Rows.IndexOf(arrRows[0]);
if (index != -1) if (index != -1)
{ {
DataRow drEmployee = dt_d.Rows[index]; DataRow drEmployee = dt_d.Rows[index];
drEmployee.BeginEdit(); drEmployee.BeginEdit();
drEmployee["DIO"] = Value; drEmployee["DIO"] = Value;
drEmployee.EndEdit(); drEmployee.EndEdit();
drEmployee.AcceptChanges(); drEmployee.AcceptChanges();
drEmployee.ClearErrors(); drEmployee.ClearErrors();
} }*/
DataRow drEmployee = dt_d.Rows.Find(key);
drEmployee.BeginEdit();
drEmployee["DIO"] = Value;
drEmployee.EndEdit();
drEmployee.AcceptChanges();
drEmployee.ClearErrors();
} }
} }
catch (Exception ex) catch (Exception ex)
@ -1016,15 +1066,21 @@ namespace DyeingComputer.ViewModel
{ {
lock (dt_a) lock (dt_a)
{ {
DataRow[] arrRows = dt_a.Select("ID='" + key + "'"); /* DataRow[] arrRows = dt_a.Select("ID='" + key + "'");
int index = dt_a.Rows.IndexOf(arrRows[0]); int index = dt_a.Rows.IndexOf(arrRows[0]);
if (index != -1) if (index != -1)
{ {
DataRow drEmployee = dt_a.Rows[index]; DataRow drEmployee = dt_a.Rows[index];
drEmployee.BeginEdit(); drEmployee.BeginEdit();
drEmployee["AIO"] = Value; drEmployee["AIO"] = Value;
drEmployee.EndEdit(); drEmployee.EndEdit();
} }*/
DataRow drEmployee = dt_a.Rows.Find(key);
drEmployee.BeginEdit();
drEmployee["AIO"] = Value;
drEmployee.EndEdit();
drEmployee.AcceptChanges();
drEmployee.ClearErrors();
} }
} }
catch (Exception ex) catch (Exception ex)

Loading…
Cancel
Save