예제 #1
0
        public StocktakeRequest CreateCycleCount(User user, List <View_StocktakeDetails> deletedDetails, List <View_StocktakeDetails> updatedDetails)
        {
            PartBLL partBll = new PartBLL();
            IQueryable <ViewPart> partQry = partBll.GetPartsByPlantToCycleCount();//partBll.GetPartsToCycleCount();
            NewStocktakeRequest   request = new NewStocktakeRequest {
                IsStatic = true, IsCycleCount = true
            };

            request.RequestBy = user.UserID;

            request.Details = new List <NewStocktakeDetails>();
            foreach (var item in partQry)
            {
                NewStocktakeDetails details = new NewStocktakeDetails
                {
                    PartID            = item.PartID.ToString(),
                    StocktakeTypeID   = 90,
                    StocktakePriority = 1
                };
                View_StocktakeDetails deletedItem = deletedDetails.Find(d => d.PartID == int.Parse(details.PartID));
                if (deletedItem == null)
                {
                    View_StocktakeDetails updatedItem = updatedDetails.Find(d => d.PartID == int.Parse(details.PartID));
                    if (updatedItem != null)
                    {
                        details.Description = updatedItem.DetailsDesc;
                    }
                    request.Details.Add(details);
                }
            }
            StocktakeRequest result       = CreateStocktakeRequest(request);
            BizParamsBLL     bizParamsBLL = new BizParamsBLL();
            BizParams        param        = bizParamsBLL.GetBizParamByKey(new BizParams {
                ParamKey = Consts.BIZ_PARAMS_CYCLECOUNTED
            });

            param.ParamValue = "True";
            bizParamsBLL.UpdateBizParams(param);

            BizParams paramCycledTimes = bizParamsBLL.GetBizParamByKey(new BizParams {
                ParamKey = Consts.BIZ_PARAMS_CYCLEDTIMES
            });
            int cycledTimes = int.Parse(paramCycledTimes.ParamValue);

            paramCycledTimes.ParamValue = (cycledTimes + 1).ToString();
            bizParamsBLL.UpdateBizParams(paramCycledTimes);
            return(result);
        }
예제 #2
0
        public List <StocktakeRequest> CreateCycleCountByPlant(User user)
        {
            PlantBLL     plantBLL = new PlantBLL();
            List <Plant> plants   = plantBLL.GetPlants();
            PartBLL      partBll  = new PartBLL();

            List <ViewPart> partList = partBll.GetPartsByPlantToCycleCount().ToList();//GetPartsToCycleCount().ToList();
            Dictionary <int, List <ViewPart> > dictDetails = new Dictionary <int, List <ViewPart> >();

            foreach (var item in plants)
            {
                int             plantID      = item.PlantID;
                List <ViewPart> partsByPlant = partList.Where(p => p.PlantID == plantID).ToList();
                if (partsByPlant != null && partsByPlant.Count > 0)
                {
                    dictDetails.Add(plantID, partsByPlant);
                }
            }
            //List<StocktakeRequest> requestList = new List<StocktakeRequest>();
            List <NewStocktakeRequest> requestList = new List <NewStocktakeRequest>();

            //group request by plant
            foreach (var plantID in dictDetails.Keys)
            {
                //StocktakeRequest request = new StocktakeRequest() { IsStatic = true, Plant = new Plant() { PlantID = plantID } };
                NewStocktakeRequest request = new NewStocktakeRequest()
                {
                    IsStatic = true, PlantID = plantID, IsCycleCount = true
                };
                request.RequestBy = user.UserID;
                //request.StocktakeDetails = new EntityCollection<StocktakeDetails>();
                request.Details = new List <NewStocktakeDetails>();
                foreach (var item in dictDetails[plantID])
                {
                    //StocktakeDetails details = new StocktakeDetails
                    //{
                    //    Part = new Part { PartID = item.PartID },
                    //    StocktakeType = new StocktakeType { TypeID = 90 },
                    //    StocktakePriority = new StocktakePriority { PriorityID = 1 }
                    //};

                    NewStocktakeDetails details = new NewStocktakeDetails
                    {
                        PartID            = item.PartID.ToString(),
                        StocktakeTypeID   = 90,
                        StocktakePriority = 1
                    };
                    //request.StocktakeDetails.Add(details);
                    request.Details.Add(details);
                }
                requestList.Add(request);
            }
            List <StocktakeRequest> newRequestList = new List <StocktakeRequest>();

            //create request by plant
            if (requestList.Count > 0)
            {
                using (Context.Connection.CreateConnectionScope())
                {
                    DbTransaction transaction = Context.BeginTransaction();
                    try
                    {
                        foreach (var item in requestList)
                        {
                            StocktakeRequest newRequest = CreateStocktakeRequest(item, transaction);
                            newRequestList.Add(newRequest);
                        }
                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                    }
                }
            }

            for (int i = 0; i < newRequestList.Count; i++)
            {
                newRequestList[i] = GetRequest(newRequestList[i]);
            }
            return(newRequestList);
        }