コード例 #1
0
 public void DeleteStoringSession(int storingSessionPK)
 {
     try
     {
         StoringSession storingSession = db.StoringSessions.Find(storingSessionPK);
         db.StoringSessions.Remove(storingSession);
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
コード例 #2
0
 public void CreateEntriesUpdatePassedItem(Box box, StoredBox storedBox, StoringSession storingSession)
 {
     try
     {
         IdentifyItemDAO       identifyItemDAO = new IdentifyItemDAO();
         BoxDAO                boxDAO          = new BoxDAO();
         UnstoredBox           unstoredBox     = boxDAO.GetUnstoredBoxbyBoxPK(box.BoxPK);
         List <IdentifiedItem> identifiedItems = (from iI in db.IdentifiedItems
                                                  where iI.UnstoredBoxPK == unstoredBox.UnstoredBoxPK
                                                  select iI).ToList();
         foreach (var identifiedItem in identifiedItems)
         {
             PackedItem packedItem = db.PackedItems.Find(identifiedItem.PackedItemPK);
             // lấy accessory
             OrderedItem orderedItem = db.OrderedItems.Find(packedItem.OrderedItemPK);
             Accessory   accessory   = db.Accessories.Find(orderedItem.AccessoryPK);
             //
             ClassifiedItem classifiedItem = (from cI in db.ClassifiedItems
                                              where cI.PackedItemPK == packedItem.PackedItemPK
                                              select cI).FirstOrDefault();
             if (classifiedItem != null)
             {
                 PassedItem passedItem = (from pI in db.PassedItems
                                          where pI.ClassifiedItemPK == classifiedItem.ClassifiedItemPK
                                          select pI).FirstOrDefault();
                 if (passedItem != null)
                 {
                     UpdatePassedItem(passedItem.PassedItemPK);
                     // tạo entry
                     Entry entry = new Entry(storedBox, "Storing", storingSession.StoringSessionPK, false,
                                             identifyItemDAO.ActualQuantity(identifiedItem.IdentifiedItemPK), passedItem.PassedItemPK, accessory);
                     db.Entries.Add(entry);
                 }
                 else
                 {
                     throw new Exception("ITEM KHÔNG HỢP LỆ");
                 }
             }
             else
             {
                 throw new Exception("ITEM KHÔNG HỢP LỆ");
             }
         }
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
コード例 #3
0
 public StoringSession CreateStoringSession(int boxPK, string userID)
 {
     try
     {
         // tạo storedBox
         StoringSession storingSession = new StoringSession(boxPK, userID);
         db.StoringSessions.Add(storingSession);
         db.SaveChanges();
         return(db.StoringSessions.OrderByDescending(unit => unit.StoringSessionPK).FirstOrDefault());
     }
     catch (Exception e)
     {
         throw e;
     }
 }
コード例 #4
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"));
            }
        }