private void BatchNumbers_Load(object sender, EventArgs e)
        {
            //retrieve all orderitems according to the part with a batch number
            using (Session4Entities db = new Session4Entities())
            {
                if (ST == 1)
                {
                    var partswithbatchnumbers = db.OrderItems.Where(p => p.PartID == PID && p.Order.SourceWarehouseID == WHID);

                    foreach (var item in partswithbatchnumbers)
                    {
                        object[] row = new object[2];
                        row[0] = item.BatchNumber;
                        row[1] = item.Amount;
                        batchNumberlist.Rows.Add(row);
                    }
                }
                if (ST == 2)
                {
                    var partswithbatchnumbers = db.OrderItems.Where(p => p.PartID == PID && p.Order.DestinationWarehouseID == WHID);

                    foreach (var item in partswithbatchnumbers)
                    {
                        object[] row = new object[2];
                        row[0] = item.BatchNumber;
                        row[1] = item.Amount;
                        batchNumberlist.Rows.Add(row);
                    }
                }
            }
        }
        private void InventoryReport_Load(object sender, EventArgs e)
        {
            using (Session4Entities db = new Session4Entities())
            {
                currentStockButton.Checked = true;
                //getting list of warehouses and placing them in the warehouse dropdownlist
                var warehouses = db.Warehouses.ToList();
                warehouseselector.DataSource    = new BindingSource(warehouses, null);
                warehouseselector.DisplayMember = "Name";
                warehouseselector.ValueMember   = "ID";
            }
            long whID = ((Warehouse)warehouseselector.SelectedItem).ID;

            loadresults(whID);
        }
Exemple #3
0
        private void editWarehouseOrder()
        {
            using (Session4Entities db = new Session4Entities())
            {
                var swid = ((Warehouse)sourcewarehousebox.SelectedItem).ID;
                var dwid = ((Warehouse)destinationwarehousebox.SelectedItem).ID;
                var date = Convert.ToDateTime(dateTimePicker1.Value);

                //retrieving existing warehouse order
                var existingwarehouseorder = db.Orders.Where(a => a.ID == OID).FirstOrDefault();
                existingwarehouseorder.SourceWarehouseID      = swid;
                existingwarehouseorder.DestinationWarehouseID = dwid;
                existingwarehouseorder.Date = date;

                //retrieving existing orderitems related to the order
                var existingwarehouseorderitems = db.OrderItems.Where(oit => oit.OrderID == OID).ToList();
                foreach (var item in existingwarehouseorderitems)
                {
                    db.OrderItems.Remove(item);
                }
                foreach (var item in listofparts)
                {
                    OrderItem newOrderitem = new OrderItem();
                    newOrderitem.OrderID     = (long)OID;
                    newOrderitem.PartID      = item.partid;
                    newOrderitem.BatchNumber = item.batchnumber;
                    newOrderitem.Amount      = item.amount;
                    db.OrderItems.Add(newOrderitem);
                }
                try
                {
                    db.SaveChanges();
                    db.Dispose();
                    this.Close();
                }
                catch (Exception error)
                {
                    MessageBox.Show("Whoops, an error has occured. Error Message: " + error.ToString());
                }
            }
        }
Exemple #4
0
        private void newWarehouseOrder()
        {
            using (Session4Entities db = new Session4Entities())
            {
                var swid = ((Warehouse)sourcewarehousebox.SelectedItem).ID;
                var dwid = ((Warehouse)destinationwarehousebox.SelectedItem).ID;
                var date = Convert.ToDateTime(dateTimePicker1.Value);

                Order newOrder = new Order();
                newOrder.SourceWarehouseID      = swid;
                newOrder.DestinationWarehouseID = dwid;
                newOrder.TransactionTypeID      = 2;
                newOrder.Supplier = null;
                newOrder.Date     = date;
                db.Orders.Add(newOrder);
                foreach (var item in listofparts)
                {
                    OrderItem orderItem = new OrderItem();
                    orderItem.OrderID     = newOrder.ID;
                    orderItem.PartID      = item.partid;
                    orderItem.BatchNumber = item.batchnumber;
                    orderItem.Amount      = item.amount;
                    db.OrderItems.Add(orderItem);
                }
                try
                {
                    db.SaveChanges();
                    db.Dispose();
                    this.Close();
                }
                catch (Exception error)
                {
                    MessageBox.Show("Whoops, an Error has occured. Error Message: " + error.ToString());
                }
            }
        }
