public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { AssortingKanbanTodayStatistics todayStatistics = (AssortingKanbanTodayStatistics)value; GridLength finishedBatchCount = new GridLength(0, GridUnitType.Star); GridLength remainBatchCount = new GridLength(1, GridUnitType.Star); GridLength finishedPalletCount = new GridLength(0, GridUnitType.Star); GridLength remainPalletCount = new GridLength(1, GridUnitType.Star); GridLength finishedMaterialCount = new GridLength(0, GridUnitType.Star); GridLength remainMaterialCount = new GridLength(1, GridUnitType.Star); if (todayStatistics != null) { finishedBatchCount = new GridLength(todayStatistics.FinishedBatchCount, GridUnitType.Star); remainBatchCount = new GridLength(todayStatistics.TotalBatchCount - todayStatistics.FinishedBatchCount, GridUnitType.Star); finishedPalletCount = new GridLength(todayStatistics.FinishedPalletCount, GridUnitType.Star); remainPalletCount = new GridLength(todayStatistics.TotalPalletCount - todayStatistics.FinishedPalletCount, GridUnitType.Star); finishedMaterialCount = new GridLength(todayStatistics.FinishedMaterialCount, GridUnitType.Star); remainMaterialCount = new GridLength(todayStatistics.TotalMaterialCount - todayStatistics.FinishedMaterialCount, GridUnitType.Star); } switch ((string)parameter) { case Parameter_FinishedBatchCount: return(finishedBatchCount); case Parameter_RemainBatchCount: return(remainBatchCount); case Parameter_FinishedPalletCount: return(finishedPalletCount); case Parameter_RemainPalletCount: return(remainPalletCount); case Parameter_FinishedMaterialCount: return(finishedMaterialCount); case Parameter_RemainMaterialCount: return(remainMaterialCount); default: return(new GridLength(1, GridUnitType.Star)); } }
/// <summary> /// 按巷道查询今日统计。 /// </summary> /// <param name="cfgChannelId">巷道的主键。</param> public AssortingKanbanTodayStatistics QueryTodayStatistics(int cfgChannelId) { AssortingKanbanTodayStatistics result = new AssortingKanbanTodayStatistics(); try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { DateTime minTime = DateTime.Today; DateTime maxTime = minTime.AddDays(1); result.FinishedBatchCount = dbContext.AST_PalletResults .Where(pr => pr.CFG_ChannelId == cfgChannelId && pr.EndPickTime > minTime && pr.EndPickTime < maxTime) .Select(pr => pr.BatchCode) .Distinct() .Count(); result.TotalBatchCount = dbContext.AST_LesTasks .Where(lt => lt.CFG_ChannelId == cfgChannelId && lt.RequestTime > minTime && lt.RequestTime < maxTime) .Select(lt => lt.BatchCode) .Distinct() .Count(); result.FinishedPalletCount = dbContext.AST_PalletResults .Where(pr => pr.CFG_ChannelId == cfgChannelId && pr.EndPickTime > minTime && pr.EndPickTime < maxTime) .Select(pr => new { pr.BatchCode, pr.CFG_PalletId }) .Distinct() .Count(); result.TotalPalletCount = dbContext.AST_LesTasks .Where(lt => lt.CFG_ChannelId == cfgChannelId && lt.RequestTime > minTime && lt.RequestTime < maxTime) .Select(lt => new { lt.BatchCode, lt.CFG_PalletId }) .Distinct() .Count(); result.FinishedMaterialCount = dbContext.AST_PalletResultItems .Where(pri => pri.AST_PalletResult.CFG_ChannelId == cfgChannelId && pri.AST_PalletResult.EndPickTime > minTime && pri.AST_PalletResult.EndPickTime < maxTime) .Select(pri => (int?)pri.PickedQuantity) .Sum() .GetValueOrDefault(); result.TotalMaterialCount = dbContext.AST_LesTaskItems .Where(lti => lti.AST_LesTask.CFG_ChannelId == cfgChannelId && lti.AST_LesTask.RequestTime > minTime && lti.AST_LesTask.RequestTime < maxTime) .Select(lti => (int?)lti.ToPickQuantity) .Sum() .GetValueOrDefault(); } } catch (Exception ex) { string message = ex.Message; DbEntityValidationException dbEntityValidationException = ex as DbEntityValidationException; if (dbEntityValidationException != null) { foreach (DbEntityValidationResult validationResult in dbEntityValidationException.EntityValidationErrors) { foreach (DbValidationError validationError in validationResult.ValidationErrors) { message += Environment.NewLine + validationError.ErrorMessage; } } } message += Environment.NewLine + ex.StackTrace; Logger.Log("ForAssortingKanbanService.QueryTodayStatistics", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine + message + Environment.NewLine + Environment.NewLine); } return(result); }