/// <summary> /// 上传零件记录 /// </summary> public static void UploadMaterialTable() { try { string sql = string.Format("SELECT * FROM {0}", BaseVariable.ResultTableName); //获取当前产品的数据表 DataTable table = LocalDbDAL.GetDataTable(sql); if (table == null || table.Rows.Count == 0) { return; } //向服务器发送请求,数据上传并返回上传成功的数据TID string IDs = ResultDAL.Upload(BaseVariable.DeviceEntity.ProductType, BaseVariable.ResultTableName, table); if (!string.IsNullOrEmpty(IDs)) { sql = string.Format("DELETE FROM {0} WHERE tid IN ({1});", BaseVariable.ResultTableName, IDs); LocalDbDAL.ExecuteSql(sql);//上传后删除本地数据 CLog.WriteStationLog("Sys", "UploadMaterialTable:TID->{" + IDs + "},Time:{" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "}"); //string[] str = IDs.Split(','); } } catch (Exception ex) { CLog.WriteErrLog(ex.Message); } }
/// <summary> /// 上传零件记录 /// </summary> private void UploadTable() { this.Invoke((EventHandler) delegate { try { Cursor.Current = Cursors.WaitCursor; progressBar.Value = 0; progressBar.Maximum = 1; string sql = string.Format("SELECT * FROM {0}", BaseVariable.ResultTableName); //获取当前产品的数据表 DataTable table = LocalDbDAL.GetDataTable(sql); if (table == null || table.Rows.Count < 1) { return; } //向服务器发送请求,数据上传并返回上传成功的数据TID string IDs = ResultDAL.Upload(BaseVariable.DeviceEntity.ProductType, BaseVariable.ResultTableName, table); if (!string.IsNullOrEmpty(IDs)) { sql = string.Format("DELETE FROM {0} WHERE tid IN ({1});", BaseVariable.ResultTableName, IDs); LocalDbDAL.ExecuteSql(sql);//上传后删除本地数据 string [] str = IDs.Split(','); uploadnum += str.Length; } ProgressTip(1);//更新进度 Cursor.Current = Cursors.Default; } catch (Exception ex) { CLog.WriteErrLog(ex.Message); } }); }
/// <summary> /// 保存数据到本地 /// </summary> /// <returns></returns> private bool SaveToLocal() { string sql = ""; try { //1.整合追溯信息 Hashtable HTResult = GetHashtable(); if (HTResult == null && HTResult.Count < 1) { return(false); } //2.组装SQL语句 sql = AssembleSqlCode(HTResult); bool flag = LocalDbDAL.ExecuteSql(sql); return(flag); } catch (Exception ex) { CLog.WriteErrLog(ex.Message); CLog.WriteStationLog("DataErr", sql); return(false); } }
/// <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); } }