Exemplo n.º 1
0
        /// <summary>
        /// 批次暂停操作。
        /// </summary>
        /// <remarks>
        /// 操作名称:<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_HOLD"/>。
        /// </remarks>
        /// <param name="dsParams">包含批次暂停信息的数据集对象。</param>
        /// <param name="dbTran">数据库操作事务对象。</param>
        public void LotHold(DbTransaction dbTran, DataSet dsParams)
        {
            //参数数据。
            if (dsParams == null ||
                !dsParams.Tables.Contains(WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME) ||
                !dsParams.Tables.Contains(WIP_HOLD_RELEASE_FIELDS.DATABASE_TABLE_NAME) ||
                dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME].Rows.Count == 0 ||  //暂停批次操作记录不能为空记录。
                dsParams.Tables[WIP_HOLD_RELEASE_FIELDS.DATABASE_TABLE_NAME].Rows.Count != 1      //暂停原因只能有一条记录
                )
            {
                throw new Exception("传入参数不正确,请检查。");
            }
            IDbConnection dbConn = dbTran.Connection;
            IDbCommand    dbCmd  = dbConn.CreateCommand();

            dbCmd.Transaction = dbTran;
            dbCmd.CommandType = CommandType.Text;
            DataTable dtTransaction = dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME];   //存放操作数据
            DataTable dtHold        = dsParams.Tables[WIP_HOLD_RELEASE_FIELDS.DATABASE_TABLE_NAME];  //存放批次暂停原因明细数据

            //插入操作记录
            foreach (DataRow drTransaction in dtTransaction.Rows)
            {
                string lotKey   = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]);     //批次主键
                string activity = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]);
                string editor   = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);        //编辑人
                string timeZone = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);        //编辑时区
                //操作动作必须是 HOLD
                if (activity != ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_HOLD)
                {
                    throw new Exception("传入参数的操作动作不正确,请检查。");
                }
                string transKey = UtilHelper.GenerateNewKey(0);
                AddWIPLot(dbTran, transKey, lotKey);
                //向WIP_TRANSACTION表插入批次调整的操作记录。
                WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY] = transKey;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME]       = DBNull.Value;
                string sql = DatabaseTable.BuildInsertSqlStatement(wipFields, drTransaction, null);
                dbCmd.CommandText = sql;
                dbCmd.ExecuteNonQuery();
                //向WIP_HOLD_RELEASE表插入批次暂停的明细记录。
                WIP_HOLD_RELEASE_FIELDS holdFields = new WIP_HOLD_RELEASE_FIELDS();
                dtHold.Rows[0][WIP_HOLD_RELEASE_FIELDS.FIELD_TRANSACTION_KEY] = transKey;
                sql = DatabaseTable.BuildInsertSqlStatement(holdFields, dtHold.Rows[0], null);
                dbCmd.CommandText = sql;
                dbCmd.ExecuteNonQuery();
                //更新批次数据
                StringBuilder sbUpdateSql = new StringBuilder();
                sbUpdateSql.AppendFormat(@"UPDATE POR_LOT 
                                           SET HOLD_FLAG=1,EDITOR='{1}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{2}'
                                           WHERE LOT_KEY='{0}'",
                                         lotKey.PreventSQLInjection(),
                                         editor.PreventSQLInjection(),
                                         timeZone.PreventSQLInjection());
                db.ExecuteNonQuery(dbTran, CommandType.Text, sbUpdateSql.ToString());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///(电池片/组件)不良操作
        /// </summary>
        /// <remarks>
        /// 操作名称:<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_CELLDEFECT"/>和<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_DEFECT"/>。
        /// </remarks>
        /// <param name="dsParams">包含不良信息的数据集对象。</param>
        /// <param name="dbTran">数据库操作事务对象。</param>
        private void LotDefect(DataSet dsParams, DbTransaction dbTran)
        {
            //参数数据。
            if (dsParams == null ||
                !dsParams.Tables.Contains(WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME) ||
                !dsParams.Tables.Contains(WIP_DEFECT_FIELDS.DATABASE_TABLE_NAME) ||
                dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME].Rows.Count == 0         //批次操作记录不能为空记录。
                )
            {
                throw new Exception("传入参数不正确,请检查。");
            }
            DataTable dtTransaction = dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME];             //存放操作数据
            Hashtable htTransaction = CommonUtils.ConvertToHashtable(dtTransaction);
            string    lotKey        = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]); //批次主键
            string    activity      = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]);

            //操作动作必须是 DEFECT 或 CELLDEFECT
            if (activity != ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_CELLDEFECT &&
                activity != ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_DEFECT)
            {
                throw new Exception("传入参数的不良操作动作不正确,请检查。");
            }
            string transactionKey = UtilHelper.GenerateNewKey(0);

            AddWIPLot(dbTran, transactionKey, lotKey);
            //向WIP_TRANSACTION表插入批次不良的操作记录。
            WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();

            if (!htTransaction.ContainsKey(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY))
            {
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
            }
            htTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY] = transactionKey;
            string sql = DatabaseTable.BuildInsertSqlStatement(wipFields, htTransaction, null);

            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
            //如果数据集中包含名称WIP_DEFECT_FIELDS.DATABASE_TABLE_NAME的数据表对象。
            if (dsParams.Tables.Contains(WIP_DEFECT_FIELDS.DATABASE_TABLE_NAME))
            {
                WIP_DEFECT_FIELDS defectFields = new WIP_DEFECT_FIELDS();
                DataTable         dtDefect     = dsParams.Tables[WIP_DEFECT_FIELDS.DATABASE_TABLE_NAME];  //存放不良明细数据
                //遍历批次的不良数据。
                for (int i = 0; i < dtDefect.Rows.Count; i++)
                {
                    DataRow   drDefect = dtDefect.Rows[i];
                    Hashtable htDefect = CommonUtils.ConvertRowToHashtable(drDefect);
                    if (!htDefect.ContainsKey(WIP_DEFECT_FIELDS.FIELD_TRANSACTION_KEY))
                    {
                        htDefect.Add(WIP_DEFECT_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
                    }
                    htDefect[WIP_DEFECT_FIELDS.FIELD_TRANSACTION_KEY] = transactionKey;
                    //插入一笔批次不良数据。
                    sql = DatabaseTable.BuildInsertSqlStatement(defectFields, htDefect, null);
                    db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 批次终止操作
        /// </summary>
        /// <remarks>
        /// 操作名称:<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_TERMINALLOT"/>。
        /// </remarks>
        /// <param name="dsParams">包含批次终止信息的数据集对象。</param>
        /// <param name="dbTran">数据库操作事务对象。</param>
        private void LotTerminal(DataSet dsParams, DbTransaction dbTran)
        {
            //参数数据。
            if (dsParams == null ||
                !dsParams.Tables.Contains(WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME) ||
                dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME].Rows.Count == 0         //批次操作记录不能为空记录。
                )
            {
                throw new Exception("传入参数不正确,请检查。");
            }
            DataTable dtTransaction = dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME];   //存放操作数据
            Hashtable htTransaction = CommonUtils.ConvertToHashtable(dtTransaction);
            string    activity      = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]);
            string    stepKey       = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY]);
            string    lotKey        = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]);
            string    editTimeZone  = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY]);
            string    editor        = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);

            string transactionKey = UtilHelper.GenerateNewKey(0);

            AddWIPLot(dbTran, transactionKey, lotKey);
            //操作动作必须是 TERMINALLOT
            if (activity != ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_TERMINALLOT)
            {
                throw new Exception("传入参数的不良操作动作不正确,请检查。");
            }
            //向WIP_TRANSACTION表插入批次不良的操作记录。
            WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();

            if (!htTransaction.ContainsKey(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY))
            {
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
            }
            htTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY] = transactionKey;
            string sql = DatabaseTable.BuildInsertSqlStatement(wipFields, htTransaction, null);

            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);

            //更新批次终止状态。
            sql = string.Format(@"UPDATE POR_LOT 
                                 SET DELETED_TERM_FLAG=1,EDITOR='{0}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{1}'
                                 WHERE LOT_KEY='{0}'",
                                lotKey.PreventSQLInjection(),
                                editor.PreventSQLInjection(),
                                editTimeZone.PreventSQLInjection());
            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);

            //更新批次设备信息表
            sql = string.Format(@"UPDATE EMS_LOT_EQUIPMENT
                                SET END_TIMESTAMP =  GETDATE(),USER_KEY='{2}' 
                                WHERE LOT_KEY = '{0}' AND STEP_KEY = '{1}' AND END_TIMESTAMP IS NULL",
                                lotKey.PreventSQLInjection(),
                                stepKey.PreventSQLInjection(),
                                editor.PreventSQLInjection());
            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 添加撤销某笔历史操作记录的操作记录。
        /// </summary>
        /// <param name="dbtran">数据库事务操作对象。</param>
        /// <param name="transactionKey">撤销操作的主键。</param>
        private void AddUndoTransaction(DbTransaction dbtran, string transactionKey, DataRow drTransaction)
        {
            object activity = string.Format("{0}${1}", ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_UNDO,
                                            drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]);
            Hashtable htTransaction          = new Hashtable();
            WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();

            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, "0");
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, activity);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, null);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY]);
            string sql = DatabaseTable.BuildInsertSqlStatement(wipFields, htTransaction, null);

            db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 保存,返修批次。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbOK_Click(object sender, EventArgs e)
        {
            if (this.gvHoldInfoList.State == GridState.Editing &&
                this.gvHoldInfoList.IsEditorFocused &&
                this.gvHoldInfoList.EditingValueModified)
            {
                this.gvHoldInfoList.SetFocusedRowCellValue(this.gvHoldInfoList.FocusedColumn, this.gvHoldInfoList.EditingValue);
            }
            this.gvHoldInfoList.UpdateCurrentRow();
            //待返工批次信息
            DataTable dtLotInfo = this.gcLotList.DataSource as DataTable;

            if (dtLotInfo == null || dtLotInfo.Rows.Count < 1)
            {
                MessageService.ShowMessage("待返工批次信息列表至少要有一条记录。", "提示");
                return;
            }
            //暂停信息
            DataTable dtHoldInfo = this.gcHoldInfoList.DataSource as DataTable;

            if (dtHoldInfo.Rows.Count < 1)
            {
                MessageService.ShowMessage("暂停信息列表至少要有一条记录。", "提示");
                return;
            }
            string newEnterpriseName = this.beEnterpriseName.Text;
            string newEnterpriseKey  = Convert.ToString(this.beEnterpriseName.Tag);
            string newRouteName      = this.teRouteName.Text;
            string newRouteKey       = Convert.ToString(this.teRouteName.Tag);
            string newStepName       = this.teStepName.Text;
            string newStepKey        = Convert.ToString(this.teStepName.Tag);

            //返工工艺流程必须选择
            if (string.IsNullOrEmpty(newStepKey))
            {
                MessageService.ShowMessage("请选择工艺流程。", "提示");
                this.beEnterpriseName_ButtonClick(this.teStepName, new ButtonPressedEventArgs(new EditorButton()));
                return;
            }
            string remark = this.teRemark.Text.Trim();

            if (string.IsNullOrEmpty(remark))
            {
                MessageService.ShowMessage("备注必须输入。", "提示");
                this.teRemark.Select();
                return;
            }

            StringBuilder afterContent = new StringBuilder();

            afterContent.AppendFormat("工艺流程组:{0};", newEnterpriseName);
            afterContent.AppendFormat("工艺流程:{0};", newRouteName);
            afterContent.AppendFormat("工序:{0};", newStepName);
            //密码和释放密码不一致
            var lnq = from item in dtHoldInfo.AsEnumerable()
                      where Convert.ToString(item[TEMP_HOLD_LIST_RELEASE_PASSWORD]) != Convert.ToString(item[WIP_HOLD_RELEASE_FIELDS.FIELD_HOLD_PASSWORD])
                      select item;

            foreach (var item in lnq)
            {
                MessageService.ShowMessage("释放密码和暂停密码不一致,请确认。", "提示");
                this.gvHoldInfoList.FocusedColumn    = this.gclPassword;
                this.gvHoldInfoList.FocusedRowHandle = dtHoldInfo.Rows.IndexOf(item);
                this.gvHoldInfoList.ShowEditor();
                return;
            }

            string shiftName = this._model.ShiftName;
            string shiftKey  = string.Empty;
            //Shift shiftEntity = new Shift();
            //string shiftKey = shiftEntity.IsShiftValueExists(shiftName);//班次主键。
            ////获取班次主键失败。
            //if (!string.IsNullOrEmpty(shiftEntity.ErrorMsg))
            //{
            //    MessageService.ShowError(shiftEntity.ErrorMsg);
            //    return;
            //}
            ////没有排班。
            //if (string.IsNullOrEmpty(shiftKey))
            //{
            //    MessageService.ShowMessage("请先在系统中进行排班。", "提示");
            //    return;
            //}
            string oprComputer = PropertyService.Get(PROPERTY_FIELDS.COMPUTER_NAME);
            string timezone    = PropertyService.Get(PROPERTY_FIELDS.TIMEZONE);

            DataSet dsParams = new DataSet();
            //存放批次返工信息。
            Hashtable htMaindata = new Hashtable();

            htMaindata.Add(POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY, newEnterpriseKey);
            htMaindata.Add(POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY, newRouteKey);
            htMaindata.Add(POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY, newStepKey);
            DataTable dtMaindata = CommonUtils.ParseToDataTable(htMaindata);

            dtMaindata.TableName = TRANS_TABLES.TABLE_MAIN_DATA;
            //存放待返工的批次的操作数据
            WIP_TRANSACTION_FIELDS transFields = new WIP_TRANSACTION_FIELDS();
            DataTable dtTransaction            = CommonUtils.CreateDataTable(transFields);
            //存在批次返工操作的明细记录。
            WIP_COMMENT_FIELDS commentFileds = new WIP_COMMENT_FIELDS();
            DataTable          dtComment     = CommonUtils.CreateDataTable(commentFileds);

            foreach (DataRow dr in dtLotInfo.Rows)
            {
                string transKey = CommonUtils.GenerateNewKey(0);
                string lotKey   = Convert.ToString(dr[POR_LOT_FIELDS.FIELD_LOT_KEY]);
                //组织待返工的批次的操作数据
                DataRow drTransaction = dtTransaction.NewRow();
                dtTransaction.Rows.Add(drTransaction);
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY]  = transKey;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]        = lotKey;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]         = ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_REWORK;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN]      = dr[POR_LOT_FIELDS.FIELD_QUANTITY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT]     = dr[POR_LOT_FIELDS.FIELD_QUANTITY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY]   = dr[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_NAME]  = dr[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ENTERPRISE_NAME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY]        = dr[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_NAME]       = dr[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_NAME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY]         = dr[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_NAME]        = dr[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY]   = dr[POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY]        = shiftKey;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME]       = shiftName;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG]       = dr[POR_LOT_FIELDS.FIELD_STATE_FLAG];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG]      = dr[POR_LOT_FIELDS.FIELD_IS_REWORKED];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPERATOR]         = this._model.UserName;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER]     = oprComputer;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY]         = dr[POR_LOT_FIELDS.FIELD_CUR_PRODUCTION_LINE_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE]         = dr[POR_LOT_FIELDS.FIELD_OPR_LINE];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE_PRE]     = dr[POR_LOT_FIELDS.FIELD_OPR_LINE_PRE];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDC_INS_KEY]      = dr[POR_LOT_FIELDS.FIELD_EDC_INS_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EQUIPMENT_KEY]    = dr[EMS_EQUIPMENTS_FIELDS.FIELD_EQUIPMENT_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT] = remark;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]           = this._model.UserName;
                //用于暂存序列号批次信息最后的编辑时间,以便判断序列号信息是否过期。
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME]         = dr[POR_LOT_FIELDS.FIELD_EDIT_TIME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY] = timezone;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TIME_STAMP]        = DBNull.Value;
                //组织新的工艺流程数据
                DataRow drComment = dtComment.NewRow();
                dtComment.Rows.Add(drComment);
                drComment[WIP_COMMENT_FIELDS.FIELDS_TRANSACTION_KEY] = transKey;
                drComment[WIP_COMMENT_FIELDS.FIELDS_EDIT_TIMEZONE]   = timezone;
                drComment[WIP_COMMENT_FIELDS.FIELDS_EDIT_TIME]       = DBNull.Value;
                drComment[WIP_COMMENT_FIELDS.FIELDS_EDITOR]          = this._model.UserName;
                drComment[WIP_COMMENT_FIELDS.FIELDS_ENTERPRISE_KEY]  = newEnterpriseKey;
                drComment[WIP_COMMENT_FIELDS.FIELDS_ROUTE_KEY]       = newRouteKey;
                drComment[WIP_COMMENT_FIELDS.FIELDS_STEP_KEY]        = newStepKey;
                StringBuilder beforeContent = new StringBuilder();
                beforeContent.AppendFormat("工艺流程组:{0};", dr[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ENTERPRISE_NAME]);
                beforeContent.AppendFormat("工艺流程:{0};", dr[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_NAME]);
                beforeContent.AppendFormat("工序:{0};", dr[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME]);
                drComment[WIP_COMMENT_FIELDS.FIELDS_BEFORE_CONTENT] = beforeContent;
                drComment[WIP_COMMENT_FIELDS.FIELDS_AFTER_CONTENT]  = afterContent;
                //组织暂停批次信息。
                lnq = from item in dtHoldInfo.AsEnumerable()
                      where Convert.ToString(item[POR_LOT_FIELDS.FIELD_LOT_KEY]) == lotKey
                      select item;
                foreach (DataRow drHoldInfo in lnq)
                {
                    drHoldInfo[WIP_HOLD_RELEASE_FIELDS.FIELD_RELEASE_TRANSACTION_KEY] = transKey;
                    drHoldInfo[WIP_HOLD_RELEASE_FIELDS.FIELD_RELEASE_DESCRIPTION]     = remark;
                    drHoldInfo[WIP_HOLD_RELEASE_FIELDS.FIELD_RELEASE_OPERATOR]        = this._model.UserName;
                    drHoldInfo[WIP_HOLD_RELEASE_FIELDS.FIELD_RELEASE_TIMEZONE]        = timezone;
                    drHoldInfo[WIP_HOLD_RELEASE_FIELDS.FIELD_EDITOR]        = this._model.UserName;
                    drHoldInfo[WIP_HOLD_RELEASE_FIELDS.FIELD_EDIT_TIMEZONE] = timezone;
                }
            }
            //存放暂停明细。
            DataTable dtHoldParams = dtHoldInfo.Copy();

            dtHoldParams.Columns.Remove(TEMP_HOLD_LIST_RELEASE_PASSWORD);     //移除临时列。
            dtHoldParams.Columns.Remove(POR_LOT_FIELDS.FIELD_LOT_KEY);        //移除批次主键列。
            dtHoldParams.Columns.Remove(POR_LOT_FIELDS.FIELD_LOT_NUMBER);     //移除批次号列。

            dsParams.Tables.Add(dtMaindata);
            dsParams.Tables.Add(dtTransaction);
            dsParams.Tables.Add(dtHoldParams);
            dsParams.Tables.Add(dtComment);
            //执行(返工/返修)批次。
            this._entity.LotRework(dsParams);
            if (!string.IsNullOrEmpty(this._entity.ErrorMsg))
            {
                MessageService.ShowError(this._entity.ErrorMsg);
            }
            else
            {
                this.tsbCancle_Click(sender, e);
            }
            dsParams.Tables.Clear();
            dtTransaction = null;
            dtHoldParams  = null;
            dtComment     = null;
            dsParams      = null;
        }
