예제 #1
0
        /// <summary>
        /// 终止批次操作,根据操作名称(<see cref="WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY"/>)区分。
        /// </summary>
        /// <remarks>
        /// 操作名称:<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_TERMINALLOT"/>。
        /// </remarks>
        /// <param name="dsParams">包含终止批次信息的数据集对象。</param>
        /// <returns>包含结果数据的数据集对象。</returns>
        public DataSet LotTerminal(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)               //存放操作数据
                    | dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME].Rows.Count == 0)
                {
                    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]);
                string    activity      = Convert.ToString(htTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]);
                //检查记录是否过期。防止重复修改。
                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);
                }
                LotTerminal(dsParams, dbTran);
                dbTran.Commit();
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Empty);
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("LotDefect Error: " + ex.Message);
                dbTran.Rollback();
            }
            finally
            {
                dbConn.Close();
            }
            return(dsReturn);
        }
예제 #2
0
        /// <summary>
        /// 执行拆分批次。
        /// </summary>
        /// <param name="dsParams">包含拆分批次数据的数据集。</param>
        /// <returns>包含执行结果的数据集。</returns>
        public DataSet SplitLotTransact(DataSet dsParams)
        {
            DateTime      startTime = DateTime.Now;
            DataSet       dsReturn = new DataSet();
            DbTransaction dbtran = null;
            DbConnection  dbconn = null;
            string        lotKey = "", strEditTime = "", strEditor = "";

            try
            {
                //Open Connection
                dbconn = db.CreateConnection();
                dbconn.Open();
                dbtran = dbconn.BeginTransaction();

                #region CheckExpired
                if (dsParams.Tables.Contains(TRANS_TABLES.TABLE_MAIN_DATA))
                {
                    DataTable dataTable = dsParams.Tables[TRANS_TABLES.TABLE_MAIN_DATA];
                    Hashtable hashData  = SolarViewer.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dataTable);
                    lotKey      = hashData[POR_LOT_FIELDS.FIELD_LOT_KEY].ToString();
                    strEditTime = hashData[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME].ToString();
                    strEditor   = hashData[WIP_TRANSACTION_FIELDS.FIELD_EDITOR].ToString();
                    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, strEditTime))
                    {
                        SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, COMMON_FIELDS.FIELD_COMMON_EDITTIME_EXP);
                        return(dsReturn);
                    }
                }
                #endregion

                SplitLotTransact(db, dbtran, dsParams, ref dsReturn);
                dbtran.Commit();
                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "");
            }
            catch (Exception ex)
            {
                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("SplitLotTransact Error: " + ex.Message);
                //Rollback Transaction
                dbtran.Rollback();
            }
            finally
            {
                //Close Connection
                dbconn.Close();
            }
            DateTime endTime = DateTime.Now;
            LogService.LogInfo("SplitLotTransact Time: " + (endTime - startTime).TotalMilliseconds.ToString());
            return(dsReturn);
        }
예제 #3
0
        /// <summary>
        /// 批次终结操作。
        /// </summary>
        /// <param name="dsParams">包含批次终结数据的数据集。</param>
        /// <returns>包含执行结果的数据集。</returns>
        public DataSet TerminalLot(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_PARAM))
                {
                    DataTable dtParams    = dsParams.Tables[TRANS_TABLES.TABLE_PARAM];
                    Hashtable htParams    = SolarViewer.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dtParams);
                    string    lotKey      = htParams[POR_LOT_FIELDS.FIELD_LOT_KEY].ToString();
                    string    strEditTime = htParams[POR_LOT_FIELDS.FIELD_EDIT_TIME].ToString();

                    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, strEditTime))
                    {
                        SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, COMMON_FIELDS.FIELD_COMMON_EDITTIME_EXP);
                        return(dsReturn);
                    }
                }
                #endregion

                WipManagement.TerminalLot(db, dbTran, dsParams);
                dbTran.Commit();
                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Empty);
            }
            catch (Exception ex)
            {
                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("TerminalLot Error: " + ex.Message);
                dbTran.Rollback();
            }
            finally
            {
                dbConn.Close();
                dbTran.Dispose();
                dbConn.Dispose();
            }

            DateTime endTime = DateTime.Now;
            LogService.LogInfo("TerminalLot Time: " + (endTime - startTime).TotalMilliseconds.ToString());
            return(dsReturn);
        }
예제 #4
0
        /// <summary>
        /// 更新排班计划班次数据。
        /// </summary>
        /// <param name="dsParams">包含排班计划班次数据的数据集对象。</param>
        /// <returns>包含执行结果的数据集对象。</returns>
        public DataSet UpdateShift(DataSet dsParams)
        {
            DataSet       dsReturn = new DataSet();
            DbConnection  dbConn   = null;
            DbTransaction dbTran   = null;

            if (dsParams.Tables.Contains(CAL_SHIFT.DATABASE_TABLE_NAME))
            {
                #region 检查记录是否过期。
                string oldEditTime = "", shiftKey = "";
                for (int i = 0; i < dsParams.Tables[0].Rows.Count; i++)
                {
                    if (dsParams.Tables[0].Rows[i][COMMON_FIELDS.FIELD_COMMON_UPDATE_NAME].ToString() == COMMON_FIELDS.FIELD_COMMON_EDIT_TIME)
                    {
                        oldEditTime = dsParams.Tables[0].Rows[i][COMMON_FIELDS.FIELD_COMMON_UPDATE_OLD_VALUE].ToString();
                        shiftKey    = dsParams.Tables[0].Rows[i][COMMON_FIELDS.FIELD_COMMON_UPDATE_KEY].ToString();
                        break;
                    }
                }
                KeyValuePair <string, string>         kvp           = new KeyValuePair <string, string>(CAL_SHIFT.FIELD_SHIFT_KEY, shiftKey);
                List <KeyValuePair <string, string> > listCondition = new List <KeyValuePair <string, string> >();
                listCondition.Add(kvp);
                if (UtilHelper.CheckRecordExpired(db, CAL_SHIFT.DATABASE_TABLE_NAME, listCondition, oldEditTime))
                {
                    FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, COMMON_FIELDS.FIELD_COMMON_EDITTIME_EXP);
                    return(dsReturn);
                }
                #endregion

                List <string> sqlCommandList = new List <string>();
                DatabaseTable.BuildUpdateSqlStatements(ref sqlCommandList,
                                                       new CAL_SHIFT(),
                                                       dsParams.Tables[CAL_SHIFT.DATABASE_TABLE_NAME],
                                                       new Dictionary <string, string>()
                {
                    { CAL_SHIFT.FIELD_EDIT_TIME, null },
                },
                                                       new List <string>()
                {
                    CAL_SHIFT.FIELD_SHIFT_KEY
                },
                                                       CAL_SHIFT.FIELD_SHIFT_KEY);
                if (sqlCommandList.Count > 0)
                {
                    dbConn = db.CreateConnection();
                    dbConn.Open();
                    //Create Transaction
                    dbTran = dbConn.BeginTransaction();
                    try
                    {
                        foreach (string sql in sqlCommandList)
                        {
                            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                        }
                        dbTran.Commit();
                        FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "");
                    }
                    catch (Exception ex)
                    {
                        dbTran.Rollback();
                        FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                        LogService.LogError("UpdateShift Error: " + ex.Message);
                    }
                    finally
                    {
                        dbTran.Dispose();
                        dbConn.Close();
                        dbConn.Dispose();
                    }
                }
            }
            else
            {
                FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "${res:FanHai.Hemera.Modules.EMS.CalShiftEngine.TableIsNotExist}");
            }
            return(dsReturn);
        }
