using Gm_WMS.DataAccess.DataService; using Stone.Common; using Stone.Entity; using Stone.WinBiz.Preordering; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Stone.WinModule.Preordering { public partial class frmOnLineScan : Form { #region 初始化 private HtmlDocument doc = null; public frmOnLineScan() { InitializeComponent(); } private void frmPreordering_Load(object sender, EventArgs e) { this.webBrowser1.Navigate(Application.StartupPath + "\\html\\上线扫描.html"); } private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { try { doc = webBrowser1.Document; timer2.Enabled = true; ShowData(); } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } } #endregion #region 事件 private void txtBarCode_KeyDown(object sender, KeyEventArgs e) { if(e.KeyCode == Keys.Enter) { ScanBarCode(); } } private void timer1_Tick(object sender, EventArgs e) { if (!this.txtBarCode.Focused) { this.txtBarCode.Focus(); this.txtBarCode.SelectAll(); } } private void timer2_Tick(object sender, EventArgs e) { try { ShowData(); } catch (Exception ex) { this.lblMsg.Text = ex.Message; } } private void btnExit_Click(object sender, EventArgs e) { this.Close(); } #endregion #region 自定义方法 private void ScanBarCode() { try { this.lblMsg.Text = ""; string BarCode = this.txtBarCode.Text.Trim().ToUpper(); if (BarCode == "") throw new Exception("条码不能为空"); ScanBarCode(BarCode); } catch (Exception ex) { this.lblMsg.Text = ex.Message; } finally { this.txtBarCode.Focus(); this.txtBarCode.SelectAll(); } } private void ScanBarCode(string BarCode) { LocalDBService db = null; try { db = new LocalDBService(); db.BeginTrans(); Entity_t_JIS_Assemble t_JIS_Assemble = new Entity_t_JIS_Assemble(db); Entity_t_JIS_List t_JIS_List = new Entity_t_JIS_List(); Entity_t_StationLine t_StationLine = new Entity_t_StationLine(db); Entity_t_LED t_LED = new Entity_t_LED(db); DataTable dtData = t_JIS_Assemble.GetData($"[productionNumber]='{BarCode}' and [IsOnline]=0").Tables[0]; if (Convert.ToInt32(dtData.Rows[0]["IsCheck"]) == 0) throw new Exception($"{BarCode} 未做预排序扫描"); if (Convert.ToInt32(dtData.Rows[0]["IsOnline"]) == 1) throw new Exception($"{BarCode} 重复上线扫描"); t_JIS_Assemble.Edit("[IsOnline]=1, [OnlineTime]=getdate()", $"[ID]='{dtData.Rows[0]["ID"]}'"); int StationCode = 0; if (t_StationLine.GetData("[StationCode]=1").Tables[0].Rows.Count == 0) { StationCode = 1; } DataTable dtList = t_JIS_List.GetData("[ItemNumber]", "[productionNumber]='" + dtData.Rows[0]["productionNumber"].ToString() + "'", "[ID] asc").Tables[0]; string itemNumbers = GetItems(dtList); //写数据到生成线上去 DataRow drStationLine = t_StationLine.Table.NewRow(); drStationLine["JisID"] = dtData.Rows[0]["ID"].ToString(); drStationLine["StationCode"] = StationCode; drStationLine["CarModelCode"] = dtData.Rows[0]["CarModelCode"].ToString(); drStationLine["productionNumber"] = dtData.Rows[0]["productionNumber"].ToString(); drStationLine["itemNumber"] = dtData.Rows[0]["itemNumber"].ToString(); drStationLine["description"] = dtData.Rows[0]["description"].ToString(); drStationLine["sequenceNumber"] = dtData.Rows[0]["sequenceNumber"].ToString(); drStationLine["assemblyDate"] = dtData.Rows[0]["assemblyDate"]; drStationLine["BillNo"] = dtData.Rows[0]["BillNo"].ToString(); drStationLine["vehicleModelCode"] = dtData.Rows[0]["vehicleModelCode"].ToString(); drStationLine["lineStationCode_aliasName"] = dtData.Rows[0]["lineStationCode_aliasName"].ToString(); drStationLine["partType"] = dtData.Rows[0]["partType"].ToString(); drStationLine["ColorName"] = dtData.Rows[0]["ColorName"].ToString(); drStationLine["BarCode"] = dtData.Rows[0]["BarCode"].ToString(); drStationLine["LUS"] = itemNumbers.Replace("'", ""); drStationLine["IsInsert"] = dtData.Rows[0]["IsInsert"].ToString(); t_StationLine.Add(drStationLine); //写数据到亮灯 DataRow drLED = t_LED.Table.NewRow(); drLED["productionNumber"] = dtData.Rows[0]["productionNumber"].ToString(); drLED["partType"] = dtData.Rows[0]["partType"].ToString(); drLED["itemNumber"] = dtData.Rows[0]["itemNumber"].ToString(); drLED["description"] = dtData.Rows[0]["description"].ToString(); drLED["ColorName"] = dtData.Rows[0]["ColorName"].ToString(); drLED["LUS"] = itemNumbers.Replace("'", ""); drLED["CarModelCode"] = dtData.Rows[0]["CarModelCode"].ToString(); t_LED.Add(drLED); db.Commit(); } catch (Exception ex) { if (db != null) db.Rollback(); throw ex; } finally { if (db != null) db.EndTrans(); } ShowData(); } private void ShowData() { Entity_t_JIS_Assemble t_JIS_Assemble = new Entity_t_JIS_Assemble(); DataSet dsData = t_JIS_Assemble.GetData("top 4 *", "[IsCheck]=1 and [IsOnline]=0", "[BillNo] asc, [Sort] asc"); //显示前4个 for (int i = 0; i < 4; i++) { doc.GetElementById("lbl_sequenceNumber_" + (i + 1)).InnerHtml = " "; doc.GetElementById("lbl_description_" + (i + 1)).InnerHtml = " "; doc.GetElementById("lbl_ColorName_" + (i + 1)).InnerHtml = " "; doc.GetElementById("lbl_assemblyDate_" + (i + 1)).InnerHtml = " "; doc.GetElementById("lbl_productionNumber_" + (i + 1)).InnerHtml = " "; } for (int i = 0; i < dsData.Tables[0].Rows.Count; i++) { doc.GetElementById("lbl_sequenceNumber_" + (i + 1)).InnerHtml = dsData.Tables[0].Rows[i]["BillNo"].ToString() + " " + dsData.Tables[0].Rows[i]["Sort"].ToString(); doc.GetElementById("lbl_description_" + (i + 1)).InnerHtml = dsData.Tables[0].Rows[i]["description"].ToString(); doc.GetElementById("lbl_ColorName_" + (i + 1)).InnerHtml = dsData.Tables[0].Rows[i]["ColorName"].ToString(); doc.GetElementById("lbl_assemblyDate_" + (i + 1)).InnerHtml = dsData.Tables[0].Rows[i]["assemblyDate"].ToString(); doc.GetElementById("lbl_productionNumber_" + (i + 1)).InnerHtml = dsData.Tables[0].Rows[i]["productionNumber"].ToString(); } } public string GetItems(DataTable dtList) { string ret = ""; foreach (DataRow drData in dtList.Rows) { ret += "'" + drData["itemNumber"].ToString() + "',"; } if (ret != "") ret = ret.Substring(0, ret.Length - 1); return ret; } #endregion } }