Exemplo n.º 1
0
        /// <summary>
        /// 检查是否要HOLD批次。如果需要HOLD批次,则HOLD批次。
        /// </summary>
        /// <param name="dbtran">数据库事务对象。。</param>
        /// <param name="lotKey">批次主键。</param>
        /// <param name="stepKey">工步主键。</param>
        /// <param name="shiftName">班别名称。</param>
        /// <param name="shiftKey">班别主键。</param>
        /// <param name="editor">编辑人。</param>
        /// <param name="oprComputer">操作计算机名称。</param>
        /// <param name="editTimeZone">编辑时间时区。</param>
        /// <param name="action">动作名称。<see cref="COMMON_FIELDS.FIELD_ACTIVITY_TRACKIN"/>或者<see cref="COMMON_FIELDS.FIELD_ACTIVITY_TRACKOUT"/></param>
        /// <returns>触发预设暂停的个数。0:没有批次被HOLD。>0:该批次被HOLD。</returns>
        private int CheckAndUpdateFutureHold(DbTransaction dbtran, string lotKey, string stepKey,
                                             string shiftName, string shiftKey,
                                             string editor, string oprComputer, string editTimeZone, string action)
        {
            string    sql   = @"SELECT * FROM WIP_FUTUREHOLD 
                           WHERE LOT_KEY=@lotKey AND STEP_KEY=@stepKey AND STATUS=1 AND ACTION_NAME=@action
                           ORDER BY EDIT_TIME DESC";
            DbCommand dbCmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(dbCmd, "lotKey", DbType.String, lotKey);
            db.AddInParameter(dbCmd, "stepKey", DbType.String, stepKey);
            db.AddInParameter(dbCmd, "action", DbType.String, action);
            DataSet dsFutureHold = db.ExecuteDataSet(dbCmd, dbtran);
            int     nRet         = 0;

            if (dsFutureHold != null && dsFutureHold.Tables.Count > 0 && dsFutureHold.Tables[0].Rows.Count > 0)
            {
                DataTable dtFutureHold = dsFutureHold.Tables[0];
                DataRow   drFutureHold = dtFutureHold.Rows[0];

                string transactionKey = UtilHelper.GenerateNewKey(0);
                string rcCodeKey      = Convert.ToString(drFutureHold[WIP_FUTUREHOLD_FIELDS.FIELDS_REASON_CODE_KEY]);
                string rcCodeName     = Convert.ToString(drFutureHold[WIP_FUTUREHOLD_FIELDS.FIELDS_REASON_CODE]);
                string comment        = Convert.ToString(drFutureHold[WIP_FUTUREHOLD_FIELDS.FIELDS_REMARK]);
                string opUser         = Convert.ToString(drFutureHold[WIP_FUTUREHOLD_FIELDS.FIELDS_EDITOR]);

                Hashtable htParams = new Hashtable();
                htParams[POR_LOT_FIELDS.FIELD_LOT_KEY] = lotKey;
                htParams[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY]   = transactionKey;
                htParams[WIP_HOLD_RELEASE_FIELDS.FIELD_REASON_CODE_KEY]  = rcCodeKey;
                htParams[WIP_HOLD_RELEASE_FIELDS.FIELD_REASON_CODE_NAME] = rcCodeName;
                htParams[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT]  = comment;
                htParams[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME]        = shiftName;
                htParams[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY]         = shiftKey;
                htParams[WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER]      = oprComputer;
                htParams[WIP_TRANSACTION_FIELDS.FIELD_OPERATOR]          = opUser;
                htParams[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]            = opUser;
                htParams[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY] = editTimeZone;
                DataTable dtParams = SolarViewer.Hemera.Share.Common.CommonUtils.ParseToDataTable(htParams);
                dtParams.TableName = TRANS_TABLES.TABLE_MAIN_DATA;
                DataSet dsParams = new DataSet();
                dsParams.Tables.Add(dtParams);

                WipManagement.HoldLot(db, dbtran, dsParams);

                sql = @"UPDATE WIP_FUTUREHOLD 
                        SET STATUS=0,EDITOR=@editor,EDIT_TIME= GETDATE()
                        WHERE LOT_KEY=@lotKey AND STEP_KEY=@stepKey AND STATUS=1 AND ACTION_NAME=@action";

                dbCmd = db.GetSqlStringCommand(sql);
                db.AddInParameter(dbCmd, "lotKey", DbType.String, lotKey);
                db.AddInParameter(dbCmd, "stepKey", DbType.String, stepKey);
                db.AddInParameter(dbCmd, "action", DbType.String, action);
                db.AddInParameter(dbCmd, "editor", DbType.String, editor);
                nRet = db.ExecuteNonQuery(dbCmd, dbtran);
            }
            return(nRet);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 锁定批次。
        /// </summary>
        /// <param name="dsParams">包含锁定批次数据的数据集。</param>
        /// <returns>包含执行结果的数据集。</returns>
        public DataSet HoldLot(DataSet dsParams)
        {
            DateTime startTime = DateTime.Now;

            DataSet       dsReturn = new DataSet();
            DbConnection  dbConn   = null;
            DbTransaction dbTran   = null;

            try
            {
                dbConn = db.CreateConnection();
                dbConn.Open();
                //Create Transaction
                dbTran = dbConn.BeginTransaction();
                #region CheckExpired
                if (dsParams.Tables.Contains(TRANS_TABLES.TABLE_MAIN_DATA))
                {
                    DataTable dtParams = dsParams.Tables[TRANS_TABLES.TABLE_MAIN_DATA];
                    Hashtable htParams = SolarViewer.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dtParams);
                    KeyValuePair <string, string>         kvp           = new KeyValuePair <string, string>(POR_LOT_FIELDS.FIELD_LOT_KEY, htParams[POR_LOT_FIELDS.FIELD_LOT_KEY].ToString());
                    List <KeyValuePair <string, string> > listCondition = new List <KeyValuePair <string, string> >();
                    listCondition.Add(kvp);
                    if (UtilHelper.CheckRecordExpired(db, POR_LOT_FIELDS.DATABASE_TABLE_NAME, listCondition, htParams[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME].ToString()))
                    {
                        SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, COMMON_FIELDS.FIELD_COMMON_EDITTIME_EXP);
                        return(dsReturn);
                    }
                }
                #endregion
                WipManagement.HoldLot(db, dbTran, dsParams);
                dbTran.Commit();
                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "");
            }
            catch (Exception ex)
            {
                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("HoldLot Error: " + ex.Message);
                dbTran.Rollback();
            }
            finally
            {
                dbConn.Close();
            }

            System.DateTime endTime = System.DateTime.Now;
            LogService.LogInfo("HoldLot Time: " + (endTime - startTime).TotalMilliseconds.ToString());

            return(dsReturn);
        }