io页面功能
This commit is contained in:
commit
30cf155f5b
5 files changed
+394
-12
No files matched your search
@@ -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<DATA_A>(dt_a);
|
||||
SYSData_D = ToObservableCollection<DATA_D>(dt_d);
|
||||
SYSData_M = ToObservableCollection<DATA_M>(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<DATA_A> sysData_A = new ObservableCollection<DATA_A>();
|
||||
ObservableCollection<DATA_D> sysData_D = new ObservableCollection<DATA_D>();
|
||||
ObservableCollection<DATA_M> sysData_M = new ObservableCollection<DATA_M>();
|
||||
public ObservableCollection<DATA_A> SYSData_A
|
||||
{
|
||||
|
||||
get { return sysData_A; }
|
||||
set
|
||||
{
|
||||
sysData_A = value;
|
||||
RaisePropertyChanged("SYSData_A");
|
||||
}
|
||||
}
|
||||
public ObservableCollection<DATA_D> SYSData_D
|
||||
{
|
||||
|
||||
get { return sysData_D; }
|
||||
set
|
||||
{
|
||||
sysData_D = value;
|
||||
RaisePropertyChanged("SYSData_D");
|
||||
}
|
||||
}
|
||||
public ObservableCollection<DATA_M> 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<T> ToObservableCollection<T>(DataTable dt) where T : class, new()
|
||||
{
|
||||
Type t = typeof(T);
|
||||
PropertyInfo[] propertys = t.GetProperties();
|
||||
ObservableCollection<T> lst = new ObservableCollection<T>();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user