/// <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));
        }
        protected override void ShowItemInGridViewRow(DataGridViewRow row, object item)
        {
            ProductInventoryItem c = item as ProductInventoryItem;

            row.Tag = c;
            row.Cells["colInventorySheet"].Value = c.InventorySheet;
            row.Cells["colPurchaseID"].Value     = c.PurchaseID;
            row.Cells["colProductID"].Value      = c.ProductID;
            if (_Products == null)
            {
                _Products = new List <Product>();
            }
            Product p = _Products.SingleOrDefault(it => it.ID == c.ProductID);

            if (p == null)
            {
                p = new ProductBLL(AppSettings.Current.ConnStr).GetByID(c.ProductID).QueryObject;
                _Products.Add(p);
            }
            row.Cells["colProductName"].Value   = p != null ? p.Name : string.Empty;
            row.Cells["colSpecification"].Value = p != null ? p.Specification : string.Empty;
            row.Cells["colInventoryDate"].Value = c.AddDate.ToString("yyyy-MM-dd");
            row.Cells["colCount"].Value         = c.Count.Trim();
            row.Cells["colOrderID"].Value       = c.OrderID;
            row.Cells["colDeliverySheet"].Value = c.DeliverySheet;
        }
        /// <summary>
        /// 取消备货
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public CommandResult UnReserve(ProductInventoryItem item)
        {
            ProductInventoryItem clone = item.Clone();

            item.OrderItem = null;
            item.OrderID   = null;
            return(ProviderFactory.Create <IProvider <ProductInventoryItem, Guid> >(RepoUri).Update(item, clone));
        }