Exemplo n.º 6
0
        /// <summary>
        /// 执行拆分批次。
        /// </summary>
        /// <param name="db">数据库对象。</param>
        /// <param name="dbtran">数据库事务操作对象。</param>
        /// <param name="dataset">包含拆分批次数据的数据集。</param>
        /// <param name="dsReturn">包含执行结果的数据集。</param>
        /// <returns></returns>
        internal static int SplitLotTransact(Database db, DbTransaction dbtran, DataSet dsParams, ref DataSet dsReturn)
        {
            String  sql = string.Empty;
            DataSet ds;
            string  strParentLotKey = "";
            string  strParentLotNumber = "";
            string  strParentSEQ = "";
            string  strParentTransKey = "";
            string  strParentStepKey = "";
            string  strParentRouteKey = "";
            string  strParentEnterpriseKey = "";
            string  strParentQTY = "";
            string  strRemnantQTY = "";
            string  strComment = "";
            string  strEditor = "", strEditTimeZone = "", strEditTime = "";
            string  strLineKey = "", strShiftName = "", strWorkOrderKey = "", strParentStateFlag = "";
            string  oprLine = string.Empty;
            string  reworkFlag       = string.Empty;
            int     splitQuantitySum = 0;
            int     intSEQ        = 0;
            int     workOrderStep = 0;

            if (dsParams.Tables.Count > 0)
            {
                //获取参数输入。
                strEditTime = UtilHelper.GetSysdate(db).ToString("yyyy-MM-dd HH:mm:ss");
                DataTable dataTable = dsParams.Tables[TRANS_TABLES.TABLE_MAIN_DATA];
                Hashtable hashData  = SolarViewer.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dataTable);
                strParentLotKey = hashData[POR_LOT_FIELDS.FIELD_LOT_KEY].ToString();
                strRemnantQTY   = hashData[POR_LOT_FIELDS.FIELD_QUANTITY].ToString();
                strComment      = hashData[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT].ToString();
                strEditor       = hashData[WIP_TRANSACTION_FIELDS.FIELD_EDITOR].ToString();
                strEditTimeZone = hashData[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY].ToString();
                strParentQTY    = hashData[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN].ToString();
                string shiftKey         = Convert.ToString(hashData[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY]);
                string operComputerName = Convert.ToString(hashData[WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER]);
                if (hashData.ContainsKey(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME))
                {
                    strShiftName = hashData[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME].ToString();
                }
                else
                {
                    strShiftName = UtilHelper.GetShiftValue(db, strEditTime);
                }
                if (string.IsNullOrEmpty(shiftKey))
                {
                    shiftKey = UtilHelper.GetShiftKey(db, strEditTime);
                }

                if (hashData.Contains(POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY))
                {
                    strParentStepKey = hashData[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY].ToString();
                }
                if (hashData.Contains(POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY))
                {
                    strParentRouteKey = hashData[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY].ToString();
                }
                if (hashData.Contains(POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY))
                {
                    strParentEnterpriseKey = hashData[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY].ToString();
                }
                if (hashData.Contains(POR_LOT_FIELDS.FIELD_STATE_FLAG))
                {
                    strParentStateFlag = hashData[POR_LOT_FIELDS.FIELD_STATE_FLAG].ToString();
                }
                if (hashData.ContainsKey(COMMON_FIELDS.FIELD_WORK_ORDER_STEP))
                {
                    workOrderStep = Convert.ToInt32(hashData[COMMON_FIELDS.FIELD_WORK_ORDER_STEP]);
                }
                //获取被拆分批次信息。
                ds = LotManagement.GetLotDetailsEx(db, dbtran, strParentLotKey);
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    strParentSEQ       = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_WORK_ORDER_SEQ].ToString();
                    strParentLotNumber = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_LOT_NUMBER].ToString();

                    strWorkOrderKey = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY].ToString();
                    strLineKey      = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_CUR_PRODUCTION_LINE_KEY].ToString();
                    oprLine         = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_OPR_LINE].ToString();
                    reworkFlag      = Convert.ToString(ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_IS_REWORKED]);
                    if (strParentStepKey == "" || strParentRouteKey == "" || strParentEnterpriseKey == "" || strParentStateFlag == "")
                    {
                        strParentStepKey       = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY].ToString();
                        strParentRouteKey      = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY].ToString();
                        strParentEnterpriseKey = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY].ToString();
                        strParentStateFlag     = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_STATE_FLAG].ToString();
                    }
                }
                WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
                //更新批次信息
                sql = string.Format(@"UPDATE POR_LOT 
                                    SET QUANTITY='{0}',EDITOR='{1}',EDIT_TIME= GETDATE(),EDIT_TIMEZONE='{2}' ",
                                    strRemnantQTY.PreventSQLInjection(),
                                    strEditor.PreventSQLInjection(),
                                    strEditTimeZone.PreventSQLInjection());
                //如果数量为0终止批次。
                if (strRemnantQTY == "0")
                {
                    sql += ",DELETED_TERM_FLAG=1 ";
                }
                sql += string.Format("WHERE LOT_KEY='{0}'", strParentLotKey.PreventSQLInjection());
                db.ExecuteNonQuery(dbtran, CommandType.Text, sql);

                #region 记录批次拆分操作数据
                Hashtable parenttransactionTable = new Hashtable();
                DataTable parenttransaction      = new DataTable();
                strParentTransKey = UtilHelper.GenerateNewKey(0);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, strParentTransKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, "0");
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, strParentLotKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, strParentQTY);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, strRemnantQTY);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_SPLIT);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, strComment);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, strEditor);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, null);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, strEditTimeZone);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, strWorkOrderKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY, strParentStepKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY, strParentRouteKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY, strParentEnterpriseKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, strParentStateFlag);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE, oprLine);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG, reworkFlag);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPERATOR, strEditor);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY, strLineKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME, strShiftName);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY, shiftKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER, operComputerName);

                sql = DatabaseTable.BuildInsertSqlStatement(wipFields, parenttransactionTable, null);
                db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                #endregion

                #region 创建子批次。

                string strChildLotKey    = "";
                string strChildLotNumber = "";
                string strChildQty       = "";
                string strChildLotSEQ    = "";
                //int intSEQ = 0;
                int intCount = 0;
                if (dsParams.Tables.Contains(BASE_PARAMETER_FIELDS.DATABASE_TABLE_NAME))
                {
                    DataTable dtReturn = new DataTable();
                    dtReturn.Columns.Add("ITEM_SEQ", Type.GetType("System.String"));
                    dtReturn.Columns.Add("LOT_NUMBER", Type.GetType("System.String"));
                    dtReturn.Columns.Add("QUANTITY", Type.GetType("System.String"));
                    dtReturn.Columns.Add("LOT_KEY", Type.GetType("System.String"));

                    intCount = strParentSEQ.Length;
                    //get exist max seq
                    sql = string.Format(@"SELECT MAX(A.WORK_ORDER_SEQ) AS WORK_ORDER_SEQ, 
	                                           SUBSTRING(MAX(A.WORK_ORDER_SEQ),{0},2) AS WORK_ORDER_STEP,
	                                           LEN(MAX(A.WORK_ORDER_SEQ)),A.WORK_ORDER_KEY 
                                        FROM POR_LOT A  
                                        WHERE A.WORK_ORDER_KEY = '{1}'
                                        AND A.WORK_ORDER_SEQ LIKE '{2}.%'
                                        GROUP BY A.WORK_ORDER_KEY",
                                        (intCount + 2),
                                        strWorkOrderKey.PreventSQLInjection(),
                                        strParentSEQ.PreventSQLInjection());
                    using (IDataReader readerSEQ = db.ExecuteReader(dbtran, CommandType.Text, sql))
                    {
                        if (readerSEQ.Read())
                        {
                            if (readerSEQ["WORK_ORDER_STEP"].ToString() != "")
                            {
                                intSEQ = Int32.Parse(readerSEQ["WORK_ORDER_STEP"].ToString());
                            }
                        }
                        readerSEQ.Close();
                    }
                    if (workOrderStep > intSEQ)
                    {
                        intSEQ = workOrderStep;
                    }
                    DataTable parameterdatatable = dsParams.Tables[BASE_PARAMETER_FIELDS.DATABASE_TABLE_NAME];
                    for (int i = 0; i < parameterdatatable.Rows.Count; i++)
                    {
                        //get form collect data
                        strChildLotKey    = UtilHelper.GenerateNewKey(0);
                        strChildLotNumber = GetChildLotNumber(db, dbtran, strParentLotNumber, i + 1);
                        strChildQty       = parameterdatatable.Rows[i]["QUANTITY"].ToString();
                        strChildLotSEQ    = parameterdatatable.Rows[i]["SPLIT_SEQ"].ToString();
                        dtReturn.Rows.Add(strChildLotSEQ, strChildLotNumber, strChildQty, strChildLotKey);

                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_LOT_KEY]                  = strChildLotKey;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_LOT_NUMBER]               = strChildLotNumber;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_QUANTITY]                 = strChildQty;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_EDIT_TIME]                = strEditTime;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_CREATE_TIME]              = strEditTime;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_START_WAIT_TIME]          = strEditTime;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_STATE_FLAG]               = strParentStateFlag;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY] = strParentEnterpriseKey;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]        = strParentRouteKey;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]         = strParentStepKey;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_IS_MAIN_LOT]              = 0;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_OPR_COMPUTER]             = operComputerName;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_CREATOR]                  = strEditor;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_EDITOR]              = strEditor;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_EDIT_TIMEZONE]       = strEditTimeZone;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_CREATE_TIMEZONE_KEY] = strEditTimeZone;
                        ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_IS_PRINT]            = "0";
                        if (intSEQ == 0)
                        {
                            //new SEQ
                            ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_WORK_ORDER_SEQ] = strParentSEQ + "." + strChildLotSEQ;
                        }
                        else
                        {
                            //add SEQ
                            intSEQ = intSEQ + 1;
                            ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_WORK_ORDER_SEQ] = strParentSEQ + "." + intSEQ.ToString("00");
                        }

                        //Create chilid Lot
                        if (ds.Tables.Contains(TRANS_TABLES.TABLE_MAIN_DATA))
                        {
                            ds.Tables.Remove(TRANS_TABLES.TABLE_MAIN_DATA);
                        }

                        #region Create Lot & Create Udas for the lot
                        Hashtable hashDataOfLot = SolarViewer.Hemera.Share.Common.CommonUtils.ConvertRowToHashtable(ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0]);
                        //initialize tablefields
                        POR_LOT_FIELDS      porLotFields = new POR_LOT_FIELDS();
                        POR_LOT_ATTR_FIELDS lotUda       = new POR_LOT_ATTR_FIELDS();

                        //get sql
                        sql = DatabaseTable.BuildInsertSqlStatement(porLotFields, hashDataOfLot, null);
                        db.ExecuteNonQuery(dbtran, CommandType.Text, sql);

                        //create udas for the child lot
                        if (ds.Tables.Contains(POR_LOT_ATTR_FIELDS.DATABASE_TABLE_NAME))
                        {
                            List <string> sqlCommandList = new List <string>();
                            foreach (DataRow row in ds.Tables[POR_LOT_ATTR_FIELDS.DATABASE_TABLE_NAME].Rows)
                            {
                                row[POR_LOT_ATTR_FIELDS.FIELD_LOT_KEY] = strChildLotKey;
                            }
                            DatabaseTable.BuildInsertSqlStatements(ref sqlCommandList,
                                                                   new POR_LOT_ATTR_FIELDS(),
                                                                   ds.Tables[POR_LOT_ATTR_FIELDS.DATABASE_TABLE_NAME],
                                                                   new Dictionary <string, string>()
                            {
                                { COMMON_FIELDS.FIELD_COMMON_EDIT_TIME, null },
                                { COMMON_FIELDS.FIELD_COMMON_EDIT_TIMEZONE, "CN-ZH" }
                            },
                                                                   new List <string>()
                            {
                                BASE_ATTRIBUTE_FIELDS.FIELDS_DATA_TYPE
                            });

                            foreach (string sqlU in sqlCommandList)
                            {
                                db.ExecuteNonQuery(dbtran, CommandType.Text, sqlU);
                            }
                        }
                        #endregion

                        #region Insert WipTransaction
                        //insert Wip transaction
                        Hashtable childtransactionTable = new Hashtable();
                        DataTable childtransaction      = new DataTable();
                        string    strChildTransKey      = UtilHelper.GenerateNewKey(0);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, strChildTransKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, "0");
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, strChildLotKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, strChildQty);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, strChildQty);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_CREATELOT);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, "");
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, strEditor);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, null);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, strEditTimeZone);

                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY, strLineKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, strWorkOrderKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY, strParentEnterpriseKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY, strParentRouteKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY, strParentStepKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, strParentStateFlag);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE, oprLine);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG, reworkFlag);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPERATOR, strEditor);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME, strShiftName);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY, shiftKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER, operComputerName);

                        sql = DatabaseTable.BuildInsertSqlStatement(wipFields, childtransactionTable, null);
                        db.ExecuteNonQuery(dbtran, CommandType.Text, sql);

                        //insert wip split
                        Hashtable        splitHashTable = new Hashtable();
                        DataTable        splitTable     = new DataTable();
                        WIP_SPLIT_FIELDS wipSplit       = new WIP_SPLIT_FIELDS();

                        splitHashTable.Add(WIP_SPLIT_FIELDS.FIELD_TRANSACTION_KEY, strParentTransKey);
                        splitHashTable.Add(WIP_SPLIT_FIELDS.FIELD_CHILD_LOT_KEY, strChildLotKey);
                        splitHashTable.Add(WIP_SPLIT_FIELDS.FIELD_CHILD_LOT_TRANSACTION_KEY, strChildTransKey);
                        splitHashTable.Add(WIP_SPLIT_FIELDS.FIELD_SPLIT_QUANTITY, strChildQty);
                        splitHashTable.Add(WIP_SPLIT_FIELDS.FIELD_STEP_KEY, strParentStepKey);
                        splitHashTable.Add(WIP_SPLIT_FIELDS.FIELD_ROUTE_KEY, strParentRouteKey);
                        splitHashTable.Add(WIP_SPLIT_FIELDS.FIELD_ENTERPRISE_KEY, strParentEnterpriseKey);
                        splitHashTable.Add(WIP_SPLIT_FIELDS.FIELD_EDITOR, strEditor);
                        splitHashTable.Add(WIP_SPLIT_FIELDS.FIELD_EDIT_TIME, null);
                        splitHashTable.Add(WIP_SPLIT_FIELDS.FIELD_EDIT_TIMEZONE, strEditTimeZone);
                        sql = DatabaseTable.BuildInsertSqlStatement(wipSplit, splitHashTable, null);
                        db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                        #endregion
                    }
                    dtReturn.TableName = "CHILDLOT_DATA";
                    dsReturn.Merge(dtReturn, false, MissingSchemaAction.Add);
                }
                #endregion

                #region 获取批次当前加工的设备数据
                sql = string.Format(@"SELECT EQUIPMENT_KEY,LOT_EQUIPMENT_KEY 
                                    FROM EMS_LOT_EQUIPMENT 
                                    WHERE LOT_KEY='{0}' AND STEP_KEY='{1}' AND END_TIMESTAMP IS NULL",
                                    strParentLotKey.PreventSQLInjection(),
                                    strParentStepKey.PreventSQLInjection());
                DataSet dsLotEquipment = db.ExecuteDataSet(dbtran, CommandType.Text, sql);
                if (dsLotEquipment.Tables[0].Rows.Count > 0)
                {
                    string equipmentKey    = dsLotEquipment.Tables[0].Rows[0]["EQUIPMENT_KEY"].ToString();
                    string lotEquipmentKey = dsLotEquipment.Tables[0].Rows[0]["LOT_EQUIPMENT_KEY"].ToString();
                    if (dsReturn.Tables.Contains("CHILDLOT_DATA"))
                    {
                        for (int i = 0; i < dsReturn.Tables["CHILDLOT_DATA"].Rows.Count; i++)
                        {
                            string splitLotKey   = dsReturn.Tables["CHILDLOT_DATA"].Rows[i]["LOT_KEY"].ToString();
                            int    splitQuantity = Convert.ToInt32(dsReturn.Tables["CHILDLOT_DATA"].Rows[i]["QUANTITY"]);
                            splitQuantitySum += splitQuantity;
                            sql = string.Format(@"INSERT INTO EMS_LOT_EQUIPMENT
                                                (LOT_EQUIPMENT_KEY, LOT_KEY,EQUIPMENT_KEY, START_TIMESTAMP, USER_KEY, QUANTITY,STEP_KEY)
                                                VALUES('{0}','{1}','{2}',  GETDATE(), '{3}', {4},'{5}')",
                                                UtilHelper.GenerateNewKey(0),
                                                splitLotKey.PreventSQLInjection(),
                                                equipmentKey.PreventSQLInjection(),
                                                strEditor.PreventSQLInjection(),
                                                splitQuantity,
                                                strParentStepKey.PreventSQLInjection());
                            db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                        }
                    }
                    sql = string.Format(@"UPDATE EMS_LOT_EQUIPMENT 
                                        SET QUANTITY=QUANTITY-{0} 
                                        WHERE LOT_EQUIPMENT_KEY='{1}'",
                                        splitQuantitySum,
                                        lotEquipmentKey.PreventSQLInjection());
                    db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                }
                #endregion
            }
            return(intSEQ);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 批次入库。
        /// </summary>
        /// <param name="dbTran">数据库事务对象。</param>
        /// <param name="drLotInfo">批次信息。</param>
        /// <param name="dtOperationParam">工序入库参数数据。</param>
        /// <param name="htParams">附近参数数据。</param>
        private void LotToWarehouse(DbTransaction dbTran, DataRow drLotInfo, DataTable dtOperationParam, Hashtable htParams)
        {
            string    lotKey        = Convert.ToString(drLotInfo[POR_LOT_FIELDS.FIELD_LOT_KEY]);
            Hashtable htTransaction = new Hashtable();

            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_TO_WAREHOUSE);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, null);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, htParams[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, htParams[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY, drLotInfo[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_NAME, drLotInfo[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ENTERPRISE_NAME]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EQUIPMENT_KEY, htParams[WIP_TRANSACTION_FIELDS.FIELD_EQUIPMENT_KEY]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY, htParams[WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPERATOR, htParams[WIP_TRANSACTION_FIELDS.FIELD_OPERATOR]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER, htParams[WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE, htParams[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE_PRE, drLotInfo[POR_LOT_FIELDS.FIELD_LINE_NAME]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, drLotInfo[POR_LOT_FIELDS.FIELD_LOT_KEY]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, 0);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, drLotInfo[POR_LOT_FIELDS.FIELD_QUANTITY]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, drLotInfo[POR_LOT_FIELDS.FIELD_QUANTITY]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG, drLotInfo[POR_LOT_FIELDS.FIELD_IS_REWORKED]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY, drLotInfo[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_NAME, drLotInfo[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_NAME]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY, htParams[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME, htParams[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, 9);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY, drLotInfo[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_NAME, drLotInfo[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TO_STEP_KEY, drLotInfo[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TIME_STAMP, null);
            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, drLotInfo[POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY]);

            string transactionKey = UtilHelper.GenerateNewKey(0);

            AddWIPLot(dbTran, transactionKey, lotKey);
            //向WIP_TRANSACTION表插入批次入库的操作记录。
            WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();

            if (!htTransaction.ContainsKey(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY))
            {
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
            }
            htTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY] = transactionKey;
            string sql = DatabaseTable.BuildInsertSqlStatement(wipFields, htTransaction, null);

            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
            //工步采集参数数据。
            //如果数据集中包含名称WIP_PARAM_FIELDS.DATABASE_TABLE_NAME的数据表对象。
            if (dtOperationParam != null)
            {
                WIP_PARAM_FIELDS wipParamFields = new WIP_PARAM_FIELDS();
                //遍历批次的工步采集参数数据。
                for (int i = 0; i < dtOperationParam.Rows.Count; i++)
                {
                    DataRow   drWIPParam = dtOperationParam.Rows[i];
                    Hashtable htWIPParam = CommonUtils.ConvertRowToHashtable(drWIPParam);
                    if (!htWIPParam.ContainsKey(WIP_PARAM_FIELDS.FIELD_TRANSACTION_KEY))
                    {
                        htWIPParam.Add(WIP_PARAM_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
                    }
                    htWIPParam[WIP_PARAM_FIELDS.FIELD_TRANSACTION_KEY] = transactionKey;
                    //插入一笔工序参数数据。
                    sql = DatabaseTable.BuildInsertSqlStatement(wipParamFields, htWIPParam, null);
                    db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                }
            }
            //更新批次状态,11-已入库
            sql = string.Format(@"UPDATE POR_LOT SET STATE_FLAG=11,EDIT_TIME=GETDATE()
                                WHERE LOT_KEY='{0}'",
                                lotKey.PreventSQLInjection());
            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 创建批次。
        /// </summary>
        /// <param name="db">数据库对象。</param>
        /// <param name="dsParams">包含批次创建信息的数据集对象。</param>
        /// <param name="drLotCell">创批组件对应的。</param>
        public static void CreateNewLot(Database db, DataSet dsParams, DataRow drCellData)
        {
            DataSet       dsReturn       = new DataSet();
            List <string> sqlCommandList = new List <string>();
            DateTime      curTime        = UtilHelper.GetSysdate(db);
            string        lotEditTime    = curTime.ToString("yyyy-MM-dd HH:mm:ss");

            if (dsParams.Tables.Contains(TRANS_TABLES.TABLE_MAIN_DATA))
            {
                DataTable dtMainData    = dsParams.Tables[TRANS_TABLES.TABLE_MAIN_DATA];
                DataTable dtAddtionData = dsParams.Tables[1];   //存放附加数据

                Hashtable htMainData     = CommonUtils.ConvertToHashtable(dtMainData);
                Hashtable htAddtionData  = CommonUtils.ConvertToHashtable(dtAddtionData);
                string    enterpriseName = Convert.ToString(htAddtionData[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_NAME]);
                string    routeName      = Convert.ToString(htAddtionData[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_NAME]);
                string    stepName       = Convert.ToString(htAddtionData[WIP_TRANSACTION_FIELDS.FIELD_STEP_NAME]);

                string editor       = Convert.ToString(htMainData[POR_LOT_FIELDS.FIELD_CREATOR]);
                string editTimezone = string.Empty;
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_EDIT_TIMEZONE))
                {
                    editTimezone = Convert.ToString(htMainData[POR_LOT_FIELDS.FIELD_EDIT_TIMEZONE]);
                }
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_EDITOR) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_EDITOR, editor);
                }
                string lotKey = UtilHelper.GenerateNewKey(0);
                htMainData[POR_LOT_FIELDS.FIELD_LOT_KEY]         = lotKey;
                htMainData[POR_LOT_FIELDS.FIELD_EDIT_TIME]       = null;
                htMainData[POR_LOT_FIELDS.FIELD_CREATE_TIME]     = null;
                htMainData[POR_LOT_FIELDS.FIELD_START_WAIT_TIME] = null;

                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_ORG_WORK_ORDER_NO) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_ORG_WORK_ORDER_NO, htMainData[POR_LOT_FIELDS.FIELD_WORK_ORDER_NO]);
                }
                else
                {
                    htMainData[POR_LOT_FIELDS.FIELD_ORG_WORK_ORDER_NO] = htMainData[POR_LOT_FIELDS.FIELD_WORK_ORDER_NO];
                }

                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_STATE_FLAG) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_STATE_FLAG, "0");
                }
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_DELETED_TERM_FLAG) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_DELETED_TERM_FLAG, "0");
                }
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_IS_REWORKED) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_IS_REWORKED, "0");
                }
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_IS_MAIN_LOT) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_IS_MAIN_LOT, "1");
                }
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_HOLD_FLAG) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_HOLD_FLAG, "0");
                }
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_IS_SPLITED) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_IS_SPLITED, "0");
                }
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_SHIPPED_FLAG) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_SHIPPED_FLAG, "0");
                }
                //创建批次。
                POR_LOT_FIELDS porLotFields = new POR_LOT_FIELDS();
                string         sql          = DatabaseTable.BuildInsertSqlStatement(porLotFields, htMainData, null);
                db.ExecuteNonQuery(CommandType.Text, sql);

                #region 插入组件片对应电池片信息

                string sqlCommond = string.Empty;

                sqlCommond = string.Format(@"SELECT LOT_KEY FROM POR_LOT_CELL_PARAM
                                            WHERE LOT_NUMBER = '{0}' 
                                            AND IS_USED = 'Y'", drCellData["LOT_NUMBER"].ToString());
                DataTable dtCellReturn = db.ExecuteDataSet(CommandType.Text, sqlCommond).Tables[0];

                if (dtCellReturn.Rows.Count > 0)
                {
                    sqlCommond = string.Format(@"UPDATE  POR_LOT_CELL_PARAM
                                                SET IS_USED = 'N'
                                                WHERE LOT_KEY = '{0}'", dtCellReturn.Rows[0]["LOT_KEY"].ToString());
                    db.ExecuteNonQuery(CommandType.Text, sqlCommond);
                }

                sqlCommond = string.Format(@"INSERT INTO POR_LOT_CELL_PARAM (  [LOT_KEY]
                                                                              ,[LOT_NUMBER]
                                                                              ,[CELLLOT1]
                                                                              ,[CELLPN1]
                                                                              ,[CELLLOT2]
                                                                              ,[CELLPN2]
                                                                              ,[PACKAGEQTY]
                                                                              ,[CELLSUPPLIER]
                                                                              ,[CELLFACTORY]
                                                                              ,[CELLLINE]
                                                                              ,[CELLCOLOR]
                                                                              ,[CELLEFFICIENCY]
                                                                              ,[CELLPOWER]
                                                                              ,[SMALL_PACK_NUMBER]
                                                                              ,[IS_USED]
                                                                              ,[CREATOR]
                                                                              ,[CREATE_TIME]
                                                                              ,[CREATE_TIMEZONE]
                                                                              ,[EDITOR]
                                                                              ,[EDIT_TIME]
                                                                              ,[EDIT_TIMEZONE]
                                                                              ,[ETL_FLAG])
                                                                              VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}',
                                                                                      '{12}','{13}','Y','{14}',SYSDATETIME(),'{15}','{16}',SYSDATETIME(),'{17}','Y')",
                                           lotKey,
                                           drCellData["LOT_NUMBER"].ToString(),
                                           drCellData["CELLLOT1"].ToString(),
                                           drCellData["CELLPN1"].ToString(),
                                           drCellData["CELLLOT2"].ToString(),
                                           drCellData["CELLPN2"].ToString(),
                                           drCellData["PACKAGEQTY"].ToString(),
                                           drCellData["CELLSUPPLIER"].ToString(),
                                           drCellData["CELLFACTORY"].ToString(),
                                           drCellData["CELLLINE"].ToString(),
                                           drCellData["CELLCOLOR"].ToString(),
                                           drCellData["CELLEFFICIENCY"].ToString(),
                                           drCellData["CELLPOWER"].ToString(),
                                           drCellData["SMALL_PACK_NUMBER"].ToString(),
                                           editor,
                                           editTimezone,
                                           editor,
                                           editTimezone
                                           );


                db.ExecuteNonQuery(CommandType.Text, sqlCommond);
                #endregion


                #region 插入操作记录
                WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
                Hashtable htTransaction          = new Hashtable();
                DataTable dtTransaction          = new DataTable();
                string    strChildTransKey       = UtilHelper.GenerateNewKey(0);
                string    strShiftKey            = UtilHelper.GetShiftKey(db, curTime.ToString("yyyy-MM-dd HH:mm:ss"));
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, strChildTransKey);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, "0");
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, htMainData[POR_LOT_FIELDS.FIELD_LOT_KEY]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, htMainData[POR_LOT_FIELDS.FIELD_QUANTITY]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, htMainData[POR_LOT_FIELDS.FIELD_QUANTITY]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_CREATELOT);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, htMainData[POR_LOT_FIELDS.FIELD_STATE_FLAG]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, string.Empty);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER, htMainData[POR_LOT_FIELDS.FIELD_OPR_COMPUTER]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY, strShiftKey);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME, htMainData[POR_LOT_FIELDS.FIELD_SHIFT_NAME]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, htMainData[POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY, htMainData[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY, htMainData[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY, htMainData[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_NAME, stepName);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_NAME, routeName);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_NAME, enterpriseName);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, curTime);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, editTimezone);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, editor);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPERATOR, editor);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG, htMainData[POR_LOT_FIELDS.FIELD_IS_REWORKED]);
                sql = DatabaseTable.BuildInsertSqlStatement(wipFields, htTransaction, null);
                db.ExecuteNonQuery(CommandType.Text, sql);
                #endregion

                if (dsParams.Tables.Contains(POR_LOT_ATTR_FIELDS.DATABASE_TABLE_NAME))
                {
                    DatabaseTable.BuildInsertSqlStatements(ref sqlCommandList,
                                                           new POR_LOT_ATTR_FIELDS(),
                                                           dsParams.Tables[POR_LOT_ATTR_FIELDS.DATABASE_TABLE_NAME],
                                                           new Dictionary <string, string>()
                    {
                        { COMMON_FIELDS.FIELD_COMMON_EDIT_TIME, null },
                        { COMMON_FIELDS.FIELD_COMMON_EDIT_TIMEZONE, "CN-ZH" }
                    },
                                                           new List <string>()
                    {
                        COMMON_FIELDS.FIELD_COMMON_OPERATION_ACTION, BASE_ATTRIBUTE_FIELDS.FIELDS_DATA_TYPE
                    });
                }
                foreach (string s in sqlCommandList)
                {
                    db.ExecuteNonQuery(CommandType.Text, s);
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 确定撤销操作。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            DataTable dtExchangeLineInfo = this.gcExchangeLine.DataSource as DataTable;

            if (dtExchangeLineInfo.Rows.Count < 1)
            {
                MessageService.ShowMessage(StringParser.Parse("${res:FanHai.Hemera.Addins.WIP.LotOperationExchangeLine.Msg003}"), MESSAGEBOX_CAPTION);//暂停信息列表至少要有一条记录
                //MessageService.ShowMessage("暂停信息列表至少要有一条记录。", "提示");
                return;
            }

            string lotMainLineCode = lueLotLine.Text.ToString();

            //判断是否有进行线别的选择
            if (string.IsNullOrEmpty(lotMainLineCode))
            {
                MessageService.ShowMessage(StringParser.Parse("${res:FanHai.Hemera.Addins.WIP.LotOperationExchangeLine.Msg004}"), MESSAGEBOX_CAPTION);//请选择要调整到的线别
                //MessageService.ShowMessage("请选择要调整到的线别!", "提示");
                return;
            }

            string lotMainLineKey = Convert.ToString(lueLotLine.EditValue);

            string remark = this.teRemark.Text.Trim();

            if (string.IsNullOrEmpty(remark))
            {
                MessageService.ShowMessage(StringParser.Parse("${res:FanHai.Hemera.Addins.WIP.LotOperationExchangeLine.Msg005}"), MESSAGEBOX_CAPTION);//备注必须输入
                //MessageService.ShowMessage("备注必须输入。", "提示");
                this.teRemark.Select();
                return;
            }

            //对视图信息进行更新
            if (this.gvExchangeLine.State == GridState.Editing &&
                this.gvExchangeLine.IsEditorFocused &&
                this.gvExchangeLine.EditingValueModified)
            {
                this.gvExchangeLine.SetFocusedRowCellValue(this.gvExchangeLine.FocusedColumn, this.gvExchangeLine.EditingValue);
            }
            this.gvExchangeLine.UpdateCurrentRow();

            DataTable dtLotInfo = this.gcExchangeLine.DataSource as DataTable;

            string shiftName   = string.Empty;
            string shiftKey    = string.Empty;
            string userName    = PropertyService.Get(PROPERTY_FIELDS.USER_NAME);
            string oprComputer = PropertyService.Get(PROPERTY_FIELDS.COMPUTER_NAME);
            string timezone    = PropertyService.Get(PROPERTY_FIELDS.TIMEZONE);

            DataSet dsParams = new DataSet();
            //存放待线别调整的批次的操作数据
            WIP_TRANSACTION_FIELDS transFields = new WIP_TRANSACTION_FIELDS();
            DataTable dtTransaction            = CommonUtils.CreateDataTable(transFields);

            foreach (DataRow dr in dtLotInfo.Rows)
            {
                //组织待线别调整的批次的操作数据
                DataRow drTransaction = dtTransaction.NewRow();
                dtTransaction.Rows.Add(drTransaction);
                string transKey = CommonUtils.GenerateNewKey(0);
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY]  = transKey;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]        = dr[POR_LOT_FIELDS.FIELD_LOT_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]         = POR_LOT_FIELDS.FIELD_LOT_LINE_EXCHANGE;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN]      = dr[POR_LOT_FIELDS.FIELD_QUANTITY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT]     = dr[POR_LOT_FIELDS.FIELD_QUANTITY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY]   = dr[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_NAME]  = dr[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ENTERPRISE_NAME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY]        = dr[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_NAME]       = dr[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_NAME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY]         = dr[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_NAME]        = dr[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY]   = dr[POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY]        = shiftKey;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME]       = shiftName;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG]       = dr[POR_LOT_FIELDS.FIELD_STATE_FLAG];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG]      = dr[POR_LOT_FIELDS.FIELD_IS_REWORKED];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPERATOR]         = userName;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER]     = oprComputer;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY]         = dr[POR_LOT_FIELDS.FIELD_CUR_PRODUCTION_LINE_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE]         = dr[POR_LOT_FIELDS.FIELD_OPR_LINE];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE_PRE]     = dr[POR_LOT_FIELDS.FIELD_OPR_LINE_PRE];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDC_INS_KEY]      = dr[POR_LOT_FIELDS.FIELD_EDC_INS_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EQUIPMENT_KEY]    = dr[EMS_EQUIPMENTS_FIELDS.FIELD_EQUIPMENT_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT] = remark;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]           = userName;
                //用于暂存序列号批次信息最后的编辑时间,以便判断序列号信息是否过期。
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME]         = dr[POR_LOT_FIELDS.FIELD_EDIT_TIME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY] = timezone;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TIME_STAMP]        = DBNull.Value;
            }

            foreach (DataRow dr in dtLotInfo.Rows)
            {
                dr[POR_LOT_FIELDS.FIELD_LOT_LINE_KEY]  = lotMainLineKey;
                dr[POR_LOT_FIELDS.FIELD_LOT_LINE_CODE] = lotMainLineCode;
                dr[POR_LOT_FIELDS.FIELD_EDITOR]        = userName;
                dr[POR_LOT_FIELDS.FIELD_EDIT_TIMEZONE] = timezone;
            }

            dsParams.Tables.Add(dtTransaction);

            if (dtLotInfo.DataSet != null)
            {
                dtLotInfo.DataSet.Clear();
            }

            dtLotInfo.TableName = POR_LOT_FIELDS.DATABASE_TABLE_NAME;
            dsParams.Tables.Add(dtLotInfo);

            //执行批次线别调整。
            this._entity.LotExchangeLine(dsParams);
            if (!string.IsNullOrEmpty(this._entity.ErrorMsg))
            {
                MessageService.ShowError(this._entity.ErrorMsg);
            }
            else
            {
                dsParams.Tables.Clear();
                dtTransaction = null;
                dtLotInfo     = null;
                dsParams      = null;

                MessageService.ShowMessage(StringParser.Parse("${res:FanHai.Hemera.Addins.WIP.LotOperationExchangeLine.Msg006}"), MESSAGEBOX_CAPTION);//保存成功
                //MessageService.ShowMessage("保存成功!", "提示");

                ResetControlValue();
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 释放批次。
        /// </summary>
        /// <param name="dsParams">包含批次释放信息的数据集对象。</param>
        /// <param name="dbTran">数据库操作事务对象。</param>
        private void LotRelease(DataSet dsParams, DbTransaction dbTran)
        {
            //参数数据。
            if (dsParams == null ||
                !dsParams.Tables.Contains(WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME) ||
                !dsParams.Tables.Contains(WIP_HOLD_RELEASE_FIELDS.DATABASE_TABLE_NAME) ||
                dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME].Rows.Count == 0 ||      //暂停批次操作记录不能为空记录。
                dsParams.Tables[WIP_HOLD_RELEASE_FIELDS.DATABASE_TABLE_NAME].Rows.Count == 0        //暂停信息不能为空
                )
            {
                throw new Exception("传入参数不正确,请检查。");
            }

            DataTable dtTransaction = dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME];   //存放操作数据
            DataTable dtHold        = dsParams.Tables[WIP_HOLD_RELEASE_FIELDS.DATABASE_TABLE_NAME];  //存放批次暂停原因明细数据

            //插入操作记录
            foreach (DataRow drTransaction in dtTransaction.Rows)
            {
                string lotKey   = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]);     //批次主键
                string editor   = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);        //编辑人
                string timeZone = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);        //编辑时区
                if (Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]) != ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_RELEASE)
                {
                    throw new Exception("传入的操作名称不正确,请检查。");
                }
                string transactionKey = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY]);
                AddWIPLot(dbTran, transactionKey, lotKey);
                //向WIP_TRANSACTION表插入批次调整的操作记录。
                WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME] = DBNull.Value;
                string sql = DatabaseTable.BuildInsertSqlStatement(wipFields, drTransaction, null);
                db.ExecuteNonQuery(dbTran, CommandType.Text, sql);

                //更新批次数据
                StringBuilder sbUpdateSql = new StringBuilder();
                sbUpdateSql.AppendFormat(@"UPDATE POR_LOT 
                                           SET HOLD_FLAG=0,EDITOR='{1}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{2}'
                                           WHERE LOT_KEY='{0}'",
                                         lotKey.PreventSQLInjection(),
                                         editor.PreventSQLInjection(),
                                         timeZone.PreventSQLInjection());
                db.ExecuteNonQuery(dbTran, CommandType.Text, sbUpdateSql.ToString());
            }
            //更新暂停记录,用于释放批次。
            foreach (DataRow drHold in dtHold.Rows)
            {
                string transKey           = Convert.ToString(drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_TRANSACTION_KEY]);
                string releaseTransKey    = Convert.ToString(drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_RELEASE_TRANSACTION_KEY]);
                string releaseOperator    = Convert.ToString(drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_RELEASE_OPERATOR]);
                string releaseTimezone    = Convert.ToString(drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_RELEASE_TIMEZONE]);
                string releaseDescription = Convert.ToString(drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_RELEASE_DESCRIPTION]);
                string editTimezone       = Convert.ToString(drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_EDIT_TIMEZONE]);
                string editor             = Convert.ToString(drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_EDITOR]);
                string sql = string.Format(@"UPDATE WIP_HOLD_RELEASE
                                             SET IS_RELEASE=1,
                                                 RELEASE_TRANSACTION_KEY='{1}',
                                                 RELEASE_OPERATOR='{2}',
                                                 RELEASE_TIME=GETDATE(),
                                                 RELEASE_TIMEZONE='{3}',
                                                 RELEASE_DESCRIPTION='{4}',
                                                 EDIT_TIME=GETDATE(),
                                                 EDIT_TIMEZONE='{5}',
                                                 EDITOR='{6}'
                                             WHERE TRANSACTION_KEY='{0}'",
                                           transKey.PreventSQLInjection(),
                                           releaseTransKey.PreventSQLInjection(),
                                           releaseOperator.PreventSQLInjection(),
                                           releaseTimezone.PreventSQLInjection(),
                                           releaseDescription.PreventSQLInjection(),
                                           editTimezone.PreventSQLInjection(),
                                           editor.PreventSQLInjection());
                db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 将线边仓中的批次进行合并。
        /// </summary>
        /// <param name="db">数据库对象。</param>
        /// <param name="dbtran">数据库操作事务对象。</param>
        /// <param name="dsParams">
        /// 包含合批数据的数据集对象.
        /// (1)数据集对象中包含一个名称为<see cref="BASE_PARAMETER_FIELDS.DATABASE_TABLE_NAME"/>的数据表对象。
        /// 数据表中存放待合并的批次返工或退库数据。
        /// (2) 数据集对象中包含一个名称为<see cref="TRANS_TABLES.TABLE_MAIN_DATA"/>的数据表对象。
        /// 数据表中必须包含两个列"name"和"value"。列name存放哈希表的键名,列value存放哈希表键对应的键值。
        /// 键名:
        /// 合并到批次的返工或退库记录的主键<see cref="WST_STORE_MAT_FIELDS.FIELD_ROW_KEY"/>,
        /// 合并到批次的批次号<see cref="POR_LOT_FIELDS.FIELD_LOT_NUMBER"/>,
        /// 合并后批次的数量<see cref="POR_LOT_FIELDS.FIELD_QUANTITY"/>,
        /// 编辑人<see cref="WIP_TRANSACTION_FIELDS.FIELD_EDITOR"/>,
        /// 编辑时区<see cref="WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY"/>,
        /// 编辑时间<see cref="WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME"/>,
        /// 批次主键<see cref="POR_LOT_FIELDS.FIELD_LOT_KEY"/>。
        /// </param>
        private void MergeLotInStore(Database db, DbTransaction dbtran, DataSet dsParams)
        {
            String  sql      = string.Empty;
            DataSet dsReturn = new DataSet();
            DataSet ds;
            string  strParentRowKey        = "";
            string  strParentLotNumber     = "";
            string  strParentTransKey      = "";
            string  strParentStepKey       = "";
            string  strParentRouteKey      = "";
            string  strParentEnterpriseKey = "";
            string  strParentQTY           = "";
            string  strTotalQTY            = "";
            string  strSumQTY = "";
            string  strComment = "";
            string  strEditor = "", strEditTimeZone = "", strEditTime = "";
            string  strLineKey = "", strShiftName = "", strWorkOrderKey = "", strStateFlag = "";

            if (dsParams.Tables.Count > 0)//数据集中包含数据表。
            {
                DataTable dataTable = dsParams.Tables[TRANS_TABLES.TABLE_MAIN_DATA];
                Hashtable hashData  = SolarViewer.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dataTable);
                strParentRowKey    = hashData[WST_STORE_MAT_FIELDS.FIELD_ROW_KEY].ToString();
                strParentLotNumber = hashData["LOT_NUMBER"].ToString();
                strSumQTY          = hashData[POR_LOT_FIELDS.FIELD_QUANTITY].ToString();
                //strComment = hashData[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT].ToString();
                strEditor       = hashData[WIP_TRANSACTION_FIELDS.FIELD_EDITOR].ToString();
                strEditTimeZone = hashData[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY].ToString();
                strEditTime     = UtilHelper.GetSysdate(db).ToString("yyyy-MM-dd HH:mm:ss");
                // Get Lot Details
                ds = StoreEngine.GetStoreLotDetailsInfor(db, strParentRowKey);
                strParentStepKey       = ds.Tables[WST_STORE_MAT_FIELDS.DATABASE_TABLE_NAME].Rows[0][WST_STORE_MAT_FIELDS.FIELD_STEP_KEY].ToString();
                strParentRouteKey      = ds.Tables[WST_STORE_MAT_FIELDS.DATABASE_TABLE_NAME].Rows[0][WST_STORE_MAT_FIELDS.FIELD_ROUTE_KEY].ToString();
                strParentEnterpriseKey = ds.Tables[WST_STORE_MAT_FIELDS.DATABASE_TABLE_NAME].Rows[0][WST_STORE_MAT_FIELDS.FIELD_ENTERPRISE_KEY].ToString();
                strParentQTY           = ds.Tables[WST_STORE_MAT_FIELDS.DATABASE_TABLE_NAME].Rows[0][WST_STORE_MAT_FIELDS.FIELD_ITEM_QTY].ToString();

                strLineKey      = ds.Tables[WST_STORE_MAT_FIELDS.DATABASE_TABLE_NAME].Rows[0][WST_STORE_MAT_FIELDS.FIELD_LINE_KEY].ToString();
                strShiftName    = UtilHelper.GetShiftKey(db, strEditTime);
                strWorkOrderKey = ds.Tables[WST_STORE_MAT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY].ToString();

                //更新WST_STORE_MAT记录
                sql = string.Format(@"UPDATE WST_STORE_MAT 
                                    SET ITEM_QTY= '{0}', EDIT_TIME=GETDATE() 
                                    WHERE ROW_KEY='{1}'",
                                    strSumQTY.PreventSQLInjection(),
                                    strParentRowKey.PreventSQLInjection());
                db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                strTotalQTY = (Convert.ToInt32(strParentQTY) + Convert.ToInt32(strSumQTY)).ToString();

                WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();

                #region 合并批次操作记录
                Hashtable parenttransactionTable = new Hashtable();
                DataTable parenttransaction      = new DataTable();
                strParentTransKey = UtilHelper.GenerateNewKey(0);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, strParentTransKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, "0");
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, hashData[POR_LOT_FIELDS.FIELD_LOT_KEY].ToString());
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_CHILD_LOT_KEY, strParentRowKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, strParentQTY);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, strTotalQTY);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_STOREMERGE);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, strComment);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, strEditor);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, strEditTimeZone);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, strEditTime);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY, strLineKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME, strShiftName);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, strWorkOrderKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY, strParentStepKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY, strParentRouteKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY, strParentEnterpriseKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, strStateFlag);
                //向WIP_TRANSACTION插入合并到批次的操作记录
                sql = DatabaseTable.BuildInsertSqlStatement(wipFields, parenttransactionTable, null);
                db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                #endregion

                #region 生成子批次
                string strChildRowKey    = "";
                string strChildLotNumber = "";
                string strChildQty       = "";

                if (dsParams.Tables.Contains(BASE_PARAMETER_FIELDS.DATABASE_TABLE_NAME))
                {
                    DataTable parameterdatatable = dsParams.Tables[BASE_PARAMETER_FIELDS.DATABASE_TABLE_NAME];
                    for (int i = 0; i < parameterdatatable.Rows.Count; i++)
                    {
                        //更新WST_STORE_MAT数据
                        strChildRowKey    = parameterdatatable.Rows[i][WST_STORE_MAT_FIELDS.FIELD_ROW_KEY].ToString();
                        strChildLotNumber = parameterdatatable.Rows[i]["LOT_NUMBER"].ToString();
                        strChildQty       = parameterdatatable.Rows[i][WST_STORE_MAT_FIELDS.FIELD_ITEM_QTY].ToString();

                        sql = @"UPDATE WST_STORE_MAT 
                                SET ITEM_QTY='0',OBJECT_STATUS='3', EDIT_TIME=GETDATE() 
                                WHERE ROW_KEY='" + strChildRowKey.PreventSQLInjection() + "'";
                        db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                        //向WIP_TRANSACTION插入被合并批次的操作记录
                        Hashtable childtransactionTable = new Hashtable();
                        DataTable childtransaction      = new DataTable();
                        //sql = "";
                        string strChildTransKey = UtilHelper.GenerateNewKey(0);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, strChildTransKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, "0");
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, parameterdatatable.Rows[i][POR_LOT_FIELDS.FIELD_LOT_KEY].ToString());
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_CHILD_LOT_KEY, strChildRowKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, strChildQty);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, "0");
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_STORE_MERGED);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, "");
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, strEditor);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, strEditTimeZone);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, strEditTime);

                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY, strLineKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME, strShiftName);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, strWorkOrderKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY, strParentEnterpriseKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY, strParentRouteKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY, strParentStepKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, strStateFlag);
                        sql = DatabaseTable.BuildInsertSqlStatement(wipFields, childtransactionTable, null);
                        db.ExecuteNonQuery(dbtran, CommandType.Text, sql);

                        //向WIP_MERGE插入合并批次记录
                        Hashtable        MergeHashTable = new Hashtable();
                        WIP_MERGE_FIELDS wipMerge       = new WIP_MERGE_FIELDS();

                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_TRANSACTION_KEY, strParentTransKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_CHILD_LOT_KEY, strChildRowKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_MAIN_LOT_KEY, strParentRowKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_MERGE_QUANTITY, strChildQty);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_STEP_KEY, strParentStepKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_ROUTE_KEY, strParentRouteKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_ENTERPRISE_KEY, strParentEnterpriseKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_EDITOR, strEditor);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_EDIT_TIME, strEditTime);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_EDIT_TIMEZONE, strEditTimeZone);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_CHILD_TRANSACTION_KEY, strChildTransKey);
                        sql = DatabaseTable.BuildInsertSqlStatement(wipMerge, MergeHashTable, null);
                        db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                    }
                }
                #endregion
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 批次调整操作。
        /// </summary>
        /// <remarks>
        /// 操作名称:<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_ADJUST"/>。
        /// </remarks>
        /// <param name="dsParams">包含批次调整信息的数据集对象。</param>
        /// <returns>包含结果数据的数据集对象。</returns>
        public DataSet LotAdjust(DataSet dsParams)
        {
            DataSet       dsReturn = new DataSet();
            DbConnection  dbConn   = null;
            DbTransaction dbTran   = null;

            try
            {
                dbConn = db.CreateConnection();
                dbConn.Open();
                dbTran = dbConn.BeginTransaction();
                //参数数据。
                if (dsParams == null ||
                    !dsParams.Tables.Contains(TRANS_TABLES.TABLE_MAIN_DATA) ||
                    !dsParams.Tables.Contains(WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME) ||
                    !dsParams.Tables.Contains(WIP_COMMENT_FIELDS.DATABASE_TABLE_NAME))              //存放操作数据
                {
                    dbTran.Rollback();
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "传入参数不正确,请检查。");
                    return(dsReturn);
                }
                DataTable dtParams      = dsParams.Tables[TRANS_TABLES.TABLE_MAIN_DATA];               //存放修改后批次数据
                DataTable dtTransaction = dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME]; //存放操作数据
                DataTable dtComment     = dsParams.Tables[WIP_COMMENT_FIELDS.DATABASE_TABLE_NAME];     //存放批次调整明细数据
                Hashtable htParams      = CommonUtils.ConvertToHashtable(dtParams);
                //检查是否存在重复的批次主键。
                var lnq = from item in dtTransaction.AsEnumerable()
                          group item by item[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY] into g
                          where g.Count() > 1
                          select g.Count();

                if (lnq.Count() > 0)
                {
                    dbTran.Rollback();
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "存在重复记录,请检查。");
                    return(dsReturn);
                }
                //检查记录是否过期。防止重复修改。
                foreach (DataRow drTransaction in dtTransaction.Rows)
                {
                    string opEditTime = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME]);   //操作前批次编辑时间
                    string lotKey     = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]);   //批次主键
                    string editor     = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);      //编辑人
                    string timeZone   = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);      //编辑时区
                    //检查记录是否过期。防止重复修改。
                    KeyValuePair <string, string>         kvp           = new KeyValuePair <string, string>(POR_LOT_FIELDS.FIELD_LOT_KEY, lotKey);
                    List <KeyValuePair <string, string> > listCondition = new List <KeyValuePair <string, string> >();
                    listCondition.Add(kvp);
                    //如果记录过期,当前编辑时间<数据库中的记录编辑时间。结束方法执行。
                    if (UtilHelper.CheckRecordExpired(db, POR_LOT_FIELDS.DATABASE_TABLE_NAME, listCondition, opEditTime))
                    {
                        dbTran.Rollback();
                        ReturnMessageUtils.AddServerReturnMessage(dsReturn, "信息已过期,请关闭该界面后重试。");
                        return(dsReturn);
                    }
                }
                //插入操作记录
                foreach (DataRow drTransaction in dtTransaction.Rows)
                {
                    if (Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]) != ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_ADJUST)
                    {
                        throw new Exception("传入操作动作名称不正确,请检查。");
                    }
                    string transactionKey = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY]);
                    string lotKey         = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]); //批次主键
                    string editor         = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);    //编辑人
                    string timeZone       = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);    //编辑时区
                    AddWIPLot(dbTran, transactionKey, lotKey);
                    //向WIP_TRANSACTION表插入批次调整的操作记录。
                    WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
                    drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME] = DBNull.Value;
                    string sql = DatabaseTable.BuildInsertSqlStatement(wipFields, drTransaction, null);
                    db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                    //更新批次信息。
                    StringBuilder sbUpdateSql = new StringBuilder();
                    sbUpdateSql.AppendFormat("UPDATE POR_LOT SET EDITOR='{0}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{1}'",
                                             editor.PreventSQLInjection(),
                                             timeZone.PreventSQLInjection());
                    if (htParams.ContainsKey(POR_LOT_FIELDS.FIELD_LOT_NUMBER))
                    {
                        sbUpdateSql.AppendFormat(",LOT_NUMBER='{0}'",
                                                 Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_LOT_NUMBER]).PreventSQLInjection());
                    }
                    if (htParams.ContainsKey(POR_LOT_FIELDS.FIELD_PRO_ID))
                    {
                        sbUpdateSql.AppendFormat(",PRO_ID='{0}'",
                                                 Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_PRO_ID]).PreventSQLInjection());
                    }
                    if (htParams.ContainsKey(POR_LOT_FIELDS.FIELD_CREATE_TYPE))
                    {
                        sbUpdateSql.AppendFormat(",CREATE_TYPE='{0}'",
                                                 Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_CREATE_TYPE]).PreventSQLInjection());
                    }
                    if (htParams.ContainsKey(POR_LOT_FIELDS.FIELD_LOT_TYPE))
                    {
                        sbUpdateSql.AppendFormat(",LOT_TYPE='{0}'",
                                                 Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_LOT_TYPE]).PreventSQLInjection());
                    }
                    if (htParams.ContainsKey(POR_LOT_FIELDS.FIELD_PRIORITY))
                    {
                        sbUpdateSql.AppendFormat(",PRIORITY='{0}'",
                                                 Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_PRIORITY]).PreventSQLInjection());
                    }
                    if (htParams.ContainsKey(POR_LOT_FIELDS.FIELD_EFFICIENCY))
                    {
                        sbUpdateSql.AppendFormat(",EFFICIENCY='{0}'",
                                                 Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_EFFICIENCY]).PreventSQLInjection());
                    }
                    if (htParams.ContainsKey(POR_LOT_FIELDS.FIELD_SI_LOT))
                    {
                        sbUpdateSql.AppendFormat(",SI_LOT='{0}'",
                                                 Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_SI_LOT]).PreventSQLInjection());
                    }
                    if (htParams.ContainsKey(POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY))
                    {
                        sbUpdateSql.AppendFormat(",ROUTE_ENTERPRISE_VER_KEY='{0}'",
                                                 Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY]).PreventSQLInjection());
                    }
                    if (htParams.ContainsKey(POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY))
                    {
                        sbUpdateSql.AppendFormat(",CUR_ROUTE_VER_KEY='{0}'",
                                                 Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]).PreventSQLInjection());
                    }
                    if (htParams.ContainsKey(POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY))
                    {
                        string stepKey = Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]);
                        sbUpdateSql.AppendFormat(",CUR_STEP_VER_KEY='{0}',STATE_FLAG='{1}',START_WAIT_TIME=GETDATE()",
                                                 stepKey.PreventSQLInjection(), 0); //更新批次状态为等待进站。
                        //更新设备数据,以完成设备出站,切换设备状态。
                        sql = string.Format(@"SELECT B.EQUIPMENT_KEY,A.EQUIPMENT_NAME,A.EQUIPMENT_STATE_KEY
                                                    FROM EMS_EQUIPMENTS A,EMS_LOT_EQUIPMENT B
                                                    WHERE A.EQUIPMENT_KEY = B.EQUIPMENT_KEY 
                                                    AND B.STEP_KEY = '{0}' AND B.LOT_KEY='{1}' 
                                                    AND B.END_TIMESTAMP IS NULL",
                                            stepKey.PreventSQLInjection(),
                                            lotKey.PreventSQLInjection());
                        DataSet dsResult = db.ExecuteDataSet(CommandType.Text, sql);
                        if (dsResult != null && dsResult.Tables.Count > 0 && dsResult.Tables[0].Rows.Count > 0)
                        {
                            string equipmentKey = Convert.ToString(dsResult.Tables[0].Rows[0]["EQUIPMENT_KEY"]);
                            WipManagement.TrackOutForEquipment(db, dbTran, lotKey, stepKey, equipmentKey, editor);
                        }
                    }
                    sbUpdateSql.AppendFormat(" WHERE LOT_KEY='{0}'", lotKey.PreventSQLInjection());
                    db.ExecuteNonQuery(dbTran, CommandType.Text, sbUpdateSql.ToString());
                }
                //插入批次调整明细记录
                foreach (DataRow drComment in dtComment.Rows)
                {
                    //向WIP_COMMENT表插入批次调整的操作记录。
                    WIP_COMMENT_FIELDS commentFields = new WIP_COMMENT_FIELDS();
                    string             sql           = DatabaseTable.BuildInsertSqlStatement(commentFields, drComment, null);
                    db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                }
                dbTran.Commit();
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Empty);
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("LotAdjust Error: " + ex.Message);
                dbTran.Rollback();
            }
            finally
            {
                dbConn.Close();
            }
            return(dsReturn);
        }
