sc 5 months ago
parent
commit
2ea530d0b6
  1. 3
      View/TechnologicalProcessView.xaml.cs
  2. 207
      ViewModel/CurveDiagramViewModel.cs
  3. 49
      ViewModel/MainWindowViewModel.cs

3
View/TechnologicalProcessView.xaml.cs

@ -295,7 +295,8 @@ namespace DyeingComputer.View
catch (Exception) { } catch (Exception) { }
SQLiteHelpers.Close(); //关闭连接 SQLiteHelpers.Close(); //关闭连接
if (sql != null) dt_TP = sql.Tables[0]; //转换显示计划表 // if (sql != null)
MainWindowViewModel.dt_TP = sql.Tables[0]; //转换显示计划表
} }
private void UserControl_Loaded(object sender, RoutedEventArgs e) private void UserControl_Loaded(object sender, RoutedEventArgs e)

207
ViewModel/CurveDiagramViewModel.cs

@ -21,6 +21,7 @@ using System.Collections.ObjectModel;
using DyeingComputer.Properties; using DyeingComputer.Properties;
using LiveChartsCore.Measure; using LiveChartsCore.Measure;
using LiveChartsCore.Motion; using LiveChartsCore.Motion;
using System.Windows.Documents;
namespace DyeingComputer.ViewModel namespace DyeingComputer.ViewModel
{ {
@ -104,18 +105,18 @@ namespace DyeingComputer.ViewModel
//new AnimatableAxisBounds //new AnimatableAxisBounds
}; };
private readonly Random _r = new Random(); private Random _r = new Random();
private readonly ObservableCollection<DateTimePoint> MTT_values; private List<DateTimePoint> MTT_values;
private readonly ObservableCollection<DateTimePoint> MTL_values; private List<DateTimePoint> MTL_values;
private readonly ObservableCollection<DateTimePoint> MTH_values; private List<DateTimePoint> MTH_values;
private readonly ObservableCollection<DateTimePoint> MST_values; private List<DateTimePoint> MST_values;
private readonly ObservableCollection<DateTimePoint> MUT_values; private List<DateTimePoint> MUT_values;
private readonly ObservableCollection<DateTimePoint> STTA_values; private List<DateTimePoint> STTA_values;
private readonly ObservableCollection<DateTimePoint> STLA_values; private List<DateTimePoint> STLA_values;
private readonly ObservableCollection<DateTimePoint> STTB_values; private List<DateTimePoint> STTB_values;
private readonly ObservableCollection<DateTimePoint> STLB_values; private List<DateTimePoint> STLB_values;
private readonly ObservableCollection<DateTimePoint> STTC_values; private List<DateTimePoint> STTC_values;
private readonly ObservableCollection<DateTimePoint> STLC_values; private List<DateTimePoint> STLC_values;
private SQLiteHelper SQLiteHelpers = null; //定义数据库 private SQLiteHelper SQLiteHelpers = null; //定义数据库
private readonly string ChartAdress = Environment.CurrentDirectory + "\\DataBase\\Chart.db"; //数据库路径 private readonly string ChartAdress = Environment.CurrentDirectory + "\\DataBase\\Chart.db"; //数据库路径
@ -168,25 +169,25 @@ namespace DyeingComputer.ViewModel
} }
} }
MTT_values = new ObservableCollection<DateTimePoint>(MTT_items); MTT_values = new List<DateTimePoint>(MTT_items);
MTL_values = new ObservableCollection<DateTimePoint>(MTL_items); MTL_values = new List<DateTimePoint>(MTL_items);
MTH_values = new ObservableCollection<DateTimePoint>(MTH_items); MTH_values = new List<DateTimePoint>(MTH_items);
MST_values = new ObservableCollection<DateTimePoint>(MST_items); MST_values = new List<DateTimePoint>(MST_items);
MUT_values = new ObservableCollection<DateTimePoint>(MUT_items); MUT_values = new List<DateTimePoint>(MUT_items);
if (MainWindowViewModel.SM01 == 1) if (MainWindowViewModel.SM01 == 1)
{ {
STTA_values = new ObservableCollection<DateTimePoint>(STTA_items); STTA_values = new List<DateTimePoint>(STTA_items);
STLA_values = new ObservableCollection<DateTimePoint>(STLA_items); STLA_values = new List<DateTimePoint>(STLA_items);
} }
if (MainWindowViewModel.SM02 == 1) if (MainWindowViewModel.SM02 == 1)
{ {
STTB_values = new ObservableCollection<DateTimePoint>(STTB_items); STTB_values = new List<DateTimePoint>(STTB_items);
STLB_values = new ObservableCollection<DateTimePoint>(STLB_items); STLB_values = new List<DateTimePoint>(STLB_items);
} }
if (MainWindowViewModel.SM03 == 1) if (MainWindowViewModel.SM03 == 1)
{ {
STTC_values = new ObservableCollection<DateTimePoint>(STTC_items); STTC_values = new List<DateTimePoint>(STTC_items);
STLC_values = new ObservableCollection<DateTimePoint>(STLC_items); STLC_values = new List<DateTimePoint>(STLC_items);
} }
Series = new ISeries[] Series = new ISeries[]
{ {
@ -223,7 +224,7 @@ namespace DyeingComputer.ViewModel
LineSmoothness = 0, LineSmoothness = 0,
ScalesYAt = 0, ScalesYAt = 0,
}, //主缸 }, //主缸
new LineSeries<DateTimePoint> /*new LineSeries<DateTimePoint>
{ {
Name = Properties.Resources.Temperature +"2("+Properties.Resources.MasterCylinder+Properties.Resources.Bottom+")", Name = Properties.Resources.Temperature +"2("+Properties.Resources.MasterCylinder+Properties.Resources.Bottom+")",
Values = MUT_values, Values = MUT_values,
@ -233,86 +234,86 @@ namespace DyeingComputer.ViewModel
Fill = null, Fill = null,
LineSmoothness = 0, LineSmoothness = 0,
ScalesYAt = 0, ScalesYAt = 0,
}, //缸底 }, */ //缸底
new LineSeries<DateTimePoint>
{
Name = Properties.Resources.Temperature +"3("+Resources.Medicine + Resources.Tank +"1)",
Values = STTA_values,
Stroke = new SolidColorPaint(s_blue_1, 2),
GeometrySize = 0,
GeometryStroke = new SolidColorPaint(s_blue_1, 2),
Fill = null,
LineSmoothness = 0,
ScalesYAt = 0,
}, //附缸1
new LineSeries<DateTimePoint> new LineSeries<DateTimePoint>
{ {
Name = Properties.Resources.Temperature +"4("+Resources.Medicine + Resources.Tank +"2)", Name = Properties.Resources.Temperature +"3("+Resources.Medicine + Resources.Tank +"1)",
Values = STTB_values, Values = STTA_values,
Stroke = new SolidColorPaint(s_blue_2, 2), Stroke = new SolidColorPaint(s_blue_1, 2),
GeometrySize = 0, GeometrySize = 0,
GeometryStroke = new SolidColorPaint(s_blue_2, 2), GeometryStroke = new SolidColorPaint(s_blue_1, 2),
Fill = null, Fill = null,
LineSmoothness = 0, LineSmoothness = 0,
ScalesYAt = 0, ScalesYAt = 0,
}, //附缸2 }, //附缸1
new LineSeries<DateTimePoint> new LineSeries<DateTimePoint>
{ {
Name = Properties.Resources.Temperature +"5("+Resources.Medicine + Resources.Tank +"3)", Name = Properties.Resources.Temperature +"4("+Resources.Medicine + Resources.Tank +"2)",
Values = STTC_values, Values = STTB_values,
Stroke = new SolidColorPaint(s_blue_3, 2), Stroke = new SolidColorPaint(s_blue_2, 2),
GeometrySize = 0, GeometrySize = 0,
GeometryStroke = new SolidColorPaint(s_blue_3, 2), GeometryStroke = new SolidColorPaint(s_blue_2, 2),
Fill = null, Fill = null,
LineSmoothness = 0, LineSmoothness = 0,
ScalesYAt = 0, ScalesYAt = 0,
}, //附缸3 }, //附缸2
new LineSeries<DateTimePoint> new LineSeries<DateTimePoint>
{ {
Name = Properties.Resources.WaterLevel +"("+Properties.Resources.MasterCylinder+")", Name = Properties.Resources.Temperature +"5("+Resources.Medicine + Resources.Tank +"3)",
Values = MTL_values, Values = STTC_values,
Stroke = new SolidColorPaint(s_red, 2), Stroke = new SolidColorPaint(s_blue_3, 2),
GeometrySize = 0, GeometrySize = 0,
GeometryStroke = new SolidColorPaint(s_red, 2), GeometryStroke = new SolidColorPaint(s_blue_3, 2),
Fill = null, Fill = null,
LineSmoothness = 0, LineSmoothness = 0,
ScalesYAt = 1, ScalesYAt = 0,
}, //主缸液位 }, //附缸3
new LineSeries<DateTimePoint> new LineSeries<DateTimePoint>
{ {
Name = Properties.Resources.WaterLevel +"("+Resources.Medicine + Resources.Tank +"1)", Name = Properties.Resources.WaterLevel +"("+Properties.Resources.MasterCylinder+")",
Values = STLA_values, Values = MTL_values,
Stroke = new SolidColorPaint(s_red_1, 2), Stroke = new SolidColorPaint(s_red, 2),
GeometrySize = 0, GeometrySize = 0,
GeometryStroke = new SolidColorPaint(s_red_1, 2), GeometryStroke = new SolidColorPaint(s_red, 2),
Fill = null, Fill = null,
LineSmoothness = 0, LineSmoothness = 0,
ScalesYAt = 1, ScalesYAt = 1,
}, //附缸1液位 }, //主缸液位
new LineSeries<DateTimePoint> new LineSeries<DateTimePoint>
{ {
Name = Properties.Resources.WaterLevel +"("+Resources.Medicine + Resources.Tank +"2)", Name = Properties.Resources.WaterLevel +"("+Resources.Medicine + Resources.Tank +"1)",
Values = STLB_values, Values = STLA_values,
Stroke = new SolidColorPaint(s_red_2, 2), Stroke = new SolidColorPaint(s_red_1, 2),
GeometrySize = 0, GeometrySize = 0,
GeometryStroke = new SolidColorPaint(s_red_2, 2), GeometryStroke = new SolidColorPaint(s_red_1, 2),
Fill = null, Fill = null,
LineSmoothness = 0, LineSmoothness = 0,
ScalesYAt = 1, ScalesYAt = 1,
}, //附缸2液位 }, //附缸1液位
new LineSeries<DateTimePoint> new LineSeries<DateTimePoint>
{ {
Name = Properties.Resources.WaterLevel +"("+Resources.Medicine + Resources.Tank +"3)", Name = Properties.Resources.WaterLevel +"("+Resources.Medicine + Resources.Tank +"2)",
Values = STLC_values, Values = STLB_values,
Stroke = new SolidColorPaint(s_red_3, 2), Stroke = new SolidColorPaint(s_red_2, 2),
GeometrySize = 0, GeometrySize = 0,
GeometryStroke = new SolidColorPaint(s_red_3, 2), GeometryStroke = new SolidColorPaint(s_red_2, 2),
Fill = null, Fill = null,
LineSmoothness = 0, LineSmoothness = 0,
ScalesYAt = 1, ScalesYAt = 1,
}, //附缸3 液位 }, //附缸2液位
new LineSeries<DateTimePoint>
{
Name = Properties.Resources.WaterLevel +"("+Resources.Medicine + Resources.Tank +"3)",
Values = STLC_values,
Stroke = new SolidColorPaint(s_red_3, 2),
GeometrySize = 0,
GeometryStroke = new SolidColorPaint(s_red_3, 2),
Fill = null,
LineSmoothness = 0,
ScalesYAt = 1,
}, //附缸3液位
}; };
} }
} }
} }
} }

