Пример #1
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            DialogResult xoa = MessageBox.Show("Đồng ý xóa?", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (xoa == DialogResult.Yes)
            {
                try
                {
                    var context = new Dtb_NhaSachContext();
                    var delete  = new Sach()
                    {
                        //Stt = int.Parse(this.dgvBook.CurrentRow.Cells[0].Value.ToString().Trim()),
                        MaSach = this.dgvBook.CurrentRow.Cells[1].Value.ToString().Trim(),
                    };
                    context.Remove <Sach>(delete);
                    context.SaveChanges();

                    refreshControl();
                    sapXep();
                    loadDgvBook();
                    MessageBox.Show("Xóa thành công!!!!");
                }
                catch
                {
                    MessageBox.Show("đã xảy ra lỗi. vui lòng thử lại!");
                    return;
                }
            }
        }
Пример #2
0
        public void addTblCthd()
        {
            var context = new Dtb_NhaSachContext();

            for (int i = 0; i < this.dgv1.Rows.Count - 1; i++)
            {
                var maSach = context.Saches.Where(s => s.TenSach.Trim() == this.dgv1.Rows[i].Cells[1].Value.ToString().Trim())
                             .Select(s => s.MaSach).FirstOrDefault();

                var getSohd = context.Hoadons.Select(s => s.SoHd).Max();

                var cthd = new Chitiethoadon()
                {
                    MaSach     = maSach.Trim(),
                    SoHd       = getSohd,
                    SoLuongBan = int.Parse(this.dgv1.Rows[i].Cells[2].Value.ToString().Trim()),
                    ThanhTien  = double.Parse(this.dgv1.Rows[i].Cells[5].Value.ToString().Trim()),
                    GiamGia    = double.Parse(this.dgv1.Rows[i].Cells[4].Value.ToString().Trim()),
                    GiaSauGiam = double.Parse(this.dgv1.Rows[i].Cells[6].Value.ToString().Trim()),
                    DonGia     = double.Parse(this.dgv1.Rows[i].Cells[3].Value.ToString().Trim()),
                };
                context.Chitiethoadons.Add(cthd);
                context.SaveChanges();
            }
        }
Пример #3
0
        public void addTblHD()
        {
            var context = new Dtb_NhaSachContext();

            var maNv = context.Nhanviens.Where(s => s.TenNv.Trim() == this.cbbTenNv.Text.Trim())
                       .Select(s => new { s.MaNv }).FirstOrDefault().MaNv.Trim();
            var getSohd = context.Hoadons.Select(s => s.SoHd).Max();


            var getMatv = context.Thanhviens.Where(s => s.TenTv.Trim() == this.txtTenKh.Text.Trim())
                          .Select(s => s.MaTv).FirstOrDefault();

            var addHd = new Hoadon()
            {
                SoHd     = getSohd + 1,
                MaNv     = maNv,
                NgayBan  = DateTime.Now,
                TenKh    = this.txtTenKh.Text.Trim(),
                MaTv     = getMatv,
                TongTien = double.Parse(this.txtTongCong.Text.Trim()),
            };

            context.Hoadons.Add(addHd);
            context.SaveChanges();
        }
Пример #4
0
        public void delCthd()
        {
            var context = new Dtb_NhaSachContext();
            var list    = context.Chitiethoadons.Where(s => s.SoHd == int.Parse(this.txtMahd.Text.Trim())).ToList();

            foreach (var item in list)
            {
                context.Remove <Chitiethoadon>(item);
                context.SaveChanges();
            }
        }
Пример #5
0
        public void delHd()
        {
            var context = new Dtb_NhaSachContext();
            var hd      = new Hoadon()
            {
                SoHd = int.Parse(this.txtMahd.Text.Trim()),
            };

            context.Remove <Hoadon>(hd);
            context.SaveChanges();
        }
