private void btnEdit_Click(object sender, EventArgs e) { List<BillDetail> lstBillDetail = new List<BillDetail>(); for (int i = 0; i < gvProductsToBills.Rows.Count; i++) { BillDetail billDetail = new BillDetail() { ProductId = int.Parse(gvProductsToBills.Rows[i].Cells["colID"].Value.ToString()), Amounts = int.Parse(gvProductsToBills.Rows[i].Cells["colAmounts"].Value.ToString()), RealPrice = float.Parse(gvProductsToBills.Rows[i].Cells["colRealPrice"].Value.ToString()), Sum = float.Parse(gvProductsToBills.Rows[i].Cells["colTotal"].Value.ToString()), BillDetailDescription = string.Empty }; lstBillDetail.Add(billDetail); } Bill bills = new Bill() { BillId = int.Parse(gvBills.Rows[gvBills.CurrentCell.RowIndex].Cells["colBillsId"].Value.ToString()), CreatedDate = DateTime.Parse(gvBills.Rows[gvBills.CurrentCell.RowIndex].Cells["colBillsDate"].Value.ToString()), BillDescription = "", Total = SumTotal(), BillDetails = lstBillDetail }; BLLBills bllBills = new BLLBills(); bllBills.Updated(bills); MessageBox.Show("Update Successful", "Message"); LoadGridBills(); gvProductsToBills.Rows.Clear(); lbTotal.Text = string.Empty; pictureBox1.Enabled = true; pictureBox2.Enabled = true; btnEdit.Enabled = false; }
private void pictureBox1_Click_1(object sender, EventArgs e) { if (gvProductsToBills.Rows.Count == 0) { MessageBox.Show("Choose product, Please!", "Message"); return; } List<BillDetail> lstBillDetail = new List<BillDetail>(); for (int i = 0; i < gvProductsToBills.Rows.Count; i++) { BillDetail billDetail = new BillDetail() { ProductId = int.Parse(gvProductsToBills.Rows[i].Cells["colID"].Value.ToString()), Amounts = int.Parse(gvProductsToBills.Rows[i].Cells["colAmounts"].Value.ToString()), RealPrice = float.Parse(gvProductsToBills.Rows[i].Cells["colRealPrice"].Value.ToString()), Sum = float.Parse(gvProductsToBills.Rows[i].Cells["colTotal"].Value.ToString()), BillDetailDescription = string.Empty }; lstBillDetail.Add(billDetail); } Bill bills = new Bill() { CreatedDate = DateTime.Parse(DateTime.Now.ToShortDateString()), BillDescription = "", Total = double.Parse(lbTotal.Text), BillDetails = lstBillDetail }; BLLBills billsBLL = new BLLBills(); if (billsBLL.Inserted(bills)) { MessageBox.Show("Add Successful", "Message"); LoadGridBills(); } }