コード例 #1
0
 private void btnThemTieuThu_Click(object sender, EventArgs e)
 {
     try
     {
         ThemTieuThu mThemTieuThu = new ThemTieuThu(mUser, CustomerID);
         this.Parent.Parent.Enabled    = false;
         mThemTieuThu.mUCQuanLyTieuThu = this;
         mThemTieuThu.Show();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #2
0
 private void dgvTieuThu_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if ((mUser.isAdmin == 1 || mUR.isRemove.Value) && e.ColumnIndex == (tempXoa - 12)) // click nut xóa
         {
             if (dgvTieuThu["TrangThai", e.RowIndex].Value.ToString() == "CHƯA THANH TOÁN")
             {
                 string fromStr = e.RowIndex > 0 ? dgvTieuThu["ThoiGian", e.RowIndex - 1].Value.ToString() : "BAN ĐẦU";
                 var    result  = MessageBox.Show($"Bạn có chắc chắn muốn xóa tiêu thụ từ {fromStr} đến {dgvTieuThu["ThoiGian", e.RowIndex].Value.ToString()}?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                 if (result == DialogResult.Yes)
                 {
                     if (new TieuThuLDM().Delete(int.Parse(dgvTieuThu["ID", e.RowIndex].Value.ToString())))
                     {
                         MessageBox.Show("Xóa tiêu thụ thành công");
                         ReLoadDataTieuThu();
                     }
                     else
                     {
                         MessageBox.Show("Xóa tiêu thụ thất bại");
                     }
                 }
             }
             else
             {
                 MessageBox.Show("Không thể xóa tiêu thụ đã thanh toán!");
             }
         }
         if ((mUser.isAdmin == 1 || mUR.isEdit.Value) && e.ColumnIndex == (tempSua - 12)) // click nút sửa
         {
             if (dgvTieuThu["TrangThai", e.RowIndex].Value.ToString() == "CHƯA THANH TOÁN")
             {
                 Consume EditConsume = new Consume
                 {
                     ID = int.Parse(dgvTieuThu["ID", e.RowIndex].Value.ToString()),
                     NewElectricIndex = int.Parse(dgvTieuThu["ChiSoDienMoi", e.RowIndex].Value.ToString()),
                     NewWaterIndex    = int.Parse(dgvTieuThu["ChiSoNuocMoi", e.RowIndex].Value.ToString()),
                     Time             = DateTime.ParseExact(dgvTieuThu["ThoiGian", e.RowIndex].Value.ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture)
                 };
                 ThemTieuThu mThemTieuThu = new ThemTieuThu(mUser, CustomerID, EditConsume);
                 this.Parent.Parent.Enabled    = false;
                 mThemTieuThu.mUCQuanLyTieuThu = this;
                 mThemTieuThu.Show();
             }
             else
             {
                 MessageBox.Show("Không thể sửa tiêu thụ đã thanh toán!");
             }
         }
         if ((mUser.isAdmin == 1 || mUser.isPay.Value) && e.ColumnIndex == (tempTT - 12)) // click nut Thanh toan
         {
             if (dgvTieuThu["TrangThai", e.RowIndex].Value.ToString() == "CHƯA THANH TOÁN")
             {
                 Consume mConsume = new Consume
                 {
                     ID = int.Parse(dgvTieuThu["ID", e.RowIndex].Value.ToString()),
                     NewElectricIndex = int.Parse(dgvTieuThu["ChiSoDienMoi", e.RowIndex].Value.ToString()),
                     NewWaterIndex    = int.Parse(dgvTieuThu["ChiSoNuocMoi", e.RowIndex].Value.ToString()),
                     OldElectricIndex = int.Parse(dgvTieuThu["ChiSoDienCu", e.RowIndex].Value.ToString()),
                     OldWaterIndex    = int.Parse(dgvTieuThu["ChiSoNuocCu", e.RowIndex].Value.ToString()),
                     ElectricConsume  = int.Parse(dgvTieuThu["LuongDienTieuThu", e.RowIndex].Value.ToString()),
                     WaterConsume     = int.Parse(dgvTieuThu["LuongNuocTieuThu", e.RowIndex].Value.ToString()),
                     Time             = DateTime.ParseExact(dgvTieuThu["ThoiGian", e.RowIndex].Value.ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture),
                     CustomerID       = CustomerID
                 };
                 string thoiGian = string.Empty;
                 if (e.RowIndex > 0)
                 {
                     thoiGian = "Từ ngày " + dgvTieuThu["ThoiGian", e.RowIndex - 1].Value.ToString() + " đến ngày " + dgvTieuThu["ThoiGian", e.RowIndex].Value.ToString();
                 }
                 else
                 {
                     thoiGian = "Ban đầu" + " đến ngày " + dgvTieuThu["ThoiGian", e.RowIndex].Value.ToString();
                 }
                 XacNhanThanhToan oFrm = new XacNhanThanhToan(mUser, mConsume, thoiGian);
                 oFrm.mUC = this;
                 this.Parent.Parent.Enabled = false;
                 oFrm.Show();
             }
             else
             {
                 MessageBox.Show("Tiêu thụ này đã thanh toán rồi vui lòng chọn tiêu thụ khác!");
             }
         }
         if (e.ColumnIndex == (tempTHD - 12))
         {
             if (dgvTieuThu["TrangThai", e.RowIndex].Value.ToString() == "ĐÃ THANH TOÁN")
             {
                 mConsume = new Consume
                 {
                     ID = int.Parse(dgvTieuThu["ID", e.RowIndex].Value.ToString()),
                     NewElectricIndex = int.Parse(dgvTieuThu["ChiSoDienMoi", e.RowIndex].Value.ToString()),
                     NewWaterIndex    = int.Parse(dgvTieuThu["ChiSoNuocMoi", e.RowIndex].Value.ToString()),
                     OldElectricIndex = int.Parse(dgvTieuThu["ChiSoDienCu", e.RowIndex].Value.ToString()),
                     OldWaterIndex    = int.Parse(dgvTieuThu["ChiSoNuocCu", e.RowIndex].Value.ToString()),
                     ElectricConsume  = int.Parse(dgvTieuThu["LuongDienTieuThu", e.RowIndex].Value.ToString()),
                     WaterConsume     = int.Parse(dgvTieuThu["LuongNuocTieuThu", e.RowIndex].Value.ToString()),
                     Time             = DateTime.ParseExact(dgvTieuThu["ThoiGian", e.RowIndex].Value.ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture),
                     CustomerID       = CustomerID
                 };
                 thoiGian = string.Empty;
                 if (e.RowIndex > 0)
                 {
                     thoiGian = "Từ ngày " + dgvTieuThu["ThoiGian", e.RowIndex - 1].Value.ToString() + " đến ngày " + dgvTieuThu["ThoiGian", e.RowIndex].Value.ToString();
                 }
                 else
                 {
                     thoiGian = "Ban đầu" + " đến ngày " + dgvTieuThu["ThoiGian", e.RowIndex].Value.ToString();
                 }
                 mPrice = new PriceLDM().GetElement(new KhachHangLDM().GetElement(CustomerID).PriceID.Value);
                 saveFileDialog.FileName = $"Hóa đơn_{new KhachHangLDM().GetElement(CustomerID).User.DisplayName}_" + dgvTieuThu["ThoiGian", e.RowIndex].Value.ToString().Replace("/", "");
                 saveFileDialog.Title    = "Save As";
                 saveFileDialog.Filter   = "DocX|*.docx";
                 saveFileDialog.ShowDialog();
             }
             else
             {
                 MessageBox.Show("Vui lòng thanh toán trước khi tải hóa đơn!");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }