忱 沈 4 months ago
parent
commit
33b970eff9
  1. 173
      ViewModel/MainWindowViewModel.cs

173
ViewModel/MainWindowViewModel.cs

@ -79,7 +79,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public static string SN_ID;
public static string SN_KEY;
public static bool DyelotsDispenser;
public static SqlConnection conn_SC =new SqlConnection();//数据库
public static SqlConnection conn_SC = new SqlConnection();//数据库
public static SQLiteHelper SQLiteHelpers = null; //定义数据库
private BDC_SQL.BDCSqlHelper bDCSqlHelper = new BDC_SQL.BDCSqlHelper();
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
@ -95,7 +95,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public static int ERR_c = 0;//错误计数器
public bool UPort1, UPort2, UPort3;
public static bool[] USER_Capacity { set; get; } = new bool[99];
public MainWindowViewModel()
{
try
@ -150,15 +150,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
}
else
else
{
for (int i = 0; i < 99; i++)
{
USER_Capacity[i] = true;
{
USER_Capacity[i] = true;
}
}
}
public async void SQL_LINK()//连接dbc数据库
{
if (conn_SC.State == ConnectionState.Open) conn_SC.Close();
@ -180,7 +180,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
LogGing.LogGingDATA("[Database='" + ex + "']=SQLSERVER");
ERR_c++;
}
if (SQMOD == "Windows Authentication") //连接数据库测试
{
bDCSqlHelper.Config(SQLIP, SQLNAME, SQLUSER, SQLPASWORD, true);
@ -258,6 +258,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
dat_.Add("Dye", dataRow["DYELOT"].ToString());
dat_.Add("Time", dataRow["StepTime"].ToString());
dat_.Add("ReDye", dataRow["ReDye"].ToString());
dat_.Add("Program", dataRow["Program"].ToString());
dat_.Add("Step", dataRow["Step"].ToString());
dat_.Add("StepID", dataRow["StepID"].ToString());
dat_.Add("P1", dataRow["Parameter1"].ToString());
@ -400,6 +401,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
dat_.Add("Dye", dt_temp["DYELOT"].ToString());
dat_.Add("STime", dt_temp["StartTime"].ToString());
dat_.Add("Time", dt_temp["Time"].ToString());
dat_.Add("ReDye", 0);
int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderdata_m + "'").ToString());
string dat = "SC810[" + Selet_Machines(Machines, "Station", "ID='" + index + "'") + "]" + dat_.ToJsonString();
@ -648,6 +650,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
});
}
}
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");
}
else if (MachinesRow["Serial"].ToString() == "PORT2")
{
@ -786,7 +789,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
}
if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309")|| (mac_s == "802"))//获取信息
if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309"))//获取信息
{
if (MachinesRow["Serial"].ToString() == "PORT1")
{
@ -885,7 +888,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
else { Time30++; }
}
async void Tick_Event_5S()//Tick_Event周期执行事件5S
{
{
try
{//处理呼叫请求列表完成发送后(202》203)
if (Dyelot_CALL.Select("State='202'").Count() > 0)
@ -1129,55 +1132,37 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
else
{//串口
int index = Convert.ToInt16(MachinesRow["ID"]);
string dat_ = "SC827[" + MachinesRow["Station"] + "]";
if (MachinesRow["Serial"].ToString() == "PORT1")
{
bool exists = stringQueueSerial_1.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_1.Enqueue(new QueueSerial
{
stringQueueSerial_1.Enqueue(new QueueSerial
{
ID = index,
DAT = dat_
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827[" + MachinesRow["Station"] + "]"
});
}
else if (MachinesRow["Serial"].ToString() == "PORT2")
{
bool exists = stringQueueSerial_2.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_2.Enqueue(new QueueSerial
{
stringQueueSerial_2.Enqueue(new QueueSerial
{
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827[" + MachinesRow["Station"] + "]"
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827[" + MachinesRow["Station"] + "]"
});
}
else if (MachinesRow["Serial"].ToString() == "PORT3")
{
bool exists = stringQueueSerial_3.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_3.Enqueue(new QueueSerial
{
stringQueueSerial_3.Enqueue(new QueueSerial
{
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827[" + MachinesRow["Station"] + "]"
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827[" + MachinesRow["Station"] + "]"
});
}
else if (MachinesRow["Serial"].ToString() == "PORT4")
{
bool exists = stringQueueSerial_4.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_4.Enqueue(new QueueSerial
{
stringQueueSerial_4.Enqueue(new QueueSerial
{
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827[" + MachinesRow["Station"] + "]"
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC827[" + MachinesRow["Station"] + "]"
});
}
}
}
@ -1208,55 +1193,37 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
else
{//串口
int index = Convert.ToInt16(MachinesRow["ID"]);
string dat_ = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString();
if (MachinesRow["Serial"].ToString() == "PORT1")
{
bool exists = stringQueueSerial_1.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_1.Enqueue(new QueueSerial
{
stringQueueSerial_1.Enqueue(new QueueSerial
{
ID = index,
DAT = dat_
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString()
});
}
else if (MachinesRow["Serial"].ToString() == "PORT2")
{
bool exists = stringQueueSerial_2.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_2.Enqueue(new QueueSerial
{
stringQueueSerial_2.Enqueue(new QueueSerial
{
ID = index,
DAT = dat_
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString()
});
}
else if (MachinesRow["Serial"].ToString() == "PORT3")
{
bool exists = stringQueueSerial_3.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_3.Enqueue(new QueueSerial
{
stringQueueSerial_3.Enqueue(new QueueSerial
{
ID = index,
DAT = dat_
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString()
});
}
else if (MachinesRow["Serial"].ToString() == "PORT4")
{
bool exists = stringQueueSerial_4.Any(item => item.ID == index && item.DAT == dat_);
if (!exists)
stringQueueSerial_4.Enqueue(new QueueSerial
{
stringQueueSerial_4.Enqueue(new QueueSerial
{
ID = index,
DAT = dat_
});
}
ID = Convert.ToInt16(MachinesRow["ID"]),
DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString()
});
}
}
@ -1297,7 +1264,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
catch (Exception EX) { LogGing.ERRDATA(EX); }
}
public static TcpClient[] MachiensTcpClient = new TcpClient[99];
public static SerialPortClient[] MachiensPortClient = new SerialPortClient[4];
//public static DataRow[] machinesdata = new DataRow[999];
@ -1349,7 +1316,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD1")));
AsyncSerialPortClient._responseEvent.Set();
Port1_link();
Port1_link();
}
if (Machines.Select("Type='false' AND Serial='PORT2'").Length > 0)
{
@ -1392,7 +1359,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
await Task.Run(() =>
{
while (MachiensPortClient[0].Online )
while (MachiensPortClient[0].Online)
{
try
{
@ -1438,7 +1405,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
}
}
});
});
}//发送
private async void Port2_link()
{
@ -1490,7 +1457,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
}
}
});
});
}//发送
private async void Port3_link()
{
@ -1542,7 +1509,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
}
}
});
});
}//发送
private async void Port4_link()
{
@ -1594,7 +1561,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
}
}
});
});
}//发送
public static string SYS_WorkNumder; //工单号
@ -1609,12 +1576,12 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
set { sys_Time = value; OnPropertyChanged("Sys_Time"); }
}
public static string MachineLOG;
/* public string sys_machine; //显示log
public string Sys_machine //通知UI控件参数改变
{
get { return sys_machine; }
set { sys_machine = value; OnPropertyChanged("Sys_machine"); }
}*/
/* public string sys_machine; //显示log
public string Sys_machine //通知UI控件参数改变
{
get { return sys_machine; }
set { sys_machine = value; OnPropertyChanged("Sys_machine"); }
}*/
public static object Selet_Machines(DataTable DB, string name, string key)//查询
{
@ -1628,7 +1595,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
catch (Exception ex)
{
{
LogGing.LogGingDATA("SDTD:" + ex.ToString());
return "ERR";
}
@ -1644,14 +1611,14 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
drEmployee[name] = Value;
drEmployee.EndEdit();
drEmployee.AcceptChanges();
// drEmployee.ClearErrors();
// drEmployee.ClearErrors();
}
}
catch (Exception ex)
{
LogGing.LogGingDATA("SDTD:" + ex.ToString());
{
LogGing.LogGingDATA("SDTD:" + ex.ToString());
}
}
}
public static DataTable dt_d = new DataTable("DIO");
public static DataTable dt_a = new DataTable("AIO");
@ -1660,20 +1627,20 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public static DataTable dt_TP = new DataTable();
public static DataTable dt_ParameterSet = new DataTable();
public static DataTable dt_SysSet = new DataTable();
public static bool TechnologicalProcess_bool =true;
// public static bool A_view =true;
// public static bool D_view =true;
public static bool TechnologicalProcess_bool = true;
// public static bool A_view =true;
// public static bool D_view =true;
public static bool IO_view;
// public static bool ParameterSet_view=true;
// public static bool SysSet_view=true;
// public static bool ParameterSet_view=true;
// public static bool SysSet_view=true;
public static string machine;
public static string workOrder;
public static string dyelot;
public static string machin_LOG;
//通讯队列
public static UInt32 RX=0;
public static UInt32 TX=0;
public static UInt32 RX = 0;
public static UInt32 TX = 0;
public class QueueSerial
{
public int ID { get; set; }

Loading…
Cancel
Save