public ReturnType AddStockCheckAndDetails(StockCheck stockCheck, List <StockCheckDetail> CheckDetails)
        {
            try
            {
                using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString()))
                {
                    alading.AddToStockCheck(stockCheck);
                    foreach (StockCheckDetail detail in CheckDetails)
                    {
                        alading.AddToStockCheckDetail(detail);

                        #region StockInOut
                        Alading.Entity.StockInOut stockInOut = new Alading.Entity.StockInOut();
                        stockInOut.AmountTax      = 0;
                        stockInOut.DiscountFee    = 0;
                        stockInOut.DueFee         = 0;
                        stockInOut.FreightCode    = string.Empty;
                        stockInOut.FreightCompany = string.Empty;
                        stockInOut.InOutCode      = Guid.NewGuid().ToString();
                        stockInOut.InOutTime      = DateTime.Now;
                        if (detail.ProfitType == (int)ProfitType.PROFIT)
                        {
                            stockInOut.InOutType = (int)InOutType.ProfitIn;
                        }
                        else
                        {
                            stockInOut.InOutType = (int)InOutType.LossOut;
                        }
                        stockInOut.TradeOrderCode = string.Empty;

                        stockInOut.OperatorCode = stockCheck.OperatorCode;
                        stockInOut.OperatorName = string.Empty;
                        stockInOut.PayType      = (int)PayType.CASH;

                        stockInOut.IsSettled   = true;
                        stockInOut.PayTerm     = 0;
                        stockInOut.IncomeTime  = DateTime.MinValue;
                        stockInOut.PayThisTime = 0;
                        #endregion

                        #region StockDetail
                        StockDetail stockDetailOut = new StockDetail();
                        stockDetailOut.ProductSkuOuterId = detail.SkuOuterID;
                        stockDetailOut.DetailRemark      = string.Empty;
                        stockDetailOut.DetailType        = (int)DetailType.AllocateOut;
                        stockDetailOut.DurabilityDate    = DateTime.Now;
                        stockDetailOut.InOutCode         = stockInOut.InOutCode;
                        stockDetailOut.Price             = 0;
                        stockDetailOut.Quantity          = detail.CheckQuantity;
                        stockDetailOut.StockDetailCode   = Guid.NewGuid().ToString();
                        stockDetailOut.StockHouseCode    = stockCheck.StockHouseCode;
                        stockDetailOut.StockLayOutCode   = detail.LayoutCode;
                        stockDetailOut.Tax      = string.Empty;
                        stockDetailOut.TotalFee = 0;
                        #endregion

                        StockProduct product = alading.StockProduct.FirstOrDefault(i => i.SkuOuterID == detail.SkuOuterID);
                        if (product != null)
                        {
                            product.SkuQuantity = detail.Quantity;//归档
                        }
                        alading.AddToStockInOut(stockInOut);
                        alading.AddToStockDetail(stockDetailOut);
                    }

                    alading.SaveChanges();
                    return(ReturnType.Success);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
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();
                    }
                }
            }
        }