Beispiel #1
0
        public void generateInstructions(List <Shelf> shelfList)
        {
            bool   shelffound = false;
            string shelfName  = "-1";
            List <Shelfandshelfitems> shelfandshelfitems = new List <Shelfandshelfitems>();
            List <ShelfItems>         sitemsList         = new List <ShelfItems>();
            Shelfandshelfitems        ssi = new Shelfandshelfitems();
            ArrayList al = new ArrayList();

            foreach (var shelf in shelfList)
            {
                for (int i = 0; i < instructions.Count; i++)
                {
                    if (instructions[i].shelfid == shelf.id)
                    {
                        if (shelffound == false)
                        {
                            shelfName  = shelf.shelfName;
                            sitemsList = covert_to_object(shelf.shelfItems);
                            shelffound = true;
                        }
                        for (int a = instructions[i].startslot - 1; a < instructions[i].endslot; a++)
                        {
                            sitemsList[a].item_id   = instructions[i].itemid;
                            sitemsList[a].item_name = instructions[i].itemname;
                        }
                        try
                        {
                            if (instructions[i + 1].shelfid != instructions[i].shelfid)
                            {
                                ssi.shelfitemslist = sitemsList;
                                ssi.id             = shelf.id;
                                shelfandshelfitems.Add(ssi);
                                shelffound = false;
                            }
                        }
                        catch (Exception e)
                        {
                            ssi.shelfitemslist = sitemsList;
                            ssi.id             = shelf.id;
                            shelfandshelfitems.Add(ssi);
                            shelffound = false;
                            continue;
                        }
                    }
                }
            }
            SlottingBusinessLayer sbl = new SlottingBusinessLayer();

            foreach (var z in shelfandshelfitems)
            {
                int shelfid              = z.id;
                List <ShelfItems>    si  = z.shelfitemslist;
                JavaScriptSerializer jss = new JavaScriptSerializer();
                string output            = jss.Serialize(si);
                sbl.updateShelfSlotting(shelfid, output);
            }
            string oneI;

            foreach (var i in instructions)
            {
                WarehouseDBEntities wdb = new WarehouseDBEntities();
                string   sName          = wdb.Shelves.FirstOrDefault(s => s.id == i.shelfid).shelfName;
                string[] shelveName     = sName.Split('s');
                string   shelve         = "s" + shelveName[1];
                oneI = "Place " + i.itemname + " on shelf " + shelve + ", from slot " + i.startslot + " to slot " + i.endslot;

                instructionsList.Add(oneI);
                shelfInserted.Add(shelve);
            }
            JavaScriptSerializer jsss = new JavaScriptSerializer();
            string output2            = jsss.Serialize(instructionsList);
        }
Beispiel #2
0
        public ActionResult Save(List <Item> ware, List <Item_Consignment> itemcon, List <Consignment> con)
        {
            int conid = -1;
            List <ItemsSlotter> isl = new List <ItemsSlotter>();

            foreach (Consignment conn in con)
            {
                WarehouseBusinessLayer wbl = new WarehouseBusinessLayer();
                int warehouseIdd           = wbl.getWarehouseId(Convert.ToInt32(Session["UserID"]));
                conn.warehouseId       = warehouseIdd;
                conn.consignmentStatus = "Added";
                try
                {
                    conid = db.Consignments.Max(u => u.id) + 1;
                }
                catch (Exception ex) { conid = 1; }
                conn.id = conid;
                cbl.addConsignment(conn);


                int index = 0;
                foreach (Item_Consignment ic in itemcon)
                {
                    Item items = ware.ElementAt(index);
                    ic.itemId = getNewOrOldId(items);

                    ItemsSlotter itemslot = new ItemsSlotter();

                    itemslot.item_id  = ic.itemId;
                    itemslot.quantity = (int)ic.quantity;
                    //   itemslot.expiry_date = ic.expiry.Value.ToShortDateString();

                    Item it = db.Items.FirstOrDefault(a => a.id == itemslot.item_id);
                    itemslot.item_name = it.itemName;



                    bool val = db.Item_Warehouse.Any(o => o.itemId == ic.itemId && o.warehouseId == warehouseIdd);
                    if (val == true)
                    {
                        Item_Warehouse iw = db.Item_Warehouse.FirstOrDefault(a => a.itemId == ic.itemId && a.warehouseId == warehouseIdd);
                        iw.quantity += ic.quantity;
                        cbl.updateItemWarehouse(iw);
                        itemslot.quantity = (int)iw.quantity;
                        // found = true;
                        //TODO: ADO.NET CODE
                    }
                    else
                    {
                        Item_Warehouse iw = new Item_Warehouse();
                        iw.warehouseId = warehouseIdd;
                        iw.itemId      = ic.itemId;
                        iw.quantity    = ic.quantity;
                        iw.orders      = 0;
                        cbl.addItemWarehouse(iw);
                        itemslot.quantity = (int)iw.quantity;
                    }

                    ic.consignmentId = conid;
                    cbl.addItem_Consignment(ic);

                    isl.Add(itemslot);
                    index++;
                }


                //Yaha pe SLotting Horae ha
                List <Shelf> newShelf = db.Shelves.Where(a => a.warehouse_id == warehouseIdd).ToList();
                Slotting     slotting = new Slotting();
                bool         isError  = slotting.slotting(newShelf, isl);
                if (isError)
                {
                    ViewBag.throwError = "Unfortunately, there is no space in warehouse for the new items";
                }
                List <String>        instructionList = slotting.instructionsList;
                JavaScriptSerializer jss             = new JavaScriptSerializer();
                string inst = jss.Serialize(instructionList);
                SlottingBusinessLayer sbl = new SlottingBusinessLayer();
                sbl.UpdateConsignmentInstruction(conid, inst);
                List <String> shelfInserted     = slotting.shelfInserted.Distinct().ToList();
                string        insertedShelfJSON = jss.Serialize(shelfInserted);

                WarehouseDBEntities wdb         = new WarehouseDBEntities();
                Consignment         consignment = wdb.Consignments.Find(conid);
                consignment.consignmentStatus = "Added";
                consignment.shelfInserted     = insertedShelfJSON;
                wdb.Entry(consignment).State  = EntityState.Modified;
                wdb.SaveChanges();

                Session["consignmentID"] = conid;

                break;
            }


            return(RedirectToAction("LoggedIn", "Account"));
        }