예제 #5
0
        /// <summary>
        /// 入库检验作业。
        /// </summary>
        /// <param name="dsParams"></param>
        /// <returns></returns>
        public DataSet LotToWarehouseCheck(DataSet dsParams)
        {
            DataSet dsReturn = new DataSet();

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

            try
            {
                DataTable dtParams         = dsParams.Tables[TRANS_TABLES.TABLE_PARAM];
                DataTable dtWipConsignment = dsParams.Tables[WIP_CONSIGNMENT_FIELDS.DATABASE_TABLE_NAME];
                DataTable dtLots           = dsParams.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME];
                Hashtable htParams         = CommonUtils.ConvertToHashtable(dtParams);
                string    editor           = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]); //编辑人
                string    timeZone         = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]); //编辑时区

                using (DbConnection dbConn = db.CreateConnection())
                {
                    dbConn.Open();
                    using (DbTransaction dbTran = dbConn.BeginTransaction())
                    {
                        WIP_CONSIGNMENT_FIELDS consigmentFields = new WIP_CONSIGNMENT_FIELDS();

                        foreach (DataRow dr in dtWipConsignment.Rows)
                        {
                            #region 更新包装表。
                            int    csDataGroup = Convert.ToInt32(dr[WIP_CONSIGNMENT_FIELDS.FIELDS_CS_DATA_GROUP]);
                            string palletNo    = Convert.ToString(dr[WIP_CONSIGNMENT_FIELDS.FIELDS_VIRTUAL_PALLET_NO]);
                            string palletKey   = Convert.ToString(dr[WIP_CONSIGNMENT_FIELDS.FIELDS_CONSIGNMENT_KEY]);
                            //托盘主键为空。给出提示。
                            if (string.IsNullOrEmpty(palletKey))
                            {
                                ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Format("托盘记录{0}不存在,请检查。", palletNo));
                                return(dsReturn);
                            }
                            //检查记录是否过期。防止重复修改。
                            KeyValuePair <string, string>         kvp           = new KeyValuePair <string, string>(WIP_CONSIGNMENT_FIELDS.FIELDS_CONSIGNMENT_KEY, palletKey);
                            List <KeyValuePair <string, string> > listCondition = new List <KeyValuePair <string, string> >();
                            listCondition.Add(kvp);
                            string opEditTime = Convert.ToString(dr[WIP_CONSIGNMENT_FIELDS.FIELDS_EDIT_TIME]);
                            //如果记录过期,当前编辑时间<数据库中的记录编辑时间。结束方法执行。
                            if (UtilHelper.CheckRecordExpired(db, WIP_CONSIGNMENT_FIELDS.DATABASE_TABLE_NAME, listCondition, opEditTime))
                            {
                                ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Format("托盘{0}信息已过期,请确认。", palletNo));
                                return(dsReturn);
                            }
                            Hashtable hashTable = CommonUtils.ConvertRowToHashtable(dr);
                            hashTable.Remove(WIP_CONSIGNMENT_FIELDS.FIELDS_CONSIGNMENT_KEY);
                            hashTable[WIP_CONSIGNMENT_FIELDS.FIELDS_EDIT_TIME]     = null;
                            hashTable[WIP_CONSIGNMENT_FIELDS.FIELDS_CS_DATA_GROUP] = 2;
                            WhereConditions wc  = new WhereConditions(WIP_CONSIGNMENT_FIELDS.FIELDS_CONSIGNMENT_KEY, palletKey);
                            string          sql = DatabaseTable.BuildUpdateSqlStatement(consigmentFields, hashTable, wc);
                            db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                            #endregion

                            var lnq = from item in dtLots.AsEnumerable()
                                      where Convert.ToString(item[POR_LOT_FIELDS.FIELD_PALLET_NO]) == palletNo
                                      orderby Convert.ToInt32(item[WIP_CONSIGNMENT_FIELDS.FIELDS_SEQ])
                                      select item;

                            Hashtable htStepTransaction = null;//存储下一工步数据。
                            foreach (DataRow drLot in lnq)
                            {
                                string lotKey        = Convert.ToString(drLot[POR_LOT_FIELDS.FIELD_LOT_KEY]);
                                string lotNumber     = Convert.ToString(drLot[POR_LOT_FIELDS.FIELD_LOT_NUMBER]);
                                string lotPalletNo   = Convert.ToString(drLot[POR_LOT_FIELDS.FIELD_PALLET_NO]);
                                string lotPalletTime = Convert.ToString(drLot[POR_LOT_FIELDS.FIELD_PALLET_TIME]);

                                //检查记录是否过期。防止重复修改。
                                KeyValuePair <string, string>         kvpLot          = new KeyValuePair <string, string>(POR_LOT_FIELDS.FIELD_LOT_KEY, lotKey);
                                List <KeyValuePair <string, string> > lstLotCondition = new List <KeyValuePair <string, string> >();
                                lstLotCondition.Add(kvpLot);
                                string opLotEditTime = Convert.ToString(drLot[POR_LOT_FIELDS.FIELD_EDIT_TIME]);
                                //如果记录过期,当前编辑时间<数据库中的记录编辑时间。结束方法执行。
                                if (UtilHelper.CheckRecordExpired(db, POR_LOT_FIELDS.DATABASE_TABLE_NAME, lstLotCondition, opLotEditTime))
                                {
                                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Format("组件{0}信息已过期,请确认。", lotNumber));
                                    return(dsReturn);
                                }

                                #region 批次进站
                                //获取批次数据
                                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];
                                int       stateFlag = Convert.ToInt32(drLotInfo[POR_LOT_FIELDS.FIELD_STATE_FLAG]);
                                //如果批次没有进站,先进站。
                                if (stateFlag == 0)
                                {
                                    PackageLotTrackIn(dbTran, drLotInfo, htParams);
                                    stateFlag = 9;
                                }
                                #endregion

                                #region 批次过站
                                //重新获取批次数据。
                                if (stateFlag > 0 && stateFlag <= 9)
                                {
                                    string enterpriseKey  = Convert.ToString(drLotInfo[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY]);
                                    string routeKey       = Convert.ToString(drLotInfo[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]);
                                    string stepKey        = Convert.ToString(drLotInfo[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]);
                                    string enterpriseName = Convert.ToString(drLotInfo[POR_ROUTE_ENTERPRISE_VER_FIELDS.FIELD_ENTERPRISE_NAME]);
                                    string routeName      = Convert.ToString(drLotInfo[POR_ROUTE_ROUTE_VER_FIELDS.FIELD_ROUTE_NAME]);
                                    string stepName       = Convert.ToString(drLotInfo[POR_ROUTE_STEP_FIELDS.FIELD_ROUTE_STEP_NAME]);
                                    //如果下一个工步主键为空,则获取下一个工步数据。每包抓第一块组件的下一工步为标准工步。从而统一包的工艺流程。
                                    if (htStepTransaction == null)
                                    {
                                        IEnterpriseEngine enterpriseEngine = RemotingServer.ServerObjFactory.Get <IEnterpriseEngine>();
                                        DataSet           dsRouteNextStep  = enterpriseEngine.GetEnterpriseNextRouteAndStep(enterpriseKey, routeKey, stepKey);
                                        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]);
                                        }
                                        htStepTransaction = new Hashtable();
                                        htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_EDIT_TIME, null);
                                        htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE, timeZone);
                                        htStepTransaction.Add(WIP_STEP_TRANSACTION_FIELDS.FIELD_EDITOR, editor);
                                        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);
                                        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);
                                    }
                                    else
                                    {
                                        htStepTransaction[WIP_STEP_TRANSACTION_FIELDS.FIELD_ENTERPRISE_KEY] = enterpriseKey;
                                        htStepTransaction[WIP_STEP_TRANSACTION_FIELDS.FIELD_ROUTE_KEY]      = routeKey;
                                        htStepTransaction[WIP_STEP_TRANSACTION_FIELDS.FIELD_STEP_KEY]       = stepKey;
                                    }

                                    DataTable dtStepTransaction = CommonUtils.ParseToDataTable(htStepTransaction);
                                    dtStepTransaction.TableName = WIP_STEP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME;
                                    string nextStepKey = Convert.ToString(htStepTransaction[WIP_STEP_TRANSACTION_FIELDS.FIELD_TO_STEP_KEY]);
                                    bool   isFinish    = stepKey == nextStepKey; //最后一个工步,则结束批次。
                                    PackageLotTrackOut(dbTran, drLotInfo, dtStepTransaction, htParams, isFinish);
                                }
                                #endregion
                            }
                        }
                        dbTran.Commit();
                    }
                    dbConn.Close();
                }
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("LotOperationEngine.LotToWarehouseCheck Error: " + ex.Message);
            }
            return(dsReturn);
        }
예제 #6
0
        /// <summary>
        /// 批次释放操作。
        /// </summary>
        /// <remarks>
        /// 操作名称:<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_RELEASE"/>。
        /// </remarks>
        /// <param name="dsParams">包含批次释放信息的数据集对象。</param>
        /// <returns>包含结果数据的数据集对象。</returns>
        public DataSet LotRelease(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(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        //暂停信息不能为空
                    )
                {
                    dbTran.Rollback();
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "传入参数不正确,请检查。");
                    return(dsReturn);
                }
                DataTable dtTransaction = dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME];   //存放操作数据
                DataTable dtHold        = dsParams.Tables[WIP_HOLD_RELEASE_FIELDS.DATABASE_TABLE_NAME];  //存放批次暂停原因明细数据
                //检查是否存在重复的批次主键。
                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);
                    }
                }
                //释放批次。
                LotRelease(dsParams, dbTran);
                dbTran.Commit();
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Empty);
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("LotRelease Error: " + ex.Message);
                dbTran.Rollback();
            }
            finally
            {
                dbConn.Close();
            }
            return(dsReturn);
        }
예제 #7
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);
        }
예제 #8
0
        /// <summary>
        /// 将线边仓中的批次进行合并。
        /// </summary>
        /// <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>
        /// <returns>
        /// 包含批次合并执行结果的数据集对象。
        /// </returns>
        public DataSet MergeLotInStore(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();
                //组织合批数据
                if (dsParams.Tables.Count > 0)
                {
                    List <KeyValuePair <string, string> > listCondition = new List <KeyValuePair <string, string> >();
                    KeyValuePair <string, string>         kvp           = new KeyValuePair <string, string>();
                    //存放待合并的批次返工或退库数据的数据表存在。
                    if (dsParams.Tables.Contains(TRANS_TABLES.TABLE_MAIN_DATA))
                    {
                        DataTable dataTable = dsParams.Tables[TRANS_TABLES.TABLE_MAIN_DATA];
                        Hashtable hashData  = SolarViewer.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dataTable);
                        kvp = new KeyValuePair <string, string>(WST_STORE_MAT_FIELDS.FIELD_ROW_KEY, hashData[WST_STORE_MAT_FIELDS.FIELD_ROW_KEY].ToString());
                        listCondition.Add(kvp);
                        //检查记录是否过期。
                        if (UtilHelper.CheckRecordExpired(db, WST_STORE_MAT_FIELDS.DATABASE_TABLE_NAME, listCondition, hashData[WST_STORE_MAT_FIELDS.FIELD_EDIT_TIME].ToString()))
                        {
                            SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, COMMON_FIELDS.FIELD_COMMON_EDITTIME_EXP);
                            return(dsReturn);
                        }
                    }

                    if (dsParams.Tables.Contains(BASE_PARAMETER_FIELDS.DATABASE_TABLE_NAME))
                    {
                        listCondition = new List <KeyValuePair <string, string> >();
                        DataTable parameterdatatable = dsParams.Tables[BASE_PARAMETER_FIELDS.DATABASE_TABLE_NAME];

                        for (int i = 0; i < parameterdatatable.Rows.Count; i++)
                        {
                            kvp = new KeyValuePair <string, string>(WST_STORE_MAT_FIELDS.FIELD_ROW_KEY, parameterdatatable.Rows[i][WST_STORE_MAT_FIELDS.FIELD_ROW_KEY].ToString());
                            listCondition.Add(kvp);
                            //检查记录是否过期。
                            if (UtilHelper.CheckRecordExpired(db, WST_STORE_MAT_FIELDS.DATABASE_TABLE_NAME, listCondition, parameterdatatable.Rows[i][WST_STORE_MAT_FIELDS.FIELD_EDIT_TIME].ToString()))
                            {
                                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, COMMON_FIELDS.FIELD_COMMON_EDITTIME_EXP);
                                return(dsReturn);
                            }
                        }
                    }
                }
                MergeLotInStore(db, dbtran, dsParams);
                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "");
                dbtran.Commit();
            }
            catch (Exception ex)
            {
                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("MergeLotInStore Error: " + ex.Message);
                dbtran.Rollback();
            }
            finally
            {
                dbconn.Close();
            }

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

            return(dsReturn);
        }
