Example #1
0
        /// <summary>
        /// 批次自动过站。
        /// </summary>
        /// <param name="rowKey">WIP_JOB表主键。</param>
        /// <returns>包含自动过站执行结果的数据集。</returns>
        public DataSet AutoTrackOut(string rowKey)
        {
            DataSet dsReturn = new DataSet();

            try
            {
                string msg = string.Empty;
                //获取批次自动过站任务记录
                string  sql   = string.Format(@"SELECT * FROM WIP_JOB WHERE ROW_KEY='{0}'", rowKey);
                DataSet dsJob = db.ExecuteDataSet(CommandType.Text, sql);
                if (dsJob == null || dsJob.Tables.Count <= 0 || dsJob.Tables[0].Rows.Count <= 0)
                {
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "WIP_JOB表主键对应的记录不存在。");
                    return(dsReturn);
                }
                string equipmentKey  = dsJob.Tables[0].Rows[0][EMS_EQUIPMENTS_FIELDS.FIELD_EQUIPMENT_KEY].ToString();
                string enterpriseKey = dsJob.Tables[0].Rows[0][WIP_JOB_FIELDS.FIELDS_ENTERPRISE_KEY].ToString();
                string routeKey      = dsJob.Tables[0].Rows[0][WIP_JOB_FIELDS.FIELDS_ROUTE_KEY].ToString();
                string stepKey       = dsJob.Tables[0].Rows[0][WIP_JOB_FIELDS.FIELDS_STEP_KEY].ToString();
                string lotKey        = dsJob.Tables[0].Rows[0][WIP_JOB_FIELDS.FIELDS_LOT_KEY].ToString();
                string editor        = dsJob.Tables[0].Rows[0][WIP_JOB_FIELDS.FIELDS_EDITOR].ToString();
                string editTimeZone  = dsJob.Tables[0].Rows[0][WIP_JOB_FIELDS.FIELDS_EDIT_TIMEZONE].ToString();
                string strToUser     = dsJob.Tables[0].Rows[0][WIP_JOB_FIELDS.FIELDS_EDITOR].ToString();
                //获取自动出站的批次信息。
                ILotEngine lotEngine = RemotingServer.ServerObjFactory.Get <ILotEngine>();
                DataSet    dsLots    = lotEngine.GetLotInfo(lotKey);
                msg = ReturnMessageUtils.GetServerReturnMessage(dsLots);
                if (!string.IsNullOrEmpty(msg) ||
                    dsLots == null ||
                    dsLots.Tables.Count <= 0 ||
                    dsLots.Tables[0].Rows.Count <= 0)
                {
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, msg);
                    WipManagement.RecordErrorMessage(db, "批次出站异常:获取批次信息失败,", msg, strToUser, "EMSGOUT", editor, editTimeZone, lotKey, "LOT");
                    return(dsReturn);
                }
                DataRow drLot     = dsLots.Tables[0].Rows[0];
                int     stateFlag = Convert.ToInt32(drLot[POR_LOT_FIELDS.FIELD_STATE_FLAG]);
                if (stateFlag == 9 || stateFlag == 4)
                {
                    DataSet dsParams = new DataSet();
                    //获取下一个工步数据。
                    IEnterpriseEngine enterpriseEngine = RemotingServer.ServerObjFactory.Get <IEnterpriseEngine>();
                    DataSet           dsRouteNextStep  = enterpriseEngine.GetEnterpriseNextRouteAndStep(enterpriseKey, routeKey, stepKey);
                    msg = ReturnMessageUtils.GetServerReturnMessage(dsRouteNextStep);
                    if (!string.IsNullOrEmpty(msg))
                    {
                        ReturnMessageUtils.AddServerReturnMessage(dsReturn, msg);
                        WipManagement.RecordErrorMessage(db, "批次出站异常:获取下一工艺流程失败,", msg, strToUser, "EMSGOUT", editor, editTimeZone, lotKey, "LOT");
                        return(dsReturn);
                    }
                    string enterpriseName   = Convert.ToString(drLot[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ENTERPRISE_NAME]);
                    string routeName        = Convert.ToString(drLot[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_NAME]);
                    string stepName         = Convert.ToString(drLot[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME]);
                    string toEnterpriseKey  = enterpriseKey;
                    string toRouteKey       = routeKey;
                    string toStepKey        = stepKey;
                    string toEnterpriseName = enterpriseName;
                    string toRouteName      = routeName;
                    string toStepName       = stepName;
                    if (null != dsRouteNextStep &&
                        dsRouteNextStep.Tables.Count > 0 &&
                        dsRouteNextStep.Tables[0].Rows.Count > 0)
                    {
                        DataRow drRouteNextStep = dsRouteNextStep.Tables[0].Rows[0];
                        toEnterpriseKey  = Convert.ToString(drRouteNextStep[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY]);
                        toRouteKey       = Convert.ToString(drRouteNextStep[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_ROUTE_VER_KEY]);
                        toStepKey        = Convert.ToString(drRouteNextStep[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_KEY]);
                        toEnterpriseName = Convert.ToString(drRouteNextStep[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ENTERPRISE_NAME]);
                        toRouteName      = Convert.ToString(drRouteNextStep[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_NAME]);
                        toStepName       = Convert.ToString(drRouteNextStep[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME]);
                    }
                    //组织下一工步数据。
                    Hashtable htStepTransaction = new Hashtable();
                    htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, null);
                    htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE, editTimeZone);
                    htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_EDITOR, "SYSTEM");
                    htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY, enterpriseKey);
                    htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY, routeKey);
                    htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_STEP_KEY, stepKey);
                    htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_TO_ENTERPRISE_KEY, toEnterpriseKey);
                    htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_TO_ENTERPRISE_NAME, toEnterpriseName);
                    htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_TO_ROUTE_KEY, toRouteKey);
                    htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_TO_ROUTE_NAME, toRouteName);
                    htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_TO_STEP_KEY, toStepKey);
                    htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_TO_STEP_NAME, toStepName);
                    DataTable dtStepTransaction = CommonUtils.ParseToDataTable(htStepTransaction);
                    dtStepTransaction.TableName = WIP_STEP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME;
                    dsParams.Tables.Add(dtStepTransaction);
                    //组织操作数据。
                    string    shiftName     = RemotingServer.ServerObjFactory.Get <IShift>().GetShiftNameBySysdate();
                    string    shiftKey      = RemotingServer.ServerObjFactory.Get <IShift>().IsExistsShift(shiftName);
                    Hashtable htTransaction = new Hashtable();
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_PIECE_KEY, lotKey);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_TRACKOUT);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN, drLot[POR_LOT_FIELDS.FIELD_QUANTITY]);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT, drLot[POR_LOT_FIELDS.FIELD_QUANTITY]);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY, enterpriseKey);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_NAME, enterpriseName);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY, routeKey);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ROUTE_NAME, routeName);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY, stepKey);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STEP_NAME, stepName);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY, drLot[POR_LOT_FIELDS.FIELD_WORK_ORDER_KEY]);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY, shiftKey);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME, shiftName);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_STATE_FLAG, stateFlag);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_REWORK_FLAG, drLot[POR_LOT_FIELDS.FIELD_IS_REWORKED]);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPERATOR, editor);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER, "SYSTEM");
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY, drLot[POR_LOT_FIELDS.FIELD_CUR_PRODUCTION_LINE_KEY]);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE, drLot[POR_LOT_FIELDS.FIELD_OPR_LINE]);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EQUIPMENT_KEY, equipmentKey);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TO_STEP_KEY, toStepKey);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE_PRE, drLot[POR_LOT_FIELDS.FIELD_OPR_LINE]);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDC_INS_KEY, drLot[POR_LOT_FIELDS.FIELD_EDC_INS_KEY]);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY_COMMENT, string.Empty);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDITOR, "SYSTEM");
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, null);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY, editTimeZone);
                    htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TIME_STAMP, null);
                    DataTable dtTransaction = CommonUtils.ParseToDataTable(htTransaction);
                    dtTransaction.TableName = WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME;
                    dsParams.Tables.Add(dtTransaction);
                    //组织其他附加参数数据
                    Hashtable htMaindata  = new Hashtable();
                    string    lotEditTime = Convert.ToString(drLot[POR_LOT_FIELDS.FIELD_EDIT_TIME]);
                    htMaindata.Add(COMMON_FIELDS.FIELD_COMMON_EDIT_TIME, lotEditTime);
                    IRouteEngine routeEngine    = RemotingServer.ServerObjFactory.Get <IRouteEngine>();
                    DataSet      dsStepBaseData = routeEngine.GetStepBaseDataAndParamDataByKey(stepKey, 0);
                    msg = ReturnMessageUtils.GetServerReturnMessage(dsStepBaseData);
                    if (!string.IsNullOrEmpty(msg) ||
                        dsStepBaseData == null ||
                        dsStepBaseData.Tables.Count <= 0 ||
                        dsStepBaseData.Tables[0].Rows.Count <= 0)
                    {
                        ReturnMessageUtils.AddServerReturnMessage(dsReturn, msg);
                        WipManagement.RecordErrorMessage(db, "批次出站异常:获取当前工艺流程数据失败,", msg, strToUser, "EMSGOUT", editor, editTimeZone, lotKey, "LOT");
                        return(dsReturn);
                    }
                    string operationKey = Convert.ToString(dsStepBaseData.Tables[0].Rows[0][POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_OPERATION_VER_KEY]);
                    string duration     = Convert.ToString(dsStepBaseData.Tables[0].Rows[0][POR_ROUTE_STEP_FIELDS.FIELD_DURATION]);
                    string partNumber   = Convert.ToString(drLot[POR_LOT_FIELDS.FIELD_PART_NUMBER]);
                    htMaindata.Add(POR_ROUTE_OPERATION_VER_FIELDS.FIELD_ROUTE_OPERATION_VER_KEY, operationKey);
                    htMaindata.Add(POR_ROUTE_STEP_FIELDS.FIELD_DURATION, duration);
                    htMaindata.Add(POR_LOT_FIELDS.FIELD_LOT_NUMBER, drLot[POR_LOT_FIELDS.FIELD_LOT_NUMBER]);
                    htMaindata.Add(POR_LOT_FIELDS.FIELD_WORK_ORDER_NO, drLot[POR_LOT_FIELDS.FIELD_WORK_ORDER_NO]);
                    htMaindata.Add(POR_LOT_FIELDS.FIELD_PART_NUMBER, partNumber);
                    htMaindata.Add(ROUTE_OPERATION_ATTRIBUTE.IsShowSetNewRoute, false);
                    DataTable dtParams = CommonUtils.ParseToDataTable(htMaindata);
                    dtParams.TableName = TRANS_TABLES.TABLE_PARAM;
                    dsParams.Tables.Add(dtParams);
                    dsReturn = LotTrackOut(dsParams);
                    msg      = ReturnMessageUtils.GetServerReturnMessage(dsReturn);
                    if (string.IsNullOrEmpty(msg))
                    {
                        sql = @"UPDATE WIP_JOB SET JOB_STATUS=1 WHERE ROW_KEY='" + rowKey.PreventSQLInjection() + "'";
                        db.ExecuteNonQuery(CommandType.Text, sql);
                    }
                    else
                    {
                        WipManagement.RecordErrorMessage(db, "批次出站异常", msg, strToUser, "EMSGOUT", editor, editTimeZone, lotKey, "LOT");
                    }
                }
                else
                {
                    msg = "批次" + dsLots.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_LOT_NUMBER].ToString() + "抽检未完成";
                    WipManagement.RecordErrorMessage(db, "批次出站异常", msg, strToUser, "EMSGOUT", editor, editTimeZone, lotKey, "LOT");
                    //更新WIP_JOB表。
                    sql = string.Format(@"UPDATE WIP_JOB
                                        SET JOB_NEXTRUNTIME = DATEADD(mi,5,GETDATE()),JOB_RUNACCOUNT=JOB_RUNACCOUNT +1
                                        WHERE ROW_KEY = '{0}'", rowKey.PreventSQLInjection());
                    db.ExecuteNonQuery(CommandType.Text, sql);
                }
                if (msg.Length > 0)
                {
                    msg = string.Format("批次[{0}] 自动出站失败.\n\t原因:{1}", drLot[POR_LOT_FIELDS.FIELD_LOT_NUMBER], msg);
                }
                else
                {
                    msg = string.Format("批次[{0}] 自动出站成功.", drLot[POR_LOT_FIELDS.FIELD_LOT_NUMBER]);
                }
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, msg);
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("AutoTrackOut Error: " + ex.Message);
            }
            return(dsReturn);
        }
Example #2
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);
        }
Example #3
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);
            }
        }