using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web.Mvc; using BeWo.Report; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using DevExpress.XtraPrinting.Native; using DevExpress.XtraReports.UI; namespace BeWoPlanerMobil.Models { public class ReportViewerModel : AbstractModel { public List AllEmployees { get; set; } public List AllTeams { get; set; } public List Queries { get; set; } public AbstractReportCreator ReportCreator { get; set; } [Display(Name = "Monat")] public int? SelectedMonth { get; set; } public List Months { get { var result = new List(); for(var i = 1; i < 13; i++) { result.Add(new SelectListItem { Value = i.ToString(), Text = new DateTime(DateTime.Now.Year, i, 1).ToString("MMMM") }); } return result; } } [Display(Name = "Jahr")] public int? SelectedYear { get; set; } public List Years { get { var result = new List(); for(var i = DateTime.Today.Year; i > DateTime.Today.Year - 11; i--) { result.Add(new SelectListItem { Value = i.ToString(), Text = i.ToString() }); } return result; } } [Display(Name="Bericht")] public ReportType SelectedReportType { get; set; } public List ReportTypes { get; set; } [Display(Name = "Bericht")] public long? SelectedCustomReport { get; set; } public List CustomReports { get { var result = new List(); if(Queries is null) { return result; } result.Add(new SelectListItem { Text = "", Value = "0" }); foreach(var query in Queries) { result.Add(new SelectListItem { Text = query.Title, Value = query.Oid.ToString() }); } return result; } } [Display(Name="Mitarbeiter")] public long? SelectedEmployeeOid { get; set; } public List Employees { get { var result = new List(); if(AllEmployees is null) { return result; } if(HasRightMitarbeiterstundenkontoViewSelf && !HasRightMitarbeiterstundenkontoViewAll) { result.Add(new SelectListItem{ Text = Employee.LastNameFirstName, Value = Employee.EmployeeOid.ToString()}); return result; } result.Add(new SelectListItem { Text = string.Empty, Value = "0" }); foreach(var employee in AllEmployees.OrderBy(e => e.SimpleDescription)) { result.Add(new SelectListItem { Text = employee.SimpleDescription, Value = employee.EmployeeOid.ToString() }); } return result; } } [Display(Name = "Team")] public long? SelectedTeamOid { get; set; } public List Teams { get { var result = new List(); if(AllTeams is null) { return result; } result.Add(new SelectListItem { Text = string.Empty, Value = "0" }); foreach(var team in AllTeams.OrderBy(t => t.Name)) { result.Add(new SelectListItem { Text = team.Name, Value = team.TeamOid.ToString() }); } return result; } } public List SelectedEmployees { get; set; } public List SelectedTeams { get; set; } public XtraReport Report { get; set; } public double ReportRatio { get { if(Report is null) { return 0d; } var width = 1f; var height = 1f; var ratio = 1d; if(Report.Pages.Count == 0) { return Math.Round(21d / 27d, 2); } foreach(PSPage page in Report.Pages) { var size = page.Size; if(size.Width > width) { width = size.Width; } if(size.Height > height) { height = size.Height; } } ratio = width < height ? width / height : height / width; return Math.Round(ratio, 2); } } } public enum ReportType { Berichte = 0, Mitarbeiterstundenkonto = 1 } }