Exemplo n.º 13
0
        /// <summary>
        ///(电池片/组件)报废操作
        /// </summary>
        /// <remarks>
        /// 操作名称:<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_CELLSCRAP"/>和<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_SCRAP"/>。
        /// </remarks>
        /// <param name="dsParams">包含报废信息的数据集对象。</param>
        /// <param name="dbTran">数据库操作事务对象。</param>
        private void LotScrap(DataSet dsParams, DbTransaction dbTran)
        {
            //参数数据。
            if (dsParams == null ||
                !dsParams.Tables.Contains(WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME) ||
                !dsParams.Tables.Contains(WIP_SCRAP_FIELDS.DATABASE_TABLE_NAME) ||
                dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME].Rows.Count == 0         //批次操作记录不能为空记录。
                )
            {
                throw new Exception("传入参数不正确,请检查。");
            }
            DataTable dtTransaction = dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME];             //存放操作数据
            Hashtable htTransaction = CommonUtils.ConvertToHashtable(dtTransaction);
            string    lotKey        = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]); //批次主键
            string    activity      = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]);

            //操作动作必须是 SCRAP 或 CELLSCRAP
            if (activity != ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_SCRAP &&
                activity != ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_CELLSCRAP)
            {
                throw new Exception("传入参数的报废操作动作不正确,请检查。");
            }
            string transactionKey = UtilHelper.GenerateNewKey(0);

            AddWIPLot(dbTran, transactionKey, lotKey);

            string sql = string.Empty;

            //是否是组件报废操作?
            if (activity == ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_SCRAP)
            {
                //更新批次状态。
                sql = string.Format(@"UPDATE POR_LOT 
                                    SET DELETED_TERM_FLAG=1
                                    WHERE LOT_KEY='{0}'",
                                    lotKey.PreventSQLInjection());
                db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
            }
            //向WIP_TRANSACTION表插入批次报废的操作记录。
            WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();

            if (!htTransaction.ContainsKey(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY))
            {
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
            }
            htTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY] = transactionKey;
            sql = DatabaseTable.BuildInsertSqlStatement(wipFields, htTransaction, null);
            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
            //如果数据集中包含名称WIP_SCRAP_FIELDS.DATABASE_TABLE_NAME的数据表对象。
            if (dsParams.Tables.Contains(WIP_SCRAP_FIELDS.DATABASE_TABLE_NAME))
            {
                WIP_SCRAP_FIELDS scrapFields = new WIP_SCRAP_FIELDS();
                DataTable        dtScrap     = dsParams.Tables[WIP_SCRAP_FIELDS.DATABASE_TABLE_NAME];   //存放报废明细数据
                //遍历批次的报废数据。
                for (int i = 0; i < dtScrap.Rows.Count; i++)
                {
                    DataRow   drScrap = dtScrap.Rows[i];
                    Hashtable htScrap = CommonUtils.ConvertRowToHashtable(drScrap);
                    if (!htScrap.ContainsKey(WIP_SCRAP_FIELDS.FIELD_TRANSACTION_KEY))
                    {
                        htScrap.Add(WIP_SCRAP_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
                    }
                    htScrap[WIP_SCRAP_FIELDS.FIELD_TRANSACTION_KEY] = transactionKey;
                    //插入一笔批次报废数据。
                    sql = DatabaseTable.BuildInsertSqlStatement(scrapFields, htScrap, null);
                    db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// 保存,调整批次。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbOK_Click(object sender, EventArgs e)
        {
            DataTable dtLotInfo = this.gcList.DataSource as DataTable;

            if (dtLotInfo.Rows.Count < 1)
            {
                MessageService.ShowMessage("待调整批次信息列表至少要有一条记录。", "提示");
                return;
            }
            string newLotNumber      = this.teLotNumber.Text.Trim().ToUpper();
            string newProId          = Convert.ToString(this.lueProId.EditValue);
            string newCreateType     = Convert.ToString(this.lueCreateType.EditValue);
            string newLotType        = Convert.ToString(this.lueLotType.EditValue);
            string newPriority       = Convert.ToString(this.luePriority.EditValue);
            string newEfficiency     = Convert.ToString(this.lueEfficiency.EditValue);
            string newSiLot          = this.teSILot.Text.Trim();
            string newEnterpriseName = this.beEnterpriseName.Text;
            string newEnterpriseKey  = Convert.ToString(this.beEnterpriseName.Tag);
            string newRouteName      = this.teRouteName.Text;
            string newRouteKey       = Convert.ToString(this.teRouteName.Tag);
            string newStepName       = this.teStepName.Text;
            string newStepKey        = Convert.ToString(this.teStepName.Tag);
            string remark            = this.teRemark.Text;

            //必须要输入一个调整项目。
            if (string.IsNullOrEmpty(newLotNumber) &&
                string.IsNullOrEmpty(newProId) &&
                string.IsNullOrEmpty(newCreateType) &&
                string.IsNullOrEmpty(newLotType) &&
                string.IsNullOrEmpty(newPriority) &&
                string.IsNullOrEmpty(newEfficiency) &&
                string.IsNullOrEmpty(newSiLot) &&
                string.IsNullOrEmpty(newStepKey))
            {
                MessageService.ShowMessage("必须要输入一个调整项目。", "提示");
                return;
            }
            //如果批次号不为空,则判断批次号是否存在。
            if (!string.IsNullOrEmpty(newLotNumber))
            {
                LotQueryEntity queryEntity = new LotQueryEntity();
                DataSet        dsReturn    = queryEntity.GetLotInfo(newLotNumber);
                if (!string.IsNullOrEmpty(queryEntity.ErrorMsg))
                {
                    MessageService.ShowError(queryEntity.ErrorMsg);
                    dsReturn = null;
                    return;
                }
                if (dsReturn.Tables[0].Rows.Count > 0)
                {
                    MessageService.ShowMessage(string.Format("【{0}】在数据库中已存在,请确认。", newLotNumber));
                    dsReturn = null;
                    return;
                }
            }
            string shiftName = this._model.ShiftName;
            string shiftKey  = string.Empty;
            //Shift shiftEntity = new Shift();
            //string shiftKey = shiftEntity.IsShiftValueExists(shiftName);//班次主键。
            ////获取班次主键失败。
            //if (!string.IsNullOrEmpty(shiftEntity.ErrorMsg))
            //{
            //    MessageService.ShowError(shiftEntity.ErrorMsg);
            //    return;
            //}
            ////没有排班。
            //if (string.IsNullOrEmpty(shiftKey))
            //{
            //    MessageService.ShowMessage("请先在系统中进行排班。", "提示");
            //    return;
            //}
            string oprComputer = PropertyService.Get(PROPERTY_FIELDS.COMPUTER_NAME);
            string timezone    = PropertyService.Get(PROPERTY_FIELDS.TIMEZONE);

            DataSet dsParams = new DataSet();
            //存放新批次信息。
            Hashtable htMaindata = new Hashtable();
            //存放待调整的批次的操作数据
            WIP_TRANSACTION_FIELDS transFields = new WIP_TRANSACTION_FIELDS();
            DataTable dtTransaction            = CommonUtils.CreateDataTable(transFields);
            //存放调整操作的明细记录。
            WIP_COMMENT_FIELDS commentFileds = new WIP_COMMENT_FIELDS();
            DataTable          dtComment     = CommonUtils.CreateDataTable(commentFileds);
            StringBuilder      afterContent  = new StringBuilder();

            foreach (DataRow dr in dtLotInfo.Rows)
            {
                //组织待调整的批次的操作数据
                DataRow drTransaction = dtTransaction.NewRow();
                dtTransaction.Rows.Add(drTransaction);
                string transKey = CommonUtils.GenerateNewKey(0);
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY]  = transKey;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]        = dr[POR_LOT_FIELDS.FIELD_LOT_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]         = ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_ADJUST;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN]      = dr[POR_LOT_FIELDS.FIELD_QUANTITY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT]     = dr[POR_LOT_FIELDS.FIELD_QUANTITY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY]   = dr[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_NAME]  = dr[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ENTERPRISE_NAME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY]        = dr[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_NAME]       = dr[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_NAME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY]         = dr[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_NAME]        = dr[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY]   = dr[POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY]        = shiftKey;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME]       = shiftName;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG]       = dr[POR_LOT_FIELDS.FIELD_STATE_FLAG];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG]      = dr[POR_LOT_FIELDS.FIELD_IS_REWORKED];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPERATOR]         = this._model.UserName;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER]     = oprComputer;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY]         = dr[POR_LOT_FIELDS.FIELD_CUR_PRODUCTION_LINE_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE]         = dr[POR_LOT_FIELDS.FIELD_OPR_LINE];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE_PRE]     = dr[POR_LOT_FIELDS.FIELD_OPR_LINE_PRE];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDC_INS_KEY]      = dr[POR_LOT_FIELDS.FIELD_EDC_INS_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EQUIPMENT_KEY]    = dr[EMS_EQUIPMENTS_FIELDS.FIELD_EQUIPMENT_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT] = remark;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]           = this._model.UserName;
                //用于暂存序列号批次信息最后的编辑时间,以便判断序列号信息是否过期。
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME]         = dr[POR_LOT_FIELDS.FIELD_EDIT_TIME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY] = timezone;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TIME_STAMP]        = DBNull.Value;
                //组织待调整的批次的明细操作数据
                DataRow drComment = dtComment.NewRow();
                dtComment.Rows.Add(drComment);
                drComment[WIP_COMMENT_FIELDS.FIELDS_TRANSACTION_KEY] = transKey;
                drComment[WIP_COMMENT_FIELDS.FIELDS_ENTERPRISE_KEY]  = dr[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY];
                drComment[WIP_COMMENT_FIELDS.FIELDS_ROUTE_KEY]       = dr[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY];
                drComment[WIP_COMMENT_FIELDS.FIELDS_STEP_KEY]        = dr[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY];
                drComment[WIP_COMMENT_FIELDS.FIELDS_EDIT_TIMEZONE]   = timezone;
                drComment[WIP_COMMENT_FIELDS.FIELDS_EDIT_TIME]       = DBNull.Value;
                drComment[WIP_COMMENT_FIELDS.FIELDS_EDITOR]          = this._model.UserName;
                StringBuilder beforeContent = new StringBuilder();
                //新批次号不为空。
                if (!string.IsNullOrEmpty(newLotNumber))
                {
                    if (!htMaindata.ContainsKey(POR_LOT_FIELDS.FIELD_LOT_NUMBER))
                    {
                        htMaindata.Add(POR_LOT_FIELDS.FIELD_LOT_NUMBER, newLotNumber);
                        afterContent.AppendFormat("批次号:{0};", newLotNumber);
                    }
                    beforeContent.AppendFormat("批次号:{0};", dr[POR_LOT_FIELDS.FIELD_LOT_NUMBER]);
                }
                //新产品ID号不为空
                if (!string.IsNullOrEmpty(newProId))
                {
                    if (!htMaindata.ContainsKey(POR_LOT_FIELDS.FIELD_PRO_ID))
                    {
                        htMaindata.Add(POR_LOT_FIELDS.FIELD_PRO_ID, newProId);
                        afterContent.AppendFormat("产品ID号:{0};", newProId);
                    }
                    beforeContent.AppendFormat("产品ID号:{0};", dr[POR_LOT_FIELDS.FIELD_PRO_ID]);
                }
                //新的创建类别。
                if (!string.IsNullOrEmpty(newCreateType))
                {
                    if (!htMaindata.ContainsKey(POR_LOT_FIELDS.FIELD_CREATE_TYPE))
                    {
                        htMaindata.Add(POR_LOT_FIELDS.FIELD_CREATE_TYPE, newCreateType);
                        afterContent.AppendFormat("创建类别:{0};", newCreateType);
                    }
                    beforeContent.AppendFormat("创建类别:{0};", dr[POR_LOT_FIELDS.FIELD_CREATE_TYPE]);
                }
                //新的批次类别。
                if (!string.IsNullOrEmpty(newLotType))
                {
                    if (!htMaindata.ContainsKey(POR_LOT_FIELDS.FIELD_LOT_TYPE))
                    {
                        htMaindata.Add(POR_LOT_FIELDS.FIELD_LOT_TYPE, newLotType);
                        afterContent.AppendFormat("批次类别:{0};", newLotType);
                    }
                    beforeContent.AppendFormat("批次类别:{0};", dr[POR_LOT_FIELDS.FIELD_LOT_TYPE]);
                }
                //新的优先级。
                if (!string.IsNullOrEmpty(newPriority))
                {
                    if (!htMaindata.ContainsKey(POR_LOT_FIELDS.FIELD_PRIORITY))
                    {
                        htMaindata.Add(POR_LOT_FIELDS.FIELD_PRIORITY, newPriority);
                        afterContent.AppendFormat("优先级:{0};", newPriority);
                    }
                    beforeContent.AppendFormat("优先级:{0};", dr[POR_LOT_FIELDS.FIELD_PRIORITY]);
                }
                //新的转换效率。
                if (!string.IsNullOrEmpty(newEfficiency))
                {
                    if (!htMaindata.ContainsKey(POR_LOT_FIELDS.FIELD_EFFICIENCY))
                    {
                        htMaindata.Add(POR_LOT_FIELDS.FIELD_EFFICIENCY, newEfficiency);
                        afterContent.AppendFormat("转换效率:{0};", newEfficiency);
                    }
                    beforeContent.AppendFormat("转换效率:{0};", dr[POR_LOT_FIELDS.FIELD_EFFICIENCY]);
                }
                //新的硅片供应商。
                if (!string.IsNullOrEmpty(newSiLot))
                {
                    if (!htMaindata.ContainsKey(POR_LOT_FIELDS.FIELD_SI_LOT))
                    {
                        htMaindata.Add(POR_LOT_FIELDS.FIELD_SI_LOT, newSiLot);
                        afterContent.AppendFormat("硅片供应商:{0};", newSiLot);
                    }
                    beforeContent.AppendFormat("硅片供应商:{0};", dr[POR_LOT_FIELDS.FIELD_SI_LOT]);
                }
                //新的工步主键。
                if (!string.IsNullOrEmpty(newStepKey))
                {
                    if (!htMaindata.ContainsKey(POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY))
                    {
                        htMaindata.Add(POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY, newEnterpriseKey);
                        afterContent.AppendFormat("工艺流程组:{0};", newEnterpriseName);
                    }
                    if (!htMaindata.ContainsKey(POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY))
                    {
                        htMaindata.Add(POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY, newRouteKey);
                        afterContent.AppendFormat("工艺流程:{0};", newRouteName);
                    }
                    if (!htMaindata.ContainsKey(POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY))
                    {
                        htMaindata.Add(POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY, newStepKey);
                        afterContent.AppendFormat("工序:{0};", newStepName);
                    }
                    drComment[WIP_COMMENT_FIELDS.FIELDS_ENTERPRISE_KEY] = newEnterpriseKey;
                    drComment[WIP_COMMENT_FIELDS.FIELDS_ROUTE_KEY]      = newRouteKey;
                    drComment[WIP_COMMENT_FIELDS.FIELDS_STEP_KEY]       = newStepKey;
                    beforeContent.AppendFormat("工艺流程组:{0};", dr[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ENTERPRISE_NAME]);
                    beforeContent.AppendFormat("工艺流程:{0};", dr[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_NAME]);
                    beforeContent.AppendFormat("工序:{0};", dr[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME]);
                }
                drComment[WIP_COMMENT_FIELDS.FIELDS_BEFORE_CONTENT] = beforeContent;
                drComment[WIP_COMMENT_FIELDS.FIELDS_AFTER_CONTENT]  = afterContent;
            }
            DataTable dtMaindata = CommonUtils.ParseToDataTable(htMaindata);

            dtMaindata.TableName = TRANS_TABLES.TABLE_MAIN_DATA;
            dsParams.Tables.Add(dtMaindata);
            dsParams.Tables.Add(dtTransaction);
            dsParams.Tables.Add(dtComment);
            //执行调整批次。
            this._entity.LotAdjust(dsParams);
            if (!string.IsNullOrEmpty(this._entity.ErrorMsg))
            {
                MessageService.ShowError(this._entity.ErrorMsg);
            }
            else
            {
                //this.tsbCancle_Click(sender, e);
                MessageService.ShowMessage("保存成功");
                WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.CloseWindow(false);
                //重新打开批次创建视图。
                LotOperationViewContent view = new LotOperationViewContent(this._model.OperationType);
                WorkbenchSingleton.Workbench.ShowView(view);
            }
            dsParams.Tables.Clear();
            dtTransaction = null;
            dtComment     = null;
            dsParams      = null;
        }
