Пример #1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            TransactionType trans = (from x in db.TransactionTypes where x.Name == "Purchase Order" select x).FirstOrDefault();

            if (data["Type"] == "New")
            {
                Order order = new Order
                {
                    //ID = null,
                    TransactionTypeID      = trans.ID,
                    SupplierID             = int.Parse(data["SupplierID"]),
                    SourceWarehouseID      = int.Parse(data["WarehouseID"]),
                    DestinationWarehouseID = int.Parse(data["WarehouseID"]),
                    Date = dpkDate.Value
                };
                for (int i = 0; i < dgvPurchaseOrder.Rows.Count; i++)
                {
                    OrderItem ordItem = new OrderItem {
                        // ID = null,
                        PartID      = Convert.ToInt32(dgvPurchaseOrder.Rows[i].Cells["PartID"].Value),
                        BatchNumber = dgvPurchaseOrder.Rows[i].Cells["BatchNumber"].Value.ToString(),
                        Amount      = Convert.ToInt32(dgvPurchaseOrder.Rows[i].Cells["Amount"].Value),
                    };
                    //ordItem.Part = (from x in db.Parts where x.ID == ordItem.PartID select x).SingleOrDefault();
                    order.OrderItems.Add(ordItem);
                }
                db.Orders.Add(order);
                db.SaveChanges();
                return;
            }
            if (data["Type"] == "Edit")
            {
                db.SaveChanges();
                //delete (chỉ trước orderItem, xóa Order sau)

                /*int supplierid = int.Parse(data["SupplierID"]);
                 * int warehouseid = int.Parse(data["WarehouseID"]);
                 * List < OrderItem > listOrderItem = (from x in db.OrderItems
                 *                                  from y in db.Orders
                 *                                  where x.OrderID == y.ID && y.SupplierID == supplierid && y.SourceWarehouseID == warehouseid
                 *                                  select x).ToList();
                 * foreach (OrderItem orderItem in listOrderItem)
                 * {
                 *  db.OrderItems.Remove(orderItem);
                 * }
                 * List<Order> listOrder = (from x in db.Orders where x.SupplierID == supplierid && x.SourceWarehouseID == warehouseid select x).ToList();
                 * foreach (Order order in listOrder)
                 * {
                 *  db.Orders.Remove(order);
                 * }
                 *
                 * //insert (thêm Order trước, thêm OrderItem sau)
                 *
                 * for (int i=0;i<dgvPurchaseOrder.Rows.Count;i++)
                 * {
                 *
                 * }*/
            }
        }
Пример #2
0
        private void dgvCurrentIventory_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //click Remove
            if (dgvCurrentIventory.CurrentCell.ColumnIndex == 7)
            {
                int       orderitemid = Convert.ToInt32(dgvCurrentIventory.Rows[dgvCurrentIventory.CurrentCell.RowIndex].Cells["OrderItemID"].Value);
                OrderItem orderitem   = (from x in db.OrderItems where orderitemid == x.ID select x).FirstOrDefault();
                db.OrderItems.Remove(orderitem);
                db.SaveChanges();
                return;
            }

            //click Edit
            if (dgvCurrentIventory.CurrentCell.ColumnIndex == 6)
            {
                frmPurchaseOrder            frm2 = new frmPurchaseOrder();
                Dictionary <string, string> data = new Dictionary <string, string>();
                data["SupplierID"]  = dgvCurrentIventory.CurrentRow.Cells["SupplierID"].Value.ToString();
                data["WarehouseID"] = dgvCurrentIventory.CurrentRow.Cells["SourceID"].Value.ToString();
                data["Date"]        = dgvCurrentIventory.CurrentRow.Cells["Date"].Value.ToString();
                data["OrderID"]     = dgvCurrentIventory.CurrentRow.Cells["OrderID"].Value.ToString();
                data["Type"]        = "Edit";
                frm2.Tag            = data;
                frm2.ShowDialog();
                LoadDataTable();
            }
        }