protected override List <ProductInventory> GetingItems(System.Data.Linq.DataContext dc, SearchCondition search)
        {
            IQueryable <ProductInventory> ret = dc.GetTable <ProductInventory>();

            if (search is ProductInventorySearchCondition)
            {
                ProductInventorySearchCondition con = search as ProductInventorySearchCondition;
                if (!string.IsNullOrEmpty(con.WareHouseID))
                {
                    ret = ret.Where(item => item.WareHouseID.Contains(con.WareHouseID));
                }
                if (!string.IsNullOrEmpty(con.ProductID))
                {
                    ret = ret.Where(item => item.ProductID.Contains(con.ProductID));
                }
            }
            List <ProductInventory> items = ret.ToList();

            if (items != null && items.Count > 0)
            {
                List <Product>   ps = (new ProductProvider(ConnectStr, _MappingResource)).GetItems(null).QueryObjects;
                List <WareHouse> ws = (new WareHouseProvider(ConnectStr, _MappingResource)).GetItems(null).QueryObjects;
                foreach (ProductInventory pi in items)
                {
                    pi.Product   = ps.SingleOrDefault(p => p.ID == pi.ProductID);
                    pi.WareHouse = ws.SingleOrDefault(w => w.ID == pi.WareHouseID);
                }
            }
            return(items);
        }
        /// <summary>
        /// 建立库存
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public CommandResult CreateInventory(ProductInventory info)
        {
            ProductInventorySearchCondition con = new ProductInventorySearchCondition()
            {
                ProductID = info.ProductID, WareHouseID = info.WareHouseID
            };
            List <ProductInventory> items = ProviderFactory.Create <IProvider <ProductInventory, Guid> >(RepoUri).GetItems(con).QueryObjects;

            if (items != null && items.Count > 0)
            {
                return(new CommandResult(ResultCode.Fail, "库存项已经存在,如果想要更新库库数量,请通过盘点或收货单收货"));
            }
            ProductInventoryItem pii = new ProductInventoryItem()
            {
                ID             = Guid.NewGuid(),
                ProductID      = info.ProductID,
                WareHouseID    = info.WareHouseID,
                Unit           = info.Unit,
                Price          = info.Amount / info.Count,
                Count          = info.Count,
                AddDate        = DateTime.Now,
                InventorySheet = "初始库存"
            };

            return(ProviderFactory.Create <IProvider <ProductInventoryItem, Guid> >(RepoUri).Insert(pii));
        }
        public override CommandResult Add(InventoryCheckRecord info)
        {
            IUnitWork unitWork = ProviderFactory.Create <IUnitWork>(RepoUri);
            ProductInventorySearchCondition con = new ProductInventorySearchCondition();

            con.ProductID   = info.ProductID;
            con.WareHouseID = info.WarehouseID;
            List <ProductInventory> items = ProviderFactory.Create <IProvider <ProductInventory, Guid> >(RepoUri).GetItems(con).QueryObjects;

            if (items == null || items.Count == 0)
            {
                throw new Exception("没有该产品的库存项");
            }
            ProductInventory pi = items[0];

            if (info.Inventory != pi.Count)
            {
                throw new Exception("产品库存有改动,请重新操作");
            }
            if (info.CheckCount > pi.Count) //盘盈
            {
                InventoryIn(info, unitWork);
            }
            else if (info.CheckCount < pi.Count)  //盘亏
            {
                InventoryOut(info, UserSettings.Current.InventoryOutType, unitWork);
            }
            ProviderFactory.Create <IProvider <InventoryCheckRecord, Guid> >(RepoUri).Insert(info, unitWork);
            return(unitWork.Commit());
        }
Exemple #4
0
        private void btn_Add_Click(object sender, EventArgs e)
        {
            FrmProductInventoryMaster frm = new FrmProductInventoryMaster();

            frm.ForSelect = true;
            ProductInventorySearchCondition con = new ProductInventorySearchCondition();

            con.WareHouseID     = txtWareHouse.Tag != null ? (txtWareHouse.Tag as WareHouse).ID : null;
            frm.SearchCondition = con;
            if (frm.ShowDialog() == DialogResult.OK)
            {
                ProductInventory p = frm.SelectedItem as ProductInventory;
                AddDeliveryItem(p);
            }
        }
 private void Fresh()
 {
     if (!string.IsNullOrEmpty(WarehouseID) && !string.IsNullOrEmpty(ProductID))
     {
         ProductInventorySearchCondition con = new ProductInventorySearchCondition()
         {
             ProductID = ProductID, WareHouseID = WarehouseID
         };
         List <ProductInventory> items = (new ProductInventoryBLL(AppSettings.Current.ConnStr)).GetItems(con).QueryObjects;
         if (items != null && items.Count > 0)
         {
             txtCount.DecimalValue = items[0].Valid < MaxCount ? items[0].Valid : MaxCount;
         }
     }
 }
 private void mnu_Check_Click(object sender, EventArgs e)
 {
     if (dataGridView1.SelectedRows.Count == 1)
     {
         ProductInventory  pi  = dataGridView1.SelectedRows[0].Tag as ProductInventory;
         FrmInvnetoryCheck frm = new FrmInvnetoryCheck();
         frm.ProductInventory = pi;
         DialogResult ret = frm.ShowDialog();
         if (ret == DialogResult.OK)
         {
             ProductInventorySearchCondition con = new ProductInventorySearchCondition();
             con.ProductID   = pi.ProductID;
             con.WareHouseID = pi.WareHouseID;
             List <ProductInventory> items = (new ProductInventoryBLL(AppSettings.Current.ConnStr)).GetItems(con).QueryObjects;
             ProductInventory        pii   = items[0];
             ShowItemInGridViewRow(dataGridView1.SelectedRows[0], pii);
         }
     }
 }