public void DispatchOrders(string id) { WarehouseBusinessLayer wbl = new WarehouseBusinessLayer(); int warehouseId = wbl.getWarehouseId(Convert.ToInt32(Session["UserID"])); int oid = Convert.ToInt32(id); WarehouseDBEntities wde = new WarehouseDBEntities(); List <Order> orders = wde.Orders.Where(a => a.warehouseId == warehouseId && a.orderId == oid && (a.orderStatus == "Unseen" || a.orderStatus == "Seen")).OrderBy(a => a.totalOrderQuanitity).ToList(); int i = 0; //Sorting items according to quantity foreach (var order in orders) { var neworder = order.item_Order; neworder = neworder.OrderBy(a => a.quantity).ToList(); orders.ElementAt(i).item_Order = neworder; i++; } Slotting slotting = new Slotting(); List <Item_Warehouse> itemWarehouse = wde.Item_Warehouse.Where(a => a.warehouseId == warehouseId).ToList(); List <Shelf> shelfs = wde.Shelves.Where(a => a.warehouse_id == warehouseId).ToList(); Dictionary <int, List <ShelfItems> > shelfItems = new Dictionary <int, List <ShelfItems> >(); foreach (Shelf shelf in shelfs) { List <ShelfItems> shelves = slotting.covert_to_object(shelf.shelfItems); shelfItems.Add(shelf.id, shelves); } List <Item> items = new List <Item>(); foreach (Item_Warehouse item_Warehouse in itemWarehouse) { items.Add(item_Warehouse.Item); } OrderPicking orderPick = new OrderPicking(); orderPick.getFirstOrder(orders, shelfItems); }
public void generateOrderIntruction(Order order) { List <String> instruction = new List <string>(); JavaScriptSerializer jsonSerialiser = new JavaScriptSerializer(); WarehouseDBEntities wdb = new WarehouseDBEntities(); OrderBusinessLayer wbl = new OrderBusinessLayer(); string instructionString = ""; /** * * Go to Shelf "shelf id" and pick "item name" from slots "start slot" to "end slot" and send them to depot **/ foreach (var inst in dispatchInstructions.Distinct()) { Shelf shelf = wdb.Shelves.Find(inst.shelfid); string[] shelveName = shelf.shelfName.Split('s'); string shelves = "s" + shelveName[1]; shelfRetrieval.Add(shelves); instructionString = "Go to shelf " + shelves + " and pick " + inst.itemname + " from slots " + inst.startslot + " to " + inst.endslot + " and send them to depot"; instruction.Add(instructionString); Slotting s = new Slotting(); List <ShelfItems> shelfItems = s.covert_to_object(shelf.shelfItems); List <ShelfItems> copyShelfItems = new List <ShelfItems>(); copyShelfItems.AddRange(shelfItems); bool with = false; int i = 0; foreach (ShelfItems shelve in shelfItems) { if (shelve.slot_id == inst.startslot || with == true) { with = true; copyShelfItems[i].item_id = -1; copyShelfItems[i].status = 0; copyShelfItems[i].item_name = ""; copyShelfItems[i].expiry_date = ""; if (shelve.slot_id == inst.endslot) { with = false; } } i++; } string updatedString = jsonSerialiser.Serialize(copyShelfItems); wbl.updateShelf(inst.shelfid, updatedString); } string json = jsonSerialiser.Serialize(instruction); int maxDispatchId = 1; try { maxDispatchId = wdb.Orders.Max(a => a.dispatchNo).Value + 1; } catch (Exception ex) { maxDispatchId = 1; } wbl.updateOrder(order.orderId, json, maxDispatchId); WarehouseDBEntities wde = new WarehouseDBEntities(); Order orders = wde.Orders.Find(order.orderId); orders.shelfRetrieval = jsonSerialiser.Serialize(shelfRetrieval.Distinct().ToList()); wde.Entry(orders).State = System.Data.Entity.EntityState.Modified; wde.SaveChanges(); }
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")); }