private void tlLuu_ItemClick(object sender, TileItemEventArgs e) { if (insertKH) { if (string.IsNullOrEmpty(txtMaKH.Text)) { MessageBox.Show("Mã khach hang chưa được nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (balKhachHang.KiemTraMaKH(this.txtMaKH.Text).Tables[0].Rows.Count != 0) { MessageBox.Show("Mã khách hàng đã có", "Yêu cầu", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { string error = ""; try { if (balKhachHang.ThemKhachHang(ref error, this.txtMaKH.Text, this.txtTenKH.Text, this.txtPhone.Text, this.txtDiaChi.Text, this.txtGhiChu.Text)) { MessageBox.Show("thêm thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); loadThongTin(); HienThiThongTin(false); HienThiChucNang(true); HienThiHanhDong(false); insertKH = false; } } catch (Exception err) { MessageBox.Show(err.Message, "Loi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } else if (updateKH) { try { if (string.IsNullOrEmpty(txtMaKH.Text)) { MessageBox.Show("Mã khách hàng chưa được nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (balKhachHang.KiemTraMaKH(this.txtMaKH.Text).Tables[0].Rows.Count == 0) { MessageBox.Show("Không tìm thấy mã khách hàng", "Yêu cầu", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { string error = ""; try { if (balKhachHang.CapNhatKhachHang(ref error, this.txtMaKH.Text, this.txtTenKH.Text, this.txtPhone.Text, this.txtGhiChu.Text, this.txtDiaChi.Text)) { MessageBox.Show("Cập nhật thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); loadThongTin(); HienThiThongTin(false); HienThiChucNang(true); HienThiHanhDong(false); updateKH = false; } } catch (Exception err) { MessageBox.Show(err.Message, "Loi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch (Exception error) { MessageBox.Show(error.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }