123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- using System;
- using System.Data;
- using UAS_LabelMachine.CustomControl;
- using UAS_LabelMachine.Entity;
- namespace UAS_LabelMachine.PublicMethod
- {
- class LogicHandler
- {
- static SqliteDBHelper adh = SystemInf.adh;
- static DataHelper dh = SystemInf.dh;
- /// <summary>
- /// 更新为已复核
- /// </summary>
- /// <param name="iPibID"></param>
- public static void UpdateRowRechecked(object iPibID)
- {
- adh.UpdateByCondition("prodiobarcode", "pib_ifcheck=-1", "pib_id=" + iPibID);
- }
- /// <summary>
- /// 更新为已打印
- /// </summary>
- /// <param name="iPibID"></param>
- public static void UpdateRowPrinted(object iPibID)
- {
- adh.UpdateByCondition("prodiobarcode", "pib_ifprint=-1", "pib_id=" + iPibID);
- }
- /// <summary>
- /// 更新为已采集
- /// </summary>
- /// <param name="iPibID"></param>
- public static void UpdateRowPicked(object iPibID)
- {
- adh.UpdateByCondition("prodiobarcode", "pib_ifpick=-1,pib_modify=-1", "pib_id=" + iPibID);
- }
- /// <summary>
- /// 根据对应的动作查找字段发送指令
- /// </summary>
- /// <param name="PLC"></param>
- /// <param name="Movement"></param>
- public static void SendDataToPLC(SerialPortWithTag PLC, string Movement, SqliteDBHelper adh)
- {
- DataTable dt = (DataTable)adh.ExecuteSql("select * from plcinstruct", "select");
- if (PLC.IsOpen && dt.Rows.Count > 0)
- {
- string DevStart = dt.Rows[0][Movement].ToString();
- byte[] newbyte = new byte[1];
- newbyte[0] = (byte)Convert.ToInt32(DevStart == "" ? "0" : DevStart, 16);
- PLC.Write(newbyte, 0, 1);
- }
- }
- public static void GetBarCode(string iPIID, string iPDID, int BarCodeNum, out string oBarCode)
- {
- oBarCode = "";
- string[] param = new string[] { iPIID, iPDID, BarCodeNum.ToString(), "", "", "", "", "", "", oBarCode };
- dh.CallProcedure("GETCUSTBARCODERULE", ref param);
- oBarCode = param[9];
- }
- 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";
- oDay = "0";
- oDate = "19000101";
- string[] param = new string[] { iDatecode, iCustcode, oYear, oMonth, oDay, oDate };
- dh.CallProcedure("GETTIMEFROMDATECODE", ref param);
- oYear = param[2];
- oMonth = param[3];
- oDay = param[4];
- oDate = param[5];
- }
- /// <summary>
- /// 获取十六进制字节数组
- /// </summary>
- /// <param name="Data"></param>
- /// <returns></returns>
- public static byte[] SendPLCData(string Data)
- {
- byte[] arr = new byte[1];
- arr[0] = (byte)Convert.ToInt32(Data, 16);
- return arr;
- }
- /// <summary>
- /// 检测数据库未上传的数据,根据设置的上传条数上传数据
- /// </summary>
- /// <param name="iInoutno"></param>
- public static bool CheckUploadData(string iInoutno, int iUploadNum)
- {
- DataTable dt = (DataTable)adh.ExecuteSql("select pib_id,pib_outboxcode1,pib_outboxcode2,pib_custmidboxcode,pib_custoutboxcode,pib_lotno,pib_datecode,pib_ifmodify,pib_ifupload,pib_ifpick,pib_ifprint,pib_ifrecheck,pib_year,pib_month,pib_day from prodiobarcode where pib_inoutno='" + iInoutno + "' ", "select");
- DataTable upload = BaseUtil.filterDataTable(dt, "pib_ifupload=0 and pib_ifrecheck=-1");
- DataTable unupload = BaseUtil.filterDataTable(dt, "pib_ifpick=0");
- //如果本地需要上传的数据已经达到了需要上传的条数或者已经采集完了最后一条数据
- for (int i = 0; i < upload.Rows.Count; i++)
- {
- upload.Rows[i]["pib_ifupload"] = -1;
- }
- if (iUploadNum <= upload.Rows.Count || unupload.Rows.Count == 0)
- {
- dh.CallProcedure("sp_uploadbarcode", upload);
- //更新本地数据为已上传
- if (adh.UpdateByCondition("prodiobarcode", "pib_ifupload=-1", "pib_inoutno='" + iInoutno + "' and pib_ifrecheck=-1 and pib_ifupload<>-1") > 0)
- {
- return true;
- }
- }
- return false;
- }
- /// <summary>
- /// 检测数据库未上传的数据,根据设置的上传条数上传数据
- /// </summary>
- /// <param name="iInoutno"></param>
- public static bool CheckUploadData(string iInoutno)
- {
- DataTable dt = (DataTable)adh.ExecuteSql("select count(1) from prodiobarcode where pib_inoutno='" + iInoutno + "' and pib_ifupload=0 and pib_ifrecheck=-1 ", "select");
- if (dt.Rows[0][0].ToString() != "")
- {
- int rowcount = int.Parse(dt.Rows[0][0].ToString());
- for (int i = 0; i < rowcount; i++)
- {
- if (i % 100 == 0 || i == rowcount - 1)
- {
- dt = (DataTable)adh.ExecuteSql("select pib_id,pib_outboxcode1,pib_outboxcode2,pib_custmidboxcode,pib_custoutboxcode,pib_lotno,pib_datecode,pib_ifmodify,-1 as pib_ifupload,pib_ifpick,pib_ifprint,pib_ifrecheck,pib_year,pib_month,pib_day from prodiobarcode where pib_inoutno='" + iInoutno + "' and pib_ifupload=0 and pib_ifrecheck=-1 limit " + 150, "select");
- string pibid = "";
- if (dt.Rows.Count > 0)
- {
- dh.CallProcedure("sp_uploadbarcode", dt, out pibid);
- dt = (DataTable)dh.ExecuteSql("select count(1) from prodiobarcode where pib_inoutno='" + iInoutno + "' and pib_ifupload=0", "select");
- if (dt.Rows.Count > 0)
- {
- //全部数据上传之后更新单据状态
- if (int.Parse(dt.Rows[0][0].ToString()) == 0)
- {
- dh.ExecuteSql("update prodinout set pi_pdastatus='已复核' where pi_inoutno='" + iInoutno + "'", "update");
- }
- }
- //更新本地数据为已上传
- if (adh.UpdateByCondition("prodiobarcode", "pib_ifupload=-1", "pib_id in (" + pibid + ")") > 0)
- {
- //return true;
- }
- }
- }
- }
- }
- return true;
- }
- }
- }
|