public List<BillDetail> GetBillDetail(string billId) { try { List<BillDetail> list = new List<DTO.Sales.BillDetail>(); //DataTable dt = SqlQuery.readSQL("select TenSanPham, CHITIETHOADON.SoLuong, DonGiaBan from CHITIETHOADON join SANPHAM on CHITIETHOADON.MaSanPham=SANPHAM.MaSanPham where MaHD='" + billId + "'"); DataTable dt = SqlHelper.ExecuteDataset(Constants.ConnectionString, CommandType.Text, "select TenSanPham, CHITIETHOADON.SoLuong, DonGiaBan from CHITIETHOADON join SANPHAM on CHITIETHOADON.MaSanPham=SANPHAM.MaSanPham where MaHD='" + billId + "'").Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { BillDetail b = new BillDetail(billId, dt.Rows[0][0].ToString(), int.Parse(dt.Rows[0][1].ToString()), int.Parse(dt.Rows[0][2].ToString().Substring(0, dt.Rows[0][2].ToString().IndexOf(".")))); list.Add(b); } return list; } catch (Exception ex) { throw ex; } }
// Thêm hóa đơn private void btnSave_Click(object sender, EventArgs e) { Customer c = new Customer(txtCustomerId.Text, txtCustomerName.Text, txtIdCardNumber.Text, txtAddress.Text, txtPhoneNumber.Text); List<BillDetail> proList = new List<BillDetail>(); foreach(DataGridViewRow row in dgvProductAdded.Rows) { BillDetail bp= new BillDetail(row.Cells[0].Value.ToString(),"",int.Parse(row.Cells[2].Value.ToString()),0); proList.Add(bp); } if (checkBeforeSave(proList) == false) return; try { bll.SaveBill(c, MaNV, int.Parse(rule.partToInt( txtSumMoney.Text)), proList); // DisplayNotify("Lưu thành công", 1); } catch (Exception ex) { DisplayNotify("Bị lỗi trong quá trình lưu dữ liệu" + ex.Message, -1);return; } try { dgvProduct.DataSource = bll.GetAllProduct(); cleanDataInForm(); loadWhenInit(); } catch (Exception ex) { DisplayNotify("Bị lỗi trong quá trình load lại danh sách san phẩm" + ex.Message, -1); } }