457 lines
19 KiB
C#
457 lines
19 KiB
C#
|
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 SafeMobileLib;
|
|||
|
using Telerik.WinControls.Layouts;
|
|||
|
using Telerik.WinControls.UI;
|
|||
|
|
|||
|
namespace Safedispatch_4_0.Radio
|
|||
|
{
|
|||
|
public class SubscriberVisualListItem : SimpleListViewVisualItem
|
|||
|
{
|
|||
|
public LightVisualElement topRightElement;
|
|||
|
|
|||
|
private DockLayoutPanel dockLayout;
|
|||
|
private StackLayoutElement subscriberStack;
|
|||
|
private StackLayoutElement fastCommandsStack;
|
|||
|
private StackLayoutElement bottomStack;
|
|||
|
private LightVisualElement subscriberIcon;
|
|||
|
private TextBlockElement subscriberName;
|
|||
|
private LightVisualElement liveIcon;
|
|||
|
private LightVisualElement favIcon;
|
|||
|
private LightVisualElement remoteIcon;
|
|||
|
private LightVisualElement textIcon;
|
|||
|
private RadTextBoxControlElement tbMessage;
|
|||
|
|
|||
|
private Subscriber dataSubscriber = null;
|
|||
|
|
|||
|
protected override void CreateChildElements()
|
|||
|
{
|
|||
|
base.CreateChildElements();
|
|||
|
|
|||
|
this.dockLayout = new DockLayoutPanel();
|
|||
|
this.dockLayout.BorderThickness = new Padding(4);
|
|||
|
this.dockLayout.MaxSize = new Size(180, 130);
|
|||
|
this.dockLayout.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
|
|||
|
this.dockLayout.StretchHorizontally = false;
|
|||
|
this.dockLayout.ShouldHandleMouseInput = false;
|
|||
|
this.dockLayout.Padding = new Padding(5, 0, 0, 0);
|
|||
|
|
|||
|
|
|||
|
this.subscriberStack = new StackLayoutElement();
|
|||
|
this.subscriberStack.Size = new Size(180, 60);
|
|||
|
this.subscriberStack.AutoSize = true;
|
|||
|
this.subscriberStack.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.WrapAroundChildren;
|
|||
|
this.subscriberStack.Alignment = ContentAlignment.MiddleCenter;
|
|||
|
this.subscriberStack.DrawFill = false;
|
|||
|
this.subscriberStack.BackColor = Color.Red;
|
|||
|
this.subscriberStack.NumberOfColors = 1;
|
|||
|
this.subscriberStack.Padding = new Padding(5, 5, 0, 5);
|
|||
|
this.subscriberStack.Margin = new Padding(0, 10, 0, 0);
|
|||
|
this.subscriberStack.ShouldHandleMouseInput = false;
|
|||
|
this.subscriberStack.Orientation = Orientation.Vertical;
|
|||
|
this.dockLayout.Children.Add(this.subscriberStack);
|
|||
|
DockLayoutPanel.SetDock(this.subscriberStack, Telerik.WinControls.Layouts.Dock.Top);
|
|||
|
|
|||
|
|
|||
|
this.subscriberIcon = new LightVisualElement();
|
|||
|
this.subscriberIcon.AutoSize = true;
|
|||
|
this.subscriberIcon.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.WrapAroundChildren;
|
|||
|
this.subscriberIcon.ShouldHandleMouseInput = false;
|
|||
|
this.subscriberIcon.StretchHorizontally = false;
|
|||
|
this.subscriberIcon.Padding = new Padding(0, 0, 0, 0);
|
|||
|
this.subscriberIcon.Margin = new Padding(0, 0, 0, 0);
|
|||
|
this.subscriberIcon.Alignment = ContentAlignment.TopCenter;
|
|||
|
this.subscriberIcon.Size = new Size(64, 64);
|
|||
|
this.subscriberIcon.MaxSize = new Size(64, 64);
|
|||
|
this.subscriberIcon.BackColor = Color.Cyan;
|
|||
|
this.subscriberIcon.DrawFill = false;
|
|||
|
this.subscriberIcon.NumberOfColors = 1;
|
|||
|
this.subscriberStack.Children.Add(this.subscriberIcon);
|
|||
|
|
|||
|
|
|||
|
this.subscriberName = new TextBlockElement();
|
|||
|
this.subscriberName.StretchHorizontally = false;
|
|||
|
this.subscriberName.StretchVertically = true;
|
|||
|
this.subscriberName.AutoSize = true;
|
|||
|
this.subscriberName.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.WrapAroundChildren;
|
|||
|
//this.subscriberName.TextWrap = true;
|
|||
|
//this.subscriberName.DrawBackgroundImage = true;
|
|||
|
this.subscriberName.BackColor = Color.Black;
|
|||
|
this.subscriberName.DrawFill = false;
|
|||
|
this.subscriberName.MaxSize = new Size(180, 20);
|
|||
|
this.subscriberName.ShouldHandleMouseInput = false;
|
|||
|
this.subscriberName.StretchHorizontally = false;
|
|||
|
this.subscriberName.Padding = new Padding(0, 0, 0, 0);
|
|||
|
this.subscriberName.Margin = new Padding(0, 17, 0, 0);
|
|||
|
this.subscriberName.Font = new System.Drawing.Font("Segoe UI", 9, FontStyle.Bold, GraphicsUnit.Point);
|
|||
|
this.subscriberName.Alignment = ContentAlignment.BottomCenter;
|
|||
|
this.subscriberStack.Children.Add(this.subscriberName);
|
|||
|
|
|||
|
|
|||
|
this.bottomStack = new StackLayoutElement();
|
|||
|
this.bottomStack.BackColor = Color.Green;
|
|||
|
this.bottomStack.DrawFill = false;
|
|||
|
this.bottomStack.Padding = new Padding(1);
|
|||
|
this.bottomStack.ShouldHandleMouseInput = false;
|
|||
|
this.bottomStack.Orientation = Orientation.Vertical;
|
|||
|
this.dockLayout.Children.Add(this.bottomStack);
|
|||
|
DockLayoutPanel.SetDock(this.bottomStack, Telerik.WinControls.Layouts.Dock.Bottom);
|
|||
|
|
|||
|
this.fastCommandsStack = new StackLayoutElement();
|
|||
|
this.fastCommandsStack.BackColor = Color.White;
|
|||
|
this.fastCommandsStack.Padding = new Padding(1);
|
|||
|
this.fastCommandsStack.ShouldHandleMouseInput = false;
|
|||
|
this.fastCommandsStack.Orientation = Orientation.Horizontal;
|
|||
|
this.bottomStack.Children.Add(this.fastCommandsStack);
|
|||
|
|
|||
|
|
|||
|
this.textIcon = new LightVisualElement();
|
|||
|
this.textIcon.Image = MainForm2.GetImage("fc_sms");
|
|||
|
this.textIcon.ShouldHandleMouseInput = true;
|
|||
|
this.textIcon.StretchHorizontally = false;
|
|||
|
this.textIcon.Padding = new Padding(0, 0, 0, 0);
|
|||
|
this.textIcon.Click += textIcon_Click;
|
|||
|
this.fastCommandsStack.Children.Add(this.textIcon);
|
|||
|
|
|||
|
|
|||
|
this.liveIcon = new LightVisualElement();
|
|||
|
|
|||
|
this.liveIcon.Image = MainForm2.GetImage("fc_live");
|
|||
|
this.liveIcon.ShouldHandleMouseInput = true;
|
|||
|
this.liveIcon.StretchHorizontally = false;
|
|||
|
this.liveIcon.Padding = new Padding(0, 0, 0, 0);
|
|||
|
this.liveIcon.MouseUp += delegate(object sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
//Console.WriteLine("Mouse Click");
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
this.remoteIcon = new LightVisualElement();
|
|||
|
this.remoteIcon.Image = MainForm2.GetImage("fc_remote");
|
|||
|
this.remoteIcon.ShouldHandleMouseInput = true;
|
|||
|
this.remoteIcon.StretchHorizontally = false;
|
|||
|
this.remoteIcon.Padding = new Padding(0, 0, 0, 0);
|
|||
|
|
|||
|
this.remoteIcon.Click += delegate(object sender, EventArgs e)
|
|||
|
{
|
|||
|
// get data
|
|||
|
if (this.Data != null)
|
|||
|
{
|
|||
|
Subscriber item = this.Data.DataBoundItem as Subscriber;
|
|||
|
if (item != null)
|
|||
|
{
|
|||
|
dataSubscriber = item;
|
|||
|
// trigger event for when click is done
|
|||
|
if (_onRemote_Click != null)
|
|||
|
_onRemote_Click(remoteIcon, new ToggleClickEventArgs()
|
|||
|
{
|
|||
|
subscriber = item,
|
|||
|
isActive = true
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
this.fastCommandsStack.Children.Add(this.remoteIcon);
|
|||
|
|
|||
|
|
|||
|
this.favIcon = new LightVisualElement();
|
|||
|
this.favIcon.Image = MainForm2.GetImage("fc_favorite");
|
|||
|
this.favIcon.Tag = "false";
|
|||
|
this.favIcon.ShouldHandleMouseInput = true;
|
|||
|
this.favIcon.StretchHorizontally = false;
|
|||
|
this.favIcon.StretchVertically = false;
|
|||
|
this.favIcon.DrawFill = false;
|
|||
|
//this.favIcon.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.FitToAvailableSize;
|
|||
|
this.favIcon.Alignment = ContentAlignment.TopLeft;
|
|||
|
this.favIcon.Padding = new Padding(0, 0, 0, 0);
|
|||
|
this.favIcon.MouseUp += delegate(object sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
//Console.WriteLine("FAV Click");
|
|||
|
if (this.favIcon.Tag.Equals("false"))
|
|||
|
{
|
|||
|
this.favIcon.Image = MainForm2.GetImage("fc_favorite_yellow");
|
|||
|
this.favIcon.Tag = "true";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.favIcon.Image = MainForm2.GetImage("fc_favorite");
|
|||
|
this.favIcon.Tag = "false";
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// get data
|
|||
|
if (this.Data != null)
|
|||
|
{
|
|||
|
Subscriber item = this.Data.DataBoundItem as Subscriber;
|
|||
|
if (item != null)
|
|||
|
{
|
|||
|
dataSubscriber = item;
|
|||
|
// trigger event for when click is done
|
|||
|
if (_onFavorite_Click != null)
|
|||
|
_onFavorite_Click(favIcon, new ToggleClickEventArgs()
|
|||
|
{
|
|||
|
subscriber = item,
|
|||
|
isActive = this.favIcon.Tag.Equals("true")
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
//this.fastCommandsStack.Children.Add(this.favIcon);
|
|||
|
|
|||
|
this.tbMessage = new RadTextBoxControlElement();
|
|||
|
this.tbMessage.Text = "";
|
|||
|
this.tbMessage.BackColor = Color.Red;
|
|||
|
this.tbMessage.AutoSize = false;
|
|||
|
this.tbMessage.Size = new Size(145, 24);
|
|||
|
this.tbMessage.MaxLength = SmsUtils.GetMaxNumberOfCharacters(MainForm2.radioType);
|
|||
|
this.tbMessage.Padding = new Padding(0, 3, 0, 0);
|
|||
|
this.tbMessage.KeyUp += delegate(object sender, KeyEventArgs e)
|
|||
|
{
|
|||
|
if (e.KeyCode == Keys.Enter)
|
|||
|
{
|
|||
|
//Utils.WriteLine("1");
|
|||
|
// get data
|
|||
|
if (this.Data != null)
|
|||
|
{
|
|||
|
//Utils.WriteLine("2");
|
|||
|
Subscriber item = this.Data.DataBoundItem as Subscriber;
|
|||
|
|
|||
|
if (item != null)
|
|||
|
{
|
|||
|
//Utils.WriteLine("3");
|
|||
|
dataSubscriber = item;
|
|||
|
// trigger event for when click is done
|
|||
|
if (_onTextSend_Req != null)
|
|||
|
{
|
|||
|
//Utils.WriteLine("4");
|
|||
|
_onTextSend_Req(textIcon, new TextSendEventArgs()
|
|||
|
{
|
|||
|
subscriber = item,
|
|||
|
text = tbMessage.Text
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
tbMessage.Clear();
|
|||
|
textIcon_Click(tbMessage, null);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
this.tbMessage.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
|
|||
|
this.fastCommandsStack.Children.Add(this.tbMessage);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
this.topRightElement = new LightVisualElement();
|
|||
|
this.topRightElement.StretchHorizontally = false;
|
|||
|
this.topRightElement.StretchVertically = false;
|
|||
|
this.topRightElement.DrawFill = true;
|
|||
|
this.topRightElement.NumberOfColors = 1;
|
|||
|
this.topRightElement.BackColor = Color.FromArgb(171, 171, 171);
|
|||
|
this.topRightElement.ForeColor = Color.White;
|
|||
|
this.topRightElement.Font = new Font("Segoe UI Semibold", 8f);
|
|||
|
this.topRightElement.Alignment = ContentAlignment.TopRight;
|
|||
|
this.topRightElement.Padding = new Padding(2);
|
|||
|
//this.topRightElement.Text = "This is a demo";
|
|||
|
|
|||
|
|
|||
|
|
|||
|
this.Children.Add(favIcon);
|
|||
|
this.Children.Add(topRightElement);
|
|||
|
this.Children.Add(this.dockLayout);
|
|||
|
}
|
|||
|
|
|||
|
void textIcon_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
//Console.WriteLine("Mouse Click");
|
|||
|
if (tbMessage.Visibility == Telerik.WinControls.ElementVisibility.Hidden)
|
|||
|
{
|
|||
|
//favIcon.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
|
|||
|
liveIcon.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
|
|||
|
remoteIcon.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
|
|||
|
if (MainForm2.vehicleHT.Contains(subscriberName.Text))
|
|||
|
((Vehicle)MainForm2.vehicleHT[subscriberName.Text]).CheckPositionInSystem();
|
|||
|
|
|||
|
string GatewayAndRadioID = "0.0";
|
|||
|
/*
|
|||
|
if (MainForm2.vehicleHT.ContainsKey(subscriberName.Text))
|
|||
|
GatewayAndRadioID = ((Vehicle)MainForm2.vehicleHT[subscriberName.Text]).GwandRadioID;
|
|||
|
else
|
|||
|
{
|
|||
|
|
|||
|
if (this.Data != null)
|
|||
|
{
|
|||
|
Subscriber item = this.Data.DataBoundItem as Subscriber;
|
|||
|
|
|||
|
if(item != null)
|
|||
|
GatewayAndRadioID = item.Gw_and_radioID;
|
|||
|
}
|
|||
|
}*/
|
|||
|
|
|||
|
if (this.Data != null)
|
|||
|
{
|
|||
|
Subscriber item = this.Data.DataBoundItem as Subscriber;
|
|||
|
|
|||
|
if (item != null)
|
|||
|
GatewayAndRadioID = item.Gw_and_radioID;
|
|||
|
}
|
|||
|
|
|||
|
int gwType = (int)GatewayType.Unknown;
|
|||
|
if (MainForm2.radioGwHT[GatewayAndRadioID] != null)
|
|||
|
{
|
|||
|
gwType = ((RadioGateway)MainForm2.radioGwHT[GatewayAndRadioID]).Type;
|
|||
|
tbMessage.MaxLength = SmsUtils.GetMaxNumberOfCharacters(gwType);
|
|||
|
}
|
|||
|
tbMessage.Visibility = Telerik.WinControls.ElementVisibility.Visible;
|
|||
|
tbMessage.Clear();
|
|||
|
tbMessage.Focus();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//favIcon.Visibility = Telerik.WinControls.ElementVisibility.Visible;
|
|||
|
liveIcon.Visibility = Telerik.WinControls.ElementVisibility.Visible;
|
|||
|
|
|||
|
if (!dataSubscriber.HasRemoteMonitor && this.fastCommandsStack.Children.Contains(remoteIcon))
|
|||
|
{
|
|||
|
this.remoteIcon.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
|
|||
|
}
|
|||
|
else
|
|||
|
this.remoteIcon.Visibility = Telerik.WinControls.ElementVisibility.Visible;
|
|||
|
|
|||
|
|
|||
|
tbMessage.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
protected override void SynchronizeProperties()
|
|||
|
{
|
|||
|
base.SynchronizeProperties();
|
|||
|
|
|||
|
if (this.Data == null)
|
|||
|
return;
|
|||
|
|
|||
|
|
|||
|
Subscriber subscriber = (Subscriber)this.Data.DataBoundItem;
|
|||
|
|
|||
|
if (subscriber == null)
|
|||
|
return;
|
|||
|
|
|||
|
|
|||
|
UpdateUIElements(subscriber);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private void UpdateUIElements(Subscriber subscriber)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
dataSubscriber = subscriber;
|
|||
|
|
|||
|
this.Text = "";
|
|||
|
/*
|
|||
|
if(subscriber.IsEmergency && subscriber.SubscriberType == SubscriberType.SUBSCRIBER)
|
|||
|
this.subscriberIcon.Image = MainForm2.GetImage(subscriber.IconFilePath + "_e");
|
|||
|
else*/
|
|||
|
this.subscriberIcon.Image = MainForm2.GetImage(subscriber.IconFilePath);
|
|||
|
|
|||
|
this.subscriberName.Text = subscriber.DispatcherName;
|
|||
|
this.favIcon.Image = (subscriber.Favorite ?
|
|||
|
MainForm2.GetImage("fc_favorite_yellow") : MainForm2.GetImage("fc_favorite"));
|
|||
|
this.favIcon.Tag = (subscriber.Favorite ? "true" : "false");
|
|||
|
|
|||
|
/*
|
|||
|
topRightElement.Visibility = subscriber.SubscriberType == SubscriberType.DISPATCHER
|
|||
|
? Telerik.WinControls.ElementVisibility.Hidden : Telerik.WinControls.ElementVisibility.Visible;
|
|||
|
*/
|
|||
|
|
|||
|
if (tbMessage.IsFocused)
|
|||
|
{
|
|||
|
// do not anything if the tbMessage is focused
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
// hide the text message box
|
|||
|
tbMessage.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
|
|||
|
favIcon.Visibility = Telerik.WinControls.ElementVisibility.Visible;
|
|||
|
if (!subscriber.HasRemoteMonitor && this.fastCommandsStack.Children.Contains(remoteIcon))
|
|||
|
{
|
|||
|
this.remoteIcon.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
|
|||
|
}
|
|||
|
else
|
|||
|
this.remoteIcon.Visibility = Telerik.WinControls.ElementVisibility.Visible;
|
|||
|
|
|||
|
if (!subscriber.HasTextMessage && this.fastCommandsStack.Children.Contains(textIcon))
|
|||
|
{
|
|||
|
this.textIcon.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
|
|||
|
}
|
|||
|
else
|
|||
|
this.textIcon.Visibility = Telerik.WinControls.ElementVisibility.Visible;
|
|||
|
}
|
|||
|
}catch(Exception ex)
|
|||
|
{
|
|||
|
Utils.WriteLine("EXCEPION ex " + ex.ToString(), ConsoleColor.Red);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
protected override Type ThemeEffectiveType
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return typeof(SimpleListViewVisualItem);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#region CELL CLICK EVENTS
|
|||
|
public class ToggleClickEventArgs : EventArgs
|
|||
|
{
|
|||
|
public Subscriber subscriber { get; set; }
|
|||
|
public Boolean isActive { get; set; }
|
|||
|
}
|
|||
|
|
|||
|
private object _lockFavoriteClick = new object();
|
|||
|
private event EventHandler<ToggleClickEventArgs> _onFavorite_Click;
|
|||
|
public event EventHandler<ToggleClickEventArgs> OnFavorite_Click
|
|||
|
{
|
|||
|
add { lock (_lockFavoriteClick) { _onFavorite_Click += value; } }
|
|||
|
remove { lock (_lockFavoriteClick) { _onFavorite_Click -= value; } }
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public class TextSendEventArgs : EventArgs
|
|||
|
{
|
|||
|
public Subscriber subscriber { get; set; }
|
|||
|
public String text { get; set; }
|
|||
|
}
|
|||
|
|
|||
|
private object _lockTextClick = new object();
|
|||
|
private event EventHandler<TextSendEventArgs> _onTextSend_Req;
|
|||
|
public event EventHandler<TextSendEventArgs> OnTextSend_Req
|
|||
|
{
|
|||
|
add { lock (_lockTextClick) { _onTextSend_Req += value; } }
|
|||
|
remove { lock (_lockTextClick) { _onTextSend_Req -= value; } }
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
private object _lockRemoteClick = new object();
|
|||
|
private event EventHandler<ToggleClickEventArgs> _onRemote_Click;
|
|||
|
public event EventHandler<ToggleClickEventArgs> OnRemote_Click
|
|||
|
{
|
|||
|
add { lock (_lockRemoteClick) { _onRemote_Click += value; } }
|
|||
|
remove { lock (_lockRemoteClick) { _onRemote_Click -= value; } }
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|