예제 #9
0
        /// <summary>
        /// 执行合并批次操作。
        /// </summary>
        /// <param name="dsParams">包含合并批次数据的数据集。</param>
        /// <returns>包含执行结果的数据集。</returns>
        public DataSet MergeLot(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();
                //check edittime
                if (dsParams.Tables.Count > 0)
                {
                    //检查记录是否过期。
                    List <KeyValuePair <string, string> > listCondition = new List <KeyValuePair <string, string> >();
                    KeyValuePair <string, string>         kvp           = new KeyValuePair <string, string> ();
                    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);
                        kvp = new KeyValuePair <string, string>(POR_LOT_FIELDS.FIELD_LOT_KEY, htParams[POR_LOT_FIELDS.FIELD_LOT_KEY].ToString());
                        listCondition.Add(kvp);
                        if (UtilHelper.CheckRecordExpired(db, POR_LOT_FIELDS.DATABASE_TABLE_NAME, listCondition, htParams[POR_LOT_FIELDS.FIELD_EDIT_TIME].ToString()))
                        {
                            SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, COMMON_FIELDS.FIELD_COMMON_EDITTIME_EXP);
                            return(dsReturn);
                        }
                    }
                    //检查记录是否过期。
                    if (dsParams.Tables.Contains(BASE_PARAMETER_FIELDS.DATABASE_TABLE_NAME))
                    {
                        listCondition = new List <KeyValuePair <string, string> >();
                        DataTable parameterdatatable = dsParams.Tables[BASE_PARAMETER_FIELDS.DATABASE_TABLE_NAME];

                        for (int i = 0; i < parameterdatatable.Rows.Count; i++)
                        {
                            kvp = new KeyValuePair <string, string>(POR_LOT_FIELDS.FIELD_LOT_KEY, parameterdatatable.Rows[i]["LOT_KEY"].ToString());
                            listCondition.Add(kvp);
                            if (UtilHelper.CheckRecordExpired(db, POR_LOT_FIELDS.DATABASE_TABLE_NAME, listCondition, parameterdatatable.Rows[i]["EDIT_TIME"].ToString()))
                            {
                                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, COMMON_FIELDS.FIELD_COMMON_EDITTIME_EXP);
                                return(dsReturn);
                            }
                        }
                    }
                }
                MergeLot(db, dbTran, dsParams);
                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "");
                dbTran.Commit();
            }
            catch (Exception ex)
            {
                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("MergeLot Error: " + ex.Message);
                dbTran.Rollback();
            }
            finally
            {
                dbConn.Close();
                dbTran.Dispose();
                dbConn.Dispose();
            }
            DateTime endTime = DateTime.Now;

            LogService.LogInfo("MergeLot Time: " + (endTime - startTime).TotalMilliseconds.ToString());
            return(dsReturn);
        }
예제 #10
0
        /// <summary>
        /// 执行批次出站或仅采集批次报废数量。
        /// </summary>
        /// <param name="dataset">包含批次出站信息的数据集对象。
        /// 必须包含名称为<see cref=" TRANS_TABLES.TABLE_PARAM"/>的数据表,用于存储批次及批出站主信息的数据。
        /// 包含名称为<see cref=" WIP_SCRAP_FIELDS.DATABASE_TABLE_NAME"/>的数据表(可选),用于存储批次报废的数据。
        /// 包含名称为<see cref="WST_STORE_MAT_FIELDS.DATABASE_TABLE_NAME"/>的数据表(可选),用于存储批次返工或退库的数据。
        /// 包含名称为<see cref="EMS_EQUIPMENTS_FIELDS.DATABASE_TABLE_NAME"/>的数据表(可选),用于存储设备数据。</param>
        /// <returns>
        /// 包含方法执行结果的数据集。
        /// </returns>
        public DataSet TrackOutLot(DataSet dsParams)
        {
            System.DateTime startTime = System.DateTime.Now;
            DataSet         dsReturn  = new DataSet();
            DbConnection    dbConn    = null;
            DbTransaction   dbtran    = null;
            DataTable       dtParams  = new DataTable();
            Hashtable       htParams  = new Hashtable();
            //string module = "";
            int    quantityOut = 0;
            int    quantityToMerge = 0;
            string lotKeyForMerge = string.Empty;
            string lotKey = string.Empty;
            string workOrderKey = string.Empty, lineKey = "", editor = "", opUser = "", editTime = string.Empty;
            int    workOrderStep = 0;                                         //工单序号
            string isAutoTrackIn = string.Empty, oprLine = string.Empty;      //是否自动进站,操作线别
            string shiftName       = string.Empty;                            //班次名称
            bool   isFinished      = false;                                   //批次完成状态。
            string toStepKey       = string.Empty;                            //工步主键
            string toRouteKey      = string.Empty;                            //工艺流程主键
            string toEnterpriseKey = string.Empty;                            //工艺流程组主键
            string editTimeZone    = string.Empty;                            //编辑时间时区
            string operateCompName = string.Empty;                            //操作计算机名称
            string shiftKey        = string.Empty;                            //班次主键
            string stepKey         = string.Empty;                            //当前工步主键

            try
            {
                dbConn = db.CreateConnection();
                dbConn.Open();
                //Create Transaction
                dbtran = dbConn.BeginTransaction();

                if (dsParams.Tables.Contains(TRANS_TABLES.TABLE_PARAM))
                {
                    dtParams        = dsParams.Tables[TRANS_TABLES.TABLE_PARAM];
                    htParams        = SolarViewer.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dtParams);
                    lotKey          = Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_LOT_KEY]);
                    lotKeyForMerge  = lotKey;
                    workOrderKey    = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY]);
                    lineKey         = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY]);
                    oprLine         = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE]);
                    editor          = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);
                    opUser          = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_OPERATOR]);
                    shiftName       = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME]);
                    editTime        = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME]);
                    toStepKey       = Convert.ToString(htParams[WIP_FIELDS.FIELDS_TO_STEP_VER_KEY]);
                    toRouteKey      = Convert.ToString(htParams[WIP_FIELDS.FIELDS_TO_ROUTE_VER_KEY]);
                    toEnterpriseKey = Convert.ToString(htParams[WIP_FIELDS.FIELDS_TO_ENTERPRISE_VER_KEY]);
                    //module = Convert.ToString(htParams[POR_LOT_FIELDS.FIELD_MODULE]);
                    editTimeZone    = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY]);
                    operateCompName = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER]);
                    shiftKey        = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY]);
                    stepKey         = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY]);
                    //如果哈希表中包含最后一步的字段。表示该工步为最后一个工步,设置批次完成状态为true
                    if (htParams.ContainsKey("LAST_STEP"))
                    {
                        isFinished = Boolean.Parse(htParams["LAST_STEP"].ToString());
                    }
                    quantityOut     = Convert.ToInt32(htParams[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT]);
                    quantityToMerge = quantityOut;
                }

                #region 检查记录是否过期。防止重复修改。
                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, editTime))
                {
                    SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, COMMON_FIELDS.FIELD_COMMON_EDITTIME_EXP);
                    return(dsReturn);
                }
                #endregion

                //如果数据集中包含批次报废数据表。
                if (dsParams.Tables.Contains(WIP_SCRAP_FIELDS.DATABASE_TABLE_NAME))
                {
                    WipManagement.SetLossBonus(db, dbtran, dsParams);
                }
                //如果数据集中包含批次返工或退库的数据表。
                if (dsParams.Tables.Contains(WST_STORE_MAT_FIELDS.DATABASE_TABLE_NAME))
                {
                    SetDefect(dbtran, dsParams);
                }
                //插入批次出站的记录信息。
                WipManagement.TrackOutOrReworkLot(db, dbtran, dsParams, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_TRACKOUT);
                //更新批次出站和设备关联的记录信息。
                if (dsParams.Tables.Contains(EMS_EQUIPMENTS_FIELDS.DATABASE_TABLE_NAME))
                {
                    TrackOutOrReworkForEquipment(dbtran, dsParams);
                }

                #region 确定是否自动分批或自动合批
                //如果不是完成状态且数量>0
                if (isFinished == false && quantityOut > 0)
                {
                    int    maxBoxQuantity = -1;
                    string autoMerge      = "";
                    string autoSplit      = "";
                    //获取下一工步的自定义属性。
                    DataSet dsStepUda = GetStepUda(toStepKey);
                    if (dsStepUda.Tables[0].Rows.Count > 0)
                    {
                        //获取下一工步的自定义属性成功。
                        for (int i = 0; i < dsStepUda.Tables[0].Rows.Count; i++)
                        {
                            string szStepUdaName  = dsStepUda.Tables[0].Rows[i][POR_ROUTE_STEP_ATTR_FIELDS.FIELD_ATTRIBUTE_NAME].ToString();
                            string szStepUdaValue = dsStepUda.Tables[0].Rows[i][POR_ROUTE_STEP_ATTR_FIELDS.FIELD_ATTRIBUTE_VALUE].ToString();
                            //箱的最大数量
                            if (szStepUdaName == "MaxBoxQuantity")
                            {
                                maxBoxQuantity = Convert.ToInt32(szStepUdaValue);
                            }
                            //自动合批
                            if (szStepUdaName == "AutoMerge")
                            {
                                autoMerge = szStepUdaValue;
                            }
                            //自动分批
                            if (szStepUdaName == "AutoSplit")
                            {
                                autoSplit = szStepUdaValue;
                            }
                            //自动出站
                            if (szStepUdaName == "AutoTrackIn")
                            {
                                isAutoTrackIn = szStepUdaValue;
                            }
                        }
                        //确定自动分批
                        if (autoSplit.ToLower() == "true")
                        {
                            //箱最大数量
                            if (maxBoxQuantity == -1)
                            {
                                throw new Exception("${res:SolarViewer.Hemera.Addins.WIP.AutoSplit.Exception}");
                            }
                            else if (quantityOut > maxBoxQuantity)//出站数量>箱最大数量。
                            {
                                #region splitLot
                                #region MainDataTable
                                if (htParams.Contains(POR_LOT_FIELDS.FIELD_QUANTITY))
                                {
                                    htParams.Remove(POR_LOT_FIELDS.FIELD_QUANTITY);
                                }
                                htParams.Add(POR_LOT_FIELDS.FIELD_QUANTITY, maxBoxQuantity.ToString());
                                htParams[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN]      = quantityOut;
                                htParams[POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY] = toEnterpriseKey;
                                htParams[POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]        = toRouteKey;
                                htParams[POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]         = toStepKey;
                                htParams.Add(POR_LOT_FIELDS.FIELD_STATE_FLAG, "0");
                                if (workOrderStep != 0)
                                {
                                    htParams.Add(COMMON_FIELDS.FIELD_WORK_ORDER_STEP, workOrderStep);
                                }
                                DataTable splitTable = SolarViewer.Hemera.Share.Common.CommonUtils.ParseToDataTable(htParams);
                                splitTable.TableName = TRANS_TABLES.TABLE_MAIN_DATA;
                                DataSet splitDS = new DataSet();
                                splitDS.Tables.Add(splitTable);
                                #endregion
                                int remainderQty = quantityOut - maxBoxQuantity;
                                #region ChildTable
                                DataTable childTable = new DataTable();
                                //childTable.Columns.Add("LOT_NUMBER", Type.GetType("System.String"));
                                childTable.Columns.Add("QUANTITY", Type.GetType("System.String"));
                                childTable.Columns.Add("SPLIT_SEQ", Type.GetType("System.String"));
                                childTable.Columns.Add("LOT_KEY", Type.GetType("System.String"));
                                //string childLotNumber = "";
                                string lastChildLotKey = "";
                                int    i = 0;
                                //剩余数量-箱最大数量>0,继续分批
                                while ((remainderQty - maxBoxQuantity) >= 0)
                                {
                                    #region GenerateChildLotNumber
                                    i++;
                                    #endregion
                                    //childTable.Rows.Add(childLotNumber, maxBoxQuantity.ToString(), i.ToString("00"), Utils.GenerateNewKey(0));
                                    childTable.Rows.Add(maxBoxQuantity.ToString(), i.ToString("00"), UtilHelper.GenerateNewKey(0));
                                    remainderQty = remainderQty - maxBoxQuantity;
                                }
                                //如果剩余数量>0,作为最后一批。
                                if (remainderQty > 0)
                                {
                                    i++;
                                    lastChildLotKey = UtilHelper.GenerateNewKey(0);
                                    childTable.Rows.Add(remainderQty.ToString(), i.ToString("00"), lastChildLotKey);
                                }
                                childTable.TableName = BASE_PARAMETER_FIELDS.DATABASE_TABLE_NAME;
                                splitDS.Tables.Add(childTable);
                                #endregion
                                //Excute Split
                                //SplitLot(db, dbtran, splitDS);
                                DataSet childLotReturn = new DataSet();
                                //执行分批操作。
                                SplitLotTransact(db, dbtran, splitDS, ref childLotReturn);
                                quantityToMerge = remainderQty;
                                lotKeyForMerge  = lastChildLotKey;
                                #endregion
                            }
                        }
                        #region AutoMerge
                        //如果自动合批。
                        if (autoMerge.ToLower() == "true")
                        {
                            //执行自动合批操作。
                            AutoMerge(db, dbtran, lotKeyForMerge, workOrderKey, toStepKey, lineKey, quantityToMerge.ToString(), maxBoxQuantity, 0, editor, false, oprLine, shiftName);
                        }
                        #endregion
                    }
                }
                #endregion

                //检查是否需要进行锁定。
                int nHoldCount = 0;
                if (isFinished == false)
                {
                    nHoldCount = CheckAndUpdateFutureHold(dbtran, lotKey, stepKey, shiftName, shiftKey, editor,
                                                          operateCompName, editTimeZone, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_TRACKOUT);
                }
                dbtran.Commit();
                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "");

                #region AutoTrackIn 确定是否自动进站。
                //如果自动进站
                if (isFinished == false && isAutoTrackIn.ToLower() == "true" && nHoldCount == 0)
                {
                    //执行自动进站作业。
                    AutoTrackIn(lotKey, string.Empty, shiftName);
                }
                #endregion
            }
            catch (Exception ex)
            {
                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("TrackOutLot Error: " + ex.Message);
                dbtran.Rollback();
            }
            finally
            {
                dbConn.Close();
            }
            //记录操作时间 记录。
            System.DateTime endTime = System.DateTime.Now;
            LogService.LogInfo("TrackOut Lot Time: " + (endTime - startTime).TotalMilliseconds.ToString());

            return(dsReturn);
        }
