/// <summary> /// 新增生产批次预设暂停的记录。 /// </summary> /// <param name="db">数据库操作对象。</param> /// <param name="dbtran">数据库操作事务对象。</param> /// <param name="lotKey">生产批次主键。</param> /// <param name="operationName">暂停批次的工序。</param> private static void InsertFutureHold(Database db, DbTransaction dbtran, string lotKey, string operationName) { //根据批次主键和工序名称获取暂停的工艺流程组主键、工艺流程主键、工步主键以及批次信息。 string sql = string.Format(@"SELECT a.ROUTE_ENTERPRISE_VER_KEY,a.ROUTE_ROUTE_VER_KEY,a.ROUTE_STEP_KEY, b.LOT_NUMBER,b.CUR_ROUTE_VER_KEY,b.CUR_STEP_VER_KEY,b.WORK_ORDER_NO FROM V_PROCESS_PLAN a INNER JOIN POR_LOT b ON a.ROUTE_ENTERPRISE_VER_KEY=b.ROUTE_ENTERPRISE_VER_KEY WHERE a.ROUTE_STEP_NAME='{0}' AND b.LOT_KEY='{1}'", operationName.PreventSQLInjection(), lotKey.PreventSQLInjection()); DataSet dsInfo = db.ExecuteDataSet(dbtran, CommandType.Text, sql); if (null != dsInfo && dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0) { DataRow drInfo = dsInfo.Tables[0].Rows[0]; //检查生产批次对应的工步是否设置了预设暂停批次的自定义属性。 sql = string.Format(@"SELECT A.ATTRIBUTE_VALUE FROM POR_ROUTE_STEP_ATTR A,POR_LOT B WHERE A.ROUTE_STEP_KEY =B.CUR_STEP_VER_KEY AND B.LOT_KEY='{0}' AND A.ATTRIBUTE_NAME='{1}'", lotKey.PreventSQLInjection(), ROUTE_STEP_ATTRIBUTE.HoldPassword); string holdPassword = Convert.ToString(db.ExecuteScalar(dbtran, CommandType.Text, sql)); Hashtable htFuturHold = new Hashtable(); WIP_FUTUREHOLD_FIELDS futureHoldField = new WIP_FUTUREHOLD_FIELDS(); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_ACTION_NAME, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_TRACKIN); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_CREATE_TIME, null); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_CREATOR, "system"); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_DELETE_FLAG, 0); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_EDIT_TIME, null); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_EDITOR, "system"); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_ENTERPRISE_KEY, drInfo[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY]); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_HOLD_LEVEL, 1); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_HOLD_PASSWORD, holdPassword); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_LOT_KEY, lotKey); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_LOT_NUMBER, drInfo[POR_LOT_FIELDS.FIELD_LOT_NUMBER]); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_OPERATION_NAME, operationName); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_REASON_CODE, string.Empty); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_REASON_CODE_KEY, string.Empty); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_REASON_CODE_CATEGORY_KEY, string.Empty); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_REASON_CODE_CATEGORY_NAME, string.Empty); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_REMARK, "超出控制规格线。"); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_ROUTE_KEY, drInfo[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_ROW_KEY, UtilHelper.GenerateNewKey(0)); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_SET_ENTERPRISE_KEY, drInfo[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY]); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_SET_ROUTE_KEY, drInfo[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_ROUTE_VER_KEY]); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_SET_STEP_KEY, drInfo[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_KEY]); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_STATUS, 0); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_STEP_KEY, drInfo[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]); htFuturHold.Add(WIP_FUTUREHOLD_FIELDS.FIELDS_WORKORDER_NUMBER, drInfo[POR_LOT_FIELDS.FIELD_WORK_ORDER_NO]); sql = DatabaseTable.BuildInsertSqlStatement(futureHoldField, htFuturHold, null); db.ExecuteNonQuery(dbtran, CommandType.Text, sql); } }
/// <summary> /// 确定按钮Click事件函数。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOk_Click(object sender, EventArgs e) { if (_dsLot == null) { return; } if (_dsParams == null) { return; } DataTable dtLots = _dsLot.Tables[0]; if (dtLots == null || dtLots.Rows.Count == 0) { MessageService.ShowMessage("记录为空,不能进行修改。", "提示"); return; } string enterpriseKey = this._enterpriseKey; string routeKey = this._routeKey; string stepKey = Convert.ToString(this.lueStep.EditValue); string stepName = Convert.ToString(this.lueStep.Text); string action = Convert.ToString(this.lueAction.EditValue); string holdGroupName = Convert.ToString(this.lueHoldGroup.Text); string holdGroupKey = Convert.ToString(this.lueHoldGroup.EditValue); string holdCode = Convert.ToString(this.lueHoldCode.Text); string holdCodeKey = Convert.ToString(this.lueHoldCode.EditValue); string remark = this.meRemark.Text.Trim(); string editor = PropertyService.Get(PROPERTY_FIELDS.USER_NAME); string holdPassword = this.teHoldPassword.Text; string confirmPassword = this.teConfirmPassword.Text; if (string.IsNullOrEmpty(stepKey)) { MessageService.ShowMessage("请先选择暂停工序。", "提示"); this.lueStep.Select(); return; } if (string.IsNullOrEmpty(action)) { MessageService.ShowMessage("请先选择暂停动作。", "提示"); this.lueAction.Select(); return; } if (string.IsNullOrEmpty(holdGroupKey)) { MessageService.ShowMessage("请先选择暂停组别。", "提示"); this.lueHoldGroup.Select(); return; } if (string.IsNullOrEmpty(holdCodeKey)) { MessageService.ShowMessage("请先选择暂停原因。", "提示"); this.lueHoldCode.Select(); return; } //if (string.IsNullOrEmpty(holdPassword)) //{ // MessageService.ShowMessage("请先输入暂停密码。", "提示"); // this.teHoldPassword.Select(); // return; //} if (holdPassword != confirmPassword) { MessageService.ShowMessage("输入的密码不一致,请重新输入。", "提示"); this.teConfirmPassword.Select(); return; } if (string.IsNullOrEmpty(remark)) { MessageService.ShowMessage("请必须输入备注。", "提示"); this.meRemark.Select(); return; } DataSet dsParams = new DataSet(); DataTable dtParams = new DataTable(); dtParams.TableName = WIP_FUTUREHOLD_FIELDS.DATABASE_TABLE_NAME; WIP_FUTUREHOLD_FIELDS field = new WIP_FUTUREHOLD_FIELDS(); foreach (string key in field.FIELDS.Keys) { dtParams.Columns.Add(key); } foreach (DataRow dr in dtLots.Rows) { DataRow drNew = dtParams.NewRow(); string rowkey = this._futureHoldKey; string lotNo = Convert.ToString(dr[POR_LOT_FIELDS.FIELD_LOT_NUMBER]); string lotKey = Convert.ToString(dr[POR_LOT_FIELDS.FIELD_LOT_KEY]); string setEnterpriseKey = Convert.ToString(dr[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY]); string setRouteKey = Convert.ToString(dr[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]); string setStepKey = Convert.ToString(dr[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]); string orderNumber = Convert.ToString(dr[POR_LOT_FIELDS.FIELD_WORK_ORDER_NO]); string editTime = Convert.ToString(_dsParams.Tables[0].Rows[0][WIP_FUTUREHOLD_FIELDS.FIELDS_EDIT_TIME]); drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_ACTION_NAME] = action; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_EDITOR] = editor; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_ENTERPRISE_KEY] = enterpriseKey; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_LOT_KEY] = lotKey; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_LOT_NUMBER] = lotNo; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_OPERATION_NAME] = stepName; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_REASON_CODE] = holdCode; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_REASON_CODE_CATEGORY_KEY] = holdGroupKey; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_REASON_CODE_CATEGORY_NAME] = holdGroupName; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_REASON_CODE_KEY] = holdCodeKey; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_REMARK] = remark; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_ROUTE_KEY] = routeKey; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_SET_ENTERPRISE_KEY] = setEnterpriseKey; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_SET_ROUTE_KEY] = setRouteKey; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_SET_STEP_KEY] = setStepKey; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_STEP_KEY] = stepKey; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_WORKORDER_NUMBER] = orderNumber; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_ROW_KEY] = rowkey; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_HOLD_PASSWORD] = holdPassword; drNew[WIP_FUTUREHOLD_FIELDS.FIELDS_EDIT_TIME] = editTime; dtParams.Rows.Add(drNew); } dsParams.Tables.Add(dtParams); FutureHoldEntity entity = new FutureHoldEntity(); entity.Update(dsParams); if (string.IsNullOrEmpty(entity.ErrorMsg)) { this.DialogResult = DialogResult.OK; this.Close(); } else { MessageService.ShowMessage(entity.ErrorMsg, "错误"); } }