private void UpdateMaterialReport() { ReportCollection <MaterialReport> materialReports = new ReportCollection <MaterialReport>(); using DbRbuContext db = new DbRbuContext(); var materials = db.Materials.ToList(); var containers = db.Containers.ToList(); foreach (var materialDosingReports in db.DosingSourceMaterials.Where(x => x.BatcherMaterial.Batch.StartDt >= DateTimeFrom && x.BatcherMaterial.Batch.FinishDt <= DateTimeTo).AsEnumerable().GroupBy(x => x.MaterialId)) { var material = materials.Find(x => x.Id == materialDosingReports.Key.GetValueOrDefault()); string materialName = material != null ? material.Name : "нет в справочнике"; foreach (var containerGroup in materialDosingReports.GroupBy(x => x.ContainerId)) { var container = containers.Find(x => x.Id == containerGroup.Key.GetValueOrDefault()); string containerName = container != null ? container.Name : "нет в справочнике"; int storageId = container != null?Convert.ToInt32(container.Id) : 0; materialReports.Add(new MaterialReport { MaterialName = materialName, Storage = containerName, StorageId = storageId, SetVolume = materialDosingReports.Sum(x => x.SetVolume.Value), Volume = materialDosingReports.Sum(x => x.FinishWeightDosage - x.StartWeightDosage) }); } } Report.Load(@"Data\ReportTemplates\MaterialsReport.mrt"); Report["DateTimeFrom"] = DateTimeFrom; Report["DateTimeTo"] = DateTimeTo; Report["TaskCount"] = _batchTasks.Count(); Report["TaskVolume"] = _batchTasks.Sum(x => x.Volume); Report["BatchCount"] = _batchTasks.Sum(x => x.BatchesCount); Report.RegData("MaterialReports", materialReports); if (_designerMode) { Report.DesignWithWpf(false); _designerMode = false; } else { Report.Render(true); } }
private void UpdateTasksReport() { ReportCollection <TaskReport> taskReports = new ReportCollection <TaskReport>(); using DbRbuContext db = new DbRbuContext(); var materials = db.Materials.ToList(); var containers = db.Containers.ToList(); foreach (var report in db.Reports.Where(x => x.StartDt >= DateTimeFrom && x.FinishDt <= DateTimeTo).Include(t => t.Task).Include(c => c.Task.Customer).Include(r => r.Task.Recipe).Include(rg => rg.Task.Recipe.Group)) { TaskReport taskReport = new TaskReport { TaskId = Convert.ToInt32(report.TaskId.Value), Customer = (report.Task != null && report.Task.Customer != null) ? report.Task.Customer.Name : "не указан", Recipe = (report.Task != null && report.Task.Recipe != null) ? report.Task.Recipe.Name : "не указан", RecipeGroup = (report.Task != null && report.Task.Recipe != null && report.Task.Recipe.Group != null) ? report.Task.Recipe.Group.Name : "не указана", StartTime = report.StartDt, FinishTime = report.FinishDt, Volume = report.Task != null ? report.Task.Volume : 0, BatchCount = report.Task != null ? report.Task.BatchesAmount : 0, BatchVolume = report.Task != null ? report.Task.BatchVolume : 0 }; taskReports.Add(taskReport); } Report.Load(@"Data\ReportTemplates\TasksReport.mrt"); Report["DateTimeFrom"] = DateTimeFrom; Report["DateTimeTo"] = DateTimeTo; Report.RegData("TaskReports", taskReports); if (_designerMode) { Report.DesignWithWpf(false); _designerMode = false; } else { Report.Render(true); } }
public MaterialsUnloadReport() { MaterialsDosingReports = new ReportCollection <MaterialsDosingReport>(); }
public BatchReport() { MaterialsUnloadReports = new ReportCollection <MaterialsUnloadReport>(); }
private void UpdateReport() { if (_selectedTask != null) { ReportCollection <BatchReport> batchReports = new ReportCollection <BatchReport>(); using DbRbuContext db = new DbRbuContext(); var materials = db.Materials.Include(x => x.MaterialType).ToList(); var batchers = db.Batchers.ToList(); var dosingSources = db.DosingSources.ToList(); foreach (var batch in db.Batches.Include(x => x.Report).Where(r => r.Report.Id == _selectedTask.ReportId).Include(b => b.BatcherMaterials).ThenInclude(d => d.DosingSourceMaterials)) { BatchReport batchReport = new BatchReport { Id = batch.Id, StartTime = batch.StartDt, FinishTime = batch.FinishDt }; foreach (var unload in batch.BatcherMaterials) { MaterialsUnloadReport unloadReport = new MaterialsUnloadReport { StartWeight = unload.StartWeight, FinishWeight = unload.FinishWeight, StartTime = unload.StartLoading, FinishTime = unload.FinishLoading }; if (unload.DosingSourceMaterials.Count != 0) { long?containerID = unload.DosingSourceMaterials.First().ContainerId; if (containerID.HasValue) { var dosingSource = dosingSources.Where(x => x.ContainerId == containerID); if (dosingSource.Any()) { long?batcherId = dosingSource.First().BatcherId; var batcher = batchers.Where(x => x.Id == batcherId).FirstOrDefault(); if (batcher != null) { unloadReport.Batcher = batcher.Name; } } } } foreach (var dosing in unload.DosingSourceMaterials) { MaterialsDosingReport dosingReport = new MaterialsDosingReport { SetVolume = dosing.SetVolume.Value, StartWeight = dosing.StartWeightDosage, FinishWeight = dosing.FinishWeightDosage, StartTime = dosing.StartDosage, FinishTime = dosing.FinishDosage }; dosingReport.Material = dosing.MaterialId.ToString(); unloadReport.MaterialsDosingReports.Add(dosingReport); unloadReport.SetVolumeTotal += dosingReport.SetVolume; unloadReport.DosingWeightTotal += dosingReport.FinishWeight - dosingReport.StartWeight; } foreach (MaterialsDosingReport report in unloadReport.MaterialsDosingReports) { if (Int64.TryParse(report.Material, out long materialId)) { var material = materials.Where(x => x.Id == materialId).FirstOrDefault(); if (material != null) { report.Material = material.Name; } } } batchReport.MaterialsUnloadReports.Add(unloadReport); } batchReports.Add(batchReport); } Report.Load(@"Data\ReportTemplates\TaskReport.mrt"); Report["TaskId"] = _selectedTask.TaskId; Report["RecipeGroup"] = _selectedTask.RecipeGroup; Report["RecipeName"] = _selectedTask.RecipeName; Report["Volume"] = _selectedTask.Volume; Report["BatchVolume"] = _selectedTask.BatchVolume; Report["BatchesCount"] = _selectedTask.BatchesCount; Report["Customer"] = _selectedTask.Customer; Report["StartTime"] = _selectedTask.StartTime; Report["FinishTime"] = _selectedTask.FinishTime; Report.RegData("Batches", batchReports); if (_designerMode) { Report.DesignWithWpf(false); _designerMode = false; } else { Report.Render(true); } } }