From 1d9f82659dbfdfd6ac0ddbb33f1fd5af1164d939 Mon Sep 17 00:00:00 2001 From: yangle <admin@YINMOU> Date: 星期五, 29 十一月 2024 16:52:14 +0800 Subject: [PATCH] 浸渍 铁芯检测 无尘 单品过站 不能开工不能过站控制 --- WFormSynchronizeData_SMR/WFormReadData_SMR/DBHelper.cs | 254 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 244 insertions(+), 10 deletions(-) diff --git a/WFormSynchronizeData_SMR/WFormReadData_SMR/DBHelper.cs b/WFormSynchronizeData_SMR/WFormReadData_SMR/DBHelper.cs index 606667f..21fbdca 100644 --- a/WFormSynchronizeData_SMR/WFormReadData_SMR/DBHelper.cs +++ b/WFormSynchronizeData_SMR/WFormReadData_SMR/DBHelper.cs @@ -1,10 +1,14 @@ -锘縰sing System; +锘縰sing Newtonsoft.Json; +using System; using System.Collections.Generic; +using System.Configuration; using System.Data; using System.Data.SqlClient; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; namespace WFormReadData_SMR { @@ -38,16 +42,27 @@ } public DBHelper() { - sServer = "47.96.97.237,15127"; - sDataBase = "HX_LMESsys"; - sUser = "HX_USER"; - sPassword = "lc@841022"; - //鏂帿灏� - //sServer = "10.11.18.195"; - //sDataBase = "HX_LMESsys_test"; - //sUser = "HX_USER"; - //sPassword = "lc@841022"; + sServer = GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "Config/SQLAPI.config", "sServer"); //"10.11.18.195"; + sDataBase = GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "Config/SQLAPI.config", "sDataBase"); //"HX_LMESsys_test"; + sUser = GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "Config/SQLAPI.config", "sUser"); //"HX_USER"; + sPassword = GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "Config/SQLAPI.config", "sPassword");// "lc@841022"; } + + public static String GetConfigKey(String configPath, String key) + { + Configuration ConfigurationInstance = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap() + { + ExeConfigFilename = configPath + }, ConfigurationUserLevel.None); + + + if (ConfigurationInstance.AppSettings.Settings[key] != null) + return ConfigurationInstance.AppSettings.Settings[key].Value; + else + + return string.Empty; + } + private bool CnOpen()//OPEN鏁版嵁搴撹繛鎺� { @@ -253,5 +268,224 @@ return null; } } + public static Int64 isLong(object message) + { + try + { + return Convert.ToInt64(message); + } + catch (Exception e) + { + return 0; + } + } + public static string isStrNull(object message) + { + try + { + if (message == null) + { + return ""; + } + else + { + return message.ToString().Trim(); + } + } + catch (Exception e) + { + return ""; + } + } + + public static int isInt(object message) + { + try + { + return Convert.ToInt16(message); + } + catch (Exception e) + { + return 0; + } + } + + public Int64 CreateBillID_Prod(string BillCode, ref string sReturn) + { + try + { + string BillType = ""; + DataSet Ds; + Int64 lID; + Ds = RunProcReturn("exec h_p_Xt_GetMaxBillID '" + BillCode + "'", "h_p_Xt_GetMaxBillID"); + if (Ds == null || Ds.Tables[0].Rows.Count == 0) + { + lID = -1; + } + else + { + lID = DBHelper.isLong(Ds.Tables[0].Rows[0]["HBillNo"]); + } + CnClose(); + CnDispose(); + Ds = null; + return lID; + } + catch (Exception e) + { + return -2; + } + } + private static readonly object lockObj = new object(); + //鍐欐棩蹇� + public static void CustomWriteLog(object obj, string FileName, string filePath = "Vlog", bool isAppend = true) + { + try + { + lock (lockObj) + { + filePath = $@"{filePath}\{FileName}.txt"; + + filePath = AppDomain.CurrentDomain.BaseDirectory + filePath; + + if (!System.IO.Directory.Exists(Path.GetDirectoryName(filePath))) + { + System.IO.Directory.CreateDirectory(Path.GetDirectoryName(filePath)); + } + + bool fileExists = System.IO.File.Exists(filePath); + //涓嶅瓨鍦� 鍒欏垱寤鸿鏂囦欢 + if (!fileExists) + { + System.IO.File.Create(filePath).Close(); + } + + using (StreamWriter writer = new StreamWriter(filePath, isAppend)) + { + //瀛樺湪鐨勬椂鍊欐墠鍐欎竴琛� + if (fileExists && isAppend) + { + writer.WriteLine(); + } + + var content = obj is string ? obj : JsonConvert.SerializeObject(obj); + writer.WriteLine($"{DateTime.Now} {content}"); + } + } + } + catch (Exception ex) + { + } + } + + //寰楀埌鏈�澶у崟鎹彿 + public string CreateBillCode(string BillCode, ref string sReturn, bool Add) + { + Int64 BillCodeMode; + string Profix; + Int64 Glida; + Int32 CodeLen; + string sBillNo = ""; + char c = Convert.ToChar("0"); + string sKjYear = DateTime.Today.Year.ToString(); + string sPeriod = DateTime.Today.Month.ToString(); + string sDay = DateTime.Today.Day.ToString(); + //寰楀埌鍗曟嵁鍙疯〃 淇℃伅 + DataSet Ds = new DataSet(); + Ds = RunProcReturn("Select * from Gy_BillNumber where BillCode='" + BillCode.Trim() + "'", "Gy_BillNumber"); + if (Ds.Tables[0].Rows.Count != 0) + { + BillCodeMode = DBHelper.isLong(Ds.Tables[0].Rows[0]["BillCodeMode"].ToString()); + Profix = DBHelper.isStrNull(Ds.Tables[0].Rows[0]["Profix"].ToString()); + Glida = DBHelper.isLong(Ds.Tables[0].Rows[0]["Glida"].ToString()); + CodeLen = DBHelper.isInt(Ds.Tables[0].Rows[0]["CodeLen"].ToString()); + } + else + { + return ""; + } + // + string sStr; + switch (BillCodeMode) + { + case 0: + switch (Glida) + { + case 0://绾祦姘村彿 + Ds = RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "'", "Gy_MaxNum"); + if (Ds.Tables[0].Rows.Count != 0) + { + sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length); + sBillNo = Profix.Trim() + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim(); + } + else //鎻掑叆鏂拌褰� + { + sStr = new string(c, CodeLen - 1); + RunProc("insert into Gy_MaxNum(BillCode,NowNumber) values('" + BillCode.Trim() + "',1)"); + sBillNo = Profix.Trim() + sStr + 1; + } + if (Add == true) + { + RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "'"); + } + return sBillNo; + + case 1://鏍规嵁 YY骞�+MM鏈� 鏃� + 娴佹按鍙� 鐢熸垚鍗曟嵁鍙� 锛堟棩 閲囩敤浜� 浠撳簱鐨勫瓧娈碉級 + sKjYear = sKjYear.Substring(2, 2); + sPeriod = "0" + sPeriod; + sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2); + sDay = ""; + Ds = RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'", "Gy_MaxNum"); + if (Ds.Tables[0].Rows.Count != 0) + { + sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length); + sBillNo = Profix.Trim() + sKjYear + sPeriod + sDay + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim(); + } + else //鎻掑叆鏂拌褰� + { + sStr = new string(c, CodeLen - 1); + RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber) values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)"); + sBillNo = Profix.Trim() + sKjYear + sPeriod + sDay + sStr + "1"; + } + if (Add == true) + { + RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'"); + } + return sBillNo; + case 2: //鏍规嵁骞�+鏈�+鏃� 鐢熸垚鍗曟嵁鍙� + Ds = RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'", "Gy_MaxNum"); + if (Ds.Tables[0].Rows.Count != 0) + { + sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length); + sBillNo = Profix.Trim() + sKjYear + DBHelper.isStrNull(("0" + sPeriod)).Substring(DBHelper.isStrNull(("0" + sPeriod)).Length - 2, 2) + DBHelper.isStrNull(("0" + sDay)).Substring(DBHelper.isStrNull(("0" + sDay)).Length - 2, 2) + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim(); + } + else //鎻掑叆鏂拌褰� + { + sStr = new string(c, CodeLen - 1); + RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber) values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)"); + sBillNo = Profix.Trim() + sKjYear + DBHelper.isStrNull(("0" + sPeriod)).Substring(DBHelper.isStrNull(("0" + sPeriod)).Length - 2, 2) + DBHelper.isStrNull(("0" + sDay)).Substring(DBHelper.isStrNull(("0" + sDay)).Length - 2, 2) + sStr + 1; + } + if (Add == true) + { + RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'"); + } + return sBillNo; + + + default: + return sBillNo; + + } + + case 1: + return sBillNo; + + default: + return sBillNo; + + } + CnClose(); + CnDispose(); + } } } -- Gitblit v1.9.1