SafeDispatch/Safedispatch_4_0/maptab/TelemTab.cs

1081 lines
49 KiB
C#
Raw Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Microsoft.Win32;
using System.Resources;
using System.IO;
using Telerik.WinControls.UI;
using Telerik.WinControls;
using Telerik.WinControls.UI.Docking;
using SafeMobileLib;
using Dispatcher.maptab;
namespace Safedispatch_4_0
{
public partial class TelemTab : UserControl
{
public enum TelemCommands { SET = 0, CLEAR = 1, TOGGLE = 2, PULSE = 3 };
public bool KillTimerActive = false;
private String milesh, kmh;
public Boolean docLoad = false;
private Boolean PingGoogle = false;
private Int32 loadcnt = 0;
public String updatecomand;
public String getADDRcomand;
public String lasttime;
private String selectName = "";
public static volatile Boolean StreetViewOpened = false;
private void setLanguage()
{
langProgStat = MainForm2.returnLNGString("txProgStatLive");
kmh = MainForm2.returnLNGString("kmh");
milesh = MainForm2.returnLNGString("milesh");
toolWindow2.Text = MainForm2.returnLNGString("tabPage1");
toolWindow3.Text = MainForm2.returnLNGString("tabPage2");
vehiclesList.Columns[2].HeaderText = MainForm2.returnLNGString("htableVehiclesListColumns1");
lasttime = MainForm2.returnLNGString("lbLastTime");
lbStatus1.Text = MainForm2.returnLNGString("SMSStatus");
lbStatus2.Text = MainForm2.returnLNGString("SMSStatus");
lbStatus3.Text = MainForm2.returnLNGString("SMSStatus");
lbStatus4.Text = MainForm2.returnLNGString("SMSStatus");
lbStatus5.Text = MainForm2.returnLNGString("SMSStatus");
btSend1.Text = MainForm2.returnLNGString("send");
btSend2.Text = MainForm2.returnLNGString("send");
btSend3.Text = MainForm2.returnLNGString("send");
btSend4.Text = MainForm2.returnLNGString("send");
btSend5.Text = MainForm2.returnLNGString("send");
documentWindow1.Text = MainForm2.returnLNGString("telemetryStatus");
}
public TelemTab(MainForm2 parentParam)
{
DateTime FirstTime;
parent = parentParam;
InitializeComponent();
// set height for the grid items
this.vehiclesList.TableElement.RowHeight = 45;
this.vehiclesList.GridViewElement.DrawBorder = false;
this.vehiclesList.GridViewElement.GroupPanelElement.DrawBorder = false;
String safemobileDirPath = System.Windows.Forms.Application.StartupPath.Replace('\\', '/').Replace(" ", "%20");
safemobileDirPath = safemobileDirPath.Replace("#", "%23");
mapGoogles = new CefSharpChromiumWebBrowser("file:///" + safemobileDirPath + "/resource/" + MainForm2.MapHtmlName);
mapGoogles.OnWebPageLoaded += delegate()
{
bool isClassicIcons = (Safedispatch_4_0.MainForm2.iconThemeType == IconTheme.CLASSIC ? true : false);
try
{
mapGoogles.ExecuteScript(string.Format("window.GWTcallback('showconsole,{0}');", MainForm2.MapDebugConsole)); //FORKITT
mapGoogles.ExecuteScript("window.GWTcallback('setLegacyIcons," + (isClassicIcons ? "true" : "false") + "');");
mapGoogles.ExecuteScript("window.GWTcallback('centerzoom,"
+ MainForm2.FixDoubleLAT(Safedispatch_4_0.MainForm2.LatStart.ToString()) + ","
+ MainForm2.FixDoubleLAT(Safedispatch_4_0.MainForm2.LngStart.ToString()) + ","
+ Safedispatch_4_0.MainForm2.ZoomStart + "');");
// open bubble for selected row once the map is loaded
this.Invoke(new MethodInvoker(delegate()
{
vehiclesList.CurrentRow = vehiclesList.Rows[0];
vehiclesList.CurrentColumn = vehiclesList.Columns["UnitName"];
// use the selected row
if (vehiclesList.SelectedRows.Count > 0)
vehiclesList_CellDoubleClick(vehiclesList, new GridViewCellEventArgs(vehiclesList.SelectedRows[0], null, null));
else if (vehiclesList.RowCount > 0)
{
// select first row
vehiclesList.Rows[0].IsSelected = true;
vehiclesList_CellDoubleClick(vehiclesList, new GridViewCellEventArgs(vehiclesList.SelectedRows[0], null, null));
}
}));
}
catch (Exception ex)
{
Utils.WriteLine("Error on loadPage telemtry Ex:"+ex.ToString(),ConsoleColor.Red);
}
};
mapGoogles.OnBrowserURLChanged += delegate(String currentURL)
{
};
mapGoogles.OnURLResponseReceived += delegate(String urlResponse)
{
try
{
this.Invoke(new ProcessResponseFromMapInvokeCallBack(this.ProcessResponseFromMap), urlResponse);
}
catch (Exception ex)
{
Utils.WriteLine("Error on Response telemtry Ex:" + ex.ToString(), ConsoleColor.Red);
}
};
LiveMapPanel.Controls.Add(mapGoogles);
//mapGoogles.AllowFileAccessFromFileURLs = true;
//this.SelectionLive.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(219)))), ((int)(((byte)(255)))));
//ThemeResolutionService.ApplyThemeToControlTree(this, "ControlDefault");
FirstTime = DateTime.Now;
setLanguage();
//vehiclesList.TableElement.RowHeight = 32;
StartGoogleMap.Enabled = true;
StartGoogleMap.Start();
populateVehiclesList(vehicleListNames);
//update data
try
{
if (vehiclesList.SelectedRows[0].Cells["UnitName"].Value != null)
{
selectName = vehiclesList.SelectedRows[0].Cells["UnitName"].Value.ToString();
foreach (TelemetryObj temobj in ((Vehicle)MainForm2.vehicleHT[vehiclesList.SelectedRows[0].Cells["UnitName"].Value.ToString()]).telemList)
{
ChangePreview(temobj, (Bitmap)vehiclesList.SelectedRows[0].Cells[temobj.DigitalNr + 2].Value);
}
/*
if (((Vehicle)MainForm2.vehicleHT[vehiclesList.SelectedRows[0].Cells[2].Value.ToString()]).telemPos != null)
lbLastUpdate.Text = lasttime + ": " + convDT.GetDTFromSeconds(convDT.ConvertGMTToLocal(((Vehicle)MainForm2.vehicleHT[vehiclesList.SelectedRows[0].Cells[2].Value.ToString()]).telemPos.TimeGMT));*/
}
else selectName = "";
}
catch (Exception ex)
{
SM.Debug("Unable to change telemetry " + ex.ToString());
}
MainForm2.RestartMEM += 40000000;
cbType1.SelectedIndex = 0;
cbType2.SelectedIndex = 0;
cbType3.SelectedIndex = 0;
cbType4.SelectedIndex = 0;
cbType5.SelectedIndex = 0;
GetPositionForPlace = false;
GetPositionForStart = false;
GetPositionForZones = false;
toolWindow2.ToolCaptionButtons = Telerik.WinControls.UI.Docking.ToolStripCaptionButtons.AutoHide | Telerik.WinControls.UI.Docking.ToolStripCaptionButtons.SystemMenu;
toolWindow2.DocumentButtons &= ~Telerik.WinControls.UI.Docking.DocumentStripButtons.Close;
toolWindow3.ToolCaptionButtons = Telerik.WinControls.UI.Docking.ToolStripCaptionButtons.AutoHide | Telerik.WinControls.UI.Docking.ToolStripCaptionButtons.SystemMenu;
toolWindow3.DocumentButtons &= ~Telerik.WinControls.UI.Docking.DocumentStripButtons.Close;
toolWindow3.AllowedDockState = AllowedDockState.Docked | AllowedDockState.AutoHide;
ContextMenuService menuService = this.radDock1.GetService<ContextMenuService>();
menuService.ContextMenuDisplaying += menuService_ContextMenuDisplaying;
//this disables the context menu
menuService.AllowActiveWindowListContextMenu = false;
menuService.AllowDocumentContextMenu = false;
menuService.AllowToolContextMenu = false;
ContextMenu cm = new System.Windows.Forms.ContextMenu();
cm.Popup += delegate(object sender, EventArgs e)
{
// select the cell in the grid in order for the telerik context menu
// to activate the required options
if (cm.SourceControl == splitPanel2)
vehiclesList.CurrentColumn = vehiclesList.Columns["Digi1"];
else if (cm.SourceControl == splitPanel3)
vehiclesList.CurrentColumn = vehiclesList.Columns["Digi2"];
else if (cm.SourceControl == splitPanel4)
vehiclesList.CurrentColumn = vehiclesList.Columns["Digi3"];
else if (cm.SourceControl == splitPanel5)
vehiclesList.CurrentColumn = vehiclesList.Columns["Digi4"];
else if (cm.SourceControl == splitPanel6)
vehiclesList.CurrentColumn = vehiclesList.Columns["Digi5"];
this.vehiclesList.ContextMenuManager.ShowContextMenu(this.vehiclesList.CurrentCell);
};
// assign a context menu to the split panels
// this context menu is necessary because the split panels allows only microsoft context
// and in this way I intercept the right click and the display the context menu
// that telerik provided
splitPanel2.ContextMenu = cm;
splitPanel3.ContextMenu = cm;
splitPanel4.ContextMenu = cm;
splitPanel5.ContextMenu = cm;
splitPanel6.ContextMenu = cm;
}
private void menuService_ContextMenuDisplaying(object sender, ContextMenuDisplayingEventArgs e)
{
if (e.MenuType == ContextMenuType.DockWindow &&
e.DockWindow.DockTabStrip is DocumentTabStrip)
{
for (int i = 0; i < e.MenuItems.Count; i++)
{
RadMenuItemBase menuItem = e.MenuItems[i];
if (menuItem.Name == "CloseWindow" ||
menuItem.Name == "CloseAllButThis" ||
menuItem.Name == "CloseAll" ||
menuItem.Name == "Floating" ||
menuItem.Name == "Docked" ||
menuItem.Name == "Hidden" ||
menuItem is RadMenuSeparatorItem)
{
menuItem.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
}
}
}
}
/// <summary>
///populates the list of vehicles from the left part of the tab </summary>
/// <param name="listOfVehicles">an array of strings containing the vehicles names</param>
public volatile List<DataforTelemList> ListforTelemList = new List<DataforTelemList>();
volatile String GroupNameforgrid = "";
volatile Image Imageforgrid = null;
volatile String Statusforgrid = "";
volatile List<Image> ListImg = new List<Image>();
private void populateVehiclesList(ArrayList listOfVehicles)
{
vehiclesList.Columns[2].SortOrder = RadSortOrder.None;
int cont = 0;
ListforTelemList.Clear();
foreach(String obj in MainForm2.vehicleHT.Keys)
{
GroupNameforgrid = MainForm2.returnLNGString("otherunit");
if (MainForm2.GrpIdforScId[((Vehicle)MainForm2.vehicleHT[obj]).sc_id] != null)
GroupNameforgrid = ((GroupClass)MainForm2.GrpIdforScId[((Vehicle)MainForm2.vehicleHT[obj]).sc_id]).name;
Car crtCar = ((Car)MainForm2.carlist[((Vehicle)MainForm2.vehicleHT[obj]).IconID]);
String iconPath = crtCar.listFilePath;
try
{
Bitmap bmp = new Bitmap(iconPath);
Image tmp2 = bmp; //tmp.ToBitmap();
Imageforgrid = tmp2;
}
catch (Exception ex)
{
SM.Debug("Grid icon could not be found [" + iconPath + "]");
Imageforgrid = imageList1.Images[2];
}
ListImg.Clear();
for (int i=0;i<5;i++)
ListImg.Add(global::Dispatcher.Properties.Resources.te_in_d);
if ((((Vehicle)MainForm2.vehicleHT[obj]).telemList.Count != 0))
{
foreach (TelemetryObj temobj in ((Vehicle)MainForm2.vehicleHT[obj]).telemList)
{
// set icon for no valid info in case of a out pin
if (!temobj.DigitalType.Equals("IN"))
ListImg[temobj.DigitalNr - 1] = global::Dispatcher.Properties.Resources.te_out_d;
Byte digit = (Byte)Math.Pow(2, temobj.DigitalNr - 1);
// if old value exists for this unit
if ((((Vehicle)MainForm2.vehicleHT[obj]).telemPos != null))
{
// if the pin value is on
if ((((Byte)((Vehicle)MainForm2.vehicleHT[obj]).telemPos.ByteValue) & digit) > 0)
{
// set icon for in pin
ListImg[temobj.DigitalNr - 1] = global::Dispatcher.Properties.Resources.te_in_g;
// set icon for out pin
if (!temobj.DigitalType.Equals("IN"))
ListImg[temobj.DigitalNr - 1] = global::Dispatcher.Properties.Resources.te_out_g;//vehiclesList.Rows[cont].Cells[temobj.DigitalNr + 2].Value = global::Dispatcher.Properties.Resources.green_status;
}
// if pin vlaue is off
else
{
// set icon for in pin
ListImg[temobj.DigitalNr - 1] = global::Dispatcher.Properties.Resources.te_in_r;
// set icon for out pin
if (!temobj.DigitalType.Equals("IN"))
ListImg[temobj.DigitalNr - 1] = global::Dispatcher.Properties.Resources.te_out_r;
}
}
}
}
cont++;
ListforTelemList.Add(new DataforTelemList(GroupNameforgrid, Imageforgrid, obj, ListImg[0], ListImg[1], ListImg[2], ListImg[3], ListImg[4]));
}
try
{
vehiclesList.DataSource = null;
vehiclesList.DataSource = ListforTelemList;
}
catch (Exception ex)
{
SM.Debug("Error on populate grid" + ex.ToString());
}
vehiclesList.Columns[2].SortOrder = RadSortOrder.Ascending;
//grouping stuff
vehiclesList.GroupDescriptors.Clear();
GridGroupByExpression expression = new GridGroupByExpression();
expression.Expression = "GroupName as GroupName format \"{0}: {1}\" Group By GroupName";
vehiclesList.GroupDescriptors.Add(expression);
// vehiclesList.MasterGridViewTemplate.GroupDescriptors.Insert(0, new Telerik.WinControls.Data.GroupDescriptor("GroupName as GroupName format \"{0}: {1}\" Group By GroupName"));
GridExpandAnimationType temp = vehiclesList.GroupExpandAnimationType;
vehiclesList.GroupExpandAnimationType = GridExpandAnimationType.None;
for (int i = 0; i < vehiclesList.Groups.Count; i++)
this.Expand(vehiclesList.Groups[i]);
vehiclesList.GroupExpandAnimationType = temp;
//if (vehiclesList.RowCount > 0)
// vehiclesList.Rows[0].IsSelected = true;
//vehiclesList.Refresh();
}
public void updateName(String Name)
{
Boolean change = false;
try
{
foreach (GridViewRowInfo obj in vehiclesList.Rows)
if (obj.Cells[2].Value.ToString() == Name)
{
if ((((Vehicle)MainForm2.vehicleHT[Name]).telemList.Count != 0) && (((Vehicle)MainForm2.vehicleHT[Name]).telemPos != null))
{
foreach (TelemetryObj temobj in ((Vehicle)MainForm2.vehicleHT[Name]).telemList)
{
Byte digit = (Byte)Math.Pow(2, temobj.DigitalNr - 1);
Bitmap tmpImg = global::Dispatcher.Properties.Resources.te_in_r;
if (!temobj.DigitalType.Equals("IN"))
tmpImg = global::Dispatcher.Properties.Resources.te_out_r;
if ((((Byte)((Vehicle)MainForm2.vehicleHT[Name]).telemPos.ByteValue) & digit) > 0)
{
tmpImg = global::Dispatcher.Properties.Resources.te_in_g;
if (!temobj.DigitalType.Equals("IN"))
tmpImg = global::Dispatcher.Properties.Resources.te_out_g;
}
obj.Cells[temobj.DigitalNr + 2].Value = tmpImg;
change = true;
if (selectName == Name)
{
ChangePreview(temobj, tmpImg);
//lbLastUpdate.Text = lasttime + ": " + convDT.GetDTFromSeconds(convDT.ConvertGMTToLocal(((Vehicle)MainForm2.vehicleHT[Name]).telemPos.TimeGMT));
}
}
}
break;
}
if (change) vehiclesList.Refresh();
}
catch (Exception ex)
{
SM.Debug("Erorr on UpdateName:"+ex.ToString());
}
}
private void Expand(DataGroup group)
{
group.Expand();
if (group.Groups.Count > 0)
{
for (int i = 0; i < group.Groups.Count; i++)
{
this.Expand(group.Groups[i]);
}
}
}
private void Killtimer_Tick(object sender, EventArgs e)
{
if (MainForm2.ClosingApp)
{
SM.Debug("Worker Live:Telem FINISHED from timer");
SM.Debug("RELEASE SEMAFOR TAB LIVE: Telem");
KillTimerActive = true;
}
}
void SendTelem_Click(object sender, EventArgs e)
{
foreach(TelemetryObj obj in ((Vehicle)MainForm2.vehicleHT[(String)vehiclesList.SelectedRows[0].Cells[2].Value]).telemList)
if (obj.Name == ((RadMenuItem)sender).Text)
{
String Totrans = "#106#"+((Vehicle)MainForm2.vehicleHT[(String)vehiclesList.SelectedRows[0].Cells[2].Value]).sc_id+"#"+ obj.DigitalNr+"#";
parent.Send_UDP_cmd(Totrans, 10000,0);
break;
}
}
private void vehiclesList_SelectionChanged(object sender, EventArgs e)
{
if (vehiclesList.SelectedRows.Count > 0)
{
lbName1.Text = "Unknown1";
lbName2.Text = "Unknown2";
lbName3.Text = "Unknown3";
lbName4.Text = "Unknown4";
lbName5.Text = "Unknown5";
panStat1.BackgroundImage = global::Dispatcher.Properties.Resources.te_in_d;
panStat2.BackgroundImage = global::Dispatcher.Properties.Resources.te_in_d;
panStat3.BackgroundImage = global::Dispatcher.Properties.Resources.te_in_d;
panStat4.BackgroundImage = global::Dispatcher.Properties.Resources.te_in_d;
panStat5.BackgroundImage = global::Dispatcher.Properties.Resources.te_in_d;
btSend1.Visible = true; cbType1.Visible = true;
btSend2.Visible = true; cbType2.Visible = true;
btSend3.Visible = true; cbType3.Visible = true;
btSend4.Visible = true; cbType4.Visible = true;
btSend5.Visible = true; cbType5.Visible = true;
btSend1.Enabled = false; cbType1.Enabled = false;
btSend2.Enabled = false; cbType2.Enabled = false;
btSend3.Enabled = false; cbType3.Enabled = false;
btSend4.Enabled = false; cbType4.Enabled = false;
btSend5.Enabled = false; cbType5.Enabled = false;
try
{
if (vehiclesList.SelectedRows[0].Cells[2].Value != null)
{
selectName = vehiclesList.SelectedRows[0].Cells[2].Value.ToString();
foreach (TelemetryObj temobj in ((Vehicle)MainForm2.vehicleHT[vehiclesList.SelectedRows[0].Cells[2].Value.ToString()]).telemList)
{
ChangePreview(temobj, (Bitmap)vehiclesList.SelectedRows[0].Cells[temobj.DigitalNr + 2].Value);
}
}
else selectName = "";
}
catch (Exception ex)
{
SM.Debug("Unable to change telemetry " + ex.ToString());
}
}
}
private void ChangePreview(TelemetryObj temobj,Bitmap tmpImg)
{
switch (temobj.DigitalNr)
{
case 1:
lbName1.Text = temobj.Name;
panStat1.BackgroundImage = tmpImg;
if (temobj.DigitalType == "IN")
{
btSend1.Visible = false;
cbType1.Visible = false;
}
else
{
btSend1.Enabled = true;
cbType1.Enabled = true;
}
break;
case 2:
lbName2.Text = temobj.Name;
panStat2.BackgroundImage = tmpImg;
if (temobj.DigitalType == "IN")
{
btSend2.Visible = false;
cbType2.Visible = false;
}
else
{
btSend2.Enabled = true;
cbType2.Enabled = true;
}
break;
case 3:
lbName3.Text = temobj.Name;
panStat3.BackgroundImage = tmpImg;
if (temobj.DigitalType == "IN")
{
btSend3.Visible = false;
cbType3.Visible = false;
}
else
{
btSend3.Enabled = true;
cbType3.Enabled = true;
}
break;
case 4:
lbName4.Text = temobj.Name;
panStat4.BackgroundImage = tmpImg;
if (temobj.DigitalType == "IN")
{
btSend4.Visible = false;
cbType4.Visible = false;
}
else
{
btSend4.Enabled = true;
cbType4.Enabled = true;
}
break;
case 5:
lbName5.Text = temobj.Name;
panStat5.BackgroundImage = tmpImg;
if (temobj.DigitalType == "IN")
{
btSend5.Visible = false;
cbType5.Visible = false;
}
else
{
btSend5.Enabled = true;
cbType5.Enabled = true;
}
break;
}
}
private void btSend1_Click(object sender, EventArgs e)
{
parent.Send_telem_digit((String)vehiclesList.SelectedRows[0].Cells[2].Value, 1, cbType1.SelectedIndex);
}
private void btSend2_Click(object sender, EventArgs e)
{
parent.Send_telem_digit((String)vehiclesList.SelectedRows[0].Cells[2].Value, 2, cbType2.SelectedIndex);
}
private void btSend3_Click(object sender, EventArgs e)
{
parent.Send_telem_digit((String)vehiclesList.SelectedRows[0].Cells[2].Value, 3, cbType3.SelectedIndex);
}
private void btSend4_Click(object sender, EventArgs e)
{
parent.Send_telem_digit((String)vehiclesList.SelectedRows[0].Cells[2].Value, 4, cbType4.SelectedIndex);
}
private void btSend5_Click(object sender, EventArgs e)
{
parent.Send_telem_digit((String)vehiclesList.SelectedRows[0].Cells[2].Value, 5, cbType5.SelectedIndex);
}
private void btRefresh_Click(object sender, EventArgs e)
{
if (selectName != "")
parent.Send_telem_digit(selectName,10,0);
}
private void vehiclesList_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
try
{
string suff = String.Concat(" (", e.Group.ItemCount.ToString(), ")");
if (e.FormatString.Contains(":"))
{
e.FormatString = e.FormatString.Replace("{0}:", "");
}
if (!e.FormatString.EndsWith(suff))
{
e.FormatString = String.Concat(e.FormatString, suff);
}
// convert text to upper case
e.FormatString = e.FormatString.ToUpper();
}
catch (Exception ex)
{
SM.Debug("Erorr on GroupSummaryEvaluate" + ex.ToString());
}
}
private void vehiclesList_CellDoubleClick(object sender, GridViewCellEventArgs e)
{
if (vehiclesList.SelectedRows.Count > 0)
{
lbName1.Text = "Unknown1";
lbName2.Text = "Unknown2";
lbName3.Text = "Unknown3";
lbName4.Text = "Unknown4";
lbName5.Text = "Unknown5";
panStat1.BackgroundImage = global::Dispatcher.Properties.Resources.te_in_d;
panStat2.BackgroundImage = global::Dispatcher.Properties.Resources.te_in_d;
panStat3.BackgroundImage = global::Dispatcher.Properties.Resources.te_in_d;
panStat4.BackgroundImage = global::Dispatcher.Properties.Resources.te_in_d;
panStat5.BackgroundImage = global::Dispatcher.Properties.Resources.te_in_d;
btSend1.Visible = true; cbType1.Visible = true;
btSend2.Visible = true; cbType2.Visible = true;
btSend3.Visible = true; cbType3.Visible = true;
btSend4.Visible = true; cbType4.Visible = true;
btSend5.Visible = true; cbType5.Visible = true;
btSend1.Enabled = false; cbType1.Enabled = false;
btSend2.Enabled = false; cbType2.Enabled = false;
btSend3.Enabled = false; cbType3.Enabled = false;
btSend4.Enabled = false; cbType4.Enabled = false;
btSend5.Enabled = false; cbType5.Enabled = false;
try
{
if (vehiclesList.SelectedRows[0].Cells["UnitName"].Value != null)
{
selectName = vehiclesList.SelectedRows[0].Cells["UnitName"].Value.ToString();
foreach (TelemetryObj temobj in ((Vehicle)MainForm2.vehicleHT[vehiclesList.SelectedRows[0].Cells["UnitName"].Value.ToString()]).telemList)
{
ChangePreview(temobj, (Bitmap)vehiclesList.SelectedRows[0].Cells[temobj.DigitalNr + 2].Value);
}
}
else selectName = "";
}
catch (Exception ex)
{
SM.Debug("Unable to change telemetry " + ex.ToString());
}
try
{
if (vehiclesList.SelectedRows[0].Cells["UnitName"].Value != null)
{
String datasetCMD = "setDataset,PointSelect";
Vehicle veh = (Vehicle)MainForm2.vehicleHT[vehiclesList.SelectedRows[0].Cells["UnitName"].Value.ToString()];
if (Math.Abs(veh.LAT) <= 0.1 && Math.Abs(veh.LNG) <= 0.1)
parent.DisplayToast(string.Format(MainForm2.returnLNGString("unableDisp") , selectName),
string.Format(MainForm2.returnLNGString("HTMLnoValidGPS"), selectName ));
DateTime positionTime = (((veh).lastValidPositionTime).ConvertGMTToLocal()).GetDTFromSeconds();
Boolean hasVoice = veh.has_voice;
Boolean hasText = veh.has_text;
Boolean isInCall = veh.inCall;
int smsLength = SmsUtils.GetMaxNumberOfCharacters(MainForm2.radioType);
#region mapCallTimeout
int mapCallTimeout = 3;
((Vehicle)MainForm2.vehicleHT[vehiclesList.SelectedRows[0].Cells["UnitName"].Value.ToString()]).CheckPositionInSystem();
string GatewayAndRadioID = ((Vehicle)MainForm2.vehicleHT[vehiclesList.SelectedRows[0].Cells["UnitName"].Value.ToString()]).GwandRadioID;
int gwType = (int)GatewayType.Unknown;
if (MainForm2.radioGwHT[GatewayAndRadioID] != null)
{
if (((RadioGateway)MainForm2.radioGwHT[GatewayAndRadioID]).Type == (int)GatewayType.Broadband || ((RadioGateway)MainForm2.radioGwHT[GatewayAndRadioID]).Type == (int)GatewayType.Tier3Radio)
{
mapCallTimeout = MainForm2.MapCallTimeout;
}
gwType = ((RadioGateway)MainForm2.radioGwHT[GatewayAndRadioID]).Type;
smsLength = SmsUtils.GetMaxNumberOfCharacters(gwType);
}
#endregion
datasetCMD = datasetCMD + ","
+ MainForm2.FixDoubleLAT(veh.LAT.ToString()) + ","
+ MainForm2.FixDoubleLNG(veh.LNG.ToString()) + ","
+ positionTime.ToString("yyyy-MM-dd HH:mm:ss") + ","
+ veh.busName + ","
+ veh.GetSpeed() + (MainForm2.isInMile ? "mph" : "kph") + ","
+ veh.GetAlt() + ","
+ veh.GetLastAddress().Replace(',', ' ') + ","
+ "images/telemetry.png" + ","
+ (hasVoice ? mapCallTimeout : 0) + "," + (hasText ? smsLength : 0) + "," + isInCall;
if (docLoad)
{
datasetCMD = datasetCMD.Replace(';', ' ');
mapGoogles.ExecuteScript("window.GWTcallback('" + datasetCMD + "');");
mapGoogles.ExecuteScript("window.GWTcallback('" + "putOnMap,true,PointSelect');");
mapGoogles.ExecuteScript("window.GWTcallback('" + "openInfo," + MainForm2.FixComma(vehiclesList.SelectedRows[0].Cells[2].Value.ToString()) + "');");
}
}
}
catch (Exception ex)
{
SM.Debug("Eroare cu google" + ex.ToString());
}
}
}
private void StartGoogleMap_Tick(object sender, EventArgs e)
{
StartGoogleMap.Stop();
StartGoogleMap.Enabled = false;
String safemobileDirPath = System.Windows.Forms.Application.StartupPath.Replace('\\', '/').Replace(" ", "%20");
safemobileDirPath = safemobileDirPath.Replace("#", "%23");
mapGoogles.LoadWebPage("file:///" + safemobileDirPath + "/resource/" + MainForm2.MapHtmlName);
TimerToLoadMap.Enabled = true;
TimerToLoadMap.Start();
docLoad = true;
}
private void vehiclesList_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS))
{
if (e.CellElement is GridGroupContentCellElement)
{
e.CellElement.ForeColor = MainForm2.HarTextColor;
}
else
{
e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
}
}
}
private void Timer_Tick(object sender, EventArgs e)
{
}
private WaitToLoad WaitWindow = null;
private void MessageScreen_Tick(object sender, EventArgs e)
{
try
{
MessageScreen.Stop();
MessageScreen.Enabled = false;
WaitWindow = new WaitToLoad(false);
WaitWindow.ShowDialog();
}
catch (Exception ex)
{
SM.Debug("Ex10:" + ex.ToString());
}
}
public delegate void ProcessResponseFromMapInvokeCallBack(String url);
private void ProcessResponseFromMap(String url)
{
if (url.IndexOf("app://") > -1)
{
Utils.WriteLine("RESPONSE FROM MAP : " + url, ConsoleColor.Magenta);
// hide the loading window because the map has loaded
if (url.IndexOf("map-loaded") > -1)
{
if (WaitWindow != null)
WaitWindow.Close();
}
else if (url.IndexOf("street-view-open") > -1)
{
String tmpstr = url.Remove(0, url.IndexOf("street-view-open") + 17);
Console.WriteLine("parsare:" + tmpstr);
tmpstr = tmpstr.Trim();
if (tmpstr.ToUpper().CompareTo("TRUE") == 0) StreetViewOpened = true;
else StreetViewOpened = false;
}
}
}
/// <summary>
/// Hide borders and grid lines for the grid
/// </summary>
private void vehiclesList_CellFormatting(object sender, CellFormattingEventArgs e)
{
GridCellElement cellElement = e.CellElement;
GridViewDataColumn columnInfo = e.CellElement.ColumnInfo as GridViewDataColumn;
if (cellElement != null)
cellElement.DrawBorder = false;
// do not highlight the cell on which was clicked
if (e.CellElement.IsCurrent)
e.CellElement.IsCurrent = false;
if(columnInfo.Name.StartsWith("Digi"))
{
string unitName = e.Row.Cells[2].Value.ToString();
foreach (TelemetryObj temobj in ((Vehicle)MainForm2.vehicleHT[unitName]).telemList)
{
/*
if (("Digi" + temobj.DigitalNr).Equals(columnInfo.Name) && !temobj.DigitalType.Equals("IN"))
{
cellElement.DrawFill = true;
cellElement.NumberOfColors = 1;
cellElement.BackColor = Color.Thistle;
}*/
}
}
}
private void vehiclesList_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
GridDataCellElement cell = e.ContextMenuProvider as GridDataCellElement;
if (cell == null)
{
return;
}
try
{
if (e.ContextMenuProvider is GridDataCellElement)
{
GridViewRowInfo row = ((GridDataCellElement)e.ContextMenuProvider).RowInfo;
// create the drop down menu
RadDropDownMenu TelemMenu = new RadDropDownMenu();
try
{
if (vehiclesList.SelectedRows[0].Cells[2].Value != null)
{
selectName = vehiclesList.SelectedRows[0].Cells[2].Value.ToString();
foreach (TelemetryObj temobj in ((Vehicle)MainForm2.vehicleHT[vehiclesList.SelectedRows[0].Cells[2].Value.ToString()]).telemList)
{
if (temobj.DigitalNr == cell.ColumnIndex - 2)
{
TelemMenu.Text = "Pin " + temobj.DigitalNr + " options";
if (temobj.DigitalType != "IN")
{
// create context menu button
RadMenuItem itemSet = new RadMenuItem(MainForm2.returnLNGString("telemSet"));
// add click listener for the context menu button
itemSet.Click += delegate(object s, EventArgs ev)
{
// send SET command
parent.Send_telem_digit(selectName, temobj.DigitalNr, (int)TelemCommands.SET);
parent.DisplayToast(string.Format(MainForm2.returnLNGString("telemSent"), selectName),
string.Format(MainForm2.returnLNGString("pinCmdToGW"), itemSet.Text.ToUpper(), temobj.DigitalNr));
TelemMenu.ClosePopup(RadPopupCloseReason.Mouse);
};
// add button to context menu
TelemMenu.Items.Add(itemSet);
// create context menu button
RadMenuItem itemClear = new RadMenuItem(MainForm2.returnLNGString("telemClear"));
// add click listener for the context menu button
itemClear.Click += delegate(object s, EventArgs ev)
{
// send CLEAR command
parent.Send_telem_digit(selectName, temobj.DigitalNr, (int)TelemCommands.CLEAR);
parent.DisplayToast(string.Format(MainForm2.returnLNGString("telemSent"), selectName),
string.Format(MainForm2.returnLNGString("pinCmdToGW"), itemClear.Text.ToUpper(), temobj.DigitalNr));
TelemMenu.ClosePopup(RadPopupCloseReason.Mouse);
};
// add button to context menu
TelemMenu.Items.Add(itemClear);
// create context menu button
RadMenuItem itemToggle = new RadMenuItem(MainForm2.returnLNGString("telemToggle"));
// add click listener for the context menu button
itemToggle.Click += delegate(object s, EventArgs ev)
{
// send TOGGLE command
parent.Send_telem_digit(selectName, temobj.DigitalNr, (int)TelemCommands.TOGGLE);
parent.DisplayToast(string.Format(MainForm2.returnLNGString("telemSent"), selectName),
string.Format(MainForm2.returnLNGString("pinCmdToGW"),itemToggle.Text.ToUpper(),temobj.DigitalNr));
TelemMenu.ClosePopup(RadPopupCloseReason.Mouse);
};
// add button to context menu
TelemMenu.Items.Add(itemToggle);
// create context menu button
RadMenuItem itemPulse = new RadMenuItem(MainForm2.returnLNGString("telemPulse"));
// add click listener for the context menu button
itemPulse.Click += delegate(object s, EventArgs ev)
{
// send PULSE command
parent.Send_telem_digit(selectName, temobj.DigitalNr, (int)TelemCommands.PULSE);
parent.DisplayToast(string.Format(MainForm2.returnLNGString("telemSent"), selectName),
string.Format(MainForm2.returnLNGString("pinCmdToGW"),itemPulse.Text.ToUpper(),temobj.DigitalNr));
TelemMenu.ClosePopup(RadPopupCloseReason.Mouse);
};
// add button to context menu
TelemMenu.Items.Add(itemPulse);
}
}
}
}
}
catch (Exception ex)
{
SM.Debug("Unable to change telemetry " + ex.ToString());
}
// create context menu button
RadMenuItem itemRefresh = new RadMenuItem(MainForm2.returnLNGString("refreshAll"));
// add click listener for the context menu button
itemRefresh.Click += delegate(object s, EventArgs ev)
{
// send the refresh command
if (selectName != "")
{
parent.Send_telem_digit(selectName, 10, 0);
parent.DisplayToast(string.Format(MainForm2.returnLNGString("telemSent"), selectName),
string.Format(MainForm2.returnLNGString("CmdHTML"),itemRefresh.Text.ToUpper()));
}
TelemMenu.ClosePopup(RadPopupCloseReason.Mouse);
};
// add button to context menu
TelemMenu.Items.Add(itemRefresh);
e.ContextMenu = TelemMenu;
}
}
catch (Exception ex)
{
SM.Debug("EXLive10:" + ex.ToString());
}
}
/// <summary>
/// Format the cell in order to remove the indent of the cells
/// </summary>
private void vehiclesList_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
// format live column
if (e.Row is GridDataRowElement)
{
// increase row height
//e.Row.RowInfo.Height = 53;
if (e.Column is GridViewIndentColumn)
{
e.Column.IsVisible = false;
/*
e.Column.MaxWidth = 7;
e.Column.MinWidth = 7;
e.Column.Width = 7;*/
//e.CellElement.Visibility = ElementVisibility.Hidden;
}
}
}
/// <summary>
/// Event handler for when the left tab panel needs to be docked/transfor in floating state.
/// This will cancel this event in order to prevent the stupid case with hiding the dock window
/// </summary>
private void radDock1_DockStateChanging(object sender, DockStateChangingEventArgs e)
{
e.Cancel = true;
}
private void TelemTab_Load(object sender, EventArgs e)
{
// register for when the unit call status is changed
this.parent.OnCallStatusChanged += delegate(string unitname, bool inCall, Boolean fromField)
{
Utils.WriteLine("SET CALL " + unitname + " " + inCall);
mapGoogles.ExecuteScript(String.Format("window.GWTcallback('setCall,{0},{1}')", unitname, inCall));
};
}
/// <summary>
/// Change background color for the row according to its state and theme
/// </summary>
private void vehiclesList_RowFormatting(object sender, RowFormattingEventArgs e)
{
if (e.RowElement.IsSelected)
{
e.RowElement.DrawFill = true;
e.RowElement.BackColor = MainForm2.GridSelectedRow;
e.RowElement.NumberOfColors = 1;
}
else
e.RowElement.DrawFill = false;
}
#region CHANGE TABS BACKGROUND
private DockWindow oldDockWindow = null;
private void radDock1_ActiveWindowChanging(object sender, DockWindowCancelEventArgs e)
{
// reset the background icon for the previous tab
e.OldWindow.TabStripItem.BackColor = Color.White;
e.OldWindow.TabStripItem.DrawFill = true;
e.OldWindow.TabStripItem.NumberOfColors = 1;
// reset the background for the new window
e.NewWindow.TabStripItem.DrawFill = true;
e.NewWindow.TabStripItem.NumberOfColors = 1;
e.NewWindow.TabStripItem.BackColor = MainForm2.TabSelectedColor;
// save old dock window
oldDockWindow = e.OldWindow;
}
private void radDock1_ActiveWindowChanged(object sender, DockWindowEventArgs e)
{
// reset the background icon for the previous tab
oldDockWindow.TabStripItem.BackColor = Color.White;
oldDockWindow.TabStripItem.DrawFill = true;
oldDockWindow.TabStripItem.NumberOfColors = 1;
e.DockWindow.TabStripItem.DrawFill = true;
e.DockWindow.TabStripItem.NumberOfColors = 1;
e.DockWindow.TabStripItem.BackColor = MainForm2.TabSelectedColor;
}
#endregion
private void vehiclesList_CellClick(object sender, GridViewCellEventArgs e)
{
if(e.ColumnIndex > vehiclesList.Columns["UnitName"].Index)
this.vehiclesList.ContextMenuManager.ShowContextMenu(this.vehiclesList.CurrentCell);
}
private void splitPanel3_Click(object sender, EventArgs e)
{
// select the cell in the grid in order for the telerik context menu
// to activate the required options
if (sender == splitPanel2)
vehiclesList.CurrentColumn = vehiclesList.Columns["Digi1"];
else if (sender == splitPanel3)
vehiclesList.CurrentColumn = vehiclesList.Columns["Digi2"];
else if (sender == splitPanel4)
vehiclesList.CurrentColumn = vehiclesList.Columns["Digi3"];
else if (sender == splitPanel5)
vehiclesList.CurrentColumn = vehiclesList.Columns["Digi4"];
else if (sender == splitPanel6)
vehiclesList.CurrentColumn = vehiclesList.Columns["Digi5"];
this.vehiclesList.ContextMenuManager.ShowContextMenu(this.vehiclesList.CurrentCell);
}
}
}