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

252 lines
11 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 SafeMobileLib;
using Telerik.WinControls.Layouts;
using Telerik.WinControls.UI;
namespace Dispatcher.maptab.UIClasses
{
public class TicketStatusTransitionCellElement : GridDataCellElement
{
private LightVisualElement ticketPreviousStateElement;
private LightVisualElement ticketPreviousStateImageElement;
private LightVisualElement ticketCurrentStateElement;
private LightVisualElement ticketCurrentStateImageElement;
private LightVisualElement arrowElement;
private StackLayoutElement stackLeft;
private StackLayoutElement stackCenter;
private StackLayoutElement stackRight;
private StackLayoutElement stackSpace;
private DockLayoutPanel dockLayout;
public TicketStatusTransitionCellElement(GridViewColumn column, GridRowElement row)
: base(column, row)
{
}
protected override void CreateChildElements()
{
base.CreateChildElements();
this.dockLayout = new DockLayoutPanel();
this.dockLayout.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.Auto;
this.dockLayout.StretchHorizontally = false;
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);
this.dockLayout.Size = new System.Drawing.Size(46,53);
this.dockLayout.MaxSize = new System.Drawing.Size(270, 53);
stackLeft = new StackLayoutElement();
stackLeft.StretchHorizontally = false;
stackLeft.StretchVertically = true;
stackLeft.AutoSize = true;
stackLeft.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
stackLeft.ElementSpacing = 0;
stackLeft.Orientation = Orientation.Vertical;
stackLeft.TextAlignment = ContentAlignment.MiddleCenter;
stackLeft.Alignment = ContentAlignment.MiddleCenter;
stackLeft.Margin = new Padding(5, 5, 5, 0);
stackLeft.Size = new System.Drawing.Size(105, 53);
stackLeft.MinSize = new System.Drawing.Size(105, 53);
stackLeft.MaxSize = new System.Drawing.Size(105, 53);
ticketPreviousStateElement = new LightVisualElement();
Font font = new Font(
ticketPreviousStateElement.Font.FontFamily,
11,
FontStyle.Regular,
GraphicsUnit.Pixel);
ticketPreviousStateElement.Font = font;
ticketPreviousStateElement.ForeColor = Color.FromArgb(0,67,106);
ticketPreviousStateElement.StretchHorizontally = true;
ticketPreviousStateElement.AutoSize = true;
ticketPreviousStateElement.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
ticketPreviousStateElement.Alignment = ContentAlignment.MiddleCenter;
ticketPreviousStateElement.TextAlignment = ContentAlignment.MiddleCenter;
//ticketPreviousStateElement.MinSize = new System.Drawing.Size(105, ticketPreviousStateElement.Size.Height);
ticketPreviousStateImageElement = new LightVisualElement();
ticketPreviousStateImageElement.AutoSize = true;
ticketPreviousStateImageElement.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
ticketPreviousStateImageElement.StretchHorizontally = true;
ticketPreviousStateImageElement.Alignment = ContentAlignment.MiddleCenter;
ticketPreviousStateImageElement.TextAlignment = ContentAlignment.MiddleCenter;
// add Subject and body into left stack
stackLeft.Children.Add(ticketPreviousStateImageElement);
stackLeft.Children.Add(ticketPreviousStateElement);
stackCenter = new StackLayoutElement();
stackCenter.ElementSpacing = 0;
stackCenter.Orientation = Orientation.Vertical;
stackCenter.TextAlignment = ContentAlignment.MiddleCenter;
stackCenter.Alignment = ContentAlignment.MiddleCenter;
stackCenter.StretchHorizontally = false;
stackCenter.StretchVertically = true;
stackCenter.Margin = new Padding(5, 5, 5, 0);
stackCenter.BackColor = Color.DarkMagenta;
stackCenter.MaxSize = new System.Drawing.Size(40, 53);
stackCenter.MinSize = new System.Drawing.Size(40, 53);
stackCenter.Size = new System.Drawing.Size(40, 53);
arrowElement = new LightVisualElement();
arrowElement.AutoSize = true;
arrowElement.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
arrowElement.StretchHorizontally = true;
arrowElement.Alignment = ContentAlignment.MiddleCenter;
arrowElement.TextAlignment = ContentAlignment.MiddleCenter;
arrowElement.ImageAlignment = ContentAlignment.MiddleCenter;
arrowElement.Image = Utils.ScaleImage(global::Dispatcher.Properties.Resources.i_arrow, 24, 24);
// add the arrow element
stackCenter.Children.Add(arrowElement);
stackRight = new StackLayoutElement();
stackRight.ElementSpacing = 0;
stackRight.AutoSize = false;
stackRight.Orientation = Orientation.Vertical;
stackRight.TextAlignment = ContentAlignment.MiddleLeft;
stackRight.Alignment = ContentAlignment.MiddleLeft;
stackRight.StretchHorizontally = false;
stackRight.StretchVertically = true;
stackRight.Margin = new Padding(5, 5, 5, 0);
stackRight.Size = new System.Drawing.Size(105, 53);
stackRight.MinSize = new System.Drawing.Size(105, 53);
stackRight.MaxSize = new System.Drawing.Size(105, 53);
ticketCurrentStateElement = new LightVisualElement();
ticketCurrentStateElement.Font = font;
ticketCurrentStateElement.ForeColor = Color.FromArgb(0, 67, 106);
ticketCurrentStateElement.StretchHorizontally = true;
ticketCurrentStateElement.AutoSize = true;
ticketCurrentStateElement.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
ticketCurrentStateElement.Alignment = ContentAlignment.MiddleCenter;
ticketCurrentStateElement.TextAlignment = ContentAlignment.MiddleCenter;
ticketCurrentStateImageElement = new LightVisualElement();
ticketCurrentStateImageElement.StretchHorizontally = true;
ticketCurrentStateImageElement.Alignment = ContentAlignment.MiddleRight;
ticketCurrentStateImageElement.TextAlignment = ContentAlignment.MiddleRight;
Font fontNumber = new Font(
ticketCurrentStateImageElement.Font.FontFamily,
11,
FontStyle.Regular,
GraphicsUnit.Pixel);
ticketCurrentStateImageElement.Font = fontNumber;
ticketCurrentStateImageElement.ForeColor = Color.FromArgb(0x66, 0x66, 0x66);
// add status and number into right stack
stackRight.Children.Add(ticketCurrentStateImageElement);
stackRight.Children.Add(ticketCurrentStateElement);
// create the space stack element
stackSpace = new StackLayoutElement();
stackSpace.ElementSpacing = 0;
stackSpace.StretchHorizontally = true;
stackSpace.StretchVertically = true;
stackSpace.AutoSize = true;
stackSpace.Margin = new Padding(5, 5, 5, 0);
dockLayout.Children.Add(stackLeft);
dockLayout.Children.Add(stackCenter);
dockLayout.Children.Add(stackRight);
dockLayout.Children.Add(stackSpace);
DockLayoutPanel.SetDock(this.stackLeft, Telerik.WinControls.Layouts.Dock.Left);
DockLayoutPanel.SetDock(this.stackSpace, 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()
{
GridViewDataRowInfo row = this.RowInfo as GridViewDataRowInfo;
if (row != null)
{
JobTickets_log jtl = row.DataBoundItem as JobTickets_log;
if (jtl != null)
{
if (jtl.Job_status == null)
return;
if (jtl.PreviousJobStatus != null && jtl.PreviousJobStatus.Length > 0)
{
this.ticketPreviousStateElement.Text = jtl.PreviousJobStatus;
this.ticketPreviousStateImageElement.Image =
Utils.ScaleImage(GetTicketStatusImage(jtl.PreviousJobStatus), 24, 24);
this.ticketCurrentStateElement.Text = jtl.Job_status;
this.ticketCurrentStateImageElement.Image =
Utils.ScaleImage(GetTicketStatusImage(jtl.Job_status), 24, 24);
}
else
{
this.ticketPreviousStateElement.Text = jtl.Job_status;
this.ticketPreviousStateImageElement.Image =
Utils.ScaleImage(GetTicketStatusImage(jtl.Job_status), 24, 24);
// I don't have previous state
this.arrowElement.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
}
}
}
this.Text = string.Empty;
}
public static Image GetTicketStatusImage(String ticketStatus)
{
if (ticketStatus.Equals(Utils.TicketingStatuses.ASSIGNED.ToString()))
return global::Dispatcher.Properties.Resources.i_assigned;
else if (ticketStatus.Equals(Utils.TicketingStatuses.ACCEPTED.ToString()))
return global::Dispatcher.Properties.Resources.i_started;
else if (ticketStatus.Equals(Utils.TicketingStatuses.IN_PROGRESS.ToString()))
return global::Dispatcher.Properties.Resources.i_inprogress;
else if (ticketStatus.Equals(Utils.TicketingStatuses.COMPLETED.ToString()))
return global::Dispatcher.Properties.Resources.i_completed;
else if (ticketStatus.Equals(Utils.TicketingStatuses.REJECTED.ToString()))
return global::Dispatcher.Properties.Resources.i_rejected;
else if (ticketStatus.Equals(Utils.TicketingStatuses.OVERDUE.ToString()))
return global::Dispatcher.Properties.Resources.i_overdue;
return global::Dispatcher.Properties.Resources.i_assigned;
}
}
}