예제 #11
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);
        }
예제 #12
0
        /// <summary>
        /// 托盘入库作业。
        /// </summary>
        /// <param name="dsParams">包含托盘入库信息的数据集对象。</param>
        /// <returns>包含结果数据的数据集对象。</returns>
        public DataSet PalletToWarehouse(DataSet dsParams)
        {
            DataSet dsReturn = new DataSet();

            try
            {
                //参数数据。
                if (dsParams == null ||
                    !dsParams.Tables.Contains(TRANS_TABLES.TABLE_PARAM) ||                              //存放附加参数数据
                    !dsParams.Tables.Contains(WIP_CONSIGNMENT_FIELDS.DATABASE_TABLE_NAME)               //存放托盘数据
                    )
                {
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "传入参数不正确,请检查。");
                    return(dsReturn);
                }
                DataTable dtParams     = dsParams.Tables[TRANS_TABLES.TABLE_PARAM];                    //存放附加参数数据
                DataTable dtPalletInfo = dsParams.Tables[WIP_CONSIGNMENT_FIELDS.DATABASE_TABLE_NAME];  //存放托盘数据
                //检查是否存在重复的托盘记录。
                var lnq = from item in dtPalletInfo.AsEnumerable()
                          group item by item[WIP_CONSIGNMENT_FIELDS.FIELDS_CONSIGNMENT_KEY] into g
                          where g.Count() > 1
                          select g.Count();

                if (lnq.Count() > 0)
                {
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "存在重复托盘记录,请检查。");
                    return(dsReturn);
                }
                Hashtable htParams = CommonUtils.ConvertToHashtable(dtParams);
                string    editor   = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);    //编辑人
                string    timeZone = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_EDITOR]);    //编辑时区
                //验证托盘信息是否过期,防止重复修改。
                foreach (DataRow drPallet in dtPalletInfo.Rows)
                {
                    string opEditTime = Convert.ToString(drPallet[WIP_CONSIGNMENT_FIELDS.FIELDS_EDIT_TIME]);       //操作前编辑时间
                    string palletKey  = Convert.ToString(drPallet[WIP_CONSIGNMENT_FIELDS.FIELDS_CONSIGNMENT_KEY]); //托盘主键
                    //检查记录是否过期。防止重复修改。
                    KeyValuePair <string, string>         kvp           = new KeyValuePair <string, string>(WIP_CONSIGNMENT_FIELDS.FIELDS_CONSIGNMENT_KEY, palletKey);
                    List <KeyValuePair <string, string> > listCondition = new List <KeyValuePair <string, string> >();
                    listCondition.Add(kvp);
                    //如果记录过期,当前编辑时间<数据库中的记录编辑时间。结束方法执行。
                    if (UtilHelper.CheckRecordExpired(db, WIP_CONSIGNMENT_FIELDS.DATABASE_TABLE_NAME, listCondition, opEditTime))
                    {
                        ReturnMessageUtils.AddServerReturnMessage(dsReturn, "信息已过期,请关闭该界面后重试。");
                        return(dsReturn);
                    }
                }
                //入库采集的参数数据。
                DataTable dtOperationParam = null;
                if (dsParams.Tables.Contains(WIP_PARAM_FIELDS.DATABASE_TABLE_NAME))
                {
                    dtOperationParam = dsParams.Tables[WIP_PARAM_FIELDS.DATABASE_TABLE_NAME];
                }
                StringBuilder sbMsg = new StringBuilder();
                using (DbConnection dbConn = db.CreateConnection())
                {
                    dbConn.Open();
                    //循环托盘
                    foreach (DataRow drPallet in dtPalletInfo.Rows)
                    {
                        string palletNo  = Convert.ToString(drPallet[WIP_CONSIGNMENT_FIELDS.FIELDS_VIRTUAL_PALLET_NO]);
                        string palletKey = Convert.ToString(drPallet[WIP_CONSIGNMENT_FIELDS.FIELDS_CONSIGNMENT_KEY]); //托盘主键
                        //根据托盘号获取托盘中当前的批次信息。
                        DataSet dsLotInfo = this.GetPalletLotInfo(null, palletNo);
                        using (DbTransaction dbTran = dbConn.BeginTransaction())
                        {
                            try
                            {
                                if (dsLotInfo != null && dsLotInfo.Tables.Count > 0)
                                {
                                    DataTable dtLotInfo = dsLotInfo.Tables[0];
                                    //循环托盘中的批次信息
                                    foreach (DataRow drLotInfo in dtLotInfo.Rows)
                                    {
                                        int stateFlag = Convert.ToInt32(drLotInfo[POR_LOT_FIELDS.FIELD_STATE_FLAG]);
                                        if (stateFlag == 0)
                                        {
                                            //批次进站
                                            LotToWarehouseTrackIn(dbTran, drLotInfo, htParams);
                                        }
                                        if (stateFlag <= 9)
                                        {
                                            //批次出站
                                            LotToWarehouseTrackOut(dbTran, drLotInfo, htParams);
                                        }
                                        //批次入库
                                        LotToWarehouse(dbTran, drLotInfo, dtOperationParam, htParams);
                                    }//结束循环
                                }
                                //更新托盘信息为入库。
                                StringBuilder sbUpdateSql = new StringBuilder();
                                sbUpdateSql.AppendFormat(@"UPDATE WIP_CONSIGNMENT 
                                                           SET CS_DATA_GROUP=3,EDITOR='{1}',EDIT_TIME=GETDATE(),TO_WH='{1}',TO_WH_TIME=GETDATE()
                                                           WHERE CONSIGNMENT_KEY='{0}'",
                                                         palletKey.PreventSQLInjection(),
                                                         editor.PreventSQLInjection());
                                db.ExecuteNonQuery(dbTran, CommandType.Text, sbUpdateSql.ToString());
                                dbTran.Commit();
                            }
                            catch (Exception ex)
                            {
                                sbMsg.AppendFormat("托号:{0}入库失败,请重新入库,失败原因:{1}。\r\n", palletNo, ex.Message);
                                dbTran.Rollback();
                            }
                        }
                    }
                    dbConn.Close();
                }
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, sbMsg.ToString());
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("PalletToWarehouse Error: " + ex.Message);
            }
            return(dsReturn);
        }
