/// <summary> /// 更新批次信息 /// </summary> private void Update(BatchNoMDL model = null) { try { if (model == null)//Insert 方法传过来的 { this.Insert(); return; } else { bool flag = DataDAL.Update(model); if (flag) { ReturnData.Code = "1"; ReturnData.Msg = "OK"; } BatchNoHisDAL HisDAL = new BatchNoHisDAL(); BatchNoHisMDL HisModel = new BatchNoHisMDL(); HisModel.MaterialCode = model.MaterialCode; HisModel.BatchNo = model.BatchNo; HisModel.BatchNum = model.BatchNum; HisModel.Supplier = model.Supplier; HisModel.CreateTime = DateTime.Now; flag = HisDAL.Add(HisModel); } } catch (Exception ex) { CLog.WriteErrLog(ex.Message + ex.StackTrace); } }
/// <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); } }