Exemplo n.º 1
0
        static public void Del(string strPhieuNhapID)
        {
            dbControl = new QlShop();
            PhieuNhap DelItem = dbControl.PhieuNhaps.SingleOrDefault(p => p.PhieuNhapID == strPhieuNhapID);

            if (DelItem != null)
            {
                //lay danh sach san pham cua don hang
                List <PhieuNhapChiTiet> ListSanPham = new List <PhieuNhapChiTiet>();
                ListSanPham = (from p in dbControl.PhieuNhapChiTiets
                               where p.PhieuNhapID == strPhieuNhapID
                               select p).ToList <PhieuNhapChiTiet>();
                using (TransactionScope scope = new TransactionScope())
                {
                    //foreach (PhieuNhapChiTiet item in ListSanPham)
                    //{
                    //    //cap nhat lai ton kho khi xoa
                    //    SanPhamController.CapNhatTonKho(item.SanPhamID, item.SoLuong);
                    //}
                    //cap nhat lai con no khach hang va tien hang
                    if (DelItem.NhaCungCapID != null)
                    {
                        NhaCungCapControlller.CapNhatCongNo_NhapHang(DelItem.NhaCungCapID, 0 - DelItem.ConNo, 0 - DelItem.TienHang);
                    }
                    dbControl.PhieuNhaps.Remove(DelItem);
                    dbControl.PhieuNhapChiTiets.RemoveRange(ListSanPham);
                    dbControl.SaveChanges();
                    scope.Complete();
                }
            }
        }
Exemplo n.º 2
0
        static public void Add(PhieuNhap item, List <PhieuNhapChiTiet> items)
        {
            dbControl = new QlShop();
            using (TransactionScope scope = new TransactionScope())
            {
                dbControl.PhieuNhaps.Add(item);
                dbControl.PhieuNhapChiTiets.AddRange(items);


                //cap nhat so luong ton kho

                //foreach (PhieuNhapChiTiet PhieuNhapItem in items)
                //{
                //    SanPhamController.CapNhatTonKho(PhieuNhapItem.SanPhamID, 0 - PhieuNhapItem.SoLuong);
                //}
                //cap nha cong no va tong tien hang
                if (item.NhaCungCapID != null)
                {
                    NhaCungCapControlller.CapNhatCongNo_NhapHang(item.NhaCungCapID, item.ConNo, item.TienHang);
                }
                dbControl.SaveChanges();
                scope.Complete();
            }
        }