Пример #1
0
 private void dgvPart_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dgvPart.CurrentCell.ColumnIndex == 3) //Remove
     {
         int       partid    = Convert.ToInt32(dgvPart.CurrentRow.Cells["PartID"].Value);
         OrderItem orderItem = db.OrderItems.Where(x => x.PartID == partid && x.BatchNumber == txtBatchNumber.Text).SingleOrDefault();
         if (orderItem != null)
         {
             db.OrderItems.Remove(orderItem);
         }
         dgvPart.Rows.Remove(dgvPart.CurrentRow);
         db.SaveChanges();
     }
 }
Пример #2
0
 private void dgvManagement_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dgvManagement.CurrentCell.ColumnIndex == 7) //remove
     {
         if (MessageBox.Show("Do you want to delete this record?", "", MessageBoxButtons.YesNo) == DialogResult.No)
         {
             return;
         }
         int       oiid      = Convert.ToInt32(dgvManagement.CurrentRow.Cells["OrderItemID"].Value);
         OrderItem orderitem = db.OrderItems.Where(x => x.ID == oiid).SingleOrDefault();
         db.OrderItems.Remove(orderitem);
         dgvManagement.Rows.Remove(dgvManagement.CurrentRow);
         db.SaveChanges();
     }
     else if (dgvManagement.CurrentCell.ColumnIndex == 6) //edit
     {
         int transactionid = Convert.ToInt32(dgvManagement.CurrentRow.Cells["TransactionTypeID"].Value);
         int oiid          = Convert.ToInt32(dgvManagement.CurrentRow.Cells["OrderItemID"].Value);
         if (transactionid == 1) //edit purchase order
         {
             PurchaseOrder form2 = new PurchaseOrder();
             form2.selectedOrderItem = db.OrderItems.Where(x => x.ID == oiid).SingleOrDefault();
             form2.ShowDialog();
         }
         else
         {
             WarehouseManagement form2 = new WarehouseManagement();
             form2.selectedOrderItem = db.OrderItems.Where(x => x.ID == oiid).SingleOrDefault();
             form2.ShowDialog();
         }
     }
 }
Пример #3
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (cbSource.SelectedValue == cbDestination.SelectedValue)
            {
                MessageBox.Show("Source warehouse is like Destination warehouse");
                return;
            }
            if (dgvPart.Rows.Count == 0)
            {
                MessageBox.Show("At least one part needs to be added to the order for it to be valid");
                return;
            }
            if (txtDate.Text == "  -  -")
            {
                MessageBox.Show("Date is empty");
                return;
            }
            try
            {
                Convert.ToDateTime(txtDate.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Date is invalid");
                return;
            }

            //new Warehouse management
            if (selectedOrderItem == null)
            {
                //Add order
                Order order = new Order();
                //order.SupplierID = (int?)cbSupplier.SelectedValue;
                order.DestinationWarehouseID = (int?)cbSource.SelectedValue;
                order.SourceWarehouseID      = (int?)cbDestination.SelectedValue;
                order.TransactionTypeID      = 2;
                order.Date = Convert.ToDateTime(txtDate.Text);
                db.Orders.Add(order);
                db.SaveChanges();
                order = db.Orders.Where(x => x.SupplierID == order.SupplierID && order.DestinationWarehouseID == x.DestinationWarehouseID && order.TransactionTypeID == x.TransactionTypeID && x.Date == order.Date).SingleOrDefault();

                //Add orderitem
                for (int i = 0; i < dgvPart.Rows.Count; i++)
                {
                    if (dgvPart.Rows[i].Cells["Flag"].Value.ToString() == "1")
                    {
                        OrderItem orderitem = new OrderItem();
                        orderitem.OrderID     = order.ID;
                        orderitem.PartID      = Convert.ToInt32(dgvPart.Rows[i].Cells["PartID"].Value);
                        orderitem.BatchNumber = dgvPart.Rows[i].Cells["BatchNumber"].Value.ToString();
                        orderitem.Amount      = Convert.ToDouble(dgvPart.Rows[i].Cells["Amount"].Value);
                        db.OrderItems.Add(orderitem);
                    }
                }
                db.SaveChanges();
            }
            else //edit purchase order
            {
                Order order = db.Orders.Where(x => x.ID == selectedOrderItem.OrderID).SingleOrDefault();
                //order.SupplierID = (int?)cbSupplier.SelectedValue;
                order.DestinationWarehouseID = (int?)cbSource.SelectedValue;
                order.SourceWarehouseID      = (int?)cbDestination.SelectedValue;
                order.Date = Convert.ToDateTime(txtDate.Text);
                db.SaveChanges();

                //Add orderitem
                for (int i = 0; i < dgvPart.Rows.Count; i++)
                {
                    if (dgvPart.Rows[i].Cells["Flag"].Value.ToString() == "1")
                    {
                        OrderItem orderitem = new OrderItem();
                        orderitem.OrderID     = order.ID;
                        orderitem.PartID      = Convert.ToInt32(dgvPart.Rows[i].Cells["PartID"].Value);
                        orderitem.BatchNumber = dgvPart.Rows[i].Cells["BatchNumber"].Value.ToString();
                        orderitem.Amount      = Convert.ToDouble(dgvPart.Rows[i].Cells["Amount"].Value);
                        db.OrderItems.Add(orderitem);
                    }
                }
                db.SaveChanges();
            }
            MessageBox.Show("Submit successfully");
        }