Pārlūkot izejas kodu

新增数据库链接

章政 6 gadi atpakaļ
vecāks
revīzija
8aaaac5bce

+ 2 - 0
UAS-出货标签管理(吉利通)/Entity/SystemInf.cs

@@ -3,6 +3,8 @@
     class SystemInf
     {
         public static DataHelper dh;
+        //备用数据库链接,防止主链接被释放
+        public static DataHelper dh1;
 
         public static AccessDBHelper adh;
 

+ 4 - 0
UAS-出货标签管理(吉利通)/Login.cs

@@ -12,6 +12,8 @@ namespace UAS_LabelMachine
     public partial class Login : Form
     {
         DataHelper dh;
+
+        DataHelper dh1;
         //后端操作
         AccessDBHelper adh1;
         //数据上传操作
@@ -34,11 +36,13 @@ namespace UAS_LabelMachine
         private void Login_Load(object sender, EventArgs e)
         {
             dh = new DataHelper();
+            dh1 = new DataHelper();
             //启动时压缩数据库
             BaseUtil.CompactAccessDB("LabelPrint.accdb");
             adh1 = new AccessDBHelper("LabelPrint.accdb");
             adh2 = new AccessDBHelper("LabelPrint.accdb");
             SystemInf.dh = dh;
+            SystemInf.dh1 = dh1;
             SystemInf.back_adh = adh1;
             SystemInf.adh = adh2;
             //获取账套信息

+ 1 - 1
UAS-出货标签管理(吉利通)/PublicMethod/LogicHandler.cs

@@ -63,7 +63,7 @@ namespace UAS_LabelMachine.PublicMethod
             oBarCode = param[9];
         }
 
-        public static void GetTimeFromDatecode(string iDatecode, string iCustcode, out string oYear, out string oMonth, out string oDay, out string oDate)
+        public static void GetTimeFromDatecode(DataHelper dh,string iDatecode, string iCustcode, out string oYear, out string oMonth, out string oDay, out string oDate)
         {
             oYear = "0";
             oMonth = "0";

+ 13 - 11
UAS-出货标签管理(吉利通)/UAS_出货标签管理.cs

@@ -24,6 +24,8 @@ namespace UAS_LabelMachine
 
         DataHelper dh;
 
+        DataHelper dh1;
+
         AccessDBHelper adh;
 
         AccessDBHelper back_adh;
@@ -136,6 +138,7 @@ namespace UAS_LabelMachine
             //用计时器重置数据库链接
             LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
             dh = SystemInf.dh;
+            dh1 = SystemInf.dh1;
             adh = SystemInf.adh;
             back_adh = SystemInf.back_adh;
             CheckForIllegalCrossThreadCalls = false;
@@ -360,7 +363,6 @@ namespace UAS_LabelMachine
                         }
                         break;
                     case "BackendCheck":
-
                         BackCheck.Text = msg;
                         if (BackendCheckFunction(msg, "Auto", out ErrorMsg))
                         {
@@ -460,7 +462,7 @@ namespace UAS_LabelMachine
                                         string month = "";
                                         string day = "";
                                         string date = "";
-                                        LogicHandler.GetTimeFromDatecode(DateCode, pi_cardcode.Text, out year, out month, out day, out date);
+                                        LogicHandler.GetTimeFromDatecode(dh,DateCode, pi_cardcode.Text, out year, out month, out day, out date);
                                         System.DateTime dtime;
                                         //有效期比对
                                         if (System.DateTime.TryParseExact(date, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dtime))
@@ -700,7 +702,7 @@ namespace UAS_LabelMachine
                             dr[0]["pib_datecode"] = DateCode;
                             try
                             {
-                                LogicHandler.GetTimeFromDatecode(DateCode, pi_cardcode.Text, out year, out month, out day, out date);
+                                LogicHandler.GetTimeFromDatecode(dh1,DateCode, pi_cardcode.Text, out year, out month, out day, out date);
                                 dr[0]["pib_year"] = year;
                                 dr[0]["pib_month"] = month;
                                 dr[0]["pib_day"] = day;
@@ -776,7 +778,7 @@ namespace UAS_LabelMachine
                     //解析DateCode,将值设置到年月日
                     try
                     {
-                        LogicHandler.GetTimeFromDatecode(DateCode, pi_cardcode.Text, out year, out month, out day, out date);
+                        LogicHandler.GetTimeFromDatecode(dh1,DateCode, pi_cardcode.Text, out year, out month, out day, out date);
                         LabelInf.Rows[CurrentRowIndex].Cells["pib_year"].Value = year;
                         LabelInf.Rows[CurrentRowIndex].Cells["pib_month"].Value = month;
                         LabelInf.Rows[CurrentRowIndex].Cells["pib_day"].Value = day;
@@ -2320,7 +2322,7 @@ namespace UAS_LabelMachine
             string month = "0";
             string day = "0";
             string date = "";
-            LogicHandler.GetTimeFromDatecode(datecode, pi_cardcode.Text, out year, out month, out day, out date);
+            LogicHandler.GetTimeFromDatecode(dh1,datecode, pi_cardcode.Text, out year, out month, out day, out date);
             adh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_ifmodify=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno, "update");
             LoadGridData();
             setvalue.FindForm().Close();
@@ -2336,7 +2338,7 @@ namespace UAS_LabelMachine
             string month = "0";
             string day = "0";
             string date = "";
-            LogicHandler.GetTimeFromDatecode(datecode, pi_cardcode.Text, out year, out month, out day, out date);
+            LogicHandler.GetTimeFromDatecode(dh1,datecode, pi_cardcode.Text, out year, out month, out day, out date);
             adh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_ifmodify=-1,pib_ifprint=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno, "update");
             LoadGridData();
             DataTable pibid_dt = (DataTable)adh.ExecuteSql("select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno, "select");
@@ -2366,7 +2368,7 @@ namespace UAS_LabelMachine
             //解析DateCode,将值设置到年月日
             try
             {
-                LogicHandler.GetTimeFromDatecode(DateCode, pi_cardcode.Text, out year, out month, out day, out date);
+                LogicHandler.GetTimeFromDatecode(dh,DateCode, pi_cardcode.Text, out year, out month, out day, out date);
                 LabelInf.Rows[CurrentRowIndex].Cells["pib_year"].Value = year;
                 LabelInf.Rows[CurrentRowIndex].Cells["pib_month"].Value = month;
                 LabelInf.Rows[CurrentRowIndex].Cells["pib_day"].Value = day;
@@ -2375,8 +2377,6 @@ namespace UAS_LabelMachine
             int outboxcode1 = int.Parse(Process_midboxcode.Text == "" ? "1" : Process_midboxcode.Text);
             int outboxcode2 = int.Parse(Process_outboxcode.Text == "" ? "1" : Process_outboxcode.Text);
             string pd_id = LabelInf.Rows[CurrentRowIndex].Cells["pd_id"].Value.ToString();
-            //获取上一行的数据
-            DataTable LastRowData = null;
             //如果满容量获取过箱号就不再重复获取了
             bool GetBarcode = false;
             //获取当前的行号
@@ -2392,7 +2392,8 @@ namespace UAS_LabelMachine
             }
             else if (CurrentRowNum - 1 > 0)
             {
-                LastRowData = (DataTable)adh.ExecuteSql("select pib_lotno,pib_custmidboxcode,pib_custoutboxcode,pd_pocode,pd_custprodcode,pd_custprodspec,pib_datecode from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and rownum=" + (CurrentRowNum - 1), "select");
+                //获取上一行的数据
+                DataTable LastRowData = (DataTable)adh.ExecuteSql("select pib_lotno,pib_custmidboxcode,pib_custoutboxcode,pd_pocode,pd_custprodcode,pd_custprodspec,pib_datecode from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and rownum=" + (CurrentRowNum - 1), "select");
                 string custmidboxcode = LastRowData.Rows[0]["pib_custmidboxcode"].ToString();
                 if (custmidboxcode == "")
                 {
@@ -2475,7 +2476,8 @@ namespace UAS_LabelMachine
             }
             else if (CurrentRowNum - 1 > 0)
             {
-                LastRowData = (DataTable)adh.ExecuteSql("select pib_lotno,pib_custmidboxcode,pib_custoutboxcode,pd_pocode,pd_custprodcode,pd_custprodspec,pib_datecode from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and rownum=" + (CurrentRowNum - 1), "select");
+                //获取上一行数据
+                DataTable LastRowData = (DataTable)adh.ExecuteSql("select pib_lotno,pib_custmidboxcode,pib_custoutboxcode,pd_pocode,pd_custprodcode,pd_custprodspec,pib_datecode from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and rownum=" + (CurrentRowNum - 1), "select");
                 string custoutboxcode = LastRowData.Rows[0]["pib_custoutboxcode"].ToString();
                 if (custoutboxcode == "")
                 {