예제 #4
0
        private void Assign(StackOutItem si, InventoryOutType inventoryOutType, List <ProductInventoryItem> inventoryItems, List <ProductInventoryItem> addingItems)
        {
            List <ProductInventoryItem> items = new List <ProductInventoryItem>();

            if (si.OrderItem != null)  //如果出货单项有相关的订单项,那么出货时只扣除与此订单项相关的库存项和未分配给任何订单的库存项
            {
                items.AddRange(inventoryItems.Where(item => item.ProductID == si.ProductID && item.DeliveryItem == null && item.OrderItem == si.OrderItem));
            }
            if (inventoryOutType == InventoryOutType.FIFO) //根据产品的出货方式将未指定订单项的库存排序
            {
                items.AddRange(from item in inventoryItems
                               where item.ProductID == si.ProductID && item.DeliveryItem == null && item.OrderItem == null
                               orderby item.AddDate ascending
                               select item);
            }
            else
            {
                items.AddRange(from item in inventoryItems
                               where item.ProductID == si.ProductID && item.DeliveryItem == null && item.OrderItem == null
                               orderby item.AddDate descending
                               select item);
            }
            if (items.Sum(item => item.Count) < si.Count)
            {
                throw new Exception(string.Format("产品 {0} 库存不足,出货失败!", si.ProductID));
            }

            decimal count = si.Count;

            foreach (ProductInventoryItem item in items)
            {
                if (count > 0)
                {
                    if (item.Count > count) //对于部分出货的情况,一条库存记录拆成两条,其中一条表示出货的,另一条表示未出货部分,即要保证DelvieryItem不为空的都是未出货的,为空的都是已经出货的
                    {
                        ProductInventoryItem pii = item.Clone();
                        pii.ID            = Guid.NewGuid();
                        pii.OrderItem     = si.OrderItem;
                        pii.OrderID       = si.OrderID;
                        pii.DeliveryItem  = si.ID;
                        pii.DeliverySheet = si.SheetNo;
                        pii.Count         = count;
                        addingItems.Add(pii);

                        item.Count -= count;
                        count       = 0;
                    }
                    else
                    {
                        item.OrderItem     = si.OrderItem;
                        item.OrderID       = si.OrderID;
                        item.DeliveryItem  = si.ID;
                        item.DeliverySheet = si.SheetNo;
                        count -= item.Count;
                    }
                }
            }
        }
        /// <summary>
        /// 将库存分配给某个订单项,分配给某个订单项的库存不能再用于其它订单的出货,只能用于该订单项出货
        /// </summary>
        /// <param name="pi"></param>
        /// <param name="orderItem"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public CommandResult Reserve(string warehouseID, string productID, Guid orderItem, string orderID, decimal count)
        {
            IUnitWork unitWork = ProviderFactory.Create <IUnitWork>(RepoUri);
            ProductInventoryItemSearchCondition con = new ProductInventoryItemSearchCondition();

            con.Products = new List <string>();
            con.Products.Add(productID);
            con.WareHouseID = warehouseID;
            con.UnShipped   = true; //未发货的库存项
            con.UnReserved  = true; //未分配给某个特定的订单
            List <ProductInventoryItem> items = ProviderFactory.Create <IProvider <ProductInventoryItem, Guid> >(RepoUri).GetItems(con).QueryObjects;

            if (items.Sum(item => item.Count) < count)
            {
                return(new CommandResult(ResultCode.Fail, string.Format("库存不足,预分配失败!", productID)));
            }

            if (UserSettings.Current.InventoryOutType == InventoryOutType.FIFO) //根据产品的出货方式排序
            {
                items = (from item in items orderby item.AddDate ascending select item).ToList();
            }
            else
            {
                items = (from item in items orderby item.AddDate descending select item).ToList();
            }
            foreach (ProductInventoryItem pii in items)
            {
                if (count > 0)
                {
                    ProductInventoryItem pii1 = pii.Clone();
                    if (pii.Count > count) //对于部分出货的情况,一条库存记录拆成两条,其中一条表示出货的,另一条表示未出货部分,即要保证DelvieryItem不为空的都是未出货的,为空的都是已经出货的
                    {
                        pii.OrderItem = orderItem;
                        pii.OrderID   = orderID;
                        pii.Count     = count;
                        ProviderFactory.Create <IProvider <ProductInventoryItem, Guid> >(RepoUri).Update(pii, pii1, unitWork);

                        pii1.ID     = Guid.NewGuid();
                        pii1.Count -= count;
                        ProviderFactory.Create <IProvider <ProductInventoryItem, Guid> >(RepoUri).Insert(pii1, unitWork);
                        count = 0;
                    }
                    else
                    {
                        pii.OrderItem = orderItem;
                        pii.OrderID   = orderID;
                        ProviderFactory.Create <IProvider <ProductInventoryItem, Guid> >(RepoUri).Update(pii, pii1, unitWork);
                        count -= pii.Count;
                    }
                }
            }
            return(unitWork.Commit());
        }
 private void mnu_UnReserve_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("是否取消选中的订单备货项?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         foreach (DataGridViewRow row in dataGridView1.SelectedRows)
         {
             ProductInventoryItem pii = row.Tag as ProductInventoryItem;
             CommandResult        ret = (new ProductInventoryBLL(AppSettings.Current.ConnStr)).UnReserve(pii);
             if (ret.Result == ResultCode.Successful)
             {
                 row.Cells["colOrderID"].Value = string.Empty;
             }
         }
     }
 }
        private void InventoryIn(InventoryCheckRecord record, IUnitWork unitWork)
        {
            ProductInventoryItem pii = new ProductInventoryItem()
            {
                ID             = Guid.NewGuid(),
                ProductID      = record.ProductID,
                WareHouseID    = record.WarehouseID,
                Unit           = record.Unit,
                Price          = record.Price,
                Count          = record.CheckCount - record.Inventory,
                AddDate        = DateTime.Now,
                InventoryItem  = record.ID,
                InventorySheet = "盘盈",
            };

            ProviderFactory.Create <IProvider <ProductInventoryItem, Guid> >(RepoUri).Insert(pii, unitWork);
        }
        protected override void DoNullify(Order info, IUnitWork unitWork, DateTime dt, string opt)
        {
            //首先取消订单的备货项
            ProductInventoryItemSearchCondition con = new ProductInventoryItemSearchCondition();

            con.OrderID   = info.ID;
            con.UnShipped = true;
            List <ProductInventoryItem> items = ProviderFactory.Create <IProvider <ProductInventoryItem, Guid> >(RepoUri).GetItems(con).QueryObjects;

            if (items != null && items.Count > 0)
            {
                foreach (ProductInventoryItem item in items)
                {
                    ProductInventoryItem clone = item.Clone();
                    item.OrderID   = null;
                    item.OrderItem = null;
                    ProviderFactory.Create <IProvider <ProductInventoryItem, Guid> >(RepoUri).Update(item, clone, unitWork);
                }
            }
            base.DoNullify(info, unitWork, dt, opt);
        }