예제 #13
0
        /// <summary>
        /// 更新线上仓数据。
        /// </summary>
        /// <param name="dsParams">包含线上仓数据的数据集对象。</param>
        /// <returns>包含执行结果的数据集对象。</returns>
        public DataSet UpdateStore(DataSet dsParams)
        {
            DataSet       dsReturn = new DataSet();
            DbConnection  dbconn   = null;
            DbTransaction dbtran   = null;

            if (null != dsParams && dsParams.Tables.Contains(WST_STORE_FIELDS.DATABASE_TABLE_NAME))
            {
                DataTable dtParams = dsParams.Tables[WST_STORE_FIELDS.DATABASE_TABLE_NAME];
                string    oldEditTime = "", storeKey = "";
                for (int i = 0; i < dsParams.Tables[0].Rows.Count; i++)
                {
                    if (dsParams.Tables[0].Rows[i][COMMON_FIELDS.FIELD_COMMON_UPDATE_NAME].ToString() == COMMON_FIELDS.FIELD_COMMON_EDIT_TIME)
                    {
                        oldEditTime = dsParams.Tables[0].Rows[i][COMMON_FIELDS.FIELD_COMMON_UPDATE_OLD_VALUE].ToString();
                        storeKey    = dsParams.Tables[0].Rows[i][COMMON_FIELDS.FIELD_COMMON_UPDATE_KEY].ToString();
                        break;
                    }
                }

                #region 检查记录是否过期。
                KeyValuePair <string, string>         kvp           = new KeyValuePair <string, string>(WST_STORE_FIELDS.FIELD_STORE_KEY, storeKey);
                List <KeyValuePair <string, string> > listCondition = new List <KeyValuePair <string, string> >();
                listCondition.Add(kvp);
                if (UtilHelper.CheckRecordExpired(db, WST_STORE_FIELDS.DATABASE_TABLE_NAME, listCondition, oldEditTime))
                {
                    FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, COMMON_FIELDS.FIELD_COMMON_EDITTIME_EXP);
                    return(dsReturn);
                }
                #endregion
                //判断线上仓名称是否重复。
                if (dtParams.Rows[0][COMMON_FIELDS.FIELD_COMMON_UPDATE_NAME].ToString() == WST_STORE_FIELDS.FIELD_STORE_NAME)
                {
                    string storeName = Convert.ToString(dtParams.Rows[0][COMMON_FIELDS.FIELD_COMMON_UPDATE_NEW_VALUE]);
                    string strSql    = @"SELECT COUNT(*) FROM WST_STORE WHERE STORE_NAME='" + storeName.PreventSQLInjection() + "'";
                    int    count     = Convert.ToInt32(db.ExecuteScalar(CommandType.Text, strSql));
                    if (count > 0)
                    {
                        //提示“仓库名称不能重复,请重新输入。”
                        FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "${res:FanHai.Hemera.Modules.FMM.StoreEngine.StoreNameAlreadyExist}");
                        return(dsReturn);
                    }
                }
                //生成UPDATE SQL
                List <string> sqlCommandList = new List <string>();
                DatabaseTable.BuildUpdateSqlStatements(ref sqlCommandList,
                                                       new WST_STORE_FIELDS(),
                                                       dsParams.Tables[WST_STORE_FIELDS.DATABASE_TABLE_NAME],
                                                       new Dictionary <string, string>()
                {
                    { WST_STORE_FIELDS.FIELD_EDIT_TIME, null },
                },
                                                       new List <string>()
                {
                    WST_STORE_FIELDS.FIELD_STORE_KEY
                },
                                                       WST_STORE_FIELDS.FIELD_STORE_KEY);
                //更新线上仓数据。
                if (sqlCommandList.Count > 0)
                {
                    dbconn = db.CreateConnection();
                    dbconn.Open();
                    //Create Transaction
                    dbtran = dbconn.BeginTransaction();
                    try
                    {
                        foreach (string sql in sqlCommandList)
                        {
                            db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                        }
                        dbtran.Commit();
                        FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "");
                    }
                    catch (Exception ex)
                    {
                        dbtran.Rollback();
                        FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                        LogService.LogError("UpdateStore Error: " + ex.Message);
                    }
                    finally
                    {
                        dbtran = null;
                        //Close Connection
                        dbconn.Close();
                        dbconn = null;
                    }
                }
            }
            else
            {
                FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "${res:Global.ServerMessage.M0004}");
            }
            return(dsReturn);
        }
