private void gridControl1_Click(object sender, EventArgs e) { int[] ids = gridView1.GetSelectedRows(); foreach (int id in ids) { curBill = gridView1.GetRow(id) as HoaDonTinhCuoc; DateTime Date = curBill.NgayLapHD.Value; DateTime From = new DateTime(Date.Year, Date.Month, 1); DateTime To = new DateTime(Date.Year, Date.Month, DateTime.DaysInMonth(Date.Year, Date.Month)); gridControl2.DataSource = db.ChiTietSuDungs.Where(x => x.IDSIM == curBill.IDSIM).Where(x => x.TGBD >= From && x.TGBD <= To).ToList(); } }
private void btnCal_Click(object sender, EventArgs e) { List <String> IDSims = db.ThongTinSIMs.Select(x => x.IDSIM).Distinct().ToList(); foreach (string sim in IDSims) { string MaHDTC = "HDTC" + DateTime.Now.Month + sim; if (db.HoaDonTinhCuocs.FirstOrDefault(x => x.MaHDTC == MaHDTC) != null) { continue; } HoaDonTinhCuoc bill = new HoaDonTinhCuoc { IDSIM = sim, MaHDTC = MaHDTC, NgayLapHD = DateTime.Now, PhiThueBao = 50000, ThanhToan = false, ThongTinSIM = db.ThongTinSIMs.FirstOrDefault(x => x.IDSIM == sim), TongTien = 0 }; decimal TongTien = 0; DateTime Date = bill.NgayLapHD.Value; DateTime From = new DateTime(Date.Year, Date.Month, 1); DateTime To = new DateTime(Date.Year, Date.Month, DateTime.DaysInMonth(Date.Year, Date.Month)); List <ChiTietSuDung> ChiTiets = db.ChiTietSuDungs.Where(x => x.IDSIM == bill.IDSIM).Where(x => x.TGBD >= From && x.TGBD <= To).ToList(); foreach (ChiTietSuDung ct in ChiTiets) { TongTien += Convert.ToDecimal(ct.PhiCuocGoi); } bill.TongTien = bill.PhiThueBao + TongTien; db.HoaDonTinhCuocs.Add(bill); db.SaveChanges(); } RefreshData(); }