//提交fail 登记 private void btn_addfaillog_Click(object sender, EventArgs e) { ServiceReference.ServiceClient client = new ServiceReference.ServiceClient(); try { string strfailsfc = txtBox_registeredsfc.Text; if (string.IsNullOrWhiteSpace(txtBox_registeredsfc.Text)) { SendMsgShow("SFC 信息为空,请检查", 2); return; } if (string.IsNullOrWhiteSpace(ktxtBox_orderno.Text)) { SendMsgShow("工单 信息为空,请检查", 2); return; } if (string.IsNullOrWhiteSpace(kComboBox_Process1.Text)) { SendMsgShow("测试工序 信息为空,请检查", 2); return; } //if (string.IsNullOrWhiteSpace(kComboBox_TestStation.Text)) //{ // SendMsgShow("测试工位 信息为空,请检查", 2); // return; //} //if (string.IsNullOrWhiteSpace(txtBox_empname.Text)) //{ // SendMsgShow("测试人 信息为空,请检查", 2); // return; //} //检查员工号是否正常???? double dfailqty = 0; //是否需要拆分批次 if (kryptonCheckBox1.Checked == true) { if (string.IsNullOrWhiteSpace(txtBox_newregisteredsfc.Text)) { SendMsgShow("新的批次号为空,请检查", 2); return; } if (string.IsNullOrWhiteSpace(KtxtBox_newregisteredsfcNum.Text)) { SendMsgShow("新的批次号的数量为空,请检查", 2); return; } if (double.Parse(KtxtBox_newregisteredsfcNum.Text.Trim()) - double.Parse(kTxtBox_SFCQty.Text.Trim()) >= 0.000001) { dfailqty = 0; MessageBox.Show("拆分批次数量大于或等于总数量 ", "错误"); return; } strfailsfc = txtBox_newregisteredsfc.Text; } ////////////////////////////////////////////////////// string wipdata = client.RunServerAPI("BLL.WIP", "GetWipQty1ByLot", txtBox_registeredsfc.Text); if (!string.IsNullOrEmpty(wipdata)) { decimal SumNum = 0; for (int i = 0; i < dataGridView_faildesc.RowCount; i++) { decimal num = Convert.ToDecimal(this.dataGridView_faildesc.Rows[i].Cells["strfailNum"].Value.ToString()); if (num != 0) { SumNum += num; } } decimal wipqty = Convert.ToDecimal(wipdata); if (SumNum > wipqty) { MessageBox.Show("该批次已使用,线边仓剩余数量小于登记不良数量 ", "提示"); return; } } ///////////////////////////////////////////////////// try { if (KtxtBox_newregisteredsfcNum.Enabled == false) { dfailqty = double.Parse(kTxtBox_SFCQty.Text.Trim()); } else { dfailqty = double.Parse(KtxtBox_newregisteredsfcNum.Text.Trim()); } } catch (Exception exp) { MessageBox.Show("请输入正确数量 " + exp.Message, "提示"); return; } int iisProcess = 0; // 提交维修登记时,如果现象中都是不需要处理的,则维修状态为-1=不需要处理,否则维修状态为0=需要处理; List <NGCode_Data> lstcurrngcode = new List <NGCode_Data>(); for (int i = 0; i < dataGridView_faildesc.Rows.Count; i++) { //如果DataGridView是可编辑的,将数据提交,否则处于编辑状态的行无法取到 dataGridView_faildesc.EndEdit(); DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dataGridView_faildesc.Rows[i].Cells["bselect"]; Boolean flag = Convert.ToBoolean(checkCell.Value); if (flag == true) //查找被选择的数据行 { //从 DATAGRIDVIEW 中获取数据项 NGCode_Data clngcode = new NGCode_Data(); clngcode.failPhenomenoncode = dataGridView_faildesc.Rows[i].Cells[0].Value.ToString().Trim(); clngcode.failPhenomenondesc = dataGridView_faildesc.Rows[i].Cells[1].Value.ToString().Trim(); clngcode.failtypecode = dataGridView_faildesc.Rows[i].Cells[2].Value.ToString().Trim(); clngcode.strfailNum = dataGridView_faildesc.Rows[i].Cells[3].Value.ToString().Trim(); clngcode.isProcess = dataGridView_faildesc.Rows[i].Cells[4].Value.ToString().Trim(); if (clngcode.isProcess == "是") { iisProcess = 1; } double dfailNum = double.Parse(clngcode.strfailNum); if (dfailNum <= 0.0000001) { SendMsgShow("不良现象[" + clngcode.failPhenomenoncode + "]对应数量为0 请检查", 2); lstcurrngcode.Clear(); return; } if ((dfailNum - dfailqty) > 0.0000001) { SendMsgShow("不良现象[" + clngcode.failPhenomenoncode + "]对应数量大于总数量, 请检查", 2); lstcurrngcode.Clear(); return; } lstcurrngcode.Add(clngcode); } } if (lstcurrngcode.Count <= 0) { SendMsgShow("未选择不良现象, 请检查", 2); return; } if (kryptonCheckBox1.Checked) { if (txtBox_newregisteredsfc.Text == txtBox_registeredsfc.Text) { SendMsgShow("拆分新批次不能与批次号相同", 2); return; } string jsdata = client.RunServerAPI("BLL.SFC", "GetSfcState", txtBox_newregisteredsfc.Text); if (!string.IsNullOrEmpty(jsdata)) { SendMsgShow("拆分批次号已存在,请更改", 2); return; } //如果有新的批次号,需要将主批次号的过站记录复制到新的批次号中 int iRet = CreateNewSFCInfo(txtBox_registeredsfc.Text, txtBox_newregisteredsfc.Text, double.Parse(KtxtBox_newregisteredsfcNum.Text.Trim())); if (iRet == 0) { //strfailsfc = txtBox_newregisteredsfc.Text; //kTxtBox_SFCQty.Text = KtxtBox_newregisteredsfcNum.Text; } else { MessageBox.Show("拆分批次失败 ", "错误"); return; } } //在P_FailLog表中增加不良记录 //获取P_Date string str = ""; str = client.RunServerAPI("BLL.Faillog", "GetPDate", strGroupCode); DateTime dPdate = new DateTime(); dPdate = DateTime.Parse(str); P_FailLog dtpfaillog = new P_FailLog(); dtpfaillog.fguid = Guid.NewGuid().ToString(); dtpfaillog.order_no = ktxtBox_orderno.Text; dtpfaillog.sfc = strfailsfc; //dtpfaillog.from_process= dtpfaillog.from_process = dicTestProcessInfo[kComboBox_Process1.Text]; //来源工序id //dtpfaillog.from_station = dicTestStationInfo[kComboBox_TestStation.Text]; //来源工站id dtpfaillog.process_code = dicTestProcessInfo[kComboBox_Process1.Text]; //当前工序id,责任工序,先预设维修工序id,再在维修中来修改 dtpfaillog.from_emp = g_stremp; dtpfaillog.fail_times = 1; dtpfaillog.p_date = dPdate; dtpfaillog.class_code = client.RunServerAPI("BLL.Faillog", "GetClassCode", strGroupCode); dtpfaillog.Disposal_Process = g_stremp; dtpfaillog.ws_code = g_strWorkShopCode; if (iRepairProcc == 3) { dtpfaillog.state = 9; //报废 iisProcess = 1; } else { if (iisProcess == 1) { dtpfaillog.state = 0; //后续会根据不良现象来判断是否需要给“-1”, } else { dtpfaillog.state = -1; } } dtpfaillog.qty = (decimal)dfailqty; dtpfaillog.ng_remark = richTextBox_ng_remark.Text.Trim(); string strJson = JsonConvert.SerializeObject(dtpfaillog); str = ""; str = client.RunServerAPI("BLL.Faillog", "AddFailLog", strJson); if (string.IsNullOrWhiteSpace(str) || str == "0") { SendMsgShow("增加不良记录失败", 2); return; } //在P_Fail_Detail表中增加不良记录 for (int i = 0; i < lstcurrngcode.Count; i++) { P_Fail_Detail clpfiledetail = new P_Fail_Detail(); clpfiledetail.fguid = dtpfaillog.fguid; clpfiledetail.order_no = ktxtBox_orderno.Text; clpfiledetail.sfc = strfailsfc; clpfiledetail.ng_code = lstcurrngcode[i].failPhenomenoncode; clpfiledetail.qty = decimal.Parse(lstcurrngcode[i].strfailNum); clpfiledetail.ws_code = g_strWorkShopCode; strJson = JsonConvert.SerializeObject(clpfiledetail); str = ""; str = client.RunServerAPI("BLL.Fail_Detail", "AddFail_Detail", strJson); if (string.IsNullOrWhiteSpace(str) || str == "0") { SendMsgShow("增加不良明细失败", 2); return; } } //更新P_SFC_State 当前工序和过站时间 +P_SFC_Process_IOLog 当前工序和工站 if (iisProcess == 1) //如果需要处理,才更新state表信息??? { str = ""; //order,sfc,nowprocess,state,failtimes,pass,grade_id,grade_type,iofailtimes strJson = ktxtBox_orderno.Text + "," + strfailsfc + "," + dicTestProcessInfo[kComboBox_Process1.Text] + "," + "0" + "," + "1" + "," + "0" + "," + "grade_id" + "," + "grade_type" + "," + "1" + "," + dicTestProcessInfo[kComboBox_Process1.Text]; str = client.RunServerAPI("BLL.SFC", "UpDataSFCInfoAndSFCIOLogData", strJson); if (!str.Contains("OK")) { SendMsgShow("更新P_SFC_State 失败 Or P_SFC_Process_IOLog 失败," + str, 2); return; } } SendMsgShow("提交不良信息已完成", 0); //判断是否需要快速报废 if (iRepairProcc == 3) { P_SFC_State clpsfcstateTmp = new P_SFC_State(); clpsfcstateTmp.order_no = ktxtBox_orderno.Text; clpsfcstateTmp.SFC = strfailsfc; clpsfcstateTmp.fail_times = 0; clpsfcstateTmp.state = -1; //设置状态为 -1 ,已报废 clpsfcstateTmp.now_process = "END"; //order,sfc,nowprocess,state,failtimes,pass,grade_id,grade_type,iofailtimes strJson = clpsfcstateTmp.order_no + "," + strfailsfc + "," + "END" + "," + "-1" + "," + "0" + "," + "0" + "," + "grade_id" + "," + "grade_type" + "," + "0" + "," + dicTestProcessInfo[kComboBox_Process1.Text]; str = client.RunServerAPI("BLL.SFC", "UpDataSFCInfoAndSFCIOLogData", strJson); if (!str.Contains("OK")) { MessageBox.Show("更新P_SFC_State 失败 Or P_SFC_Process_IOLog 失败," + str, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } ClearFormPar(); txtBox_registeredsfc.Text = ""; } catch (Exception exp) { SendMsgShow(exp.Message, 2); } return; }
//提交操作 private void btn_reback_Click(object sender, EventArgs e) { ServiceReference.ServiceClient client = new ServiceReference.ServiceClient(); try { if (string.IsNullOrWhiteSpace(richTextBox_faildesc.Text.Trim())) { MessageBox.Show("请给出维修说明,在记录中填写", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrWhiteSpace(kComboBox_Process.Text.Trim())) { MessageBox.Show("请选择责任工序", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //修改数据库信息,1.P_SFC_State(如果P_SFC_State表中存在记录才修改), //更新P_SFC_State 当前工序和过站时间 +P_SFC_Process_IOLog 当前工序 int ishebeifail = 0; string str = ""; List <P_Fail_Detail> lstpFailDetail = new List <P_Fail_Detail>(); for (int i = 0; i < dataGridView_faildetail.Rows.Count; i++) { P_Fail_Detail onepfaildetail = new P_Fail_Detail(); onepfaildetail.id = int.Parse(dataGridView_faildetail.Rows[i].Cells["detail_id"].Value.ToString()); if ((this.dataGridView_faildetail.Rows[i].Cells["failReasoncode"] as DataGridViewComboBoxCell).Value == null) { MessageBox.Show("原因代码为空,请选择", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } onepfaildetail.reason_code = dicReason[(string)(this.dataGridView_faildetail.Rows[i].Cells["failReasoncode"] as DataGridViewComboBoxCell).Value]; if (onepfaildetail.reason_code.Contains("EEE")) //判断是否为设备不良原因代码 { ishebeifail = 1; } if ((this.dataGridView_faildetail.Rows[i].Cells["failtype"] as DataGridViewComboBoxCell).Value == null) { MessageBox.Show("原因类型代码为空,请选择", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } onepfaildetail.reasontype_code = dicTypeReason[(string)(this.dataGridView_faildetail.Rows[i].Cells["failtype"] as DataGridViewComboBoxCell).Value]; lstpFailDetail.Add(onepfaildetail); } //order,sfc,nowprocess,state,failtimes,pass,grade_id,grade_type,iofailtimes if (checkBox1.Checked == true) { if (checkedListBox1.CheckedItems.Count > 0) { for (int items = 0; items < checkedListBox1.CheckedItems.Count; items++) { string judecode = ((ComboboxItem)checkedListBox1.CheckedItems[items]).Value; string judename = ((ComboboxItem)checkedListBox1.CheckedItems[items]).Text; string SFC = textBox_sfc.Text.ToString(); string JudeCodeJson = client.RunServerAPI("BLL.SFC", "GetJudeSFC", judecode + "," + SFC); if (string.IsNullOrEmpty(JudeCodeJson)) { P_SFC_Jude sfc_jude = new P_SFC_Jude() { jude_code = judecode, jude_name = judename, sfc = SFC, state = 0 }; string judejson = JsonToolsNet.ObjectToJson(sfc_jude); client.RunServerAPI("BLL.SFC", "InsertSFCJude", judejson); } else { MessageBox.Show("该批次已存在[ " + judename + " ]的待判,不可重复", "提示"); return; } } } else { MessageBox.Show("请勾选待判名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } string strJson = ""; P_SFC_State clpsfcstateTmp = new P_SFC_State(); clpsfcstateTmp.order_no = strorderno; clpsfcstateTmp.SFC = strsfc; clpsfcstateTmp.fail_times = 0; if (iRepairProcc == 1) //降级 { if (string.IsNullOrWhiteSpace(kComboBox_ProductGrade.Text.Trim())) { MessageBox.Show("请先设置级别", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrWhiteSpace(kComboBox_rebackprocess.Text.Trim())) { MessageBox.Show("请先设置返回工序", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } clpsfcstateTmp.from_process = strfromprocess_code; clpsfcstateTmp.now_process = diczrprocess[this.kComboBox_rebackprocess.Text.ToString().Trim()]; if (clpsfcstateTmp.now_process == "END") { clpsfcstateTmp.state = 2;//该批次已完成,可以流向下一工序 } else { clpsfcstateTmp.state = 1; //设置状态为 1 ,未完成,,正常加工 } B_Product_Grade clBProductGrade = new B_Product_Grade(); clBProductGrade = dicProductGrade[kComboBox_ProductGrade.Text.Trim()]; clpsfcstateTmp.grade_id = clBProductGrade.grade_id.ToString(); clpsfcstateTmp.grade_type = clBProductGrade.grade_type; //order,sfc,nowprocess,state,failtimes,pass,grade_id,grade_type,iofailtimes strJson = strorderno + "," + strsfc + "," + diczrprocess[this.kComboBox_rebackprocess.Text.ToString().Trim()] + "," + "1" + "," + "0" + "," + "0" + "," + clBProductGrade.grade_id + "," + clBProductGrade.grade_type + "," + "0" + "," + strfromprocess_code; } else if (iRepairProcc == 2) //待判 { //待完善??? } else if (iRepairProcc == 3) //报废 { clpsfcstateTmp.state = -1; //设置状态为 -1 ,已报废 clpsfcstateTmp.now_process = "END"; //order,sfc,nowprocess,state,failtimes,pass,grade_id,grade_type,iofailtimes strJson = strorderno + "," + strsfc + "," + "END" + "," + "-1" + "," + "0" + "," + "0" + "," + "grade_id" + "," + "grade_type" + "," + "0" + "," + strfromprocess_code; } else //不做操作,直接返回指定工序 { if (string.IsNullOrWhiteSpace(kComboBox_rebackprocess.Text.Trim())) { MessageBox.Show("请先设置返回工序", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } clpsfcstateTmp.state = 1; //设置状态为 1 ,未完成,,正常加工 clpsfcstateTmp.now_process = diczrprocess[this.kComboBox_rebackprocess.Text.ToString().Trim()]; //order,sfc,nowprocess,state,failtimes,pass,grade_id,grade_type,iofailtimes strJson = strorderno + "," + strsfc + "," + diczrprocess[this.kComboBox_rebackprocess.Text.ToString().Trim()] + "," + "1" + "," + "0" + "," + "0" + "," + "grade_id" + "," + "grade_type" + "," + "0" + "," + strfromprocess_code; } str = client.RunServerAPI("BLL.SFC", "UpDataSFCInfoAndSFCIOLogData", strJson); if (!str.Contains("OK")) { MessageBox.Show("更新P_SFC_State 失败 Or P_SFC_Process_IOLog 失败," + str, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //更新维修结果 P_FailLog P_Fail_Detail P_FailLog clpfaillog = new P_FailLog(); clpfaillog.fid = int.Parse(strfid); if (!string.IsNullOrWhiteSpace(kComboBox_Process.Text.Trim())) { clpfaillog.process_code = strfromprocess_code; clpfaillog.Disposal_Process = strfromprocess_code; #region //if (diczrprocess.Keys.Contains(kComboBox_Process.Text.Trim())) //{ // clpfaillog.process_code = diczrprocess[kComboBox_Process.Text.Trim()]; //} //else //{ // MessageBox.Show("请选择责任工序!"); // return; //} //clpfaillog.Disposal_Process = diczrprocess[kComboBox_Process.Text.Trim()]; #endregion //根据责任工序,找到责任人和工位 strJson = ""; strJson = strsfc + "," + clpfaillog.process_code; str = client.RunServerAPI("BLL.SFC", "GetSFCIOLogInfo", strJson); if (string.IsNullOrWhiteSpace(str)) { // } else { List <P_SFC_Process_IOLog> lstsfciolog = JsonConvert.DeserializeObject <List <P_SFC_Process_IOLog> >(str); if (lstsfciolog.Count > 0) { clpfaillog.emp_code = lstsfciolog[0].emp_code; } if (ishebeifail == 1) //存在设备不良,需要根据工位代码找到设备代码 { //根据工位,找到设备 str = client.RunServerAPI("BLL.Station", "GetStationEquipmentByStation", lstsfciolog[0].station_code); if (string.IsNullOrWhiteSpace(str)) { // } else { List <B_StationMachine> lststationequipment = JsonConvert.DeserializeObject <List <B_StationMachine> >(str); if (lstsfciolog.Count > 0) { clpfaillog.equipment_code = lststationequipment[0].machine_code; } } } } } if (iRepairProcc == 1) //降级 { clpfaillog.state = 1; } else if (iRepairProcc == 2) //待判 { //待完善??? } else if (iRepairProcc == 3) //报废 { clpfaillog.state = 9; //报废状态 } else { clpfaillog.state = 1; } if (!string.IsNullOrWhiteSpace(richTextBox_faildesc.Text.Trim())) { clpfaillog.repair_remark = richTextBox_faildesc.Text.Trim(); } str = ""; str = client.RunServerAPI("BLL.Faillog", "UpdateFailLog", JsonConvert.SerializeObject(clpfaillog)); if (!str.Contains("1")) { MessageBox.Show("更新P_FailLog 失败" + str, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } str = ""; str = client.RunServerAPI("BLL.Fail_Detail", "UpdateFail_Detail", JsonConvert.SerializeObject(lstpFailDetail)); if (!str.Contains("1")) { MessageBox.Show("更新P_Fail_Detail 失败" + str, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } catch (Exception exp) { MessageBox.Show("提交失败:" + exp.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //提交完成 MessageBox.Show("维修完成", "OK", MessageBoxButtons.OK, MessageBoxIcon.None); this.Close(); }