Example #1
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            DialogResult tl = MessageBox.Show("Không thể khôi phục!!! Bạn chắc chắn xóa thông tin này?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (tl == DialogResult.Yes)
            {
                int      r      = dataGridView1.CurrentCell.RowIndex;
                DateTime t      = Convert.ToDateTime(dataGridView1.Rows[r].Cells[0].Value.ToString());
                int      SoTien = Convert.ToInt32(dataGridView1.Rows[r].Cells[1].Value.ToString());
                string   lyDo   = dataGridView1.Rows[r].Cells[2].Value.ToString();

                context = new Quan_Ly_Tieu_DungEntities3();
                var removeRows = context.LanChiTieux.Where(p => p.Ngay == t && p.Money == SoTien && p.Reasion == lyDo).ToList();
                if (removeRows != null)
                {
                    context.LanChiTieux.Remove(removeRows.First());
                    context.SaveChanges();
                    TienTrongVi ttv = new TienTrongVi
                    {
                        Ngay   = DateTime.Today,
                        SoTien = tien + SoTien,
                        UserID = USER,
                    };

                    context.TienTrongVis.Add(ttv);
                    context.SaveChanges();
                    MessageBox.Show("Đã xóa - Số tiền đã được khôi phục trở lại ví");
                    frmTrangChu_Load(null, null);
                }
            }
        }
        void newchitieu()
        {
            context = new Quan_Ly_Tieu_DungEntities3();
            LanChiTieu lct = new LanChiTieu
            {
                Money   = Convert.ToInt32(textBox1.Text),
                Reasion = textBox2.Text,
                Ngay    = DateTime.Now,
                UserID  = USER
            };

            context.LanChiTieux.Add(lct);
            context.SaveChanges();

            var sst = context.TienTrongVis.Where(p => p.UserID == USER);

            if (sst.ToList().Count != 0)
            {
                int sstv = Convert.ToInt32(sst.ToList().Last().SoTien.ToString());

                TienTrongVi ttv = new TienTrongVi
                {
                    Ngay   = DateTime.Today,
                    SoTien = sstv - Convert.ToInt32(textBox1.Text),
                    UserID = USER
                };

                context.TienTrongVis.Add(ttv);
                context.SaveChanges();
            }
            MessageBox.Show("Đã lưu");
            this.Close();
        }
        void themThuNhap()
        {
            context = new Quan_Ly_Tieu_DungEntities3();
            var thistn = context.TienTrongVis.Where(p => p.UserID == USER);
            int st     = 0;

            if (thistn.ToList().Count != 0)
            {
                st = Convert.ToInt32(thistn.ToList().Last().SoTien);
                TienTrongVi ttv = new TienTrongVi
                {
                    Ngay   = DateTime.Today,
                    SoTien = st + Convert.ToInt32(textBox1.Text),
                    UserID = USER,
                };

                context.TienTrongVis.Add(ttv);
                context.SaveChanges();
                MessageBox.Show("Đã thêm");
            }
            else
            {
                st = Convert.ToInt32(thistn.ToList().Last().SoTien);
                TienTrongVi ttv = new TienTrongVi
                {
                    Ngay   = DateTime.Today,
                    SoTien = Convert.ToInt32(textBox1.Text),
                    UserID = USER,
                };

                context.TienTrongVis.Add(ttv);
                context.SaveChanges();
                MessageBox.Show("Đã thêm");
            }
        }
Example #4
0
        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");
        }
Example #5
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            context = new Quan_Ly_Tieu_DungEntities3();
            var isnewper = context.Users.Where(p => p.userID == textBox1.Text);

            if (isnewper.ToList().Count == 0)
            {
                if (textBox2.Text != textBox3.Text)
                {
                    MessageBox.Show("Mật khẩu không khớp");
                    textBox2.ResetText();
                    textBox3.ResetText();
                }
                else
                {
                    User nu = new User
                    {
                        userID       = textBox1.Text,
                        userPassWord = textBox2.Text,
                        userName     = textBox4.Text
                    };
                    context.Users.Add(nu);
                    context.SaveChanges();


                    TienTrongVi ttv = new TienTrongVi
                    {
                        Ngay   = DateTime.Today,
                        SoTien = 0,
                        UserID = textBox1.Text,
                    };

                    context.TienTrongVis.Add(ttv);
                    context.SaveChanges();
                    MessageBox.Show("Đã tạo tài khoản");
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Tài khoản đã tổn tại");
                textBox1.ResetText();
                textBox2.ResetText();
                textBox3.ResetText();
            }
        }
Example #6
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");
            }
        }