private void ScanRecordToDb() { try { if (IsHjScan) //合件扫描记录 { #region 封装Model resultModel = new PedalResultMDL(); resultModel.barcode = this.txtHJCode.Text; resultModel.productcode = this.txtProductCode.Text; resultModel.userid = BaseVariable.UserEntity.UserID; resultModel.stationid = BaseVariable.DeviceEntity.StationID; resultModel.createtime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); bool rst = resultDAL.Add(resultModel); //添加到远程服务器数据库 if (!rst) { bool rs = lResultDAL.Add(resultModel); //添加到本地数据库 } #endregion } else //材料扫描记录 { } } catch (Exception ex) { CLog.WriteErrLog(ex.Message); } }
/// <summary> /// 复位操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnReset_Click(object sender, EventArgs e) { try { IsHjScan = true; //合件扫描 IsOK = false; this.Tip("扫描合件号"); this.txtHJCode.Text = ""; this.lblCurrentMaterialCode.Text = ""; resultModel = null; foreach (ListViewItem item in lvMaterial.Items) { item.SubItems[1].Text = ""; //初始化状态为空 item.SubItems[3].Text = "0"; //初始化状态为空 item.ForeColor = Color.Black; //初始化字体颜色为黑色 } } catch (Exception ex) { CLog.WriteErrLog("[FrmScan.btnReset]" + ex.Message); } }
/// <summary> /// 防错追溯,将信息添加到数据库 /// </summary> private void ScanResultToDb() { try { if (resultModel != null) { bool rst = false; if (!BaseVariable.NetworkStatus || !BaseVariable.ServerStatus) //离线状态 { resultModel.createtime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); PedalResultMDL IsExistLocal = lResultDAL.GetModel(string.Format("barcode='{0}' and productcode='{1}'", this.txtHJCode.Text, this.txtProductCode.Text)); if (IsExistLocal != null && !IsExistLocal.tid.ToString().Equals("0")) { resultModel.tid = IsExistLocal.tid; string sql = DataExistToDb(false); rst = LocalDbDAL.ExecuteSql(sql); //存到本地数据库 } else { rst = lResultDAL.Add(resultModel); //添加到本地数据库 } } else //在线状态 { //添加批量追溯信息 GetBatchInfoToModel(); //同步到数据库:在没有同步到远程数据库时记录到本地数据库 #region 步到数据库 resultModel.createtime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); rst = false; //更新到远程服务器数据库是否成功 PedalResultMDL IsExistRomote = resultDAL.GetModel(string.Format("barcode='{0}' and productcode='{1}'", this.txtHJCode.Text, this.txtProductCode.Text)); //更新到远程服务器数据库 if (IsExistRomote != null && !IsExistRomote.tid.ToString().Equals("0")) { resultModel.tid = IsExistRomote.tid; resultModel.createtime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //封装更新字段 string sql = DataExistToDb(true); //sql += string.Format("CreateTime='{0}',", resultModel.CreateTime); rst = CommonDAL.ExecuteSql(sql, null); //存到远程服务器数据库 } else { rst = resultDAL.Add(resultModel); //添加到远程服务器数据库 } //更新到本地数据库 //rst = false; if (!rst) { PedalResultMDL IsExistLocal = lResultDAL.GetModel(string.Format("barcode='{0}' and productcode='{1}'", this.txtHJCode.Text, this.txtProductCode.Text)); if (IsExistLocal != null && !IsExistLocal.tid.ToString().Equals("0")) { resultModel.tid = IsExistLocal.tid; string sql = DataExistToDb(true); rst = LocalDbDAL.ExecuteSql(sql); //存到本地数据库 } else { rst = lResultDAL.Add(resultModel); //添加到本地数据库 } } //批次材料数量更新 foreach (DictionaryEntry item in RemoteMaterialHT) // 遍历哈希表 { string code = item.Key.ToString(); ProductBomInfoMDL obj = item.Value as ProductBomInfoMDL; //var obj = item.Value; BatchNoMDL model = LocalMaterialHT[code] as BatchNoMDL; model.StockNum -= obj.MaterialNum; batchDAL.Update(model); //更新数据 } #endregion if (rst) { this.lblOK.Text = "OK"; this.lblOK.ForeColor = Color.Green; } else { this.lblOK.Text = "NG"; this.lblOK.ForeColor = Color.Red; } BatchChangeTip(); //批次数量提示 } } else { this.Tip("记录错误"); } } catch (Exception ex) { CLog.WriteErrLog("[FrmScan.ScanResultToDB]" + ex.Message); } }
/// <summary> /// 记录扫描信息 /// </summary> private void RecordScanInfo() { try { if (IsHjScan) //合件扫描记录 { #region 封装Model resultModel = new PedalResultMDL(); resultModel.barcode = this.txtHJCode.Text; resultModel.productcode = this.txtProductCode.Text; resultModel.userid = BaseVariable.UserEntity.UserID; resultModel.stationid = BaseVariable.DeviceEntity.StationID; //resultModel.CreateTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); #endregion } else //材料扫描记录 { //字段表 if (!BaseVariable.NetworkStatus || !BaseVariable.ServerStatus) { materialFieldModel = lMaterialFieldDAL.GetModel(string.Format("materialcode='{0}' and materialname='{1}'", materialCode, materialName)); } else { materialFieldModel = materialFieldDAL.GetModel(string.Format("materialcode='{0}' and materialname='{1}'", materialCode, materialName)); } //更改相关信息 #region 对应更新字段 switch (materialFieldModel.FieldName) { //踏板总成 case "pedalassycode": resultModel.pedalassycode = this.lblCurrentMaterialCode.Text; break; //油门踏板 case "accelpedalcode": resultModel.accelpedalcode = this.lblCurrentMaterialCode.Text; break; //离合器把手批次号 case "cluthhandlebatchno": resultModel.cluthhandlebatchno = this.lblCurrentMaterialCode.Text; break; //螺栓批次号 case "boltbatchno": resultModel.boltbatchno = this.lblCurrentMaterialCode.Text; break; //螺母批次号 case "nutbatchno": resultModel.nutbatchno = this.lblCurrentMaterialCode.Text; break; } #endregion } } catch (Exception ex) { CLog.WriteErrLog("[FrmScan.RecordScanInfo]" + ex.Message); } }