Пример #6
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (loiNhap() == true)
            {
                return;
            }

            var context = new Dtb_NhaSachContext();

            if (this.txtManv.Text.Trim() != this.dgvEmploy.CurrentRow.Cells[0].Value.ToString().Trim())
            {
                var cEmploy = context.Nhanviens
                              .Where(s => s.MaNv.Trim() == this.txtManv.Text.Trim())
                              .Select(s => s.MaNv).ToList();
                if (cEmploy.Count > 0)
                {
                    this.errEmploy.SetError(this.txtManv, "Mã nhân viên không được trùng");
                    return;
                }
                else
                {
                    this.errEmploy.SetError(this.txtManv, null);
                }
            }

            try
            {
                var edit = new Nhanvien()
                {
                    MaNv = this.txtManv.Text.Trim(),
                };
                edit.TenNv  = this.txtTenNv.Text.Trim();
                edit.NgSinh = this.dtpNgaySinh.Value;
                edit.DiaChi = this.txtDiaChi.Text.Trim();
                edit.Luong  = int.Parse(this.txtLuong.Text.Trim());
                edit.Sdt    = this.txtSdt.Text.Trim();
                context.Update <Nhanvien>(edit);
                context.SaveChanges();
                refreshControl();
                loadEmploy();
            }
            catch
            {
                MessageBox.Show("Đã xảy ra lỗi. Vui lòng thử lại!");
                return;
            }
        }
Пример #7
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            DialogResult xoa = MessageBox.Show("Đồng ý xóa?", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (xoa == DialogResult.Yes)
            {
                var context = new Dtb_NhaSachContext();
                var delete  = new Thanhvien()
                {
                    MaTv = int.Parse(this.dgvMember.CurrentRow.Cells[0].Value.ToString().Trim()),
                };
                context.Remove <Thanhvien>(delete);
                context.SaveChanges();
                refreshControl();
                loadMember();
            }
        }
Пример #8
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (loiNhap() == true)
            {
                return;
            }
            var context = new Dtb_NhaSachContext();
            var cEmploy = context.Nhanviens
                          .Where(s => s.MaNv.Trim() == this.txtManv.Text.Trim())
                          .Select(s => s.MaNv).ToList();

            if (cEmploy.Count > 0)
            {
                this.errEmploy.SetError(this.txtManv, "Mã nhân viên không được trùng");
                return;
            }
            else
            {
                this.errEmploy.SetError(this.txtManv, null);
            }

            try
            {
                int i  = this.dgvEmploy.Rows.Count;
                var nv = new Nhanvien()
                {
                    MaNv   = this.txtManv.Text.Trim(),
                    TenNv  = this.txtTenNv.Text.Trim(),
                    Sdt    = this.txtSdt.Text.Trim(),
                    NgSinh = this.dtpNgaySinh.Value,
                    DiaChi = this.txtDiaChi.Text.Trim(),
                    Luong  = int.Parse(this.txtLuong.Text.Trim()),
                };
                context.Nhanviens.Add(nv);
                context.SaveChanges();
                refreshControl();
                loadEmploy();
            }
            catch
            {
                MessageBox.Show("Đã xảy ra lỗi. Vui lòng thử lại!");
                return;
            }
        }
Пример #9
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (loiNhap())
            {
                return;
            }
            var context = new Dtb_NhaSachContext();
            var edit    = new Thanhvien()
            {
                MaTv = int.Parse(this.dgvMember.CurrentRow.Cells[0].Value.ToString().Trim()),
            };

            edit.TenTv       = this.txtTentv.Text.Trim();
            edit.NgaySinh    = this.dtpNgaySinh.Value;
            edit.DiaChi      = this.txtDiaChi.Text.Trim();
            edit.DiemTichLuy = int.Parse(this.txtDiem.Text.Trim());
            edit.Sdt         = this.txtSdt.Text.Trim();
            context.Update <Thanhvien>(edit);
            context.SaveChanges();
            refreshControl();
            loadMember();
        }
Пример #10
0
        public void sapXep()
        {
            var context = new Dtb_NhaSachContext();

            var sxSach = context.Saches.ToList();
            int i      = 1;

            foreach (var s in sxSach)
            {
                s.MaSach  = s.MaSach;
                s.Stt     = i;
                s.TenSach = s.TenSach;
                s.MaTg    = s.MaTg;
                s.MaNxb   = s.MaNxb;
                s.MaTl    = s.MaTl;
                s.SoLuong = s.SoLuong;
                s.GiaBan  = s.GiaBan;
                context.Update <Sach>(s);
                context.SaveChanges();
                i++;
            }
        }