Exemplo n.º 15
0
        /// <summary>
        /// 保存,暂停批次。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbOK_Click(object sender, EventArgs e)
        {
            if (this.gvHoldInfoList.State == GridState.Editing &&
                this.gvHoldInfoList.IsEditorFocused &&
                this.gvHoldInfoList.EditingValueModified)
            {
                this.gvHoldInfoList.SetFocusedRowCellValue(this.gvHoldInfoList.FocusedColumn, this.gvHoldInfoList.EditingValue);
            }
            this.gvHoldInfoList.UpdateCurrentRow();

            DataTable dtLotInfo = this.gcLotList.DataSource as DataTable;

            if (dtLotInfo.Rows.Count < 1)
            {
                MessageService.ShowMessage("待暂停批次信息列表至少要有一条记录。", "提示");
                return;
            }
            DataTable dtHoldInfo = this.gcHoldInfoList.DataSource as DataTable;

            if (dtHoldInfo.Rows.Count < 1)
            {
                MessageService.ShowMessage("暂停信息列表至少要有一条记录。", "提示");
                return;
            }
            string remark = this.teRemark.Text.Trim();

            if (string.IsNullOrEmpty(remark))
            {
                MessageService.ShowMessage("备注必须输入。", "提示");
                this.teRemark.Select();
                return;
            }
            //暂停组代码必须输入
            var lnq = from item in dtHoldInfo.AsEnumerable()
                      where string.IsNullOrEmpty(Convert.ToString(item[WIP_HOLD_RELEASE_FIELDS.FIELD_REASON_CODE_CATEGORY_KEY]))
                      select item;

            foreach (var item in lnq)
            {
                MessageService.ShowMessage("暂停组代码必须输入。", "提示");
                this.gvHoldInfoList.FocusedColumn    = this.gclReasonCodeGroup;
                this.gvHoldInfoList.FocusedRowHandle = dtHoldInfo.Rows.IndexOf(item);
                this.gvHoldInfoList.ShowEditor();
                return;
            }
            //暂停名称必须输入
            lnq = from item in dtHoldInfo.AsEnumerable()
                  where string.IsNullOrEmpty(Convert.ToString(item[WIP_HOLD_RELEASE_FIELDS.FIELD_REASON_CODE_KEY]))
                  select item;

            foreach (var item in lnq)
            {
                MessageService.ShowMessage("暂停名称必须输入。", "提示");
                this.gvHoldInfoList.FocusedColumn    = this.gclReasonCode;
                this.gvHoldInfoList.FocusedRowHandle = dtHoldInfo.Rows.IndexOf(item);
                this.gvHoldInfoList.ShowEditor();
                return;
            }
            //密码和确认密码不匹配。
            lnq = from item in dtHoldInfo.AsEnumerable()
                  where Convert.ToString(item[WIP_HOLD_RELEASE_FIELDS.FIELD_HOLD_PASSWORD]) != Convert.ToString(item[TMP_HOLD_INFO_CONFIRM_HOLD_PASSWORD])
                  select item;

            foreach (var item in lnq)
            {
                MessageService.ShowMessage("暂停密码和确认密码不匹配。", "提示");
                this.gvHoldInfoList.FocusedColumn    = this.gclPassword;
                this.gvHoldInfoList.FocusedRowHandle = dtHoldInfo.Rows.IndexOf(item);
                this.gvHoldInfoList.ShowEditor();
                return;
            }

            string shiftName = this._model.ShiftName;
            string shiftKey  = string.Empty;
            //string shiftKey = shiftEntity.IsShiftValueExists(shiftName);//班次主键。
            //Shift shiftEntity = new Shift();
            ////获取班次主键失败。
            //if (!string.IsNullOrEmpty(shiftEntity.ErrorMsg))
            //{
            //    MessageService.ShowError(shiftEntity.ErrorMsg);
            //    return;
            //}
            ////没有排班。
            //if (string.IsNullOrEmpty(shiftKey))
            //{
            //    MessageService.ShowMessage("请先在系统中进行排班。", "提示");
            //    return;
            //}
            string oprComputer = PropertyService.Get(PROPERTY_FIELDS.COMPUTER_NAME);
            string timezone    = PropertyService.Get(PROPERTY_FIELDS.TIMEZONE);

            DataSet dsParams = new DataSet();
            //存放待暂停的批次的操作数据
            WIP_TRANSACTION_FIELDS transFields = new WIP_TRANSACTION_FIELDS();
            DataTable dtTransaction            = CommonUtils.CreateDataTable(transFields);

            foreach (DataRow dr in dtLotInfo.Rows)
            {
                //组织待暂停的批次的操作数据
                DataRow drTransaction = dtTransaction.NewRow();
                dtTransaction.Rows.Add(drTransaction);
                string transKey = CommonUtils.GenerateNewKey(0);
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY]  = transKey;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]        = dr[POR_LOT_FIELDS.FIELD_LOT_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]         = ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_HOLD;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN]      = dr[POR_LOT_FIELDS.FIELD_QUANTITY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT]     = dr[POR_LOT_FIELDS.FIELD_QUANTITY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY]   = dr[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_NAME]  = dr[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ENTERPRISE_NAME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY]        = dr[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_NAME]       = dr[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_NAME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY]         = dr[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_NAME]        = dr[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY]   = dr[POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY]        = shiftKey;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME]       = shiftName;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG]       = dr[POR_LOT_FIELDS.FIELD_STATE_FLAG];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG]      = dr[POR_LOT_FIELDS.FIELD_IS_REWORKED];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPERATOR]         = this._model.UserName;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER]     = oprComputer;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY]         = dr[POR_LOT_FIELDS.FIELD_CUR_PRODUCTION_LINE_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE]         = dr[POR_LOT_FIELDS.FIELD_OPR_LINE];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE_PRE]     = dr[POR_LOT_FIELDS.FIELD_OPR_LINE_PRE];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDC_INS_KEY]      = dr[POR_LOT_FIELDS.FIELD_EDC_INS_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EQUIPMENT_KEY]    = dr[EMS_EQUIPMENTS_FIELDS.FIELD_EQUIPMENT_KEY];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT] = remark;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]           = this._model.UserName;
                //用于暂存序列号批次信息最后的编辑时间,以便判断序列号信息是否过期。
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME]         = dr[POR_LOT_FIELDS.FIELD_EDIT_TIME];
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY] = timezone;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TIME_STAMP]        = DBNull.Value;
            }
            //存放暂停操作的明细记录。
            DataTable dtHoldParams = dtHoldInfo.Copy();

            dtHoldParams.Columns.Remove(TMP_HOLD_INFO_CONFIRM_HOLD_PASSWORD);     //移除临时列。
            foreach (DataRow dr in dtHoldParams.Rows)
            {
                dr[WIP_HOLD_RELEASE_FIELDS.FIELD_HOLD_OPERATOR] = this._model.UserName;
                dr[WIP_HOLD_RELEASE_FIELDS.FIELD_HOLD_TIMEZONE] = timezone;
                dr[WIP_HOLD_RELEASE_FIELDS.FIELD_EDITOR]        = this._model.UserName;
                dr[WIP_HOLD_RELEASE_FIELDS.FIELD_EDIT_TIMEZONE] = timezone;
            }
            dsParams.Tables.Add(dtTransaction);
            dsParams.Tables.Add(dtHoldParams);
            //执行暂停批次。
            this._entity.LotHold(dsParams);
            if (!string.IsNullOrEmpty(this._entity.ErrorMsg))
            {
                MessageService.ShowError(this._entity.ErrorMsg);
            }
            else
            {
                //this.tsbCancle_Click(sender, e);
                MessageService.ShowMessage("保存成功");
                WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.CloseWindow(false);
                //重新打开批次创建视图。
                LotOperationViewContent view = new LotOperationViewContent(this._model.OperationType);
                WorkbenchSingleton.Workbench.ShowView(view);
            }
            dsParams.Tables.Clear();
            dtTransaction = null;
            dtHoldParams  = null;
            dsParams      = null;
        }
