diff --git a/MainWindow.xaml b/MainWindow.xaml index 47a1b65..f54954b 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -56,7 +56,6 @@ - diff --git a/Properties/Resources.en-US.resx b/Properties/Resources.en-US.resx index 90fb965..45a77b6 100644 --- a/Properties/Resources.en-US.resx +++ b/Properties/Resources.en-US.resx @@ -864,4 +864,7 @@ Message + + Orders + \ No newline at end of file diff --git a/Properties/Resources.zh-TW.resx b/Properties/Resources.zh-TW.resx index cd3c72f..95a3650 100644 --- a/Properties/Resources.zh-TW.resx +++ b/Properties/Resources.zh-TW.resx @@ -864,4 +864,7 @@ 訊息 + + 訂單 + \ No newline at end of file diff --git a/SunlightCentralizedControlManagement_SCCM_.csproj b/SunlightCentralizedControlManagement_SCCM_.csproj index c62f3a5..1fe3bd2 100644 --- a/SunlightCentralizedControlManagement_SCCM_.csproj +++ b/SunlightCentralizedControlManagement_SCCM_.csproj @@ -91,6 +91,7 @@ + @@ -102,6 +103,9 @@ info.xaml + + RoilingTextBlock.xaml + Whole.xaml @@ -134,6 +138,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/UserClass/ClsLock.cs b/UserClass/ClsLock.cs index f486b11..c36f10c 100644 --- a/UserClass/ClsLock.cs +++ b/UserClass/ClsLock.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -namespace DyeingComputer.UserClass +namespace SunlightCentralizedControlManagement_SCCM_.UserClass { /// /// 使用using代替lock操作的对象,可指定写入和读取锁定模式 diff --git a/UserClass/SqliteHelper.cs b/UserClass/SqliteHelper.cs new file mode 100644 index 0000000..94b9f75 --- /dev/null +++ b/UserClass/SqliteHelper.cs @@ -0,0 +1,686 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Data; +using System.IO; +using System.Data.Common; +using System.Windows.Media.Animation; +using System.Data.SQLite; +using System.Windows.Shapes; +using System.Drawing; + + +namespace SunlightCentralizedControlManagement_SCCM_.UserClass +{ + public class SqliteHelper + { + + public class SQLiteHelper + { + #region 字段 + + /// + /// 事务的基类 + /// + private DbTransaction DBtrans; + /// + /// 使用静态变量字典解决多线程实例本类,实现一个数据库对应一个clslock + /// + private static readonly Dictionary RWL = new Dictionary(); + /// + /// 数据库地址 + /// + private readonly string mdataFile; + /// + /// 数据库密码 + /// + private readonly string mPassWord; + private readonly string LockName = null; + /// + /// 数据库连接定义 + /// + private SQLiteConnection mConn; + + #endregion + + #region 构造函数 + + /// + /// 根据数据库地址初始化 + /// + /// 数据库地址 + public SQLiteHelper(string dataFile) + { + this.mdataFile = dataFile ?? throw new ArgumentNullException("dataFile=null"); + //this.mdataFile = AppDomain.CurrentDomain.BaseDirectory + dataFile; + this.mdataFile = dataFile; + if (!RWL.ContainsKey(dataFile)) + { + LockName = dataFile; + RWL.Add(dataFile, new ClsLock()); + } + } + + /// + /// 使用密码打开数据库 + /// + /// 数据库地址 + /// 数据库密码 + public SQLiteHelper(string dataFile, string PassWord) + { + this.mdataFile = dataFile ?? throw new ArgumentNullException("dataFile is null"); + this.mPassWord = PassWord ?? throw new ArgumentNullException("PassWord is null"); + //this.mdataFile = AppDomain.CurrentDomain.BaseDirectory + dataFile; + this.mdataFile = dataFile; + if (!RWL.ContainsKey(dataFile)) + { + LockName = dataFile; + RWL.Add(dataFile, new ClsLock()); + } + } + + #endregion + + #region 打开/关闭 数据库 + + /// + /// 打开 SQLiteManager 使用的数据库连接 + /// + public void Open() + { + if (string.IsNullOrWhiteSpace(mPassWord)) + { + mConn = OpenConnection(this.mdataFile); + } + else + { + mConn = OpenConnection(this.mdataFile, mPassWord); + } + Console.WriteLine("The database was opened successfully"); + } + + /// + /// 关闭连接 + /// + public void Close() + { + if (this.mConn != null) + { + try + { + this.mConn.Close(); + if (RWL.ContainsKey(LockName)) + { + RWL.Remove(LockName); + } + } + catch + { + Console.WriteLine("Shutdown failed"); + } + } + Console.WriteLine("The database was shut down successfully"); + } + + #endregion + + #region 事务 + + /// + /// 开始事务 + /// + public void BeginTrain() + { + EnsureConnection(); + DBtrans = mConn.BeginTransaction(); + } + + /// + /// 提交事务 + /// + public void DBCommit() + { + try + { + DBtrans.Commit(); + } + catch (Exception) + { + DBtrans.Rollback(); + } + } + + #endregion + + #region 工具 + + /// + /// 打开一个SQLite数据库文件,如果文件不存在,则创建(无密码) + /// + /// + /// SQLiteConnection 类 + private SQLiteConnection OpenConnection(string dataFile) + { + if (dataFile == null) + { + throw new ArgumentNullException("dataFiledataFile=null"); + } + if (!File.Exists(dataFile)) + { + SQLiteConnection.CreateFile(dataFile); + } + SQLiteConnection conn = new SQLiteConnection(); + SQLiteConnectionStringBuilder conStr = new SQLiteConnectionStringBuilder + { + DataSource = dataFile + }; + conn.ConnectionString = conStr.ToString(); + conn.Open(); + return conn; + } + + /// + /// 打开一个SQLite数据库文件,如果文件不存在,则创建(有密码) + /// + /// + /// + /// SQLiteConnection 类 + private SQLiteConnection OpenConnection(string dataFile, string Password) + { + if (dataFile == null) + { + throw new ArgumentNullException("dataFile=null"); + } + if (!File.Exists(Convert.ToString(dataFile))) + { + SQLiteConnection.CreateFile(dataFile); + } + try + { + SQLiteConnection conn = new SQLiteConnection(); + SQLiteConnectionStringBuilder conStr = new SQLiteConnectionStringBuilder + { + DataSource = dataFile, + Password = Password + }; + conn.ConnectionString = conStr.ToString(); + conn.Open(); + return conn; + } + catch (Exception) + { + return null; + } + } + + /// + /// 读取 或 设置 SQLiteManager 使用的数据库连接 + /// + public SQLiteConnection Connection + { + get + { + return mConn; + } + private set + { + mConn = value ?? throw new ArgumentNullException(); + } + } + + /// + /// 确保数据库是连接状态 + /// + /// + protected void EnsureConnection() + { + if (this.mConn == null) + { + throw new Exception("SQLiteManager.Connection=null"); + } + if (mConn.State != ConnectionState.Open) + { + mConn.Open(); + } + } + + /// + /// 获取数据库文件的路径 + /// + /// + public string GetDataFile() + { + return this.mdataFile; + } + + /// + /// 判断表 table 是否存在 + /// + /// + /// 存在返回true,否则返回false + public bool TableExists(string table) + { + if (table == null) + { + throw new ArgumentNullException("table=null"); + } + EnsureConnection(); + SQLiteDataReader reader = ExecuteReader("SELECT count(*) as c FROM sqlite_master WHERE type='table' AND name=@tableName ", new SQLiteParameter[] { new SQLiteParameter("tableName", table) }); + if (reader == null) + { + return false; + } + reader.Read(); + int c = reader.GetInt32(0); + reader.Close(); + reader.Dispose(); + //return false; + return c == 1; + } + + /// + /// VACUUM 命令(通过复制主数据库中的内容到一个临时数据库文件,然后清空主数据库,并从副本中重新载入原始的数据库文件) + /// + /// + public bool Vacuum() + { + try + { + using (SQLiteCommand Command = new SQLiteCommand("VACUUM", Connection)) + { + Command.ExecuteNonQuery(); + } + return true; + } + catch (System.Data.SQLite.SQLiteException) + { + return false; + } + } + + #endregion + + #region 执行SQL + + /// + /// 执行SQL, 并返回 SQLiteDataReader 对象结果 + /// + /// + /// null 表示无参数 + /// + public SQLiteDataReader ExecuteReader(string sql, SQLiteParameter[] paramArr) + { + if (sql == null) + { + throw new ArgumentNullException("sql=null"); + } + EnsureConnection(); + using (RWL[LockName].Read()) + { + using (SQLiteCommand cmd = new SQLiteCommand(sql, Connection)) + { + if (paramArr != null) + { + cmd.Parameters.AddRange(paramArr); + } + try + { + SQLiteDataReader reader = cmd.ExecuteReader(); + cmd.Parameters.Clear(); + return reader; + } + catch (Exception) + { + return null; + } + } + } + } + + /// + /// 执行查询,并返回dataset对象 + /// + /// SQL查询语句 + /// 参数数组 + /// + public DataSet ExecuteDataSet(string sql, SQLiteParameter[] paramArr) + { + if (sql == null) + { + throw new ArgumentNullException("sql=null"); + } + this.EnsureConnection(); + using (RWL[LockName].Read()) + { + using (SQLiteCommand cmd = new SQLiteCommand(sql, this.Connection)) + { + if (paramArr != null) + { + cmd.Parameters.AddRange(paramArr); + } + try + { + SQLiteDataAdapter da = new SQLiteDataAdapter(); + DataSet ds = new DataSet(); + da.SelectCommand = cmd; + da.Fill(ds); + cmd.Parameters.Clear(); + da.Dispose(); + return ds; + } + catch (Exception) + { + return null; + } + } + } + } + + /// + /// 执行SQL查询,并返回dataset对象。 + /// + /// 映射源表的名称 + /// SQL语句 + /// SQL参数数组 + /// + public DataSet ExecuteDataSet(string strTable, string sql, SQLiteParameter[] paramArr) + { + if (sql == null) + { + throw new ArgumentNullException("sql=null"); + } + this.EnsureConnection(); + using (RWL[LockName].Read()) + { + using (SQLiteCommand cmd = new SQLiteCommand(sql, this.Connection)) + { + if (paramArr != null) + { + cmd.Parameters.AddRange(paramArr); + } + try + { + SQLiteDataAdapter da = new SQLiteDataAdapter(); + DataSet ds = new DataSet(); + da.SelectCommand = cmd; + da.Fill(ds, strTable); + cmd.Parameters.Clear(); + da.Dispose(); + return ds; + } + catch (Exception) + { + return null; + } + } + } + } + + /// + /// 执行SQL,返回受影响的行数,可用于执行表创建语句,paramArr == null 表示无参数 + /// + /// + /// + public int ExecuteNonQuery(string sql, SQLiteParameter[] paramArr) + { + if (sql == null) + { + throw new ArgumentNullException("sql=null"); + } + this.EnsureConnection(); + using (RWL[LockName].Read()) + { + try + { + using (SQLiteCommand cmd = new SQLiteCommand(sql, Connection)) + { + if (paramArr != null) + { + foreach (SQLiteParameter p in paramArr) + { + cmd.Parameters.Add(p); + } + } + int c = cmd.ExecuteNonQuery(); + cmd.Parameters.Clear(); + return c; + } + } + catch (SQLiteException) + { + return 0; + } + } + } + + /// + /// 执行SQL,返回结果集第一行,如果结果集为空,那么返回空 List(List.Count=0), + /// rowWrapper = null 时,使用 WrapRowToDictionary + /// + /// + /// + /// + public object ExecuteScalar(string sql, SQLiteParameter[] paramArr) + { + if (sql == null) + { + throw new ArgumentNullException("sql=null"); + } + this.EnsureConnection(); + using (RWL[LockName].Read()) + { + using (SQLiteCommand cmd = new SQLiteCommand(sql, Connection)) + { + if (paramArr != null) + { + cmd.Parameters.AddRange(paramArr); + } + try + { + object reader = cmd.ExecuteScalar(); + cmd.Parameters.Clear(); + cmd.Dispose(); + return reader; + } + catch (Exception) + { + return null; + } + } + } + } + + /// + /// 查询一行记录,无结果时返回 null,conditionCol = null 时将忽略条件,直接执行 select * from table + /// + /// 表名 + /// + /// + /// + public object QueryOne(string table, string conditionCol, object conditionVal) + { + if (table == null) + { + throw new ArgumentNullException("table=null"); + } + this.EnsureConnection(); + string sql = "select * from " + table; + if (conditionCol != null) + { + sql += " where " + conditionCol + "=@" + conditionCol; + } + object result = ExecuteScalar(sql, new SQLiteParameter[] { new SQLiteParameter(conditionCol, conditionVal) }); + return result; + } + + #endregion + + #region 增 删 改 + + /// + /// 执行 insert into 语句 + /// + /// + /// + /// + public int InsertData(string table, Dictionary entity) + { + if (table == null) + { + throw new ArgumentNullException("table=null"); + } + this.EnsureConnection(); + string sql = BuildInsert(table, entity); + return this.ExecuteNonQuery(sql, BuildParamArray(entity)); + } + + /// + /// 执行 update 语句,注意:如果 where = null,那么 whereParams 也为 null, + /// + /// 表名 + /// 要修改的列名和列名的值 + /// 查找符合条件的列 + /// where条件中参数的值 + /// + public int Update(string table, Dictionary entity, string where, SQLiteParameter[] whereParams) + { + if (table == null) + { + throw new ArgumentNullException("table=null"); + } + this.EnsureConnection(); + string sql = BuildUpdate(table, entity); + SQLiteParameter[] parameter = BuildParamArray(entity); + if (where != null) + { + sql += " where " + where; + if (whereParams != null) + { + SQLiteParameter[] newArr = new SQLiteParameter[(parameter.Length + whereParams.Length)]; + Array.Copy(parameter, newArr, parameter.Length); + Array.Copy(whereParams, 0, newArr, parameter.Length, whereParams.Length); + parameter = newArr; + } + } + return this.ExecuteNonQuery(sql, parameter); + } + + /// + /// 执行 delete from table 语句,where不必包含'where'关键字,where = null 时将忽略 whereParams + /// + /// + /// + /// + /// + public int Delete(string table, string where, SQLiteParameter[] whereParams) + { + if (table == null) + { + throw new ArgumentNullException("table=null"); + } + this.EnsureConnection(); + string sql = "delete from " + table + " "; + if (where != null) + { + sql += "where " + where; + } + return ExecuteNonQuery(sql, whereParams); + } + + /// + /// 将 Dictionary 类型数据 转换为 SQLiteParameter[] 类型 + /// + /// + /// + private SQLiteParameter[] BuildParamArray(Dictionary entity) + { + List list = new List(); + foreach (string key in entity.Keys) + { + list.Add(new SQLiteParameter(key, entity[key])); + } + if (list.Count == 0) + { + return null; + } + return list.ToArray(); + } + + /// + /// 将 Dictionary 类型数据 转换为 插入数据 的 SQL语句 + /// + /// 表名 + /// 字典 + /// + private string BuildInsert(string table, Dictionary entity) + { + StringBuilder buf = new StringBuilder(); + buf.Append("insert into ").Append(table); + buf.Append(" ("); + foreach (string key in entity.Keys) + { + buf.Append(key).Append(","); + } + buf.Remove(buf.Length - 1, 1); // 移除最后一个, + buf.Append(") "); + buf.Append("values("); + foreach (string key in entity.Keys) + { + buf.Append("@").Append(key).Append(","); // 创建一个参数 + } + buf.Remove(buf.Length - 1, 1); + buf.Append(") "); + + return buf.ToString(); + } + + /// + /// 将 Dictionary 类型数据 转换为 修改数据 的 SQL语句 + /// + /// 表名 + /// 字典 + /// + private string BuildUpdate(string table, Dictionary entity) + { + StringBuilder buf = new StringBuilder(); + buf.Append("update ").Append(table).Append(" set "); + foreach (string key in entity.Keys) + { + buf.Append(key).Append("=").Append("@").Append(key).Append(","); + } + buf.Remove(buf.Length - 1, 1); + buf.Append(" "); + return buf.ToString(); + } + + /// + /// 将 DataTable 转换为 Dictionary 类型数据 + /// + public Dictionary DataTableToDictionary(DataTable dataTable) + { + Dictionary result = new Dictionary(); + if (dataTable != null) + { + foreach (DataRow dataRow in dataTable.Rows) + { + foreach (DataColumn dataColumn in dataTable.Columns) + { + result.Add(dataColumn.ColumnName, dataRow[dataColumn].ToString()); + //result = Console.WriteLine(dataRow[dataColumn].ToString()); + //result.Add(dataColumn.ColumnName, dataRow[dataColumn].ToString())(new RepeatDictionaryComparer()); + } + } + } + else + { + result = null; + } + return result; + } + + } + #endregion + } +} diff --git a/View/RoilingTextBlock.xaml b/View/RoilingTextBlock.xaml new file mode 100644 index 0000000..5254a15 --- /dev/null +++ b/View/RoilingTextBlock.xaml @@ -0,0 +1,36 @@ + + + + + + + + + + + + diff --git a/View/RoilingTextBlock.xaml.cs b/View/RoilingTextBlock.xaml.cs new file mode 100644 index 0000000..0f2efe7 --- /dev/null +++ b/View/RoilingTextBlock.xaml.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.Linq; +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; + +namespace SunlightCentralizedControlManagement_SCCM_.View +{ + /// + /// RoilingTextBlock.xaml 的交互逻辑 + /// + public partial class RoilingTextBlock : UserControl + { + private bool canRoll = false; + private readonly double rollingInterval = 0.5;//每一步的偏移量 + private double offset=6;//最大的偏移量 + private TextBlock currentTextBlock = null; + private DispatcherTimer currentTimer = null; + public RoilingTextBlock() + { + InitializeComponent(); + Loaded += RoilingTextBlock_Loaded; + } + + void RoilingTextBlock_Loaded(object sender, RoutedEventArgs e) + { + if (this.currentTextBlock != null) + { + canRoll = this.currentTextBlock.ActualWidth > this.ActualWidth; + } + currentTimer = new System.Windows.Threading.DispatcherTimer(); + currentTimer.Interval = TimeSpan.FromMilliseconds(100); + currentTimer.Tick += new EventHandler(currentTimer_Tick); + currentTimer.Start(); + } + + public override void OnApplyTemplate() + { + try + { + base.OnApplyTemplate(); + currentTextBlock = this.GetTemplateChild("textBlock") as TextBlock; + } + catch (Exception) + { + } + } + + void currentTimer_Tick(object sender, EventArgs e) + { + if (this.currentTextBlock != null && canRoll) + { + if (Math.Abs(Left) <= this.currentTextBlock.ActualWidth-offset) + { + Left-=rollingInterval; + } + else + { + Left = this.ActualHeight; + } + } + } + + #region Dependency Properties + public static DependencyProperty TextProperty = + DependencyProperty.Register("Text", typeof(string), typeof(RoilingTextBlock), + new PropertyMetadata("")); + + public static new DependencyProperty FontSizeProperty = + DependencyProperty.Register("FontSize", typeof(double), typeof(RoilingTextBlock), + new PropertyMetadata(14D)); + + public static new readonly DependencyProperty ForegroundProperty = + DependencyProperty.Register("Foreground", typeof(Brush), typeof(RoilingTextBlock), new FrameworkPropertyMetadata(Brushes.Green)); + + public static DependencyProperty LeftProperty = + DependencyProperty.Register("Left", typeof(double), typeof(RoilingTextBlock), new PropertyMetadata(0D)); + + public static DependencyProperty TopProperty = + DependencyProperty.Register("Top", typeof(double), typeof(RoilingTextBlock), new PropertyMetadata(0D)); + + #endregion + + #region Public Variables + public string Text + { + get { return (string)GetValue(TextProperty); } + set { SetValue(TextProperty, value); } + } + + public new double FontSize + { + get { return (double)GetValue(FontSizeProperty); } + set { SetValue(FontSizeProperty, value); } + } + + public new Brush Foreground + { + get { return (Brush)GetValue(ForegroundProperty); } + set { SetValue(ForegroundProperty, value); } + } + + public double Left + { + get { return (double)GetValue(LeftProperty); } + set { SetValue(LeftProperty, value); } + } + + public double Top + { + get { return (double)GetValue(TopProperty); } + set { SetValue(TopProperty, value); } + } + #endregion + } +} diff --git a/View/Whole.xaml.cs b/View/Whole.xaml.cs index 5f8621b..4dfb802 100644 --- a/View/Whole.xaml.cs +++ b/View/Whole.xaml.cs @@ -1,5 +1,8 @@ -using System; +using DyeingComputer.UserClass; +using SunlightCentralizedControlManagement_SCCM_.ViewModel; +using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,7 +15,8 @@ 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 { /// @@ -24,35 +28,93 @@ namespace SunlightCentralizedControlManagement_SCCM_.View { InitializeComponent(); } - + + View.info[] inf = new View.info[999]; //定义总览信息卡 private void UserControl_Loaded(object sender, RoutedEventArgs e) { - TextBox textBox = new TextBox(); - textBox.Text = "12431414"; - // textBox.HorizontalAlignment = HorizontalAlignment.Left; - // textBox.VerticalAlignment = VerticalAlignment.Top; - textBox.Background =new SolidColorBrush( Color.FromRgb(100,100,100)); - textBox.Width = 100; - textBox.Height = 200; - textBox.Margin = new Thickness( 5,5,0,0); - WholeView.Children.Add(textBox); - + /// + /// 生成总览信息卡 + /// + //View.info[] inf = new View.info[999]; + for (int i = 0; i < MainWindowViewModel.Machines.Rows.Count; i++) + { + inf[i] = new View.info(); + inf[i].Margin = new Thickness(5, 5, 0, 5); + inf[i].Width = 300; + inf[i].Height = 400; + inf[i].name.Text = Selet_Machines(MainWindowViewModel.Machines, "name",i.ToString()).ToString(); + string State_ = Selet_Machines(MainWindowViewModel.Machines, "State", i.ToString()).ToString(); + if (State_ == "101") + { inf[i].name.Background = new SolidColorBrush(Color.FromRgb(100, 100, 100)); } + else if (State_ == "201") + { inf[i].name.Background = new SolidColorBrush(Color.FromRgb(0, 255, 0)); } + else if (State_ == "202") + { inf[i].name.Background = new SolidColorBrush(Color.FromRgb(255, 255, 0)); } + else + { inf[i].name.Background = new SolidColorBrush(Color.FromRgb(255, 0, 0)); } + inf[i].temp.Text = (Selet_Machines(MainWindowViewModel.Machines, "Temperature", i.ToString()) + "°C").ToString(); + inf[i].Process.Text = Selet_Machines(MainWindowViewModel.Machines, "Process", i.ToString()).ToString(); + inf[i].Step.Text = Selet_Machines(MainWindowViewModel.Machines, "Step", i.ToString()).ToString(); + inf[i].Message.Text = Selet_Machines(MainWindowViewModel.Machines, "Message", i.ToString()).ToString(); + inf[i].Orders.Text = Selet_Machines(MainWindowViewModel.Machines, "Orders", i.ToString()).ToString(); + inf[i].time.Text = Selet_Machines(MainWindowViewModel.Machines, "time", i.ToString()).ToString(); + WholeView.Children.Add(inf[i]); + } + CountDown(); + } + public static object Selet_Machines(DataTable DB,string name ,string key)//查询 + { + try + { + lock (DB) + { + DataRow drEmployee = DB.Select("ID=" + key).First();; + object index = drEmployee.Field(name); + return index; + } + } + catch (Exception) + { + // LogGing.LogGingDATA("SDTD:" + ex.ToString()); + return "ERR"; + } + } - View.info[] inf = new View.info[60]; - for (int i=1; i<50; i++) + private void CountDown() + { + DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick { - inf[i] = new View.info(); - inf[i].Margin = new Thickness(5, 5, 0, 5); - inf[i].Width = 300; - inf[i].Height = 400; - inf[i].name.Text = i.ToString(); - inf[i].temp.Text = "123c"; - WholeView.Children.Add(inf[i]); + Interval = TimeSpan.FromSeconds(1)//秒 + }; + timer1s.Tick += Tick_Event_1S; + timer1s.Start(); + }//时间周期初始化 + void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S + { + for (int i = 0; i < MainWindowViewModel.Machines.Rows.Count; i++) + { + string State_ = Selet_Machines(MainWindowViewModel.Machines, "State", i.ToString()).ToString(); + if (State_ == "101") + { inf[i].name.Background = new SolidColorBrush(Color.FromRgb(100, 100, 100)); } + else if (State_ == "201") + { inf[i].name.Background = new SolidColorBrush(Color.FromRgb(0, 255, 0)); } + else if (State_ == "202") + { inf[i].name.Background = new SolidColorBrush(Color.FromRgb(255, 255, 0)); } + else + { inf[i].name.Background = new SolidColorBrush(Color.FromRgb(255, 0, 0)); } + + inf[i].temp.Text = (Selet_Machines(MainWindowViewModel.Machines, "Temperature", i.ToString()) + "°C").ToString(); + inf[i].Process.Text = Selet_Machines(MainWindowViewModel.Machines, "Process", i.ToString()).ToString(); + inf[i].Step.Text = Selet_Machines(MainWindowViewModel.Machines, "Step", i.ToString()).ToString(); + inf[i].Message.Text = Selet_Machines(MainWindowViewModel.Machines, "Message", i.ToString()).ToString(); + inf[i].Orders.Text = Selet_Machines(MainWindowViewModel.Machines, "Orders", i.ToString()).ToString(); + inf[i].time.Text = Selet_Machines(MainWindowViewModel.Machines, "time", i.ToString()).ToString(); + } } } diff --git a/View/info.xaml b/View/info.xaml index 1ff3705..1db824b 100644 --- a/View/info.xaml +++ b/View/info.xaml @@ -3,22 +3,21 @@ 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:SunlightCentralizedControlManagement_SCCM_.View" - xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties" + xmlns:local="clr-namespace:SunlightCentralizedControlManagement_SCCM_.View" + xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" Background="White"> - - - + + - - - - - - + + + + + + diff --git a/View/info.xaml.cs b/View/info.xaml.cs index 3e4afdd..21837aa 100644 --- a/View/info.xaml.cs +++ b/View/info.xaml.cs @@ -1,5 +1,7 @@ -using System; +using ScottPlot.Plottables; +using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,9 +11,12 @@ using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; +using System.Windows.Media.Animation; using System.Windows.Media.Imaging; +using System.Windows.Media.Media3D; using System.Windows.Navigation; using System.Windows.Shapes; +using System.Windows.Threading; namespace SunlightCentralizedControlManagement_SCCM_.View { @@ -23,7 +28,22 @@ namespace SunlightCentralizedControlManagement_SCCM_.View public info() { InitializeComponent(); - + CountDown(); } - } + + private void CountDown() + { + DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick + { + Interval = TimeSpan.FromSeconds(10)//秒 + }; + timer1s.Tick += Tick_Event_1S; + timer1s.Start(); + }//时间周期初始化 + void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S + { + + } + } + } diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index 12660d0..25c491a 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -2,11 +2,13 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; using System.Windows.Threading; +using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper; namespace SunlightCentralizedControlManagement_SCCM_.ViewModel { @@ -74,10 +76,30 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel void DisTimer_500MS(object sender, EventArgs e)//Tick_Event周期执行事件500MS { } + + + private SQLiteHelper SQLiteHelpers = null; //定义数据库 + private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径 + public static DataTable Machines = new DataTable(); //设备表缓存 + public static View.info[] inf = new View.info[999]; //定义总览信息卡 public MainWindowViewModel() { + SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 + SQLiteHelpers.Open(); //打开数据库 + Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines ", null).Tables[0]; //读取表写入缓存 + SQLiteHelpers.Close(); + CountDown(); } -} + + + + + + + + + + } }