private void btnQuayLai_Click(object sender, EventArgs e) { var kiemtrahdx = dt.selectTTHDX(Convert.ToInt32(lbMaHD.Text)).FirstOrDefault(); if (kiemtrahdx == null) { FormKhachHangMoi.TTKHM.Ma = 0; FormKiemTraKhachHang.TTKHC.Ma = 0; FormTrangChu FTC = new FormTrangChu(); FTC.Show(); this.Close(); } else if (kiemtrahdx != null) { DialogResult a = MessageBox.Show("Bạn có muốn hủy hóa đơn này không ???", "Hủy", MessageBoxButtons.YesNo); if (a == DialogResult.Yes) { TTMHDX.MoFormGhiChuHuyHDX = 1; FormGhiChuHuyHDX FGCHHDX = new FormGhiChuHuyHDX(); FGCHHDX.ShowDialog(); if (FormGhiChuHuyHDX.TTDongForm.HuyHDX == 1) { FormKhachHangMoi.TTKHM.Ma = 0; FormKiemTraKhachHang.TTKHC.Ma = 0; FormTrangChu FTC = new FormTrangChu(); FTC.Show(); FormGhiChuHuyHDX.TTDongForm.HuyHDX = 0; this.Close(); } } } }
private void dgvHDX_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dgvHDX.Columns[e.ColumnIndex].Name == "Xem") { int Ma = Convert.ToInt32(dgvHDX.Rows[e.RowIndex].Cells[0].Value.ToString()); TTHDX.MaHDX = Ma; TTHDX.MoFormRP = 1; FormRPHDX FRPHDX = new FormRPHDX(); FRPHDX.ShowDialog(); } else if (dgvHDX.Columns[e.ColumnIndex].Name == "ThayDoiTrangThai") { int Ma = Convert.ToInt32(dgvHDX.Rows[e.RowIndex].Cells[0].Value.ToString()); var tthdx = dt.HDXuats.Where(s => s.Ma == Ma).FirstOrDefault(); if (tthdx.TrangThai == Convert.ToBoolean("False")) { MessageBox.Show("Hóa đơn đã hủy"); } else if (tthdx.TrangThai == Convert.ToBoolean("True")) { if (DateTime.Now.DayOfYear - Convert.ToDateTime(tthdx.NgayXuat).DayOfYear <= 2) { TTHDX.MaHDX = Ma; TTHDX.MoFormGhiChuHuy = 1; FormGhiChuHuyHDX FGCHHDX = new FormGhiChuHuyHDX(); FGCHHDX.ShowDialog(); if (FormGhiChuHuyHDX.TTDongForm.ThayDoiTrangThaiHDX == 1) { var HDX = dt.selectTTHDX(Ma).FirstOrDefault(); var KH = dt.selectTTKH(HDX.Ma_KH).FirstOrDefault(); var LKH = dt.LoaiKHs.Where(s => s.Ma == KH.Ma_LoaiKH).FirstOrDefault(); if (HDX.TongTien >= 200000) { int DiemTL = Convert.ToInt32(KH.DiemTichLuy) - 10; dt.updatediemtichluy(KH.Ma, DiemTL); if (DiemTL < 200) { dt.updateKH_LoaiKH(KH.Ma, 1); } else if (DiemTL >= 200 && DiemTL < 400) { dt.updateKH_LoaiKH(KH.Ma, 2); } } dgvHDX.DataSource = dt.selectHDX(); FormGhiChuHuyHDX.TTDongForm.ThayDoiTrangThaiHDX = 0; FGCHHDX.Close(); } } else if (DateTime.Now.DayOfYear - Convert.ToDateTime(tthdx.NgayXuat).DayOfYear > 2) { MessageBox.Show("Hóa đơn đã thanh toán trên 2 ngày\nKhông thể hủy", "Thất bại"); } } } }