예제 #14
0
        /// <summary>
        /// 执行批次进站作业。
        /// </summary>
        /// <param name="dsParams">
        /// 数据集对象。包含名称为<see cref="TRANS_TABLES.TABLE_PARAM"/>的数据表。
        /// 数据表中必须包含两个列"name"和"value"。列name存放哈希表的键名,列value存放哈希表键对应的键值。</param>
        /// <returns>
        /// 包含执行结果的数据集。
        /// 0:成功。-1或1:失败。 2:需要进行数据采集。
        /// </returns>
        public DataSet TrackInLot(DataSet dsParams)
        {
            DateTime      startTime         = DateTime.Now;
            DataSet       dsReturn          = new DataSet();
            string        sql               = "";
            DbConnection  dbconn            = null;
            DbTransaction dbtran            = null;
            string        lotKey            = "",
                          lineKey           = "",
                          workOrderKey      = "",
                          stepKey           = "",
                          quantityIn        = "",
                          user              = "",
                          editTime          = "",
                          lotNumber         = "",
                          strEquKey         = "",
                          strEquStateKey    = "",
                          strOperationKey   = "",
                          strIsBatch        = "",
                          maxQuantity       = "",
                          inProductQuantity = "",
                          isAutoTrackOut    = string.Empty,
                          oprLine           = string.Empty,
                          shiftName         = string.Empty,
                          lineName          = string.Empty,
                          editTimeZone      = string.Empty,
                          shiftKey          = string.Empty,
                          operateCompName   = string.Empty;

            try
            {
                dbconn = db.CreateConnection();
                dbconn.Open();
                //Create Transaction
                dbtran = dbconn.BeginTransaction();

                //如果数据集中包含TRANS_TABLES.TABLE_PARAM的数据表
                if (dsParams.Tables.Contains(TRANS_TABLES.TABLE_PARAM))
                {
                    DataTable dtParams = dsParams.Tables[TRANS_TABLES.TABLE_PARAM];
                    Hashtable htParams = SolarViewer.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dtParams);
                    lotKey          = htParams[POR_LOT_FIELDS.FIELD_LOT_KEY].ToString();
                    lotNumber       = htParams[POR_LOT_FIELDS.FIELD_LOT_NUMBER].ToString();
                    lineKey         = htParams[WIP_TRANSACTION_FIELDS.FIELD_LINE_KEY].ToString();
                    workOrderKey    = htParams[WIP_TRANSACTION_FIELDS.FIELD_WORK_ORDER_KEY].ToString();
                    stepKey         = htParams[WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY].ToString();
                    quantityIn      = htParams[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_IN].ToString();
                    user            = htParams[WIP_TRANSACTION_FIELDS.FIELD_EDITOR].ToString();
                    editTime        = htParams[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME].ToString();
                    editTimeZone    = htParams[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY].ToString();
                    oprLine         = htParams[WIP_TRANSACTION_FIELDS.FIELD_OPR_LINE].ToString();
                    shiftName       = htParams[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_NAME].ToString();
                    lineName        = htParams[POR_LOT_FIELDS.FIELD_LINE_NAME].ToString();
                    shiftKey        = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_SHIFT_KEY]);
                    operateCompName = Convert.ToString(htParams[WIP_TRANSACTION_FIELDS.FIELD_OPR_COMPUTER]);
                }

                #region 检查记录是否过期。
                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, editTime))
                {
                    SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, 1, "数据已过期");
                    return(dsReturn);
                }
                #endregion

                DateTime dtCurrent = UtilHelper.GetSysdate(db);

                #region 检查设备
                //如果数据集合中包含EMS_EQUIPMENTS_FIELDS.DATABASE_TABLE_NAME数据表对象。
                if (dsParams.Tables.Contains(EMS_EQUIPMENTS_FIELDS.DATABASE_TABLE_NAME))
                {
                    DataTable equDataTable = dsParams.Tables[EMS_EQUIPMENTS_FIELDS.DATABASE_TABLE_NAME];
                    Hashtable equHashData  = SolarViewer.Hemera.Share.Common.CommonUtils.ConvertToHashtable(equDataTable);
                    strEquKey       = equHashData[EMS_EQUIPMENTS_FIELDS.FIELD_EQUIPMENT_KEY].ToString();
                    strOperationKey = equHashData[POR_ROUTE_OPERATION_VER_FIELDS.FIELD_ROUTE_OPERATION_VER_KEY].ToString();
                    //如果设备主键有值。
                    if (strEquKey != "" && strEquKey.Length > 0)
                    {
                        sql = @"SELECT a.ISBATCH,a.EQUIPMENT_STATE_KEY,a.MAXQUANTITY ,b.EQUIPMENT_STATE_TYPE,b.EQUIPMENT_STATE_NAME
                                FROM EMS_EQUIPMENTS a
                                LEFT JOIN EMS_EQUIPMENT_STATES b ON a.EQUIPMENT_STATE_KEY=b.EQUIPMENT_STATE_KEY
                                WHERE EQUIPMENT_KEY='" + strEquKey.PreventSQLInjection() + "'";
                        DataSet dsEqu = db.ExecuteDataSet(CommandType.Text, sql);//查询设备
                        //如果有数据。
                        if (dsEqu.Tables[0].Rows.Count > 0)
                        {
                            strIsBatch     = Convert.ToString(dsEqu.Tables[0].Rows[0][EMS_EQUIPMENTS_FIELDS.FIELD_ISBATCH]);                             //设备是否是批处理设备。
                            strEquStateKey = Convert.ToString(dsEqu.Tables[0].Rows[0][EMS_EQUIPMENTS_FIELDS.FIELD_EQUIPMENT_STATE_KEY]);                 //设备状态。
                            maxQuantity    = Convert.ToString(dsEqu.Tables[0].Rows[0][EMS_EQUIPMENTS_FIELDS.FIELD_MAXQUANTITY]);                         //最大数量。
                            string strEquStateName = Convert.ToString(dsEqu.Tables[0].Rows[0][EMS_EQUIPMENT_STATES_FIELDS.FIELD_EQUIPMENT_STATE_NAME]);  //设备状态名称。
                            string strEquStateType = Convert.ToString(dsEqu.Tables[0].Rows[0][EMS_EQUIPMENT_STATES_FIELDS.FIELD_EQUIPMENT_STATE_TYPE]);  //设备状态类型。
                            #region 检查设备状态
                            //如果设备状态不是“待产”
                            if (strEquStateType != "LOST")
                            {
                                //如果设备状态是“在产”
                                if (strEquStateType == "RUN")
                                {
                                    //如果是批处理设备。
                                    if (strIsBatch == "1")
                                    {
                                        //获取设备在产数量。
                                        sql = @"SELECT ISNULL(SUM(T.QUANTITY),0) AS INQUANTITY 
                                                FROM EMS_LOT_EQUIPMENT T
                                                WHERE T.EQUIPMENT_KEY = '" + strEquKey + "' AND T.END_TIMESTAMP IS NULL";
                                        DataSet dsLotEqu = db.ExecuteDataSet(CommandType.Text, sql);
                                        if (dsLotEqu.Tables[0].Rows.Count > 0 && !string.IsNullOrEmpty(maxQuantity))//获取设备在产数量成功
                                        {
                                            inProductQuantity = dsLotEqu.Tables[0].Rows[0]["inQuantity"].ToString();
                                            //在产数量>设备的最大数量,结束方法执行。
                                            if (Convert.ToInt32(inProductQuantity) + Convert.ToInt32(quantityIn) > Convert.ToInt32(maxQuantity))
                                            {
                                                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "${res:SolarViewer.Hemera.Modules.Wip.WipEngine.Msg.BigThenMaxQuantity}");
                                                return(dsReturn);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //如果不是批处理设备,结束方法执行。
                                        SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "${res:SolarViewer.Hemera.Modules.Wip.WipEngine.Msg.BatchIsFalse}");
                                        return(dsReturn);
                                    }
                                }
                                else
                                {
                                    //如果设备状态不是在产,结束方法执行。
                                    SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "${res:SolarViewer.Hemera.Modules.Wip.WipEngine.Msg.EquipmentCanNotUser}");
                                    return(dsReturn);
                                }
                            }
                            #endregion
                        }
                        else//获取设备数据失败。
                        {
                            SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "${res:SolarViewer.Hemera.Modules.Wip.WipEngine.Msg.GetEquipmentError}");
                            return(dsReturn);
                        }
                    }
                }
                #endregion

                //批次进站,更新批次数据,插入批次进站操作记录。
                WipManagement.TrackInLot(db, dbtran, dsParams);
                //设备主键不为空。
                if (strEquKey != "")
                {
                    //批次和设备进行关联。
                    WipManagement.TrackInForEquipment(lotKey, Convert.ToInt32(quantityIn), strOperationKey, stepKey, strEquKey, user, dbtran);
                }

                #region 检查自动合批
                //工步主键不为空。
                if (stepKey != "")
                {
                    string  isLastStep     = "";
                    string  isAutoMerge    = "";
                    int     maxBoxQuantity = -1;
                    DataSet dsStepUda      = GetStepUda(stepKey);
                    //如果获取到工步自定义属性数据。
                    if (dsStepUda.Tables[0].Rows.Count > 0)
                    {
                        //遍历工序的自定义属性。
                        for (int i = 0; i < dsStepUda.Tables[0].Rows.Count; i++)
                        {
                            string szAttriName  = dsStepUda.Tables[0].Rows[i][POR_ROUTE_STEP_ATTR_FIELDS.FIELD_ATTRIBUTE_NAME].ToString();
                            string szAttriValue = dsStepUda.Tables[0].Rows[i][POR_ROUTE_STEP_ATTR_FIELDS.FIELD_ATTRIBUTE_VALUE].ToString();
                            //是否是最后一个工步。
                            if (szAttriName == "IsLastStep")
                            {
                                isLastStep = szAttriValue;
                            }
                            //是否自动合批。
                            if (szAttriName == "AutoMerge")
                            {
                                isAutoMerge = szAttriValue;
                            }
                            //箱子最大数量。
                            if (szAttriName == "MaxBoxQuantity" && !int.TryParse(szAttriValue, out maxBoxQuantity))
                            {
                                maxBoxQuantity = -1;
                            }
                            //是否自动出站。
                            if (szAttriName == "AutoTrackOut")
                            {
                                isAutoTrackOut = szAttriValue;
                            }
                        }
                        if (isAutoMerge.ToLower() == "true")//进行自动合批
                        {
                            AutoMerge(db, dbtran, lotKey, workOrderKey, stepKey, lineKey,
                                      quantityIn, maxBoxQuantity, 4, user, false, oprLine, shiftName);
                        }
                    }
                }

                #endregion

                #region 检查自动出站
                //自动出站
                if (isAutoTrackOut.ToLower() == "true")
                {
                    DataSet dsInfo = GetLotsInfo(dbtran, lotKey);
                    //获取批次信息成功。
                    if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
                    {
                        string nextRunTime = string.Empty;
                        string sDuration   = Convert.ToString(dsInfo.Tables[0].Rows[0][POR_ROUTE_STEP_FIELDS.FIELD_DURATION]);
                        double duration    = 0;
                        if (!double.TryParse(sDuration, out duration))
                        {
                            duration = 0;
                        }
                        nextRunTime = dtCurrent.AddMinutes(duration).ToString("yyyy-MM-dd HH:mm:ss");
                        Hashtable hashWipJob = new Hashtable();
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_EDIT_TIMEZONE, editTimeZone);
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_EDITOR, user);
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_EDIT_TIME, dtCurrent);
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_ENTERPRISE_KEY, dsInfo.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_ROUTE_ENTERPRISE_VER_KEY].ToString());
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_JOB_CREATETIME, dtCurrent);
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_EQUIPMENT_KEY, strEquKey);
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_JOB_CLOSETYPE, string.Empty);
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_JOB_NEXTRUNTIME, nextRunTime);
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_JOB_RUNACCOUNT, "0");
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_JOB_STATUS, "0");
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_JOB_TYPE, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_TRACKIN);
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_LINE_NAME, lineName);
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_LOT_KEY, lotKey);
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_LOT_NUMBER, lotNumber);
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_NOTIFY_USER, string.Empty);
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_ROUTE_KEY, dsInfo.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_CUR_ROUTE_VER_KEY]);
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_ROW_KEY, UtilHelper.GenerateNewKey(0));
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_STEP_KEY, dsInfo.Tables[0].Rows[0][POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY]);
                        hashWipJob.Add(WIP_JOB_FIELDS.FIELDS_WORKORDER_NUMBER, dsInfo.Tables[0].Rows[0][POR_WORK_ORDER_FIELDS.FIELD_ORDER_NUMBER]);
                        //插入一笔自动过站任务。
                        WipJobAutoTrack.InsertWipJob(db, dbtran, hashWipJob);
                    }
                }
                #endregion

                //检查是否需要进行数据采集。
                string edcPointKey = string.Empty;
                if (CheckNeedEdc(dbtran, lotKey, strEquKey, out edcPointKey))
                {
                    IEDCEngine edcEngine = RemotingServer.ServerObjFactory.Get <IEDCEngine>();
                    edcEngine.SaveEdcMainInfo(dbtran, lotKey, edcPointKey, user, strEquKey, oprLine, shiftKey);
                    SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, 2, "批次" + lotNumber + "需要抽检");
                }
                else
                {
                    //更新批次状态为9(WaitingForTrackout)
                    UpdateLotState(dbtran, lotKey, 9);
                    SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, 0, string.Empty);
                }
                //检查是否需要进行锁定。
                CheckAndUpdateFutureHold(dbtran, lotKey, stepKey, shiftName, shiftKey, user,
                                         operateCompName, editTimeZone, ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_TRACKIN);

                dbtran.Commit();
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, 1, "批次进站出错" + ex.Message);
                LogService.LogError("TrackInLot Error: " + ex.Message);
                dbtran.Rollback();
            }
            finally
            {
                dbconn.Close();
            }
            System.DateTime endTime = System.DateTime.Now;
            LogService.LogInfo("TrackIn Lot Time: " + (endTime - startTime).TotalMilliseconds.ToString());
            return(dsReturn);
        }
예제 #15
0
        /// <summary>
        /// (电池片/组件)不良操作,根据操作名称(<see cref="WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY"/>)区分。
        /// </summary>
        /// <remarks>
        /// 操作名称:<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_CELLDEFECT"/>和<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_DEFECT"/>。
        /// </remarks>
        /// <param name="dsParams">包含不良信息的数据集对象。</param>
        /// <returns>包含结果数据的数据集对象。</returns>
        public DataSet LotDefect(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)               //存放操作数据
                    | dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME].Rows.Count == 0)
                {
                    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]);
                int       deletedTermFlag = 0;
                //检查记录是否过期。防止重复修改。
                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);
                }
                LotDefect(dsParams, dbTran);
                //更新批次数量。
                string sql = string.Format(@"UPDATE POR_LOT 
                                            SET QUANTITY={0},EDITOR='{1}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{2}',DELETED_TERM_FLAG={4}
                                            WHERE LOT_KEY='{3}'",
                                           leftQty,
                                           editor.PreventSQLInjection(),
                                           editTimeZone.PreventSQLInjection(),
                                           lotKey.PreventSQLInjection(),
                                           deletedTermFlag);
                db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                dbTran.Commit();
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Empty);
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("LotDefect Error: " + ex.Message);
                dbTran.Rollback();
            }
            finally
            {
                dbConn.Close();
            }
            return(dsReturn);
        }
예제 #16
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);
        }
