diff --git a/ConvertMoels/BoolRBConvert.cs b/ConvertMoels/BoolRBConvert.cs
new file mode 100644
index 0000000..287c42f
--- /dev/null
+++ b/ConvertMoels/BoolRBConvert.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+
+namespace DyeingComputer.ConvertMoels
+{
+ internal class BoolRBConvert : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ String G = value.ToString();
+ // bool G = (bool)value;
+ if (G == "False")//判断单元格值是否为零
+ {
+ return "white";//零返回
+ }
+ else
+ {
+ return "red";//非零返回红色
+ }
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return null;
+ }
+ }
+}
diff --git a/DyeingComputer.csproj b/DyeingComputer.csproj
index e9360dc..52e1e76 100644
--- a/DyeingComputer.csproj
+++ b/DyeingComputer.csproj
@@ -62,6 +62,7 @@
MSBuild:Compile
Designer
+
@@ -303,6 +304,9 @@
8.0.0
+
+ 3.0.81
+
5.0.37
diff --git a/View/InOutView.xaml b/View/InOutView.xaml
index a3393ff..3c08dfe 100644
--- a/View/InOutView.xaml
+++ b/View/InOutView.xaml
@@ -3,10 +3,152 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:local="clr-namespace:DyeingComputer.View"
- mc:Ignorable="d"
+ xmlns:local="clr-namespace:DyeingComputer.View"
+ xmlns:lang="clr-namespace:DyeingComputer.Properties"
+ xmlns:ConvertMoels="clr-namespace:DyeingComputer.ConvertMoels"
+ xmlns:viewmodel="clr-namespace:DyeingComputer.ViewModel"
+ mc:Ignorable="d" d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}"
d:DesignHeight="630" d:DesignWidth="1280" VerticalAlignment="Top">
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/View/InOutView.xaml.cs b/View/InOutView.xaml.cs
index 1ee17b8..eddba62 100644
--- a/View/InOutView.xaml.cs
+++ b/View/InOutView.xaml.cs
@@ -1,4 +1,5 @@
-using System;
+using DyeingComputer.ViewModel;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -24,5 +25,20 @@ namespace DyeingComputer.View
{
InitializeComponent();
}
+
+ 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)
+ {
+
+ }
}
}
diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs
index d1a1a34..2e6a93b 100644
--- a/ViewModel/MainWindowViewModel.cs
+++ b/ViewModel/MainWindowViewModel.cs
@@ -7,6 +7,15 @@ using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommonServiceLocator;
using System.Windows.Threading;
+using static DyeingComputer.UserClass.SqliteHelper;
+using System.Data;
+using System.Collections.ObjectModel;
+using DyeingComputer.View;
+using System.Windows;
+using DyeingComputer.UserClass;
+using System.Reflection;
+using System.Windows.Documents;
+using System.Runtime.CompilerServices;
namespace DyeingComputer.ViewModel
{
@@ -22,14 +31,24 @@ namespace DyeingComputer.ViewModel
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
+
+ public void RaisePropertyChanged(string propertyName)
+ {
+ if (propertyName != null)
+ {
+ PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+
}
- public class MainWindowViewModel: ViewModelBase
+ public class MainWindowViewModel : ViewModelBase
{
- public MainWindowViewModel()
+ public MainWindowViewModel()
{
WorkNumder = "----------";
CountDown();
+ SQL_data();
}
public string work_Temp; //显示温度
@@ -64,24 +83,193 @@ namespace DyeingComputer.ViewModel
{
DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每0.5秒调用一次Tick
{
- Interval = TimeSpan.FromSeconds(1)
+ Interval = TimeSpan.FromSeconds(0.5)//秒
};
timer1s.Tick += Tick_Event_1S;
timer1s.Start();
//设置定时器
- // disTimer.Tick += new EventHandler(DisTimer_Tick);//每一秒执行的方法
- // disTimer.Interval = new TimeSpan(10000000); //时间间隔为一秒。
- // disTimer.Start();//计时开始
+ DispatcherTimer disTimer = new DispatcherTimer
+ {
+ Interval = TimeSpan.FromMilliseconds(100) //毫秒
+ };
+ disTimer.Tick += new EventHandler(DisTimer_Tick);//每一秒执行的方法
+ disTimer.Start();//计时开始
}
public static object WorkNumder;
+ int lk;
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件
{
Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
- Work_Temp = "130"+" ℃";
+ Work_Temp = "130" + " ℃";
Work_Numder = WorkNumder.ToString();
Status_Str = "qweqeqwqqfwfqef";
+
+ IO_data();
+ }
+ void DisTimer_Tick(object sender, EventArgs e)//Tick_Event周期执行事件
+ {
+ lk++;
+ }
+
+ private SQLiteHelper SQLiteHelpers = null; //定义数据库
+ private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
+ DataTable dt_d = new DataTable("DIO");
+ DataTable dt_a = new DataTable("AIO");
+ DataTable dt_m = new DataTable("M");
+
+ void SQL_data()//获得io表
+ {
+ SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
+ SQLiteHelpers.Open(); //打开数据库
+ dt_d = SQLiteHelpers.ExecuteDataSet("select * from IOName where type='DI' OR type='DO'", 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];
+ SQLiteHelpers.Close();
+
+ }
+
+
+ void IO_data()//刷新
+ {
+ updata_dtm("1", lk);
+ updata_dtd("1", Convert.ToBoolean(1));
+ updata_dta("1",10000+lk);
+
+
+ SYSData_A = ToObservableCollection(dt_a);
+ SYSData_D = ToObservableCollection(dt_d);
+ SYSData_M = ToObservableCollection(dt_m);
+ }
+
+
+ void updata_dtm(string key,int Value)//更新M寄存器
+ {
+ DataRow[] arrRows = dt_m.Select("ID="+key);
+ int index = dt_m.Rows.IndexOf(arrRows[0]);
+ DataRow drEmployee = dt_m.Rows[index];
+ drEmployee.BeginEdit();
+ drEmployee["Value"] = Value;
+ drEmployee.EndEdit();
+ }
+ void updata_dtd(string key, bool Value)//更新D寄存器
+ {
+ DataRow[] arrRows = dt_d.Select("ID=" + key);
+ int index = dt_d.Rows.IndexOf(arrRows[0]);
+ DataRow drEmployee = dt_d.Rows[index];
+ drEmployee.BeginEdit();
+ drEmployee["DIO"] = Value;
+ drEmployee.EndEdit();
+ }
+ void updata_dta(string key, int Value)//更新A寄存器
+ {
+ DataRow[] arrRows = dt_a.Select("ID=" + key);
+ int index = dt_a.Rows.IndexOf(arrRows[0]);
+ DataRow drEmployee = dt_a.Rows[index];
+ drEmployee.BeginEdit();
+ drEmployee["AIO"] = Value;
+ drEmployee.EndEdit();
+ }
+
+ ObservableCollection sysData_A = new ObservableCollection();
+ ObservableCollection sysData_D = new ObservableCollection();
+ ObservableCollection sysData_M = new ObservableCollection();
+ public ObservableCollection SYSData_A
+ {
+
+ get { return sysData_A; }
+ set
+ {
+ sysData_A = value;
+ RaisePropertyChanged("SYSData_A");
+ }
+ }
+ public ObservableCollection SYSData_D
+ {
+
+ get { return sysData_D; }
+ set
+ {
+ sysData_D = value;
+ RaisePropertyChanged("SYSData_D");
+ }
+ }
+ public ObservableCollection SYSData_M
+ {
+
+ get { return sysData_M; }
+ set
+ {
+ sysData_M = value;
+ RaisePropertyChanged("SYSData_M");
+ }
+ }
+ public class DATA_A
+ {
+ public string IOName { get; set; }
+ public int AIO { get; set; }
+ public String ID { get; set; }
+ }
+ public class DATA_D
+ {
+ public string IOName { get; set; }
+ public bool DIO { get; set; }
+ public String ID { get; set; }
}
+ public class DATA_M
+ {
+ public string IOName { get; set; }
+ public int Value { get; set; }
+ public String ID { get; set; }
+ }
+ public ObservableCollection ToObservableCollection(DataTable dt) where T : class, new()
+ {
+ Type t = typeof(T);
+ PropertyInfo[] propertys = t.GetProperties();
+ ObservableCollection lst = new ObservableCollection();
+ string typeName = string.Empty;
+ foreach (DataRow dr in dt.Rows)
+ {
+ T entity = new T();
+ foreach (PropertyInfo pi in propertys)
+ {
+ typeName = pi.Name;
+ if (dt.Columns.Contains(typeName))
+ {
+ if (!pi.CanWrite) continue;
+ object value = dr[typeName];
+ if (value == DBNull.Value) continue;
+ if (pi.PropertyType == typeof(string))
+ {
+ pi.SetValue(entity, value.ToString(), null);
+ }
+ else if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(int?))
+ {
+ pi.SetValue(entity, int.Parse(value.ToString()), null);
+ }
+ else if (pi.PropertyType == typeof(DateTime?) || pi.PropertyType == typeof(DateTime))
+ {
+ pi.SetValue(entity, DateTime.Parse(value.ToString()), null);
+ }
+ else if (pi.PropertyType == typeof(float))
+ {
+ pi.SetValue(entity, float.Parse(value.ToString()), null);
+ }
+ else if (pi.PropertyType == typeof(double))
+ {
+ pi.SetValue(entity, double.Parse(value.ToString()), null);
+ }
+ else
+ {
+ pi.SetValue(entity, value, null);
+ }
+ }
+ }
+ lst.Add(entity);
+ }
+ return lst;
+ }
+
}
-}
+}
\ No newline at end of file