49
ViewModel/MainWindowViewModel.cs

@ -81,14 +81,54 @@ namespace DyeingComputer.ViewModel
SQL_data(); //读数据库 SQL_data(); //读数据库
UPort(); //启动串口 UPort(); //启动串口
CountDown(); //启动循环任务 CountDown(); //启动循环任务
dt_a.RowChanged += Dt_a_rowchanged;//添加行更新事件
dt_d.RowChanged += Dt_d_rowchanged;
dt_m.RowChanged += Dt_m_rowchanged;
dt_TP.RowChanged += Dt_tp_rowchanged;
dt_TP.RowDeleted += Dt_tp_rowchanged;
IO_view();
_ = AsyncTcpServer.Main(); _ = AsyncTcpServer.Main();
IsInteractive = false; IsInteractive = false;
UserButton = false; UserButton = false;
ProgramgroupView_run = new RelayCommand( ProgramgroupView_run = new RelayCommand(
execute:ProgramgroupView_run_ );//开始/暂停事件 execute:ProgramgroupView_run_ );//开始/暂停事件
} }
private void Dt_tp_rowchanged(object sender, DataRowChangeEventArgs e)
{
try
{
TechnologicalProcess_View = ToObservableCollection<TechnologicalProcess>(dt_TP);
}
catch (Exception) { }
}//工艺步骤表更新事件
private void Dt_a_rowchanged(object sender,DataRowChangeEventArgs e)
{
try
{
if ((bool)A_view) SYSData_A = ToObservableCollection<DATA_A>(dt_a);
}
catch (Exception ex) { Name_err = "IO_SYSData_A" + "(" + ex.Message + ")"; }
}//aio表更新事件
private void Dt_d_rowchanged(object sender, DataRowChangeEventArgs e)
{
try
{
if ((bool)D_view) SYSData_D = ToObservableCollection<DATA_D>(dt_d);
}
catch (Exception ex) { Name_err = "IO_SYSData_D" + "(" + ex.Message + ")"; }
}//dio表更新事件
private void Dt_m_rowchanged(object sender, DataRowChangeEventArgs e)
{
try
{
SYSData_M = ToObservableCollection<DATA_M>(dt_m);
}
catch (Exception ex) { Name_err = "IO_SYSData_M" + "(" + ex.Message + ")"; }
}//寄存器表更新事件
DataTable dt_con = new DataTable(); DataTable dt_con = new DataTable();
DataTable dt_sys = new DataTable(); DataTable dt_sys = new DataTable();
public string Selet_con(string key)//配置缓存 public string Selet_con(string key)//配置缓存
@ -317,7 +357,6 @@ namespace DyeingComputer.ViewModel
STEP_RUN(); STEP_RUN();
LOG_view(); LOG_view();
IO_view();
if (!string.IsNullOrEmpty(Name_err.ToString())) if (!string.IsNullOrEmpty(Name_err.ToString()))
{ {
@ -1697,7 +1736,7 @@ namespace DyeingComputer.ViewModel
public static object D_view=true; public static object D_view=true;
public static object A_view=true; public static object A_view=true;
private async void IO_view()//IO显示 public async void IO_view()//IO显示
{ {
await Task.Run(() => await Task.Run(() =>
{ {
@ -1706,13 +1745,13 @@ namespace DyeingComputer.ViewModel
SYSData_M = ToObservableCollection<DATA_M>(dt_m); SYSData_M = ToObservableCollection<DATA_M>(dt_m);
} }
catch (Exception ex) { Name_err = "IO_SYSData_M" + "(" + ex.Message + ")"; } catch (Exception ex) { Name_err = "IO_SYSData_M" + "(" + ex.Message + ")"; }
try try
{ {
if ((bool)A_view) SYSData_A = ToObservableCollection<DATA_A>(dt_a); if ((bool)A_view) SYSData_A = ToObservableCollection<DATA_A>(dt_a);
} }
catch (Exception ex) { Name_err = "IO_SYSData_A" + "(" + ex.Message + ")"; } catch (Exception ex) { Name_err = "IO_SYSData_A" + "(" + ex.Message + ")"; }
try try
{ {
if ((bool)D_view) SYSData_D = ToObservableCollection<DATA_D>(dt_d); if ((bool)D_view) SYSData_D = ToObservableCollection<DATA_D>(dt_d);

Loading…
Cancel
Save