/// <summary> /// 报工 /// </summary> /// <param name="eqmNo">设备编号</param> /// <returns>报工信息</returns> public Model.ProductBarcode Submit(string eqmNo) { long sqlLast = GetMaxId(eqmNo); long accessLast = GetMaxId(); Model.ProductBarcode barcode = GetCurrentSubmitRecord(sqlLast, accessLast, eqmNo); SubmitMesFb(barcode, eqmNo); return(barcode); }
/// <summary> /// 私有方法,计时器函数(报工业务) /// </summary> /// <param name="sender">触发计时器事件的对象</param> /// <param name="e">计时器事件的句柄</param> private void timSubmit_Tick(object sender, EventArgs e) { timSubmit.Enabled = false; Ctrl.EqmLock eqmLock = new Ctrl.EqmLock(); eqmLock.GetEqmLock(MyDataUniversal.EqmNo); if (MyDataUniversal.EnumEqmStatus != Client.Ctrl.DataUniversal.EqmStatus.Working) { timSubmit.Enabled = false; return; } Ctrl.SubmitCtrl subCtrl = new Ctrl.SubmitCtrl(); Model.ProductBarcode barcode = subCtrl.Submit(MyDataUniversal.EqmNo); ReLoadData(barcode.MpoNo); if (barcode.Result.ToLower() == "ng") { timSubmit.Enabled = false; NextProductModel = barcode; btnQcCauseSave.BackColor = Color.Red; return; } timSubmit.Enabled = true; }
/// <summary> /// 报工记录提交并将新提交的报工记录返回 /// </summary> /// <param name="barcode">记录信息</param> /// <param name="eqmNo">设备编号</param> /// <returns>报工记录</returns> public Model.TableModel.Mes_fb SubmitMesFb(Model.ProductBarcode barcode, string eqmNo) { if (barcode == null) { return(null); } //如果上次报过工,就不报了 if (barcode.IsLastSubmit) { return(null); }//一定不是上一次报工的记录 DateTime actTime = DateTime.Now; actTime = DateTime.TryParse(barcode.ProductDate + " " + barcode.ProductTime, out actTime)?actTime:DateTime.Now; string userNo = barcode.User; string tmpUser = DataLoadCtrl.LoadFieldByColumn("worker_no", "worker_name", barcode.User, "mes_worker"); userNo = tmpUser == "UNKNOWN" ? userNo : tmpUser; if (barcode.SerialNoExist)//该序列号存在,这个序列号必定存在报工记录 { Model.TableModel.Mes_fb_item mesFbItem = GetMesFbItem(barcode.ProductSerialNo, eqmNo); Model.TableModel.Mes_fb mesFb = GetMesFb(barcode.MpoNo, eqmNo); Model.TableModel.Mpo mpo = GetMpo(barcode.MpoNo); if (mesFbItem == null || mesFb == null || mpo == null) { return(null); } string result = mesFbItem.quality_no == "QA01" ? "OK" : "NG"; if (result != barcode.Result) { if (barcode.Result == "OK") { mesFb.fb_end_qty_ok += 1; mesFb.fb_end_qty_ng -= 1; mesFbItem.quality_no = "QA01"; if (IsLastEqm(eqmNo)) { mpo.procedure_finished_qty += 1; } } else { mesFb.fb_end_qty_ok -= 1; mesFb.fb_end_qty_ng += 1; mesFbItem.quality_no = "QA04"; if (IsLastEqm(eqmNo)) { mpo.procedure_finished_qty -= 1; } } if (mpo.mpo_qty <= mpo.procedure_finished_qty) { mpo.procedure_status_name = "已完工"; } } mesFb.upd_time = actTime; mesFb.upd_user_name = barcode.User; mesFb.upd_user_no = userNo; mesFb.fb_end_datetime = actTime; mesFb.worker_no = userNo; mesFb.worker_name = barcode.User; mesFb.fb_time = actTime; mesFbItem.upd_time = actTime; mesFbItem.upd_user_name = barcode.User; mesFbItem.upd_user_no = userNo; mesFbItem.fb_datetime = actTime; mesFbItem.worker_no = userNo; mesFbItem.worker_name = barcode.User; mesFbItem.in_id = barcode.ID; int b = DbEngine.QueryInt <Model.TableModel.Mes_fb>("update", new List <Model.TableModel.Mes_fb>() { mesFb }); if (b > 0) { b = DbEngine.QueryInt <Model.TableModel.Mes_fb_item>("update", new List <Model.TableModel.Mes_fb_item>() { mesFbItem }); if (b > 0) { b = DbEngine.QueryInt <Model.TableModel.Mes_fb_info>("insert", barcode.SubmitInfo); if (b > 0) { DbEngine.QueryInt <Model.TableModel.Mpo>("update", new List <Model.TableModel.Mpo>() { mpo }); } } } } else //序列号不存在,则一定不存在报工记录 { bool isNeedUpdateMpo = true; //检测生产订单号 Model.TableModel.Mpo mpo = GetMpo(barcode.MpoNo); if (mpo == null) { isNeedUpdateMpo = false; mpo = new Model.TableModel.Mpo(); mpo.id = "virtualMpo"; mpo.mpo_no = barcode.MpoNo; mpo.part_no = barcode.ProductTypeNo; mpo.mpo_qty = 0; mpo.mpo_hope_start_datetime = DateTime.Now; mpo.mpo_hope_end_datetime = DateTime.Now; mpo.commit_status_no = "310"; mpo.commit_status_name = "已下发"; mpo.procedure_finished_qty = 0; mpo.procedure_status_name = "已开工"; } Model.TableModel.Mes_fb mesFb = new Model.TableModel.Mes_fb(); mesFb.id = Common.Md5Operate.CreateGuidId(); mesFb.status_no = "310"; mesFb.status_name = "已确认"; mesFb.crt_time = actTime; mesFb.crt_user_name = barcode.User; mesFb.crt_user_no = userNo; mesFb.upd_time = actTime; mesFb.upd_user_name = barcode.User; mesFb.upd_user_no = userNo; mesFb.fb_no = DataBllCtrl.GetNextNoByTblName("mes_fb"); mesFb.mpo_no = mpo.mpo_no; mesFb.part_no = barcode.ProductTypeNo; mesFb.fb_start_datetime = actTime; mesFb.fb_end_datetime = actTime; if (barcode.Result == "OK") { mesFb.fb_end_qty_ok = 1; if (IsLastEqm(eqmNo)) { mpo.procedure_finished_qty += 1; } } else { mesFb.fb_end_qty_ng = 1; } mesFb.worker_no = userNo; mesFb.worker_name = barcode.User; mesFb.fb_time = actTime; mesFb.eqm_no = eqmNo; mesFb.eqm_name = DataLoadCtrl.LoadFieldByColumn("eqm_name", "eqm_no", eqmNo, "pdm_eqm"); mesFb.factory_no = "dfs_f"; Model.TableModel.Mes_fb_item mesFbItem = new Model.TableModel.Mes_fb_item(); mesFbItem.id = Common.Md5Operate.CreateGuidId(); mesFbItem.status_no = "310"; mesFbItem.status_name = "已确认"; mesFbItem.crt_time = actTime; mesFbItem.crt_user_name = barcode.User; mesFbItem.crt_user_no = userNo; mesFbItem.upd_time = actTime; mesFbItem.upd_user_name = barcode.User; mesFbItem.upd_user_no = userNo; mesFbItem.fb_item_no = DataBllCtrl.GetNextNoByTblName("mes_fb_item"); mesFbItem.serial_no = barcode.ProductSerialNo; mesFbItem.fb_no = mesFb.fb_no; mesFbItem.mpo_no = mpo.mpo_no; mesFbItem.part_no = barcode.ProductTypeNo; mesFbItem.fb_datetime = actTime; mesFbItem.quality_no = barcode.Result == "OK" ? "QA01" : "QA04"; mesFbItem.worker_no = userNo; mesFbItem.worker_name = barcode.User; mesFbItem.eqm_no = eqmNo; mesFbItem.eqm_name = mesFb.eqm_name; mesFbItem.wkc_no = "PSH On BYD"; mesFbItem.wkc_name = "PSH On BYD生产线"; mesFbItem.in_id = barcode.ID; int b = DbEngine.QueryInt <Model.TableModel.Mes_fb>("insert", new List <Model.TableModel.Mes_fb>() { mesFb }); if (b > 0) { b = DbEngine.QueryInt <Model.TableModel.Mes_fb_item>("insert", new List <Model.TableModel.Mes_fb_item>() { mesFbItem }); if (b > 0) { b = DbEngine.QueryInt <Model.TableModel.Mes_fb_info>("insert", barcode.SubmitInfo); if (b > 0 && isNeedUpdateMpo) { DbEngine.QueryInt <Model.TableModel.Mpo>("update", new List <Model.TableModel.Mpo>() { mpo }); } } } } return(null); }
/// <summary> /// 将数据行转换为序列号实体类 /// </summary> /// <param name="dr">数据行</param> /// <param name="eqmNo">设备编号</param> /// <returns>报工信息</returns> public Model.ProductBarcode ChangeDataRowToObject(DataRow dr, string eqmNo) { Model.ProductBarcode barcode = new Model.ProductBarcode(); barcode.SubmitInfo = new List <Model.TableModel.Mes_fb_info>(); DataTable dt = dr.Table; for (int i = 0; i < dr.ItemArray.Count(); i++) { switch (dt.Columns[i].ColumnName) { case "ID": barcode.ID = long.Parse((dr["ID"] ?? "0").ToString()); break; case "生产日期": barcode.ProductDate = (dr["生产日期"] ?? DateTime.Now.Date).ToString();; break; case "生产时间": barcode.ProductTime = (dr["生产时间"] ?? "00:00:00").ToString(); break; case "产品型号": barcode.ProductTypeNo = (dr["产品型号"] ?? "TypeNo").ToString(); break; case "产品序列号": barcode.ProductSerialNo = (dr["产品序列号"] ?? "VirtualSerialNo").ToString(); string mpoNo = DataLoadCtrl.LoadFieldByColumn("mpo_no", "serial_no", barcode.ProductSerialNo, "mpo_item"); barcode.MpoNo = mpoNo == "UNKNOWN" ? "VirtualMpoNo" : mpoNo; break; case "操作者": barcode.User = (dr["操作者"] ?? "Server").ToString(); break; case "判定": barcode.Result = (dr["判定"] ?? "NG").ToString().ToLower() == "ok" ? "OK" : "NG"; break; default: Model.TableModel.Mes_fb_info model = new Model.TableModel.Mes_fb_info(); model.id = Common.Md5Operate.CreateGuidId(); model.serial_no = string.IsNullOrEmpty(barcode.ProductSerialNo) ? "VirtualSerialNo" : barcode.ProductSerialNo; model.eqm_no = eqmNo; model.part_no = barcode.ProductTypeNo; model.information = dt.Columns[i].ColumnName; model.information_value = (dr[dt.Columns[i].ColumnName] ?? string.Empty).ToString(); DateTime dtTmp = DateTime.Now; model.create_time = string.IsNullOrEmpty(barcode.ProductDate + " " + barcode.ProductTime) ? DateTime.Now : DateTime.TryParse(barcode.ProductDate + " " + barcode.ProductTime, out dtTmp) ? dtTmp : DateTime.Now; barcode.SubmitInfo.Add(model); break; } } if (string.IsNullOrEmpty(barcode.ProductSerialNo)) { barcode.ProductSerialNo = "VirtualSerialNo"; } long serialId = GetLastInId4SerialNo(string.IsNullOrEmpty(barcode.ProductSerialNo) ? "SerialNo" : barcode.ProductSerialNo, eqmNo); barcode.SerialNoExist = serialId > 0; barcode.IsLastSubmit = serialId == barcode.ID; barcode.User = string.IsNullOrEmpty(barcode.User) ? "Server" : barcode.User; barcode.MpoNo = string.IsNullOrEmpty(barcode.MpoNo) ? "VirtualMpoNo" : barcode.MpoNo; return(barcode); }