Exemplo n.º 16
0
        /// <summary>
        /// 暂停生产批次。
        /// </summary>
        /// <param name="db">数据库对象。</param>
        /// <param name="dbtran">数据库事务对象。</param>
        /// <param name="dsParams">包含暂停生产批次数据的数据集。</param>
        private static void HoldLot(Database db, DbTransaction dbtran, DataSet dsParams)
        {
            if (!dsParams.Tables.Contains(TRANS_TABLES.TABLE_MAIN_DATA))
            {
                return;
            }
            DataTable dtParams = dsParams.Tables[TRANS_TABLES.TABLE_MAIN_DATA];
            Hashtable htParams = CommonUtils.ConvertToHashtable(dtParams);

            string lotKey         = Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_LOT_KEY]);
            string transactionKey = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY]);
            string reasonCode     = Convert.ToString(htParams[WIP_HOLD_RELEASE_FIELDS.FIELD_REASON_CODE_KEY]);
            string reasonCodeName = Convert.ToString(htParams[WIP_HOLD_RELEASE_FIELDS.FIELD_REASON_CODE_NAME]);
            string comment        = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT]);
            string shiftName      = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME]);
            string shiftKey       = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY]);
            string oprComputer    = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER]);
            string opUser         = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_OPERATOR]);
            string editor         = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);
            string editTimeZone   = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY]);

            DataSet dsLot = GetLotsInfo(db, dbtran, lotKey);

            if (null != dsLot &&
                dsLot.Tables.Count > 0 &&
                dsLot.Tables[0].Rows.Count > 0)
            {
                DataRow drLot = dsLot.Tables[0].Rows[0];

                //组织暂停操作数据。
                WIP_TRANSACTION_FIELDS transFileds = new WIP_TRANSACTION_FIELDS();
                DataTable dtHoldTransaction        = CommonUtils.CreateDataTable(transFileds);
                DataRow   drHoldTransaction        = dtHoldTransaction.NewRow();
                dtHoldTransaction.Rows.Add(drHoldTransaction);
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]          = ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_HOLD;
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT]  = "检验数据超出控制线。";
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDC_INS_KEY]       = drLot[POR_LOT_FIELDS.FIELD_EDC_INS_KEY];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME]         = DBNull.Value;
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY] = editTimeZone;
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]            = editor;
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY]    = drLot[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_NAME]   = drLot[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ENTERPRISE_NAME];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_EQUIPMENT_KEY]     = drLot[EMS_EQUIPMENTS_FIELDS.FIELD_EQUIPMENT_KEY];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY]         = drLot[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_NAME]        = drLot[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_NAME];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY]          = drLot[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_NAME]         = drLot[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY]          = drLot[POR_LOT_FIELDS.FIELD_CUR_PRODUCTION_LINE_KEY];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPERATOR]          = "system";
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER]      = oprComputer;
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE]          = drLot[POR_LOT_FIELDS.FIELD_LINE_NAME];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE_PRE]      = drLot[POR_LOT_FIELDS.FIELD_OPR_LINE_PRE];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]         = lotKey;
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE]        = 0;
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN]       = drLot[POR_LOT_FIELDS.FIELD_QUANTITY];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT]      = drLot[POR_LOT_FIELDS.FIELD_QUANTITY];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG]       = drLot[POR_LOT_FIELDS.FIELD_IS_REWORKED];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY]         = shiftKey;
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME]        = shiftName;
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG]        = drLot[POR_LOT_FIELDS.FIELD_STATE_FLAG];
                drHoldTransaction[WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY]    = drLot[POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY];
                //组织暂停数据
                //检查生产批次对应的工步是否设置了预设暂停批次的自定义属性。
                string 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));
                WIP_HOLD_RELEASE_FIELDS holdFields = new WIP_HOLD_RELEASE_FIELDS();
                DataTable dtHold = CommonUtils.CreateDataTable(holdFields);
                DataRow   drHold = dtHold.NewRow();
                dtHold.Rows.Add(drHold);
                drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_EDIT_TIME]                 = DBNull.Value;
                drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_EDIT_TIMEZONE]             = editTimeZone;
                drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_EDITOR]                    = "system";
                drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_HOLD_DESCRIPTION]          = comment;
                drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_HOLD_OPERATOR]             = "system";
                drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_HOLD_PASSWORD]             = holdPassword;
                drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_HOLD_TIME]                 = DBNull.Value;
                drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_HOLD_TIMEZONE]             = editTimeZone;
                drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_REASON_CODE_CATEGORY_KEY]  = string.Empty;
                drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_REASON_CODE_CATEGORY_NAME] = string.Empty;
                drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_REASON_CODE_KEY]           = string.Empty;
                drHold[WIP_HOLD_RELEASE_FIELDS.FIELD_REASON_CODE_NAME]          = string.Empty;
                //组织暂停参数。
                DataSet dsHoldParams = new DataSet();
                dsHoldParams.Tables.Add(dtHoldTransaction);
                dsHoldParams.Tables.Add(dtHold);
                //执行批次暂停。
                RemotingServer.ServerObjFactory.Get <ILotOperationEngine>().LotHold(dbtran, dsHoldParams);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// 保存数据采集实例数据。
        /// </summary>
        /// <param name="dbTrans">事务操作对象。</param>
        /// <param name="lotKey">批次主键。</param>
        /// <param name="edcPointKey">抽检点设置主键。</param>
        /// <param name="editor">编辑人。</param>
        /// <param name="equipmentKey">设备主键。</param>
        /// <param name="oprLine">操作线别名称。</param>
        /// <param name="shiftKey">班别主键。</param>
        internal static void SaveEdcMainInfo(Database db, DbTransaction dbTrans, string lotKey, string edcPointKey,
                                             string editor, string equipmentKey, string oprLine, string shiftKey)
        {
            string        activityType     = string.Empty;
            string        transactionState = string.Empty;
            string        sql            = string.Empty;
            List <string> sqlCommandList = new List <string>();
            DataTable     lotTable       = GetLotsInfo(db, dbTrans, lotKey).Tables[0];

            string lotNumber     = lotTable.Rows[0][POR_LOT_FIELDS.FIELD_LOT_NUMBER].ToString();
            string enterpriseKey = lotTable.Rows[0][POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY].ToString();
            string routeKey      = lotTable.Rows[0][POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY].ToString();
            string stepKey       = lotTable.Rows[0][POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY].ToString();
            string workOrderKey  = lotTable.Rows[0][POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY].ToString();
            string partKey       = lotTable.Rows[0][POR_LOT_FIELDS.FIELD_PART_VER_KEY].ToString();
            string stateFlag     = lotTable.Rows[0][POR_LOT_FIELDS.FIELD_STATE_FLAG].ToString();
            string edcName       = lotTable.Rows[0][EDC_MAIN_FIELDS.FIELD_EDC_NAME].ToString();
            string stepName      = lotTable.Rows[0][POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME].ToString();
            string partNo        = lotTable.Rows[0][POR_LOT_FIELDS.FIELD_PART_NUMBER].ToString();
            string locationKey   = lotTable.Rows[0][POR_LOT_FIELDS.FIELD_FACTORYROOM_KEY].ToString();
            string matrialLot    = lotTable.Rows[0][POR_LOT_FIELDS.FIELD_MATERIAL_LOT].ToString();
            string supplier      = Convert.ToString(lotTable.Rows[0][POR_LOT_FIELDS.FIELD_SUPPLIER_NAME]);
            //string partType = lotTable.Rows[0][POR_LOT_FIELDS.FIELD_TYPE].ToString();
            string shiftName   = Convert.ToString(lotTable.Rows[0][POR_LOT_FIELDS.FIELD_SHIFT_NAME]);
            string reworkFlag  = Convert.ToString(lotTable.Rows[0][POR_LOT_FIELDS.FIELD_IS_REWORKED]);
            string userName    = Convert.ToString(lotTable.Rows[0][POR_LOT_FIELDS.FIELD_OPERATOR]);
            string computeName = Convert.ToString(lotTable.Rows[0][POR_LOT_FIELDS.FIELD_OPR_COMPUTER]);

            //插入数据采集记录
            #region 创建生成EDC_MAIN_INS记录的INSERT SQL
            sql = @"SELECT EDC_KEY,SP_KEY FROM EDC_POINT WHERE ROW_KEY='" + edcPointKey.PreventSQLInjection() + "'";
            DataTable           pointTable   = db.ExecuteDataSet(CommandType.Text, sql).Tables[0];
            string              edcInsKey    = UtilHelper.GenerateNewKey(0);
            Hashtable           mainTable    = new Hashtable();
            EDC_MAIN_INS_FIELDS edcMainField = new EDC_MAIN_INS_FIELDS();
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_EDC_INS_KEY, edcInsKey);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_EDC_KEY, pointTable.Rows[0][EDC_POINT_FIELDS.FIELD_EDC_KEY].ToString());
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_EDC_SP_KEY, pointTable.Rows[0][EDC_POINT_FIELDS.FIELD_SP_KEY].ToString());
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_ENTERPRISE_KEY, enterpriseKey);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_ROUTE_KEY, routeKey);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_STEP_KEY, stepKey);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_WORK_ORDER_KEY, workOrderKey);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_LOT_KEY, lotKey);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_LOT_NUMBER, lotNumber);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_PART_KEY, partKey);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_EDC_POINT_KEY, edcPointKey);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_EQUIPMENT_KEY, equipmentKey);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_COL_START_TIME, null);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_SUPPLIER, supplier);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_STEP_NAME, stepName);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_PART_NO, partNo);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_MATERIAL_LOT, matrialLot);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_LOCATION_KEY, locationKey);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_EDC_NAME, edcName);
            //mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_PART_TYPE, partType);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_EDITOR, editor);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_CREATOR, editor);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_CREATE_TIME, null);
            mainTable.Add(EDC_MAIN_INS_FIELDS.FIELD_EDIT_TIME, null);
            sql = DatabaseTable.BuildInsertSqlStatement(edcMainField, mainTable, null);
            sqlCommandList.Add(sql);
            #endregion

            if (sqlCommandList.Count > 0)
            {
                foreach (string sqlCommand in sqlCommandList)
                {
                    db.ExecuteNonQuery(dbTrans, CommandType.Text, sqlCommand);
                }
            }
            //更新批次状态。
            if (Convert.ToInt32(stateFlag) == 0)//等待进站数据采集。
            {
                transactionState = "1";
                activityType     = ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_INEDC;
                //更新为进站数据采集。
                sql = string.Format(@"UPDATE POR_LOT 
                                    SET STATE_FLAG=1,EDITOR='{0}',EDIT_TIME=GETDATE(),EDC_INS_KEY='{1}' 
                                    WHERE LOT_KEY='{2}'",
                                    editor.PreventSQLInjection(),
                                    edcInsKey.PreventSQLInjection(),
                                    lotKey.PreventSQLInjection());
            }
            else if (Convert.ToInt32(stateFlag) == 4)//等待出站数据收集
            {
                activityType     = ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_OUTEDC;
                transactionState = "5";
                //更新为数据采集。
                sql = string.Format(@"UPDATE POR_LOT 
                                    SET STATE_FLAG=5,EDITOR='{0}',EDIT_TIME=GETDATE(),EDC_INS_KEY='{1}' 
                                    WHERE LOT_KEY='{2}'",
                                    editor.PreventSQLInjection(),
                                    edcInsKey.PreventSQLInjection(),
                                    lotKey.PreventSQLInjection());
            }
            db.ExecuteNonQuery(dbTrans, CommandType.Text, sql);

            #region 插入操作历史记录
            WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
            Hashtable hashTable         = new Hashtable();
            string    strTransactionKey = UtilHelper.GenerateNewKey(0);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, strTransactionKey);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, "0");
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, lotKey);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, activityType);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, lotTable.Rows[0][POR_LOT_FIELDS.FIELD_QUANTITY].ToString());
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, lotTable.Rows[0][POR_LOT_FIELDS.FIELD_QUANTITY].ToString());
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, "EDC");
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE, oprLine);

            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, editor);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, "CN-ZH");
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, null);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, transactionState);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY, lotTable.Rows[0][POR_LOT_FIELDS.FIELD_CUR_PRODUCTION_LINE_KEY].ToString());
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY, stepKey);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY, routeKey);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY, enterpriseKey);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, workOrderKey);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDC_INS_KEY, edcInsKey);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EQUIPMENT_KEY, equipmentKey);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME, shiftName);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY, shiftKey);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG, reworkFlag);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPERATOR, userName);
            hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER, computeName);

            sql = DatabaseTable.BuildInsertSqlStatement(wipFields, hashTable, null);
            db.ExecuteNonQuery(dbTrans, CommandType.Text, sql);
            #endregion
        }
Exemplo n.º 18
0
        /// <summary>
        /// 保存数据采集实例数据。
        /// </summary>
        /// <remarks>
        /// 新增数据采集实例数据并根据生产批次状态以完成生产批次的数据采集。
        /// </remarks>
        /// <param name="db">数据库对象。</param>
        /// <param name="dbtran">数据库事务对象。</param>
        /// <param name="dataset">包含数据采集实例数据的数据集。</param>
        internal static void SaveEDCMainIn(Database db, DbTransaction dbtran, DataSet dsParams)
        {
            string sql = "";
            string activityType = string.Empty;
            string editor = "", lineKey = "", workOrderKey = "", quantity = "", stepKey = "";
            //新增数据采集实例数据
            EDC_MAIN_INS_FIELDS edcMainIns = new EDC_MAIN_INS_FIELDS();
            DataTable           dtParams   = dsParams.Tables[EDC_MAIN_INS_FIELDS.DATABASE_TABLE_NAME];
            Hashtable           htParams   = FanHai.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dtParams);
            string lotKey                  = Convert.ToString(htParams[EDC_MAIN_INS_FIELDS.FIELD_LOT_KEY]);
            string edcInsKey               = Convert.ToString(htParams[EDC_MAIN_INS_FIELDS.FIELD_EDC_INS_KEY]);
            string transactionState        = string.Empty;

            editor = Convert.ToString(htParams[COMMON_FIELDS.FIELD_COMMON_EDITOR]);
            htParams.Remove(COMMON_FIELDS.FIELD_COMMON_EDITOR);
            htParams.Add(EDC_MAIN_INS_FIELDS.FIELD_COL_START_TIME, null);
            htParams.Add(EDC_MAIN_INS_FIELDS.FIELD_COL_END_TIME, null);
            htParams.Add(EDC_MAIN_INS_FIELDS.FIELD_CREATOR, editor);
            htParams.Add(EDC_MAIN_INS_FIELDS.FIELD_EDITOR, editor);
            sql = DatabaseTable.BuildInsertSqlStatement(edcMainIns, htParams, null);
            db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
            //获取生产批次状态。
            int state = -1;

            sql   = @"SELECT STATE_FLAG FROM POR_LOT WHERE LOT_KEY='" + lotKey + "'";
            state = Convert.ToInt32(db.ExecuteScalar(CommandType.Text, sql));
            //更新生产批次状态。
            if (state == 0)
            {
                transactionState = "1";
                activityType     = ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_INEDC;
                sql = @"UPDATE POR_LOT SET STATE_FLAG=1, EDITOR='" + editor.PreventSQLInjection() + "'," +
                      "EDIT_TIME=GETDATE()," +
                      "EDC_INS_KEY='" + edcInsKey.PreventSQLInjection() + "' " +
                      "WHERE LOT_KEY='" + lotKey.PreventSQLInjection() + "'";
            }
            else if (state == 4)
            {
                activityType     = ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_OUTEDC;
                transactionState = "5";
                sql = @"UPDATE POR_LOT SET STATE_FLAG=5, EDITOR='" + editor.PreventSQLInjection() + "'," +
                      "EDIT_TIME=GETDATE()," +
                      "EDC_INS_KEY='" + edcInsKey.PreventSQLInjection() + "' " +
                      "WHERE LOT_KEY='" + lotKey.PreventSQLInjection() + "'";
            }
            db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
            //获取批次信息。
            DataSet dsLot = GetLotsInfo(db, dbtran, lotKey);

            if (null != dsLot && dsLot.Tables.Count > 0 && dsLot.Tables[0].Rows.Count > 0)
            {
                lineKey      = Convert.ToString(dsLot.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_CUR_PRODUCTION_LINE_KEY]);
                quantity     = Convert.ToString(dsLot.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_QUANTITY]);
                workOrderKey = Convert.ToString(dsLot.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY]);
                stepKey      = Convert.ToString(dsLot.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]);

                #region 新增交易记录
                WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
                Hashtable hashTable         = new Hashtable();
                string    strTransactionKey = UtilHelper.GenerateNewKey(0);
                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, strTransactionKey);
                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, "0");
                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, lotKey);
                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, activityType);
                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, quantity);
                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, quantity);
                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, "EDC");

                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, editor);
                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, "CN-ZH");
                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, null);
                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, transactionState);
                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY, lineKey);
                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY, stepKey);
                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, workOrderKey);
                hashTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDC_INS_KEY, edcInsKey);
                sql = DatabaseTable.BuildInsertSqlStatement(wipFields, hashTable, null);
                db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                #endregion
            }
            else
            {
                throw new Exception("获取批次信息失败。");
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// 退料操作,根据操作名称(<see cref="WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY"/>)区分。
        /// </summary>
        /// <remarks>
        /// 操作名称:<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_RETURN_MATERIAL"/>。
        /// </remarks>
        /// <param name="dsParams">包含退料信息的数据集对象。</param>
        /// <returns>包含结果数据的数据集对象。</returns>
        public DataSet LotReturnMaterial(DataSet dsParams)
        {
            DataSet       dsReturn = new DataSet();
            DbConnection  dbConn   = null;
            DbTransaction dbTran   = null;

            try
            {
                dbConn = db.CreateConnection();
                dbConn.Open();
                dbTran = dbConn.BeginTransaction();
                //参数数据。
                if (dsParams == null ||
                    !dsParams.Tables.Contains(TRANS_TABLES.TABLE_PARAM) ||                              //存放附加参数数据
                    !dsParams.Tables.Contains(WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME))              //存放操作数据
                {
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "传入参数不正确,请检查。");
                    return(dsReturn);
                }
                DataTable dtParams      = dsParams.Tables[TRANS_TABLES.TABLE_PARAM];                    //存放附加参数数据
                DataTable dtTransaction = dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME];  //存放操作数据
                Hashtable htTransaction = FanHai.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dtTransaction);
                Hashtable htParams      = FanHai.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dtParams);
                string    opEditTime    = Convert.ToString(htParams[COMMON_FIELDS.FIELD_COMMON_EDIT_TIME]); //操作时编辑时间
                string    lotKey        = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]);
                string    editTimeZone  = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY]);
                string    editor        = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);
                double    qty           = Convert.ToDouble(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN]);
                double    leftQty       = Convert.ToDouble(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT]);
                string    activity      = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]);
                //操作动作必须是 RETURN_MATERIAL
                if (activity != ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_RETURN_MATERIAL)
                {
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "传入参数的退料操作动作不正确,请检查。");
                    return(dsReturn);
                }
                //检查记录是否过期。防止重复修改。
                KeyValuePair <string, string>         kvp           = new KeyValuePair <string, string>(POR_LOT_FIELDS.FIELD_LOT_KEY, lotKey);
                List <KeyValuePair <string, string> > listCondition = new List <KeyValuePair <string, string> >();
                listCondition.Add(kvp);
                //如果记录过期,当前编辑时间<数据库中的记录编辑时间。结束方法执行。
                if (UtilHelper.CheckRecordExpired(db, POR_LOT_FIELDS.DATABASE_TABLE_NAME, listCondition, opEditTime))
                {
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, COMMON_FIELDS.FIELD_COMMON_EDITTIME_EXP);
                    return(dsReturn);
                }
                string transactionKey = UtilHelper.GenerateNewKey(0);
                AddWIPLot(dbTran, transactionKey, lotKey);
                //更新批次数量。
                string sql = string.Format(@"UPDATE POR_LOT 
                                            SET QUANTITY={0},EDITOR='{1}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{2}',DELETED_TERM_FLAG={3}
                                            WHERE LOT_KEY='{4}'",
                                           leftQty,
                                           editor.PreventSQLInjection(),
                                           editTimeZone.PreventSQLInjection(),
                                           leftQty > 0 ? 0 : 1,
                                           lotKey.PreventSQLInjection());
                db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                //更新线上仓物料
                //查询工单主键,批次数量,物料批号,车间主键,工序名称。
                string sqlCommand = string.Format(@"SELECT a.MATERIAL_CODE,a.MATERIAL_LOT,a.FACTORYROOM_KEY,a.CREATE_OPERTION_NAME
                                                    FROM POR_LOT a
                                                    WHERE a.LOT_KEY='{0}'",
                                                  lotKey.PreventSQLInjection());
                DataSet ds = db.ExecuteDataSet(dbTran, CommandType.Text, sqlCommand);
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    string materialLot         = Convert.ToString(ds.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_MATERIAL_LOT]);
                    string materialCode        = Convert.ToString(ds.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_MATERIAL_CODE]);
                    string factoryRoomKey      = Convert.ToString(ds.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_FACTORYROOM_KEY]);
                    string createOperationName = Convert.ToString(ds.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_CREATE_OPERTION_NAME]);
                    //根据车间主键+工序+仓库类型获取线上仓主键。
                    sqlCommand = string.Format(@"SELECT STORE_KEY,STORE_NAME
                                                FROM WST_STORE 
                                                WHERE STORE_TYPE='9' AND LOCATION_KEY='{0}' AND OPERATION_NAME='{1}'",
                                               factoryRoomKey.PreventSQLInjection(),
                                               createOperationName.PreventSQLInjection());
                    ds = db.ExecuteDataSet(dbTran, CommandType.Text, sqlCommand);
                    string storeKey = string.Empty;
                    if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        storeKey = Convert.ToString(ds.Tables[0].Rows[0]["STORE_KEY"]);
                    }
                    string storeMaterialDetailKey = string.Empty;
                    //根据线上仓主键 + 物料批号键获取线上仓物料明细主键。
                    sqlCommand = string.Format(@"SELECT b.STORE_MATERIAL_DETAIL_KEY
                                        FROM WST_STORE_MATERIAL a
                                        LEFT JOIN POR_MATERIAL c ON a.MATERIAL_KEY=c.MATERIAL_KEY
                                        LEFT JOIN WST_STORE_MATERIAL_DETAIL b ON a.STORE_MATERIAL_KEY=b.STORE_MATERIAL_KEY
                                        WHERE a.STORE_KEY='{0}' AND b.MATERIAL_LOT='{1}' AND c.MATERIAL_CODE='{2}'",
                                               storeKey.PreventSQLInjection(),
                                               materialLot.PreventSQLInjection(),
                                               materialCode.PreventSQLInjection());
                    ds = db.ExecuteDataSet(dbTran, CommandType.Text, sqlCommand);
                    if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        storeMaterialDetailKey = Convert.ToString(ds.Tables[0].Rows[0]["STORE_MATERIAL_DETAIL_KEY"]);
                    }
                    //更新线上仓+物料批次数量。
                    sqlCommand = string.Format(@"UPDATE WST_STORE_MATERIAL_DETAIL 
                                                SET CURRENT_QTY=CURRENT_QTY+{0}
                                                WHERE STORE_MATERIAL_DETAIL_KEY='{1}'",
                                               qty - leftQty,
                                               storeMaterialDetailKey.PreventSQLInjection());
                    db.ExecuteNonQuery(dbTran, CommandType.Text, sqlCommand);
                }
                //向WIP_TRANSACTION表插入批次退料的操作记录。
                WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
                if (!htTransaction.ContainsKey(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY))
                {
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
                }
                htTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY] = transactionKey;
                sql = DatabaseTable.BuildInsertSqlStatement(wipFields, htTransaction, null);
                db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                //如果数据集中包含名称WIP_RETURN_MAT_FIELDS.DATABASE_TABLE_NAME的数据表对象。
                if (dsParams.Tables.Contains(WIP_RETURN_MAT_FIELDS.DATABASE_TABLE_NAME))
                {
                    WIP_RETURN_MAT_FIELDS returnFields = new WIP_RETURN_MAT_FIELDS();
                    DataTable             dtReturn     = dsParams.Tables[WIP_RETURN_MAT_FIELDS.DATABASE_TABLE_NAME]; //存放退料明细数据
                    //遍历批次的退料数据。
                    for (int i = 0; i < dtReturn.Rows.Count; i++)
                    {
                        DataRow   drReturn = dtReturn.Rows[i];
                        Hashtable htReturn = CommonUtils.ConvertRowToHashtable(drReturn);
                        if (!htReturn.ContainsKey(WIP_RETURN_MAT_FIELDS.FIELD_TRANSACTION_KEY))
                        {
                            htReturn.Add(WIP_RETURN_MAT_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
                        }
                        htReturn[WIP_RETURN_MAT_FIELDS.FIELD_TRANSACTION_KEY] = transactionKey;
                        //插入一笔批次退料数据。
                        sql = DatabaseTable.BuildInsertSqlStatement(returnFields, htReturn, null);
                        db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                    }
                }
                dbTran.Commit();
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Empty);
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("LotReturnMaterial Error: " + ex.Message);
                dbTran.Rollback();
            }
            finally
            {
                dbConn.Close();
            }
            return(dsReturn);
        }
