Ejemplo n.º 1
0
        public static List <IItem> GetJsupItemsByStore(DesktopSession dSession, string pStoreNumber, string pTransferType, out string errorMessage)
        {
            // Declare OUT parameters.
            DataTable table     = new DataTable();
            DataTable tableDesc = new DataTable();
            string    errorCode;
            string    errorText;

            errorMessage = string.Empty;

            List <IItem> items = new List <IItem>();

            bool retVal =
                TransfersDBProcedures.ExecuteGetJsupMerchandise(
                    pStoreNumber, pTransferType,
                    out table, out tableDesc, out errorCode, out errorText);

            if (retVal == false || table == null || string.IsNullOrEmpty(errorText) == false)
            {
                errorMessage = errorCode + ": " + errorText;
                FileLogger.Instance.logMessage(LogLevel.ERROR, null, errorMessage);
                return(items);
            }

            IItem item = new Item(); //re-instantiated and re-used in each loop iteration

            foreach (DataRow r in table.Rows)
            {
                if (pTransferType.Equals("SCRAP", StringComparison.CurrentCultureIgnoreCase))
                {
                    item = new ScrapItem();
                }
                else if (pTransferType.Equals("REFURB", StringComparison.CurrentCultureIgnoreCase))
                {
                    //item = new Item();
                    item = new ScrapItem();
                }
                else if (pTransferType.Equals("EXCESS", StringComparison.CurrentCultureIgnoreCase))
                {
                    // item = new Item();
                    item = new ScrapItem();
                }
                //else handled by TransfersDBProcedures's call above returning false with errorCode and errorText having been set

                int    icndocFromRow      = Utilities.GetIntegerValue(r["ICN_DOC"], -1);
                string storeNumberFromRow = Utilities.GetStringValue(r["STORENUMBER"], "");

                item.RefurbNumber      = Utilities.GetIntegerValue(r["RFB_NO"]);
                item.Icn               = Utilities.GetStringValue(r["ICN"]);
                item.TicketDescription = Utilities.GetStringValue(r["MD_DESC"]);
                item.ItemAmount        = Utilities.GetDecimalValue(r["PFI_AMOUNT"]);

                item.ItemStatus          = (ProductStatus)Enum.Parse(typeof(ProductStatus), Utilities.GetStringValue(r["STATUS_CD"], ""));
                item.mDocType            = Utilities.GetStringValue(r["ICN_DOC_TYPE"]);
                item.mStore              = Utilities.GetIntegerValue(r["ICN_STORE"]);
                item.CategoryCode        = Utilities.GetIntegerValue(r["CAT_CODE"], 0);
                item.CategoryDescription = Utilities.GetStringValue(r["CAT_DESC"], "");
                item.mItemOrder          = Utilities.GetIntegerValue(r["ICN_ITEM"]);
                item.CaccLevel           = Utilities.GetIntegerValue(r["CACC_LEV"], -1);

                item.Attributes = new List <ItemAttribute>();

                //Used to get the attributes of the item.
                //This will be helpful later, such as determining the type of metal for scraps.
                for (int iMask = 1; iMask <= 15; iMask++)
                {
                    ItemAttribute itemAttribute = new ItemAttribute();

                    if (Utilities.GetIntegerValue(r["MASK" + iMask.ToString()], 0) > 0)
                    {
                        itemAttribute.MaskOrder = iMask;

                        Answer answer = new Answer();
                        answer.AnswerCode = Utilities.GetIntegerValue(r["MASK" + iMask.ToString()], 0);
                        answer.AnswerText = Utilities.GetStringValue(r["MASK_DESC" + iMask.ToString()], "");

                        // Pull from Other Description List Table
                        if (tableDesc != null && answer.AnswerCode == 999)
                        {
                            string sOtherDscFilter = "STORENUMBER = '" + storeNumberFromRow + "'";
                            sOtherDscFilter += " and ICN_STORE = " + item.mStore.ToString();
                            sOtherDscFilter += " and ICN_YEAR = " + item.mYear.ToString();
                            sOtherDscFilter += " and ICN_DOC = '" + icndocFromRow + "' ";
                            sOtherDscFilter += " and ICN_DOC_TYPE = " + item.mDocType;
                            sOtherDscFilter += " and ICN_ITEM = " + item.mItemOrder;
                            sOtherDscFilter += " and ICN_SUB_ITEM = 0";
                            sOtherDscFilter += " and MASK_SEQ = " + iMask.ToString();

                            DataRow[] dataOtherDScRows = tableDesc.Select(sOtherDscFilter);
                            if (dataOtherDScRows.Length > 0)
                            {
                                answer.AnswerCode = 999;
                                answer.AnswerText = Utilities.GetStringValue(dataOtherDScRows[0]["OD_DESC"], "");
                            }
                            else
                            {
                                answer.AnswerCode = 0;
                                answer.AnswerText = "";
                            }
                        }
                        itemAttribute.Answer = answer;
                    }
                    if (itemAttribute.Answer.AnswerCode == 999 || itemAttribute.Answer.AnswerCode > 0)
                    {
                        item.Attributes.Add(itemAttribute);
                    }
                }

                //Set item attributes
                int iCategoryMask = dSession.CategoryXML.GetCategoryMask(item.CategoryCode);
                DescribedMerchandise dmPawnItem = new DescribedMerchandise(iCategoryMask);

                Item pawnItem = (Item)item;
                Item.PawnItemMerge(ref pawnItem, dmPawnItem.SelectedPawnItem, true);

                //Should copy the description, etc. over to the item.
                PropertyInfo[] fromFields = typeof(Item).GetProperties();
                PropertyInfo[] toFields   = //typeof(ScrapItem).GetProperties();
                                            item.GetType().GetProperties();
                PropertyHandler.SetProperties(fromFields, toFields, pawnItem, item);

                //Does not merge well.
                item.Quantity = Utilities.GetIntegerValue(r["QUANTITY"]);

                if (item is ScrapItem)
                {
                    //Wait to add scrap items until after merge.
                    ((ScrapItem)item).StoreNumber  = storeNumberFromRow;
                    ((ScrapItem)item).TicketNumber = icndocFromRow;
                }

                items.Add(item);
            }

            return(items);
        }