private void bt_Luu_Click(object sender, EventArgs e) { DataTable temp = HoaDon.searchHoaDon(tbMaTiecCuoi.Text); int t = temp.Rows.Count; if (t == 0) { // Tạo SoHoaDon string SoHoaDon = ""; DataTable hd = HoaDon.getHoaDon(); int totalRow = hd.Rows.Count; if (totalRow < 9) { SoHoaDon = "HD0" + (totalRow + 1).ToString(); } else { SoHoaDon = "HD" + (totalRow + 1).ToString(); } string NgayThanhToan = string.Format("{0:dd/MM/yyyy}", dtpNgayThanhToan.Value); DTO_HoaDon hoadon = new DTO_HoaDon(SoHoaDon, tbMaTiecCuoi.Text, NgayThanhToan, int.Parse(txtTongTienBan.Text.ToString()), int.Parse(txtTongTienDichVu.Text.ToString()), int.Parse(txtTongTienHoaDon.Text.ToString()), int.Parse(txtConLai.Text.ToString()), 1); if (HoaDon.insertHoaDon(hoadon)) { HoaDon.CapNhatTiecCuoi(hoadon.MaTiecCuoi); MessageBox.Show("Lưu thành công"); resetForm(); //tbMaTiecCuoi.Text = ""; } else { MessageBox.Show("Lưu thất bại !"); } } else { MessageBox.Show("Đã có Hóa Đơn cho tiệc cưới này"); } }