Esempio n. 1
0
        /// <summary>
        /// 电池片补片操作。
        /// </summary>
        /// <remarks>
        /// 操作名称:<see cref="ACTIVITY_FIELD_VALUES.FIELD_ACTIVITY_PATCH"/>。
        /// </remarks>
        /// <param name="dsParams">包含补片信息的数据集对象。</param>
        /// <returns>包含结果数据的数据集对象。</returns>
        public DataSet LotPatch(DataSet dsParams)
        {
            DataSet       dsReturn = new DataSet();
            DbConnection  dbConn   = null;
            DbTransaction dbTran   = null;

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

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

                    AddWIPLot(dbTran, transactionKey, lotKey);
                    //获取组件补片批次当前数量
                    sql = string.Format("SELECT QUANTITY FROM POR_LOT WHERE LOT_KEY='{0}'", lotKey.PreventSQLInjection());
                    double quantity = Convert.ToDouble(db.ExecuteScalar(CommandType.Text, sql));
                    if (quantity < sumPatchedQty)
                    {
                        ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Format("组件补片批次当前实际数量[{0}]小于补片数量[{1}],请确认。", quantity, sumPatchedQty));
                        dbTran.Rollback();
                        return(dsReturn);
                    }
                    //更新批次数量。
                    sql = string.Format(@"UPDATE POR_LOT 
                                        SET QUANTITY={0},EDITOR='{1}',EDIT_TIME=GETDATE(),EDIT_TIMEZONE='{2}',DELETED_TERM_FLAG={3}
                                        WHERE LOT_KEY='{4}'",
                                        quantity - sumPatchedQty,
                                        editor.PreventSQLInjection(),
                                        editTimeZone.PreventSQLInjection(),
                                        (quantity - sumPatchedQty) > 0 ? 0 : 1,
                                        lotKey.PreventSQLInjection());
                    db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                    //向WIP_TRANSACTION表插入批次补片的操作记录。
                    if (!htTransaction.ContainsKey(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY))
                    {
                        htTransaction.Add(WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY, transactionKey);
                    }
                    htTransaction[WIP_TRANSACTION_FIELDS.FIELD_TRANSACTION_KEY] = transactionKey;
                    sql = DatabaseTable.BuildInsertSqlStatement(wipFields, htTransaction, null);
                    db.ExecuteNonQuery(dbTran, CommandType.Text, sql);
                }
                dbTran.Commit();
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Empty);
            }
            catch (Exception ex)
            {
                ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message);
                LogService.LogError("LotPatch Error: " + ex.Message);
                dbTran.Rollback();
            }
            finally
            {
                dbConn.Close();
            }
            return(dsReturn);
        }
Esempio n. 2
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);
        }