private void CustomerScreen_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'cIS375_InventoryManagementDataSet.Customers' table. You can move, or remove it, as needed. //this.customersTableAdapter.Fill(this.cIS375_InventoryManagementDataSet.Customers); // TODO: This line of code loads data into the 'cIS375_InventoryManagementDataSet.Orders' table. You can move, or remove it, as needed. this.ordersTableAdapter.Fill(this.cIS375_InventoryManagementDataSet.Orders); // TODO: This line of code loads data into the 'cIS375_InventoryManagementDataSet.ItemCategories' table. You can move, or remove it, as needed. // this.itemCategoriesTableAdapter.Fill(this.cIS375_InventoryManagementDataSet.ItemCategories); using (InvContext ctx = new InvContext()) { ItemCategories = ctx.ItemCategories.ToList(); Customers = ctx.Customers.ToList(); } this.drop_item.DataSource = ItemCategories; this.drop_item.DisplayMember = "Name"; this.drop_item.ValueMember = null; // keeps the object as the value member this.drop_customer.DataSource = Customers; this.drop_customer.DisplayMember = "Name"; this.drop_customer.ValueMember = null; // keeps the object as the value member // Order tab functionality OrderGridView.Visible = false; dgv_orderedItems.Visible = false; }
/// <summary> /// Submit the order - save to the database (still editable). /// </summary> /// <returns></returns> public bool Submit() { if (this.ItemsOrdered.Count == 0) { Statics.DebugOut("Error: cannot submit an order without an items"); return(false); } using (InvContext ctx = new InvContext()) { // ensure the context knows about this item in reference to the database ctx.Customers.Attach(this.Customer); ctx.Entry(this).State = this.OrderID == default(int) ? EntityState.Added : EntityState.Modified; // tell the database that this item already exists or needs to be added this.DateOrdered = DateTime.Now; this.OrderCode = "ABC" + Statics.rand.Next(0, 999).ToString().PadLeft(3, '0'); ctx.SaveChanges(); } return(true); }
public static int DeleteVendor(int vendorID) { using (InvContext context = new InvContext()) { Vendor vendor = context.Vendors.FirstOrDefault(x => x.VendorID == vendorID); if (vendor != null) { int quantity = context.ItemStocks.FirstOrDefault(x => x.ItemStored.Name == vendor.ItemProvided.Name).Quantity; //Delete Vendor if (quantity <= 0) { context.Vendors.Remove(vendor); context.SaveChanges(); } else { return(2); } } else { return(1); } return(0); } }
public static int QuantityOfItemInEveryWareHouse(ItemCategory item) { //Quantity of a specified item from every warehouse using (InvContext ctx = new InvContext()) { return(0); } }
private void OrderSearchButton_Click(object sender, EventArgs e) { using (InvContext context = new InvContext()) { Customer searchedCustomer = context.Customers.FirstOrDefault(x => x.Name.ToLower() == CustomerNameTextBox.Text.ToLower()); if (searchedCustomer == null) { MessageBox.Show("Sorry, that customer could not be found"); OrderGridView.Visible = false; dgv_orderedItems.Visible = false; return; } customersOrders = context.Orders.Where(x => x.Customer.CustomerID == searchedCustomer.CustomerID) .Include(x => x.ItemsOrdered) .Include(x => x.ItemsOrdered.Select(y => y.Item)) .ToList(); if (customersOrders.Count > 0) { OrderGridView.Visible = true; dgv_orderedItems.Visible = true; var query = customersOrders.Select( x => new DataBindingProjection { OrderID = x.OrderID, OrderCode = x.OrderCode, DateOrdered = x.DateOrdered, }); OrderGridView.DataSource = query.ToList(); dgv_orderedItems.DataSource = customersOrders.Select( x => x.ItemsOrdered.Select( o => new otherbinding { OrderNumber = o.Order.OrderID, Item = o.Item.Name, Quantity = o.Quantity, Price = ((float)o.Item.Price * (float)o.Quantity), } )).ToList(); } else { MessageBox.Show("Error: Customer has no order history"); OrderGridView.Visible = false; dgv_orderedItems.Visible = false; } } }
static void Main(string[] args) // test each use case { Console.WriteLine("INFO - Taking sample customer and items"); Customer testCustomer = null; List <ItemCategory> itemsToOrder = new List <ItemCategory>(); // start with a customer and items to order using (InvContext ctx = new InvContext()) { testCustomer = ctx.Customers.FirstOrDefault(); itemsToOrder = ctx.ItemCategories.ToList(); } Console.WriteLine("INFO - Asserting we have a customer and items"); Debug.Assert(testCustomer != null, "Requires customer in database"); Debug.Assert(itemsToOrder != null, "Requires items in database"); // create a bunch of random orders // THIS SHOULD BE PART OF THE ITEM SHOPPING Console.WriteLine("INFO - Creating shopping cart order"); var testOrder = new Order() { Customer = testCustomer, // changing customers can wipe out this shopping cart }; // emulate the customer shopping // populate the shopping cart with random item and quantities Console.WriteLine("INFO - Filling shopping cart"); for (int i = 0; i < 10; i++) { ItemCategory randomItem = itemsToOrder[Statics.rand.Next(0, itemsToOrder.Count)]; var randomQuantity = Statics.rand.Next(0, 100); testOrder.AddItemToOrder(randomItem, randomQuantity); } Console.WriteLine("INFO - Submitting Order to database"); testOrder.Submit(); // submit the order and make sure that its fields are filled correctly Console.WriteLine("INFO - Asserting order is filled correctly"); Debug.Assert(testOrder.DateOrdered != null); Debug.Assert(testOrder.OrderCode != null); Debug.Assert(testOrder.ItemsOrdered.Count > 0); Console.WriteLine("Congrats if youre seeing this you passed all the tests so far."); Console.WriteLine("Pres <enter> to quit."); Console.ReadLine(); }
public static void CreateTestWarehouses() { using (InvContext ctx = new InvContext()) { for (int i = 0; i < 7; i++) { var newWarehouse = new Warehouse() { Address = $"Addres {i}00 Wares St.", Name = "Warehouse " + i, WarehouseID = i, }; ctx.Warehouses.Add(newWarehouse); } } }
public static void AddItem(string name, string description, string price, decimal distributionField) { using (InvContext context = new InvContext()) { ItemCategory itemCategory = new ItemCategory(); ItemStock itemStock = new ItemStock(); itemCategory.Name = name; itemCategory.Price = Convert.ToDecimal(price); itemCategory.Description = description; itemStock.ItemStored = itemCategory; itemStock.Quantity = 0; context.ItemCategories.Add(itemCategory); context.ItemStocks.Add(itemStock); context.SaveChanges(); } }
// ------------ Functions public bool AddItemToOrder(int itemID, int quantity) { if (itemID == 0 || quantity <= 0) { return(false); } ItemCategory itemtoOrder; using (InvContext ctx = new InvContext()) { itemtoOrder = ctx.ItemCategories.FirstOrDefault(x => x.ItemCategoryID == itemID); } return(AddItemToOrder(itemtoOrder, quantity)); }
public static bool DeleteItem(string itemName) { using (InvContext context = new InvContext()) { ItemCategory itemCategory = context.ItemCategories.FirstOrDefault(x => x.Name == itemName); ItemStock itemStock = context.ItemStocks.FirstOrDefault(x => x.ItemStored.Name == itemName); if (itemCategory != null && itemStock != null) { context.ItemCategories.Remove(itemCategory); context.ItemStocks.Remove(itemStock); context.SaveChanges(); return(true); } else { return(false); } } }
public static bool AddVendor(string nameOfVendorToAdd, string nameOfItem) { using (InvContext context = new InvContext()) { ItemCategory itemCategory = context.ItemCategories.FirstOrDefault(x => x.Name == nameOfItem); int quantity = context.ItemStocks.FirstOrDefault(x => x.ItemStored.Name == itemCategory.Name).Quantity; if (quantity <= 0) { //New vendor Vendor vendor = new Vendor(); vendor.Name = nameOfVendorToAdd; vendor.ItemProvided = itemCategory; context.Vendors.Add(vendor); context.SaveChanges(); return(true); } else { return(false); } } }
public RolData(InvContext context) { db = context ?? new InvContext(); }
public AreaData(InvContext context) { db = context ?? new InvContext(); }
public static void BackOrderOperation(int remainingQuantity, ItemCategory item) { InvContext ctx = new InvContext(); BackOrder backOrder = new BackOrder(); }
public EntradaRepositorio(InvContext context) : base(context) { ubicacion = new Repositorio <Ubicacion>(db); producto = new Repositorio <Producto>(db); inventario = new InventarioRepositorio(db); }
public RolRepositorio() { db = new InvContext(); repositorioRolAcceso = new RolAccesoRepositorio(db); }
public InventarioRepositorio(InvContext context) : base(context) { }
public UsuarioRepositorio(InvContext context) : base(context) { rolAccesoRepositorio = new Repositorio <Rol>(db); }
public Repositorio() { db = new InvContext(); }
public RolAccesoRepositorio(InvContext contexto) : base(contexto) { }
public Repositorio(InvContext context) { db = context; }
public PermisoData(InvContext context) { db = context ?? new InvContext(); }