Пример #11
0
        public void refreshSach()
        {
            var context = new Dtb_NhaSachContext();

            for (int i = 0; i < this.dgv1.Rows.Count - 1; i++)
            {
                var MaSach = context.Saches.Where(s => s.TenSach.Trim() == this.dgv1.Rows[i].Cells[1].Value.ToString().Trim())
                             .Select(s => s.MaSach).FirstOrDefault();
                var stt = context.Saches.Where(s => s.TenSach.Trim() == this.dgv1.Rows[i].Cells[1].Value.ToString().Trim())
                          .Select(s => s.Stt).FirstOrDefault();
                var sl = context.Saches.Where(s => s.TenSach.Trim() == this.dgv1.Rows[i].Cells[1].Value.ToString().Trim())
                         .Select(s => s.SoLuong).FirstOrDefault();
                var tenS = context.Saches.Where(s => s.TenSach.Trim() == this.dgv1.Rows[i].Cells[1].Value.ToString().Trim())
                           .Select(s => s.TenSach).FirstOrDefault();
                var nxb = context.Saches.Where(s => s.TenSach.Trim() == this.dgv1.Rows[i].Cells[1].Value.ToString().Trim())
                          .Select(s => s.MaNxb).FirstOrDefault();
                var tl = context.Saches.Where(s => s.TenSach.Trim() == this.dgv1.Rows[i].Cells[1].Value.ToString().Trim())
                         .Select(s => s.MaTl).FirstOrDefault();
                var tg = context.Saches.Where(s => s.TenSach.Trim() == this.dgv1.Rows[i].Cells[1].Value.ToString().Trim())
                         .Select(s => s.MaTg).FirstOrDefault();
                var gia = context.Saches.Where(s => s.TenSach.Trim() == this.dgv1.Rows[i].Cells[1].Value.ToString().Trim())
                          .Select(s => s.GiaBan).FirstOrDefault();

                var refresh = new Sach()
                {
                    MaSach = MaSach,
                };
                refresh.Stt     = stt;
                refresh.SoLuong = sl - int.Parse(this.dgv1.Rows[i].Cells[2].Value.ToString().Trim());
                refresh.TenSach = tenS;
                refresh.MaNxb   = nxb;
                refresh.MaTg    = tg;
                refresh.MaTl    = tl;
                refresh.GiaBan  = gia;
                context.Saches.Update(refresh);
                context.SaveChanges();
            }
        }
Пример #12
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (loiNhap())
            {
                return;
            }

            var context = new Dtb_NhaSachContext();
            int i       = this.dgvMember.Rows.Count;
            var tv      = new Thanhvien()
            {
                MaTv        = int.Parse(this.dgvMember.Rows[i - 1].Cells[0].Value.ToString().Trim()) + 1,
                TenTv       = this.txtTentv.Text.Trim(),
                Sdt         = this.txtSdt.Text.Trim(),
                NgaySinh    = this.dtpNgaySinh.Value,
                DiaChi      = this.txtDiaChi.Text.Trim(),
                DiemTichLuy = int.Parse(this.txtDiem.Text.Trim()),
            };

            context.Thanhviens.Add(tv);
            context.SaveChanges();
            refreshControl();
            loadMember();
        }
