// //Update grid control void updateGridControl(DataRow row, int index) { PurchaseBillDetail detail = new PurchaseBillDetail(); detail.product = new ProductDAO().getObject(row[0].ToString()); detail.bill = new PurchaseBillDAO().getObject(row[2].ToString()); detail.quantily = Convert.ToInt16(row[3].ToString()); detail.price = long.Parse(row[4].ToString()); MainView.SetRowCellValue(index, "Total", (Convert.ToInt16(row[3].ToString()) * long.Parse(row[4].ToString())).ToString()); if (!pDetail.UpdateObject(detail)) { MessageBox.Show("Check information again!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); MainView.SelectRow(index); return; } }
// //Import product into Bill Detail private void sbtAdd_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(txPurchaseID.Text)) { MessageBox.Show("Please enter a Bill ID!!", "Warring!", MessageBoxButtons.OK, MessageBoxIcon.Warning); txPurchaseID.Focus(); return; } if (String.IsNullOrEmpty(cbEmployee.Text)) { MessageBox.Show("Please choose a Employee!!", "Warring!", MessageBoxButtons.OK, MessageBoxIcon.Warning); cbEmployee.Focus(); return; } // //Check Product ID if (String.IsNullOrEmpty(cbProductID.Text)) { MessageBox.Show("Please chose a Product ID!!", "Warring!", MessageBoxButtons.OK, MessageBoxIcon.Warning); cbProductID.Focus(); return; } // //Check purchase price if (String.IsNullOrEmpty(txPrice.Text)) { MessageBox.Show("Please enter price!!", "Warring!", MessageBoxButtons.OK, MessageBoxIcon.Warning); txPrice.Focus(); return; } if (cbEmployee.EditValue == null) { MessageBox.Show("Please choose a employee!!", "Warring!", MessageBoxButtons.OK, MessageBoxIcon.Warning); cbEmployee.Focus(); return; } // //If bill ID not exists then add new bill if (!pd.checkID(txPurchaseID.Text)) { PurchaseBill bill = new PurchaseBill(); bill.purchaseID = txPurchaseID.Text; Employee emp = ec.getObject(cbEmployee.EditValue.ToString()); bill.employee = emp; bill.purchaseDate = purchaseDate.DateTime; bill.totalPrice = long.Parse(txTotal.Text); pd.AddObject(bill); txPurchaseID.Properties.Items.Add(txPurchaseID.Text); } // //import product into bill detail PurchaseBillDetail p = new PurchaseBillDetail(); p.bill = pd.getObject(txPurchaseID.Text); p.product = pc.getObject(cbProductID.Text); p.quantily = Convert.ToInt16(txQuantily.Text); p.price = long.Parse(txPrice.Text); if (!pDetail.AddObject(p)) { MessageBox.Show("Check Information again!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } // //Load grid control again gridControl1.DataSource = pDetail.getTable(txPurchaseID.Text); txTotal.Text = pd.getTotalMoney(txPurchaseID.Text); //cbProductID.Text = txName.Text = txPrice.Text = txQuantily.Text = ""; sbtAdd.Enabled = false; }