Exemple #5
0
        private void WarehouseManagement_Load(object sender, EventArgs e)
        {
            using (Session4Entities db = new Session4Entities())
            {
                var warehouselist = db.Warehouses.ToList();
                var partslist     = db.Parts.ToList();

                sourcewarehousebox.DataSource    = new BindingSource(warehouselist, null);
                sourcewarehousebox.DisplayMember = "Name";
                sourcewarehousebox.ValueMember   = "ID";

                destinationwarehousebox.DataSource    = new BindingSource(warehouselist, null);
                destinationwarehousebox.DisplayMember = "Name";
                destinationwarehousebox.ValueMember   = "ID";

                partsbox.DataSource    = new BindingSource(partslist, null);
                partsbox.DisplayMember = "Name";
                partsbox.ValueMember   = "ID";

                //foreach(var item in partslist)
                //{
                //    partorderitems.Add(item.ID, item.Name);
                //}
                //partsbox.DataSource = new BindingSource(partorderitems, null);
                //partsbox.DisplayMember = "Value";
                //partsbox.ValueMember = "Key";


                if (edit == true)
                {
                    //get existing warehouse order details
                    var warehouseorder = db.Orders.Where(order => order.ID == OID).FirstOrDefault();
                    foreach (var item in sourcewarehousebox.Items)
                    {
                        var selecteditem = (Warehouse)item;
                        if (selecteditem.ID == warehouseorder.SourceWarehouseID)
                        {
                            sourcewarehousebox.SelectedItem = item;
                        }
                    }
                    foreach (var item in destinationwarehousebox.Items)
                    {
                        var selecteditem = (Warehouse)item;
                        if (selecteditem.ID == warehouseorder.DestinationWarehouseID)
                        {
                            destinationwarehousebox.SelectedItem = item;
                        }
                    }
                    dateTimePicker1.Value = warehouseorder.Date;
                    //Retrieving all  existing orderitems
                    var existingorderitems = db.OrderItems.Where(orderitem => orderitem.OrderID == OID).ToList();
                    foreach (var item in existingorderitems)
                    {
                        parts expts = new parts();
                        expts.partid      = item.PartID;
                        expts.partname    = item.Part.Name;
                        expts.amount      = item.Amount;
                        expts.batchnumber = item.BatchNumber;
                        listofparts.Add(expts);
                    }
                    showParts();
                }
            }
        }
        void loadresults(long warehouseID)
        {
            //loading current stock in the warehouse
            using (Session4Entities db = new Session4Entities())
            {
                if (currentStockButton.Checked)
                {
                    stockType = 1;
                    var getcurrentstock = db.OrderItems.Where(a => a.Order.SourceWarehouseID == warehouseID);
                    var warehouses      = db.Warehouses;
                    inventoryReportTable.Rows.Clear();
                    foreach (var item in getcurrentstock.Select(a => a.Part.Name).Distinct())
                    {
                        object[] row          = new object[5];
                        var      pD           = db.Parts.Where(p => p.Name == item).First();
                        var      currentStock = db.OrderItems.Where(a => a.PartID == pD.ID && a.Order.SourceWarehouseID == warehouseID).Select(a => a.Amount).Sum();
                        row[0] = item;
                        row[1] = currentStock;
                        if (pD.BatchNumberHasRequired.Equals(true))
                        {
                            row[3] = "View Batch Numbers";
                        }
                        row[4] = pD.ID;
                        inventoryReportTable.Rows.Add(row);
                    }
                    inventoryReportTable.Columns[1].Visible = true;
                    inventoryReportTable.Columns[2].Visible = false;
                    inventoryReportTable.Columns[3].Visible = true;
                }
                else if (receivedStockbutton.Checked)
                {
                    stockType = 2;
                    var getcurrentstock = db.OrderItems.Where(a => a.Order.DestinationWarehouseID == warehouseID);
                    inventoryReportTable.Rows.Clear();
                    foreach (var item in getcurrentstock.Select(a => a.Part.Name).Distinct())
                    {
                        object[] row          = new object[5];
                        var      pD           = db.Parts.Where(p => p.Name == item).First();
                        var      currentStock = db.OrderItems.Where(a => a.PartID == pD.ID && a.Order.DestinationWarehouseID == warehouseID).Select(a => a.Amount).Sum();
                        row[0] = item;
                        row[2] = currentStock;
                        if (pD.BatchNumberHasRequired.Equals(true))
                        {
                            row[3] = "View Batch Numbers";
                        }
                        row[4] = pD.ID;
                        inventoryReportTable.Rows.Add(row);
                    }
                    inventoryReportTable.Columns[1].Visible = false;
                    inventoryReportTable.Columns[2].Visible = true;
                    inventoryReportTable.Columns[3].Visible = true;
                }
                else
                {
                    stockType = 3;
                    var getAllStock = db.OrderItems;
                    inventoryReportTable.Rows.Clear();
                    foreach (var item in getAllStock.Select(a => a.Part.Name).Distinct())
                    {
                        var pD = db.Parts.Where(p => p.Name == item).First();
                        if (db.OrderItems.Where(p => p.PartID == pD.ID && p.Order.SourceWarehouseID == warehouseID).FirstOrDefault() != null)
                        {
                            var currentStockCount   = db.OrderItems.Where(x => x.PartID == pD.ID && x.Order.SourceWarehouseID == warehouseID).Select(x => x.Amount).Sum();
                            var receivingStockCount = db.OrderItems.Where(x => x.PartID == pD.ID && x.Order.DestinationWarehouseID == warehouseID).Select(x => x.Amount).Sum();

                            if ((currentStockCount - receivingStockCount) <= 0)
                            {
                                inventoryReportTable.Rows.Add(item);
                            }
                            inventoryReportTable.Columns[1].Visible = false;
                            inventoryReportTable.Columns[2].Visible = false;
                            inventoryReportTable.Columns[3].Visible = false;
                        }
                    }
                }
            }
        }
        private void PurchaseOrder_Load(object sender, EventArgs e)
        {
            //get list of suppliers
            var supplierlist  = db.Suppliers;
            var warehouselist = db.Warehouses;
            var partslist     = db.Parts;


            Dictionary <long, string> supplier   = new Dictionary <long, string>();
            Dictionary <long, string> warehouses = new Dictionary <long, string>();
            Dictionary <long, string> parts      = new Dictionary <long, string>();

            foreach (var s in supplierlist)
            {
                supplier.Add(s.ID, s.Name);
            }
            foreach (var w in warehouselist)
            {
                warehouses.Add(w.ID, w.Name);
            }

            foreach (var p in partslist)
            {
                parts.Add(p.ID, p.Name);
            }

            supplierbox.DataSource    = new BindingSource(supplier, null);
            supplierbox.DisplayMember = "Value";
            supplierbox.ValueMember   = "Key";

            warehousebox.DataSource    = new BindingSource(warehouses, null);
            warehousebox.DisplayMember = "Value";
            warehousebox.ValueMember   = "Key";

            partsBox.DataSource    = new BindingSource(parts, null);
            partsBox.DisplayMember = "Value";
            partsBox.ValueMember   = "Key";

            if (edit == true)
            {
                //retrieve existing orderitems that are associated with the purchase order
                using (Session4Entities db = new Session4Entities())
                {
                    var getOrderDetails        = db.Orders.Where(po => po.ID == OID).FirstOrDefault();
                    var getexistingOrderitems  = db.OrderItems.Where(order => order.OrderID == OID);
                    var supplierId             = getOrderDetails.SupplierID;
                    var destinationwarehouseid = getOrderDetails.DestinationWarehouseID;
                    foreach (var item in supplierbox.Items)
                    {
                        var s = ((KeyValuePair <long, string>)item).Key;
                        if (s == supplierId)
                        {
                            supplierbox.SelectedItem = item;
                        }
                    }
                    foreach (var item in warehousebox.Items)
                    {
                        var wh = ((KeyValuePair <long, string>)item).Key;
                        if (wh == destinationwarehouseid)
                        {
                            warehousebox.SelectedItem = item;
                        }
                    }
                    foreach (var item in getexistingOrderitems)
                    {
                        parts expts = new parts();
                        expts.partid      = item.PartID;
                        expts.amount      = item.Amount;
                        expts.batchnumber = item.BatchNumber;
                        expts.partname    = item.Part.Name;
                        listofparts.Add(expts);
                    }
                    dateTimePicker1.Value = getOrderDetails.Date;
                    showParts(sender, e);
                }
            }
        }