Пример #13
0
 private void btnSua_Click(object sender, EventArgs e)
 {
     if (loiNhap())
     {
         return;
     }
     #region nếu trùng khóa chính khác
     var context = new Dtb_NhaSachContext();
     if (this.cbbMs.Text.Trim() != this.dgvBook.CurrentRow.Cells[1].Value.ToString().Trim())
     {
         var cSach = context.Saches
                     .Where(s => s.MaSach.Trim() == this.cbbMs.Text.Trim())
                     .Select(s => s.MaSach).ToList();
         if (cSach.Count > 0)
         {
             this.errorProvider1.SetError(this.cbbMs, "Mã sách không được trùng");
             return;
         }
         else
         {
             this.errorProvider1.SetError(this.cbbMs, null);
         }
     }
     #endregion
     try
     {
         var edit = new Sach()
         {
             //Stt = int.Parse(this.dgvBook.CurrentRow.Cells[0].Value.ToString().Trim()),
             MaSach = this.dgvBook.CurrentRow.Cells[1].Value.ToString().Trim(),
         };
         var tg = context.Tacgia
                  .Where(t => t.TenTg == this.cbbMtg.Text.Trim())
                  .Select(t => new
         {
             t.MaTg,
         }).FirstOrDefault().MaTg.Trim();
         var nxb = context.Nxbs
                   .Where(n => n.TenNxb == this.cbbnxb.Text.Trim())
                   .Select(n => new
         {
             n.MaNxb,
         }).FirstOrDefault().MaNxb.Trim();
         var tl = context.Theloais
                  .Where(t => t.TenTl == this.cbbMtl.Text.Trim())
                  .Select(t => new
         {
             t.MaTl,
         }).FirstOrDefault().MaTl.Trim();
         edit.Stt     = int.Parse(this.dgvBook.CurrentRow.Cells[0].Value.ToString().Trim());
         edit.TenSach = this.txtTenSach.Text.Trim();
         edit.SoLuong = int.Parse(this.txtSoLuong.Text.Trim());
         edit.MaTl    = tl;
         edit.MaTg    = tg;
         edit.MaNxb   = nxb;
         edit.GiaBan  = int.Parse(this.txtGiaBan.Text.Trim());
         context.Update <Sach>(edit);
         context.SaveChanges();
         refreshControl();
         loadDgvBook();
         MessageBox.Show("Sửa thành công!!!!");
     }
     catch
     {
         MessageBox.Show("Đã xảy ra lỗi. Vui lòng thử lại!");
         return;
     }
 }
Пример #14
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (loiNhap())
            {
                return;
            }
            #region nếu trùng khóa chính
            var context = new Dtb_NhaSachContext();
            var cSach   = context.Saches
                          .Where(s => s.MaSach.Trim() == this.cbbMs.Text.Trim())
                          .Select(s => s.MaSach).ToList();
            if (cSach.Count > 0)
            {
                this.errorProvider1.SetError(this.cbbMs, "Mã sách không được trùng");
                return;
            }
            else
            {
                this.errorProvider1.SetError(this.cbbMs, null);
            }

            #endregion
            try
            {
                var tg = context.Tacgia
                         .Where(t => t.TenTg == this.cbbMtg.Text.Trim())
                         .Select(t => new
                {
                    t.MaTg,
                }).FirstOrDefault().MaTg.Trim();
                var nxb = context.Nxbs
                          .Where(n => n.TenNxb == this.cbbnxb.Text.Trim())
                          .Select(n => new
                {
                    n.MaNxb,
                }).FirstOrDefault().MaNxb.Trim();
                var tl = context.Theloais
                         .Where(t => t.TenTl == this.cbbMtl.Text.Trim())
                         .Select(t => new
                {
                    t.MaTl,
                }).FirstOrDefault().MaTl.Trim();
                var addBook = new Sach()
                {
                    Stt     = context.Saches.Count() + 1,
                    MaSach  = this.cbbMs.Text.Trim(),
                    TenSach = this.txtTenSach.Text.Trim(),
                    SoLuong = int.Parse(this.txtSoLuong.Text.Trim()),
                    MaTl    = tl,
                    MaTg    = tg,
                    MaNxb   = nxb,
                    GiaBan  = int.Parse(this.txtGiaBan.Text.Trim()),
                };
                context.Saches.Add(addBook);
                context.SaveChanges();
                MessageBox.Show("Thêm thành công!!!");
                refreshControl();
                loadDgvBook();
            }
            catch
            {
                MessageBox.Show("Đã xảy ra lỗi. Vui lòng thử lại!");
                return;
            }
        }