Exemplo n.º 20
0
        /// <summary>
        /// 执行合并批次的操作。
        /// </summary>
        /// <param name="db">数据库对象。</param>
        /// <param name="dbtran">数据库操作事务。</param>
        /// <param name="dsParams">包含合并数据的数据集。</param>
        private void  MergeLot(Database db, DbTransaction dbtran, DataSet dsParams)
        {
            string  sql      = string.Empty;
            DataSet dsReturn = new DataSet();
            DataSet ds;
            string  strParentLotKey = "";
            string  strParentLotNumber = "";
            string  strParentTransKey = "";
            string  strParentStepKey = "";
            string  strParentRouteKey = "";
            string  strParentEnterpriseKey = "";
            string  strParentQTY = "";
            string  strTotalQTY = "";
            string  strComment = "";
            string  strEditor = "", strEditTimeZone = "", strEditTime = "";
            string  strLineKey = "", strShiftName = "", strWorkOrderKey = "", strStateFlag = "";
            string  oprLine = "";

            if (dsParams.Tables.Count > 0)
            {
                //获取输入参数。
                DataTable dtParams = dsParams.Tables[TRANS_TABLES.TABLE_MAIN_DATA];
                Hashtable htParams = SolarViewer.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dtParams);
                strParentLotKey    = htParams[POR_LOT_FIELDS.FIELD_LOT_KEY].ToString();
                strParentLotNumber = htParams[POR_LOT_FIELDS.FIELD_LOT_NUMBER].ToString();
                strTotalQTY        = htParams[POR_LOT_FIELDS.FIELD_QUANTITY].ToString();
                strComment         = htParams[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT].ToString();
                strEditor          = htParams[WIP_TRANSACTION_FIELDS.FIELD_EDITOR].ToString();
                strEditTimeZone    = htParams[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY].ToString();
                strEditTime        = UtilHelper.GetSysdate(db).ToString("yyyy-MM-dd HH:mm:ss");
                string shiftKey         = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY]);
                string operComputerName = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER]);
                if (htParams.ContainsKey(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME))
                {
                    strShiftName = htParams[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME].ToString();
                }
                else
                {
                    strShiftName = UtilHelper.GetShiftValue(db, strEditTime);
                }
                if (string.IsNullOrEmpty(shiftKey))
                {
                    shiftKey = UtilHelper.GetShiftKey(db, strEditTime);
                }
                //获取合并到批次的详细信息。
                ds = LotManagement.GetLotDetailsEx(db, dbtran, strParentLotKey);
                strParentStepKey       = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY].ToString();
                strParentRouteKey      = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY].ToString();
                strParentEnterpriseKey = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY].ToString();
                strParentQTY           = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_QUANTITY].ToString();
                strLineKey             = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_CUR_PRODUCTION_LINE_KEY].ToString();
                oprLine         = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_OPR_LINE].ToString();
                strWorkOrderKey = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY].ToString();
                strStateFlag    = ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_STATE_FLAG].ToString();
                string reworkFlag = Convert.ToString(ds.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows[0][POR_LOT_FIELDS.FIELD_IS_REWORKED]);
                //更新合并到批次的数据
                sql = string.Format(@"UPDATE POR_LOT 
                                    SET QUANTITY={0},EDITOR='{1}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{2}' 
                                    WHERE LOT_KEY='{3}'",
                                    strTotalQTY.PreventSQLInjection(),
                                    strEditor.PreventSQLInjection(),
                                    strEditTimeZone.PreventSQLInjection(),
                                    strParentLotKey.PreventSQLInjection());
                db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                //记录合批操作。
                WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
                Hashtable parenttransactionTable = new Hashtable();
                DataTable parenttransaction      = new DataTable();
                strParentTransKey = UtilHelper.GenerateNewKey(0);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, strParentTransKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, "0");
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, strParentLotKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, strParentQTY);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, strTotalQTY);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_MERGE);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, strComment);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, strEditor);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, strEditTimeZone);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, strEditTime);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, strWorkOrderKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY, strParentStepKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY, strParentRouteKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY, strParentEnterpriseKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, strStateFlag);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE, oprLine);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG, reworkFlag);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPERATOR, strEditor);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY, strLineKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME, strShiftName);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY, shiftKey);
                parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER, operComputerName);
                sql = DatabaseTable.BuildInsertSqlStatement(wipFields, parenttransactionTable, null);
                db.ExecuteNonQuery(dbtran, CommandType.Text, sql);

                string strChildLotKey    = "";
                string strChildLotNumber = "";
                string strChildQty       = "";

                if (dsParams.Tables.Contains(BASE_PARAMETER_FIELDS.DATABASE_TABLE_NAME))
                {
                    DataTable dtBaseParameters = dsParams.Tables[BASE_PARAMETER_FIELDS.DATABASE_TABLE_NAME];
                    //循环被合并的批次。
                    for (int i = 0; i < dtBaseParameters.Rows.Count; i++)
                    {
                        strChildLotKey    = dtBaseParameters.Rows[i]["LOT_KEY"].ToString();
                        strChildLotNumber = dtBaseParameters.Rows[i]["LOT_NUMBER"].ToString();
                        strChildQty       = dtBaseParameters.Rows[i]["QUANTITY"].ToString();
                        //更新被合并批次的数据
                        sql = string.Format(@"UPDATE POR_LOT
                                            SET QUANTITY='0',DELETED_TERM_FLAG='1',EDITOR='{0}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{1}' 
                                            WHERE LOT_KEY='{2}'",
                                            strEditor.PreventSQLInjection(),
                                            strEditTimeZone.PreventSQLInjection(),
                                            strChildLotKey.PreventSQLInjection());
                        db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                        //插入被合并批次的交易记录
                        Hashtable childtransactionTable = new Hashtable();
                        DataTable childtransaction      = new DataTable();
                        string    strChildTransKey      = UtilHelper.GenerateNewKey(0);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, strChildTransKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, "0");
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, strChildLotKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, strChildQty);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, "0");
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_MERGED);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, "");
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, strEditor);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, strEditTimeZone);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, strEditTime);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, strWorkOrderKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY, strParentEnterpriseKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY, strParentRouteKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY, strParentStepKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, strStateFlag);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE, oprLine);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG, reworkFlag);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPERATOR, strEditor);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY, strLineKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME, strShiftName);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY, shiftKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER, operComputerName);
                        sql = DatabaseTable.BuildInsertSqlStatement(wipFields, childtransactionTable, null);
                        db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                        //插入WIP_MERGE表
                        Hashtable        MergeHashTable = new Hashtable();
                        WIP_MERGE_FIELDS wipMerge       = new WIP_MERGE_FIELDS();
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_TRANSACTION_KEY, strParentTransKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_CHILD_LOT_KEY, strChildLotKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_MAIN_LOT_KEY, strParentLotKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_MERGE_QUANTITY, strChildQty);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_STEP_KEY, strParentStepKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_ROUTE_KEY, strParentRouteKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_ENTERPRISE_KEY, strParentEnterpriseKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_EDITOR, strEditor);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_EDIT_TIME, strEditTime);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_EDIT_TIMEZONE, strEditTimeZone);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_CHILD_TRANSACTION_KEY, strChildTransKey);
                        sql = DatabaseTable.BuildInsertSqlStatement(wipMerge, MergeHashTable, null);
                        db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                    }
                }
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// 转返工单作业。
        /// </summary>
        /// <param name="dsParams"></param>
        /// <returns></returns>
        public DataSet LotExchange(DataSet dsParams)
        {
            DataSet dsReturn = new DataSet();

            //参数数据。
            if (dsParams == null ||
                !dsParams.Tables.Contains(TRANS_TABLES.TABLE_PARAM) ||                      //存放附加参数数据
                !dsParams.Tables.Contains(POR_LOT_FIELDS.DATABASE_TABLE_NAME)               //存放批次数据
                )
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, "传入参数不正确,请检查。");
                return(dsReturn);
            }

            try
            {
                DataTable dtParams      = dsParams.Tables[TRANS_TABLES.TABLE_PARAM];
                DataTable dtLots        = dsParams.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME];
                Hashtable htParams      = CommonUtils.ConvertToHashtable(dtParams);
                string    editor        = Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_EDITOR]);       //编辑人
                string    opComputer    = Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_OPR_COMPUTER]); //编辑人
                string    enterpriseKey = Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY]);
                string    routeKey      = Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]);
                string    stepKey       = Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]);
                string    activity      = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]);
                using (DbConnection dbConn = db.CreateConnection())
                {
                    dbConn.Open();
                    using (DbTransaction dbTran = dbConn.BeginTransaction())
                    {
                        foreach (DataRow dr in dtLots.Rows)
                        {
                            string lotKey    = Convert.ToString(dr[POR_LOT_FIELDS.FIELD_LOT_KEY]);
                            string lotNumber = Convert.ToString(dr[POR_LOT_FIELDS.FIELD_LOT_NUMBER]);
                            string ttime     = Convert.ToString(dr[WIP_IV_TEST_FIELDS.FIELDS_T_DATE]);
                            string palletNo  = Convert.ToString(dr[POR_LOT_FIELDS.FIELD_PALLET_NO]);

                            //检查记录是否过期。防止重复修改。
                            KeyValuePair <string, string>         kvp           = new KeyValuePair <string, string>(POR_LOT_FIELDS.FIELD_LOT_KEY, lotKey);
                            List <KeyValuePair <string, string> > listCondition = new List <KeyValuePair <string, string> >();
                            listCondition.Add(kvp);
                            string opEditTime = Convert.ToString(dr[POR_LOT_FIELDS.FIELD_EDIT_TIME]);
                            //如果记录过期,当前编辑时间<数据库中的记录编辑时间。结束方法执行。
                            if (UtilHelper.CheckRecordExpired(db, POR_LOT_FIELDS.DATABASE_TABLE_NAME, listCondition, opEditTime))
                            {
                                ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Format("组件{0}信息已过期,请确认。", lotNumber));
                                return(dsReturn);
                            }
                            //获取批次数据
                            string sqlQueryLot = string.Format(@"SELECT A.*,
                                                                        B.ENTERPRISE_NAME,
                                                                        B.ENTERPRISE_VERSION,
                                                                        C.ROUTE_NAME ,
                                                                        D.ROUTE_STEP_NAME
                                                                    FROM POR_LOT A
                                                                    LEFT JOIN POR_ROUTE_ENTERPRISE_VER B ON B.ROUTE_ENTERPRISE_VER_KEY=  A.ROUTE_ENTERPRISE_VER_KEY
                                                                    LEFT JOIN POR_ROUTE_ROUTE_VER C ON C.ROUTE_ROUTE_VER_KEY=A.CUR_ROUTE_VER_KEY
                                                                    LEFT JOIN POR_ROUTE_STEP D ON D.ROUTE_STEP_KEY=A.CUR_STEP_VER_KEY
                                                                    WHERE A.STATUS < 2
                                                                    AND A.LOT_NUMBER='{0}'",
                                                               lotNumber.PreventSQLInjection());
                            DataTable dtTable        = db.ExecuteDataSet(dbTran, CommandType.Text, sqlQueryLot).Tables[0];
                            DataRow   drLotInfo      = dtTable.Rows[0];
                            string    transactionKey = CommonUtils.GenerateNewKey(0);
                            AddWIPLot(dbTran, transactionKey, lotKey);
                            //向WIP_TRANSACTION表插入批次转返工单的操作记录。
                            Hashtable htTransaction = new Hashtable();
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, activity);
                            if (htParams.Contains(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT))
                            {
                                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, htParams[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT]);
                            }
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, null);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, drLotInfo[POR_LOT_FIELDS.FIELD_EDIT_TIMEZONE]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, htParams[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY, drLotInfo[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_NAME, drLotInfo[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ENTERPRISE_NAME]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EQUIPMENT_KEY, null);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY, null);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPERATOR, editor);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER, opComputer);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE, null);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE_PRE, drLotInfo[POR_LOT_FIELDS.FIELD_LINE_NAME]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, drLotInfo[POR_LOT_FIELDS.FIELD_LOT_KEY]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, 0);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, drLotInfo[POR_LOT_FIELDS.FIELD_QUANTITY]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, drLotInfo[POR_LOT_FIELDS.FIELD_QUANTITY]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG, drLotInfo[POR_LOT_FIELDS.FIELD_IS_REWORKED]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY, drLotInfo[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_NAME, drLotInfo[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_NAME]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY, htParams[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME, htParams[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, drLotInfo[POR_LOT_FIELDS.FIELD_STATE_FLAG]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY, drLotInfo[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_NAME, drLotInfo[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME]);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TIME_STAMP, null);
                            htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, drLotInfo[POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY]);
                            WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
                            string sql = DatabaseTable.BuildInsertSqlStatement(wipFields, htTransaction, null);
                            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                            //更新批次数据
                            string updateLot = string.Format(@"UPDATE POR_LOT 
                                                              SET STATE_FLAG=0,
                                                                  {12}
                                                                  DELETED_TERM_FLAG=0,
                                                                  ROUTE_ENTERPRISE_VER_KEY='{1}',
                                                                  CUR_ROUTE_VER_KEY='{2}',
                                                                  CUR_STEP_VER_KEY='{3}',
                                                                  EDITOR='{4}',
                                                                  EDIT_TIME=GETDATE(),
                                                                  FACTORYROOM_KEY='{5}',
                                                                  FACTORYROOM_NAME='{6}',
                                                                  WORK_ORDER_NO='{7}',
                                                                  WORK_ORDER_KEY='{8}',
                                                                  PART_NUMBER='{9}',
                                                                  PRO_ID='{10}',
                                                                  CUR_PRODUCTION_LINE_KEY=NULL,
                                                                  LINE_NAME=NULL,
                                                                  START_WAIT_TIME=GETDATE(),
                                                                  START_PROCESS_TIME=NULL,
                                                                  PALLET_NO=NULL,
                                                                  PALLET_TIME=NULL,
                                                                  OPR_COMPUTER='{4}',
                                                                  OPR_LINE=NULL,
                                                                  OPERATOR='{11}'
                                                              WHERE LOT_KEY='{0}'",
                                                             lotKey.PreventSQLInjection(),
                                                             enterpriseKey.PreventSQLInjection(),
                                                             routeKey.PreventSQLInjection(),
                                                             stepKey.PreventSQLInjection(),
                                                             editor.PreventSQLInjection(),
                                                             dr[POR_LOT_FIELDS.FIELD_FACTORYROOM_KEY],
                                                             dr[POR_LOT_FIELDS.FIELD_FACTORYROOM_NAME],
                                                             dr["NEW_WORK_ORDER_NO"],
                                                             dr["NEW_WORK_ORDER_KEY"],
                                                             dr["NEW_PART_NUMBER"],
                                                             dr["NEW_PRO_ID"],
                                                             opComputer.PreventSQLInjection(),
                                                             activity == ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_CHANGE_PROID?  "REWORK_FLAG=REWORK_FLAG+1," : string.Empty);
                            this.db.ExecuteNonQuery(dbTran, CommandType.Text, updateLot);
                            //如果有有效测试数据,更新测试数据
                            if (!string.IsNullOrEmpty(ttime))
                            {
                                string updateIVTest = string.Format(@"UPDATE WIP_IV_TEST 
                                                              SET VC_TYPE='{1}',I_IDE='{2}',I_PKID='{3}',VC_MODNAME='{4}',VC_WORKORDER='{5}'
                                                              WHERE LOT_NUM='{0}'
                                                              AND VC_DEFAULT='1'",
                                                                    lotNumber.PreventSQLInjection(),
                                                                    dr[WIP_IV_TEST_FIELDS.FIELDS_VC_TYPE],
                                                                    dr[WIP_IV_TEST_FIELDS.FIELDS_I_IDE],
                                                                    dr[WIP_IV_TEST_FIELDS.FIELDS_I_PKID],
                                                                    dr[WIP_IV_TEST_FIELDS.FIELDS_VC_MODNAME],
                                                                    dr["NEW_WORK_ORDER_NO"]);
                                this.db.ExecuteNonQuery(dbTran, CommandType.Text, updateIVTest);
                            }
                        }
                        //更新包装数据。
                        var lnq = dtLots.AsEnumerable().Where(dr => string.IsNullOrEmpty(Convert.ToString(dr[POR_LOT_FIELDS.FIELD_PALLET_NO])) == false)
                                  .Select(dr => Convert.ToString(dr[POR_LOT_FIELDS.FIELD_PALLET_NO]))
                                  .Distinct();
                        foreach (string palletNo in lnq)
                        {
                            string consignmentKey = CommonUtils.GenerateNewKey(0);
                            //新增包装明细数据
                            string sql = string.Format(@"INSERT INTO WIP_CONSIGNMENT_DETAIL
                                                        (CONSIGNMENT_KEY,ITEM_NO,LOT_NUMBER,WORK_NUMBER,PART_NUMBER,PRO_ID,PRO_LEVEL,
                                                        COLOR,POWER_LEVEL,PS_CODE,PS_DTL_CODE,FULL_QTY,PS_SEQ,AVG_POWER_RANGE,CREATOR,CREATE_TIME)
                                                       SELECT '{0}',
                                                               ROW_NUMBER() OVER(PARTITION BY a.CONSIGNMENT_KEY ORDER BY b.ITEM_NO) ITEM_NO,
                                                               b.LOT_NUMBER,
                                                               b.WORK_NUMBER,
                                                               b.PART_NUMBER,
                                                               b.PRO_ID,
                                                               b.PRO_LEVEL,
                                                               b.COLOR,
                                                               b.POWER_LEVEL,
                                                               b.PS_CODE,
                                                               b.PS_DTL_CODE,
                                                               b.FULL_QTY,
                                                               b.PS_SEQ,
                                                               b.AVG_POWER_RANGE,
                                                               b.CREATOR,
                                                               b.CREATE_TIME
                                                        FROM WIP_CONSIGNMENT a
                                                        INNER JOIN WIP_CONSIGNMENT_DETAIL b ON b.CONSIGNMENT_KEY=a.CONSIGNMENT_KEY
                                                        INNER JOIN POR_LOT c ON c.PALLET_NO=a.VIRTUAL_PALLET_NO AND c.LOT_NUMBER=b.LOT_NUMBER 
                                                        WHERE a.ISFLAG=1
                                                        AND a.PALLET_NO='{1}'",
                                                       consignmentKey,
                                                       palletNo.PreventSQLInjection());
                            this.db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                            //新增包装数据
                            sql = string.Format(@"INSERT INTO WIP_CONSIGNMENT(CONSIGNMENT_KEY,VIRTUAL_PALLET_NO,PALLET_NO,WORKNUMBER,CS_DATA_GROUP,
                                                    SAP_NO,POWER_LEVEL,GRADE,SHIFT,PS_CODE,PS_DTL_SUBCODE,
                                                    LAST_PALLET,CREATER,CREATE_TIME,EDITOR,EDIT_TIME,ISFLAG,
                                                    ROOM_KEY,CUSTOMER_NO,LOT_NUMBER_QTY,FULL_QTY,TOTLE_POWER,
                                                    AVG_POWER,PRO_ID,PALLET_NO_NEW,PALLET_TYPE,
                                                    CODE_TYPE,LINE_NAME,LINE_KEY,EQUIPMENT_KEY,EQUIPMENT_NAME,
                                                    AVG_POWER_RANGE,LOT_COLOR,PS_SEQ,CHECKER,CHECK_TIME,
                                                    TO_WH,TO_WH_TIME,OUT_WH,OUT_WH_TIME,MEMO1,ARK_FLAG)
                                                SELECT '{0}', a.VIRTUAL_PALLET_NO,a.PALLET_NO,a.WORKNUMBER,a.CS_DATA_GROUP,
                                                       a.SAP_NO,a.POWER_LEVEL,a.GRADE,a.SHIFT,a.PS_CODE,a.PS_DTL_SUBCODE,
                                                       a.LAST_PALLET,a.CREATER,a.CREATE_TIME,'{2}',GETDATE(),a.ISFLAG,
                                                       a.ROOM_KEY,a.CUSTOMER_NO,a.LOT_NUMBER_QTY,a.FULL_QTY,a.TOTLE_POWER,
                                                       a.AVG_POWER,a.PRO_ID,a.PALLET_NO_NEW,a.PALLET_TYPE,
                                                       a.CODE_TYPE,a.LINE_NAME,a.LINE_KEY,a.EQUIPMENT_KEY,a.EQUIPMENT_NAME,
                                                       a.AVG_POWER_RANGE,a.LOT_COLOR,a.PS_SEQ,a.CHECKER,a.CHECK_TIME,
                                                       a.TO_WH,a.TO_WH_TIME,a.OUT_WH,a.OUT_WH_TIME,a.MEMO1,a.ARK_FLAG
                                                FROM WIP_CONSIGNMENT a
                                                WHERE a.ISFLAG=1
                                                AND a.PALLET_NO='{1}'",
                                                consignmentKey,
                                                palletNo.PreventSQLInjection(),
                                                editor.PreventSQLInjection());
                            this.db.ExecuteNonQuery(dbTran, CommandType.Text, sql);

                            //更新原来的包装数据为无效
                            sql = string.Format(@"UPDATE WIP_CONSIGNMENT
                                            SET ISFLAG=0,EDITOR='{2}',EDIT_TIME=GETDATE(),MEMO1='转/返工单 {3} {4}'
                                            WHERE ISFLAG=1
                                            AND PALLET_NO='{1}'
                                            AND CONSIGNMENT_KEY!='{0}'",
                                                consignmentKey,
                                                palletNo.PreventSQLInjection(),
                                                editor.PreventSQLInjection(),
                                                activity,
                                                htParams[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT]);
                            this.db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                            //更新现有的包装数据,为其第一条数据的基本数据
                            sql = string.Format(@"UPDATE a
                                                SET    a.WORKNUMBER=b.WORK_NUMBER,
                                                       a.SAP_NO=b.PART_NUMBER,
                                                       a.POWER_LEVEL=b.POWER_LEVEL,
                                                       a.GRADE=b.PRO_LEVEL,
                                                       a.PS_CODE=b.PS_CODE,
                                                       a.PS_DTL_SUBCODE=b.PS_DTL_CODE,
                                                       a.LOT_NUMBER_QTY=(SELECT COUNT(1) FROM WIP_CONSIGNMENT_DETAIL aa WHERE aa.CONSIGNMENT_KEY=a.CONSIGNMENT_KEY),
                                                       a.FULL_QTY=b.FULL_QTY,
                                                       a.TOTLE_POWER=(SELECT ISNULL(SUM(bb.COEF_PMAX),0)
                                                                      FROM WIP_CONSIGNMENT_DETAIL aa
                                                                      INNER JOIN WIP_IV_TEST bb ON bb.LOT_NUM=aa.LOT_NUMBER AND bb.VC_DEFAULT='1'
                                                                      WHERE aa.CONSIGNMENT_KEY=a.CONSIGNMENT_KEY),
                                                       a.PRO_ID=b.PRO_ID,
                                                       a.LOT_COLOR=b.COLOR,
                                                       a.PS_SEQ=b.PS_SEQ,
                                                       a.AVG_POWER_RANGE=b.AVG_POWER_RANGE
                                                FROM WIP_CONSIGNMENT a
                                                LEFT JOIN WIP_CONSIGNMENT_DETAIL b ON b.CONSIGNMENT_KEY=a.CONSIGNMENT_KEY AND b.ITEM_NO=1
                                                WHERE a.CONSIGNMENT_KEY='{0}'",
                                                consignmentKey);
                            this.db.ExecuteNonQuery(dbTran, CommandType.Text, sql);

                            sql = string.Format(@"UPDATE a
                                                SET    a.AVG_POWER=CASE WHEN a.LOT_NUMBER_QTY=0 THEN 0 ELSE a.TOTLE_POWER/a.LOT_NUMBER_QTY END,
                                                       a.ISFLAG=CASE WHEN a.LOT_NUMBER_QTY>0 THEN 1 ELSE 0 END
                                                FROM WIP_CONSIGNMENT a
                                                WHERE a.CONSIGNMENT_KEY='{0}'",
                                                consignmentKey);
                            this.db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                        }
                        dbTran.Commit();
                    }
                    dbConn.Close();
                }
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("LotOperationEngine.LotExchange Error: " + ex.Message);
            }
            return(dsReturn);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 电池片回收操作,用于撤销电池片报废和电池片补片。
        /// </summary>
        /// <remarks>
        /// 操作名称:<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_RECOVERED"/>。
        /// </remarks>
        /// <param name="dsParams">包含回收信息的数据集对象。</param>
        /// <returns>包含结果数据的数据集对象。</returns>
        public DataSet LotRecovered(DataSet dsParams)
        {
            DataSet       dsReturn = new DataSet();
            DbConnection  dbConn   = null;
            DbTransaction dbTran   = null;

            try
            {
                dbConn = db.CreateConnection();
                dbConn.Open();
                dbTran = dbConn.BeginTransaction();
                //参数数据。
                if (dsParams == null ||
                    !dsParams.Tables.Contains(TRANS_TABLES.TABLE_PARAM) ||                              //存放附加参数数据
                    !dsParams.Tables.Contains(WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME))              //存放操作数据
                {
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "传入参数不正确,请检查。");
                    return(dsReturn);
                }

                DataTable dtParams      = dsParams.Tables[TRANS_TABLES.TABLE_PARAM];                    //存放附加参数数据
                DataTable dtTransaction = dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME];  //存放操作数据
                Hashtable htTransaction = FanHai.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dtTransaction);
                Hashtable htParams      = FanHai.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dtParams);
                string    opEditTime    = Convert.ToString(htParams[COMMON_FIELDS.FIELD_COMMON_EDIT_TIME]); //操作时编辑时间
                string    lotKey        = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]);
                string    editTimeZone  = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY]);
                string    editor        = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);
                double    leftQty       = Convert.ToDouble(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT]);
                string    activity      = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]);
                //操作动作必须是 RECOVERED(电池片回收)
                if (activity != ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_RECOVERED)
                {
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "传入参数的电池片回收操作动作不正确,请检查。");
                    return(dsReturn);
                }
                //检查记录是否过期。防止重复修改。
                KeyValuePair <string, string>         kvp           = new KeyValuePair <string, string>(POR_LOT_FIELDS.FIELD_LOT_KEY, lotKey);
                List <KeyValuePair <string, string> > listCondition = new List <KeyValuePair <string, string> >();
                listCondition.Add(kvp);
                //如果记录过期,当前编辑时间<数据库中的记录编辑时间。结束方法执行。
                if (UtilHelper.CheckRecordExpired(db, POR_LOT_FIELDS.DATABASE_TABLE_NAME, listCondition, opEditTime))
                {
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "信息已过期,请关闭该界面后重试。");
                    return(dsReturn);
                }
                string transactionKey = UtilHelper.GenerateNewKey(0);
                AddWIPLot(dbTran, transactionKey, lotKey);

                //更新批次数量。
                string sql = string.Format(@"UPDATE POR_LOT 
                                            SET QUANTITY={0},EDITOR='{1}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{2}'
                                            WHERE LOT_KEY='{3}'",
                                           leftQty,
                                           editor.PreventSQLInjection(),
                                           editTimeZone.PreventSQLInjection(),
                                           lotKey.PreventSQLInjection());
                db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                //向WIP_TRANSACTION表插入批次回收的操作记录。
                WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
                if (!htTransaction.ContainsKey(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY))
                {
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
                }
                htTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY] = transactionKey;
                sql = DatabaseTable.BuildInsertSqlStatement(wipFields, htTransaction, null);
                db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                //如果数据集中包含名称WIP_RECOVERED_FIELDS.DATABASE_TABLE_NAME的数据表对象。
                if (dsParams.Tables.Contains(WIP_RECOVERED_FIELDS.DATABASE_TABLE_NAME))
                {
                    WIP_RECOVERED_FIELDS recoveredFields = new WIP_RECOVERED_FIELDS();
                    DataTable            dtRecovered     = dsParams.Tables[WIP_RECOVERED_FIELDS.DATABASE_TABLE_NAME]; //存放回收明细数据
                    //获取不重复的被回收批次及其对应的编辑时间,只有在电池片回收是撤销补片操作时才发生。
                    var distinctRecoveredLot = from item in dtRecovered.AsEnumerable()
                                               where Convert.ToString(item[WIP_RECOVERED_FIELDS.FIELD_RECOVERED_LOT_KEY]) != lotKey //排除回收批次
                                               group item by new
                    {
                        LotKey   = Convert.ToString(item[WIP_RECOVERED_FIELDS.FIELD_RECOVERED_LOT_KEY]),
                        EditTime = Convert.ToString(item[WIP_RECOVERED_FIELDS.FIELD_EDIT_TIME])
                    } into g
                        select new { LotKey = g.Key.LotKey, EditTime = g.Key.EditTime, Count = g.Count() };

                    foreach (var item in distinctRecoveredLot)
                    {
                        //检查记录是否过期。防止重复修改。
                        kvp           = new KeyValuePair <string, string>(POR_LOT_FIELDS.FIELD_LOT_KEY, item.LotKey);
                        listCondition = new List <KeyValuePair <string, string> >();
                        listCondition.Add(kvp);
                        //如果记录过期,编辑时间<数据库中的记录编辑时间。结束方法执行。
                        if (UtilHelper.CheckRecordExpired(db, POR_LOT_FIELDS.DATABASE_TABLE_NAME, listCondition, item.EditTime))
                        {
                            string msg = string.Format("信息已过期,请关闭该界面后重试。");
                            ReturnMessageUtils.AddServerReturnMessage(dsReturn, msg);
                            return(dsReturn);
                        }
                    }

                    //遍历批次的回收数据。
                    for (int i = 0; i < dtRecovered.Rows.Count; i++)
                    {
                        DataRow   drRecovered = dtRecovered.Rows[i];
                        Hashtable htRecovered = CommonUtils.ConvertRowToHashtable(drRecovered);
                        string    beRecoveredTransactionKey = string.Empty;
                        string    recoveredType             = Convert.ToString(htRecovered[WIP_RECOVERED_FIELDS.FIELD_RECOVERED_TYPE]);
                        //回收类型为撤销电池片补片(PATCH)操作,需要新增被回收批次的操作记录。
                        if (recoveredType == ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_PATCH)
                        {
                            string beRecoveredLotKey = Convert.ToString(htRecovered[WIP_RECOVERED_FIELDS.FIELD_BERECOVERED_LOT_KEY]);
                            double recoveredQuantity = Convert.ToDouble(htRecovered[WIP_RECOVERED_FIELDS.FIELD_RECOVERED_QUANTITY]);
                            //获取被回收批次的信息
                            DataSet dsPatchLotInfo = LotManagement.GetLotBasicInfo(db, dbTran, beRecoveredLotKey);
                            DataRow drPatchLotInfo = dsPatchLotInfo.Tables[0].Rows[0];
                            double  quantityIn     = Convert.ToDouble(drPatchLotInfo[POR_LOT_FIELDS.FIELD_QUANTITY]);
                            //double quantityOut = quantityIn - recoveredQuantity; //电池片补片时不再回加被补片批次的数量,所以在不需要减去回收数量
                            double quantityOut    = quantityIn;
                            string enterpriseKey  = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY]);
                            string enterpriseName = Convert.ToString(drPatchLotInfo[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ENTERPRISE_NAME]);
                            string routeKey       = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]);
                            string routeName      = Convert.ToString(drPatchLotInfo[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_NAME]);
                            string stepKey        = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]);
                            string stepName       = Convert.ToString(drPatchLotInfo[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME]);
                            string workOrderKey   = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY]);
                            string stateFlag      = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_STATE_FLAG]);
                            string reworkFlag     = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_IS_REWORKED]);
                            string lineKey        = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_CUR_PRODUCTION_LINE_KEY]);
                            string lineName       = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_OPR_LINE]);
                            string edcInsKey      = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_EDC_INS_KEY]);
                            string equipmentKey   = Convert.ToString(drPatchLotInfo[EMS_EQUIPMENTS_FIELDS.FIELD_EQUIPMENT_KEY]);

                            beRecoveredTransactionKey = UtilHelper.GenerateNewKey(0);
                            AddWIPLot(dbTran, beRecoveredTransactionKey, beRecoveredLotKey);
                            //更新被回收批次的数量
                            sql = string.Format(@"UPDATE POR_LOT 
                                                SET QUANTITY={0},EDITOR='{1}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{2}'
                                                WHERE LOT_KEY='{3}'",
                                                quantityOut,
                                                editor.PreventSQLInjection(),
                                                editTimeZone.PreventSQLInjection(),
                                                beRecoveredLotKey.PreventSQLInjection());
                            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                            //插入被回收批次的操作记录
                            Hashtable htBeRecoveredTransaction = new Hashtable(htTransaction);
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY] = beRecoveredTransactionKey;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]       = beRecoveredLotKey;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]        = ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_BE_RECOVERED;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN]     = quantityIn;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT]    = quantityOut;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY]  = enterpriseKey;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_NAME] = enterpriseName;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY]       = routeKey;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_NAME]      = routeName;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY]        = stepKey;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_NAME]       = stepName;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY]  = workOrderKey;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG]      = stateFlag;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG]     = reworkFlag;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY]        = lineKey;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE]        = lineName;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE_PRE]    = lineName;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDC_INS_KEY]     = edcInsKey;
                            htBeRecoveredTransaction[WIP_TRANSACTION_FIELDS.FIELD_EQUIPMENT_KEY]   = equipmentKey;
                            sql = DatabaseTable.BuildInsertSqlStatement(wipFields, htBeRecoveredTransaction, null);
                            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                        }
                        //插入一笔批次回收明细数据
                        //回收操作记录主键。
                        if (!htRecovered.ContainsKey(WIP_RECOVERED_FIELDS.FIELD_TRANSACTION_KEY))
                        {
                            htRecovered.Add(WIP_RECOVERED_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
                        }
                        htRecovered[WIP_RECOVERED_FIELDS.FIELD_TRANSACTION_KEY] = transactionKey;
                        //被回收批次操作记录主键,只是回收操作是撤销电池片补片时才有值,否则为空白值。
                        if (!htRecovered.ContainsKey(WIP_RECOVERED_FIELDS.FIELD_BERECOVERED_TRANSACTION_KEY))
                        {
                            htRecovered.Add(WIP_RECOVERED_FIELDS.FIELD_BERECOVERED_TRANSACTION_KEY, beRecoveredTransactionKey);
                        }
                        htRecovered[WIP_RECOVERED_FIELDS.FIELD_BERECOVERED_TRANSACTION_KEY] = beRecoveredTransactionKey;
                        //重置回收明细的编辑时间为当前时间。
                        htRecovered[WIP_RECOVERED_FIELDS.FIELD_EDIT_TIME] = null;
                        sql = DatabaseTable.BuildInsertSqlStatement(recoveredFields, htRecovered, null);
                        db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                    }
                }
                dbTran.Commit();
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Empty);
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("LotRecovered Error: " + ex.Message);
                dbTran.Rollback();
            }
            finally
            {
                dbConn.Close();
            }
            return(dsReturn);
        }
