Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightCentralizedControlManagement
This commit is contained in:
commit
5c7ed500b3
12 files changed
+997
-33
No files matched your search
@@ -56,7 +56,6 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
|
||||||
<Grid x:Name="GridMenu" Width="60" HorizontalAlignment="Left" Background="#FF00204E" Margin="0" SizeChanged="GridMenu_SizeChanged">
|
<Grid x:Name="GridMenu" Width="60" HorizontalAlignment="Left" Background="#FF00204E" Margin="0" SizeChanged="GridMenu_SizeChanged">
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<Grid Background="#FF006361">
|
<Grid Background="#FF006361">
|
||||||
|
|||||||
@@ -864,4 +864,7 @@
|
|||||||
<data name="message" xml:space="preserve">
|
<data name="message" xml:space="preserve">
|
||||||
<value>Message</value>
|
<value>Message</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="orders" xml:space="preserve">
|
||||||
|
<value>Orders</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -864,4 +864,7 @@
|
|||||||
<data name="message" xml:space="preserve">
|
<data name="message" xml:space="preserve">
|
||||||
<value>訊息</value>
|
<value>訊息</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="orders" xml:space="preserve">
|
||||||
|
<value>訂單</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -91,6 +91,7 @@
|
|||||||
<Compile Include="UserClass\NumericTextColumn .cs" />
|
<Compile Include="UserClass\NumericTextColumn .cs" />
|
||||||
<Compile Include="UserClass\PID.cs" />
|
<Compile Include="UserClass\PID.cs" />
|
||||||
<Compile Include="UserClass\PressKey.cs" />
|
<Compile Include="UserClass\PressKey.cs" />
|
||||||
|
<Compile Include="UserClass\SqliteHelper.cs" />
|
||||||
<Compile Include="UserClass\StrToInt.cs" />
|
<Compile Include="UserClass\StrToInt.cs" />
|
||||||
<Compile Include="UserClass\SubItem.cs" />
|
<Compile Include="UserClass\SubItem.cs" />
|
||||||
<Compile Include="UserClass\UserControlMenuItem.cs" />
|
<Compile Include="UserClass\UserControlMenuItem.cs" />
|
||||||
@@ -102,6 +103,9 @@
|
|||||||
<Compile Include="View\info.xaml.cs">
|
<Compile Include="View\info.xaml.cs">
|
||||||
<DependentUpon>info.xaml</DependentUpon>
|
<DependentUpon>info.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="View\RoilingTextBlock.xaml.cs">
|
||||||
|
<DependentUpon>RoilingTextBlock.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="View\Whole.xaml.cs">
|
<Compile Include="View\Whole.xaml.cs">
|
||||||
<DependentUpon>Whole.xaml</DependentUpon>
|
<DependentUpon>Whole.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -134,6 +138,10 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
<Page Include="View\RoilingTextBlock.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
<Page Include="View\Whole.xaml">
|
<Page Include="View\Whole.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using System.Text;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace DyeingComputer.UserClass
|
namespace SunlightCentralizedControlManagement_SCCM_.UserClass
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 使用using代替lock操作的对象,可指定写入和读取锁定模式
|
/// 使用using代替lock操作的对象,可指定写入和读取锁定模式
|
||||||
|
|||||||
@@ -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 字段
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 事务的基类
|
||||||
|
/// </summary>
|
||||||
|
private DbTransaction DBtrans;
|
||||||
|
/// <summary>
|
||||||
|
/// 使用静态变量字典解决多线程实例本类,实现一个数据库对应一个clslock
|
||||||
|
/// </summary>
|
||||||
|
private static readonly Dictionary<string, ClsLock> RWL = new Dictionary<string, ClsLock>();
|
||||||
|
/// <summary>
|
||||||
|
/// 数据库地址
|
||||||
|
/// </summary>
|
||||||
|
private readonly string mdataFile;
|
||||||
|
/// <summary>
|
||||||
|
/// 数据库密码
|
||||||
|
/// </summary>
|
||||||
|
private readonly string mPassWord;
|
||||||
|
private readonly string LockName = null;
|
||||||
|
/// <summary>
|
||||||
|
/// 数据库连接定义
|
||||||
|
/// </summary>
|
||||||
|
private SQLiteConnection mConn;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 构造函数
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据数据库地址初始化
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dataFile">数据库地址</param>
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使用密码打开数据库
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dataFile">数据库地址</param>
|
||||||
|
/// <param name="PassWord">数据库密码</param>
|
||||||
|
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 打开/关闭 数据库
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 打开 SQLiteManager 使用的数据库连接
|
||||||
|
/// </summary>
|
||||||
|
public void Open()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(mPassWord))
|
||||||
|
{
|
||||||
|
mConn = OpenConnection(this.mdataFile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mConn = OpenConnection(this.mdataFile, mPassWord);
|
||||||
|
}
|
||||||
|
Console.WriteLine("The database was opened successfully");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 关闭连接
|
||||||
|
/// </summary>
|
||||||
|
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 事务
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 开始事务
|
||||||
|
/// </summary>
|
||||||
|
public void BeginTrain()
|
||||||
|
{
|
||||||
|
EnsureConnection();
|
||||||
|
DBtrans = mConn.BeginTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 提交事务
|
||||||
|
/// </summary>
|
||||||
|
public void DBCommit()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DBtrans.Commit();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
DBtrans.Rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 工具
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 打开一个SQLite数据库文件,如果文件不存在,则创建(无密码)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dataFile"></param>
|
||||||
|
/// <returns>SQLiteConnection 类</returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 打开一个SQLite数据库文件,如果文件不存在,则创建(有密码)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dataFile"></param>
|
||||||
|
/// <param name="Password"></param>
|
||||||
|
/// <returns>SQLiteConnection 类</returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 读取 或 设置 SQLiteManager 使用的数据库连接
|
||||||
|
/// </summary>
|
||||||
|
public SQLiteConnection Connection
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return mConn;
|
||||||
|
}
|
||||||
|
private set
|
||||||
|
{
|
||||||
|
mConn = value ?? throw new ArgumentNullException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 确保数据库是连接状态
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="Exception"></exception>
|
||||||
|
protected void EnsureConnection()
|
||||||
|
{
|
||||||
|
if (this.mConn == null)
|
||||||
|
{
|
||||||
|
throw new Exception("SQLiteManager.Connection=null");
|
||||||
|
}
|
||||||
|
if (mConn.State != ConnectionState.Open)
|
||||||
|
{
|
||||||
|
mConn.Open();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取数据库文件的路径
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public string GetDataFile()
|
||||||
|
{
|
||||||
|
return this.mdataFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 判断表 table 是否存在
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="table"></param>
|
||||||
|
/// <returns>存在返回true,否则返回false</returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// VACUUM 命令(通过复制主数据库中的内容到一个临时数据库文件,然后清空主数据库,并从副本中重新载入原始的数据库文件)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
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
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行SQL, 并返回 SQLiteDataReader 对象结果
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql"></param>
|
||||||
|
/// <param name="paramArr">null 表示无参数</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行查询,并返回dataset对象
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql">SQL查询语句</param>
|
||||||
|
/// <param name="paramArr">参数数组</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行SQL查询,并返回dataset对象。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="strTable">映射源表的名称</param>
|
||||||
|
/// <param name="sql">SQL语句</param>
|
||||||
|
/// <param name="paramArr">SQL参数数组</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行SQL,返回受影响的行数,可用于执行表创建语句,paramArr == null 表示无参数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行SQL,返回结果集第一行,如果结果集为空,那么返回空 List(List.Count=0),
|
||||||
|
/// rowWrapper = null 时,使用 WrapRowToDictionary
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql"></param>
|
||||||
|
/// <param name="paramArr"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询一行记录,无结果时返回 null,conditionCol = null 时将忽略条件,直接执行 select * from table
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="table">表名</param>
|
||||||
|
/// <param name="conditionCol"></param>
|
||||||
|
/// <param name="conditionVal"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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 增 删 改
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行 insert into 语句
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="table"></param>
|
||||||
|
/// <param name="entity"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int InsertData(string table, Dictionary<string, object> entity)
|
||||||
|
{
|
||||||
|
if (table == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("table=null");
|
||||||
|
}
|
||||||
|
this.EnsureConnection();
|
||||||
|
string sql = BuildInsert(table, entity);
|
||||||
|
return this.ExecuteNonQuery(sql, BuildParamArray(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行 update 语句,注意:如果 where = null,那么 whereParams 也为 null,
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="table">表名</param>
|
||||||
|
/// <param name="entity">要修改的列名和列名的值</param>
|
||||||
|
/// <param name="where">查找符合条件的列</param>
|
||||||
|
/// <param name="whereParams">where条件中参数的值</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Update(string table, Dictionary<string, object> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行 delete from table 语句,where不必包含'where'关键字,where = null 时将忽略 whereParams
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="table"></param>
|
||||||
|
/// <param name="where"></param>
|
||||||
|
/// <param name="whereParams"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将 Dictionary 类型数据 转换为 SQLiteParameter[] 类型
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private SQLiteParameter[] BuildParamArray(Dictionary<string, object> entity)
|
||||||
|
{
|
||||||
|
List<SQLiteParameter> list = new List<SQLiteParameter>();
|
||||||
|
foreach (string key in entity.Keys)
|
||||||
|
{
|
||||||
|
list.Add(new SQLiteParameter(key, entity[key]));
|
||||||
|
}
|
||||||
|
if (list.Count == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return list.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将 Dictionary 类型数据 转换为 插入数据 的 SQL语句
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="table">表名</param>
|
||||||
|
/// <param name="entity">字典</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private string BuildInsert(string table, Dictionary<string, object> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将 Dictionary 类型数据 转换为 修改数据 的 SQL语句
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="table">表名</param>
|
||||||
|
/// <param name="entity">字典</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private string BuildUpdate(string table, Dictionary<string, object> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将 DataTable 转换为 Dictionary 类型数据
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<string, object> DataTableToDictionary(DataTable dataTable)
|
||||||
|
{
|
||||||
|
Dictionary<string, object> result = new Dictionary<string, object>();
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<UserControl x:Class="SunlightCentralizedControlManagement_SCCM_.View.RoilingTextBlock"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
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"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
DataContext="{Binding RelativeSource={RelativeSource Self}}"
|
||||||
|
d:DesignWidth="300" Height="30" >
|
||||||
|
<UserControl.Template>
|
||||||
|
<ControlTemplate TargetType="UserControl">
|
||||||
|
<Border BorderBrush="White"
|
||||||
|
BorderThickness="1"
|
||||||
|
Padding="2"
|
||||||
|
Background="White">
|
||||||
|
<Canvas x:Name="innerCanvas"
|
||||||
|
Width="Auto"
|
||||||
|
Height="Auto"
|
||||||
|
Background="White"
|
||||||
|
ClipToBounds="True">
|
||||||
|
<TextBlock x:Name="textBlock"
|
||||||
|
Width="Auto"
|
||||||
|
Height="Auto"
|
||||||
|
ClipToBounds="True"
|
||||||
|
TextAlignment="Center"
|
||||||
|
Canvas.Left="{Binding Left,Mode=TwoWay}"
|
||||||
|
Canvas.Top="{Binding Top,Mode=TwoWay}"
|
||||||
|
FontSize="{Binding FontSize,Mode=TwoWay}"
|
||||||
|
Text="{Binding Text,Mode=TwoWay}"
|
||||||
|
Foreground="{Binding Foreground,Mode=TwoWay}"/>
|
||||||
|
</Canvas>
|
||||||
|
|
||||||
|
</Border>
|
||||||
|
</ControlTemplate>
|
||||||
|
</UserControl.Template>
|
||||||
|
</UserControl>
|
||||||
@@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// RoilingTextBlock.xaml 的交互逻辑
|
||||||
|
/// </summary>
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
+84
-22
@@ -1,5 +1,8 @@
|
|||||||
using System;
|
using DyeingComputer.UserClass;
|
||||||
|
using SunlightCentralizedControlManagement_SCCM_.ViewModel;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -12,7 +15,8 @@ using System.Windows.Media;
|
|||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Navigation;
|
using System.Windows.Navigation;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
using System.Windows.Threading;
|
||||||
|
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
|
||||||
namespace SunlightCentralizedControlManagement_SCCM_.View
|
namespace SunlightCentralizedControlManagement_SCCM_.View
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -25,35 +29,93 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
View.info[] inf = new View.info[999]; //定义总览信息卡
|
||||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
TextBox textBox = new TextBox();
|
/// <summary>
|
||||||
textBox.Text = "12431414";
|
/// 生成总览信息卡
|
||||||
// textBox.HorizontalAlignment = HorizontalAlignment.Left;
|
/// </summary>
|
||||||
// textBox.VerticalAlignment = VerticalAlignment.Top;
|
//View.info[] inf = new View.info[999];
|
||||||
textBox.Background =new SolidColorBrush( Color.FromRgb(100,100,100));
|
for (int i = 0; i < MainWindowViewModel.Machines.Rows.Count; i++)
|
||||||
textBox.Width = 100;
|
|
||||||
textBox.Height = 200;
|
|
||||||
textBox.Margin = new Thickness( 5,5,0,0);
|
|
||||||
WholeView.Children.Add(textBox);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
View.info[] inf = new View.info[60];
|
|
||||||
for (int i=1; i<50; i++)
|
|
||||||
{
|
{
|
||||||
inf[i] = new View.info();
|
inf[i] = new View.info();
|
||||||
inf[i].Margin = new Thickness(5, 5, 0, 5);
|
inf[i].Margin = new Thickness(5, 5, 0, 5);
|
||||||
inf[i].Width = 300;
|
inf[i].Width = 300;
|
||||||
inf[i].Height = 400;
|
inf[i].Height = 400;
|
||||||
inf[i].name.Text = i.ToString();
|
inf[i].name.Text = Selet_Machines(MainWindowViewModel.Machines, "name",i.ToString()).ToString();
|
||||||
inf[i].temp.Text = "123c";
|
|
||||||
|
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]);
|
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<object>(name);
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// LogGing.LogGingDATA("SDTD:" + ex.ToString());
|
||||||
|
return "ERR";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CountDown()
|
||||||
|
{
|
||||||
|
DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+7
-8
@@ -8,17 +8,16 @@
|
|||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="300" d:DesignWidth="300" Background="White">
|
d:DesignHeight="300" d:DesignWidth="300" Background="White">
|
||||||
<Grid>
|
<Grid>
|
||||||
<TextBlock x:Name="name" VerticalAlignment="Top" Height="50" Background="Red" Text="Machine" FontWeight="Bold" FontSize="36" />
|
<TextBlock x:Name="name" VerticalAlignment="Top" Height="50" Background="#FF646464" Text="-----" FontWeight="Bold" FontSize="36" />
|
||||||
<TextBlock x:Name="temp" VerticalAlignment="Top" Height="50" Text="000.0°C" FontWeight="Bold" FontSize="36" HorizontalAlignment="Right" Padding="5,0,5,0"/>
|
<TextBlock x:Name="temp" VerticalAlignment="Top" Height="50" Text="---.-°C" FontWeight="Bold" FontSize="36" HorizontalAlignment="Right" Padding="5,0,5,0"/>
|
||||||
|
|
||||||
<TextBlock Text="{x:Static lang:Resources.process}" Height="30" FontWeight="Bold" FontSize="24" Margin="5,50,5,0" VerticalAlignment="Top" Focusable="False"/>
|
<TextBlock Text="{x:Static lang:Resources.process}" Height="30" FontWeight="Bold" FontSize="24" Margin="5,50,5,0" VerticalAlignment="Top" Focusable="False"/>
|
||||||
<TextBlock x:Name="Process" Text="NO Information" Height="30" FontWeight="Bold" FontSize="24" Margin="120,50,5,0" VerticalAlignment="Top" Focusable="False"/>
|
|
||||||
<TextBlock Text="{x:Static lang:Resources.Step}" Height="30" FontWeight="Bold" FontSize="24" Margin="5,100,5,0" VerticalAlignment="Top" Focusable="False"/>
|
<TextBlock Text="{x:Static lang:Resources.Step}" Height="30" FontWeight="Bold" FontSize="24" Margin="5,100,5,0" VerticalAlignment="Top" Focusable="False"/>
|
||||||
<TextBlock x:Name="Step" Text="NO Information" Height="30" FontWeight="Bold" FontSize="24" Margin="120,100,5,0" VerticalAlignment="Top" Focusable="False"/>
|
|
||||||
<TextBlock Text="{x:Static lang:Resources.message}" Height="30" FontWeight="Bold" FontSize="24" Margin="5,150,5,0" VerticalAlignment="Top" Focusable="False"/>
|
<TextBlock Text="{x:Static lang:Resources.message}" Height="30" FontWeight="Bold" FontSize="24" Margin="5,150,5,0" VerticalAlignment="Top" Focusable="False"/>
|
||||||
<TextBlock x:Name="Message" Text="NO Information" Height="30" FontWeight="Bold" FontSize="24" Margin="120,150,5,0" VerticalAlignment="Top" Focusable="False"/>
|
|
||||||
<TextBlock Text="{x:Static lang:Resources.orders}" Height="30" FontWeight="Bold" FontSize="24" Margin="5,200,5,0" VerticalAlignment="Top" Focusable="False"/>
|
<TextBlock Text="{x:Static lang:Resources.orders}" Height="30" FontWeight="Bold" FontSize="24" Margin="5,200,5,0" VerticalAlignment="Top" Focusable="False"/>
|
||||||
<TextBlock x:Name="Orders" Text="NO Information" Height="30" FontWeight="Bold" FontSize="24" Margin="120,200,5,0" VerticalAlignment="Top" Focusable="False"/>
|
<TextBlock x:Name="time" Text="----------------------------" Height="30" FontWeight="Bold" FontSize="24" Margin="5,250,5,0" VerticalAlignment="Top" Focusable="False"/>
|
||||||
<TextBlock x:Name="time" Text="" Height="30" FontWeight="Bold" FontSize="24" Margin="5,250,5,0" VerticalAlignment="Top" Focusable="False"/>
|
<local:RoilingTextBlock Foreground="Black" x:Name="Process" Text="NO Information" FontSize="21" Height="30" Margin="120,50,0,0" VerticalAlignment="Top"/>
|
||||||
|
<local:RoilingTextBlock Foreground="Black" x:Name="Step" Text="NO Information" FontSize="21" Height="30" Margin="120,100,0,0" VerticalAlignment="Top"/>
|
||||||
|
<local:RoilingTextBlock Foreground="Black" x:Name="Message" Text="NO Information" FontSize="21" Height="30" Margin="120,150,0,0" VerticalAlignment="Top"/>
|
||||||
|
<local:RoilingTextBlock Foreground="Black" x:Name="Orders" Text="NO Information" FontSize="21" Height="30" Margin="120,200,0,0" VerticalAlignment="Top"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
+21
-1
@@ -1,5 +1,7 @@
|
|||||||
using System;
|
using ScottPlot.Plottables;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -9,9 +11,12 @@ using System.Windows.Data;
|
|||||||
using System.Windows.Documents;
|
using System.Windows.Documents;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Animation;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Media.Media3D;
|
||||||
using System.Windows.Navigation;
|
using System.Windows.Navigation;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
using System.Windows.Threading;
|
||||||
|
|
||||||
namespace SunlightCentralizedControlManagement_SCCM_.View
|
namespace SunlightCentralizedControlManagement_SCCM_.View
|
||||||
{
|
{
|
||||||
@@ -23,7 +28,22 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
|
|||||||
public info()
|
public info()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
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
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,11 +2,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
|
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
|
||||||
|
|
||||||
namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
||||||
{
|
{
|
||||||
@@ -74,10 +76,30 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
|||||||
void DisTimer_500MS(object sender, EventArgs e)//Tick_Event周期执行事件500MS
|
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()
|
public MainWindowViewModel()
|
||||||
{
|
{
|
||||||
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
||||||
|
SQLiteHelpers.Open(); //打开数据库
|
||||||
|
Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines ", null).Tables[0]; //读取表写入缓存
|
||||||
|
SQLiteHelpers.Close();
|
||||||
|
|
||||||
CountDown();
|
CountDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user