예제 #17
0
        public DataSet TransferLotToStore(DataSet dataset)
        {
            //dataset.WriteXml(@"d:\TransferLotToStore.xml");

            System.DateTime startTime = System.DateTime.Now;

            DataSet       dsReturn = new DataSet();
            DbConnection  dbconn = null;
            DbTransaction dbtran = null;
            string        sql = "", storeKey = "", storeName = "", lotNumber = "";
            string        strEditor = "", strEditTimeZone = "", strEditTime = "";
            string        lotKey = "", stepKey = "";

            if (dataset != null)
            {
                if (dataset.Tables.Contains(WST_STORE_MAT_FIELDS.DATABASE_TABLE_NAME))
                {
                    WST_STORE_MAT_FIELDS tableFields = new WST_STORE_MAT_FIELDS();
                    DataTable            dataTable   = dataset.Tables[WST_STORE_MAT_FIELDS.DATABASE_TABLE_NAME];
                    storeName       = dataTable.Rows[0][WST_STORE_FIELDS.FIELD_STORE_NAME].ToString();
                    lotNumber       = dataTable.Rows[0][WST_STORE_MAT_FIELDS.FIELD_ITEM_NO].ToString();
                    strEditor       = dataTable.Rows[0][WST_STORE_MAT_FIELDS.FIELD_EDITOR].ToString();
                    strEditTimeZone = dataTable.Rows[0][WST_STORE_MAT_FIELDS.FIELD_EDIT_TIMEZONE].ToString();
                    strEditTime     = dataTable.Rows[0][WST_STORE_MAT_FIELDS.FIELD_EDIT_TIME].ToString();
                    lotKey          = dataTable.Rows[0][POR_LOT_FIELDS.FIELD_LOT_KEY].ToString();
                    stepKey         = dataTable.Rows[0][POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY].ToString();
                    try
                    {
                        #region CheckRecordExpired
                        KeyValuePair <string, string>         kvp           = new KeyValuePair <string, string>(POR_LOT_FIELDS.FIELD_LOT_NUMBER, lotNumber);
                        List <KeyValuePair <string, string> > listCondition = new List <KeyValuePair <string, string> >();
                        listCondition.Add(kvp);
                        if (UtilHelper.CheckRecordExpired(db, POR_LOT_FIELDS.DATABASE_TABLE_NAME, listCondition, strEditTime))
                        {
                            SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, COMMON_FIELDS.FIELD_COMMON_EDITTIME_EXP);
                            return(dsReturn);
                        }
                        #endregion

                        sql = @"SELECT STORE_KEY FROM WST_STORE WHERE STORE_NAME='" + storeName + "'";
                        IDataReader dataReader = db.ExecuteReader(CommandType.Text, sql);
                        if (dataReader.Read())
                        {
                            storeKey = dataReader["STORE_KEY"].ToString();
                            using (dbconn = db.CreateConnection())
                            {
                                dbconn.Open();
                                //Create Transaction
                                dbtran = dbconn.BeginTransaction();
                                try
                                {
                                    #region insert record into store_mat
                                    dataTable.Rows[0][WST_STORE_MAT_FIELDS.FIELD_EDIT_TIME] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                    sql = DatabaseTable.BuildInsertSqlStatement(tableFields, dataTable, 0,
                                                                                new Dictionary <string, string>()
                                    {
                                        { WST_STORE_MAT_FIELDS.FIELD_STORE_KEY, storeKey },
                                        { WST_STORE_MAT_FIELDS.FIELD_ITEM_TYPE, "Lot" },
                                        { WST_STORE_MAT_FIELDS.FIELD_OBJECT_STATUS, "1" },
                                    },
                                                                                new List <string>()
                                    {
                                        WST_STORE_FIELDS.FIELD_STORE_NAME,
                                        POR_LOT_FIELDS.FIELD_CUR_STEP_VER_KEY,
                                        POR_LOT_FIELDS.FIELD_LOT_KEY
                                    });
                                    db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                                    #endregion

                                    #region 更新批次信息
                                    sql = @"UPDATE POR_LOT SET STATE_FLAG=11," +
                                          "EDITOR='" + strEditor + "'," +
                                          "EDIT_TIME=SYSDATE," +
                                          "EDIT_TIMEZONE='" + strEditTimeZone + "' " +
                                          "WHERE LOT_NUMBER='" + lotNumber + "'";
                                    db.ExecuteNonQuery(dbtran, CommandType.Text, sql);
                                    #endregion

                                    #region update ems_lot_equipment
                                    DataSet resDs     = new DataSet();
                                    string  sqlString = @"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 = '" + stepKey + "' " +
                                                        "AND B.LOT_KEY='" + lotKey + "' " +
                                                        "AND B.END_TIMESTAMP IS NULL";
                                    db.LoadDataSet(CommandType.Text, sqlString, resDs, new string[] { EMS_OPERATION_EQUIPMENT_FIELDS.DATABASE_TABLE_NAME });
                                    if (resDs != null && resDs.Tables.Count > 0)
                                    {
                                        if (resDs.Tables[0].Rows.Count > 0)
                                        {
                                            string equipmentKey = resDs.Tables[0].Rows[0]["EQUIPMENT_KEY"].ToString();
                                            WipManagement.TrackOutForEquipment(lotKey, stepKey, equipmentKey, strEditor, dbtran);
                                        }
                                    }
                                    #endregion

                                    SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "");
                                    dbtran.Commit();
                                }
                                catch (Exception ex)
                                {
                                    SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                                    //Rollback Transaction
                                    dbtran.Rollback();
                                    LogService.LogError("TransferLotToStore Error: " + ex.Message);
                                }
                                finally
                                {
                                    dbconn.Close();
                                }
                            }
                        }
                        else
                        {
                            SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "${res:SolarViewer.Hemera.Modules.FMM.StoreEngine.StoreIsNotExist}");
                            return(dsReturn);
                        }

                        dataReader.Close();
                        dataReader.Dispose();
                    }
                    catch (Exception ex)
                    {
                        SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                    }
                }
            }

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

            return(dsReturn);
        }
예제 #18
0
        /// <summary>
        /// 进行批次不良操作。
        /// </summary>
        /// <param name="dsParams">
        /// 包含批次不良数据信息的数据集对象。
        /// 必须包含名称为<see cref=" TRANS_TABLES.TABLE_PARAM"/>的数据表,用于存储批次主信息的数据。
        /// 包含名称为<see cref="WST_STORE_MAT_FIELDS.DATABASE_TABLE_NAME"/>的数据表(可选),用于存储批次返工或退库的数据。
        /// 包含名称为<see cref="WIP_DEFECT_FIELDS.DATABASE_TABLE_NAME"/>的数据表(可选),用于存储批次不良数据。
        /// </param>
        /// <returns>包含执行结果的数据集。</returns>
        public DataSet LotDefect(DataSet dsParams)
        {
            DateTime      startTime = DateTime.Now;
            DataSet       dsReturn = new DataSet();
            DbConnection  dbConn = null;
            DbTransaction dbTran = null;
            string        lotKey = string.Empty, editor = string.Empty, editTimeZone = string.Empty, qty = string.Empty;

            try
            {
                dbConn = db.CreateConnection();
                dbConn.Open();
                //Create Transaction
                dbTran = dbConn.BeginTransaction();

                #region CheckExpired 检查记录是否过期。防止重复修改。
                if (dsParams.Tables.Contains(TRANS_TABLES.TABLE_PARAM))
                {
                    DataTable dtParams = dsParams.Tables[TRANS_TABLES.TABLE_PARAM];
                    Hashtable htParams = SolarViewer.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dtParams);
                    lotKey       = htParams[POR_LOT_FIELDS.FIELD_LOT_KEY].ToString();
                    qty          = htParams[WIP_TRANSACTION_FIELDS.FIELD_QUANTITY_OUT].ToString();
                    editor       = htParams[WIP_TRANSACTION_FIELDS.FIELD_EDITOR].ToString();
                    editTimeZone = htParams[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIMEZONE_KEY].ToString();

                    string strEditTime = htParams[WIP_TRANSACTION_FIELDS.FIELD_EDIT_TIME].ToString();
                    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, strEditTime))
                    {
                        SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, COMMON_FIELDS.FIELD_COMMON_EDITTIME_EXP);
                        return(dsReturn);
                    }
                }
                #endregion


                //进行不良数据收集。
                SetDefect(dbTran, dsParams);

                //更新批次数量。
                string sql = string.Format(@"UPDATE POR_LOT 
                                            SET QUANTITY='{0}',EDITOR='{1}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{2}' 
                                            WHERE LOT_KEY='{3}'",
                                           qty.PreventSQLInjection(),
                                           editor.PreventSQLInjection(),
                                           editTimeZone.PreventSQLInjection(),
                                           lotKey.PreventSQLInjection());
                db.ExecuteNonQuery(dbTran, CommandType.Text, sql);

                dbTran.Commit();
                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Empty);
            }
            catch (Exception ex)
            {
                SolarViewer.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("LotDefect Error: " + ex.Message);
                dbTran.Rollback();
            }
            finally
            {
                dbConn.Close();
            }

            System.DateTime endTime = System.DateTime.Now;
            LogService.LogInfo("LotDefect Time: " + (endTime - startTime).TotalMilliseconds.ToString());
            return(dsReturn);
        }
