SafeDispatch/Safedispatch_4_0/maptab/UIClasses/CustomTicketCellElement.cs
2024-02-22 18:43:59 +02:00

199 lines
8.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Safedispatch_4_0;
using SafeMobileLib;
using Telerik.WinControls.Layouts;
using Telerik.WinControls.UI;
namespace Dispatcher.maptab.UIClasses
{
public class CustomTicketCellElement : GridDataCellElement
{
private LightVisualElement ticketSubjectElement;
private LightVisualElement ticketBodyElement;
private LightVisualElement ticketStatusElement;
private LightVisualElement ticketNumberElement;
private StackLayoutElement stackLeft;
private StackLayoutElement stackRight;
private DockLayoutPanel dockLayout;
public CustomTicketCellElement(GridViewColumn column, GridRowElement row)
: base(column, row)
{
}
protected override void CreateChildElements()
{
base.CreateChildElements();
this.dockLayout = new DockLayoutPanel();
this.dockLayout.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
this.dockLayout.StretchHorizontally = true;
this.dockLayout.StretchVertically = true;
this.dockLayout.ShouldHandleMouseInput = false;
this.dockLayout.Margin = new Padding(0, 3, 0, 3);
this.dockLayout.Padding = new Padding(0, 3, 0, 3);
stackLeft = new StackLayoutElement();
stackLeft.StretchHorizontally = true;
stackLeft.StretchVertically = true;
stackLeft.AutoSize = true;
stackLeft.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
stackLeft.ElementSpacing = 0;
stackLeft.Orientation = Orientation.Vertical;
stackLeft.TextAlignment = ContentAlignment.MiddleLeft;
stackLeft.Alignment = ContentAlignment.MiddleLeft;
stackLeft.Margin = new Padding(5, 5, 5, 0);
ticketSubjectElement = new LightVisualElement();
Font font = new Font(
//ticketSubjectElement.Font.FontFamily,
new FontFamily("SEGOE UI"),
13,
FontStyle.Bold,
GraphicsUnit.Pixel);
ticketSubjectElement.Font = font;
ticketSubjectElement.ForeColor = MainForm2.LabelColorTicketSubject; //Color.FromArgb(72, 191, 255);
ticketSubjectElement.StretchHorizontally = true;
ticketSubjectElement.AutoSize = true;
ticketSubjectElement.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
ticketSubjectElement.Alignment = ContentAlignment.MiddleLeft;
ticketSubjectElement.TextAlignment = ContentAlignment.MiddleLeft;
ticketSubjectElement.MinSize = new System.Drawing.Size(230, 14);
ticketBodyElement = new LightVisualElement();
ticketBodyElement.AutoSize = true;
ticketBodyElement.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
ticketBodyElement.StretchHorizontally = true;
ticketBodyElement.Alignment = ContentAlignment.MiddleLeft;
ticketBodyElement.TextAlignment = ContentAlignment.MiddleLeft;
ticketBodyElement.MinSize = new System.Drawing.Size(230, 14);
// add Subject and body into left stack
stackLeft.Children.Add(ticketSubjectElement);
stackLeft.Children.Add(ticketBodyElement);
stackRight = new StackLayoutElement();
stackRight.ElementSpacing = 0;
stackRight.Orientation = Orientation.Vertical;
stackRight.TextAlignment = ContentAlignment.MiddleRight;
stackRight.Alignment = ContentAlignment.MiddleRight;
stackRight.StretchHorizontally = true;
stackRight.StretchVertically = true;
stackRight.Margin = new Padding(5, 5, 5, 0);
stackRight.MinSize = new System.Drawing.Size(107, stackRight.Size.Height);
stackRight.MaxSize = new System.Drawing.Size(107, stackRight.Size.Height);
stackRight.Size = new System.Drawing.Size(107, stackRight.Size.Height);
ticketStatusElement = new LightVisualElement();
ticketStatusElement.StretchHorizontally = false;
ticketStatusElement.Alignment = ContentAlignment.MiddleRight;
ticketStatusElement.TextAlignment = ContentAlignment.MiddleRight;
ticketStatusElement.DrawFill = true;
ticketStatusElement.NumberOfColors = 1;
ticketStatusElement.Padding = new System.Windows.Forms.Padding(0, 0, 3, 0);
ticketStatusElement.ForeColor = Color.FromArgb(213, 213, 213);
ticketNumberElement = new LightVisualElement();
ticketNumberElement.StretchHorizontally = true;
ticketNumberElement.Alignment = ContentAlignment.MiddleRight;
ticketNumberElement.TextAlignment = ContentAlignment.MiddleRight;
Font fontNumber = new Font(
ticketNumberElement.Font.FontFamily,
11,
FontStyle.Regular,
GraphicsUnit.Pixel);
ticketNumberElement.Font = fontNumber;
ticketNumberElement.ForeColor = Color.FromArgb(0x66, 0x66, 0x66);
// add status and number into right stack
stackRight.Children.Add(ticketStatusElement);
stackRight.Children.Add(ticketNumberElement);
dockLayout.Children.Add(stackLeft);
dockLayout.Children.Add(stackRight);
DockLayoutPanel.SetDock(this.stackLeft, Telerik.WinControls.Layouts.Dock.Left);
DockLayoutPanel.SetDock(this.stackRight, Telerik.WinControls.Layouts.Dock.Right);
this.Children.Add(dockLayout);
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridDataCellElement);
}
}
public override bool IsCompatible(GridViewColumn data, object context)
{
return data is CustomTicketColumn && context is GridDataRowElement;
}
public override void SetContent()
{
GridViewHierarchyRowInfo row = this.RowInfo as GridViewHierarchyRowInfo;
if (row != null)
{
JobTickets jt = row.DataBoundItem as JobTickets;
if (jt != null)
{
DateTime endDate = DateTime.UtcNow.AddDays(-10);
// try to parse the end time
if(jt.End_time_specified != null)
DateTime.TryParse(jt.End_time_specified, out endDate);
// change color for an expired ticket
if (jt.IsExpired)
this.ticketSubjectElement.ForeColor = Color.FromArgb(255, 0, 0);
else
this.ticketSubjectElement.ForeColor = MainForm2.LabelColorTicketSubject;
this.ticketSubjectElement.Text = jt.Name;
this.ticketBodyElement.Text = jt.Comment;
this.ticketNumberElement.Text = "#" + jt.Ticket_id + "";
this.ticketStatusElement.Text = jt.Status;
// change background and forecolor depending on the ticket status
this.ticketStatusElement.BackColor =
SafeMobileLib.Utils.TicketingStatuses.GetTicketStatusColor(jt.Status);
// flag the deleted tickets
if(jt.Deleted == 1)
{
this.ticketSubjectElement.ForeColor = Color.DarkGray;
this.ticketBodyElement.ForeColor = Color.DarkGray;
this.ticketStatusElement.DrawFill = false;
this.ticketStatusElement.ForeColor = Color.DarkGray;
this.ticketNumberElement.ForeColor = Color.DarkGray;
}
}
}
this.Text = string.Empty;
}
}
}