// //Add private void btAddProduct_Click(object sender, EventArgs e) { if (AcceptText()) { // // Add Bill if (od.checkID(cbBillID.Text)) { OrderBIll bill = new OrderBIll(); bill.orderID = cbBillID.Text; bill.customer = cd.getObject(cbCustomerID.EditValue.ToString()); bill.employee = ed.getObject(cbEmployee.EditValue.ToString()); bill.orderDate = DateOrder.DateTime; bill.payType = cbPayType.SelectedIndex; bill.total = long.Parse(txTotal.Text); od.AddObject(bill); cbBillID.Properties.Items.Add(cbBillID.Text); } if (String.IsNullOrEmpty(cbProductID.Text)) { cbProductID.Focus(); MessageBox.Show("Please choose a product", "Waring!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // // Add Detail Bill if (!detail.checkID(cbBillID.Text, cbProductID.Text)) { MessageBox.Show("ID is unavaillable,Please choose another!", "Warring", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } OrderBillDetail d = new OrderBillDetail(); d.orderBill = od.getObject(cbBillID.Text); d.product = pd.getObject(cbProductID.Text); d.quantily = Convert.ToInt16(txQuantily.Text); d.discount = Convert.ToInt16(txDiscount.Text); d.price = long.Parse(txPrice.Text); detail.AddObject(d); gridControl1.DataSource = detail.getTable(cbBillID.Text); // // Update Total Money txTotal.Text = od.getTotalMoney(cbBillID.Text); txQuantily.Properties.MaxValue = 1; } }
// // Update function void updateGridControl(DataRow row, int index) { OrderBillDetail Odetail = new OrderBillDetail(); Odetail.product = new ProductDAO().getObject(row[0].ToString()); Odetail.orderBill = new OrderBillDAO().getObject(row[1].ToString()); Odetail.quantily = Convert.ToInt16(row[3].ToString()); Odetail.price = long.Parse(row[5].ToString()); Odetail.discount = Convert.ToInt16(row[4].ToString()); MainView.SetRowCellValue(index, "Total", Odetail.quantily * Odetail.price * (1 - Odetail.discount / 100)); if (!detail.UpdateObject(Odetail)) { MessageBox.Show("Check information again!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } var bill = od.getObject(cbBillID.Text); txTotal.Text = bill.total.ToString(); }