SafeDispatch/Safedispatch_4_0/maptab/UIClasses/LiveGridCellElement.cs

985 lines
43 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
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 LiveGridCellElement : GridDataCellElement
{
static int counter = 0;
private LightVisualElement timeElement;
private LightVisualElement unitNameElement;
private LightVisualElement statusElement;
private LightVisualElement speedElement;
private LightVisualElement unitIconElement;
private LightVisualElement alertsIconElement;
private LightVisualElement stolenIconElement;
private LightVisualElement centerMapIconElement;
private LightVisualElement textMessageIconElement;
private LightVisualElement ticketingIconElement;
private LightVisualElement voiceIconElement;
//private RadCheckBoxElement isDisplayedElement;
private StackLayoutElement stackTop;
private StackLayoutElement stackBottom;
private StackLayoutElement stackRight;
private DockLayoutPanel dockLayout;
public LiveGridCellElement(GridViewColumn column, GridRowElement row)
: base(column, row)
{
}
protected override void CreateChildElements()
{
base.CreateChildElements();
this.dockLayout = new DockLayoutPanel();
this.dockLayout.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.WrapAroundChildren;
this.dockLayout.StretchHorizontally = true;
this.dockLayout.StretchVertically = true;
this.dockLayout.AutoSize = true;
this.dockLayout.ShouldHandleMouseInput = false;
this.dockLayout.Margin = new Padding(0, 0, 0, 0);
this.dockLayout.Padding = new Padding(0, 0, 0, 0);
this.dockLayout.AutoToolTip = true;
//this.dockLayout.MaxSize = new System.Drawing.Size(249, 55);
//this.dockLayout.MinSize = new System.Drawing.Size(249, 55);
stackRight = new StackLayoutElement();
stackRight.ElementSpacing = 0;
stackRight.Orientation = Orientation.Vertical;
stackRight.TextAlignment = ContentAlignment.MiddleLeft;
stackRight.Alignment = ContentAlignment.MiddleLeft;
stackRight.StretchHorizontally = true;
stackRight.StretchVertically = true;
stackRight.AutoSize = true;
stackRight.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
stackRight.Margin = new Padding(0, 0, 0, 0);
stackRight.AutoToolTip = true;
/*
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);*/
stackTop = new StackLayoutElement();
stackTop.StretchHorizontally = true;
stackTop.StretchVertically = true;
stackTop.AutoSize = true;
stackTop.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.Auto;
stackTop.ElementSpacing = 0;
stackTop.Orientation = Orientation.Horizontal;
stackTop.TextAlignment = ContentAlignment.MiddleLeft;
stackTop.Alignment = ContentAlignment.MiddleLeft;
stackTop.AutoToolTip = true;
stackTop.ShouldHandleMouseInput = true;
stackTop.DoubleClick += layout_DoubleClick;
unitIconElement = new LightVisualElement();
unitIconElement.ShouldHandleMouseInput = true;
unitIconElement.StretchHorizontally = false;
unitIconElement.StretchVertically = true;
unitIconElement.ImageAlignment = ContentAlignment.MiddleCenter;
unitIconElement.ImageLayout = System.Windows.Forms.ImageLayout.Zoom;
unitIconElement.Alignment = ContentAlignment.MiddleLeft;
unitIconElement.TextAlignment = ContentAlignment.MiddleLeft;
unitIconElement.Margin = new System.Windows.Forms.Padding(2);
Font fontNumber = new Font(
unitIconElement.Font.FontFamily,
9,
FontStyle.Regular,
GraphicsUnit.Pixel);
unitIconElement.Font = fontNumber;
unitIconElement.ForeColor = Color.FromArgb(161, 161, 161);
unitIconElement.MaxSize = new Size(27, 0);
unitIconElement.MinSize = new Size(27, 0);
unitIconElement.Click += layout_DoubleClick;
unitNameElement = new LightVisualElement();
unitNameElement.StretchHorizontally = true;
unitNameElement.StretchVertically = true;
unitNameElement.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
unitNameElement.AutoSize = true;
unitNameElement.TextWrap = true;
unitNameElement.MaxSize = new Size(167, 120);
//unitNameElement.Size = unitNameElement.MaxSize;
unitNameElement.TextAlignment = ContentAlignment.TopLeft;
unitNameElement.Padding = new System.Windows.Forms.Padding(0, 3, 3, 0);
unitNameElement.Margin = new Padding(0, 0, 20, 0);
unitNameElement.ForeColor = Color.FromArgb(99, 99, 99);
unitNameElement.ShouldHandleMouseInput = true;
unitNameElement.DoubleClick += layout_DoubleClick;
Font fontUnitName = new Font(
unitNameElement.Font.FontFamily,
13,
FontStyle.Bold,
GraphicsUnit.Pixel);
unitNameElement.Font = fontUnitName;
unitNameElement.AutoToolTip = true;
alertsIconElement = new LightVisualElement();
alertsIconElement.ShouldHandleMouseInput = true;
alertsIconElement.StretchHorizontally = false;
alertsIconElement.StretchVertically = true;
alertsIconElement.AutoSize = true;
//alertsIconElement.Alignment = ContentAlignment.MiddleLeft;
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_alert"))
MainForm2.imagesDictionary.Add("l_alert", global::Dispatcher.Properties.Resources.l_alert);
// set image for the list grid
alertsIconElement.Image = MainForm2.imagesDictionary["l_alert"];
alertsIconElement.ImageAlignment = ContentAlignment.MiddleCenter;
alertsIconElement.ImageLayout = System.Windows.Forms.ImageLayout.Zoom;
alertsIconElement.TextAlignment = ContentAlignment.MiddleLeft;
alertsIconElement.Margin = new System.Windows.Forms.Padding(0);
alertsIconElement.MaxSize = new Size(22, 0);
alertsIconElement.MinSize = new Size(22, 0);
alertsIconElement.Click += delegate(object sender, EventArgs args)
{
// get row
GridViewDataRowInfo row = this.RowInfo as GridViewDataRowInfo;
if (row != null)
{
// get row data
DataforVehList gridData = row.DataBoundItem as DataforVehList;
// check if data exists
if (gridData != null)
{
// trigger event for when click is done
if (_onLiveCell_Click != null)
_onLiveCell_Click(textMessageIconElement, new LiveCellClickEventArgs()
{
eventType = EventType.ALERT,
gridData = gridData
});
}
}
};
stolenIconElement = new LightVisualElement();
stolenIconElement.ShouldHandleMouseInput = true;
stolenIconElement.StretchHorizontally = false;
stolenIconElement.StretchVertically = true;
stolenIconElement.AutoSize = true;
//stolenIconElement.Alignment = ContentAlignment.MiddleLeft;
//stolenIconElement.Padding = new Padding(0, 0, 35, 0);
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_stolen"))
MainForm2.imagesDictionary.Add("l_stolen", global::Dispatcher.Properties.Resources.l_stolen);
// set image for the list grid
stolenIconElement.Image = MainForm2.imagesDictionary["l_stolen"];
stolenIconElement.ImageAlignment = ContentAlignment.MiddleCenter;
stolenIconElement.ImageLayout = System.Windows.Forms.ImageLayout.Zoom;
stolenIconElement.TextAlignment = ContentAlignment.MiddleLeft;
stolenIconElement.Margin = new System.Windows.Forms.Padding(0);
stolenIconElement.ToolTipText = MainForm2.returnLNGString("stolen");
stolenIconElement.MaxSize = new Size(22, 0);
stolenIconElement.MinSize = new Size(22, 0);
statusElement = new LightVisualElement();
statusElement.StretchHorizontally = false;
statusElement.AutoSize = true;
statusElement.AutoToolTip = true;
statusElement.Alignment = ContentAlignment.TopRight;
statusElement.TextAlignment = ContentAlignment.MiddleRight;
statusElement.Padding = new System.Windows.Forms.Padding(0, 0, 0, 0);
statusElement.Margin = new System.Windows.Forms.Padding(0, 0, 3, 0);
statusElement.MaxSize = new Size(20, 0);
statusElement.MinSize = new Size(20, 0);
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_d"))
MainForm2.imagesDictionary.Add("l_bullet_d", global::Dispatcher.Properties.Resources.l_bullet_d);
// set image for the list grid
statusElement.Image = MainForm2.imagesDictionary["l_bullet_d"];
statusElement.ImageAlignment = ContentAlignment.MiddleRight;
statusElement.ImageLayout = System.Windows.Forms.ImageLayout.Zoom;
statusElement.DrawText = false;
// add crt number and address element to the top stack
//stackTop.Children.Add(isDisplayedElement);
//stackTop.Children.Add(alertsIconElement);
//
stackTop.Children.Add(unitIconElement);
stackTop.Children.Add(unitNameElement);
stackTop.Children.Add(stolenIconElement);
stackTop.Children.Add(statusElement);
// create the middle stack
stackBottom = new StackLayoutElement();
stackBottom.StretchHorizontally = true;
stackBottom.StretchVertically = false;
stackBottom.AutoSize = true;
stackBottom.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.Auto;
stackBottom.ElementSpacing = 0;
stackBottom.Orientation = Orientation.Horizontal;
stackBottom.TextAlignment = ContentAlignment.MiddleLeft;
stackBottom.Alignment = ContentAlignment.MiddleLeft;
stackBottom.AutoToolTip = true;
stackBottom.ShouldHandleMouseInput = true;
stackBottom.DoubleClick += layout_DoubleClick;
centerMapIconElement = new LightVisualElement();
centerMapIconElement.ShouldHandleMouseInput = true;
centerMapIconElement.StretchHorizontally = false;
centerMapIconElement.StretchVertically = true;
centerMapIconElement.ImageAlignment = ContentAlignment.MiddleCenter;
centerMapIconElement.ImageLayout = System.Windows.Forms.ImageLayout.Zoom;
centerMapIconElement.Alignment = ContentAlignment.MiddleLeft;
centerMapIconElement.AutoToolTip = true;
centerMapIconElement.ToolTipText = MainForm2.returnLNGString("centerMap");
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_center"))
MainForm2.imagesDictionary.Add("l_center", global::Dispatcher.Properties.Resources.l_center);
// set image for the list grid
centerMapIconElement.Image = MainForm2.imagesDictionary["l_center"];
centerMapIconElement.TextAlignment = ContentAlignment.MiddleLeft;
centerMapIconElement.Margin = new System.Windows.Forms.Padding(2);
centerMapIconElement.MaxSize = new Size(18, 0);
centerMapIconElement.MinSize = new Size(18, 0);
centerMapIconElement.DoubleClick += centerMapIconElement_DoubleClick;
centerMapIconElement.Click += centerMapIconElement_DoubleClick;
textMessageIconElement = new LightVisualElement();
textMessageIconElement.ShouldHandleMouseInput = true;
textMessageIconElement.StretchHorizontally = false;
textMessageIconElement.StretchVertically = true;
textMessageIconElement.ImageAlignment = ContentAlignment.MiddleCenter;
textMessageIconElement.ImageLayout = System.Windows.Forms.ImageLayout.Zoom;
textMessageIconElement.Alignment = ContentAlignment.MiddleLeft;
textMessageIconElement.AutoToolTip = true;
textMessageIconElement.ToolTipText = MainForm2.returnLNGString("quickSMS");
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_text"))
MainForm2.imagesDictionary.Add("l_text", global::Dispatcher.Properties.Resources.l_text);
// set image for the list grid
textMessageIconElement.Image = MainForm2.imagesDictionary["l_text"];
textMessageIconElement.TextAlignment = ContentAlignment.MiddleLeft;
textMessageIconElement.Margin = new System.Windows.Forms.Padding(2);
textMessageIconElement.MaxSize = new Size(18, 0);
textMessageIconElement.MinSize = new Size(18, 0);
textMessageIconElement.DoubleClick += textMessageIconElement_DoubleClick;
textMessageIconElement.Click += textMessageIconElement_DoubleClick;
ticketingIconElement = new LightVisualElement();
ticketingIconElement.ShouldHandleMouseInput = true;
ticketingIconElement.StretchHorizontally = false;
ticketingIconElement.StretchVertically = true;
ticketingIconElement.ImageAlignment = ContentAlignment.MiddleCenter;
ticketingIconElement.ImageLayout = System.Windows.Forms.ImageLayout.Zoom;
ticketingIconElement.Alignment = ContentAlignment.MiddleLeft;
ticketingIconElement.AutoToolTip = true;
ticketingIconElement.ToolTipText = MainForm2.returnLNGString("quickTicketing");
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_ticketing"))
MainForm2.imagesDictionary.Add("l_ticketing", global::Dispatcher.Properties.Resources.l_ticketing);
// set image for the list grid
ticketingIconElement.Image = MainForm2.imagesDictionary["l_ticketing"];
ticketingIconElement.TextAlignment = ContentAlignment.MiddleLeft;
ticketingIconElement.Margin = new System.Windows.Forms.Padding(2);
ticketingIconElement.MaxSize = new Size(18, 0);
ticketingIconElement.MinSize = new Size(18, 0);
ticketingIconElement.Click += delegate(object sender, EventArgs args)
{
// get row
GridViewDataRowInfo row = this.RowInfo as GridViewDataRowInfo;
if (row != null)
{
// get row data
DataforVehList gridData = row.DataBoundItem as DataforVehList;
// check if data exists
if (gridData != null)
{
// trigger event for when click is done
if (_onLiveCell_Click != null)
_onLiveCell_Click(ticketingIconElement, new LiveCellClickEventArgs()
{
eventType = EventType.TICKETING,
gridData = gridData
});
}
}
};
voiceIconElement = new LightVisualElement();
voiceIconElement.ShouldHandleMouseInput = true;
voiceIconElement.StretchHorizontally = false;
voiceIconElement.StretchVertically = true;
voiceIconElement.ImageAlignment = ContentAlignment.MiddleCenter;
voiceIconElement.ImageLayout = System.Windows.Forms.ImageLayout.Zoom;
voiceIconElement.Alignment = ContentAlignment.MiddleLeft;
voiceIconElement.AutoToolTip = true;
voiceIconElement.ToolTipText = MainForm2.returnLNGString("quickPTT");
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("t_voice_b"))
MainForm2.imagesDictionary.Add("t_voice_b", global::Dispatcher.Properties.Resources.t_voice_b);
// set image for the list grid
voiceIconElement.Image = MainForm2.imagesDictionary["t_voice_b"];
voiceIconElement.TextAlignment = ContentAlignment.MiddleLeft;
voiceIconElement.Margin = new System.Windows.Forms.Padding(2);
voiceIconElement.MaxSize = new Size(18, 0);
voiceIconElement.MinSize = new Size(18, 0);
voiceIconElement.DoubleClick += voiceIconElement_DoubleClick;
voiceIconElement.Click += voiceIconElement_DoubleClick;
timeElement = new LightVisualElement();
Font font = new Font(
timeElement.Font.FontFamily,
10,
FontStyle.Regular,
GraphicsUnit.Pixel);
timeElement.Font = font;
timeElement.ForeColor = Color.FromArgb(0, 0, 0);
timeElement.StretchHorizontally = true;
timeElement.AutoSize = true;
timeElement.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
timeElement.Alignment = ContentAlignment.MiddleLeft;
timeElement.AutoToolTip = true;
timeElement.ToolTipText = "WELCOME";
timeElement.TextAlignment = ContentAlignment.MiddleLeft;
timeElement.MinSize = new Size(140, 12);
speedElement = new LightVisualElement();
speedElement.StretchHorizontally = true;
speedElement.AutoSize = true;
speedElement.Alignment = ContentAlignment.MiddleRight;
speedElement.TextAlignment = ContentAlignment.MiddleRight;
speedElement.MaxSize = new Size(110, 12);
speedElement.Padding = new System.Windows.Forms.Padding(0, 0, 3, 0);
Font fontNumber3 = new Font(
speedElement.Font.FontFamily,
9,
FontStyle.Regular,
GraphicsUnit.Pixel);
speedElement.Font = fontNumber3;
speedElement.ForeColor = Color.FromArgb(161, 161, 161);
// add coordinates and time to bottom stack
//stackBottom.Children.Add(alertsIconElement);
stackBottom.Children.Add(centerMapIconElement);
stackBottom.Children.Add(textMessageIconElement);
stackBottom.Children.Add(voiceIconElement);
stackBottom.Children.Add(ticketingIconElement);
stackBottom.Children.Add(timeElement);
stackBottom.Children.Add(speedElement);
// add top, middle and bottom stacks to the right stack
stackRight.Children.Add(stackTop);
stackRight.Children.Add(stackBottom);
stackRight.DoubleClick += layout_DoubleClick;
// add stack to the dock
dockLayout.Children.Add(stackRight);
DockLayoutPanel.SetDock(this.stackRight, Telerik.WinControls.Layouts.Dock.Right);
this.Children.Add(dockLayout);
}
/// <summary>
/// Fire the event that a cell needs to be displayed on the map
/// </summary>
void layout_DoubleClick(object sender, EventArgs e)
{
// get row
GridViewDataRowInfo row = this.RowInfo as GridViewDataRowInfo;
if (row != null)
{
// get row data
DataforVehList gridData = row.DataBoundItem as DataforVehList;
// check if data exists
if (gridData != null)
{
// change the state of displayed/not Displayed on the map
gridData.OnMap = !gridData.OnMap;
// decide which icon should be used when displaying the unit icon
SetUnitIconAndText(gridData);
// trigger event for when click is done
if (_onLiveCell_Click != null)
_onLiveCell_Click(textMessageIconElement, new LiveCellClickEventArgs()
{
eventType = EventType.DISPLAY,
gridData = gridData
});
}
}
}
void voiceIconElement_DoubleClick(object sender, EventArgs e)
{
// get row
GridViewDataRowInfo row = this.RowInfo as GridViewDataRowInfo;
if (row != null)
{
// get row data
DataforVehList gridData = row.DataBoundItem as DataforVehList;
// check if data exists
if (gridData != null)
{
// trigger event for when click is done
if (_onLiveCell_Click != null)
_onLiveCell_Click(ticketingIconElement, new LiveCellClickEventArgs()
{
eventType = EventType.VOICE,
gridData = gridData
});
}
}
}
void textMessageIconElement_DoubleClick(object sender, EventArgs e)
{
// get row
GridViewDataRowInfo row = this.RowInfo as GridViewDataRowInfo;
if (row != null)
{
// get row data
DataforVehList gridData = row.DataBoundItem as DataforVehList;
// check if data exists
if (gridData != null)
{
// trigger event for when click is done
if (_onLiveCell_Click != null)
_onLiveCell_Click(textMessageIconElement, new LiveCellClickEventArgs()
{
eventType = EventType.TEXT,
gridData = gridData
});
}
}
}
void centerMapIconElement_DoubleClick(object sender, EventArgs e)
{
// get row
GridViewDataRowInfo row = this.RowInfo as GridViewDataRowInfo;
if (row != null)
{
// get row data
DataforVehList gridData = row.DataBoundItem as DataforVehList;
// check if data exists
if (gridData != null)
{
// trigger event for when click is done
if (_onLiveCell_Click != null)
_onLiveCell_Click(textMessageIconElement, new LiveCellClickEventArgs()
{
eventType = EventType.CENTER,
gridData = gridData
});
}
}
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridDataCellElement);
}
}
public override bool IsCompatible(GridViewColumn data, object context)
{
return data is HistoryGridColumn && context is GridDataRowElement;
}
private bool createdEventListener = false;
public override void SetContent()
{
GridViewDataRowInfo row = this.RowInfo as GridViewDataRowInfo;
if (row != null)
{
DataforVehList gridData = row.DataBoundItem as DataforVehList;
if (!createdEventListener)
{
gridData.PropertyChanged += gridData_PropertyChanged;
createdEventListener = true;
}
// update the UI elements
UpdateUIElements(gridData);
if(!MainForm2.VoiceTabStarted)
voiceIconElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
}
this.Text = string.Empty;
}
/// <summary>
/// Listener and event handler for when a property changes value in
/// the gridData object. This will cause the grid element to redraw
/// with new values
/// </summary>
void gridData_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "nrOfUpdates":
{
// get row
GridViewDataRowInfo row = this.RowInfo as GridViewDataRowInfo;
if (row != null)
{
// get row data
DataforVehList gridData = row.DataBoundItem as DataforVehList;
// update the UI elements
UpdateUIElements(gridData);
}
break;
}
}
}
/// <summary>
/// Update all UI elements with the ones received in gridData object
/// </summary>
/// <param name="item">Object containing all infos for the UI elements</param>
private void UpdateUIElements(DataforVehList item)
{
if (item != null)
{
/*
if (item.UnitStatus == Status_for_tab.DISABLE)
{
this.DrawFill = true;
this.NumberOfColors = 1;
this.BackColor = Color.Silver;
}
// change background for the disabled units
else if (item.UnitStatus == Status_for_tab.EMERG)
{
this.DrawFill = true;
this.NumberOfColors = 1;
this.BackColor = Color.FromArgb(156, 34, 0);
}*/
SetUnitIconAndText(item);
// set speed value
speedElement.Text = item.Speed + (item.IsMPH ? " mph" : " kph");
// set time value
timeElement.Text = GetDateTimeAgo(item.PositionTime);
if (timeElement.Text.Equals(MainForm2.returnLNGString("scheduled")))
timeElement.Text = MainForm2.returnLNGString("inTheFuture");
timeElement.ToolTipText = (item.PositionTime.Year > 2000 ?
item.PositionTime.ToString() : MainForm2.returnLNGString("neverReported"));
// set the status icon
statusElement.Image = GetStatusImage(item.PositionTime, item.UnitStatus, item.Speed);
statusElement.ToolTipText = "Status: " + item.UnitStatus.ToString().Replace('_', ' ');
if (item.HasAlerts)
alertsIconElement.Visibility = Telerik.WinControls.ElementVisibility.Visible;
else
alertsIconElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
if (item.Stolen)
stolenIconElement.Visibility = Telerik.WinControls.ElementVisibility.Visible;
else
stolenIconElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
if (!item.HasVoice && MainForm2.VoiceTabStarted)
{
voiceIconElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
}
if (!item.HasText)
{
textMessageIconElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
}
if (this.IsCurrentRow)
{
timeElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
centerMapIconElement.Visibility = Telerik.WinControls.ElementVisibility.Visible;
if (item.HasText)
{
textMessageIconElement.Visibility = Telerik.WinControls.ElementVisibility.Visible;
}
ticketingIconElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
if (item.HasVoice && MainForm2.VoiceTabStarted)
{
voiceIconElement.Visibility = Telerik.WinControls.ElementVisibility.Visible;
}
this.DrawFill = true;
this.BackColor = MainForm2.GridSelectedRow;
//(gridData.UnitStatus == Status_for_tab.EMERG ? Color.Red : MainForm2.GridSelectedRow);
//MainForm2.GridSelectedRow;
}
else
{
timeElement.Visibility = Telerik.WinControls.ElementVisibility.Visible;
centerMapIconElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
textMessageIconElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
ticketingIconElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
voiceIconElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
// draw background if emergency or disabled
if (item.UnitStatus != Status_for_tab.DISABLE
|| item.UnitStatus != Status_for_tab.EMERG)
this.DrawFill = false;
}
// set the tooltip text which will be displayed
string tooltipText = "";
if (Math.Abs(item.Latitude) <= 0.1 && Math.Abs(item.Longitude) <= 0.1)
tooltipText = MainForm2.returnLNGString("neverReported");
else
{
tooltipText = (item.Address.Trim().Length > 0 ||
(!item.Address.Equals("N/A") && item.Address.Trim().Length > 0) ? item.Address : MainForm2.returnLNGString("unknownAddr"))
+ Environment.NewLine
+ "[" + Math.Round(item.Latitude, 5).ToString() + "," + Math.Round(item.Longitude, 5).ToString() + "]";
}
this.stackBottom.ToolTipText = stackRight.ToolTipText = stackTop.ToolTipText = tooltipText;
}
}
/// <summary>
/// Set the unit icon and the text color based on the status of the unit
/// and if it is displayed on the map or not
/// </summary>
/// <param name="gridData">The grid data for the unit which needs to be set</param>
private void SetUnitIconAndText(DataforVehList gridData)
{
if (gridData.UnitStatus == Status_for_tab.EMERG)
{
// decide which icon should be used when displaying the unit icon
if (!gridData.OnMap)
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey(gridData.Pict.Tag.ToString() + "_d"))
MainForm2.imagesDictionary.Add(gridData.Pict.Tag.ToString() + "_d", Utils.MakeGrayscale3((Bitmap)gridData.Pict, 0.5f));
// set the icon for the unit
unitIconElement.Image = MainForm2.imagesDictionary[gridData.Pict.Tag.ToString() + "_d"];
}
else
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey(gridData.Pict.Tag.ToString() + "_e"))
MainForm2.imagesDictionary.Add(gridData.Pict.Tag.ToString() + "_e", Utils.ChangeColor((Bitmap)gridData.Pict, Color.DarkRed));
// set the icon for the unit
unitIconElement.Image = MainForm2.imagesDictionary[gridData.Pict.Tag.ToString() + "_e"];
}
}
else
{
// decide which icon should be used when displaying the unit icon
if (!gridData.OnMap)
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey(gridData.Pict.Tag.ToString() + "_d"))
MainForm2.imagesDictionary.Add(gridData.Pict.Tag.ToString() + "_d", Utils.MakeGrayscale3((Bitmap)gridData.Pict, 0.5f));
// set the icon for the unit
unitIconElement.Image = MainForm2.imagesDictionary[gridData.Pict.Tag.ToString() + "_d"];
}
else
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey(gridData.Pict.Tag.ToString()))
MainForm2.imagesDictionary.Add(gridData.Pict.Tag.ToString(), gridData.Pict);
// set the icon for the unit
unitIconElement.Image = MainForm2.imagesDictionary[gridData.Pict.Tag.ToString()];
}
}
// set the vehicle name
unitNameElement.Text = gridData.UnitName + " [" + gridData.RadioId + "]";
unitNameElement.ToolTipText = "Radio id: " + gridData.RadioId;
if (gridData.UnitStatus == Status_for_tab.EMERG)
unitNameElement.ForeColor = Color.FromArgb(144, 0, 39);
else if (gridData.UnitStatus == Status_for_tab.DISABLE)
unitNameElement.ForeColor = Color.FromArgb(144, 144, 144);
else
unitNameElement.ForeColor = Color.Black;
}
/// <summary>
/// Get a text representation for the date time representing
/// the difference in minutes/hours/days from now
/// </summary>
/// <param name="utcTime">DateTime value which needs to be converted</param>
/// <returns>String 'Ago' representation fot he date</returns>
public static string GetDateTimeAgo(DateTime time)
{
// TODO
// should add a localized procedure here
// TODO
return Utils.GetDateTimeAgo(time);
}
/// <summary>
/// Get the bullet image for the current state of the unit
/// based on its position time, speed and status
/// </summary>
/// <param name="positionTime">Time of the position</param>
/// <param name="status">Unit status as decided bt the system</param>
/// <param name="speed">Speed of the unit</param>
/// <returns>Image representing the state of the unit</returns>
public Image GetStatusImage(DateTime positionTime, Status_for_tab status, Int16 speed)
{
if (status == Status_for_tab.ON)
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_aon"))
MainForm2.imagesDictionary.Add("l_bullet_aon", global::Dispatcher.Properties.Resources.l_bullet_aon);
// return the desired image
return MainForm2.imagesDictionary["l_bullet_aon"];
}
else if (status == Status_for_tab.OFF)
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_aoff"))
MainForm2.imagesDictionary.Add("l_bullet_aoff", global::Dispatcher.Properties.Resources.l_bullet_aoff);
// return the desired image
return MainForm2.imagesDictionary["l_bullet_aoff"];
}
else if (status == Status_for_tab.EMERG)
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_r"))
MainForm2.imagesDictionary.Add("l_bullet_r", global::Dispatcher.Properties.Resources.l_bullet_r);
// return the desired image
return MainForm2.imagesDictionary["l_bullet_r"];
}
else if (status == Status_for_tab.DISABLE)
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_d"))
MainForm2.imagesDictionary.Add("l_bullet_d", global::Dispatcher.Properties.Resources.l_bullet_d);
// return the desired image
return MainForm2.imagesDictionary["l_bullet_d"];
}
else if (status == Status_for_tab.ENABLE)
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_mo"))
MainForm2.imagesDictionary.Add("l_bullet_mo", global::Dispatcher.Properties.Resources.l_bullet_mo);
// return the desired image
return MainForm2.imagesDictionary["l_bullet_mo"];
}
else if (status == Status_for_tab.MADEOFF)
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_mo"))
MainForm2.imagesDictionary.Add("l_bullet_mo", global::Dispatcher.Properties.Resources.l_bullet_mo);
// return the desired image
return MainForm2.imagesDictionary["l_bullet_mo"];
}
else if (status == Status_for_tab.NOGPSFIX)
{
if (speed > 0)
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bulet_ggnf"))
MainForm2.imagesDictionary.Add("l_bulet_ggnf", global::Dispatcher.Properties.Resources.l_bulet_ggnf);
// return the desired image
return MainForm2.imagesDictionary["l_bulet_ggnf"];
}
else
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_bgnf"))
MainForm2.imagesDictionary.Add("l_bullet_bgnf", global::Dispatcher.Properties.Resources.l_bullet_bgnf);
// return the desired image
return MainForm2.imagesDictionary["l_bullet_bgnf"];
}
}
else if (status == Status_for_tab.GPS_POOR)
{
if (speed > 0)
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_ggp"))
MainForm2.imagesDictionary.Add("l_bullet_ggp", global::Dispatcher.Properties.Resources.l_bullet_ggp);
// return the desired image
return MainForm2.imagesDictionary["l_bullet_ggp"];
}
else
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_bgp"))
MainForm2.imagesDictionary.Add("l_bullet_bgp", global::Dispatcher.Properties.Resources.l_bullet_bgp);
// return the desired image
return MainForm2.imagesDictionary["l_bullet_bgp"];
}
}
else if (status == Status_for_tab.GPS_OFF)
{
if (speed > 0)
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_ggo"))
MainForm2.imagesDictionary.Add("l_bullet_ggo", global::Dispatcher.Properties.Resources.l_bullet_ggo);
// return the desired image
return MainForm2.imagesDictionary["l_bullet_ggo"];
}
else
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_bgo"))
MainForm2.imagesDictionary.Add("l_bullet_bgo", global::Dispatcher.Properties.Resources.l_bullet_bgo);
// return the desired image
return MainForm2.imagesDictionary["l_bullet_bgo"];
}
}
else if (status == Status_for_tab.GPS_ON)
{
if (speed == 0)
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_b"))
MainForm2.imagesDictionary.Add("l_bullet_b", global::Dispatcher.Properties.Resources.l_bullet_b);
// return the desired image
return MainForm2.imagesDictionary["l_bullet_b"];
}
else
{
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_g"))
MainForm2.imagesDictionary.Add("l_bullet_g", global::Dispatcher.Properties.Resources.l_bullet_g);
// return the desired image
return MainForm2.imagesDictionary["l_bullet_g"];
}
}
// return the disabled status
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("l_bullet_d"))
MainForm2.imagesDictionary.Add("l_bullet_d", global::Dispatcher.Properties.Resources.l_bullet_d);
// return the desired image
return MainForm2.imagesDictionary["l_bullet_d"];
}
#region LIVE CELL CLICK
public class LiveCellClickEventArgs : EventArgs
{
public DataforVehList gridData { get; set; }
public EventType eventType { get; set; }
}
private object _lockLiveCellClick = new object();
private event EventHandler<LiveCellClickEventArgs> _onLiveCell_Click;
public event EventHandler<LiveCellClickEventArgs> OnLiveCell_Click
{
add { lock (_lockLiveCellClick) { _onLiveCell_Click += value; } }
remove { lock (_lockLiveCellClick) { _onLiveCell_Click -= value; } }
}
#endregion
}
}