private void EditPurchaseOrder(object sender, EventArgs e)
        {
            //get supplierID
            long supplierid = ((KeyValuePair <long, string>)supplierbox.SelectedItem).Key;
            //get destinationwarehouseid
            long destwarehouseid = ((KeyValuePair <long, string>)warehousebox.SelectedItem).Key;
            //getting date
            DateTime date = dateTimePicker1.Value;
            var      existingpurchaseorder = db.Orders.Where(o => o.ID == OID).FirstOrDefault();

            existingpurchaseorder.SupplierID             = supplierid;
            existingpurchaseorder.DestinationWarehouseID = destwarehouseid;
            existingpurchaseorder.Date = date;

            //Delete all orderitems associated with this order being edited
            var existingorderitems = db.OrderItems.Where(oit => oit.OrderID == OID).ToList();

            foreach (var item in existingorderitems)
            {
                db.OrderItems.Remove(item);
            }
            foreach (var item in listofparts)
            {
                OrderItem neworderitems = new OrderItem();
                neworderitems.OrderID     = (long)OID;
                neworderitems.PartID      = item.partid;
                neworderitems.BatchNumber = item.batchnumber;
                neworderitems.Amount      = item.amount;
                db.OrderItems.Add(neworderitems);
            }
            try
            {
                db.SaveChanges();
                MessageBox.Show("Your changes have been saved");
                this.Close();
            }
            catch (Exception error)
            {
                MessageBox.Show("Unable to save changes. Report this error to technician: " + error.ToString());
            }
        }
Exemple #2
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 #3
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());
                }
            }
        }