// Field validation is checked before completing. When completed the work order is moved to the // work order history table. // Expected state return value: processState*, New, Error private Control.State ProcessCompleteWorkOrder(Control.State processState) { Control.State result = processState; if (processState == Control.State.Completed) { if (cboItemCode.SelectedItem == null) { erpItemCode.SetError(cboItemCode, "An Item must be selected"); result = processState; } else { erpItemCode.Clear(); DataProcess completeOrder = new DataProcess(ActiveSession.CompanyODBC); string won = txtWorkOrderNo.Text; string prt = cboProductType.SelectedItem.ToString(); string prl = cboProductionLine.SelectedItem.ToString(); string whs = cboWarehouse.SelectedItem.ToString(); string itc = cboItemCode.SelectedItem.ToString(); string itd = txtItemDescription.Text; string plu = txtPlannedUOM.Text; string plq = txtPlannedQuantity.Text; string pld = dtpPlannedDate.Text; string pls = txtPlannedShift.Text; string plc = txtProductionLineCapacity.Text; string mil = txtReOrderPoint.Text; string bas = txtBatchSize.Text; string nob = txtBatchNo.Text; string cun = (cboCustomerOrderNo.SelectedIndex == -1) ? "" : cboCustomerOrderNo.SelectedItem.ToString(); string fgo = (cboFGWorkOrderNo.SelectedIndex == -1) ? "" : cboFGWorkOrderNo.SelectedItem.ToString(); string sta = nameof(Control.Status.Okay); string amq = txtActualManufacturedQty.Text; string acs = txtActualShift.Text; string acd = dtpActualDate.Text; string com = txtComments.Text; string crd = txtCreatedDate.Text; string cru = txtCreatedUser.Text; string lmd = txtLastModifiedDate.Text; string lmu = txtLastModifiedUser.Text; List <string> validateErrors = completeOrder.Validate( won, prt, prl, whs, itc, itd, plu, plq, pld, pls, plc, mil, nob, bas, cun, fgo, sta, amq, acs, acd, com, crd, cru, lmd, lmu ); if (validateErrors.Count > 0) { string errors = "The following fields did not pass data validation:\n"; foreach (string s in validateErrors) { errors = string.Format("{0}\n{1}", errors, s); } Utilities.ShowError(errors, "Data Validation Error"); result = processState; } else { if (completeOrder.AddHistory()) { ProcessRecordLogHistory(completeOrder, Log); Utilities.ShowMessage(string.Format("Work Order {0} completed.", won), "Add"); result = Control.State.New; } else { Utilities.ShowMessage(string.Format("Work Order {0} was not completed.", won), "Failed"); ActiveState = Control.State.Error; result = processState; } } } } else { result = Control.State.Error; } return(result); }