public RedirectToRouteResult CompleteConsignment(int?id) { Consignment consi = wde.Consignments.Find(id); WorkerLogs wl = new WorkerLogs(); Worker worker = wde.Workers.Find(Convert.ToInt32(Session["WorkerID"])); JavaScriptSerializer jss = new JavaScriptSerializer(); if (worker.workerLogs != null) { List <WorkerLogs> workerlogs = Newtonsoft.Json.JsonConvert.DeserializeObject <List <WorkerLogs> >(worker.workerLogs); wl.date = DateTime.Now.ToShortDateString(); wl.time = DateTime.Now.ToShortTimeString(); wl.description = "Completed Consignment of " + consi.supplier; workerlogs.Add(wl); string jsObj = jss.Serialize(workerlogs); worker.workerLogs = jsObj; wde.SaveChanges(); } consi.consignmentStatus = "Completed"; wde.Entry(consi).State = EntityState.Modified; wde.SaveChanges(); return(RedirectToAction("ConsignmentsSlotted")); }
/// <summary> /// Add or edit product in warehouse /// </summary> /// <param name="product">Product to add or edit</param> /// <returns>Added or updated product</returns> public Product AddProduct(Product product) { try { using (WarehouseDBEntities context = new WarehouseDBEntities()) { if (product.ProductID == 0) { //add product Product p = new Product(); p.ProductName = product.ProductName; p.ProductCode = product.ProductCode; p.Quantity = product.Quantity; p.Price = product.Price; p.Stored = "not stored"; context.Products.Add(p); context.SaveChanges(); product.ProductID = p.ProductID; action = "added"; return(product); } else { //edit product Product productToEdit = (from x in context.Products where x.ProductID == product.ProductID select x).FirstOrDefault(); productToEdit.ProductName = product.ProductName; productToEdit.ProductCode = product.ProductCode; productToEdit.Price = product.Price; productToEdit.Quantity = product.Quantity; productToEdit.ProductID = product.ProductID; context.SaveChanges(); action = "updated"; return(product); } } } catch (Exception ex) { Console.WriteLine(ex.Message.ToString()); return(null); } }
/// <summary> /// Method for change of product Stored status /// </summary> /// <param name="product">product for storing</param> public void StoreProduct(tblProduct product) { try { using (WarehouseDBEntities context = new WarehouseDBEntities()) { tblProduct productToStore = (from x in context.tblProducts where x.ID == product.ID select x).First(); List <tblProduct> storedList = GetStoredProducts(); int counter = 0; foreach (var item in storedList) { counter += item.Quantity; } //check quantity if its less than 100 it can be stored if (productToStore.Stored == "no" && (counter + productToStore.Quantity <= 100)) { //change status to yes productToStore.Stored = "yes"; context.SaveChanges(); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); } }
public ActionResult RegisterCustomer(string fullname, string email, string number, string organizationname, string organizationaddress, string username, string password, string password2, string[] warehouses) { WarehouseBusinessLayer wbl = new WarehouseBusinessLayer(); Customer useracc = new Customer(); useracc.fullName = fullname; useracc.email = email; useracc.contact = number; useracc.password = password; useracc.userName = username; useracc.organizationAddress = organizationaddress; useracc.organizationName = organizationname; useracc.selectedWarehouse = JsonConvert.SerializeObject(warehouses); WarehouseDBEntities wdb = new WarehouseDBEntities(); wdb.Customers.Add(useracc); wdb.SaveChanges(); Session["UserID"] = wbl.getRecentlyId(); Session["Username"] = username; return(RedirectToAction("LoggedIn")); }
public ActionResult DeleteItem(List <Item_Consignment> itemcon) { Item_Consignment it = itemcon.ElementAt(0); Item_Consignment ic = db.Item_Consignment.FirstOrDefault(i => i.consignmentId == it.consignmentId && i.itemId == it.itemId); db.Item_Consignment.Remove(ic); db.SaveChanges(); int count = db.Item_Consignment.Where(u => u.consignmentId == ic.consignmentId).Count(); ConsignmentBusinessLayer cbl = new ConsignmentBusinessLayer(); cbl.updateItemsCount(count, ic.consignmentId); //Write code to update item count return(RedirectToAction("Index", "Consignments")); }
public RedirectToRouteResult Delete(int id) { WarehouseDBEntities wdb = new WarehouseDBEntities(); var user = (from d in wdb.UserAccounts where d.UserID == id select d).Single(); wdb.UserAccounts.Remove(user); wdb.SaveChanges(); return(RedirectToAction("ViewWorkers")); }
public RedirectToRouteResult CreateWorker(string fullname, string email, string number, string username, string password, string[] shelfs) { WarehouseDBEntities wde = new WarehouseDBEntities(); UserAccount acc = new UserAccount(); acc.Email = email; acc.Name = fullname; acc.UserName = username; acc.Password = password; acc.Contact = number; acc.Role = "Worker"; acc.Registered = DateTime.Now.ToShortDateString(); wde.Workers.Add(new Worker { warehouseId = Convert.ToInt32(Session["UserId"]), assignedShelfs = JsonConvert.SerializeObject(shelfs) }); if (wde.UserAccounts.Where(a => a.UserName == acc.UserName).ToList().Count < 1) { try { wde.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } // acc.workerId = Convert.ToInt32(Session["UserId"]); acc.workerId = wde.Workers.Max(a => a.Id); ConsignmentBusinessLayer cbl = new ConsignmentBusinessLayer(); cbl.addAccount(acc); return(RedirectToAction("ViewWorkers")); } else { return(null); } }
// GET: Items/Details/5 public ActionResult ItemDetails(int?id) { Item item = db.Items.Find(id); try { if (item.itemDetails == null) { item.itemDetail = new itemDetail(); item.itemDetail.Id = db.itemDetails.Max(a => a.Id) + 1; item.itemDetails = item.itemDetail.Id; db.SaveChanges(); } } catch (Exception ex) { item.itemDetail = new itemDetail(); item.itemDetail.Id = 1; item.itemDetails = item.itemDetail.Id; db.SaveChanges(); } return(View(item)); }
/// <summary> /// Method for add or edit products in database /// </summary> /// <param name="product"></param> /// <returns>new or edited product</returns> public tblProduct AddEditProduct(tblProduct product) { try { using (WarehouseDBEntities context = new WarehouseDBEntities()) { if (product.ID == 0) { tblProduct newProduct = new tblProduct(); newProduct.ProductName = product.ProductName; newProduct.ProductCode = product.ProductCode; newProduct.Quantity = product.Quantity; newProduct.Price = product.Price; newProduct.Stored = "no"; context.tblProducts.Add(newProduct); context.SaveChanges(); product.ID = newProduct.ID; action = "added"; return(product); } else { tblProduct productForEdit = (from x in context.tblProducts where x.ID == product.ID select x).FirstOrDefault(); productForEdit.ProductName = product.ProductName; productForEdit.ProductCode = product.ProductCode; productForEdit.Quantity = product.Quantity; productForEdit.Price = product.Price; productForEdit.Stored = product.Stored; context.SaveChanges(); action = "edited"; return(product); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString()); return(null); } }
public void UpdateOrderCancel(string status) { int orderId = Convert.ToInt32(status); WarehouseDBEntities wdm = new WarehouseDBEntities(); Order Oldorder = wdm.Orders.FirstOrDefault(a => a.orderId == orderId); Order orderCopy = Oldorder; orderCopy.orderStatus = "Canceled"; wdm.Entry(Oldorder).CurrentValues.SetValues(orderCopy); wdm.SaveChanges(); wdm.Dispose(); }
/// <summary> /// Delete product from warehouse /// </summary> /// <param name="id">Product id</param> public void DeleteProduct(int id) { try { using (WarehouseDBEntities context = new WarehouseDBEntities()) { Product productToDelete = (from r in context.Products where r.ProductID == id select r).First(); context.Products.Remove(productToDelete); context.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.Message.ToString()); } }
/// <summary> /// Store not stored product in warehpuse /// </summary> /// <param name="id"></param> public void StoreProduct(int id) { try { using (WarehouseDBEntities context = new WarehouseDBEntities()) { Product productToStore = (from r in context.Products where r.ProductID == id select r).First(); productToStore.Stored = "stored"; context.SaveChanges(); GetCurrentWarehouseQuantity(); } } catch (Exception ex) { Console.WriteLine(ex.Message.ToString()); } }
public RedirectToRouteResult SaveEditWorker(string userid, string fullname, string email, string number, string username, string password, string[] shelfs) { WarehouseDBEntities wde = new WarehouseDBEntities(); UserAccount useracc = wde.UserAccounts.Find(Convert.ToInt32(userid)); useracc.Name = fullname; useracc.Email = email; useracc.UserName = username; useracc.Contact = number; useracc.Password = password; useracc.ConfirmPassword = password; useracc.Worker.assignedShelfs = JsonConvert.SerializeObject(shelfs); wde.Entry(useracc).State = EntityState.Modified; try { wde.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } return(RedirectToAction("ViewWorkers")); }
/// <summary> /// Method delets product from database if product is not stored /// </summary> /// <param name="productID">product id</param> public void DeleteProduct(int productID) { try { using (WarehouseDBEntities context = new WarehouseDBEntities()) { tblProduct productToDelete = (from p in context.tblProducts where p.ID == productID select p).First(); if (productToDelete.Stored == "no") { context.tblProducts.Remove(productToDelete); context.SaveChanges(); } else { MessageBox.Show("Stored products cannot be deleted."); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); } }
public ActionResult LogOff() { if (Session["WorkerID"] != null) { WarehouseDBEntities wde = new WarehouseDBEntities(); WorkerLogs wl = new WorkerLogs(); Worker worker = wde.Workers.Find(Convert.ToInt32(Session["WorkerID"])); JavaScriptSerializer jss = new JavaScriptSerializer(); if (worker.workerLogs != null) { List <WorkerLogs> workerlogs = Newtonsoft.Json.JsonConvert.DeserializeObject <List <WorkerLogs> >(worker.workerLogs); wl.date = DateTime.Now.ToShortDateString(); wl.time = DateTime.Now.ToShortTimeString(); wl.description = "Logout"; workerlogs.Add(wl); string jsObj = jss.Serialize(workerlogs); worker.workerLogs = jsObj; wde.SaveChanges(); } } Session.Abandon(); return(RedirectToAction("Register", "Account")); }
/// <summary> /// 新增一个实体 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int Add(T entity) { context.Entry <T>(entity).State = EntityState.Added; return(context.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")); }
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 CompleteOrder() { if (Session["customerRecord"] != null && Session["orderRecord"] != null) { WarehouseDBEntities wdb = new WarehouseDBEntities(); Customer customer = (Customer)Session["customerRecord"]; List <Item> items = (List <Item>)Session["orderRecord"]; int customerId; try { customerId = wdb.Customers.Max(i => i.id) + 1; } catch (Exception ex) { customerId = 1; } customer.id = customerId; int warehouseId = Convert.ToInt32(customer.selectedWarehouse); int orderId; try { orderId = wdb.Orders.Max(i => i.orderId) + 1; } catch (Exception ex) { orderId = 1; } wdb.Customers.Add(customer); wdb.SaveChanges(); wdb.Dispose(); wdb = new WarehouseDBEntities(); Order order = new Order(); order.orderId = orderId; order.customerId = customerId; order.orderDate = System.DateTime.Now.Date; order.orderStatus = "Unseen"; order.warehouseId = warehouseId; order.totalOrderQuanitity = 0; foreach (Item item in items) { order.totalOrderQuanitity = order.totalOrderQuanitity + Convert.ToInt32(item.Manufacturer); } wdb.Orders.Add(order); wdb.SaveChanges(); wdb.Dispose(); wdb = new WarehouseDBEntities(); List <item_Order> item_OrderList = new List <item_Order>(); foreach (Item item in items) { item_Order itemOrder = new item_Order(); itemOrder.itemId = item.id; itemOrder.orderId = orderId; itemOrder.quantity = Convert.ToInt32(item.Manufacturer); item_OrderList.Add(itemOrder); Item_Warehouse original = wdb.Item_Warehouse.FirstOrDefault(a => a.itemId == item.id && a.warehouseId == warehouseId); Item_Warehouse copy = original; copy.orders += 1; copy.quantity = copy.quantity - itemOrder.quantity; if (original != null) { wdb.Entry(original).CurrentValues.SetValues(copy); wdb.SaveChanges(); wdb.Dispose(); wdb = new WarehouseDBEntities(); } } wdb.item_Order.AddRange(item_OrderList); wdb.SaveChanges(); wdb.Dispose(); Session.Clear(); Session.Abandon(); } else { RedirectToAction("Register", "Account"); } return(View()); }
public ActionResult RegisterManager(string fullname, string email, string number, string warehousename, string warehouseaddress, string username, string password, string password2, HttpPostedFileBase warehouselogo, string countries) { string thePictureDataAsString = ""; if (warehouselogo != null) { string theFileName = Path.GetFileName(warehouselogo.FileName); byte[] thePictureAsBytes = new byte[warehouselogo.ContentLength]; using (BinaryReader theReader = new BinaryReader(warehouselogo.InputStream)) { thePictureAsBytes = theReader.ReadBytes(warehouselogo.ContentLength); } thePictureDataAsString = Convert.ToBase64String(thePictureAsBytes); } WarehouseBusinessLayer wbl = new WarehouseBusinessLayer(); UserAccount useracc = new UserAccount(); useracc.Name = fullname; useracc.Email = email; useracc.Contact = number; useracc.Password = password; useracc.ConfirmPassword = password; useracc.Registered = DateTime.Now.ToShortDateString(); useracc.Role = "Manager"; useracc.UserName = username; // ConsignmentBusinessLayer cbl = new ConsignmentBusinessLayer(); // cbl.addAccount(useracc); WarehouseDBEntities wde = new WarehouseDBEntities(); wde.UserAccounts.Add(useracc); try { wde.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } int Managerid = wbl.getRecentlyId(); wbl.createWarehouse(Managerid, warehousename, warehouseaddress, thePictureDataAsString, countries); Session["UserID"] = wbl.getRecentlyId(); Session["Username"] = username; return(RedirectToAction("LoggedIn")); }
public ActionResult Login(UserAccount user) { using (WarehouseDBEntities db = new WarehouseDBEntities()) { try { var usr = db.UserAccounts.Single(u => u.UserName == user.login.UserName && u.Password == user.login.Password); if (usr != null && usr.Role == "Manager") { Session["UserID"] = usr.UserID.ToString(); Session["Username"] = usr.Name.ToString(); return(RedirectToAction("LoggedIn")); } else if (usr != null && usr.Role == "Worker") { Session["WorkerID"] = usr.workerId; Session["WorkerName"] = usr.Name.ToString(); WorkerLogs wl = new WorkerLogs(); Worker worker = db.Workers.Find(usr.workerId); JavaScriptSerializer jss = new JavaScriptSerializer(); if (worker.workerLogs != null) { List <WorkerLogs> workerlogs = Newtonsoft.Json.JsonConvert.DeserializeObject <List <WorkerLogs> >(worker.workerLogs); wl.date = DateTime.Now.ToShortDateString(); wl.time = DateTime.Now.ToShortTimeString(); wl.description = "User Logged In"; workerlogs.Add(wl); string jsObj = jss.Serialize(workerlogs); worker.workerLogs = jsObj; db.SaveChanges(); } else { List <WorkerLogs> workerlogs = new List <WorkerLogs>(); wl.date = DateTime.Now.ToShortDateString(); wl.time = DateTime.Now.ToShortTimeString(); wl.description = "User Logged In"; workerlogs.Add(wl); string jsObj = jss.Serialize(workerlogs); worker.workerLogs = jsObj; db.SaveChanges(); } return(RedirectToAction("Index", "Worker")); } else { ModelState.AddModelError("keyName", "Username or Password Incorrect."); } } catch (Exception ex) { ModelState.AddModelError("keyName", "Username or Password Incorrect."); return(View()); } } return(View()); }