SafeDispatch/Safedispatch_4_0/maptab/UIClasses/CustomGroupContentCell.cs

163 lines
5.9 KiB
C#
Raw Normal View History

2024-02-22 16:43:59 +00:00
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 CustomGroupContentCell : GridGroupContentCellElement
{
private LightVisualElement statusElement;
private LightVisualElement textElement;
private LightVisualElement priorityElement;
private StackLayoutElement stack;
private DockLayoutPanel dockLayout;
public CustomGroupContentCell(GridViewColumn column, GridRowElement row)
: base(column, row)
{
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridGroupContentCellElement);
}
}
protected override void CreateChildElements()
{
base.CreateChildElements();
this.dockLayout = new DockLayoutPanel();
this.dockLayout.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
this.dockLayout.StretchHorizontally = true;
this.dockLayout.ShouldHandleMouseInput = false;
this.dockLayout.Padding = new Padding(0, 0, 0, 0);
stack = new StackLayoutElement();
stack.Orientation = Orientation.Horizontal;
stack.TextAlignment = ContentAlignment.MiddleLeft;
stack.Alignment = ContentAlignment.MiddleLeft;
//stack.Size = new System.Drawing.Size(this.RowElement.Size.Width, this.RowElement.Size.Height);
stack.StretchHorizontally = false;
stack.Margin = new Padding(0, 2, 5, 0);
statusElement = new LightVisualElement();
statusElement.MaxSize = new System.Drawing.Size(30, 30);
statusElement.MinSize = new System.Drawing.Size(30, 30);
statusElement.StretchHorizontally = true;
textElement = new LightVisualElement();
textElement.StretchHorizontally = true;
textElement.Alignment = ContentAlignment.MiddleLeft;
textElement.TextAlignment = ContentAlignment.MiddleLeft;
textElement.MinSize = new System.Drawing.Size(350, 30);
priorityElement = new LightVisualElement();
priorityElement.StretchHorizontally = true;
priorityElement.TextAlignment = ContentAlignment.MiddleLeft;
//stack.Children.Add(statusElement);
//stack.Children.Add(textElement);
//stack.Children.Add(priorityElement);
dockLayout.Children.Add(statusElement);
dockLayout.Children.Add(textElement);
dockLayout.Children.Add(priorityElement);
DockLayoutPanel.SetDock(this.statusElement, Telerik.WinControls.Layouts.Dock.Left);
DockLayoutPanel.SetDock(this.textElement, Telerik.WinControls.Layouts.Dock.Left);
//DockLayoutPanel.SetDock(this.priorityElement, Telerik.WinControls.Layouts.Dock.Right);
this.Children.Add(dockLayout);
}
public override void SetContent()
{
base.SetContent();
GridViewGroupRowInfo row = this.RowInfo as GridViewGroupRowInfo;
if (row != null)
{
this.statusElement.BackgroundImage = Utils.ScaleImage(GetStatusImage(row), 24, 24);
this.statusElement.BackgroundImageLayout = ImageLayout.Center;
this.textElement.Text = GetTicketText(row);// row.HeaderText;
priorityElement.MinSize = new System.Drawing.Size(GetPriorityColumnWidth(row), 30);
this.priorityElement.Text = GetPriorityText(row);
}
this.Text = string.Empty;
}
private Image GetStatusImage(GridViewGroupRowInfo row)
{
foreach (GridViewRowInfo childRow in row.ChildRows)
{
if(childRow.DataBoundItem is JobTickets)
{
JobTickets jt = (JobTickets) childRow.DataBoundItem;
if(jt.Status.Equals("Assigned"))
return global::Dispatcher.Properties.Resources.i_assigned;
}
}
return global::Dispatcher.Properties.Resources.i_assigned;
}
private String GetTicketText(GridViewGroupRowInfo row)
{
foreach (GridViewRowInfo childRow in row.ChildRows)
{
if (childRow.DataBoundItem is JobTickets)
{
JobTickets jt = (JobTickets)childRow.DataBoundItem;
return String.Format("Ticket #{0}: {1}", jt.Ticket_id, jt.Name);
}
}
return row.HeaderText;
}
private String GetPriorityText(GridViewGroupRowInfo row)
{
foreach (GridViewRowInfo childRow in row.ChildRows)
{
if (childRow.DataBoundItem is JobTickets)
{
JobTickets jt = (JobTickets)childRow.DataBoundItem;
return String.Format("Priority {0}", jt.Priority);
}
}
return row.HeaderText;
}
private int GetPriorityColumnWidth(GridViewGroupRowInfo row)
{
foreach (GridViewRowInfo childRow in row.ChildRows)
{
int cellSums = 0;
bool haveToAdd = false;
foreach (GridViewCellInfo cell in childRow.Cells)
{
if (cell.ColumnInfo.HeaderText.Equals("Priority"))
haveToAdd = true;
if(haveToAdd)
cellSums += cell.ColumnInfo.Width;
}
return cellSums;
}
return 50;
}
}
}