void themNoXaus()
        {
            context = new Quan_Ly_Tieu_DungEntities3();
            NoXau nx = new NoXau
            {
                Money     = Convert.ToInt32(textBox1.Text),
                ThanhToan = false,
                Ghichu    = textBox2.Text,
                UserID    = USER,
            };

            context.NoXaus.Add(nx);
            context.SaveChanges();
            MessageBox.Show("Đã thêm");
            this.Close();
        }
Esempio n. 2
0
        private void btnThanhToanXau_Click(object sender, EventArgs e)
        {
            context = new Quan_Ly_Tieu_DungEntities3();
            var ttv = context.TienTrongVis.Where(p => p.UserID == USER);

            int r = dgvNoXau.CurrentCell.RowIndex;


            // lấy số tiền trong ví
            int temp = 0;

            if (ttv.ToList().Count != 0)
            {
                temp = Convert.ToInt32(ttv.ToList().Last().SoTien.ToString());
            }
            // lấy ghi chú
            string ghiChu = dgvNoXau.Rows[r].Cells[1].Value.ToString();

            // lấy số tiền cần thanh toán
            int st = Convert.ToInt32(dgvNoXau.Rows[r].Cells[0].Value.ToString());

            if (temp > st)
            {
                // chuyển true / false

                NoXau c = context.NoXaus.Where(p => p.UserID == USER && p.Ghichu == ghiChu && p.ThanhToan == false).ToList().First();
                c.ThanhToan = true;
                context.SaveChanges();


                //
                if (ttv.ToList().Count != 0)
                {
                    int stt = st;
                    st = Convert.ToInt32(ttv.ToList().Last().SoTien.ToString()) - st;

                    TienTrongVi ttvs = new TienTrongVi
                    {
                        UserID = USER,
                        SoTien = st,
                        Ngay   = DateTime.Today,
                    };
                    context.TienTrongVis.Add(ttvs);
                    context.SaveChanges();

                    // tạo thêm chi tiêu

                    LanChiTieu lcts = new LanChiTieu
                    {
                        Money   = stt,
                        Ngay    = DateTime.Today,
                        UserID  = USER,
                        Reasion = "Thanh toán cho " + ghiChu,
                    };

                    context.LanChiTieux.Add(lcts);
                    context.SaveChanges();
                }


                loadNoXau();
                frmTrangChu_Load(null, null);
                MessageBox.Show("Đã thanh toán");
            }
        }