using Microsoft.AspNetCore.Components; using System.Drawing; using EgwCoreLib.Razor.Data; namespace EgwCoreLib.Razor { public partial class CalWeekColumn { #region Public Enums public enum ColType { /// /// Tipo etichetta Start (SX) /// labelStart, /// /// Tipo etichetta End (DX) /// labelEnd, /// /// Colonna dati /// dataContainer } #endregion Public Enums #region Public Properties /// /// Lista etichette da mostrare (richiede tipo label...) /// [Parameter] public List EventList { get; set; } = new List(); /// /// Modalit� di disegno /// [Parameter] public ColType ItemMode { get; set; } = ColType.dataContainer; /// /// Fattore di shift in X, se 0 = nessuno shift, se > 0 è percentuale moltiplica il /// gradino calcolato /// Default: 100 (poi riportato a intero, quindi 100/100 = 1.0) /// [Parameter] public int PercX { get; set; } = 100; /// /// Fattore di shift in Y, se 0 = nessuno shift, se > 0 è percentuale moltiplica il /// gradino calcolato /// Default: 90 (poi riportato a intero, quindi 90/100 = 0.9) /// [Parameter] public int PercY { get; set; } = 90; [Parameter] public int ValMax { get; set; } = 19; [Parameter] public int ValMin { get; set; } = 9; /// /// Dimensioni viewbox /// [Parameter] public Size vBox { get; set; } = new Size(1200, 3200); #endregion Public Properties #region Protected Fields protected string Messaggio = ""; protected string titleDx = ""; protected string titleSx = ""; #endregion Protected Fields #region Protected Properties protected boxData? currData { get; set; } = null; protected int hFO { get => 100;// EventList.Count > 0 ? vBox.Height / EventList.Count : vBox.Height; } protected int mFO { get => vBox.Width * 4 / 100; } protected bool showDetail { get; set; } = false; protected int wFO { get => vBox.Width * 98 / 100; } #endregion Protected Properties #region Protected Methods protected List BoxItems() { List answ = new List(); int step = vBox.Height / (ValMax - ValMin); int numEv = EventList.Count; int evWidth = numEv > 1 ? (int)(0.5 * vBox.Width) : (int)(0.9 * vBox.Width); //int evWidth = numEv > 1 ? (int)(1.5 * vBox.Width / numEv) : (int)(0.9 * vBox.Width); int offsetX = 1; int offsetY = 0;// step / 2; if (numEv > 0) { int xStep = evWidth / (EventList.Count + 1) * PercX / 100; int yStep = evWidth * PercY / 100; //int yStep = xStep * 5; //int yStep = xStep * (EventList.Count + 50) / (EventList.Count + 6); int deltaX = 0; answ = EventList .OrderBy(x => x.Inizio) .ThenByDescending(x => x.Durata) .Select(x => new boxData() { pX = offsetX + xStep * (deltaX), pY = offsetY + yStep * (deltaX++) + (int)(x.Inizio.AddHours(-ValMin).TimeOfDay.TotalHours * step), width = evWidth, height = offsetY + (int)(x.Fine.Subtract(x.Inizio).TotalHours * step), title = x.Type, value = x.Description, start = x.Inizio, end = x.Fine, cssClass = x.CssClass }) .ToList(); } return answ; } protected async Task DetClosed(bool closed) { if (closed) { currData = null; showDetail = false; } await Task.Delay(1); } /// /// Converte la stringa in formato markup valido /// /// /// protected MarkupString getMarkup(string rawData) { return new MarkupString(rawData); } /// /// Genera una lista di etichette con corrdinate /// /// protected List LabelItems() { int step = vBox.Height / numEv;// (ValMax - ValMin); int offset = 0;// step / 2; List answ = EventList .OrderBy(x => x.Inizio) .Select(x => new labelData() { pX = vBox.Width / 10, pY = offset + (int)(x.Inizio.AddHours(-ValMin).TimeOfDay.TotalHours * step), value = x.Title }) .ToList(); return answ; } protected async void selItem(boxData item) { titleSx = $"{item.start:dddd dd}"; titleDx = $"{item.start:MMMM yyyy}"; currData = item; showDetail = true; await Task.Delay(1); await InvokeAsync(StateHasChanged); } #endregion Protected Methods #region Protected Classes protected class boxData { #region Public Properties public string cssClass { get; set; } = ""; public DateTime end { get; set; } = DateTime.Today; public int height { get; set; } = 0; public int pX { get; set; } = 0; public int pY { get; set; } = 0; public DateTime start { get; set; } = DateTime.Today; public string title { get; set; } = ""; public string value { get; set; } = ""; public int width { get; set; } = 0; #endregion Public Properties } protected class labelData { #region Public Properties public int pX { get; set; } = 0; public int pY { get; set; } = 0; public string value { get; set; } = ""; #endregion Public Properties } #endregion Protected Classes #region Private Properties private int numEv { get => EventList.Count > 0 ? EventList.Count : 1; } #endregion Private Properties } }