Beispiel #1
0
        public ReturnType Check(int num, List <StockDetail> stockDetailList, StockDetail checkDetail, StockCheckDetail stockCheckDetail)
        {
            System.Data.Common.DbTransaction tran = null;
            using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString()))
            {
                try
                {
                    alading.Connection.Open();
                    tran = alading.Connection.BeginTransaction();
                    StockProduct      stockProduct      = alading.StockProduct.FirstOrDefault(c => c.SkuOuterID == checkDetail.ProductSkuOuterId);
                    StockItem         stockItem         = alading.StockItem.FirstOrDefault(c => c.OuterID == stockProduct.OuterID);
                    StockHouseProduct stockHouseProduct = alading.StockHouseProduct.FirstOrDefault(c => c.HouseCode == checkDetail.StockHouseCode && c.LayoutCode == checkDetail.StockLayOutCode && c.SkuOuterID == checkDetail.ProductSkuOuterId);
                    /*修改相关数量,若报溢则加,报损则减*/
                    stockProduct.SkuQuantity += num;
                    stockItem.TotalQuantity  += num;
                    if (stockHouseProduct != null)
                    {
                        stockHouseProduct.Num += num;
                    }
                    else
                    {
                        stockHouseProduct                  = new StockHouseProduct();
                        stockHouseProduct.HouseCode        = checkDetail.StockHouseCode;
                        stockHouseProduct.HouseName        = checkDetail.HouseName;
                        stockHouseProduct.HouseProductCode = System.Guid.NewGuid().ToString();
                        stockHouseProduct.LayoutCode       = checkDetail.StockLayOutCode;
                        stockHouseProduct.LayoutName       = checkDetail.LayoutName;
                        stockHouseProduct.Num              = num;
                        stockHouseProduct.SkuOuterID       = checkDetail.ProductSkuOuterId;
                        alading.AddToStockHouseProduct(stockHouseProduct);
                    }

                    /*将出入库详情添加到历史表中并在StockDetail表中删除该数据*/
                    foreach (StockDetail stockDetail in stockDetailList)
                    {
                        HistoryStockDetail hisStockDetail = new HistoryStockDetail();
                        hisStockDetail.DetailRemark           = stockDetail.DetailRemark;
                        hisStockDetail.DetailType             = stockDetail.DetailType;
                        hisStockDetail.DurabilityDate         = stockDetail.DurabilityDate;
                        hisStockDetail.HistoryStockDetailCode = stockDetail.StockDetailCode;
                        hisStockDetail.HouseName         = stockDetail.HouseName;
                        hisStockDetail.InOutCode         = stockDetail.InOutCode;
                        hisStockDetail.LayoutName        = stockDetail.LayoutName;
                        hisStockDetail.Price             = stockDetail.Price;
                        hisStockDetail.ProductSkuOuterId = stockDetail.ProductSkuOuterId;
                        hisStockDetail.Quantity          = stockDetail.Quantity;
                        hisStockDetail.SearchText        = stockDetail.SearchText;
                        hisStockDetail.StockHouseCode    = stockDetail.StockHouseCode;
                        hisStockDetail.StockLayOutCode   = stockDetail.StockLayOutCode;
                        hisStockDetail.Tax      = stockDetail.Tax;
                        hisStockDetail.TotalFee = stockDetail.TotalFee;
                        alading.AddToHistoryStockDetail(hisStockDetail);

                        StockDetail temp = alading.StockDetail.FirstOrDefault(c => c.StockDetailCode == stockDetail.StockDetailCode);
                        if (temp != null)
                        {
                            alading.DeleteObject(temp);
                        }
                    }

                    /*将盘点生成的入库详情加入StockDetail表中,做为初始数据*/
                    alading.AddToStockDetail(checkDetail);
                    alading.AddToStockCheckDetail(stockCheckDetail);
                    alading.SaveChanges();
                    tran.Commit();
                    return(ReturnType.Success);
                }
                catch (System.Exception ex)
                {
                    if (tran != null)
                    {
                        tran.Rollback();
                    }
                    return(ReturnType.SaveFailed);
                }
                finally
                {
                    if (alading != null && alading.Connection.State != System.Data.ConnectionState.Closed)
                    {
                        alading.Connection.Close();
                    }
                }
            }
        }