示例#1
0
        protected bool Equals(MainStock entity)
        {
            if (entity == null) return false;
            if (!base.Equals(entity)) return false;

            return true;
        }
示例#2
0
 public void Delete(MainStock data)
 {
     MainStockDao.Delete(data);
 }
示例#3
0
 public void Update(MainStock data)
 {
     MainStockDao.Update(data);
 }
示例#4
0
 public MainStock Add(MainStock data)
 {
     MainStockDao.Add(data);
     return data;
 }
示例#5
0
        public StockIn Add(StockIn data)
        {
            IDictionary<string,MainPrice> prices = new Dictionary<string, MainPrice>();
            var maxIdResult = StockInDao.SelectSpecificType(null, Projections.Max("StockInId"));
            long nextStockInId = maxIdResult != null ? Int64.Parse(maxIdResult.ToString()) + 1 : 1;
            // add or update stock
            var maxStockIdResult = MainStockDao.SelectSpecificType(null, Projections.Max("StockId"));
            long nextStockId = maxStockIdResult != null ? Int64.Parse(maxStockIdResult.ToString()) + 1 : 1;

            data.StockInId = nextStockInId.ToString();
            StockInDao.Add(data);
            foreach (StockInDetail inDetail in data.StockInDetails)
            {
                inDetail.StockInDetailPK.StockInId = nextStockInId.ToString();
                Product current = ProductDao.FindById(inDetail.Product.ProductId);
                if (current != null)
                {
                    inDetail.Product = current;
                }
                else
                {
                    ProductDao.Add(inDetail.Product);
                }
                StockInDetailDao.Add(inDetail);

                ObjectCriteria<MainStock> findStock = new ObjectCriteria<MainStock>();
                string productId = inDetail.Product.ProductId;
                findStock.Add(stk => stk.Product.ProductId==productId);

                MainStock currentStock = MainStockDao.FindFirst(findStock) as MainStock;
                if(currentStock == null) // create new stock
                {
                   MainStock newStock = new MainStock
                                            {
                                                StockId = nextStockId++,
                                                CreateDate = DateTime.Now,
                                                UpdateDate = DateTime.Now,
                                                CreateId = "admin",
                                                UpdateId = "admin",
                                                DelFlg = 0,
                                                ExclusiveKey = 1,
                                                Product = inDetail.Product,
                                                ProductMaster = inDetail.ProductMaster,
                                                Quantity = inDetail.Quantity,
                                                GoodQuantity = inDetail.Quantity
                                            };
                    MainStockDao.Add(newStock);
                }
                else // update current stock
                {
                    currentStock.Quantity += inDetail.Quantity;
                    currentStock.GoodQuantity += inDetail.Quantity;
                    currentStock.ExclusiveKey += 1;
                    MainStockDao.Update(currentStock);
                }

                // add price for update later
                prices[inDetail.MainPrice.MainPricePK.ProductMasterId] = inDetail.MainPrice;
            }

            // update price if have
            foreach (KeyValuePair<string, MainPrice> mainPrice in prices)
            {
                ObjectCriteria<MainPrice> findPrice = new ObjectCriteria<MainPrice>();
                string productMasterId = mainPrice.Key;
                findPrice.Add(
                    price => price.MainPricePK.ProductMasterId == productMasterId);
                MainPrice currentPrice = MainPriceDao.FindFirst(findPrice) as MainPrice;
                if (currentPrice == null)
                {
                    MainPriceDao.Add(mainPrice.Value);
                }
                else
                {
                    currentPrice.Price = mainPrice.Value.Price;
                    currentPrice.WholeSalePrice = mainPrice.Value.WholeSalePrice;
                    MainPriceDao.Update(currentPrice);
                }
            }

            // color and size
            // the updating informs that specialized object has been used in stock in so it can not be deleted.
            IList<ExProductColor> colors = data.StockInDetails.Select(x => x.Product.ProductColor).Distinct().ToList();
            foreach (ExProductColor exProductColor in colors)
            {
                if(exProductColor.ExFld1 == 1) continue;
                exProductColor.ExFld1 = 1;
                ExProductColorDao.Update(exProductColor);
            }
            IList<ExProductSize> sizes = data.StockInDetails.Select(x => x.Product.ProductSize).Distinct().ToList();
            foreach (ExProductSize exProductSize in sizes)
            {
                if(exProductSize.ExFld1 == 1) continue;
                exProductSize.ExFld1 = 1;
                ExProductSizeDao.Update(exProductSize);
            }
            return data;
        }