public static void UpdateProdLineMaterialRcvCount(string _materialNo, byte _productLineNo, string _orderNo, int _receivedCount) {//string _materialNo, byte _productionLineNo, string _orderNo, int _usedCount if (_productLineNo > 0 && _productLineNo < 10 && _orderNo.Length > 0 && _materialNo.Length > 0 && _receivedCount > 0) { int _recordNo = ProductionLineMaterialBLL.GetProdLineMaterialRecord(_materialNo, _productLineNo, _orderNo); if (_recordNo > 0) { int _previousReceivedCount = ProductionLineMaterialBLL.GetProdLineMaterialReceivedCount(_materialNo, _productLineNo, _orderNo); if (ProductionLineMaterialBLL.UpdateProdLineMaterialReceivedCount(_materialNo, _productLineNo, _orderNo, _receivedCount + _previousReceivedCount)) { LogerHelper.ToLog("新物料箱更新database " + _orderNo + ":" + _materialNo + "," + _receivedCount + "+" + _previousReceivedCount, false); } else { LogerHelper.ToLog("更新databse出错 " + _orderNo + ":" + _materialNo + "," + _receivedCount + "+" + _previousReceivedCount, false); } } else { if (ProductionLineMaterialBLL.InsertProdLineMaterial(_materialNo, MaterialInfoBLL.GetMaterialName(_materialNo), 0, _productLineNo, _receivedCount, _orderNo)) { LogerHelper.ToLog("新物料写入database " + _orderNo + ":" + _materialNo + "," + _receivedCount, false); } else { LogerHelper.ToLog("写databse出错 " + _orderNo + ":" + _materialNo + "," + _receivedCount, false); } } } }
public static void UpdateProdLineMaterialUsdCount(string _materialNo, byte _productLineNo, string _orderNo, int _usedCount) {//string _materialNo, byte _productionLineNo, string _orderNo, int _usedCount if (_productLineNo > 0 && _productLineNo < 10 && _orderNo.Length > 0 && _materialNo.Length > 0) { int _previousUsedCount = ProductionLineMaterialBLL.GetProdLineMaterialUsedCount(_materialNo, _productLineNo, _orderNo); int _previousUsedCounter = ProductionLineMaterialBLL.GetProdLineMaterialUsedCounter(_materialNo, _productLineNo, _orderNo); if (ProductionLineMaterialBLL.UpdateProdLineMaterialUsedCount(_materialNo, _productLineNo, _orderNo, _previousUsedCount + _usedCount, _previousUsedCounter + _usedCount)) { LogerHelper.ToLog("物料消耗更新database " + _orderNo + ":" + _materialNo + "," + _previousUsedCount + "-" + _usedCount, false); } else { LogerHelper.ToLog("物料消耗更新database 出错 " + _orderNo + ":" + _materialNo + "," + _previousUsedCount + "-" + _usedCount, false); } } }
private void btnDownloadTags_Click(object sender, EventArgs e) { //MainForm.CheckComPorts(); if (this.listView_CurrentOrder.Items.Count < 1) { SpMessageBox.Show("BOM清单为空,请重新查询订单.", "电子标签下发"); return; } if (this.listView_CurrentOrder.Items.Count > MainForm.SupportedSerialPortNoList.Count) { SpMessageBox.Show("串口设备少于BOM清单数,请检查电子标签设备连接.", "电子标签下发"); return; } int i; for (i = 0; i < this.listView_CurrentOrder.Items.Count; i++) { if (MainForm.SerialPortsList[i] != null) { SerialPort sp = MainForm.SerialPortsList[i]; // find the right 实例化串口通讯类 from the list foreach (var sptmp in MainForm.SerialPortsList) { if (int.Parse(System.Text.RegularExpressions.Regex.Replace(sptmp.PortName, @"[^0-9]+", "").Trim()) == int.Parse(CurrentOrderMaterialsList[i].MaterialSeq.ToString().Trim()) + 9) { //匹配对应的串口, 根据物料的位置号, 获取对应的电子屏COM号, sp = sptmp; break; } } if (!sp.IsOpen) { try { sp.Open();//打开串口 } catch { SpMessageBox.Show("电子标签屏幕所对应的串口" + sp.PortName + "异常, 请检查串口连接.", "下发电子标签"); } } if (sp.IsOpen) { try { if (this.listView_CurrentOrder.Items[i].SubItems[1].Text.Trim().Length > 0) { // key codes //packaging switch pictures cmd byte[] cmds = { 0x5A, 0xA5, 0x07, 0x82, 0x00, 0x84, 0x5A, 0x01, 0x00, 0xFF }; cmds[9] = findLabelNoByMaterialNo(listView_CurrentOrder.Items[i].SubItems[1].Text.Trim()); // set the picture ID according to the 零件号 //cmds[9] = 0x04; // for debug, will delete later //packaging clear desc byte[] clear = { 0x5A, 0xA5, 0x20, 0x82, 0x10, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; clear[5] = findLabelNoByMaterialNo(listView_CurrentOrder.Items[i].SubItems[1].Text.Trim()); //clear[5] = 0x40; // for debug, will delete later //packaging desc byte[] desps = { 0x5A, 0xA5, 0x20, 0x82, 0x10, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; desps[5] = findLabelNoByMaterialNo(listView_CurrentOrder.Items[i].SubItems[1].Text.Trim()); desps[5] = 0x40; // for debug, will delete later byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(this.listView_CurrentOrder.Items[i].SubItems[1].Text.Trim()); byte[] byteArray1 = System.Text.Encoding.Default.GetBytes(this.listView_CurrentOrder.Items[i].SubItems[1].Text.Trim()); for (int j = 0; j < byteArray.Length; j++) { desps[6 + j] = byteArray[j]; } byte[] readbuffer = new byte[50]; try { sp.Write(cmds, 0, cmds.Length);//发送切换picture指令 System.Threading.Thread.Sleep(50); //sp.Read(readbuffer, 0, 20); //接收串口返回消息 } catch (Exception ex) { SpMessageBox.Show(sp.PortName + "告警:" + ex.Message, "下发电子标签"); } //Array.Clear(readbuffer, 0 , 50); //sp.Write(clear, 0, clear.Length);//clear零件号描述 的指令 //sp.Read(readbuffer, 0, 20); //Array.Clear(readbuffer, 0, 50); //sp.Write(desps, 0, desps.Length);//发送更新零件号描述 指令 //sp.Read(readbuffer, 0, 20); //LogerHelper.ToLog(this.listView_CurrentOrder.Items[i].SubItems[1].ToString() + "|" + "10" + " to " + sp.PortName, true); LogerHelper.ToLog(desps + "|" + "10" + " to " + sp.PortName, true); //if (i == 3) //{ // break; //} } } catch (Exception ex) { SpMessageBox.Show(sp.PortName + "告警:" + ex.Message, "下发电子标签"); } sp.Close(); } } } if (i >= this.listView_CurrentOrder.Items.Count) { ShowLoginTip("电子标签下发成功."); // start the timer to detect the material box usages/consumption MainForm.timer_ReadSensors.AutoReset = true; //设置是执行一次(false)还是一直执行(true); MainForm.timer_ReadSensors.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件; MainForm.ModubusReadCounter = 0; MainForm.TimerFinished = true; //MainForm.SensorsValues = new byte[8]; //切线之前,默认认为货架上的物料被清理干净了 } }