Exemplo n.º 23
0
        /// <summary>
        /// 创建批次。
        /// </summary>
        /// <param name="db">数据库对象。</param>
        /// <param name="dbTran">数据库事务操作对象。</param>
        /// <param name="dsParams">包含批次创建信息的数据集对象。</param>
        public static void CreateLot(Database db, DbTransaction dbTran, DataSet dsParams)
        {
            DataSet       dsReturn       = new DataSet();
            List <string> sqlCommandList = new List <string>();
            DateTime      curTime        = UtilHelper.GetSysdate(db);
            string        lotEditTime    = curTime.ToString("yyyy-MM-dd HH:mm:ss");

            if (dsParams.Tables.Contains(TRANS_TABLES.TABLE_MAIN_DATA))
            {
                DataTable dtMainData    = dsParams.Tables[TRANS_TABLES.TABLE_MAIN_DATA];
                DataTable dtAddtionData = dsParams.Tables[1];   //存放附加数据

                Hashtable htMainData     = CommonUtils.ConvertToHashtable(dtMainData);
                Hashtable htAddtionData  = CommonUtils.ConvertToHashtable(dtAddtionData);
                string    enterpriseName = Convert.ToString(htAddtionData[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_NAME]);
                string    routeName      = Convert.ToString(htAddtionData[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_NAME]);
                string    stepName       = Convert.ToString(htAddtionData[WIP_TRANSACTION_FIELDS.FIELD_STEP_NAME]);

                string editor       = Convert.ToString(htMainData[POR_LOT_FIELDS.FIELD_CREATOR]);
                string editTimezone = string.Empty;
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_EDIT_TIMEZONE))
                {
                    editTimezone = Convert.ToString(htMainData[POR_LOT_FIELDS.FIELD_EDIT_TIMEZONE]);
                }
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_EDITOR) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_EDITOR, editor);
                }
                htMainData[POR_LOT_FIELDS.FIELD_LOT_KEY]         = UtilHelper.GenerateNewKey(0);
                htMainData[POR_LOT_FIELDS.FIELD_EDIT_TIME]       = null;
                htMainData[POR_LOT_FIELDS.FIELD_CREATE_TIME]     = null;
                htMainData[POR_LOT_FIELDS.FIELD_START_WAIT_TIME] = null;

                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_ORG_WORK_ORDER_NO) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_ORG_WORK_ORDER_NO, htMainData[POR_LOT_FIELDS.FIELD_WORK_ORDER_NO]);
                }
                else
                {
                    htMainData[POR_LOT_FIELDS.FIELD_ORG_WORK_ORDER_NO] = htMainData[POR_LOT_FIELDS.FIELD_WORK_ORDER_NO];
                }

                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_STATE_FLAG) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_STATE_FLAG, "0");
                }
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_DELETED_TERM_FLAG) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_DELETED_TERM_FLAG, "0");
                }
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_IS_REWORKED) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_IS_REWORKED, "0");
                }
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_IS_MAIN_LOT) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_IS_MAIN_LOT, "1");
                }
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_HOLD_FLAG) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_HOLD_FLAG, "0");
                }
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_IS_SPLITED) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_IS_SPLITED, "0");
                }
                if (htMainData.ContainsKey(POR_LOT_FIELDS.FIELD_SHIPPED_FLAG) == false)
                {
                    htMainData.Add(POR_LOT_FIELDS.FIELD_SHIPPED_FLAG, "0");
                }
                //创建批次。
                POR_LOT_FIELDS porLotFields = new POR_LOT_FIELDS();
                string         sql          = DatabaseTable.BuildInsertSqlStatement(porLotFields, htMainData, null);
                db.ExecuteNonQuery(dbTran, CommandType.Text, sql);

                #region 插入操作记录
                WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
                Hashtable htTransaction          = new Hashtable();
                DataTable dtTransaction          = new DataTable();
                string    strChildTransKey       = UtilHelper.GenerateNewKey(0);
                string    strShiftKey            = UtilHelper.GetShiftKey(db, curTime.ToString("yyyy-MM-dd HH:mm:ss"));
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, strChildTransKey);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, "0");
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, htMainData[POR_LOT_FIELDS.FIELD_LOT_KEY]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, htMainData[POR_LOT_FIELDS.FIELD_QUANTITY]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, htMainData[POR_LOT_FIELDS.FIELD_QUANTITY]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_CREATELOT);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, htMainData[POR_LOT_FIELDS.FIELD_STATE_FLAG]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, string.Empty);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER, htMainData[POR_LOT_FIELDS.FIELD_OPR_COMPUTER]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY, strShiftKey);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME, htMainData[POR_LOT_FIELDS.FIELD_SHIFT_NAME]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, htMainData[POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY, htMainData[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY, htMainData[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY, htMainData[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY]);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_NAME, stepName);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_NAME, routeName);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_NAME, enterpriseName);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, curTime);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, editTimezone);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, editor);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPERATOR, editor);
                htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG, htMainData[POR_LOT_FIELDS.FIELD_IS_REWORKED]);
                sql = DatabaseTable.BuildInsertSqlStatement(wipFields, htTransaction, null);
                db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                #endregion

                if (dsParams.Tables.Contains(POR_LOT_ATTR_FIELDS.DATABASE_TABLE_NAME))
                {
                    DatabaseTable.BuildInsertSqlStatements(ref sqlCommandList,
                                                           new POR_LOT_ATTR_FIELDS(),
                                                           dsParams.Tables[POR_LOT_ATTR_FIELDS.DATABASE_TABLE_NAME],
                                                           new Dictionary <string, string>()
                    {
                        { COMMON_FIELDS.FIELD_COMMON_EDIT_TIME, null },
                        { COMMON_FIELDS.FIELD_COMMON_EDIT_TIMEZONE, "CN-ZH" }
                    },
                                                           new List <string>()
                    {
                        COMMON_FIELDS.FIELD_COMMON_OPERATION_ACTION, BASE_ATTRIBUTE_FIELDS.FIELDS_DATA_TYPE
                    });
                }
                foreach (string s in sqlCommandList)
                {
                    db.ExecuteNonQuery(dbTran, CommandType.Text, s);
                }
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// 自动合批操作。
        /// </summary>
        /// <param name="db">数据库对象。</param>
        /// <param name="dbtran">数据操作的事务对象。</param>
        /// <param name="lotKeyFrom">需要合批的批次主键。</param>
        /// <param name="workOrderKeyFrom">工单主键。</param>
        /// <param name="stepKeyFrom">工步主键</param>
        /// <param name="lineKeyFrom">线别主键</param>
        /// <param name="quantityFrom">数量</param>
        /// <param name="maxBoxQuantity">最大箱数量</param>
        /// <param name="stateFlag">批次状态标记</param>
        /// <param name="editor">编辑人</param>
        /// <param name="isRework">是否重工</param>
        /// <param name="oprLine">操作线别</param>
        /// <param name="shiftName">操作班别</param>
        public static void AutoMerge(Database db,
                                     DbTransaction dbtran,
                                     string lotKeyFrom,
                                     string workOrderKeyFrom,
                                     string stepKeyFrom,
                                     string lineKeyFrom,
                                     string quantityFrom,
                                     int maxBoxQuantity,
                                     int stateFlag,
                                     string editor,
                                     bool isRework,
                                     string oprLine,
                                     string shiftName)
        {
            string  lotKey = "", quantity = "", enterpriseKey = "", routeKey = "", stepKey = "";
            int     totalQuantity = 0;
            int     mergedQuantity = 0;
            int     leftQuantity = 0;
            string  sql = "", strParentTransKey = "";
            DataSet dsMergeLot = new DataSet();

            //获取批次主键不等于指定批次,但工单为指定工单,工步为指定工步,线别为指定线别,状态为指定状态的批次信息。
            sql = string.Format(@"SELECT A.LOT_KEY,A.QUANTITY,A.ROUTE_ENTERPRISE_VER_KEY,A.CUR_ROUTE_VER_KEY,A.CUR_STEP_VER_KEY
                                FROM POR_LOT A
                                LEFT  JOIN FMM_PRODUCTION_LINE B ON A.LINE_NAME=B.LINE_NAME
                                WHERE A.LOT_KEY !='{0}' 
                                AND A.WORK_ORDER_KEY='{1}'
                                AND A.CUR_STEP_VER_KEY='{2}'
                                AND B.PRODUCTION_LINE_KEY='{3}' 
                                AND A.STATUS = 1 AND A.QUANTITY != 0 
                                AND A.DELETED_TERM_FLAG = 0 
                                AND A.HOLD_FLAG=0 
                                AND A.STATE_FLAG={4}",
                                lotKeyFrom.PreventSQLInjection(),
                                workOrderKeyFrom.PreventSQLInjection(),
                                stepKeyFrom.PreventSQLInjection(),
                                lineKeyFrom.PreventSQLInjection(), stateFlag);
            //如果指定了最大箱数量,则查询条件增加数量小于最大箱数量。
            if (maxBoxQuantity != -1)
            {
                sql = sql + " AND A.QUANTITY<" + maxBoxQuantity + "";
            }
            //如果是重工,则查询条件增加重工>0
            if (isRework)
            {
                sql = sql + " AND A.REWORK_FLAG > 0";
            }
            dsMergeLot = db.ExecuteDataSet(CommandType.Text, sql);

            //查询得到的数据集中的数据表个数>0。
            if (dsMergeLot.Tables.Count > 0)
            {
                //可以合并的批次的记录大于0。
                if (dsMergeLot.Tables[0].Rows.Count > 0)
                {
                    lotKey        = dsMergeLot.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_LOT_KEY].ToString();                      //批次主键
                    quantity      = dsMergeLot.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_QUANTITY].ToString();                     //数量
                    enterpriseKey = dsMergeLot.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY].ToString();     //流程组主键
                    routeKey      = dsMergeLot.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY].ToString();            //流程主键
                    stepKey       = dsMergeLot.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY].ToString();             //工步主键
                    string time = UtilHelper.GetSysdate(db).ToString("yyyy-MM-dd HH:mm:ss");                                    //当前时间
                    //合并的批次数量>0 并且 被合并的批次数量>0
                    if (quantity.Length > 0 && quantityFrom.Length > 0)
                    {
                        totalQuantity = Convert.ToInt32(quantity) + Convert.ToInt32(quantityFrom);
                        #region 更新合批批次的数量
                        //如果最大箱数量不等于 -1 并且总数量>最大箱数量。
                        if (maxBoxQuantity != -1 & totalQuantity > maxBoxQuantity)
                        {
                            #region 更新合并到的批次数量为最大箱数量。
                            sql = @"UPDATE POR_LOT SET QUANTITY=" + maxBoxQuantity + "," +
                                  "EDITOR='" + editor.PreventSQLInjection() + "'," +
                                  "EDIT_TIME=GETDATE() " +
                                  "WHERE LOT_KEY='" + lotKey.PreventSQLInjection() + "'";
                            db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                            #endregion

                            #region 更新被合并的批次数量为剩余数量。
                            leftQuantity   = totalQuantity - maxBoxQuantity;
                            mergedQuantity = Convert.ToInt32(quantityFrom) - leftQuantity;
                            sql            = @"UPDATE POR_LOT SET QUANTITY=" + leftQuantity + "," +
                                             "EDITOR='" + editor.PreventSQLInjection() + "'," +
                                             "EDIT_TIME=GETDATE() " +
                                             "WHERE LOT_KEY='" + lotKeyFrom.PreventSQLInjection() + "'";
                            db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                            #endregion
                        }
                        else
                        {
                            #region 更新合并到的批次数量为总数量。
                            sql = @"UPDATE POR_LOT SET QUANTITY=" + totalQuantity + "," +
                                  "EDITOR='" + editor.PreventSQLInjection() + "'," +
                                  "EDIT_TIME=GETDATE()" +
                                  "WHERE LOT_KEY='" + lotKey.PreventSQLInjection() + "'";
                            db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                            #endregion

                            #region 更新被合并的批次数量为0。删除标记为1。
                            mergedQuantity = Convert.ToInt32(quantityFrom);
                            sql            = @"UPDATE POR_LOT SET QUANTITY='0',DELETED_TERM_FLAG='1',
                                    EDITOR='" + editor.PreventSQLInjection() + "'," +
                                             "EDIT_TIME=GETDATE() " +
                                             "WHERE LOT_KEY='" + lotKeyFrom.PreventSQLInjection() + "'";
                            db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                            #endregion
                        }
                        #endregion

                        #region 插入一笔【合并到批次】的操作记录。
                        WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
                        Hashtable parenttransactionTable = new Hashtable();
                        DataTable parenttransaction      = new DataTable();
                        strParentTransKey = UtilHelper.GenerateNewKey(0);
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, strParentTransKey);
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, "0");
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, lotKey);
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, quantity);
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, totalQuantity);
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_MERGE);
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, "");
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, "");
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, "CN-ZH");
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, time);
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY, lineKeyFrom);
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, workOrderKeyFrom);
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, stateFlag.ToString());
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME, shiftName);
                        parenttransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE, oprLine);
                        sql = DatabaseTable.BuildInsertSqlStatement(wipFields, parenttransactionTable, null);
                        db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                        #endregion

                        #region 插入一笔【被合并批次】的操作记录。
                        Hashtable childtransactionTable = new Hashtable();
                        DataTable childtransaction      = new DataTable();
                        string    strChildTransKey      = UtilHelper.GenerateNewKey(0);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, strChildTransKey);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_TYPE, "0");
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, lotKeyFrom);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, mergedQuantity.ToString());
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, leftQuantity.ToString());
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_MERGED);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, "");
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, "");
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, "CN-ZH");
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, time);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY, lineKeyFrom);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, workOrderKeyFrom);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, stateFlag.ToString());
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME, shiftName);
                        childtransactionTable.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE, oprLine);
                        sql = DatabaseTable.BuildInsertSqlStatement(wipFields, childtransactionTable, null);
                        db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                        #endregion

                        #region 插入一笔批次合批的操作记录。
                        Hashtable        MergeHashTable = new Hashtable();
                        WIP_MERGE_FIELDS wipMerge       = new WIP_MERGE_FIELDS();

                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_TRANSACTION_KEY, strParentTransKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_CHILD_LOT_KEY, lotKeyFrom);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_MAIN_LOT_KEY, lotKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_MERGE_QUANTITY, mergedQuantity.ToString());
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_STEP_KEY, stepKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_ROUTE_KEY, routeKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_ENTERPRISE_KEY, enterpriseKey);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_EDITOR, "");
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_EDIT_TIME, time);
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_EDIT_TIMEZONE, "CN-ZH");
                        MergeHashTable.Add(WIP_MERGE_FIELDS.FIELD_CHILD_TRANSACTION_KEY, strChildTransKey);

                        sql = DatabaseTable.BuildInsertSqlStatement(wipMerge, MergeHashTable, null);
                        db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                        #endregion
                    }
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// 批次线别调整操作。
        /// </summary>
        /// <remarks>
        /// 操作名称:<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_CHANGE_LINE"/>。
        /// </remarks>
        /// <param name="dsParams">包含批次线别调整信息的数据集对象。</param>
        /// <param name="dbTran">数据库操作事务对象。</param>
        public void LotExchangeLine(DbTransaction dbTran, DataSet dsParams)
        {
            //参数数据。
            if (dsParams == null ||
                !dsParams.Tables.Contains(WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME) ||
                !dsParams.Tables.Contains(POR_LOT_FIELDS.DATABASE_TABLE_NAME) ||
                dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME].Rows.Count == 0 ||  //线别调整批次操作记录不能为空记录。
                dsParams.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows.Count == 0 ||          //线别调整批次清单
                dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME].Rows.Count != dsParams.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME].Rows.Count
                )
            {
                throw new Exception("传入参数不正确,请检查。");
            }
            IDbConnection dbConn = dbTran.Connection;
            IDbCommand    dbCmd  = dbConn.CreateCommand();

            dbCmd.Transaction = dbTran;
            dbCmd.CommandType = CommandType.Text;
            DataTable dtTransaction = dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME];   //存放操作数据
            DataTable dtLotInfo     = dsParams.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME];           //线别调整批次清单

            //插入操作记录
            foreach (DataRow drTransaction in dtTransaction.Rows)
            {
                string lotKey   = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]);     //批次主键
                string activity = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]);
                string editor   = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);        //编辑人
                string timeZone = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);        //编辑时区
                //操作动作必须是 HOLD
                if (activity != ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_CHANGE_LINE)
                {
                    throw new Exception("传入参数的操作动作不正确,请检查。");
                }
                string transKey = UtilHelper.GenerateNewKey(0);

                //向Wip_Lot中插入批次参数记录
                AddWIPLot(dbTran, transKey, lotKey);

                //向WIP_TRANSACTION表插入批次调整的操作记录。
                WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY] = transKey;
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME]       = DBNull.Value;
                string sql = DatabaseTable.BuildInsertSqlStatement(wipFields, drTransaction, null);
                dbCmd.CommandText = sql;
                dbCmd.ExecuteNonQuery();

                //更新批次数据
                DataRow drLotInfo = dtLotInfo.Select(string.Format(" LOT_KEY = '{0}'", lotKey))[0];

                StringBuilder sbUpdateSql = new StringBuilder();
                sbUpdateSql.AppendFormat(@"UPDATE POR_LOT 
                                           SET LOT_LINE_KEY = '{1}',
                                               LOT_LINE_CODE = '{2}',
                                               EDITOR = '{3}',
                                               EDIT_TIME = GETDATE(),
                                               EDIT_TIMEZONE = '{4}'
                                           WHERE LOT_KEY = '{0}'",
                                         lotKey.PreventSQLInjection(),
                                         drLotInfo[POR_LOT_FIELDS.FIELD_LOT_LINE_KEY],
                                         drLotInfo[POR_LOT_FIELDS.FIELD_LOT_LINE_CODE],
                                         drLotInfo[POR_LOT_FIELDS.FIELD_EDITOR],
                                         drLotInfo[POR_LOT_FIELDS.FIELD_EDIT_TIMEZONE]);
                db.ExecuteNonQuery(dbTran, CommandType.Text, sbUpdateSql.ToString());
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// 电池片补片操作。
        /// </summary>
        /// <remarks>
        /// 操作名称:<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_PATCH"/>。
        /// </remarks>
        /// <param name="dsParams">包含补片信息的数据集对象。</param>
        /// <returns>包含结果数据的数据集对象。</returns>
        public DataSet LotPatch(DataSet dsParams)
        {
            DataSet       dsReturn = new DataSet();
            DbConnection  dbConn   = null;
            DbTransaction dbTran   = null;

            try
            {
                dbConn = db.CreateConnection();
                dbConn.Open();
                dbTran = dbConn.BeginTransaction();
                //参数数据。
                if (dsParams == null ||
                    !dsParams.Tables.Contains(TRANS_TABLES.TABLE_PARAM) ||                              //存放附加参数数据
                    !dsParams.Tables.Contains(WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME))              //存放操作数据
                {
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "传入参数不正确,请检查。");
                    return(dsReturn);
                }

                DataTable dtParams      = dsParams.Tables[TRANS_TABLES.TABLE_PARAM];                    //存放附加参数数据
                DataTable dtTransaction = dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME];  //存放操作数据
                Hashtable htTransaction = FanHai.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dtTransaction);
                Hashtable htParams      = FanHai.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dtParams);
                string    opEditTime    = Convert.ToString(htParams[COMMON_FIELDS.FIELD_COMMON_EDIT_TIME]); //操作时编辑时间
                string    lotKey        = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]);
                string    editTimeZone  = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY]);
                string    editor        = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);
                double    leftQty       = Convert.ToDouble(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT]);
                string    activity      = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]);
                //操作动作必须是 PATCH
                if (activity != ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_PATCH)
                {
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "传入参数的补片操作动作不正确,请检查。");
                    return(dsReturn);
                }
                //如果数据集中包含名称WIP_PATCH_FIELDS.DATABASE_TABLE_NAME的数据表对象。
                if (dsParams.Tables.Contains(WIP_PATCH_FIELDS.DATABASE_TABLE_NAME))
                {
                    string transactionKey              = UtilHelper.GenerateNewKey(0);
                    string sql                         = string.Empty;
                    double sumPatchedQty               = 0;
                    WIP_TRANSACTION_FIELDS wipFields   = new WIP_TRANSACTION_FIELDS();
                    WIP_PATCH_FIELDS       patchFields = new WIP_PATCH_FIELDS();
                    DataTable dtPatch                  = dsParams.Tables[WIP_PATCH_FIELDS.DATABASE_TABLE_NAME]; //存放补片明细数据
                    //遍历批次的报废数据。
                    for (int i = 0; i < dtPatch.Rows.Count; i++)
                    {
                        DataRow   drPatch         = dtPatch.Rows[i];
                        Hashtable htPatch         = CommonUtils.ConvertRowToHashtable(drPatch);
                        string    patchedLotKey   = Convert.ToString(htPatch[WIP_PATCH_FIELDS.FIELD_PATCHED_LOT_KEY]);
                        double    patchedQuantity = Convert.ToDouble(htPatch[WIP_PATCH_FIELDS.FIELD_PATCH_QUANTITY]);
                        sumPatchedQty += patchedQuantity;   //总的补片数量。
                        int isOnlyPatch = Convert.ToInt32(htPatch[WIP_PATCH_FIELDS.FIELD_IS_ONLY_PATCHED]);
                        //获取被补片批次的信息
                        DataSet dsPatchLotInfo = LotManagement.GetLotBasicInfo(db, dbTran, patchedLotKey);
                        DataRow drPatchLotInfo = dsPatchLotInfo.Tables[0].Rows[0];
                        double  quantityIn     = Convert.ToDouble(drPatchLotInfo[POR_LOT_FIELDS.FIELD_QUANTITY]);
                        //isOnlyPatch=0 先报废后补片,所以数量不需要改变。isOnlyPatch=1 仅做补片。
                        double quantityOut           = isOnlyPatch == 0? quantityIn: quantityIn + patchedQuantity;
                        string enterpriseKey         = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY]);
                        string enterpriseName        = Convert.ToString(drPatchLotInfo[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ENTERPRISE_NAME]);
                        string routeKey              = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]);
                        string routeName             = Convert.ToString(drPatchLotInfo[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_NAME]);
                        string stepKey               = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]);
                        string stepName              = Convert.ToString(drPatchLotInfo[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME]);
                        string workOrderKey          = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY]);
                        string stateFlag             = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_STATE_FLAG]);
                        string reworkFlag            = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_IS_REWORKED]);
                        string lineKey               = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_CUR_PRODUCTION_LINE_KEY]);
                        string lineName              = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_OPR_LINE]);
                        string edcInsKey             = Convert.ToString(drPatchLotInfo[POR_LOT_FIELDS.FIELD_EDC_INS_KEY]);
                        string equipmentKey          = Convert.ToString(drPatchLotInfo[EMS_EQUIPMENTS_FIELDS.FIELD_EQUIPMENT_KEY]);
                        string patchedTransactionKey = UtilHelper.GenerateNewKey(0);
                        AddWIPLot(dbTran, patchedTransactionKey, patchedLotKey);
                        //更新被补片批次的数量
                        sql = string.Format(@"UPDATE POR_LOT 
                                            SET QUANTITY={0},EDITOR='{1}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{2}'
                                            WHERE LOT_KEY='{3}'",
                                            quantityOut,
                                            editor.PreventSQLInjection(),
                                            editTimeZone.PreventSQLInjection(),
                                            patchedLotKey.PreventSQLInjection());
                        db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                        Hashtable htPatchedTransaction = new Hashtable(htTransaction);
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]       = patchedLotKey;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY]  = enterpriseKey;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_NAME] = enterpriseName;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY]       = routeKey;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_ROUTE_NAME]      = routeName;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY]        = stepKey;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_NAME]       = stepName;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY]  = workOrderKey;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG]      = stateFlag;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG]     = reworkFlag;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY]        = lineKey;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE]        = lineName;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE_PRE]    = lineName;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDC_INS_KEY]     = edcInsKey;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_EQUIPMENT_KEY]   = equipmentKey;
                        //插入报废记录。
                        //isOnlyPatch=0 先报废后补片。isOnlyPatch=1 仅做补片。
                        if (isOnlyPatch == 0)
                        {
                            string  scrapTransaction = UtilHelper.GenerateNewKey(0);
                            DataSet dsScrapParams    = new DataSet();
                            htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN]     = quantityIn;
                            htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT]    = quantityIn - patchedQuantity;
                            htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY] = scrapTransaction;
                            htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]        = ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_CELLSCRAP;
                            DataTable dtScrapTransaction = CommonUtils.ParseToDataTable(htPatchedTransaction);
                            dtScrapTransaction.TableName = WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME;
                            dsScrapParams.Tables.Add(dtScrapTransaction);
                            DataTable dtScrap = CommonUtils.CreateDataTable(new WIP_SCRAP_FIELDS());
                            DataRow   drScrap = dtScrap.NewRow();
                            drScrap[WIP_SCRAP_FIELDS.FIELD_DESCRIPTION]        = drPatch[WIP_PATCH_FIELDS.FIELD_DESCRIPTION];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_EDIT_TIME]          = drPatch[WIP_PATCH_FIELDS.FIELD_EDIT_TIME];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_EDIT_TIMEZONE_KEY]  = drPatch[WIP_PATCH_FIELDS.FIELD_EDIT_TIMEZONE_KEY];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_EDITOR]             = drPatch[WIP_PATCH_FIELDS.FIELD_EDITOR];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_ENTERPRISE_KEY]     = drPatch[WIP_PATCH_FIELDS.FIELD_ENTERPRISE_KEY];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_ENTERPRISE_NAME]    = drPatch[WIP_PATCH_FIELDS.FIELD_ENTERPRISE_NAME];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_REASON_CODE_CLASS]  = drPatch[WIP_PATCH_FIELDS.FIELD_REASON_CODE_CLASS];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_REASON_CODE_KEY]    = drPatch[WIP_PATCH_FIELDS.FIELD_REASON_CODE_KEY];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_REASON_CODE_NAME]   = drPatch[WIP_PATCH_FIELDS.FIELD_REASON_CODE_NAME];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_RESPONSIBLE_PERSON] = drPatch[WIP_PATCH_FIELDS.FIELD_RESPONSIBLE_PERSON];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_ROUTE_KEY]          = drPatch[WIP_PATCH_FIELDS.FIELD_ROUTE_KEY];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_ROUTE_NAME]         = drPatch[WIP_PATCH_FIELDS.FIELD_ROUTE_NAME];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_SCRAP_QUANTITY]     = drPatch[WIP_PATCH_FIELDS.FIELD_PATCH_QUANTITY];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_STEP_KEY]           = drPatch[WIP_PATCH_FIELDS.FIELD_STEP_KEY];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_STEP_NAME]          = drPatch[WIP_PATCH_FIELDS.FIELD_STEP_NAME];
                            drScrap[WIP_SCRAP_FIELDS.FIELD_TRANSACTION_KEY]    = scrapTransaction;
                            dtScrap.Rows.Add(drScrap);
                            dsScrapParams.Tables.Add(dtScrap);
                            LotScrap(dsScrapParams, dbTran);
                        }
                        //插入被补片批次的操作记录
                        //isOnlyPatch=0 先报废后补片。isOnlyPatch=1 仅做补片。
                        if (isOnlyPatch == 0)
                        {
                            htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN]  = quantityIn - patchedQuantity;
                            htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT] = quantityIn;
                        }
                        else
                        {
                            htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN]  = quantityIn;
                            htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT] = quantityIn + patchedQuantity;
                        }
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY] = patchedTransactionKey;
                        htPatchedTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]        = ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_PATCHED;
                        sql = DatabaseTable.BuildInsertSqlStatement(wipFields, htPatchedTransaction, null);
                        db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                        //插入一笔批次补片明细数据
                        //补片操作记录主键。
                        if (!htPatch.ContainsKey(WIP_PATCH_FIELDS.FIELD_TRANSACTION_KEY))
                        {
                            htPatch.Add(WIP_PATCH_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
                        }
                        htPatch[WIP_PATCH_FIELDS.FIELD_TRANSACTION_KEY] = transactionKey;
                        //被补片批次操作记录主键
                        if (!htPatch.ContainsKey(WIP_PATCH_FIELDS.FIELD_PATCHED_TRANSACTION_KEY))
                        {
                            htPatch.Add(WIP_PATCH_FIELDS.FIELD_PATCHED_TRANSACTION_KEY, patchedTransactionKey);
                        }
                        htPatch[WIP_PATCH_FIELDS.FIELD_PATCHED_TRANSACTION_KEY] = patchedTransactionKey;
                        //重置补片明细的编辑时间为当前时间。
                        htPatch[WIP_PATCH_FIELDS.FIELD_EDIT_TIME] = null;
                        sql = DatabaseTable.BuildInsertSqlStatement(patchFields, htPatch, null);
                        db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                    }

                    AddWIPLot(dbTran, transactionKey, lotKey);
                    //获取组件补片批次当前数量
                    sql = string.Format("SELECT QUANTITY FROM POR_LOT WHERE LOT_KEY='{0}'", lotKey.PreventSQLInjection());
                    double quantity = Convert.ToDouble(db.ExecuteScalar(CommandType.Text, sql));
                    if (quantity < sumPatchedQty)
                    {
                        ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Format("组件补片批次当前实际数量[{0}]小于补片数量[{1}],请确认。", quantity, sumPatchedQty));
                        dbTran.Rollback();
                        return(dsReturn);
                    }
                    //更新批次数量。
                    sql = string.Format(@"UPDATE POR_LOT 
                                        SET QUANTITY={0},EDITOR='{1}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{2}',DELETED_TERM_FLAG={3}
                                        WHERE LOT_KEY='{4}'",
                                        quantity - sumPatchedQty,
                                        editor.PreventSQLInjection(),
                                        editTimeZone.PreventSQLInjection(),
                                        (quantity - sumPatchedQty) > 0 ? 0 : 1,
                                        lotKey.PreventSQLInjection());
                    db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                    //向WIP_TRANSACTION表插入批次补片的操作记录。
                    if (!htTransaction.ContainsKey(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY))
                    {
                        htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
                    }
                    htTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY] = transactionKey;
                    sql = DatabaseTable.BuildInsertSqlStatement(wipFields, htTransaction, null);
                    db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                }
                dbTran.Commit();
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Empty);
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("LotPatch Error: " + ex.Message);
                dbTran.Rollback();
            }
            finally
            {
                dbConn.Close();
            }
            return(dsReturn);
        }
