private void btnThanhToanNoTots_Click(object sender, EventArgs e) { int r = dgvNoTot.CurrentCell.RowIndex; string ghiChu = dgvNoTot.Rows[r].Cells[1].Value.ToString(); int st = Convert.ToInt32(dgvNoTot.Rows[r].Cells[0].Value.ToString()); context = new Quan_Ly_Tieu_DungEntities3(); NoTot c = context.NoTots.Where(p => p.UserID == USER && p.Ghichu == ghiChu).ToList().First(); c.ThanhToan = true; context.SaveChanges(); var ttv = context.TienTrongVis.Where(p => p.UserID == USER); if (ttv.ToList().Count != 0) { st += Convert.ToInt32(ttv.ToList().Last().SoTien.ToString()); TienTrongVi ttvs = new TienTrongVi { UserID = USER, SoTien = st, Ngay = DateTime.Today, }; context.TienTrongVis.Add(ttvs); context.SaveChanges(); } else { TienTrongVi ttvs = new TienTrongVi { UserID = USER, SoTien = st, Ngay = DateTime.Today, }; context.TienTrongVis.Add(ttvs); context.SaveChanges(); } loadNoTot(); frmTrangChu_Load(null, null); MessageBox.Show("Đã thanh toán"); }
void themNoTots() { context = new Quan_Ly_Tieu_DungEntities3(); NoTot nx = new NoTot { Money = Convert.ToInt32(textBox1.Text), ThanhToan = false, Ghichu = textBox2.Text, UserID = USER, }; context.NoTots.Add(nx); context.SaveChanges(); MessageBox.Show("Đã thêm"); this.Close(); }