예제 #19
0
        /// <summary>
        /// 更新预设暂停数据。
        /// </summary>
        /// <param name="dsParams">包含待更新的预设暂停批次的数据集。</param>
        /// <returns>包含执行结果的数据集对象。</returns>
        public DataSet Update(DataSet dsParams)
        {
            DataSet       dsReturn = new DataSet();
            DbTransaction dbTrans  = null;
            DbConnection  dbCon    = null;

            if (dsParams != null)
            {
                try
                {
                    DataTable dtLots = dsParams.Tables[WIP_FUTUREHOLD_FIELDS.DATABASE_TABLE_NAME];
                    if (dtLots == null || dtLots.Rows.Count == 0)
                    {
                        FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "预设暂停的批次数据不能为空。");
                        return(dsReturn);
                    }

                    string sql = @"UPDATE WIP_FUTUREHOLD
                                   SET WORKORDER_NUMBER=@orderNo,
                                       LOT_NUMBER=@lotNo,
                                       ACTION_NAME=@action,
                                       REMARK=@remark,
                                       STEP_KEY=@stepKey,
                                       ROUTE_KEY=@routeKey,
                                       ENTERPRISE_KEY=@enterpriseKey,
                                       OPERATION_NAME=@operationName,
                                       LOT_KEY=@lotKey,
                                       HOLD_PASSWORD=@password,
                                       EDITOR=@editor,EDIT_TIME=GETDATE(),
                                       SET_STEP_KEY=@setStepKey,
                                       SET_ROUTE_KEY=@setRouteKey,
                                       SET_ENTERPRISE_KEY=@setEnterpriseKey,
                                       REASON_CODE_CATEGORY_KEY=@rcCategoryKey,
                                       REASON_CODE_CATEGORY_NAME=@rcCategoryName,
                                       REASON_CODE_KEY=@rcCodeKey,
                                       REASON_CODE=@rcCodeName
                                   WHERE ROW_KEY=@key";

                    dbCon = db.CreateConnection();
                    dbCon.Open();
                    dbTrans = dbCon.BeginTransaction();

                    foreach (DataRow dr in dtLots.Rows)
                    {
                        string key      = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_ROW_KEY]);
                        string lotNo    = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_LOT_NUMBER]);
                        string editTime = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_EDIT_TIME]);

                        #region 检查记录是否过期
                        KeyValuePair <string, string>         kvp           = new KeyValuePair <string, string>(WIP_FUTUREHOLD_FIELDS.FIELDS_ROW_KEY, key);
                        List <KeyValuePair <string, string> > listCondition = new List <KeyValuePair <string, string> >();
                        listCondition.Add(kvp);
                        //判断数据是否过期,如果过期,则返回执行结果为“数据已过期。”,结束方法执行。
                        if (UtilHelper.CheckRecordExpired(db, WIP_FUTUREHOLD_FIELDS.DATABASE_TABLE_NAME, listCondition, editTime))
                        {
                            FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Format("『{0}』数据已过期。", lotNo));
                            return(dsReturn);
                        }
                        #endregion

                        string orderNo = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_WORKORDER_NUMBER]);

                        string    action           = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_ACTION_NAME]);
                        string    remark           = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_REMARK]);
                        string    stepKey          = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_STEP_KEY]);
                        string    routeKey         = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_ROUTE_KEY]);
                        string    enterpriseKey    = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_ENTERPRISE_KEY]);
                        string    operationName    = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_OPERATION_NAME]);
                        string    lotKey           = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_LOT_KEY]);
                        string    editor           = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_EDITOR]);
                        string    setStepKey       = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_SET_STEP_KEY]);
                        string    setRouteKey      = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_SET_ROUTE_KEY]);
                        string    setEnterpriseKey = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_SET_ENTERPRISE_KEY]);
                        string    rcCategoryKey    = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_REASON_CODE_CATEGORY_KEY]);
                        string    rcCategoryName   = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_REASON_CODE_CATEGORY_NAME]);
                        string    rcCodeKey        = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_REASON_CODE_KEY]);
                        string    rcCodeName       = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_REASON_CODE]);
                        string    password         = Convert.ToString(dr[WIP_FUTUREHOLD_FIELDS.FIELDS_HOLD_PASSWORD]);
                        DbCommand dbCmd            = db.GetSqlStringCommand(sql);
                        db.AddInParameter(dbCmd, "key", DbType.String, key);
                        db.AddInParameter(dbCmd, "orderNo", DbType.String, orderNo);
                        db.AddInParameter(dbCmd, "lotNo", DbType.String, lotNo);
                        db.AddInParameter(dbCmd, "action", DbType.String, action);
                        db.AddInParameter(dbCmd, "remark", DbType.String, remark);
                        db.AddInParameter(dbCmd, "stepKey", DbType.String, stepKey);
                        db.AddInParameter(dbCmd, "routeKey", DbType.String, routeKey);
                        db.AddInParameter(dbCmd, "enterpriseKey", DbType.String, enterpriseKey);
                        db.AddInParameter(dbCmd, "operationName", DbType.String, operationName);
                        db.AddInParameter(dbCmd, "lotKey", DbType.String, lotKey);
                        db.AddInParameter(dbCmd, "password", DbType.String, password);
                        db.AddInParameter(dbCmd, "editor", DbType.String, editor);
                        db.AddInParameter(dbCmd, "setStepKey", DbType.String, setStepKey);
                        db.AddInParameter(dbCmd, "setRouteKey", DbType.String, setRouteKey);
                        db.AddInParameter(dbCmd, "setEnterpriseKey", DbType.String, setEnterpriseKey);
                        db.AddInParameter(dbCmd, "rcCategoryKey", DbType.String, rcCategoryKey);
                        db.AddInParameter(dbCmd, "rcCategoryName", DbType.String, rcCategoryName);
                        db.AddInParameter(dbCmd, "rcCodeKey", DbType.String, rcCodeKey);
                        db.AddInParameter(dbCmd, "rcCodeName", DbType.String, rcCodeName);
                        int nRet = db.ExecuteNonQuery(dbCmd, dbTrans);
                    }
                    dbTrans.Commit();
                    FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Empty);
                }
                catch (Exception ex)
                {
                    if (dbTrans != null)
                    {
                        dbTrans.Rollback();
                    }
                    FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                    LogService.LogError(string.Format("LotFutureHoldEngine-Update Error:{0}", ex.Message));
                }
                finally
                {
                    if (dbCon != null)
                    {
                        if (dbCon.State != ConnectionState.Closed)
                        {
                            dbCon.Close();
                        }
                        dbCon = null;
                    }
                }
            }
            return(dsReturn);
        }
예제 #20
0
        /// <summary>
        /// 批次撤销操作。
        /// </summary>
        /// <param name="dsParams">包含撤销操作信息的数据集对象。</param>
        /// <returns>
        /// 包含结果数据的数据集对象。
        /// </returns>
        public DataSet LotUndo(DataSet dsParams)
        {
            DataSet dsReturn = new DataSet();

            try
            {
                //参数数据。
                if (dsParams == null ||
                    !dsParams.Tables.Contains(WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME)               //存放操作数据
                    )
                {
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "传入参数不正确,请检查。");
                    return(dsReturn);
                }
                DataTable dtTransaction = dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME];  //存放操作数据
                //检查是否存在重复的批次主键。
                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)
                {
                    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))
                    {
                        ReturnMessageUtils.AddServerReturnMessage(dsReturn, "信息已过期,请关闭该界面后重试。");
                        return(dsReturn);
                    }
                }
                StringBuilder sbMsg = new StringBuilder();
                //撤销批次操作。
                for (int i = 0; i < dtTransaction.Rows.Count; i++)
                {
                    DataRow drTransaction = dtTransaction.Rows[i];
                    using (DbConnection dbConn = db.CreateConnection())
                    {
                        try
                        {
                            dbConn.Open();
                            DbTransaction dbTran   = dbConn.BeginTransaction();
                            string        activity = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]);
                            if (activity == ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_CREATELOT)
                            {
                                UndoCreateLot(dbTran, drTransaction);
                            }
                            else
                            {
                                UndoCommon(dbTran, drTransaction);
                            }
                            dbTran.Commit();
                        }
                        catch (Exception ex)
                        {
                            sbMsg.AppendFormat("失败:第{0}行处理失败 {1};", i + 1, ex.Message);
                        }
                    }
                }
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, sbMsg.ToString());
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("LotUndo Error: " + ex.Message);
            }
            return(dsReturn);
        }
예제 #21
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);
        }
예제 #22
0
        /// <summary>
        /// 批次(返工/返修)操作。
        /// </summary>
        /// <remarks>
        /// 操作名称:<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_REWORK"/>。
        /// </remarks>
        /// <param name="dsParams">包含批次(返工/返修)信息的数据集对象。</param>
        /// <returns>包含结果数据的数据集对象。</returns>
        public DataSet LotRework(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) ||
                    dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME].Rows.Count == 0 ||      //返工批次操作记录不能为空记录。
                    dsParams.Tables[WIP_COMMENT_FIELDS.DATABASE_TABLE_NAME].Rows.Count == 0)            //返工信息不能为空
                {
                    dbTran.Rollback();
                    ReturnMessageUtils.AddServerReturnMessage(dsReturn, "传入参数不正确,请检查。");
                    return(dsReturn);
                }
                DataTable dtTransaction = dsParams.Tables[WIP_TRANSACTION_FIELDS.DATABASE_TABLE_NAME];   //存放操作数据


                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];           //存放暂停信息明细数据
                }
                //检查是否存在重复的批次主键。
                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]);      //编辑时区
                    string stepKey    = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_STEP_KEY]);    //当前工步主键
                    //检查记录是否过期。防止重复修改。
                    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);
                    }
                }
                //如果有暂停批次,先记录批次释放操作。
                if (dtHold != null)
                {
                    DataSet   dsReleaseParams      = new DataSet();
                    DataTable dtReleaseTransaction = dtTransaction.Copy();
                    DataTable dtReleaseHold        = dtHold.Copy();
                    dsReleaseParams.Tables.Add(dtReleaseTransaction);
                    dsReleaseParams.Tables.Add(dtReleaseHold);
                    //组织释放批次的数据。
                    foreach (DataRow drTransaction in dtReleaseTransaction.Rows)
                    {
                        string curReleaseTransKey = Convert.ToString(drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY]);
                        string transKey           = UtilHelper.GenerateNewKey(0);
                        drTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY] = transKey;
                        drTransaction[WIP_TRANSACTION_FIELDS.FIELD_ACTIVITY]        = ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_RELEASE;
                        //组织暂停批次信息。
                        var lnqHold = from item in dtReleaseHold.AsEnumerable()
                                      where Convert.ToString(item[WIP_HOLD_RELEASE_FIELDS.FIELD_RELEASE_TRANSACTION_KEY]) == curReleaseTransKey
                                      select item;
                        foreach (DataRow drHoldInfo in lnqHold)
                        {
                            drHoldInfo[WIP_HOLD_RELEASE_FIELDS.FIELD_RELEASE_TRANSACTION_KEY] = transKey;
                        }
                    }
                    //释放批次。
                    LotRelease(dsReleaseParams, dbTran);
                    dsReleaseParams.Tables.Clear();
                    dsReleaseParams = null;
                }
                //返工/返修批次
                LotRework(dsParams, dbTran);
                dbTran.Commit();
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Empty);
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("LotRework Error: " + ex.Message);
                dbTran.Rollback();
            }
            finally
            {
                dbConn.Close();
            }
            return(dsReturn);
        }