Exemplo n.º 27
0
        /// <summary>
        /// 返工/返修批次。
        /// </summary>
        /// <param name="dsParams">包含批次返工/返修信息的数据集对象。</param>
        /// <param name="dbTran">数据库操作事务对象。</param>
        private void LotRework(DataSet dsParams, DbTransaction dbTran)
        {
            //参数数据。
            if (dsParams == null ||
                !dsParams.Tables.Contains(WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME) ||
                !dsParams.Tables.Contains(WIP_COMMENT_FIELDS.DATABASE_TABLE_NAME) ||
                dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME].Rows.Count == 0 ||          //返工批次操作记录不能为空记录。
                dsParams.Tables[WIP_COMMENT_FIELDS.DATABASE_TABLE_NAME].Rows.Count == 0)                //返工信息不能为空
            {
                throw new Exception("传入参数不正确,请检查。");
            }

            DataTable dtTransaction       = dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME]; //存放操作数据
            DataTable dtComment           = dsParams.Tables[WIP_COMMENT_FIELDS.DATABASE_TABLE_NAME];     //存放返工信息明细数据
            DataTable dtParams            = dsParams.Tables[TRANS_TABLES.TABLE_MAIN_DATA];
            Hashtable htParams            = CommonUtils.ConvertToHashtable(dtParams);
            string    reworkEnterpriseKey = Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY]);
            string    reworkRouteKey      = Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]);
            string    reworkStepKey       = Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]);
            DataTable dtHold = null;

            if (dsParams.Tables.Contains(WIP_HOLD_RELEASE_FIELDS.DATABASE_TABLE_NAME) &&
                dsParams.Tables[WIP_HOLD_RELEASE_FIELDS.DATABASE_TABLE_NAME].Rows.Count > 0)
            {
                dtHold = dsParams.Tables[WIP_HOLD_RELEASE_FIELDS.DATABASE_TABLE_NAME];           //存放暂停信息明细数据
            }

            //插入操作记录
            foreach (DataRow drTransaction in dtTransaction.Rows)
            {
                string lotKey   = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY]);     //批次主键
                string editor   = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);        //编辑人
                string timeZone = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);        //编辑时区
                string stepKey  = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY]);      //当前工步主键
                if (Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]) != ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_REWORK)
                {
                    throw new Exception("传入的操作名称不正确,请检查。");
                }
                string transactionKey = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY]);
                AddWIPLot(dbTran, transactionKey, lotKey);
                //向WIP_TRANSACTION表插入批次调整的操作记录。
                WIP_TRANSACTION_FIELDS wipFields = new WIP_TRANSACTION_FIELDS();
                drTransaction[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME] = DBNull.Value;
                string sql = DatabaseTable.BuildInsertSqlStatement(wipFields, drTransaction, null);
                db.ExecuteNonQuery(dbTran, CommandType.Text, sql);

                //更新批次数据
                StringBuilder sbUpdateSql = new StringBuilder();
                sbUpdateSql.AppendFormat(@"UPDATE POR_LOT 
                                        SET STATE_FLAG=0,START_WAIT_TIME=GETDATE(),REWORK_FLAG=REWORK_FLAG+1,
                                        ROUTE_ENTERPRISE_VER_KEY='{0}',CUR_ROUTE_VER_KEY='{1}',CUR_STEP_VER_KEY='{2}',
                                        EDITOR='{3}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{4}'",
                                         reworkEnterpriseKey.PreventSQLInjection(),
                                         reworkRouteKey.PreventSQLInjection(),
                                         reworkStepKey.PreventSQLInjection(),
                                         editor.PreventSQLInjection(),
                                         timeZone.PreventSQLInjection());
                //如果当前有HOLD批次,则释放批次。
                if (dtHold != null)
                {
                    sbUpdateSql.Append(",HOLD_FLAG=0");
                }
                sbUpdateSql.AppendFormat(" WHERE LOT_KEY='{0}'", lotKey.PreventSQLInjection());
                db.ExecuteNonQuery(dbTran, CommandType.Text, sbUpdateSql.ToString());

                //更新设备数据,以完成设备出站,切换设备状态。
                sql = string.Format(@"SELECT B.EQUIPMENT_KEY,A.EQUIPMENT_NAME,A.EQUIPMENT_STATE_KEY
                                    FROM EMS_EQUIPMENTS A,EMS_LOT_EQUIPMENT B
                                    WHERE A.EQUIPMENT_KEY = B.EQUIPMENT_KEY 
                                    AND B.STEP_KEY = '{0}' AND B.LOT_KEY='{1}' 
                                    AND B.END_TIMESTAMP IS NULL",
                                    stepKey.PreventSQLInjection(),
                                    lotKey.PreventSQLInjection());
                DataSet dsResult = db.ExecuteDataSet(CommandType.Text, sql);
                if (dsResult != null && dsResult.Tables.Count > 0 && dsResult.Tables[0].Rows.Count > 0)
                {
                    string equipmentKey = Convert.ToString(dsResult.Tables[0].Rows[0]["EQUIPMENT_KEY"]);
                    WipManagement.TrackOutForEquipment(db, dbTran, lotKey, stepKey, equipmentKey, editor);
                }
            }
            //插入批次返工明细记录
            foreach (DataRow drComment in dtComment.Rows)
            {
                //向WIP_COMMENT表插入批次调整的操作记录。
                WIP_COMMENT_FIELDS commentFields = new WIP_COMMENT_FIELDS();
                string             sql           = DatabaseTable.BuildInsertSqlStatement(commentFields, drComment, null);
                db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
            }
        }