예제 #1
0
        public IQueryable <ViewPart> GetPartsByPlantToCycleCount()
        {
            PlantBLL     plantBll  = new PlantBLL();
            List <Plant> plantList = plantBll.GetPlants();

            DateTime tmpDate = new DateTime(DateTime.Now.Year, 12, 31);

            int totalWeeksInYear                     = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(tmpDate, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
            int currentWeekInYear                    = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
            CycleCountLevelBLL     levelBLL          = new CycleCountLevelBLL();
            List <CycleCountLevel> levelList         = levelBLL.GetCycleCountLevel();
            List <ViewPart>        partsToCycleCount = new List <ViewPart>();
            IQueryable <ViewPart>  queryResult       = null;

            foreach (var level in levelList)
            {
                int weeksPerCycle           = totalWeeksInYear / level.times.Value;
                int restWeeksOfCurrentCycle = weeksPerCycle - (currentWeekInYear - 1) % weeksPerCycle;
                int cycledTimes             = ((currentWeekInYear - 1) / weeksPerCycle) + 1;
                int levelId = level.LevelID;
                foreach (var plant in plantList)
                {
                    int plantID = plant.PlantID;
                    //query parts to be cycle counted
                    IQueryable <ViewPart> partsToCycleCountQry = Context.ViewPart.Where(p => p.CycleCount == true && p.CycleCountLevel.Value == levelId && p.CycleCountTimes < cycledTimes && p.PlantID == plantID && p.Available == true).OrderBy(p => p.PartCode).ThenBy(p => p.DUNS);
                    // get number of parts are not cycle counted yet
                    int numberOfPartsToCycleCount = partsToCycleCountQry.Count();
                    if (numberOfPartsToCycleCount > 0)
                    {
                        if (restWeeksOfCurrentCycle > 1)//not last week of current cycle,average numbers
                        {
                            partsToCycleCountQry = partsToCycleCountQry.Take(numberOfPartsToCycleCount / restWeeksOfCurrentCycle);
                        }
                        if (queryResult == null)
                        {
                            queryResult = partsToCycleCountQry;
                        }
                        else
                        {
                            queryResult = queryResult.Union(partsToCycleCountQry);
                        }
                    }
                }
            }
            if (queryResult != null)
            {
                queryResult = queryResult.OrderBy(p => p.PartCode).ThenBy(p => p.PlantCode).ThenBy(p => p.DUNS);
            }
            return(queryResult);
        }
예제 #2
0
        public DataSet GetReports(List <int> details)
        {
            PlantBLL     bll    = new PlantBLL();
            List <Plant> plants = bll.GetPlants();
            DataSet      ds     = new DataSet();
            DataTable    dt     = GetAnalyseResult(details);

            dt.Columns["PartCode"].ColumnName        = "PN";
            dt.Columns["PartChineseName"].ColumnName = "零件名称";
            dt.Columns["PartPlantCode"].ColumnName   = "工厂";
            dt.Columns["Workshops"].ColumnName       = "车间";
            dt.Columns["Segments"].ColumnName        = "工段";
            dt.Columns["RequestUser"].ColumnName     = "申请人";
            dt.Columns["TypeName"].ColumnName        = "申请类别";
            dt.Columns["RepairAmount"].ColumnName    = "返修";
            dt.Columns["CSMTAmount"].ColumnName      = "外协";
            dt.Columns["RDCAmount"].ColumnName       = "RDC";
            dt.Columns["SGMAmount"].ColumnName       = "SGM";
            dt.Columns["Price"].ColumnName           = "UNIT PRICE";
            dt.Columns["LevelName"].ColumnName       = "盘点级别";
            //dt.Columns["CSMTDUNS"].ColumnName = "外协duns";
            dt.Columns["PlanDate"].ColumnName = "盘点日期";
            /* 2011/04/09 //MRP Controller */
            dt.Columns["WorkLocation"].ColumnName   = "PA";
            dt.Columns["CategoryName"].ColumnName   = "JIT";
            dt.Columns["HOLD"].ColumnName           = "其中HOLD";
            dt.Columns["SysHOLD"].ColumnName        = "HOLD";
            dt.Columns["UnRecorded"].ColumnName     = "分析";
            dt.Columns["Wip"].ColumnName            = "WIP";
            dt.Columns["M080"].ColumnName           = "M080";
            dt.Columns["Sys_Block_CSMT"].ColumnName = "M60(block)";
            dt.Columns["Specs"].ColumnName          = "车型";
            dt.Columns["SupplierName"].ColumnName   = "供应商名称";
            foreach (var plant in plants)
            {
                //List<View_DifferenceAnalyse> analyses = Context.View_DifferenceAnalyse.Where(a => a.PartPlantCode == plant.PlantCode && a.Status == Consts.STOCKTAKE_ANALYZING).ToList();
                dt.DefaultView.RowFilter = "[工厂]='" + plant.PlantCode + "'";
                dt.DefaultView.Sort      = "PA asc";
                //if (plant.PlantCode == "SH11")
                //{
                //    dt.Columns["M080"].ColumnName = "M180";
                //}
                DataTable filteredTable = dt.DefaultView.ToTable();
                filteredTable.TableName = plant.PlantName + "(" + plant.PlantCode + ")";

                List <string> numericCols = new List <string>();
                for (int j = 0; j < filteredTable.Columns.Count; j++)
                {
                    DataColumn col = filteredTable.Columns[j];
                    if (col.DataType == typeof(Int16) || col.DataType == typeof(Int32) || col.DataType == typeof(Int64) || col.DataType == typeof(Single) || col.DataType == typeof(Double) || col.DataType == typeof(Decimal))
                    {
                        col.ReadOnly = false;
                        numericCols.Add(col.ColumnName);
                    }
                }
                ConsignmentPartBLL cpBll = new ConsignmentPartBLL();
                for (int i = 0; i < filteredTable.Rows.Count; i++)
                {
                    DataRow row = filteredTable.Rows[i];

                    //item.PartID;
                    List <ConsignmentPartRecord> records = cpBll.QueryRecords(new ConsignmentPartRecord {
                        Part = new Part {
                            PartID = Convert.ToInt32(row["PartID"])
                        }
                    }).ToList();
                    if (records.Count > 0)
                    {
                        foreach (var record in records)
                        {
                            row["车间"] += "/" + record.Supplier.SupplierName;
                        }
                    }
                    foreach (var colName in numericCols)
                    {
                        if (row[colName] == DBNull.Value)
                        {
                            row[colName] = 0;
                        }
                    }
                }

                if (filteredTable != null && filteredTable.Rows.Count > 0)
                {
                    ds.Tables.Add(filteredTable);
                }
            }
            return(ds);
        }
예제 #3
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);
        }