コード例 #1
0
 private void btnThem_Click(object sender, EventArgs e)// thêm món ăn vào hóa đơn
 {
     //try
     //{
     if (!BLL.testHoaDon(txtMaHD.Text))
     {
         if (string.IsNullOrEmpty(txtMaHD.Text))
         {
             MessageBox.Show("Chưa tạo hóa đơn mới", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         if (string.IsNullOrEmpty(cbxMaNV.Text))
         {
             MessageBox.Show("Chưa chọn mã nhân viên tạo hóa đơn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         if (string.IsNullOrEmpty(cbxMaKH.Text))
         {
             MessageBox.Show("Chưa chọn mã khách hàng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         // thêm mới vào bảng hóa đơn
         string tinhTrang = "Chưa thanh toán";
         BLL.insertHD(txtMaHD.Text, dtpNgayXuat.Value.Date, cbxMaNV.Text, cbxMaKH.Text, tinhTrang);
         // thêm mới bảng chi tiết hóa đơn
         if (dgvMonAnTheoHD.Rows.Count == 0)
         {
             return;
         }
         foreach (DataGridViewRow row in dgvMonAnTheoHD.Rows)
         {
             // currQty += row.Cells["qty"].Value;
             BLL.insertChiTietHD(txtMaHD.Text, row.Cells[0].Value.ToString(), int.Parse(row.Cells[2].Value.ToString()), float.Parse(row.Cells[3].Value.ToString()), float.Parse(row.Cells[4].Value.ToString()), float.Parse(row.Cells[5].Value.ToString()));
         }
         txtTongTien.Text = BLL.showTongTienTheoMaHD(txtMaHD.Text);
         MessageBox.Show("Đã thêm thành công hóa đơn", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
         btnInHoaDon.Enabled = true;
         btnXuatFile.Enabled = true;
     }
 }