예제 #9
0
        /// <summary>
        /// 增加商品信息,同时指定初始库存
        /// </summary>
        /// <param name="info"></param>
        /// <param name="wareHouseID"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public CommandResult AddProduct(Product info, string wareHouseID, decimal count)
        {
            WareHouse ws = ProviderFactory.Create <IProvider <WareHouse, string> >(RepoUri).GetByID(wareHouseID).QueryObject;

            if (ws == null)
            {
                return(new CommandResult(ResultCode.Fail, "指定的仓库 \"" + wareHouseID + "\" 不存在"));
            }
            if (info.Category != null && !string.IsNullOrEmpty(info.Category.Prefix))
            {
                info.ID = ProviderFactory.Create <IAutoNumberCreater>(RepoUri).CreateNumber(info.Category.Prefix, UserSettings.Current.ProductSerialCount, "product");
            }
            else
            {
                info.ID = ProviderFactory.Create <IAutoNumberCreater>(RepoUri).CreateNumber("P", UserSettings.Current.ProductSerialCount, "product");
            }
            if (!string.IsNullOrEmpty(info.ID))
            {
                IUnitWork unitWork = ProviderFactory.Create <IUnitWork>(RepoUri);
                ProviderFactory.Create <IProvider <Product, string> >(RepoUri).Insert(info, unitWork);
                ProductInventoryItem pii = new ProductInventoryItem()
                {
                    ID             = Guid.NewGuid(),
                    ProductID      = info.ID,
                    WareHouseID    = wareHouseID,
                    Unit           = info.Unit,
                    Price          = info.Price,
                    Count          = count,
                    AddDate        = DateTime.Now,
                    InventorySheet = "初始库存"
                };
                ProviderFactory.Create <IProvider <ProductInventoryItem, Guid> >(RepoUri).Insert(pii, unitWork);
                return(unitWork.Commit());
            }
            else
            {
                return(new CommandResult(ResultCode.Fail, "创建商品编号失败,请重试"));
            }
        }
예제 #10
0
        private void InventoryOut(StackOutSheet sheet, InventoryOutType inventoryOutType, IUnitWork unitWork)
        {
            List <string> pids = sheet.Items.Select(it => it.ProductID).ToList();
            ProductInventoryItemSearchCondition con = new ProductInventoryItemSearchCondition();

            con.Products    = pids;
            con.WareHouseID = sheet.WareHouseID;
            con.UnShipped   = true;
            List <ProductInventoryItem> inventoryItems = ProviderFactory.Create <IProvider <ProductInventoryItem, Guid> >(RepoUri).GetItems(con).QueryObjects;

            if (inventoryItems == null || inventoryItems.Count == 0)
            {
                throw new Exception("没有找到相关的库存项");
            }
            List <ProductInventoryItem> clones = new List <ProductInventoryItem>();

            inventoryItems.ForEach(it => clones.Add(it.Clone()));                        //备分所有的项的克隆
            List <ProductInventoryItem> addingItems = new List <ProductInventoryItem>(); //要于保存将要增加的项

            ////减少库存
            foreach (StackOutItem si in sheet.Items)
            {
                Product p = ProviderFactory.Create <IProvider <Product, string> >(RepoUri).GetByID(si.ProductID).QueryObject;
                if (p != null && p.IsService != null && p.IsService.Value)
                {
                    continue;                                                        //如果是产品是服务的话就不用再从库存中扣除了
                }
                Assign(si, inventoryOutType, inventoryItems, addingItems);
            }
            foreach (ProductInventoryItem item in inventoryItems)
            {
                ProductInventoryItem clone = clones.Single(it => it.ID == item.ID);
                ProviderFactory.Create <IProvider <ProductInventoryItem, Guid> >(RepoUri).Update(item, clone, unitWork);
            }
            foreach (ProductInventoryItem item in addingItems)
            {
                ProviderFactory.Create <IProvider <ProductInventoryItem, Guid> >(RepoUri).Insert(item, unitWork);
            }
        }
예제 #11
0
 private void AddToProductInventory(StackInSheet sheet, IUnitWork unitWork)
 {
     foreach (StackInItem si in sheet.Items)
     {
         ProductInventoryItem pii = new ProductInventoryItem()
         {
             ID             = Guid.NewGuid(),
             ProductID      = si.ProductID,
             WareHouseID    = sheet.WareHouseID,
             Unit           = si.Unit,
             Price          = si.Price,
             Count          = si.Count,
             AddDate        = DateTime.Now,
             OrderItem      = si.OrderItem,
             OrderID        = si.OrderID,
             PurchaseItem   = si.PurchaseItem,
             PurchaseID     = si.PurchaseOrder,
             InventoryItem  = si.ID,
             InventorySheet = si.SheetNo,
         };
         ProviderFactory.Create <IProvider <ProductInventoryItem, Guid> >(RepoUri).Insert(pii, unitWork);
     }
 }