Exemplo n.º 1
0
 //Cập nhật sản phẩm
 public bool Update(SanPham inp)
 {
     try
     {
         IEnumerable <Model.SanPham> dssp = from sanpham in db.SanPhams
                                            where sanpham.MaSanPham == inp.MaSanPham
                                            select sanpham;
         Model.SanPham sp = dssp.ElementAtOrDefault(0);
         if (sp != null)
         {
             sp.TenSanPham  = inp.TenSanPham;
             sp.MoTa        = inp.MoTa;
             sp.Thue        = inp.Thue;
             sp.DonVi       = inp.DonViTinh;
             sp.NhomSanPham = inp.Nhom;
             int kq = db.SaveChanges();
             if (kq > 0)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 2
0
        //Thêm sản phẩm
        public bool Insert(SanPham inp)
        {
            try
            {
                Model.SanPham newsp = new Model.SanPham();
                newsp.MaSanPham   = inp.MaSanPham;
                newsp.TenSanPham  = inp.TenSanPham;
                newsp.MoTa        = inp.MoTa;
                newsp.Thue        = inp.Thue;
                newsp.DonVi       = inp.DonViTinh;
                newsp.NhomSanPham = inp.Nhom;
                newsp.SoLuongTon  = 0;

                db.SanPhams.Add(newsp);
                int kq = db.SaveChanges();
                if (kq > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
 //Xoá phiếu xuất
 public bool Delete(string mapx)
 {
     try
     {
         IEnumerable <Model.PhieuXuat_CT> dsct = from ct in db.PhieuXuat_CT
                                                 where ct.MaPhieuXuat == mapx
                                                 select ct;
         if (dsct.Count() > 0)
         {
             foreach (Model.PhieuXuat_CT ct in dsct)//xoá chi tiết
             {
                 //cộng số lượng tồn
                 IEnumerable <Model.SanPham> cnsp = from sp in db.SanPhams
                                                    where sp.MaSanPham == ct.MaSanPham
                                                    select sp;
                 Model.SanPham sanpham = cnsp.ElementAtOrDefault(0);
                 sanpham.SoLuongTon = sanpham.SoLuongTon + ct.SoLuongThucXuat;
                 db.SaveChanges();
                 //xoá chi tiết phiếu
                 db.PhieuXuat_CT.Remove(ct);
             }
             int kq = db.SaveChanges();
             if (kq > 0)
             {
                 IEnumerable <Model.PhieuXuat> dspx = from px in db.PhieuXuats
                                                      where px.MaPhieuXuat == mapx
                                                      select px;
                 if (dspx.Count() > 0)
                 {
                     foreach (Model.PhieuXuat px in dspx)//xoá phiếu
                     {
                         db.PhieuXuats.Remove(px);
                     }
                     kq = db.SaveChanges();
                 }
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 4
0
 //Xoá phiếu nhập
 public bool Delete(string mapn)
 {
     try
     {
         IEnumerable <Model.PhieuNhap_CT> dsct = from ct in db.PhieuNhap_CT
                                                 where ct.MaPhieuNhap == mapn
                                                 select ct;
         if (dsct.Count() > 0)
         {
             foreach (Model.PhieuNhap_CT ct in dsct)//xoá chi tiết
             {
                 //trừ số lượng tồn
                 IEnumerable <Model.SanPham> cnsp = from sp in db.SanPhams
                                                    where sp.MaSanPham == ct.MaSanPham
                                                    select sp;
                 Model.SanPham sanpham = cnsp.ElementAtOrDefault(0);
                 sanpham.SoLuongTon = sanpham.SoLuongTon - ct.SoLuong;
                 db.SaveChanges();
                 //xoá chi tiết phiếu
                 db.PhieuNhap_CT.Remove(ct);
             }
             int kq = db.SaveChanges();
             if (kq > 0)
             {
                 IEnumerable <Model.PhieuNhap> dspn = from pn in db.PhieuNhaps
                                                      where pn.MaPhieuNhap == mapn
                                                      select pn;
                 if (dspn.Count() > 0)
                 {
                     foreach (Model.PhieuNhap pn in dspn)//xoá phiếu
                     {
                         db.PhieuNhaps.Remove(pn);
                     }
                     kq = db.SaveChanges();
                 }
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 5
0
 //Thêm phiếu xuất
 public bool Insert(PhieuXuat inp)
 {
     try
     {
         Model.PhieuXuat newpx = new Model.PhieuXuat();
         newpx.MaPhieuXuat = inp.MaPhieuXuat;
         newpx.NgayXuat    = inp.NgayXuat;
         newpx.NhanVien    = inp.MaNhanVien;
         newpx.KhachHang   = inp.MaKhachHang;
         newpx.DiaChiNhan  = inp.DiaChiGiaoHang;
         newpx.HoaDon      = inp.MaHoaDon;
         newpx.TongTien    = inp.TongTien;
         db.PhieuXuats.Add(newpx);
         int kq = db.SaveChanges();
         if (kq > 0)
         {
             foreach (PhieuXuatCT ct in inp.DSChiTiet)
             {
                 //Thêm vào chi tiết phiếu xuất
                 Model.PhieuXuat_CT newct = new Model.PhieuXuat_CT();
                 newct.MaPhieuXuat     = ct.MaPhieuXuat;
                 newct.MaSanPham       = ct.MaSanPham;
                 newct.SoLuongYeuCau   = ct.SoLuongYeuCau;
                 newct.SoLuongThucXuat = ct.SoLuongThuc;
                 newct.DonGia          = ct.DonGia;
                 db.PhieuXuat_CT.Add(newct);
                 db.SaveChanges();
                 //Cộng vào số lượng tồn
                 IEnumerable <Model.SanPham> cnsp = from sp in db.SanPhams
                                                    where sp.MaSanPham == newct.MaSanPham
                                                    select sp;
                 Model.SanPham sanpham = cnsp.ElementAtOrDefault(0);
                 sanpham.SoLuongTon = sanpham.SoLuongTon - ct.SoLuongThuc;
                 db.SaveChanges();
             }
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 6
0
 //Thêm phiếu nhập
 public bool Insert(PhieuNhap inp)
 {
     try
     {
         Model.PhieuNhap newpn = new Model.PhieuNhap();
         newpn.MaPhieuNhap = inp.MaPhieuNhap;
         newpn.NhanVien    = inp.MaNhanVien;
         newpn.NgayNhap    = inp.NgayNhap;
         newpn.TongTien    = inp.TongTien;
         db.PhieuNhaps.Add(newpn);
         int kq = db.SaveChanges();
         if (kq > 0)
         {
             foreach (PhieuNhapCT ct in inp.DSChiTiet)
             {
                 //Thêm vào chi tiết phiếu nhập
                 Model.PhieuNhap_CT newct = new Model.PhieuNhap_CT();
                 newct.MaPhieuNhap = ct.MaPhieuNhap;
                 newct.MaSanPham   = ct.MaSanPham;
                 newct.SoLuong     = ct.SoLuong;
                 newct.DonGia      = ct.DonGia;
                 db.PhieuNhap_CT.Add(newct);
                 db.SaveChanges();
                 //Cộng vào số lượng tồn
                 IEnumerable <Model.SanPham> cnsp = from sp in db.SanPhams
                                                    where sp.MaSanPham == newct.MaSanPham
                                                    select sp;
                 Model.SanPham sanpham = cnsp.ElementAtOrDefault(0);
                 sanpham.SoLuongTon = sanpham.SoLuongTon + ct.SoLuong;
                 db.SaveChanges();
             }
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 7
0
 //Sửa phiếu xuất
 public bool Update(PhieuXuat inp)
 {
     try
     {
         IEnumerable <Model.PhieuXuat> dspx = from px in db.PhieuXuats
                                              where px.MaPhieuXuat == inp.MaPhieuXuat
                                              select px;
         Model.PhieuXuat phieuxuat = dspx.ElementAtOrDefault(0);
         if (phieuxuat != null)
         {
             phieuxuat.NhanVien   = inp.MaNhanVien;
             phieuxuat.KhachHang  = inp.MaKhachHang;
             phieuxuat.NgayXuat   = inp.NgayXuat;
             phieuxuat.DiaChiNhan = inp.DiaChiGiaoHang;
             phieuxuat.HoaDon     = inp.MaHoaDon;
             phieuxuat.TongTien   = inp.TongTien;
             db.SaveChanges();
             //Xoá chi tiết phiếu xuất cũ
             IEnumerable <Model.PhieuXuat_CT> dsctc = from ctc in db.PhieuXuat_CT
                                                      where ctc.MaPhieuXuat == inp.MaPhieuXuat
                                                      select ctc;
             if (dsctc.Count() > 0)
             {
                 foreach (Model.PhieuXuat_CT ctc in dsctc)
                 {
                     //cộng số lượng tồn
                     Model.QuanLiBanHangEntities db2  = new Model.QuanLiBanHangEntities();
                     IEnumerable <Model.SanPham> cnsp = from sp in db2.SanPhams
                                                        where sp.MaSanPham == ctc.MaSanPham
                                                        select sp;
                     Model.SanPham sanpham = cnsp.ElementAtOrDefault(0);
                     sanpham.SoLuongTon = sanpham.SoLuongTon + ctc.SoLuongThucXuat;
                     db2.SaveChanges();
                     //xoá chi tiết phiếu
                     db.PhieuXuat_CT.Remove(ctc);
                 }
                 db.SaveChanges();
             }
             //Nhập lại chi tiết phiếu
             foreach (PhieuXuatCT ct in inp.DSChiTiet)
             {
                 Model.PhieuXuat_CT newct = new Model.PhieuXuat_CT();
                 newct.MaPhieuXuat     = ct.MaPhieuXuat;
                 newct.MaSanPham       = ct.MaSanPham;
                 newct.SoLuongYeuCau   = ct.SoLuongYeuCau;
                 newct.SoLuongThucXuat = ct.SoLuongThuc;
                 newct.DonGia          = ct.DonGia;
                 db.PhieuXuat_CT.Add(newct);
                 db.SaveChanges();
                 //Trừ vào số lượng tồn
                 IEnumerable <Model.SanPham> cnsp = from sp in db.SanPhams
                                                    where sp.MaSanPham == newct.MaSanPham
                                                    select sp;
                 Model.SanPham sanpham = cnsp.ElementAtOrDefault(0);
                 sanpham.SoLuongTon = sanpham.SoLuongTon - ct.SoLuongThuc;
                 db.SaveChanges();
             }
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 8
0
 //Sửa phiếu nhập
 public bool Update(PhieuNhap inp)
 {
     try
     {
         IEnumerable <Model.PhieuNhap> dspn = from pn in db.PhieuNhaps
                                              where pn.MaPhieuNhap == inp.MaPhieuNhap
                                              select pn;
         Model.PhieuNhap phieunhap = dspn.ElementAtOrDefault(0);
         if (phieunhap != null)
         {
             phieunhap.NhanVien = inp.MaNhanVien;
             phieunhap.NgayNhap = inp.NgayNhap;
             phieunhap.TongTien = inp.TongTien;
             db.SaveChanges();
             //Xoá chi tiết phiếu nhập cũ
             IEnumerable <Model.PhieuNhap_CT> dsctc = from ctc in db.PhieuNhap_CT
                                                      where ctc.MaPhieuNhap == inp.MaPhieuNhap
                                                      select ctc;
             if (dsctc.Count() > 0)
             {
                 foreach (Model.PhieuNhap_CT ctc in dsctc)
                 {
                     //trừ số lượng tồn
                     Model.QuanLiBanHangEntities db2  = new Model.QuanLiBanHangEntities();
                     IEnumerable <Model.SanPham> cnsp = from sp in db2.SanPhams
                                                        where sp.MaSanPham == ctc.MaSanPham
                                                        select sp;
                     Model.SanPham sanpham = cnsp.ElementAtOrDefault(0);
                     sanpham.SoLuongTon = sanpham.SoLuongTon - ctc.SoLuong;
                     db2.SaveChanges();
                     //xoá chi tiết phiếu
                     db.PhieuNhap_CT.Remove(ctc);
                 }
                 db.SaveChanges();
             }
             //Nhập lại chi tiết phiếu
             foreach (PhieuNhapCT ct in inp.DSChiTiet)
             {
                 Model.PhieuNhap_CT newct = new Model.PhieuNhap_CT();
                 newct.MaPhieuNhap = ct.MaPhieuNhap;
                 newct.MaSanPham   = ct.MaSanPham;
                 newct.SoLuong     = ct.SoLuong;
                 newct.DonGia      = ct.DonGia;
                 db.PhieuNhap_CT.Add(newct);
                 db.SaveChanges();
                 //Cộng vào số lượng tồn
                 IEnumerable <Model.SanPham> cnsp = from sp in db.SanPhams
                                                    where sp.MaSanPham == newct.MaSanPham
                                                    select sp;
                 Model.SanPham sanpham = cnsp.ElementAtOrDefault(0);
                 sanpham.SoLuongTon = sanpham.SoLuongTon + ct.SoLuong;
                 db.SaveChanges();
             }
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }