示例#1
0
 public IHttpActionResult PrepareRequest(int requestPK, string userID, [FromBody] Client_InputPrepareRequestAPI input)
 {
     if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Staff"))
     {
         IssuingDAO     issuingDAO     = new IssuingDAO();
         StoringDAO     storingDAO     = new StoringDAO();
         BoxDAO         boxDAO         = new BoxDAO();
         IssuingSession issuingSession = null;
         try
         {
             issuingDAO.UpdateRequest(requestPK, true);
             boxDAO.ChangeIsActiveBoxes(input.boxIDs, false);
             issuingSession = issuingDAO.CreateIssuingSession(userID, requestPK, input.boxIDs);
             storingDAO.CreateIssueEntry(input, issuingSession);
         }
         catch (Exception e)
         {
             if (issuingSession != null)
             {
                 issuingDAO.UpdateRequest(requestPK, false);
                 boxDAO.ChangeIsActiveBoxes(input.boxIDs, true);
                 issuingDAO.DeleteIssuingSession(issuingSession.IssuingSessionPK);
             }
             return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
         }
         return(Content(HttpStatusCode.OK, "TẠO YÊU CẦU XUẤT THÀNH CÔNG!"));
     }
     else
     {
         return(Content(HttpStatusCode.Conflict, "BẠN KHÔNG CÓ QUYỀN ĐỂ THỰC HIỆN VIỆC NÀY!"));
     }
 }
