Merge branch 'master' of http://www.scserverddns.top:13000/sc/DyeingComputer
This commit is contained in:
commit
6f4d43c412
2 files changed
+112
-33
No files matched your search
+76
-32
@@ -1,6 +1,8 @@
|
||||
using DyeingComputer.View;
|
||||
using DyeingComputer.ViewModel;
|
||||
using OpenTK.Audio.OpenAL;
|
||||
using ScottPlot.Colormaps;
|
||||
using ScottPlot.TickGenerators.TimeUnits;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
@@ -8,6 +10,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using static DyeingComputer.UserClass.SqliteHelper;
|
||||
|
||||
@@ -15,46 +18,87 @@ namespace DyeingComputer.UserClass
|
||||
{
|
||||
public class APILog
|
||||
{
|
||||
static bool QueueT=false;
|
||||
private static SQLiteHelper SQLiteHelpers = null; //定义数据库
|
||||
private readonly static string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
|
||||
private readonly static string LOGAddress = Environment.CurrentDirectory + "\\DataBase\\LOG.db"; //数据库路径
|
||||
|
||||
public async static void DBlog(string Name ,string ID ,string Api,string MESSAGE)
|
||||
public class QueueString
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
Dictionary<string, object> API_LOG = new Dictionary<string, object>();//缓存函数
|
||||
API_LOG.Add("NAME",Name);
|
||||
API_LOG.Add("ID", ID);
|
||||
API_LOG.Add("API", Api);
|
||||
API_LOG.Add("MESSAGE", MESSAGE);
|
||||
API_LOG.Add("TIME", MainWindowViewModel.SYSTime);
|
||||
|
||||
SQLiteHelpers = new SQLiteHelper(LOGAddress); //数据库连接路径
|
||||
SQLiteHelpers.Open(); //打开数据库
|
||||
SQLiteHelpers.InsertData("SERVER", API_LOG);//行插入
|
||||
SQLiteHelpers.Close(); //关闭连接
|
||||
API_LOG.Clear();
|
||||
});
|
||||
public string ID { get; set; }
|
||||
public Dictionary<string, object> DAT { get; set; }
|
||||
}
|
||||
public async static void LOGlog(string WorkOrder, string TYPE, string Command, string MESSAGE)
|
||||
public static class Queue
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
Dictionary<string, object> API_LOG = new Dictionary<string, object>();//缓存函数
|
||||
API_LOG.Add("WorkOrder", WorkOrder);
|
||||
API_LOG.Add("TYPE", TYPE);
|
||||
API_LOG.Add("Command", Command);
|
||||
API_LOG.Add("MESSAGE", MESSAGE);
|
||||
API_LOG.Add("TIME", MainWindowViewModel.SYSTime);
|
||||
public static string ID { get; set; }
|
||||
public static Dictionary<string, object> DAT { get; set; }
|
||||
}
|
||||
// 创建一个字符串类型的队列
|
||||
public static Queue<QueueString> DBQueue = new Queue<QueueString>();
|
||||
|
||||
SQLiteHelpers = new SQLiteHelper(LOGAddress); //数据库连接路径
|
||||
SQLiteHelpers.Open(); //打开数据库
|
||||
SQLiteHelpers.InsertData("OperationLog", API_LOG);//行插入
|
||||
SQLiteHelpers.Close(); //关闭连接
|
||||
API_LOG.Clear();
|
||||
});
|
||||
public static void DBlog(string Name, string ID, string Api, string MESSAGE)
|
||||
{
|
||||
Dictionary<string, object> API_LOG = new Dictionary<string, object>();//缓存函数
|
||||
API_LOG.Add("NAME", Name);
|
||||
API_LOG.Add("ID", ID);
|
||||
API_LOG.Add("API", Api);
|
||||
API_LOG.Add("MESSAGE", MESSAGE);
|
||||
API_LOG.Add("TIME", MainWindowViewModel.SYSTime);
|
||||
LOGDB("SERVER", API_LOG);//行插入
|
||||
API_LOG.Clear();
|
||||
}
|
||||
public static void LOGlog(string WorkOrder, string TYPE, string Command, string MESSAGE)
|
||||
{
|
||||
Dictionary<string, object> API_LOG = new Dictionary<string, object>();//缓存函数
|
||||
API_LOG.Add("WorkOrder", WorkOrder);
|
||||
API_LOG.Add("TYPE", TYPE);
|
||||
API_LOG.Add("Command", Command);
|
||||
API_LOG.Add("MESSAGE", MESSAGE);
|
||||
API_LOG.Add("TIME", MainWindowViewModel.SYSTime);
|
||||
LOGDB("OperationLog", API_LOG);//行插入
|
||||
API_LOG.Clear();
|
||||
}
|
||||
public static void IOlog(string IOName, string TYPE_ , object dat, string ID="0000", string PLC = "0000")
|
||||
{
|
||||
Dictionary<string, object> API_LOG = new Dictionary<string, object>();//缓存函数
|
||||
API_LOG.Add("IOName", IOName);
|
||||
API_LOG.Add("type", TYPE_);
|
||||
if(TYPE_ == "M") API_LOG.Add("Value", dat);
|
||||
if ((TYPE_ == "AI") ||(TYPE_ == "AO")) API_LOG.Add("AIO", dat);
|
||||
if ((TYPE_ == "DQ") || (TYPE_ == "DO")) API_LOG.Add("DIO", dat);
|
||||
API_LOG.Add("ID", ID);
|
||||
API_LOG.Add("PLC", PLC);
|
||||
API_LOG.Add("TIME", MainWindowViewModel.SYSTime);
|
||||
LOGDB("IOLog", API_LOG);//行插入
|
||||
API_LOG.Clear();
|
||||
}
|
||||
|
||||
public static void LOGDB(string NAME, Dictionary<string, object> dat)
|
||||
{
|
||||
DBQueue.Enqueue(new QueueString
|
||||
{
|
||||
ID = NAME,
|
||||
DAT = dat
|
||||
});
|
||||
|
||||
if (!QueueT)
|
||||
{
|
||||
QueueT = true;
|
||||
LOGDB();
|
||||
}
|
||||
if(DBQueue.Count==0) QueueT=false;
|
||||
}
|
||||
|
||||
public static void LOGDB()
|
||||
{
|
||||
SQLiteHelpers = new SQLiteHelper(LOGAddress); //数据库连接路径
|
||||
SQLiteHelpers.Open(); //打开数据库
|
||||
while (DBQueue.Count > 0)//信息发送队列
|
||||
{
|
||||
QueueString t = DBQueue.Dequeue();
|
||||
SQLiteHelpers.InsertData(t.ID, t.DAT);//行插入
|
||||
}
|
||||
SQLiteHelpers.Close(); //关闭连接
|
||||
QueueT = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user