Ejemplo n.º 1
0
        public List <Client_Box_Shelf_Row2> StoredBox_ItemPK_IsRestoredOfEntries2(Accessory accessory, int issuingSessionPK)
        {
            List <Client_Box_Shelf_Row2> result = new List <Client_Box_Shelf_Row2>();
            StoringDAO storingDAO = new StoringDAO();

            try
            {
                // cực phẩm IQ
                double inStoredQuantity = InStoredQuantity(accessory.AccessoryPK);
                if (inStoredQuantity == 0)
                {
                    throw new Exception("HÀNG TRONG KHO ĐÃ HẾT!");
                }
                List <Entry> entries = (from e in db.Entries
                                        where e.AccessoryPK == accessory.AccessoryPK && e.SessionPK == issuingSessionPK && e.KindRoleName == "Issuing"
                                        select e).ToList();
                Dictionary <StoredBox_ItemPK_IsRestored, double> tempDictionary = new Dictionary <StoredBox_ItemPK_IsRestored, double>();
                foreach (var entry in entries)
                {
                    StoredBox    storedBox = db.StoredBoxes.Find(entry.StoredBoxPK);
                    Box          box       = db.Boxes.Find(storedBox.BoxPK);
                    PassedItem   passedItem;
                    RestoredItem restoredItem;
                    StoredBox_ItemPK_IsRestored key;
                    if (entry.IsRestored)
                    {
                        restoredItem = db.RestoredItems.Find(entry.ItemPK);
                        key          = new StoredBox_ItemPK_IsRestored(storedBox.StoredBoxPK, restoredItem.RestoredItemPK, entry.IsRestored);
                    }
                    else
                    {
                        passedItem = db.PassedItems.Find(entry.ItemPK);
                        key        = new StoredBox_ItemPK_IsRestored(storedBox.StoredBoxPK, passedItem.PassedItemPK, entry.IsRestored);
                    }
                    if (box.IsActive)
                    {
                        if (!tempDictionary.ContainsKey(key))
                        {
                            tempDictionary.Add(key, storingDAO.EntryQuantity(entry));
                        }
                        else
                        {
                            tempDictionary[key] += storingDAO.EntryQuantity(entry);
                        }
                    }
                }

                foreach (var item in tempDictionary)
                {
                    if (item.Value > 0)
                    {
                        StoredBox storedBox = db.StoredBoxes.Find(item.Key.StoredBoxPK);
                        Box       box       = db.Boxes.Find(storedBox.BoxPK);
                        Shelf     shelf     = db.Shelves.Find(storedBox.ShelfPK);
                        Row       row       = db.Rows.Find(shelf.RowPK);
                        result.Add(new Client_Box_Shelf_Row2(box.BoxID, shelf.ShelfID, row.RowID, item.Key.ItemPK, item.Key.IsRestored, item.Value));
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public List <Client_Box_Shelf_Row> StoredBox_ItemPK_IsRestoredOfEntries(Accessory accessory)
        {
            List <Client_Box_Shelf_Row> result = new List <Client_Box_Shelf_Row>();
            StoringDAO storingDAO = new StoringDAO();

            try
            {
                // cực phẩm IQ
                double inStoredQuantity = InStoredQuantity(accessory.AccessoryPK);
                if (inStoredQuantity == 0)
                {
                    throw new Exception("HÀNG TRONG KHO ĐÃ HẾT!");
                }
                List <Entry> entries = (from e in db.Entries
                                        where e.AccessoryPK == accessory.AccessoryPK
                                        select e).ToList();
                Dictionary <StoredBox_ItemPK_IsRestored, InBoxQuantity_AvailableQuantity> tempDictionary = new Dictionary <StoredBox_ItemPK_IsRestored, InBoxQuantity_AvailableQuantity>();
                foreach (var entry in entries)
                {
                    double    inBoxQuantity = 0;
                    StoredBox storedBox     = db.StoredBoxes.Find(entry.StoredBoxPK);

                    if (entry.KindRoleName == "AdjustingMinus" || entry.KindRoleName == "AdjustingPlus")
                    {
                        AdjustingSession adjustingSession = db.AdjustingSessions.Find(entry.SessionPK);
                        Verification     verification     = db.Verifications.Where(unit => unit.SessionPK == adjustingSession.AdjustingSessionPK &&
                                                                                   unit.IsDiscard == false).FirstOrDefault();
                        if (verification != null && verification.IsApproved)
                        {
                            inBoxQuantity = storingDAO.EntryQuantity(entry);
                        }
                    }
                    else if (entry.KindRoleName == "Discarding")
                    {
                        DiscardingSession discardingSession = db.DiscardingSessions.Find(entry.SessionPK);
                        Verification      verification      = db.Verifications.Where(unit => unit.SessionPK == discardingSession.DiscardingSessionPK &&
                                                                                     unit.IsDiscard == true).FirstOrDefault();
                        if (verification != null && verification.IsApproved)
                        {
                            inBoxQuantity = storingDAO.EntryQuantity(entry);
                        }
                    }
                    else
                    {
                        inBoxQuantity = storingDAO.EntryQuantity(entry);
                    }

                    Box          box = db.Boxes.Find(storedBox.BoxPK);
                    PassedItem   passedItem;
                    RestoredItem restoredItem;
                    StoredBox_ItemPK_IsRestored key;
                    if (entry.IsRestored)
                    {
                        restoredItem = db.RestoredItems.Find(entry.ItemPK);
                        key          = new StoredBox_ItemPK_IsRestored(storedBox.StoredBoxPK, restoredItem.RestoredItemPK, entry.IsRestored);
                    }
                    else
                    {
                        passedItem = db.PassedItems.Find(entry.ItemPK);
                        key        = new StoredBox_ItemPK_IsRestored(storedBox.StoredBoxPK, passedItem.PassedItemPK, entry.IsRestored);
                    }
                    if (box.IsActive)
                    {
                        InBoxQuantity_AvailableQuantity tmp = new InBoxQuantity_AvailableQuantity(inBoxQuantity, storingDAO.EntryQuantity(entry));
                        if (!tempDictionary.ContainsKey(key))
                        {
                            tempDictionary.Add(key, tmp);
                        }
                        else
                        {
                            tempDictionary[key].InBoxQuantity     += tmp.InBoxQuantity;
                            tempDictionary[key].AvailableQuantity += tmp.AvailableQuantity;
                        }
                    }
                }

                foreach (var item in tempDictionary)
                {
                    if (item.Value.AvailableQuantity > 0)
                    {
                        StoredBox storedBox = db.StoredBoxes.Find(item.Key.StoredBoxPK);
                        Box       box       = db.Boxes.Find(storedBox.BoxPK);
                        Shelf     shelf     = db.Shelves.Find(storedBox.ShelfPK);
                        Row       row       = db.Rows.Find(shelf.RowPK);
                        if (item.Key.IsRestored)
                        {
                            RestoredItem restoredItem = db.RestoredItems.Find(item.Key.ItemPK);
                            Restoration  restoration  = db.Restorations.Find(restoredItem.RestorationPK);
                            result.Add(new Client_Box_Shelf_Row(box.BoxID, storedBox.StoredBoxPK, shelf.ShelfID, row.RowID, item.Key.ItemPK, item.Key.IsRestored, item.Value.InBoxQuantity, restoration.RestorationID, item.Value.AvailableQuantity));
                        }
                        else
                        {
                            PassedItem     passedItem     = db.PassedItems.Find(item.Key.ItemPK);
                            ClassifiedItem classifiedItem = db.ClassifiedItems.Find(passedItem.ClassifiedItemPK);
                            PackedItem     packedItem     = db.PackedItems.Find(classifiedItem.PackedItemPK);
                            Pack           pack           = db.Packs.Find(packedItem.PackPK);
                            result.Add(new Client_Box_Shelf_Row(box.BoxID, storedBox.StoredBoxPK, shelf.ShelfID, row.RowID, item.Key.ItemPK, item.Key.IsRestored, item.Value.InBoxQuantity, pack.PackID, item.Value.AvailableQuantity));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(result);
        }