示例#2
0
        public double InOtherRequestedQuantity(int accessoryPK, int requestedItemPK)
        {
            double     result     = 0;
            StoringDAO storingDAO = new StoringDAO();

            try
            {
                List <DemandedItem> demandedItems = (from dI in db.DemandedItems
                                                     where dI.AccessoryPK == accessoryPK
                                                     select dI).ToList();
                foreach (var demandedItem in demandedItems)
                {
                    List <RequestedItem> requestedItems = (from rI in db.RequestedItems
                                                           where rI.DemandedItemPK == demandedItem.DemandedItemPK && rI.RequestedItemPK != requestedItemPK
                                                           select rI).ToList();
                    foreach (var requestedItem in requestedItems)
                    {
                        Request request = db.Requests.Find(requestedItem.RequestPK);
                        if (request.IsIssued == false)
                        {
                            result += requestedItem.RequestedQuantity;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(result);
        }
示例#3
0
 public IHttpActionResult VerifyDiscarding(int discardingSessionPK, string userID, bool isApproved)
 {
     if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Manager"))
     {
         StoringDAO        storingDAO        = new StoringDAO();
         Verification      verification      = null;
         DiscardingSession discardingSession = null;
         try
         {
             discardingSession = db.DiscardingSessions.Find(discardingSessionPK);
             if (discardingSession != null && discardingSession.IsVerified == false)
             {
                 storingDAO.UpdateDiscardingSession(discardingSession.DiscardingSessionPK, true);
                 verification = storingDAO.CreateVerification(discardingSession.DiscardingSessionPK, userID, isApproved, true);
             }
             else
             {
                 return(Content(HttpStatusCode.Conflict, "DiscardingSession SAI!"));
             }
         }
         catch (Exception e)
         {
             if (discardingSession != null)
             {
                 storingDAO.UpdateDiscardingSession(discardingSession.DiscardingSessionPK, false);
             }
             return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
         }
         return(Content(HttpStatusCode.OK, "VERIFY ADJUSTING THÀNH CÔNG!"));
     }
     else
     {
         return(Content(HttpStatusCode.Conflict, "BẠN KHÔNG CÓ QUYỀN ĐỂ THỰC HIỆN VIỆC NÀY!"));
     }
 }
示例#4
0
        public double InStoredQuantity(int accessoryPK)
        {
            double     result     = 0;
            StoringDAO storingDAO = new StoringDAO();

            try
            {
                //List<PassedItem> passedItems = new List<PassedItem>();
                //Accessory accessory = db.Accessories.Find(accessoryPK);
                //// lấy restoredItems
                //List<RestoredItem> restoredItems = (from rI in db.RestoredItems
                //                                    where rI.AccessoryPK == accessory.AccessoryPK
                //                                    select rI).ToList();
                //// lấy passedItems
                //List<OrderedItem> orderedItems = (from oI in db.OrderedItems
                //                                  where oI.AccessoryPK == accessory.AccessoryPK
                //                                  select oI).ToList();
                //List<List<PackedItem>> packedItemss = new List<List<PackedItem>>();
                //foreach (var orderedItem in orderedItems)
                //{
                //    List<PackedItem> packedItems = (from pI in db.PackedItems
                //                                    where pI.OrderedItemPK == orderedItem.OrderedItemPK
                //                                    select pI).ToList();
                //    if (packedItems.Count > 0) packedItemss.Add(packedItems);
                //}
                //if (packedItemss.Count > 0)
                //{
                //    foreach (var packedItems in packedItemss)
                //    {
                //        foreach (var packedItem in packedItems)
                //        {
                //            ClassifiedItem classifiedItem = (from cI in db.ClassifiedItems
                //                                             where cI.PackedItemPK == packedItem.PackedItemPK
                //                                             select cI).FirstOrDefault();
                //            if (classifiedItem != null && classifiedItem.QualityState == 2)
                //            {
                //                PassedItem passedItem = (from p)
                //            }
                //        }
                //    }
                //}

                List <Entry> entries = (from e in db.Entries
                                        where e.AccessoryPK == accessoryPK
                                        select e).ToList();
                result = storingDAO.EntriesQuantity(entries);
            }
            catch (Exception e)
            {
                throw e;
            }
            return(result);
        }
示例#5
0
 public IHttpActionResult DiscardInventory(string boxID, int itemPK, double discardedQuantity, bool isRestored, string userID, string comment)
 {
     if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Staff"))
     {
         BoxDAO            boxDAO            = new BoxDAO();
         StoringDAO        storingDAO        = new StoringDAO();
         DiscardingSession discardingSession = null;
         try
         {
             Box       box  = boxDAO.GetBoxByBoxID(boxID);
             StoredBox sBox = boxDAO.GetStoredBoxbyBoxPK(box.BoxPK);
             if (sBox != null)
             {
                 List <Entry> entries = (from e in db.Entries
                                         where e.StoredBoxPK == sBox.StoredBoxPK && e.ItemPK == itemPK && e.IsRestored == isRestored
                                         select e).ToList();
                 discardingSession = storingDAO.CreateDiscardingSession(comment, false, userID);
                 if (discardedQuantity > storingDAO.EntriesQuantity(entries))
                 {
                     storingDAO.CreateDiscardEntry(sBox, itemPK, discardedQuantity, isRestored, discardingSession);
                 }
                 if (discardedQuantity < storingDAO.EntriesQuantity(entries))
                 {
                     storingDAO.CreateDiscardEntry(sBox, itemPK, discardedQuantity, isRestored, discardingSession);
                 }
                 else
                 {
                     return(Content(HttpStatusCode.Conflict, "SỐ LƯỢNG KHÔNG HỢP LỆ!"));
                 }
             }
             else
             {
                 if (discardingSession != null)
                 {
                     storingDAO.DeleteDiscardingSession(discardingSession.DiscardingSessionPK);
                 }
                 return(Content(HttpStatusCode.Conflict, "THÙNG KHÔNG HỢP LỆ!"));
             }
         }
         catch (Exception e)
         {
             return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
         }
         return(Content(HttpStatusCode.OK, "THAY ĐỔI KHO THÀNH CÔNG!"));
     }
     else
     {
         return(Content(HttpStatusCode.Conflict, "BẠN KHÔNG CÓ QUYỀN ĐỂ THỰC HIỆN VIỆC NÀY!"));
     }
 }
示例#6
0
        public IHttpActionResult StoreBoxBusiness(string boxID, string shelfID, string userID)
        {
            if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Staff"))
            {
                BoxDAO         boxDAO         = new BoxDAO();
                StoringDAO     storingItemDAO = new StoringDAO();
                StoredBox      storedBox      = null;
                StoringSession storingSession = null;
                try
                {
                    // khởi tạo
                    Box   box   = boxDAO.GetBoxByBoxID(boxID);
                    Shelf shelf = (from s in db.Shelves
                                   where s.ShelfID == shelfID && s.ShelfID != "InvisibleShelf"
                                   select s).FirstOrDefault();
                    if (boxDAO.GetUnstoredBoxbyBoxPK(box.BoxPK).IsIdentified&& !boxDAO.IsStored(box.BoxPK))
                    {
                        // chạy lệnh store box
                        storedBox      = storingItemDAO.CreateStoredBox(box.BoxPK, shelf.ShelfPK);
                        storingSession = storingItemDAO.CreateStoringSession(box.BoxPK, userID);
                        storingItemDAO.CreateEntriesUpdatePassedItem(box, storedBox, storingSession);
                    }
                    else
                    {
                        return(Content(HttpStatusCode.Conflict, "THÙNG KHÔNG HỢP LỆ"));
                    }
                }
                catch (Exception e)
                {
                    if (storedBox != null)
                    {
                        storingItemDAO.DeleteStoredBox(storedBox.StoredBoxPK);
                    }
                    if (storingSession != null)
                    {
                        storingItemDAO.DeleteStoringSession(storingSession.StoringSessionPK);
                    }
                    return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
                }


                return(Content(HttpStatusCode.OK, "STORE THÙNG THÀNH CÔNG"));
            }
            else
            {
                return(Content(HttpStatusCode.Conflict, "BẠN KHÔNG CÓ QUYỀN ĐỂ THỰC HIỆN VIỆC NÀY"));
            }
        }
        public IHttpActionResult GetAllRow()
        {
            List <Row> result     = new List <Row>();
            BoxDAO     boxDAO     = new BoxDAO();
            StoringDAO storingDAO = new StoringDAO();

            try
            {
                result = (from r in db.Rows
                          select r).ToList();
                return(Content(HttpStatusCode.OK, result));
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
            }
        }
示例#8
0
 public IHttpActionResult MoveStoredBox(string boxID, string shelfID, string userID)
 {
     if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Staff"))
     {
         BoxDAO        boxDAO        = new BoxDAO();
         StoringDAO    storingDAO    = new StoringDAO();
         MovingSession movingSession = null;
         try
         {
             Box       box       = boxDAO.GetBoxByBoxID(boxID);
             StoredBox storedBox = boxDAO.GetStoredBoxbyBoxPK(box.BoxPK);
             if (storedBox != null)
             {
                 Shelf shelf = boxDAO.GetShelfByShelfID(shelfID);
                 if (storedBox.ShelfPK != shelf.ShelfPK)
                 {
                     movingSession = storingDAO.CreateMovingSession(storedBox, shelf, userID);
                     storingDAO.UpdateStoredBoxShelfPK(storedBox.StoredBoxPK, shelf.ShelfPK);
                 }
                 else
                 {
                     return(Content(HttpStatusCode.Conflict, "KỆ KHÔNG HỢP LỆ!"));
                 }
             }
             else
             {
                 return(Content(HttpStatusCode.Conflict, "THÙNG KHÔNG HỢP LỆ!"));
             }
         }
         catch (Exception e)
         {
             if (movingSession != null)
             {
                 storingDAO.DeleteMovingSession(movingSession.MovingSessionPK);
             }
             return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
         }
         return(Content(HttpStatusCode.OK, "CHUYỂN THÙNG THÀNH CÔNG!"));
     }
     else
     {
         return(Content(HttpStatusCode.Conflict, "BẠN KHÔNG CÓ QUYỀN ĐỂ THỰC HIỆN VIỆC NÀY!"));
     }
 }
示例#9
0
        public IHttpActionResult GetEmptyBoxIDsPrepared([FromBody] List <Client_ItemPK_IsRestored_StoredBoxPK_IssuedQuantity> list)
        {
            List <string> boxIDs     = new List <string>();
            IssuingDAO    issuingDAO = new IssuingDAO();
            StoringDAO    storingDAO = new StoringDAO();

            try
            {
                Dictionary <int, Dictionary <Algo_itempk_isRestored, double> > Map = new Dictionary <int, Dictionary <Algo_itempk_isRestored, double> >();
                foreach (var items in list)
                {
                    foreach (var item in items.BoxAndQuantity)
                    {
                        if (!Map.ContainsKey(item.StoredBoxPK))
                        {
                            Dictionary <Algo_itempk_isRestored, double> item_isRestored_quantity = new Dictionary <Algo_itempk_isRestored, double>
                            {
                                { new Algo_itempk_isRestored(items.ItemPK, items.IsRestored), item.Quantity }
                            };

                            Map.Add(item.StoredBoxPK, item_isRestored_quantity);
                        }
                        else
                        {
                            Algo_itempk_isRestored temp = new Algo_itempk_isRestored(items.ItemPK, items.IsRestored);
                            if (!Map[item.StoredBoxPK].ContainsKey(temp))
                            {
                                Map[item.StoredBoxPK].Add(temp, item.Quantity);
                            }
                            else
                            {
                                Map[item.StoredBoxPK][temp] += item.Quantity;
                            }
                        }
                    }
                }
                foreach (var items in Map)
                {
                    bool IsEmpty = true;

                    HashSet <Algo_itempk_isRestored> tempHSAll    = new HashSet <Algo_itempk_isRestored>();
                    HashSet <Algo_itempk_isRestored> tempHSTaking = new HashSet <Algo_itempk_isRestored>();
                    // lấy hết item trong storebox ra
                    List <Entry> tempEntries = (from e in db.Entries
                                                where e.StoredBoxPK == items.Key
                                                select e).ToList();
                    foreach (var entry in tempEntries)
                    {
                        tempHSAll.Add(new Algo_itempk_isRestored(entry.ItemPK, entry.IsRestored));
                    }

                    foreach (var item in items.Value)
                    {
                        // lấy hết item trong lượt xuất
                        tempHSTaking.Add(new Algo_itempk_isRestored(item.Key.ItemPK, item.Key.IsRestored));
                        List <Entry> entries = (from e in db.Entries
                                                where e.StoredBoxPK == items.Key && e.ItemPK == item.Key.ItemPK && e.IsRestored == item.Key.IsRestored
                                                select e).ToList();
                        double tempQuantity = storingDAO.EntriesQuantity(entries);
                        if (item.Value > tempQuantity)
                        {
                            throw new Exception("SỐ LƯỢNG PREPARE VƯỢT QUÁ HÀNG TRONG KHO");
                        }
                        // nếu số lượng xuất nhỏ hơn số lượng trong box thì box còn hàng
                        if (item.Value < tempQuantity)
                        {
                            IsEmpty = false;
                        }
                    }
                    // nếu item trong store box nhiều hơn lượt xuất thì box còn hàng
                    if (tempHSAll.Count > tempHSTaking.Count)
                    {
                        IsEmpty = false;
                    }
                    if (IsEmpty)
                    {
                        StoredBox storedBox = db.StoredBoxes.Find(items.Key);
                        Box       box       = db.Boxes.Find(storedBox.BoxPK);
                        boxIDs.Add(box.BoxID);
                    }
                }
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
            }
            return(Content(HttpStatusCode.OK, boxIDs));
        }
        public IHttpActionResult GetAllSession(string userID)
        {
            List <Client_History_Flutter> result = new List <Client_History_Flutter>();
            BoxDAO     boxDAO     = new BoxDAO();
            StoringDAO storingDAO = new StoringDAO();

            try
            {
                {
                    List <IdentifyingSession> ss = db.IdentifyingSessions.ToList();
                    foreach (var item in ss)
                    {
                        result.Add(new Client_History_Flutter(item.IdentifyingSessionPK, "identifying", item.ExecutedDate));
                    }
                }
                {
                    List <ArrangingSession> ss = db.ArrangingSessions.ToList();
                    foreach (var item in ss)
                    {
                        result.Add(new Client_History_Flutter(item.ArrangingSessionPK, "arranging", item.ExecutedDate));
                    }
                }
                {
                    List <CountingSession> ss = db.CountingSessions.ToList();
                    foreach (var item in ss)
                    {
                        result.Add(new Client_History_Flutter(item.CountingSessionPK, "counting", item.ExecutedDate));
                    }
                }
                {
                    List <CheckingSession> ss = db.CheckingSessions.ToList();
                    foreach (var item in ss)
                    {
                        result.Add(new Client_History_Flutter(item.CheckingSessionPK, "checking", item.ExecutedDate));
                    }
                }
                {
                    List <TransferringSession> ss = db.TransferringSessions.ToList();
                    foreach (var item in ss)
                    {
                        result.Add(new Client_History_Flutter(item.TransferingSessionPK, "transferring", item.ExecutedDate));
                    }
                }
                {
                    List <MovingSession> ss = db.MovingSessions.ToList();
                    foreach (var item in ss)
                    {
                        result.Add(new Client_History_Flutter(item.MovingSessionPK, "moving", item.ExecutedDate));
                    }
                }
                {
                    List <IssuingSession> ss = db.IssuingSessions.ToList();
                    foreach (var item in ss)
                    {
                        result.Add(new Client_History_Flutter(item.IssuingSessionPK, "issuing", item.ExecutedDate));
                    }
                }
                {
                    List <ReceivingSession> ss = db.ReceivingSessions.ToList();
                    foreach (var item in ss)
                    {
                        result.Add(new Client_History_Flutter(item.ReceivingSessionPK, "receiving", item.ExecutedDate));
                    }
                }
                {
                    List <AdjustingSession> ss = db.AdjustingSessions.ToList();
                    foreach (var item in ss)
                    {
                        result.Add(new Client_History_Flutter(item.AdjustingSessionPK, "adjusting", item.ExecutedDate));
                    }
                }
                {
                    List <DiscardingSession> ss = db.DiscardingSessions.ToList();
                    foreach (var item in ss)
                    {
                        result.Add(new Client_History_Flutter(item.DiscardingSessionPK, "discarding", item.ExecutedDate));
                    }
                }
                {
                    List <StoringSession> ss = db.StoringSessions.ToList();
                    foreach (var item in ss)
                    {
                        result.Add(new Client_History_Flutter(item.StoringSessionPK, "storing", item.ExecutedDate));
                    }
                }
                {
                    List <ClassifyingSession> ss = db.ClassifyingSessions.ToList();
                    foreach (var item in ss)
                    {
                        result.Add(new Client_History_Flutter(item.ClassifyingSessionPK, "classifying", item.ExecutedDate));
                    }
                }
                {
                    List <ReturningSession> ss = db.ReturningSessions.ToList();
                    foreach (var item in ss)
                    {
                        result.Add(new Client_History_Flutter(item.ReturningSessionPK, "returning", item.ExecutedDate));
                    }
                }
                {
                    List <ConfirmingSession> ss = db.ConfirmingSessions.ToList();
                    foreach (var item in ss)
                    {
                        result.Add(new Client_History_Flutter(item.ConfirmingSessionPK, "confirming", item.ExecutedDate));
                    }
                }
                {
                    List <Request> containers = db.Requests.ToList();
                    foreach (var item in containers)
                    {
                        result.Add(new Client_History_Flutter(item.RequestPK, "request", item.DateCreated));
                    }
                }
                {
                    List <Restoration> containers = db.Restorations.ToList();
                    foreach (var item in containers)
                    {
                        result.Add(new Client_History_Flutter(item.RestorationPK, "restoration", item.DateCreated));
                    }
                }

                return(Content(HttpStatusCode.OK, result));
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
            }
        }
        public IHttpActionResult GetItemByRowID(string rowID)
        {
            BoxDAO     boxDAO     = new BoxDAO();
            StoringDAO storingDAO = new StoringDAO();

            try
            {
                Client_InBoxItems_Shelf <List <string> > result;
                List <string> shelfIDs = new List <string>();
                List <Shelf>  shelves;
                Row           row = (from r in db.Rows
                                     where r.RowID == rowID
                                     select r).FirstOrDefault();
                if (row != null || rowID == "TẠM THỜI")
                {
                    if (rowID == "TẠM THỜI")
                    {
                        shelves = (from sh in db.Shelves
                                   where sh.RowPK == null && sh.ShelfID != "InvisibleShelf"
                                   select sh).ToList();
                    }
                    else
                    {
                        shelves = (from sh in db.Shelves
                                   where sh.RowPK == row.RowPK && sh.ShelfID != "InvisibleShelf"
                                   select sh).ToList();
                    }
                    Dictionary <KeyValuePair <int, bool>, Client_InBoxItem> client_InBoxItems = new Dictionary <KeyValuePair <int, bool>, Client_InBoxItem>();
                    foreach (var shelf in shelves)
                    {
                        List <StoredBox> sBoxes = (from sB in db.StoredBoxes
                                                   where sB.ShelfPK == shelf.ShelfPK
                                                   select sB).ToList();

                        shelfIDs.Add(shelf.ShelfID);
                        foreach (var sBox in sBoxes)
                        {
                            // Get list inBoxItem
                            List <Entry> entries = (from e in db.Entries
                                                    where e.StoredBoxPK == sBox.StoredBoxPK
                                                    select e).ToList();

                            // Hiện thực cặp value ko được trùng 2 key là itemPK và isRestored
                            HashSet <KeyValuePair <int, bool> > listItem = new HashSet <KeyValuePair <int, bool> >();
                            foreach (var entry in entries)
                            {
                                listItem.Add(new KeyValuePair <int, bool>(entry.ItemPK, entry.IsRestored));
                            }
                            foreach (var item in listItem)
                            {
                                List <Entry> tempEntries = new List <Entry>();
                                foreach (var entry in entries)
                                {
                                    if (entry.ItemPK == item.Key && entry.IsRestored == item.Value)
                                    {
                                        tempEntries.Add(entry);
                                    }
                                }
                                if (tempEntries.Count > 0 && storingDAO.EntriesQuantity(tempEntries) > 0)
                                {
                                    Entry        entry = tempEntries[0];
                                    PassedItem   passedItem;
                                    RestoredItem restoredItem;
                                    if (item.Value)
                                    {
                                        restoredItem = db.RestoredItems.Find(item.Key);
                                        Restoration restoration = db.Restorations.Find(restoredItem.RestorationPK);
                                        Accessory   accessory   = db.Accessories.Find(restoredItem.AccessoryPK);
                                        if (!client_InBoxItems.ContainsKey(item))
                                        {
                                            client_InBoxItems.Add(item, new Client_InBoxItem(accessory, restoration.RestorationID,
                                                                                             storingDAO.EntriesQuantity(tempEntries), restoredItem.RestoredItemPK, item.Value));
                                        }
                                        else
                                        {
                                            client_InBoxItems[item].InBoxQuantity += storingDAO.EntriesQuantity(tempEntries);
                                        }
                                    }
                                    else
                                    {
                                        passedItem = db.PassedItems.Find(item.Key);
                                        ClassifiedItem classifiedItem = db.ClassifiedItems.Find(passedItem.ClassifiedItemPK);
                                        PackedItem     packedItem     = db.PackedItems.Find(classifiedItem.PackedItemPK);
                                        // lấy pack ID
                                        Pack pack = db.Packs.Find(packedItem.PackPK);

                                        // lấy phụ liệu tương ứng
                                        OrderedItem orderedItem = db.OrderedItems.Find(packedItem.OrderedItemPK);

                                        Accessory accessory = db.Accessories.Find(orderedItem.AccessoryPK);
                                        if (!client_InBoxItems.ContainsKey(item))
                                        {
                                            client_InBoxItems.Add(item, new Client_InBoxItem(accessory, pack.PackID,
                                                                                             storingDAO.EntriesQuantity(tempEntries), passedItem.PassedItemPK, item.Value));
                                        }
                                        else
                                        {
                                            client_InBoxItems[item].InBoxQuantity += storingDAO.EntriesQuantity(tempEntries);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    result = new Client_InBoxItems_Shelf <List <string> >(shelfIDs, client_InBoxItems.Values.ToList());
                    return(Content(HttpStatusCode.OK, result));
                }
                else
                {
                    return(Content(HttpStatusCode.Conflict, "ĐỐI TƯỢNG KHÔNG TỒN TẠI"));
                }
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
            }
        }
        public IHttpActionResult GetItemByBoxID(string boxID)
        {
            BoxDAO     boxDAO     = new BoxDAO();
            StoringDAO storingDAO = new StoringDAO();

            try
            {
                Box box = boxDAO.GetBoxByBoxID(boxID);
                if (box != null)
                {
                    StoredBox   sBox = boxDAO.GetStoredBoxbyBoxPK(box.BoxPK);
                    UnstoredBox uBox = boxDAO.GetUnstoredBoxbyBoxPK(box.BoxPK);
                    // Nếu box chưa identify
                    if (uBox.IsIdentified)
                    {
                        // nếu box chưa được store
                        if (!(boxDAO.IsStored(box.BoxPK)))
                        {
                            List <Client_IdentifiedItemRead> client_IdentifiedItems = new List <Client_IdentifiedItemRead>();
                            List <IdentifiedItem>            identifiedItems;
                            identifiedItems = (from iI in db.IdentifiedItems.OrderByDescending(unit => unit.PackedItemPK)
                                               where iI.UnstoredBoxPK == uBox.UnstoredBoxPK
                                               select iI).ToList();

                            foreach (var identifiedItem in identifiedItems)
                            {
                                PackedItem packedItem = db.PackedItems.Find(identifiedItem.PackedItemPK);
                                // lấy pack ID
                                Pack pack = db.Packs.Find(packedItem.PackPK);

                                // lấy phụ liệu tương ứng
                                OrderedItem orderedItem = db.OrderedItems.Find(packedItem.OrderedItemPK);

                                Accessory accessory = db.Accessories.Find(orderedItem.AccessoryPK);
                                // lấy qualityState
                                ClassifiedItem classifiedItem = (from cI in db.ClassifiedItems
                                                                 where cI.PackedItemPK == packedItem.PackedItemPK
                                                                 select cI).FirstOrDefault();
                                int?qualityState = null;
                                if (classifiedItem != null)
                                {
                                    qualityState = classifiedItem.QualityState;
                                }
                                client_IdentifiedItems.Add(new Client_IdentifiedItemRead(identifiedItem, accessory, pack.PackID, qualityState));
                            }
                            return(Content(HttpStatusCode.OK, client_IdentifiedItems));
                        }
                        else
                        {
                            Client_InBoxItems_Shelf <Client_Shelf> result;
                            Client_Shelf            client_Shelf;
                            List <Client_InBoxItem> client_InBoxItems = new List <Client_InBoxItem>();

                            Shelf shelf = db.Shelves.Find(sBox.ShelfPK);
                            Row   row   = db.Rows.Find(shelf.RowPK);
                            client_Shelf = new Client_Shelf(shelf.ShelfID, row.RowID);

                            // Get list inBoxItem
                            List <Entry> entries = (from e in db.Entries
                                                    where e.StoredBoxPK == sBox.StoredBoxPK
                                                    select e).ToList();
                            HashSet <KeyValuePair <int, bool> > listItemPK = new HashSet <KeyValuePair <int, bool> >();
                            foreach (var entry in entries)
                            {
                                listItemPK.Add(new KeyValuePair <int, bool>(entry.ItemPK, entry.IsRestored));
                            }
                            foreach (var itemPK in listItemPK)
                            {
                                List <Entry> tempEntries = new List <Entry>();
                                foreach (var entry in entries)
                                {
                                    if (entry.ItemPK == itemPK.Key && entry.IsRestored == itemPK.Value)
                                    {
                                        tempEntries.Add(entry);
                                    }
                                }
                                if (tempEntries.Count > 0 && storingDAO.EntriesQuantity(tempEntries) > 0)
                                {
                                    Entry        entry = tempEntries[0];
                                    PassedItem   passedItem;
                                    RestoredItem restoredItem;
                                    if (entry.IsRestored)
                                    {
                                        restoredItem = db.RestoredItems.Find(entry.ItemPK);
                                        Restoration restoration = db.Restorations.Find(restoredItem.RestorationPK);
                                        Accessory   accessory   = db.Accessories.Find(restoredItem.AccessoryPK);
                                        client_InBoxItems.Add(new Client_InBoxItem(accessory, restoration.RestorationID, storingDAO.EntriesQuantity(tempEntries), restoredItem.RestoredItemPK, true));
                                    }
                                    else
                                    {
                                        passedItem = db.PassedItems.Find(entry.ItemPK);
                                        ClassifiedItem classifiedItem = db.ClassifiedItems.Find(passedItem.ClassifiedItemPK);
                                        PackedItem     packedItem     = db.PackedItems.Find(classifiedItem.PackedItemPK);
                                        // lấy pack ID
                                        Pack pack = (from p in db.Packs
                                                     where p.PackPK == packedItem.PackPK
                                                     select p).FirstOrDefault();

                                        // lấy phụ liệu tương ứng
                                        OrderedItem orderedItem = (from oI in db.OrderedItems
                                                                   where oI.OrderedItemPK == packedItem.OrderedItemPK
                                                                   select oI).FirstOrDefault();

                                        Accessory accessory = (from a in db.Accessories
                                                               where a.AccessoryPK == orderedItem.AccessoryPK
                                                               select a).FirstOrDefault();
                                        client_InBoxItems.Add(new Client_InBoxItem(accessory, pack.PackID, storingDAO.EntriesQuantity(tempEntries), passedItem.PassedItemPK, false));
                                    }
                                }
                            }
                            result = new Client_InBoxItems_Shelf <Client_Shelf>(client_Shelf, client_InBoxItems);
                            return(Content(HttpStatusCode.OK, result));
                        }
                    }
                    else
                    {
                        return(Content(HttpStatusCode.Conflict, "THÙNG NÀY CHƯA ĐƯỢC GHI NHẬN"));
                    }
                }
                else
                {
                    return(Content(HttpStatusCode.Conflict, "ĐỐI TƯỢNG KHÔNG TỒN TẠI"));
                }
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
            }
        }
示例#13
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);
        }
示例#14
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);
        }
示例#15
0
 public IHttpActionResult TransferStoredItems(string boxFromID, string boxToID, string userID, [FromBody] List <Client_ItemPK_TransferQuantity_IsRestored> list)
 {
     if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Staff"))
     {
         BoxDAO              boxDAO              = new BoxDAO();
         StoringDAO          storingDAO          = new StoringDAO();
         TransferringSession transferringSession = null;
         try
         {
             if (boxFromID != boxToID)
             {
                 // lấy inBoxQuantity
                 Box       boxFrom  = boxDAO.GetBoxByBoxID(boxFromID);
                 StoredBox sBoxFrom = boxDAO.GetStoredBoxbyBoxPK(boxFrom.BoxPK);
                 Box       boxTo    = boxDAO.GetBoxByBoxID(boxToID);
                 StoredBox sBoxTo   = boxDAO.GetStoredBoxbyBoxPK(boxTo.BoxPK);
                 if (sBoxFrom == null)
                 {
                     return(Content(HttpStatusCode.Conflict, "BOX KHÔNG HỢP LỆ!"));
                 }
                 List <Entry> entries = (from e in db.Entries
                                         where e.StoredBoxPK == sBoxFrom.StoredBoxPK
                                         select e).ToList();
                 foreach (var item in list)
                 {
                     List <Entry> tempEntries = new List <Entry>();
                     foreach (var entry in entries)
                     {
                         if (entry.ItemPK == item.ItemPK)
                         {
                             tempEntries.Add(entry);
                         }
                     }
                     if (item.TransferQuantity > storingDAO.EntriesQuantity(tempEntries))
                     {
                         return(Content(HttpStatusCode.Conflict, "SỐ LƯỢNG KHÔNG HỢP LỆ!"));
                     }
                 }
                 transferringSession = storingDAO.CreateTransferingSession(boxFromID, boxToID, userID);
                 storingDAO.CreateInAndOutEntry(list, sBoxFrom, sBoxTo, transferringSession);
             }
             else
             {
                 return(Content(HttpStatusCode.Conflict, "BOX KHÔNG HỢP LỆ!"));
             }
             return(Content(HttpStatusCode.OK, "TRANSFER THÀNH CÔNG!"));
         }
         catch (Exception e)
         {
             if (transferringSession != null)
             {
                 storingDAO.DeleteTransferingSession(transferringSession.TransferingSessionPK);
             }
             return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
         }
     }
     else
     {
         return(Content(HttpStatusCode.Conflict, "BẠN KHÔNG CÓ QUYỀN ĐỂ THỰC HIỆN VIỆC NÀY"));
     }
 }
示例#16
0
        public IHttpActionResult GetInBoxItemByBoxID(string boxID)
        {
            Client_InBoxItems_Shelf <Client_Shelf> result;
            Client_Shelf            client_Shelf;
            List <Client_InBoxItem> client_InBoxItems = new List <Client_InBoxItem>();
            BoxDAO     boxDAO     = new BoxDAO();
            StoringDAO storingDAO = new StoringDAO();

            try
            {
                // Get client Shelf
                Box       box  = boxDAO.GetBoxByBoxID(boxID);
                StoredBox sBox = boxDAO.GetStoredBoxbyBoxPK(box.BoxPK);
                if (sBox == null)
                {
                    return(Content(HttpStatusCode.Conflict, "BOX KHÔNG HỢP LỆ!"));
                }
                Shelf shelf = db.Shelves.Find(sBox.ShelfPK);
                Row   row   = db.Rows.Find(shelf.RowPK);
                client_Shelf = new Client_Shelf(shelf.ShelfID, row.RowID);

                // Get list inBoxItem
                List <Entry> entries = (from e in db.Entries
                                        where e.StoredBoxPK == sBox.StoredBoxPK
                                        select e).ToList();

                // Hiện thực cặp value ko được trùng 2 key là itemPK và isRestored
                HashSet <KeyValuePair <int, bool> > listItemPK = new HashSet <KeyValuePair <int, bool> >();
                foreach (var entry in entries)
                {
                    listItemPK.Add(new KeyValuePair <int, bool>(entry.ItemPK, entry.IsRestored));
                }
                foreach (var itemPK in listItemPK)
                {
                    List <Entry> tempEntries = new List <Entry>();
                    foreach (var entry in entries)
                    {
                        if (entry.ItemPK == itemPK.Key && entry.IsRestored == itemPK.Value)
                        {
                            tempEntries.Add(entry);
                        }
                    }
                    if (tempEntries.Count > 0)
                    {
                        Entry        entry = tempEntries[0];
                        PassedItem   passedItem;
                        RestoredItem restoredItem;
                        if (entry.IsRestored)
                        {
                            restoredItem = db.RestoredItems.Find(entry.ItemPK);
                            Restoration restoration = db.Restorations.Find(restoredItem.RestorationPK);
                            Accessory   accessory   = db.Accessories.Find(restoredItem.AccessoryPK);
                            client_InBoxItems.Add(new Client_InBoxItem(accessory, restoration.RestorationID, storingDAO.EntriesQuantity(tempEntries), restoredItem.RestoredItemPK, true));
                        }
                        else
                        {
                            passedItem = db.PassedItems.Find(entry.ItemPK);
                            ClassifiedItem classifiedItem = db.ClassifiedItems.Find(passedItem.ClassifiedItemPK);
                            PackedItem     packedItem     = db.PackedItems.Find(classifiedItem.PackedItemPK);
                            // lấy pack ID
                            Pack pack = (from p in db.Packs
                                         where p.PackPK == packedItem.PackPK
                                         select p).FirstOrDefault();

                            // lấy phụ liệu tương ứng
                            OrderedItem orderedItem = (from oI in db.OrderedItems
                                                       where oI.OrderedItemPK == packedItem.OrderedItemPK
                                                       select oI).FirstOrDefault();

                            Accessory accessory = (from a in db.Accessories
                                                   where a.AccessoryPK == orderedItem.AccessoryPK
                                                   select a).FirstOrDefault();
                            client_InBoxItems.Add(new Client_InBoxItem(accessory, pack.PackID, storingDAO.EntriesQuantity(tempEntries), passedItem.PassedItemPK, false));
                        }
                    }
                }
                result = new Client_InBoxItems_Shelf <Client_Shelf>(client_Shelf, client_InBoxItems);
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
            }
            return(Content(HttpStatusCode.OK, result));
        }