SafeDispatch/Safedispatch_4_0/Reports/ReportsControl.cs

2505 lines
129 KiB
C#
Raw Permalink 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.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls;
using Telerik.WinControls.UI.Docking;
using System.Globalization;
using SafeMobileLib;
using System.Threading;
using System.IO;
using System.Text.RegularExpressions;
namespace Safedispatch_4_0
{
public partial class ReportsControl : UserControl
{
private SMdb_access smdbObj;
private String glwhere, msgLimit, msgInteger, msgMustSel, msgInvalidEmail, msgSplitEmail, msgEmailSaved;
private rep_type RepType;
private ConvertDT convDT;
private ArrayList vehicleListNames;
private ArrayList ZoneListNames;
private volatile Boolean ValidReport = false;
private String minval = "";
private Boolean ButtonStatusCancel = false;
public static volatile Hashtable IdReportHS = new Hashtable();
private String hintText = "";
// store all the vehicles
public BindingList<DropListItem> UnitGroupItems = new BindingList<DropListItem>();
private void setLanguage()
{
rlUnitGroup.Text = MainForm2.returnLNGString("unitemail");
rlReportDaily.Text = MainForm2.returnLNGString("reptoemail");
btSaveEmail.Text = MainForm2.returnLNGString("savemail");
rlCoordinates.Text = MainForm2.returnLNGString("showcoor");
rlSelectAll.Text = MainForm2.returnLNGString("cbselAll");
rlIdle.Text = MainForm2.returnLNGString("generate") + " ";
rlComputing.Text = MainForm2.returnLNGString("comp");
hintText = MainForm2.returnLNGString("sepaemail");
// create the toolTip that will be displayed when the user sets a pattern
// over the hint pictureBox
toolTipHelp = new ToolTip();
toolTipHelp.ToolTipTitle = "Email reporting";
toolTipHelp.AutoPopDelay = 0;
toolTipHelp.InitialDelay = 0;
toolTipHelp.ReshowDelay = 0;
toolTipHelp.IsBalloon = false;
toolTipHelp.ShowAlways = true;
rlComputeAddress.Text = MainForm2.returnLNGString("compAddr");
rlDateTimeFilter.Text = MainForm2.returnLNGString("datetimefil");
rlUntil.Text = MainForm2.returnLNGString("until");
//ckSelectALL.Text = MainForm2.returnLNGString("cbselAll");
//ckStatus.Text = MainForm2.returnLNGString("SMSStatus");
rlIdle.Text = MainForm2.returnLNGString("txIDLE");
btPrintReport.Text = MainForm2.returnLNGString("btShowReport");
minval = MainForm2.returnLNGString("min");
toolWindow1.Text = MainForm2.returnLNGString("Filter");
toolWindow2.Text = MainForm2.returnLNGString("Report");
rdtFrom.Culture = MainForm2.culture;
rdtUntil.Culture = MainForm2.culture;
rcbGeoLandType.Items.Add(StringEnum.OUT.ToString());
rcbGeoLandType.Items.Add(StringEnum.IN.ToString());
rcbStatus.Items.Add(StringEnum.OFF.ToString());
rcbStatus.Items.Add(StringEnum.ON.ToString());
rcbStatus.Items.Add(StringEnum.MADEOFF.ToString());
rcbStatus.Items.Add(StringEnum.MADEON.ToString());
// select first item
if (rcbGeoLandType.Items.Count >= 1)
rcbGeoLandType.SelectedIndex = 0;
// select first item
if (rcbStatus.Items.Count >= 1)
rcbStatus.SelectedIndex = 0;
if (MainForm2.is24hours)
{
if (MainForm2.DayFirst)
{
rdtFrom.CustomFormat = "dd/MM/yyyy HH:mm";
rdtUntil.CustomFormat = "dd/MM/yyyy HH:mm";
}
else
{
rdtFrom.CustomFormat = "MM/dd/yyyy HH:mm";
rdtUntil.CustomFormat = "MM/dd/yyyy HH:mm";
}
}
else
{
if (MainForm2.DayFirst)
{
rdtFrom.CustomFormat = "dd/MM/yyyy hh:mm tt";
rdtUntil.CustomFormat = "dd/MM/yyyy hh:mm tt";
}
else
{
rdtFrom.CustomFormat = "MM/dd/yyyy hh:mm tt";
rdtUntil.CustomFormat = "MM/dd/yyyy hh:mm tt";
}
}
}
public void Refresh_GeoName()
{
try
{
ZoneListNames.Clear();
if (RepType == rep_type.GEOFENC)
{
foreach (Int32 obj in MainForm2.ZoneIDHash.Keys)
ZoneListNames.Add(new VehandID(((ZoneClass)MainForm2.ZoneIDHash[obj]).Name, obj, ""));
}
rcbGeoLandName.DataSource = null;
ZoneListNames.Sort(new VehandIDComparer());
rcbGeoLandName.DataSource = ZoneListNames;
rcbGeoLandName.DisplayMember = "Name";
if (rcbGeoLandName.Items.Count >= 1)
rcbGeoLandName.SelectedIndex = 0;
}
catch (Exception ex)
{
SM.Debug("Error Load ReportsControl: " + ex.ToString());
}
}
public void Refresh_LandName()
{
try
{
ZoneListNames.Clear();
if (RepType == rep_type.LAND)
{
foreach (Int32 obj in MainForm2.LandIDHash.Keys)
ZoneListNames.Add(new VehandID((String)MainForm2.LandIDHash[obj], obj, ""));
}
rcbGeoLandName.DataSource = null;
ZoneListNames.Sort(new VehandIDComparer());
rcbGeoLandName.DataSource = ZoneListNames;
rcbGeoLandName.DisplayMember = "Name";
if (rcbGeoLandName.Items.Count >= 1)
rcbGeoLandName.SelectedIndex = 0;
}
catch (Exception ex)
{
SM.Debug("Error Load ReportsControl: " + ex.ToString());
}
}
public ReportsControl(rep_type _RepType)
{
smdbObj = new SMdb_access();
vehicleListNames = new ArrayList();
ZoneListNames = new ArrayList();
convDT = new ConvertDT();
RepType = _RepType;
InitializeComponent();
// update the UI for the current report type
UpdateUIForReportType(_RepType);
setLanguage();
toolWindow1.ToolCaptionButtons = Telerik.WinControls.UI.Docking.ToolStripCaptionButtons.AutoHide | Telerik.WinControls.UI.Docking.ToolStripCaptionButtons.SystemMenu;
toolWindow1.DocumentButtons &= ~Telerik.WinControls.UI.Docking.DocumentStripButtons.Close;
toolWindow1.AllowedDockState = AllowedDockState.Docked | AllowedDockState.AutoHide;
toolWindow2.ToolCaptionButtons = Telerik.WinControls.UI.Docking.ToolStripCaptionButtons.AutoHide | Telerik.WinControls.UI.Docking.ToolStripCaptionButtons.SystemMenu;
toolWindow2.DocumentButtons &= ~Telerik.WinControls.UI.Docking.DocumentStripButtons.Close;
msgLimit = MainForm2.returnLNGString("endtimegreate");
msgInteger = MainForm2.returnLNGString("msgInteger");
msgMustSel = MainForm2.returnLNGString("mustselect");
msgInvalidEmail = MainForm2.returnLNGString("msgInvalidEmail");
msgSplitEmail = MainForm2.returnLNGString("msgSplitEmail");
msgEmailSaved = MainForm2.returnLNGString("msgEmailSaved");
if (MainForm2.is24hours)
{
if (MainForm2.DayFirst)
{
rdtFrom.CustomFormat = "dd/MM/yyyy HH:mm";
rdtUntil.CustomFormat = "dd/MM/yyyy HH:mm";
}
else
{
rdtFrom.CustomFormat = "MM/dd/yyyy HH:mm";
rdtUntil.CustomFormat = "MM/dd/yyyy HH:mm";
}
}
else
{
if (MainForm2.DayFirst)
{
rdtFrom.CustomFormat = "dd/MM/yyyy hh:mm tt";
rdtUntil.CustomFormat = "dd/MM/yyyy hh:mm tt";
}
else
{
rdtFrom.CustomFormat = "MM/dd/yyyy hh:mm tt";
rdtUntil.CustomFormat = "MM/dd/yyyy hh:mm tt";
}
}
DateTime now = DateTime.Now;
DateTime beginOfDay = new DateTime(now.Year, now.Month, now.Day);
rdtFrom.Value = beginOfDay;
rdtUntil.Value = now;
try
{
foreach (String obj in MainForm2.vehicleHT.Keys)
{
// get the vehicle for this key
Vehicle veh = (Vehicle)(MainForm2.vehicleHT[obj]);
// create the DropList Item and add it to the items list
DropListItem item = new DropListItem();
item.Text = veh.busName;
item.Image = GetIconForCombobox(MainForm2.radioType, "unit", true); //Dispatcher.Properties.Resources.icon_u;
item.ValueImei = "'" + veh.IMEI + "'";
item.ValueScID = veh.sc_id + "";
UnitGroupItems.Add(item);
vehicleListNames.Add(new VehandID(((Vehicle)MainForm2.vehicleHT[obj]).busName, ((Vehicle)MainForm2.vehicleHT[obj]).sc_id, ((Vehicle)MainForm2.vehicleHT[obj]).IMEI));
}
// sort alphabetically the list
List<DropListItem> sortedList = UnitGroupItems.OrderBy(x => x.Text).ToList();
UnitGroupItems = new BindingList<DropListItem>(sortedList);
// do not add the Groups to the comboBox if one of this types
if (!(_RepType == rep_type.ENDOFDAY || _RepType == rep_type.FLEET ||
_RepType == rep_type.IDLE || _RepType == rep_type.STOP))
{
// create a temporary binding list which will be sorted before being added to the
// main binding list
BindingList<DropListItem> tempGroupList = new BindingList<DropListItem>();
// add groups into drop list
foreach (DictionaryEntry pair in MainForm2.GroupHash)
{
GroupClass group = (GroupClass)pair.Value;
DropListItem item = new DropListItem();
item.Image = GetIconForCombobox(MainForm2.radioType, "group", true); //Dispatcher.Properties.Resources.icon_group;
item.Text = group.name;
item.IsGroup = true;
// create the list of sc_ids contained in this group
string scIDs = "";
foreach (int unitScID in group.arrSc_id)
{
scIDs = scIDs + unitScID + ",";
}
// remove last ,
if (scIDs.Length > 0 && scIDs.Substring(scIDs.Length - 1, 1).Equals(","))
scIDs = scIDs.Remove(scIDs.Length - 1);
// add group imeis to the data item value
item.ValueScID = scIDs;
// add only groups with units
if (scIDs.Length > 0)
tempGroupList.Add(item);
// create the list of imeis contained in this group
string imeis = "";
foreach (String unitImei in group.arrImei)
{
imeis = imeis + "'" + unitImei + "',";
}
// remove last ,
if (imeis.Length > 0 && imeis.Substring(imeis.Length - 1, 1).Equals(","))
imeis = imeis.Remove(imeis.Length - 1);
// add group imeis to the data item value
item.ValueImei = imeis;
}
// sort alphabetically the list
List<DropListItem> sortedGroupList = tempGroupList.OrderBy(x => x.Text).ToList();
// add the temporary list to the main one
foreach (DropListItem ite in sortedGroupList)
UnitGroupItems.Add(ite);
}
if (RepType == rep_type.GEOFENC)
{
foreach (Int32 obj in MainForm2.ZoneIDHash.Keys)
ZoneListNames.Add(new VehandID(((ZoneClass)MainForm2.ZoneIDHash[obj]).Name, obj, ""));
}
else if (RepType == rep_type.LAND)
{
foreach (Int32 obj in MainForm2.LandIDHash.Keys)
ZoneListNames.Add(new VehandID((String)MainForm2.LandIDHash[obj], obj, ""));
}
}
catch (Exception ex)
{
SM.Debug("Error Load ReportsControl: " + ex.ToString());
MainForm2.Connfailed = true;
return;
}
vehicleListNames.Sort(new VehandIDComparer());
// add the datasource for the vehicles ComboBox
rcbUnitGroup.DataSource = UnitGroupItems;
//cbVehName.DataSource = vehicleListNames;
//cbVehName.DisplayMember = "Name";
if (rcbUnitGroup.Items.Count > 1)
rcbUnitGroup.SelectedIndex = 0;
foreach (VehandID obj in vehicleListNames)
rcbUnitFleet.Items.Add(new CustomListDataItem(obj.Name));
pbUnitGroupForCombo.Enabled = false;
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "unit", false);
ContextMenuService menuService = this.radDock1.GetService<ContextMenuService>();
menuService.ContextMenuDisplaying += menuService_ContextMenuDisplaying;
//this disables the context menu
menuService.AllowActiveWindowListContextMenu = false;
menuService.AllowDocumentContextMenu = false;
menuService.AllowToolContextMenu = false;
try
{
switch (MainForm2.radioType)
{
case RADIOTYPE.HYT:
radDock1.BackColor = MainForm2.HyteraColor;
documentTabStrip1.BackColor = MainForm2.HyteraColor;
documentContainer1.BackColor = MainForm2.HyteraColor;
toolWindow1.BackColor = MainForm2.HyteraColor;
break;
case RADIOTYPE.HARRIS:
radDock1.BackColor = MainForm2.HarrisColor;
documentTabStrip1.BackColor = MainForm2.HarrisColor;
documentContainer1.BackColor = MainForm2.HarrisColor;
toolWindow1.BackColor = MainForm2.HarrisColor;
rlIdle.ForeColor = MainForm2.HarTextColor;
rlMin.ForeColor = MainForm2.HarTextColor;
rlUnitGroup.ForeColor = MainForm2.HarTextColor;
rlUntil.ForeColor = MainForm2.HarTextColor;
ckDataFilter.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckSelectALL.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckGeofenceType.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckStatus.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckUnitGroupFilter.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckComputeAddress.ForeColor = MainForm2.HarTextColor;
rlComputing.ForeColor = MainForm2.HarTextColor;
break;
case RADIOTYPE.ATLAS:
radDock1.BackColor = MainForm2.HarrisColor;
documentTabStrip1.BackColor = MainForm2.HarrisColor;
documentContainer1.BackColor = MainForm2.HarrisColor;
toolWindow1.BackColor = MainForm2.HarrisColor;
rlIdle.ForeColor = MainForm2.HarTextColor;
rlMin.ForeColor = MainForm2.HarTextColor;
rlUnitGroup.ForeColor = MainForm2.HarTextColor;
rlUntil.ForeColor = MainForm2.HarTextColor;
ckDataFilter.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckSelectALL.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckGeofenceType.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckStatus.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckUnitGroupFilter.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckComputeAddress.ForeColor = MainForm2.HarTextColor;
rlComputing.ForeColor = MainForm2.HarTextColor;
break;
}
}
catch (Exception ex)
{
SM.Debug("Error on change color constructor:" + ex.ToString());
}
}
/// <summary>
/// Event when the mouse is entering the Report Daily Panel. It will display a tooltip
/// containing some informations
/// </summary>
private void emailHint_MouseEnter(object sender, EventArgs e)
{
DisplayToolTip(sender, hintText);
}
/// <summary>
/// Event when the mouse is exiting the Report Daily Panel. It will hide the tooltip
/// previous displayed
/// </summary>
private void emailHint_MouseLeave(object sender, EventArgs e)
{
toolTipHelp.Hide((IWin32Window)sender);
}
/// <summary>
/// Event when the mouse is hovering over the Report Daily Panel. It will display a tooltip
/// containing some informations
/// </summary>
private void emailHint_MouseHover(object sender, EventArgs e)
{
DisplayToolTip(sender, hintText);
}
/// <summary>
/// Display a tooltip attached to a specific control
/// </summary>
private void DisplayToolTip(Object tooltipControl, string hintText)
{
// number of seconds for the toolTip to be shown
toolTipHelp.Show(hintText, (IWin32Window)tooltipControl, 150000);
}
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;
}
}
}
}
private void btPrintReport_Click(object sender, EventArgs e)
{
try
{
if (!ButtonStatusCancel)
{
if (RepType == rep_type.FLEET)
{
MainForm2.FleetPosList = new ArrayList();
for (Int32 i = 0; i < rcbUnitFleet.Items.Count; i++)
{
if (((CustomListDataItem)rcbUnitFleet.Items[i]).Checked)
{
var tmp = new FleetIdandPos
{
Name = ((CustomListDataItem)rcbUnitFleet.Items[i]).Text,
Position = new ArrayList()
};
MainForm2.FleetPosList.Add(tmp);
}
}
}
if (((RepType == rep_type.HIST) && (ckComputeAddress.Checked)) || ((RepType == rep_type.SPEED) && (ckComputeAddress.Checked)) || ((RepType == rep_type.TELEMETRY_ALARM) && (ckComputeAddress.Checked)) || ((RepType == rep_type.TELEMETRY_EVENT) && (ckComputeAddress.Checked)) || ((RepType == rep_type.SMS_LOCATION) && (ckComputeAddress.Checked)))
{
ckComputeAddress.Visible = false;
rlComputing.Visible = true;
rProgressBar.Visible = true;
ckReportDaily.Visible = false;
rtbEmail.Visible = false;
//btPrintReport.Enabled = false;
}
backDB.RunWorkerAsync();
ButtonStatusCancel = true;
btPrintReport.Text = MainForm2.returnLNGString("canReport");
}
else
{
DialogResult dr;
if ((MainForm2.radioType == RADIOTYPE.HARRIS) || (MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
dr = RadMessageBox.Show(this, MainForm2.returnLNGString("qReport"), MainForm2.returnLNGString("confirm"), MessageBoxButtons.YesNo, RadMessageIcon.Question);
if (dr == DialogResult.Yes)
{
backDB.CancelAsync();
ButtonStatusCancel = false;
btPrintReport.Text = MainForm2.returnLNGString("btShowReport");
}
}
}
catch (Exception ex)
{
SM.Debug("Error on search reports : " + ex.ToString());
if ((MainForm2.radioType == RADIOTYPE.HARRIS) || (MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
RadMessageBox.Show(MainForm2.returnLNGString("database"), MainForm2.returnLNGString("war"), MessageBoxButtons.OK, RadMessageIcon.Exclamation);
}
}
private Boolean CheckLimit()
{
Boolean Valid = true;
if (((RepType == rep_type.ENDOFDAY) || (RepType == rep_type.STOP) || (RepType == rep_type.IDLE)) && (convDT.GetSecondsFromDT(rdtFrom.Value) > convDT.GetSecondsFromDT(rdtUntil.Value)))
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS) || (MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
RadMessageBox.Show(msgLimit);
Valid = false;
}
if (RepType == rep_type.IDLE)
{
try
{
Int32 n = Convert.ToInt32(rseIdle.Value.ToString());
MainForm2.IDLETime = n;
}
catch (Exception ex)
{
SM.Debug("Ex:" + ex.ToString());
if ((MainForm2.radioType == RADIOTYPE.HARRIS) || (MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
RadMessageBox.Show(msgInteger);
Valid = false;
}
}
if (RepType == rep_type.FLEET)
{
Boolean somechecked = false;
for (Int32 i = 0; i < rcbUnitFleet.Items.Count; i++)
if (((CustomListDataItem)rcbUnitFleet.Items[i]).Checked) { somechecked = true; break; }
if (!somechecked)
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS) || (MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
RadMessageBox.Show(msgMustSel);
Valid = false;
}
}
return Valid;
}
private void CheckValue()
{
glwhere = "";
if (this.ckUnitGroupFilter.Checked)
{
/*
if (glwhere != "") glwhere = glwhere + " and ";
else glwhere = " where ";
if (RepType == rep_type.LOG) glwhere = glwhere + " imei = '" + (((RadListDataItem)rcbUnitGroup.Items[rcbUnitGroup.SelectedIndex]).Value as VehandID).Imei + "' ";
else if (RepType == rep_type.SMS_LOCATION) glwhere = glwhere + " sc_id_sour = " + (((RadListDataItem)rcbUnitGroup.Items[rcbUnitGroup.SelectedIndex]).Value as VehandID).sc_id;
else glwhere = glwhere + " sc_id = " + (((RadListDataItem)rcbUnitGroup.Items[rcbUnitGroup.SelectedIndex]).Value as VehandID).sc_id;
*/
if (glwhere != "") glwhere = glwhere + " and ";
else glwhere = " where ";
if (RepType == rep_type.LOG) glwhere = glwhere + " imei IN (" + UnitGroupItems[rcbUnitGroup.SelectedIndex].ValueImei + ") ";
else if (RepType == rep_type.SMS_LOCATION) glwhere = glwhere + " sc_id_sour IN (" + UnitGroupItems[rcbUnitGroup.SelectedIndex].ValueScID + ") ";
else glwhere = glwhere + " sc_id IN (" + UnitGroupItems[rcbUnitGroup.SelectedIndex].ValueScID + ") ";
}
if (this.ckStatus.Checked)
{
if (glwhere != "") glwhere = glwhere + " and ";
else glwhere = " where ";
if (rcbStatus.SelectedIndex < 2)
glwhere = glwhere + " status = " + rcbStatus.SelectedIndex;
else glwhere = glwhere + " status = " + (rcbStatus.SelectedIndex + 7);
}
if (this.ckGeofenceType.Checked)
{
if (glwhere != "") glwhere = glwhere + " and ";
else glwhere = " where ";
glwhere = glwhere + " action = " + (rcbGeoLandType.SelectedIndex + 1);
}
if (this.ckGeofenceName.Checked)
{
if (glwhere != "") glwhere = glwhere + " and ";
else glwhere = " where ";
if (rcbGeoLandName.Items.Count > 0) glwhere = glwhere + " zone_id = " + (((RadListDataItem)rcbGeoLandName.Items[rcbGeoLandName.SelectedIndex]).Value as VehandID).sc_id;
else glwhere = glwhere + " zone_id != -1";
}
if (ckDataFilter.Checked)
{
if (glwhere != "") glwhere = glwhere + " and ";
else glwhere = " where ";
glwhere = glwhere + " timeGMT >= " + convDT.ConvertLocalToGMT(convDT.GetSecondsFromDT(rdtFrom.Value)) + " and timeGMT <= " + convDT.ConvertLocalToGMT(convDT.GetSecondsFromDT(rdtUntil.Value));
}
if (ckCoordinates.Checked)
{
//// TODO see what needs to be changed here in order for the LAT LNG to be displayed
}
if (RepType == rep_type.SMS_LOCATION)
{
if (glwhere != "") glwhere = glwhere + " and ";
else glwhere = " where ";
glwhere = glwhere + " sc_id_sour>0";
}
}
private String unit_ids = "";
private Int32 startdate = 0;
private Int32 stopdate = 0;
private Int32 geo_id = 0;
private Int32 type = 0;
private Int32 idle_time = 0;
private Int32 reportid = 0;
private Boolean LatLng = false;
private void CheckValueReporteSaving()
{
unit_ids = "";
startdate = 0;
stopdate = 0;
geo_id = 0;
type = 0;
idle_time = 0;
reportid = 0;
LatLng = false;
if (this.ckUnitGroupFilter.Checked)
{
if (RepType == rep_type.LOG) unit_ids = UnitGroupItems[rcbUnitGroup.SelectedIndex].ValueImei;
else unit_ids = UnitGroupItems[rcbUnitGroup.SelectedIndex].ValueScID;
}
if ((ckSelectALL.Checked) && (RepType == rep_type.HIST)) type = 1;
else type = 0;
if ((ckSelectALL.Checked) && ((RepType == rep_type.HIST) || (RepType == rep_type.ALLALARM) || (RepType == rep_type.EMERG) || (RepType == rep_type.SPEED) || (RepType == rep_type.TELEMETRY_ALARM) || (RepType == rep_type.TELEMETRY_EVENT) || (RepType == rep_type.ENDOFDAY) || (RepType == rep_type.IDLE) || (RepType == rep_type.STOP))) LatLng = true;
if (this.ckStatus.Checked)
{
if (RepType == rep_type.LOG) type = rcbStatus.SelectedIndex + 1;
else
{
if (rcbStatus.Items.Count > 0) geo_id = Int16.Parse(UnitGroupItems[rcbUnitGroup.SelectedIndex].ValueScID);
else geo_id = 0;
}
}
if (this.ckGeofenceType.Checked)
{
if ((RepType == rep_type.LAND) || (RepType == rep_type.GEOFENC)) type = rcbGeoLandType.SelectedIndex + 1;
}
if (ckDataFilter.Checked)
{
startdate = convDT.ConvertLocalToGMT(convDT.GetSecondsFromDT(rdtFrom.Value));
stopdate = convDT.ConvertLocalToGMT(convDT.GetSecondsFromDT(rdtUntil.Value));
}
if ((RepType == rep_type.ENDOFDAY) || (RepType == rep_type.IDLE) || (RepType == rep_type.STOP) || (RepType == rep_type.FLEET))
{
startdate = convDT.ConvertLocalToGMT(convDT.GetSecondsFromDT(rdtFrom.Value));
stopdate = convDT.ConvertLocalToGMT(convDT.GetSecondsFromDT(rdtUntil.Value));
}
if ((RepType == rep_type.ENDOFDAY) || (RepType == rep_type.IDLE) || (RepType == rep_type.STOP))
{
unit_ids = UnitGroupItems[rcbUnitGroup.SelectedIndex].ValueScID;
}
if (RepType == rep_type.FLEET)
{
unit_ids = "";
if (ckSelectALL.Checked) idle_time = 1;
else idle_time = 0;
foreach (FleetIdandPos obj in MainForm2.FleetPosList)
{
unit_ids += ((Vehicle)MainForm2.vehicleHT[obj.Name]).sc_id.ToString() + ',';
}
}
if (RepType == rep_type.IDLE)
{
try
{
idle_time = Convert.ToInt32(rseIdle.Value.ToString());
}
catch (Exception ex)
{
SM.Debug("Idle time conversion fail so i set 5. Error:" + ex.ToString());
idle_time = 5;
}
}
reportid = (Int32)RepType;
}
private void ckDataFilter_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (ckDataFilter.Checked)
{
rdtFrom.Enabled = true;
rdtUntil.Enabled = true;
}
else
{
rdtFrom.Enabled = false;
rdtUntil.Enabled = false;
}
}
private void chStatus_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (this.ckStatus.Checked) this.rcbStatus.Enabled = true;
else this.rcbStatus.Enabled = false;
}
private void chVehName_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (this.ckUnitGroupFilter.Checked) this.rcbUnitGroup.Enabled = true;
else this.rcbUnitGroup.Enabled = false;
}
private void backDB_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
e.Result = ComputeDB(worker, e);
}
long ComputeDB(BackgroundWorker worker, DoWorkEventArgs e)
{
try
{
MainForm2.LATLNGforDinamicReports = false;
ValidReport = true;
if ((RepType != rep_type.ENDOFDAY) && (RepType != rep_type.STOP) && (RepType != rep_type.IDLE) && (RepType != rep_type.FLEET))
{
CheckValue();
switch (RepType)
{
case rep_type.LOG:
smdbObj.get_log_view_all(glwhere);
break;
case rep_type.EMERG:
smdbObj.get_EMERG(glwhere);
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), MainForm2.ONOFFList.Count + (Int32)Math.Round(MainForm2.ONOFFList.Count * 0.25));
foreach (ONOFFData obj in MainForm2.ONOFFList)
{
if (!ckCoordinates.Checked)
{
Boolean updateDB = false;
if ((obj.Status == "") || (obj.Status == " "))
{
try
{
Int32 step = ((Vehicle)MainForm2.vehicleHT[(String)MainForm2.VehIDHash[obj.sc_id]]).gps_interval;
if (step * 2 < 120) step = 120;
else step = step * 2;
//gethistory
SMposition neartheTime = null;
ArrayList tmp = smdbObj.get_HistoryTelem(obj.sc_id, obj.timeGMT - step, obj.timeGMT + step);
if (tmp.Count > 0)
{
foreach (SMposition obj2 in tmp)
{
if (neartheTime == null) neartheTime = obj2;
else if (Math.Abs(neartheTime.m_time - obj.timeGMT) > Math.Abs(obj2.m_time - obj.timeGMT)) neartheTime = obj2;
}
if ((neartheTime.m_address == "") || (neartheTime.m_address == " "))
{
if (ckComputeAddress.Checked)
{
MainForm2.AddrCnt++;
MainForm2.AddrGISQueue.Enqueue(new AddrAndID(MainForm2.AddrCnt, neartheTime.m_lat, neartheTime.m_lng));
MainForm2.IdReportHS.Add(MainForm2.AddrCnt.ToString(), "no address");
String Idtofind = MainForm2.AddrCnt.ToString();
Boolean retrynew = true;
Int32 cntmax = 0;
while (retrynew)
{
cntmax++;
retrynew = false;
if ((String)MainForm2.IdReportHS[Idtofind] == "no address")
{
System.Threading.Thread.Sleep(200);
SM.Debug("wait 200msec for address");
retrynew = true;
}
else obj.Status = (String)MainForm2.IdReportHS[Idtofind];
if (cntmax > 10) retrynew = false;
}
}
else obj.Status = "";
if ((obj.Status == "") || (obj.Status == " "))
obj.Status = "LAT:" + Math.Round(neartheTime.m_lat, 5).ToString() + " , LNG:" + Math.Round(neartheTime.m_lng, 5).ToString();
else updateDB = true;
}
else
{
obj.Status = neartheTime.m_address;
updateDB = true;
}
}
else obj.Status = "N/A";
//update datebase telemetry
if (updateDB) smdbObj.Update_address_emergency(obj.sc_id, obj.timeGMT, obj.Status.Replace(',', ' '), neartheTime.m_lat, neartheTime.m_lng);
}
catch (Exception ex)
{
SM.Debug("Error on update telemetry address:" + ex.ToString());
}
}
}
else
{
if (((Int32)Math.Round(obj.lat) == 0) && ((Int32)Math.Round(obj.lng) == 0))
{
Int32 step = ((Vehicle)MainForm2.vehicleHT[(String)MainForm2.VehIDHash[obj.sc_id]]).gps_interval;
if (step * 2 < 120) step = 120;
else step = step * 2;
//gethistory
SMposition neartheTime = null;
ArrayList tmp = smdbObj.get_HistoryTelem(obj.sc_id, obj.timeGMT - step, obj.timeGMT + step);
if (tmp.Count > 0)
{
foreach (SMposition obj2 in tmp)
{
if (neartheTime == null) neartheTime = obj2;
else if (Math.Abs(neartheTime.m_time - obj.timeGMT) > Math.Abs(obj2.m_time - obj.timeGMT)) neartheTime = obj2;
}
obj.Status = "LAT:" + Math.Round(neartheTime.m_lat, 5).ToString() + " , LNG:" + Math.Round(neartheTime.m_lng, 5).ToString();
smdbObj.Update_address_emergency(obj.sc_id, obj.timeGMT, obj.Status.Replace(',', ' '), neartheTime.m_lat, neartheTime.m_lng);
}
}
else obj.Status = "LAT:" + Math.Round(obj.lat, 5).ToString() + " , LNG:" + Math.Round(obj.lng, 5).ToString();
}
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), -1);
}
break;
case rep_type.HIST:
IdReportHS.Clear();
smdbObj.get_History(glwhere, ckComputeAddress.Checked, ckCoordinates.Checked);
if (ckComputeAddress.Checked)
{
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), IdReportHS.Keys.Count + (Int32)Math.Round(IdReportHS.Keys.Count * 0.25));
GisAddressWorker.RunWorkerAsync();
retrynew = true;
inwhile = false;
int cntmax = 0;
if (IdReportHS.Keys.Count > 0)
{
Int32 contNR = IdReportHS.Keys.Count;
if (cntmax >= contNR)
{
retrynew = false;
inwhile = false;
}
while (retrynew)
{
inwhile = true;
Thread.Sleep(1000);
SM.Debug("Wait 1 second to update");
cntmax++;
if (cntmax > contNR) retrynew = false;
}
if (GisAddressWorker.IsBusy) GisAddressWorker.CancelAsync();
}
try
{
foreach (StopData obj3 in MainForm2.HistDataReport)
{
if (IdReportHS[obj3.Location] != null)
{
obj3.Location = (String)IdReportHS[obj3.Location];
if (obj3.Location != "no address") smdbObj.Update_address_hist(obj3.Location, obj3.unique_id, obj3.Location);
}
}
}
catch (Exception ex)
{
SM.Debug("Exception on add address data in DB:" + ex.ToString());
}
}
//MainForm2.HistDataReport = new List<StopData>();
//MainForm2.HistDataReport.Add(tmp);
break;
case rep_type.ALLALARM:
smdbObj.get_ALLAlarm(glwhere);
break;
case rep_type.GEOFENC:
case rep_type.LAND:
smdbObj.get_LANDANDZONE(glwhere, RepType);
break;
case rep_type.TELEMETRY_EVENT:
case rep_type.TELEMETRY_ALARM:
if (glwhere != "") glwhere = glwhere + " and ";
else glwhere = " where ";
if (RepType == rep_type.TELEMETRY_ALARM) glwhere = glwhere + " alarm =1 ";
else glwhere = glwhere + " alarm =0 ";
smdbObj.get_TelemHist_alarm_event(glwhere);
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), MainForm2.SpeedingList.Count + (Int32)Math.Round(MainForm2.SpeedingList.Count * 0.25));
foreach (SpeedData obj in MainForm2.SpeedingList)
{
if (!ckCoordinates.Checked)
{
Boolean updateDB = false;
if ((obj.Address == "") || (obj.Address == " "))
{
try
{
Int32 step = ((Vehicle)MainForm2.vehicleHT[(String)MainForm2.VehIDHash[obj.sc_id]]).gps_interval;
if (step * 2 < 120) step = 120;
else step = step * 2;
//gethistory
SMposition neartheTime = null;
ArrayList tmp = smdbObj.get_HistoryTelem(obj.sc_id, obj.timeGMT - step, obj.timeGMT + step);
if (tmp.Count > 0)
{
foreach (SMposition obj2 in tmp)
{
if (neartheTime == null) neartheTime = obj2;
else if (Math.Abs(neartheTime.m_time - obj.timeGMT) > Math.Abs(obj2.m_time - obj.timeGMT)) neartheTime = obj2;
}
if ((neartheTime.m_address == "") || (neartheTime.m_address == " "))
{
if (ckComputeAddress.Checked)
{
MainForm2.AddrCnt++;
MainForm2.AddrGISQueue.Enqueue(new AddrAndID(MainForm2.AddrCnt, neartheTime.m_lat, neartheTime.m_lng));
MainForm2.IdReportHS.Add(MainForm2.AddrCnt.ToString(), "no address");
String Idtofind = MainForm2.AddrCnt.ToString();
Boolean retrynew = true;
Int32 cntmax = 0;
while (retrynew)
{
cntmax++;
retrynew = false;
if ((String)MainForm2.IdReportHS[Idtofind] == "no address")
{
System.Threading.Thread.Sleep(200);
SM.Debug("wait 200msec for address");
retrynew = true;
}
else obj.Address = (String)MainForm2.IdReportHS[Idtofind];
if (cntmax > 10) retrynew = false;
}
}
else obj.Address = "";
if ((obj.Address == "") || (obj.Address == " "))
obj.Address = "LAT:" + Math.Round(neartheTime.m_lat, 5).ToString() + " , LNG:" + Math.Round(neartheTime.m_lng, 5).ToString();
else updateDB = true;
}
else
{
obj.Address = neartheTime.m_address;
updateDB = true;
}
}
else obj.Address = "N/A";
//update datebase telemetry
if (updateDB) smdbObj.Update_address_telem(obj.sc_id, obj.timeGMT, obj.Address.Replace(',', ' '), neartheTime.m_lat, neartheTime.m_lng);
}
catch (Exception ex)
{
SM.Debug("Error on update telemetry address:" + ex.ToString());
}
}
}
else
{
if (((Int32)Math.Round(obj.lat) == 0) && ((Int32)Math.Round(obj.lng) == 0))
{
Int32 step = ((Vehicle)MainForm2.vehicleHT[(String)MainForm2.VehIDHash[obj.sc_id]]).gps_interval;
if (step * 2 < 120) step = 120;
else step = step * 2;
//gethistory
SMposition neartheTime = null;
ArrayList tmp = smdbObj.get_HistoryTelem(obj.sc_id, obj.timeGMT - step, obj.timeGMT + step);
if (tmp.Count > 0)
{
foreach (SMposition obj2 in tmp)
{
if (neartheTime == null) neartheTime = obj2;
else if (Math.Abs(neartheTime.m_time - obj.timeGMT) > Math.Abs(obj2.m_time - obj.timeGMT)) neartheTime = obj2;
}
obj.Address = "LAT:" + Math.Round(neartheTime.m_lat, 5).ToString() + " , LNG:" + Math.Round(neartheTime.m_lng, 5).ToString();
smdbObj.Update_address_telem(obj.sc_id, obj.timeGMT, obj.Address.Replace(',', ' '), neartheTime.m_lat, neartheTime.m_lng);
}
}
else obj.Address = "LAT:" + Math.Round(obj.lat, 5).ToString() + " , LNG:" + Math.Round(obj.lng, 5).ToString();
}
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), -1);
}
break;
case rep_type.SPEED:
smdbObj.get_Speeding(glwhere);
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), MainForm2.SpeedingList.Count + (Int32)Math.Round(MainForm2.SpeedingList.Count * 0.25));
Console.WriteLine("############################################################################");
foreach (SpeedData obj in MainForm2.SpeedingList)
{
if (!ckCoordinates.Checked)
{
Boolean updateDB = false;
if (obj.Address == "no address")
{
try
{
if (ckComputeAddress.Checked)
{
MainForm2.AddrCnt++;
MainForm2.AddrGISQueue.Enqueue(new AddrAndID(MainForm2.AddrCnt, obj.lat, obj.lng));
MainForm2.IdReportHS.Add(MainForm2.AddrCnt.ToString(), "no address");
String Idtofind = MainForm2.AddrCnt.ToString();
Boolean retrynew = true;
Int32 cntmax = 0;
while (retrynew)
{
cntmax++;
retrynew = false;
if ((String)MainForm2.IdReportHS[Idtofind] == "no address")
{
System.Threading.Thread.Sleep(200);
SM.Debug("Wait 200msec");
retrynew = true;
}
else obj.Address = (String)MainForm2.IdReportHS[Idtofind];
if (cntmax > 10) retrynew = false;
}
}
else obj.Address = "";
if ((obj.Address == "") || (obj.Address == " "))
obj.Address = "LAT:" + Math.Round(obj.lat, 5).ToString() + " , LNG:" + Math.Round(obj.lng, 5).ToString();
else updateDB = true;
if (updateDB) smdbObj.Update_address_speed(obj.sc_id, obj.timeGMT, obj.Address.Replace(',', ' '), obj.lat, obj.lng);
}
catch (Exception ex)
{
SM.Debug("Error on update speed address:" + ex.ToString());
}
}
}
else
{
if (((Int32)Math.Round(obj.lat) == 0) && ((Int32)Math.Round(obj.lng) == 0))
{
Int32 step = ((Vehicle)MainForm2.vehicleHT[(String)MainForm2.VehIDHash[obj.sc_id]]).gps_interval;
if (step * 2 < 120) step = 120;
else step = step * 2;
//gethistory
SMposition neartheTime = null;
ArrayList tmp = smdbObj.get_HistoryTelem(obj.sc_id, obj.timeGMT - step, obj.timeGMT + step);
if (tmp.Count > 0)
{
foreach (SMposition obj2 in tmp)
{
if (neartheTime == null) neartheTime = obj2;
else if (Math.Abs(neartheTime.m_time - obj.timeGMT) > Math.Abs(obj2.m_time - obj.timeGMT)) neartheTime = obj2;
}
obj.Address = "LAT:" + Math.Round(neartheTime.m_lat, 5).ToString() + " , LNG:" + Math.Round(neartheTime.m_lng, 5).ToString();
smdbObj.Update_address_speed(obj.sc_id, obj.timeGMT, obj.Address.Replace(',', ' '), neartheTime.m_lat, neartheTime.m_lng);
}
}
else obj.Address = "LAT:" + Math.Round(obj.lat, 5).ToString() + " , LNG:" + Math.Round(obj.lng, 5).ToString();
}
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), -1);
}
break;
case rep_type.SMS_LOCATION:
smdbObj.get_SMS_Location(glwhere);
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), MainForm2.SMSLocList.Count + (Int32)Math.Round(MainForm2.SMSLocList.Count * 0.25));
foreach (SMS_Location obj in MainForm2.SMSLocList)
{
if (!ckCoordinates.Checked)
{
Boolean updateDB = false;
if (obj.Address == "no address")
{
try
{
Int32 step = ((Vehicle)MainForm2.vehicleHT[(String)MainForm2.VehIDHash[obj.sc_id]]).gps_interval;
if (step * 2 < 120) step = 120;
else step = step * 2;
//gethistory
SMposition neartheTime = null;
ArrayList tmp = smdbObj.get_HistorySpeed(obj.sc_id, obj.timeGMT - step, obj.timeGMT + step, obj.timeGMT);
if (tmp.Count > 0)
{
foreach (SMposition obj2 in tmp)
{
if (neartheTime == null) neartheTime = obj2;
else if (Math.Abs(neartheTime.m_time - obj.timeGMT) > Math.Abs(obj2.m_time - obj.timeGMT)) neartheTime = obj2;
}
if ((neartheTime.m_address == "") || (neartheTime.m_address == " "))
{
if (ckComputeAddress.Checked)
{
MainForm2.AddrCnt++;
MainForm2.AddrGISQueue.Enqueue(new AddrAndID(MainForm2.AddrCnt, neartheTime.m_lat, neartheTime.m_lng));
MainForm2.IdReportHS.Add(MainForm2.AddrCnt.ToString(), "no address");
String Idtofind = MainForm2.AddrCnt.ToString();
Boolean retrynew = true;
Int32 cntmax = 0;
while (retrynew)
{
cntmax++;
retrynew = false;
if ((String)MainForm2.IdReportHS[Idtofind] == "no address")
{
System.Threading.Thread.Sleep(200);
SM.Debug("Wait 200msec");
retrynew = true;
}
else obj.Address = (String)MainForm2.IdReportHS[Idtofind];
if (cntmax > 10) retrynew = false;
}
}
else obj.Address = "";
if ((obj.Address == "") || (obj.Address == " "))
obj.Address = "LAT:" + Math.Round(neartheTime.m_lat, 5).ToString() + " , LNG:" + Math.Round(neartheTime.m_lng, 5).ToString();
else updateDB = true;
}
else
{
obj.Address = neartheTime.m_address;
updateDB = true;
}
}
else obj.Address = "N/A";
//update datebase Speed
if (updateDB) smdbObj.Update_address_SMS_Location(obj.sc_id, obj.timeGMT, obj.Address.Replace(',', ' '), neartheTime.m_lat, neartheTime.m_lng);
}
catch (Exception ex)
{
SM.Debug("Error on update telemetry address:" + ex.ToString());
}
}
}
else
{
if (((Int32)Math.Round(obj.lat) == 0) && ((Int32)Math.Round(obj.lng) == 0))
{
Int32 step = ((Vehicle)MainForm2.vehicleHT[(String)MainForm2.VehIDHash[obj.sc_id]]).gps_interval;
if (step * 2 < 120) step = 120;
else step = step * 2;
//gethistory
SMposition neartheTime = null;
ArrayList tmp = smdbObj.get_HistoryTelem(obj.sc_id, obj.timeGMT - step, obj.timeGMT + step);
if (tmp.Count > 0)
{
foreach (SMposition obj2 in tmp)
{
if (neartheTime == null) neartheTime = obj2;
else if (Math.Abs(neartheTime.m_time - obj.timeGMT) > Math.Abs(obj2.m_time - obj.timeGMT)) neartheTime = obj2;
}
obj.Address = "LAT:" + Math.Round(neartheTime.m_lat, 5).ToString() + " , LNG:" + Math.Round(neartheTime.m_lng, 5).ToString();
smdbObj.Update_address_SMS_Location(obj.sc_id, obj.timeGMT, "no address", neartheTime.m_lat, neartheTime.m_lng);
}
}
else obj.Address = "LAT:" + Math.Round(obj.lat, 5).ToString() + " , LNG:" + Math.Round(obj.lng, 5).ToString();
}
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), -1);
}
break;
}
}
else
{
if (CheckLimit())
{
if ((RepType == rep_type.ENDOFDAY) || (RepType == rep_type.STOP) || (RepType == rep_type.IDLE))
{
//MainForm2.PositionList = smdbObj.get_position_for_report((Int32)(new ConvertDT().GetSecondsLocalFromDT(dtFrom.Value)) - dtFrom.Value.Hour * 3600 - dtFrom.Value.Minute * 60 - dtFrom.Value.Second, (Int32)(new ConvertDT().GetSecondsLocalFromDT(dtTo.Value)) - dtTo.Value.Hour * 3600 - dtTo.Value.Minute * 60 - dtTo.Value.Second + 86400, (((RadComboBoxItem)cbVehName.Items[cbVehName.SelectedIndex]).Value as VehandID).sc_id);
MainForm2.PositionList = smdbObj.get_position_for_report((Int32)(new ConvertDT().GetSecondsLocalFromDT(rdtFrom.Value)), (Int32)(new ConvertDT().GetSecondsLocalFromDT(rdtUntil.Value)), Int32.Parse(UnitGroupItems[rcbUnitGroup.SelectedIndex].ValueScID));
MainForm2.NameReport = UnitGroupItems[rcbUnitGroup.SelectedIndex].Text;
MainForm2.LATLNGforDinamicReports = ckSelectALL.Checked;
}
if (RepType == rep_type.FLEET)
{
foreach (FleetIdandPos obj in MainForm2.FleetPosList)
{
//obj.Position = smdbObj.get_position_for_report((Int32)(new ConvertDT().GetSecondsLocalFromDT(dtFrom.Value)) - dtFrom.Value.Hour * 3600 - dtFrom.Value.Minute * 60 - dtFrom.Value.Second, (Int32)(new ConvertDT().GetSecondsLocalFromDT(dtTo.Value)) - dtTo.Value.Hour * 3600 - dtTo.Value.Minute * 60 - dtTo.Value.Second + 86400, ((Vehicle)MainForm2.vehicleHT[obj.Name]).sc_id);
obj.Position = smdbObj.get_position_for_report((Int32)(new ConvertDT().GetSecondsLocalFromDT(rdtFrom.Value)), (Int32)(new ConvertDT().GetSecondsLocalFromDT(rdtUntil.Value)), ((Vehicle)MainForm2.vehicleHT[obj.Name]).sc_id);
SM.Debug(obj.Name + " " + obj.Position.Count);
}
}
}
else
{
SM.Debug("Not valid Report");
ValidReport = false;
}
}
}
catch (Exception ex)
{
SM.Debug("Error compute date from DB:" + ex.ToString());
}
return 1;
}
private void backDB_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
switch (RepType)
{
case rep_type.LOG:
ONOFFReport tmp = new ONOFFReport();
tmp.timeCaptionTextBox.Value = MainForm2.returnLNGString("SMSMessTime");
switch (MainForm2.radioType)
{
case RADIOTYPE.CONECTPLUS:
case RADIOTYPE.REPEATER_TRBO:
case RADIOTYPE.MOTO:
tmp.titleTextBox.Value = MainForm2.returnLNGString("SMSlogradio");
break;
case RADIOTYPE.HYT:
tmp.titleTextBox.Value = MainForm2.returnLNGString("SMSlogradioHYT");
break;
case RADIOTYPE.HARRIS:
tmp.titleTextBox.Value = MainForm2.returnLNGString("SMSlogradioHARRIS");
break;
case RADIOTYPE.ATLAS:
tmp.titleTextBox.Value = MainForm2.returnLNGString("SMSlogradioAstro");
break;
case RADIOTYPE.TETRA:
tmp.titleTextBox.Value = MainForm2.returnLNGString("SMSlogradioTetra");
break;
}
tmp.statusCaptionTextBox.Value = MainForm2.returnLNGString("SMSStatus");
tmp.nameCaptionTextBox.Value = MainForm2.returnLNGString("htableVehiclesListColumns1");
reportViewer1.ReportSource = tmp;
break;
case rep_type.SPEED:
rlComputing.Visible = false;
rProgressBar.Visible = false;
ckReportDaily.Visible = true;
rtbEmail.Visible = true;
ckComputeAddress.Visible = true;
SpeedingReport tmpSpeed = new SpeedingReport();
tmpSpeed.nameCaptionTextBox.Value = MainForm2.returnLNGString("htableVehiclesListColumns1");
if (MainForm2.isInMile) tmpSpeed.speedCaptionTextBox.Value = MainForm2.returnLNGString("tablevehiclesListColumns3") + " (" + MainForm2.milesh + ")";
else tmpSpeed.speedCaptionTextBox.Value = MainForm2.returnLNGString("tablevehiclesListColumns3") + " (" + MainForm2.kmh + ")";
tmpSpeed.timeCaptionTextBox.Value = MainForm2.returnLNGString("alarmsListColumns1");
tmpSpeed.titleTextBox.Value = MainForm2.returnLNGString("speedalarm");
tmpSpeed.dataCaptionTextBox.Value = MainForm2.returnLNGString("rapday");
tmpSpeed.addressCaptionTextBox.Value = MainForm2.returnLNGString("addrOrLatLng");
tmpSpeed.txObeserv.Value = MainForm2.returnLNGString("obsSpeed");
reportViewer1.ReportSource = tmpSpeed;
if (MainForm2.SpeedingList.Count > 40000)
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS) || (MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
DialogResult dr = RadMessageBox.Show(this, MainForm2.returnLNGString("limit65000"), MainForm2.returnLNGString("info"), MessageBoxButtons.OK, RadMessageIcon.Info);
}
break;
case rep_type.TELEMETRY_EVENT:
case rep_type.TELEMETRY_ALARM:
rlComputing.Visible = false;
rProgressBar.Visible = false;
ckReportDaily.Visible = true;
rtbEmail.Visible = true;
ckComputeAddress.Visible = true;
SpeedingReport tmpTelem = new SpeedingReport();
tmpTelem.nameCaptionTextBox.Value = MainForm2.returnLNGString("htableVehiclesListColumns1");
tmpTelem.timeCaptionTextBox.Value = MainForm2.returnLNGString("alarmsListColumns1");
if (RepType == rep_type.TELEMETRY_ALARM)
{
tmpTelem.titleTextBox.Value = MainForm2.returnLNGString("telemreport");
tmpTelem.speedCaptionTextBox.Value = MainForm2.returnLNGString("alarmtype");
}
else
{
tmpTelem.titleTextBox.Value = MainForm2.returnLNGString("telemevent");
tmpTelem.speedCaptionTextBox.Value = MainForm2.returnLNGString("eventype");
}
tmpTelem.dataCaptionTextBox.Value = MainForm2.returnLNGString("rapday");
tmpTelem.addressCaptionTextBox.Value = MainForm2.returnLNGString("addrOrLatLng");
tmpTelem.txObeserv.Value = "";
reportViewer1.ReportSource = tmpTelem;
break;
case rep_type.GEOFENC:
ZoneReport tmpZone = new ZoneReport();
tmpZone.landNameCaptionTextBox.Value = MainForm2.returnLNGString("zonename");
tmpZone.landTypeCaptionTextBox.Value = MainForm2.returnLNGString("alarmtype");
tmpZone.nameCaptionTextBox.Value = MainForm2.returnLNGString("htableVehiclesListColumns1");
tmpZone.timeCaptionTextBox.Value = MainForm2.returnLNGString("alarmsListColumns1");
tmpZone.titleTextBox.Value = MainForm2.returnLNGString("InZoneReport");
reportViewer1.ReportSource = tmpZone;
break;
case rep_type.LAND:
ZoneReport tmpLand = new ZoneReport();
tmpLand.landNameCaptionTextBox.Value = MainForm2.returnLNGString("landmarkname");
tmpLand.landTypeCaptionTextBox.Value = MainForm2.returnLNGString("alarmtype");
tmpLand.nameCaptionTextBox.Value = MainForm2.returnLNGString("htableVehiclesListColumns1");
tmpLand.timeCaptionTextBox.Value = MainForm2.returnLNGString("alarmsListColumns1");
tmpLand.titleTextBox.Value = MainForm2.returnLNGString("landmarkrep");
reportViewer1.ReportSource = tmpLand;
break;
case rep_type.EMERG:
ONOFFReport tmpEmerg = new ONOFFReport();
tmpEmerg.timeCaptionTextBox.Value = MainForm2.returnLNGString("alarmsListColumns1");
tmpEmerg.titleTextBox.Value = MainForm2.returnLNGString("emergAlarmRep");
tmpEmerg.statusCaptionTextBox.Value = MainForm2.returnLNGString("addrOrLatLng");
tmpEmerg.nameCaptionTextBox.Value = MainForm2.returnLNGString("htableVehiclesListColumns1");
reportViewer1.ReportSource = tmpEmerg;
break;
case rep_type.HIST:
MainForm2.IsHistroyNotStop = true;
if (ckComputeAddress.Checked)
{
//btPrintReport.Enabled = true;
rlComputing.Visible = false;
rProgressBar.Visible = false;
ckReportDaily.Visible = true;
rtbEmail.Visible = true;
ckComputeAddress.Visible = true;
}
// check if unit report or group report
/*
*rlComputing.Visible = false;
rProgressBar.Visible = false;
ckReportDaily.Visible = true;
rtbEmail.Visible = true;
ckComputeAddress.Visible = true;
SpeedingReport tmpSpeed = new SpeedingReport();
tmpSpeed.nameCaptionTextBox.Value = MainForm2.returnLNGString("htableVehiclesListColumns1");
if (MainForm2.isInMile) tmpSpeed.speedCaptionTextBox.Value = MainForm2.returnLNGString("tablevehiclesListColumns3") + " (" + MainForm2.milesh + ")";
else tmpSpeed.speedCaptionTextBox.Value = MainForm2.returnLNGString("tablevehiclesListColumns3") + " (" + MainForm2.kmh + ")";
tmpSpeed.timeCaptionTextBox.Value = MainForm2.returnLNGString("alarmsListColumns1");
tmpSpeed.titleTextBox.Value = MainForm2.returnLNGString("speedalarm");
tmpSpeed.dataCaptionTextBox.Value = MainForm2.returnLNGString("rapday");
tmpSpeed.addressCaptionTextBox.Value = MainForm2.returnLNGString("addrOrLatLng");
tmpSpeed.txObeserv.Value = MainForm2.returnLNGString("obsSpeed");
reportViewer1.ReportSource = tmpSpeed;
*/
if (!UnitGroupItems[rcbUnitGroup.SelectedIndex].IsGroup)
{
/// SINGLE UNIT REPORT
StopReport tmpRep2 = new StopReport();
//tmpRep2.titleTextBox.Value = MainForm2.returnLNGString("namesandvehicleHistory") + " " + cbVehName.Text;
// set title
if (ckUnitGroupFilter.Checked) tmpRep2.titleTextBox.Value = MainForm2.returnLNGString("HistoryRep") + " " +
(UnitGroupItems[rcbUnitGroup.SelectedIndex].IsGroup ? MainForm2.returnLNGString("forGroup") : MainForm2.returnLNGString("forvehicle"))
+ " " + rcbUnitGroup.Text;
else tmpRep2.titleTextBox.Value = MainForm2.returnLNGString("HistoryRep");
// set address
tmpRep2.locationCaptionTextBox.Value = MainForm2.returnLNGString("addrOrLatLng");
// set speed
if (MainForm2.isInMile) tmpRep2.durationCaptionTextBox.Value = MainForm2.returnLNGString("tablevehiclesListColumns3") + " (" + MainForm2.milesh + ")";
else tmpRep2.durationCaptionTextBox.Value = MainForm2.returnLNGString("tablevehiclesListColumns3") + " (" + MainForm2.kmh + ")";
tmpRep2.timeCaptionTextBox.Value = MainForm2.returnLNGString("label3");
tmpRep2.dataCaptionTextBox.Value = MainForm2.returnLNGString("dateSTOP");
reportViewer1.ReportSource = tmpRep2;
}
else
{
MainForm2.SpeedingList = new List<SpeedData>();
Int32 countdata = 0;
foreach (StopData obj in MainForm2.HistDataReport)
{
SpeedData tmpSpeedData = new SpeedData();
tmpSpeedData.Name = obj.unit_name;
tmpSpeedData.Speed = obj.Duration;
tmpSpeedData.Time = obj.Time;
tmpSpeedData.Data = obj.Data;
tmpSpeedData.Address = obj.Location;
MainForm2.SpeedingList.Add(tmpSpeedData);
countdata++;
if (countdata > 50000) break;
}
Console.WriteLine("End of transfer DATA");
SpeedingReport tmpGroupHistoryReport = new SpeedingReport();
// set title
tmpGroupHistoryReport.titleTextBox.Value = MainForm2.returnLNGString("HistoryRep") + " " + MainForm2.returnLNGString("forGroup") + " " + rcbUnitGroup.Text;
// set address
tmpGroupHistoryReport.addressCaptionTextBox.Value = MainForm2.returnLNGString("addrOrLatLng");
// set speed
if (MainForm2.isInMile) tmpGroupHistoryReport.speedCaptionTextBox.Value = MainForm2.returnLNGString("tablevehiclesListColumns3") + " (" + MainForm2.milesh + ")";
else tmpGroupHistoryReport.speedCaptionTextBox.Value = MainForm2.returnLNGString("tablevehiclesListColumns3") + " (" + MainForm2.kmh + ")";
// set unit name
tmpGroupHistoryReport.nameCaptionTextBox.Value = MainForm2.returnLNGString("htableVehiclesListColumns1");
// set time
tmpGroupHistoryReport.timeCaptionTextBox.Value = MainForm2.returnLNGString("label3");
// set date
tmpGroupHistoryReport.dataCaptionTextBox.Value = MainForm2.returnLNGString("dateSTOP");
tmpGroupHistoryReport.txObeserv.Value = "";
//tmpGroupHistoryReport.txObeserv.Value = MainForm2.returnLNGString("obsSpeed");
reportViewer1.ReportSource = tmpGroupHistoryReport;
if (countdata > 50000)
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS) || (MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
DialogResult dr = RadMessageBox.Show(this, MainForm2.returnLNGString("limit65000"), MainForm2.returnLNGString("info"), MessageBoxButtons.OK, RadMessageIcon.Info);
}
}
break;
case rep_type.ALLALARM:
MainForm2.IsHistroyNotStop = true;
StopReport tmpRep3 = new StopReport();
if (ckUnitGroupFilter.Checked) tmpRep3.titleTextBox.Value = MainForm2.returnLNGString("allAlarmTitle") + " " +
(UnitGroupItems[rcbUnitGroup.SelectedIndex].IsGroup ? MainForm2.returnLNGString("forGroup") : MainForm2.returnLNGString("forvehicle"))
+ " " + rcbUnitGroup.Text;
else tmpRep3.titleTextBox.Value = MainForm2.returnLNGString("allAlarmTitle");
tmpRep3.timeCaptionTextBox.Value = MainForm2.returnLNGString("alarmtype");
tmpRep3.locationCaptionTextBox.Value = MainForm2.returnLNGString("SMSMessTime");
tmpRep3.durationCaptionTextBox.Value = MainForm2.returnLNGString("lbDescript");
tmpRep3.dataCaptionTextBox.Value = MainForm2.returnLNGString("htableVehiclesListColumns1");
reportViewer1.ReportSource = tmpRep3;
break;
case rep_type.ENDOFDAY:
if (ValidReport)
{
EndOfDay tmpEND = new EndOfDay();
tmpEND.distanceCaptionTextBox.Value = MainForm2.returnLNGString("namedistance");
tmpEND.startAddressCaptionTextBox.Value = MainForm2.returnLNGString("namestrlocTRAV");
tmpEND.stopAddressCaptionTextBox.Value = MainForm2.returnLNGString("namestoplocTRAV");
tmpEND.startTimeCaptionTextBox.Value = MainForm2.returnLNGString("namestrhourTRAV");
tmpEND.stopTimeCaptionTextBox.Value = MainForm2.returnLNGString("label3");
tmpEND.titleTextBox.Value = MainForm2.returnLNGString("nameandvehicleTRAV") + " " + rcbUnitGroup.Text;
tmpEND.tripCaptionTextBox.Value = MainForm2.returnLNGString("nameroad");
reportViewer1.ReportSource = tmpEND;
}
break;
case rep_type.STOP:
if (ValidReport)
{
MainForm2.IsHistroyNotStop = false;
MainForm2.IsIdle = false;
StopReport tmpRep = new StopReport();
tmpRep.titleTextBox.Value = MainForm2.returnLNGString("namesandvehicleSTOP") + " " + rcbUnitGroup.Text;
tmpRep.timeCaptionTextBox.Value = MainForm2.returnLNGString("label3");
tmpRep.locationCaptionTextBox.Value = MainForm2.returnLNGString("locationSTOP");
tmpRep.durationCaptionTextBox.Value = MainForm2.returnLNGString("waitingSTOP");
tmpRep.dataCaptionTextBox.Value = MainForm2.returnLNGString("dateSTOP");
reportViewer1.ReportSource = tmpRep;
}
break;
case rep_type.IDLE:
if (ValidReport)
{
MainForm2.IsHistroyNotStop = false;
MainForm2.IsIdle = true;
StopReport tmpIDLE = new StopReport();
tmpIDLE.titleTextBox.Value = MainForm2.returnLNGString("namesandvehicleSTOPENG") + " " + rcbUnitGroup.Text;
tmpIDLE.timeCaptionTextBox.Value = MainForm2.returnLNGString("label3");
tmpIDLE.locationCaptionTextBox.Value = MainForm2.returnLNGString("locationSTOP");
tmpIDLE.durationCaptionTextBox.Value = MainForm2.returnLNGString("waitingSTOP");
tmpIDLE.dataCaptionTextBox.Value = MainForm2.returnLNGString("dateSTOP");
reportViewer1.ReportSource = tmpIDLE;
}
break;
case rep_type.FLEET:
if (ValidReport)
{
MainForm2.IsSMSLocationNotFleet = false;
FleetReport tmpFleet = new FleetReport();
tmpFleet.distanceCaptionTextBox.Value = MainForm2.returnLNGString("namedistance");
tmpFleet.nameCaptionTextBox.Value = MainForm2.returnLNGString("htableVehiclesListColumns1");
tmpFleet.startCaptionTextBox.Value = MainForm2.returnLNGString("namefirst") + " " + MainForm2.returnLNGString("namerun");
tmpFleet.stopCaptionTextBox.Value = MainForm2.returnLNGString("namefirst") + " " + MainForm2.returnLNGString("namewait");
tmpFleet.titleTextBox.Value = MainForm2.returnLNGString("titleFLEET");
tmpFleet.tripsCaptionTextBox.Value = MainForm2.returnLNGString("nameroute");
reportViewer1.ReportSource = tmpFleet;
}
break;
case rep_type.SMS_LOCATION:
rlComputing.Visible = false;
rProgressBar.Visible = false;
if (ValidReport)
{
MainForm2.IsSMSLocationNotFleet = true;
FleetReport tmpSMSLoc = new FleetReport();
tmpSMSLoc.distanceCaptionTextBox.Value = MainForm2.returnLNGString("Message");
tmpSMSLoc.nameCaptionTextBox.Value = MainForm2.returnLNGString("htableVehiclesListColumns1");
tmpSMSLoc.startCaptionTextBox.Value = MainForm2.returnLNGString("rapday");
tmpSMSLoc.stopCaptionTextBox.Value = MainForm2.returnLNGString("addrOrLatLng");
tmpSMSLoc.tripsCaptionTextBox.Value = MainForm2.returnLNGString("alarmsListColumns1");
tmpSMSLoc.titleTextBox.Value = MainForm2.returnLNGString("messagewithlocation");
reportViewer1.ReportSource = tmpSMSLoc;
}
break;
}
reportViewer1.RefreshReport();
ButtonStatusCancel = false;
btPrintReport.Text = MainForm2.returnLNGString("btShowReport");
}
private void ckType_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (this.ckGeofenceType.Checked) this.rcbGeoLandType.Enabled = true;
else this.rcbGeoLandType.Enabled = false;
}
private void ckSelectALL_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (ckSelectALL.Checked)
{
for (Int32 i = 0; i < rcbUnitFleet.Items.Count; i++)
((CustomListDataItem)rcbUnitFleet.Items[i]).Checked = true;
//cbVehNameFleet.SelectedItems.Add(((CustomListDataItem)cbVehNameFleet.Items[i]));
}
else
{
for (Int32 i = 0; i < rcbUnitFleet.Items.Count; i++)
//((CustomListDataItem)cbVehNameFleet.Items[i]).IsChecked = false;
((CustomListDataItem)rcbUnitFleet.Items[i]).Checked = false;
}
}
private void ReportsControl_Load(object sender, EventArgs e)
{
/*
if ((RepType == rep_type.SPEED) || (RepType == rep_type.EMERG) || (RepType == rep_type.TELEMETRY_ALARM) || (RepType == rep_type.TELEMETRY_EVENT) || (RepType == rep_type.HIST) || (RepType == rep_type.ALLALARM) || (RepType == rep_type.LOG) || (RepType == rep_type.GEOFENC) || (RepType == rep_type.SMS_LOCATION))
{
chVehName.Location = new Point(cbVehName.Location.X -5 -chVehName.Size.Width, cbVehName.Location.Y);
lbFrom.Location = new Point(dtFrom.Location.X - 5 - lbFrom.Size.Width, dtFrom.Location.Y);
lbTo.Location = new Point(dtTo.Location.X - 5 - lbTo.Size.Width, dtTo.Location.Y);
ckDataFilter.Location = new Point(lbFrom.Location.X - 10 - ckDataFilter.Size.Width, lbFrom.Location.Y);
ckType.Location = new Point(cbType.Location.X - 5 - ckType.Size.Width, cbType.Location.Y);
chStatus.Location = new Point(cbStatus.Location.X - 5 - chStatus.Size.Width, cbStatus.Location.Y);
}
if (RepType == rep_type.HIST)
rlUnitGroup.Location = new Point(cbVehName.Location.X - 5 - rlUnitGroup.Size.Width, cbVehName.Location.Y);
if (RepType == rep_type.LOG)
chStatus.Location = new Point(cbStatus.Location.X - 10 - chStatus.Size.Width, cbStatus.Location.Y);
if ((RepType == rep_type.ENDOFDAY) || (RepType == rep_type.STOP) || (RepType == rep_type.IDLE))
{
lbFrom.Location = new Point(dtFrom.Location.X - 5 - lbFrom.Size.Width, dtFrom.Location.Y);
lbTo.Location = new Point(dtTo.Location.X - 5 - lbTo.Size.Width, dtTo.Location.Y);
rlUnitGroup.Location = new Point(cbVehName.Location.X - 5 - rlUnitGroup.Size.Width, cbVehName.Location.Y);
lbIdle.Location = new Point(txIdle.Location.X - 5 - lbIdle.Size.Width, txIdle.Location.Y);
}
if (RepType == rep_type.FLEET)
{
lbFrom.Location = new Point(dtFrom.Location.X - 5 - lbFrom.Size.Width, dtFrom.Location.Y);
lbTo.Location = new Point(dtTo.Location.X - 5 - lbTo.Size.Width, dtTo.Location.Y);
rlUnitGroup.Location = new Point(cbVehNameFleet.Location.X - 5 - rlUnitGroup.Size.Width, cbVehNameFleet.Location.Y);
}
if (RepType == rep_type.GEOFENC)
{
/* cbStatus.Items.Clear();
ZoneListNames.Sort(new VehandIDComparer());
cbStatus.DataSource = ZoneListNames;
cbStatus.DisplayMember = "Name";
if (cbStatus.Items.Count >= 1)
cbStatus.SelectedIndex = 0;
if (cbType.Items.Count >= 1)
cbType.SelectedIndex = 0;
cbVehName.Location = new Point(cbVehName.Location.X - 60, cbVehName.Location.Y);
chVehName.Location = new Point(chVehName.Location.X - 40, chVehName.Location.Y);
chStatus.Location = new Point(chStatus.Location.X - 80, chStatus.Location.Y);
cbStatus.Location = new Point(cbStatus.Location.X - 40, cbStatus.Location.Y);
cbStatus.Size = new Size(cbStatus.Size.Width - 30, cbStatus.Size.Height);
ckType.Location = new Point(ckType.Location.X + 200, ckType.Location.Y);
btPrintReport.Location = new Point(btPrintReport.Location.X + 80, btPrintReport.Location.Y);
chStatus.Text = MainForm2.returnLNGString("zonename");
ckType.Visible = true;
cbType.Visible = true;*/
//}
}
public static volatile Queue AddrGISQueue = new Queue();
private volatile Boolean findaddress;
private volatile AddrAndID tmpAddrAndID;
private Double valHash;
private volatile String AddrtmpX;
private volatile GoogleAddr2 volltmpGo = new GoogleAddr2();
private volatile Boolean retrynew;
private volatile Boolean inwhile = false;
private void GisAddressWorker_DoWork(object sender, DoWorkEventArgs e)
{
try
{
BackgroundWorker worker = sender as BackgroundWorker;
while (AddrGISQueue.Count > 0)
{
if ((worker.CancellationPending == true))
{
e.Cancel = true;
break;
}
tmpAddrAndID = (AddrAndID)AddrGISQueue.Dequeue();
findaddress = false;
try
{
tmpAddrAndID.LNG = Math.Round(tmpAddrAndID.LNG, 4);
tmpAddrAndID.LAT = Math.Round(tmpAddrAndID.LAT, 4);
valHash = tmpAddrAndID.LNG + tmpAddrAndID.LAT * 0.000001;
if (MainForm2.AddrHass[valHash] != null)
{
tmpAddrAndID.Address = (String)MainForm2.AddrHass[valHash];
findaddress = true;
}
else
{
AddrtmpX = smdbObj.get_address(tmpAddrAndID.LAT, tmpAddrAndID.LNG);
if (AddrtmpX != "")
{
MainForm2.AddrHass.Add(valHash, AddrtmpX);
tmpAddrAndID.Address = AddrtmpX;
findaddress = true;
}
}
}
catch
{
}
if (!findaddress)
{
tmpAddrAndID.Address = volltmpGo.getAddressLATLNG(tmpAddrAndID.LAT, tmpAddrAndID.LNG);
}
if ((tmpAddrAndID.Address != "") && (tmpAddrAndID.Address != " "))
{
if (!findaddress)
{
try
{
if (tmpAddrAndID.Address != "N/A")
{
valHash = tmpAddrAndID.LNG + tmpAddrAndID.LAT * 0.000001;
MainForm2.AddrHass.Add(valHash, tmpAddrAndID.Address);
AddrtmpX = smdbObj.get_address(tmpAddrAndID.LAT, tmpAddrAndID.LNG); //just for avoid Error from Event Viewer
if (AddrtmpX == "") smdbObj.Insert_Address(tmpAddrAndID.Address, tmpAddrAndID.LAT, tmpAddrAndID.LNG);
}
}
catch (Exception ex)
{
SM.Debug("Error: " + ex.ToString());
}
}
IdReportHS[tmpAddrAndID.ID.ToString()] = tmpAddrAndID.Address;
if (inwhile) rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), -1);
SM.Debug("Baga google in hash ID:" + tmpAddrAndID.ID.ToString() + "Addr:" + tmpAddrAndID.Address);
}
else
{
//dau in open street maps si apoi ies prin prin cene
Thread.Sleep(1100);
tmpAddrAndID.Address = volltmpGo.getAddressLATLNG2(tmpAddrAndID.LAT, tmpAddrAndID.LNG);
if ((tmpAddrAndID.Address != "") && (tmpAddrAndID.Address != " "))
{
if (!findaddress)
{
try
{
if (tmpAddrAndID.Address != "N/A")
{
valHash = tmpAddrAndID.LNG + tmpAddrAndID.LAT * 0.000001;
MainForm2.AddrHass.Add(valHash, tmpAddrAndID.Address);
AddrtmpX = smdbObj.get_address(tmpAddrAndID.LAT, tmpAddrAndID.LNG); //just for avoid Error from Event Viewer
if (AddrtmpX == "") smdbObj.Insert_Address(tmpAddrAndID.Address, tmpAddrAndID.LAT, tmpAddrAndID.LNG);
}
}
catch (Exception ex)
{
SM.Debug("Error: " + ex.ToString());
}
}
IdReportHS[tmpAddrAndID.ID.ToString()] = tmpAddrAndID.Address;
if (inwhile) rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), -1);
SM.Debug("Baga open street maps in hash ID:" + tmpAddrAndID.ID.ToString() + "Addr:" + tmpAddrAndID.Address);
}
else
{
SM.Debug("Iese prin Cene cu nimic");
}
}
}
}
catch (Exception ex)
{
SM.Debug("Error retrive address:" + ex.ToString());
}
Thread.Sleep(10);
}
private void GisAddressWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
retrynew = false;
}
private void UpdateProgressBar(Int32 max)
{
if (max == -1)
{
rProgressBar.ProgressBarElement.PerformStepValue1();
rProgressBar.Update();
}
else
{
rProgressBar.Maximum = max;
rProgressBar.Value1 = 0;
}
}
public delegate void UpdateProgressBarCallBack(Int32 max);
private void cbDaily_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (ckReportDaily.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
btSaveEmail.Enabled = true;
else btSaveEmail.Enabled = false;
}
private void btSaveEmail_Click(object sender, EventArgs e)
{
if (rtbEmail.Text.Contains('@') && rtbEmail.Text.Contains('.'))
{
SM.Debug("Valid email address");
if (rtbEmail.Text.IndexOf('@') != rtbEmail.Text.LastIndexOf('@'))
{
if (!rtbEmail.Text.Contains(';'))
{
SM.Debug("Be sure you split the email's");
RadMessageBox.Show(msgSplitEmail);
}
}
//write on database
//should check valid stuff also
CheckValueReporteSaving();
smdbObj.Insert_Report(startdate, stopdate, unit_ids, geo_id, type, idle_time, reportid, rtbEmail.Text, LatLng);
//save ok
ckReportDaily.ToggleState = Telerik.WinControls.Enumerations.ToggleState.Off;
RadMessageBox.Show(msgEmailSaved);
}
else
{
RadMessageBox.Show(msgInvalidEmail);
SM.Debug("Invalid email address");
}
}
/// <summary>
/// Handles the picture box click for simulating a checkbox and to
/// enable/disable other panels
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pbEnableDisable_Click(object sender, EventArgs e)
{
if ((PictureBox)sender == pbDateTime)
{
if (pbDateTime.Tag.Equals("disabled"))
{
pbDateTime.Tag = "enabled";
pbDateTime.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelDateTime.Enabled = true;
ckDataFilter.Checked = true;
}
else
{
pbDateTime.Tag = "disabled";
pbDateTime.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelDateTime.Enabled = false;
ckDataFilter.Checked = false;
}
}
else if ((PictureBox)sender == pbUnitGroup)
{
if (pbUnitGroup.Tag.Equals("disabled"))
{
pbUnitGroup.Tag = "enabled";
pbUnitGroup.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelUnitGroup.Enabled = true;
ckUnitGroupFilter.Checked = true;
}
else
{
pbUnitGroup.Tag = "disabled";
pbUnitGroup.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelUnitGroup.Enabled = false;
ckUnitGroupFilter.Checked = false;
}
}
else if ((PictureBox)sender == pbReportDaily)
{
if (pbReportDaily.Tag.Equals("disabled"))
{
pbReportDaily.Tag = "enabled";
pbReportDaily.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelReportDaily.Enabled = true;
ckReportDaily.Checked = true;
}
else
{
pbReportDaily.Tag = "disabled";
pbReportDaily.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelReportDaily.Enabled = false;
ckReportDaily.Checked = false;
}
}
else if ((PictureBox)sender == pbComputeAddress)
{
if (pbComputeAddress.Tag.Equals("disabled"))
{
pbComputeAddress.Tag = "enabled";
pbComputeAddress.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelComputeAddress.Enabled = true;
ckComputeAddress.Checked = true;
// disable coordinates for mutual exclusion
if (ckCoordinates.Checked)
pbEnableDisable_Click(pbCoordinates, null);
}
else
{
pbComputeAddress.Tag = "disabled";
pbComputeAddress.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelComputeAddress.Enabled = false;
ckComputeAddress.Checked = false;
}
}
else if ((PictureBox)sender == pbCoordinates)
{
if (pbCoordinates.Tag.Equals("disabled"))
{
pbCoordinates.Tag = "enabled";
pbCoordinates.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelLatLng.Enabled = true;
ckCoordinates.Checked = true;
// disable compute address for mutual exclusion
if (ckComputeAddress.Checked)
pbEnableDisable_Click(pbComputeAddress, null);
}
else
{
pbCoordinates.Tag = "disabled";
pbCoordinates.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelLatLng.Enabled = false;
ckCoordinates.Checked = false;
}
}
// enable or disable Geofence/Landmark Name
else if ((PictureBox)sender == pbGeofenceName)
{
if (pbGeofenceName.Tag.Equals("disabled"))
{
pbGeofenceName.Tag = "enabled";
pbGeofenceName.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelGeofenceName.Enabled = true;
ckGeofenceName.Checked = true;
}
else
{
pbGeofenceName.Tag = "disabled";
pbGeofenceName.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelGeofenceName.Enabled = false;
ckGeofenceName.Checked = false;
}
}
// enable or disable Geofence/Landmark Type
else if ((PictureBox)sender == pbGeofenceType)
{
if (pbGeofenceType.Tag.Equals("disabled"))
{
pbGeofenceType.Tag = "enabled";
pbGeofenceType.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelGeofenceType.Enabled = true;
ckGeofenceType.Checked = true;
}
else
{
pbGeofenceType.Tag = "disabled";
pbGeofenceType.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelGeofenceType.Enabled = false;
ckGeofenceType.Checked = false;
}
}
// enable or disable Status Panel
else if ((PictureBox)sender == pbStatus)
{
if (pbStatus.Tag.Equals("disabled"))
{
pbStatus.Tag = "enabled";
pbStatus.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelStatus.Enabled = true;
ckStatus.Checked = true;
}
else
{
pbStatus.Tag = "disabled";
pbStatus.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelStatus.Enabled = false;
ckStatus.Checked = false;
}
}
// enable or disable Status Panel
else if ((PictureBox)sender == pbSelectAll)
{
if (pbSelectAll.Tag.Equals("disabled"))
{
pbSelectAll.Tag = "enabled";
pbSelectAll.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelSelectAll.Enabled = true;
ckSelectALL.Checked = true;
}
else
{
pbSelectAll.Tag = "disabled";
pbSelectAll.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelSelectAll.Enabled = false;
ckSelectALL.Checked = false;
}
}
}
/// <summary>
/// Change the UI according to the report type
/// </summary>
/// <param name="reportType">Type of the report for which the UI will be displayed</param>
private void UpdateUIForReportType(rep_type reportType)
{
List<rep_type> addressPanelVisible = new List<rep_type>() { rep_type.SPEED, rep_type.HIST, rep_type.TELEMETRY_ALARM, rep_type.TELEMETRY_EVENT, rep_type.SMS_LOCATION };
List<rep_type> landmarkPanelVisible = new List<rep_type>() { rep_type.LAND, rep_type.GEOFENC };
List<rep_type> latLngPanelVisible = new List<rep_type>() { rep_type.SPEED, rep_type.EMERG, rep_type.HIST, rep_type.ENDOFDAY, rep_type.IDLE,
rep_type.STOP, rep_type.TELEMETRY_ALARM, rep_type.TELEMETRY_EVENT, rep_type.SMS_LOCATION };
List<rep_type> statusPanelVisible = new List<rep_type>() { rep_type.LOG };
List<rep_type> idlePanelVisible = new List<rep_type>() { rep_type.IDLE };
List<rep_type> selectAllPanelVisible = new List<rep_type>() { rep_type.FLEET };
List<rep_type> unitMandatory = new List<rep_type>() { rep_type.HIST, rep_type.ENDOFDAY, rep_type.IDLE, rep_type.STOP, rep_type.FLEET };
List<rep_type> dateMandatory = new List<rep_type>() { rep_type.ENDOFDAY, rep_type.IDLE, rep_type.STOP, rep_type.FLEET };
List<rep_type> progressBarSpace = new List<rep_type>() { rep_type.SPEED, rep_type.HIST, rep_type.TELEMETRY_ALARM, rep_type.TELEMETRY_EVENT };
// show hide pannels
if (addressPanelVisible.Contains(reportType))
{
pbComputeAddress.Visible = true;
radPanelComputeAddress.Visible = true;
}
else if (!addressPanelVisible.Contains(reportType))
{
pbComputeAddress.Visible = false;
radPanelComputeAddress.Visible = false;
}
// hide or show lat-lng panel
if (latLngPanelVisible.Contains(reportType))
{
pbCoordinates.Visible = true;
radPanelLatLng.Visible = true;
}
else if (!latLngPanelVisible.Contains(reportType))
{
pbCoordinates.Visible = false;
radPanelLatLng.Visible = false;
}
// hide or show Landmark/Geofence Panel
if (landmarkPanelVisible.Contains(reportType))
{
pbGeofenceName.Visible = true;
radPanelGeofenceName.Visible = true;
pbGeofenceType.Visible = true;
radPanelGeofenceType.Visible = true;
if (reportType == rep_type.LAND)
{
rlGeoLanName.Text = "Landmark Name";
rlGeoLanType.Text = "Landmark Type";
}
else if (reportType == rep_type.GEOFENC)
{
rlGeoLanName.Text = "Geofence Name";
rlGeoLanType.Text = "Geofence Type";
}
rcbStatus.Items.Clear();
ZoneListNames.Sort(new VehandIDComparer());
rcbStatus.DataSource = ZoneListNames;
rcbStatus.DisplayMember = "Name";
if (rcbStatus.Items.Count >= 1)
rcbStatus.SelectedIndex = 0;
if (rcbGeoLandType.Items.Count >= 1)
rcbGeoLandType.SelectedIndex = 0;
if (reportType == rep_type.GEOFENC)
ckStatus.Text = MainForm2.returnLNGString("zonename");
else ckStatus.Text = MainForm2.returnLNGString("landmarkname");
}
else if (!landmarkPanelVisible.Contains(reportType))
{
pbGeofenceName.Visible = false;
radPanelGeofenceName.Visible = false;
pbGeofenceType.Visible = false;
radPanelGeofenceType.Visible = false;
}
// make unit mandatory
if (unitMandatory.Contains(reportType))
{
pbUnitGroup.Visible = false;
pbUnitGroup.Tag = "disabled";
pbEnableDisable_Click(pbUnitGroup, null);
}
else if (!unitMandatory.Contains(reportType))
{
pbUnitGroup.Visible = true;
pbUnitGroup.Tag = "enabled";
pbEnableDisable_Click(pbUnitGroup, null);
}
// make date mandatory
if (dateMandatory.Contains(reportType))
{
pbDateTime.Visible = false;
pbDateTime.Tag = "disabled";
pbEnableDisable_Click(pbDateTime, null);
}
else if (!dateMandatory.Contains(reportType))
{
pbDateTime.Visible = true;
pbDateTime.Tag = "enabled";
pbEnableDisable_Click(pbDateTime, null);
}
// hide or show LOG [ON/OFF] panel
if (statusPanelVisible.Contains(reportType))
{
pbStatus.Visible = true;
radPanelStatus.Visible = true;
}
else if (!statusPanelVisible.Contains(reportType))
{
pbStatus.Visible = false;
radPanelStatus.Visible = false;
}
// hide or show Idle panel
if (idlePanelVisible.Contains(reportType))
{
radPanelIdle.Visible = true;
}
else if (!idlePanelVisible.Contains(reportType))
{
radPanelIdle.Visible = false;
}
// hide or show SELECT ALL panel
if (selectAllPanelVisible.Contains(reportType))
{
pbSelectAll.Visible = true;
radPanelSelectAll.Visible = true;
}
else if (!selectAllPanelVisible.Contains(reportType))
{
pbSelectAll.Visible = false;
radPanelSelectAll.Visible = false;
}
// show the multi selection combobox if Fleet
if (reportType == rep_type.FLEET)
{
rcbUnitFleet.Visible = true;
rcbUnitGroup.Visible = false;
pbUnitGroupForCombo.Visible = false;
}
else
{
rcbUnitFleet.Visible = false;
rcbUnitGroup.Visible = true;
pbUnitGroupForCombo.Visible = true;
}
// update picture boxes icons and button icons
pbEnabled_Changed(pbIconDateTime, null);
pbEnabled_Changed(pbIconReportDaily, null);
pbEnabled_Changed(pbIconUnitGroup, null);
// set if icon of the Report Daily Icon picture box according to its state
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
case RADIOTYPE.HARRIS:
btPrintReport.Image = Dispatcher.Properties.Resources.report_at;
rlDateTimeFilter.ForeColor = MainForm2.HarTextColor;
rlUnitGroup.ForeColor = MainForm2.HarTextColor;
rlReportDaily.ForeColor = MainForm2.HarTextColor;
rlSelectAll.ForeColor = MainForm2.HarTextColor;
rlCoordinates.ForeColor = MainForm2.HarTextColor;
rlComputeAddress.ForeColor = MainForm2.HarTextColor;
rlGeoLanName.ForeColor = MainForm2.HarTextColor;
rlGeoLanType.ForeColor = MainForm2.HarTextColor;
rlStatus.ForeColor = MainForm2.HarTextColor;
rlIdle.ForeColor = MainForm2.HarTextColor;
rlMin.ForeColor = MainForm2.HarTextColor;
rlUntil.ForeColor = MainForm2.HarTextColor;
ckDataFilter.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckSelectALL.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckGeofenceType.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckStatus.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckUnitGroupFilter.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor;
ckComputeAddress.ForeColor = MainForm2.HarTextColor;
rlComputing.ForeColor = MainForm2.HarTextColor;
break;
default:
btPrintReport.Image = Dispatcher.Properties.Resources.report;
break;
}
}
/// <summary>
/// Change the image of the sender picture box when its enabled or disabled
/// </summary>
/// <param name="sender">Picture Box which triggered the event</param>
private void pbEnabled_Changed(object sender, EventArgs e)
{
// set the icon of the Date Icon picture box according to its state
if ((PictureBox)sender == pbIconDateTime && pbIconDateTime.Enabled)
{
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
pbIconDateTime.Image = Dispatcher.Properties.Resources.icon_date_enabled_at;
break;
case RADIOTYPE.HARRIS:
pbIconDateTime.Image = Dispatcher.Properties.Resources.icon_date_enabled_ha;
break;
default:
pbIconDateTime.Image = Dispatcher.Properties.Resources.icon_date_enabled;
break;
}
}
else if ((PictureBox)sender == pbIconDateTime && !pbIconDateTime.Enabled)
{
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
case RADIOTYPE.HARRIS:
pbIconDateTime.Image = Dispatcher.Properties.Resources.icon_date_disabled_at;
break;
default:
pbIconDateTime.Image = Dispatcher.Properties.Resources.icon_date_disabled;
break;
}
}
// set if icon of the Unit Icon picture box according to its state
if ((PictureBox)sender == pbIconUnitGroup && pbIconUnitGroup.Enabled)
{
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
pbIconUnitGroup.Image = Dispatcher.Properties.Resources.icon_unit_enabled_at;
break;
case RADIOTYPE.HARRIS:
pbIconUnitGroup.Image = Dispatcher.Properties.Resources.icon_unit_enabled_ha;
break;
default:
pbIconUnitGroup.Image = Dispatcher.Properties.Resources.icon_unit_enabled;
break;
}
}
else if ((PictureBox)sender == pbIconUnitGroup && !pbIconUnitGroup.Enabled)
{
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
case RADIOTYPE.HARRIS:
pbIconUnitGroup.Image = Dispatcher.Properties.Resources.icon_unit_disabled_at;
break;
default:
pbIconUnitGroup.Image = Dispatcher.Properties.Resources.icon_unit_disabled;
break;
}
}
// set if icon of the Report Daily Icon picture box according to its state
if ((PictureBox)sender == pbIconReportDaily && pbIconReportDaily.Enabled)
{
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
pbIconReportDaily.Image = Dispatcher.Properties.Resources.icon_email_enabled_at;
break;
case RADIOTYPE.HARRIS:
pbIconReportDaily.Image = Dispatcher.Properties.Resources.icon_email_enabled_ha;
break;
default:
pbIconReportDaily.Image = Dispatcher.Properties.Resources.icon_email_enabled;
break;
}
}
else if ((PictureBox)sender == pbIconReportDaily && !pbIconReportDaily.Enabled)
{
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
case RADIOTYPE.HARRIS:
pbIconReportDaily.Image = Dispatcher.Properties.Resources.icon_email_disabled_at;
break;
default:
pbIconReportDaily.Image = Dispatcher.Properties.Resources.icon_email_disabled;
break;
}
}
// set if icon of the Report Daily Icon picture box according to its state
if ((PictureBox)sender == pbUnitGroupForCombo && pbUnitGroupForCombo.Enabled)
{
if (rcbUnitGroup.SelectedIndex == -1)
return;
if (UnitGroupItems[rcbUnitGroup.SelectedIndex].IsGroup)
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "group", true);
pbUnitGroupForCombo.BackColor = Color.FromArgb(255, 0, 0);
break;
case RADIOTYPE.HARRIS:
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "group", true);
break;
default:
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "group", true);
break;
}
else
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "unit", true);
pbUnitGroupForCombo.BackColor = Color.FromArgb(255, 0, 0);
break;
case RADIOTYPE.HARRIS:
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "unit", true);
break;
default:
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "unit", true);
break;
}
//pbUnitGroupForCombo.BackColor = Color.Transparent;
}
else if ((PictureBox)sender == pbUnitGroupForCombo && !pbUnitGroupForCombo.Enabled)
{
if (rcbUnitGroup.SelectedIndex == -1)
return;
if (UnitGroupItems[rcbUnitGroup.SelectedIndex].IsGroup)
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "group", false);
pbUnitGroupForCombo.BackColor = Color.FromArgb(188, 188, 188);
break;
case RADIOTYPE.HARRIS:
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "group", false);
break;
default:
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "group", false);
break;
}
else
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "unit", false);
pbUnitGroupForCombo.BackColor = Color.FromArgb(188, 188, 188);
break;
case RADIOTYPE.HARRIS:
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "unit", false);
break;
default:
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "unit", false);
break;
}
//pbUnitGroupForCombo.BackColor = Color.Transparent;
}
}
/// <summary>
/// Display the image and text for each unit in the combobox
/// </summary>
private void cbVehName_ItemDataBound(object sender, ListItemDataBoundEventArgs args)
{
// display the text and image for each item in the comboBox
DropListItem item = (DropListItem)args.NewItem.DataBoundItem;
args.NewItem.Text = item.Text;
args.NewItem.Image = item.Image;
}
/// <summary>
/// Resize the SendReport when the progress bar is visible or hide
/// </summary>
private void rProgressBar_VisibleChanged(object sender, EventArgs e)
{
if (rProgressBar.Visible)
btPrintReport.Size = new Size(105, 95);
else
btPrintReport.Size = new Size(105, 127);
}
/// <summary>
/// Enable or disable the Save Email button according to the email address written
/// in the email textBox
/// </summary>
private void rtbEmail_TextChanged(object sender, EventArgs e)
{
bool areEmailsAddressesValid = true;
string[] emailAddresses = rtbEmail.Text.Split(';');
if (emailAddresses.Length == 0)
areEmailsAddressesValid = false;
foreach (String str in emailAddresses)
// foreach email address check if it's a valid email address
if (str.Length > 0 && !IsValidEmail(str))
areEmailsAddressesValid = false;
if (areEmailsAddressesValid)
btSaveEmail.Enabled = true;
else
btSaveEmail.Enabled = false;
}
/// <summary>
///
/// </summary>
private void rcbUnitGroup_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
if (UnitGroupItems[e.Position].IsGroup)
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "group", true);
else
pbUnitGroupForCombo.Image = GetIconForCombobox(MainForm2.radioType, "unit", true);
}
/// <summary>
/// Verify if an email address is a valid email address, in therm of
/// well written, with '@' and '.' in the wright place
/// </summary>
/// <param name="email">Email which needs to be checked</param>
/// <returns>True if the email is a valid one, or false otherwise</returns>
bool IsValidEmail(string email)
{
bool isEmail = Regex.IsMatch(email, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);
return isEmail;
/*
try
{
var addr = new System.Net.Mail.MailAddress(email);
return addr.Address == email;
}
catch
{
return false;
}*/
}
/// <summary>
/// Get the image which needs to be set for a unit/group picture box/ list
/// according to the type of the SafeDispatch
/// </summary>
/// <param name="radioType">Type of the SafeDispatch system [this is equal with the theme]</param>
/// <param name="iconType">String containing the </param>
/// <param name="isEnabled">Specify if the icon should be in enabled or disabled state</param>
/// <returns>The image which fulfills the constrains</returns>
private Image GetIconForCombobox(RADIOTYPE radioType, String iconType, bool isEnabled)
{
if (iconType.Equals("unit"))
{
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
return (isEnabled ? Dispatcher.Properties.Resources.icon_cb_unit_enabled : Dispatcher.Properties.Resources.icon_cb_unit_disabled);
case RADIOTYPE.HARRIS:
return (isEnabled ? Dispatcher.Properties.Resources.icon_cb_unit_enabled_ha : Dispatcher.Properties.Resources.icon_cb_unit_disabled);
default:
return (isEnabled ? Dispatcher.Properties.Resources.icon_cb_unit_enabled : Dispatcher.Properties.Resources.icon_cb_unit_disabled);
}
}
else if (iconType.Equals("group"))
{
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
return (isEnabled ? Dispatcher.Properties.Resources.icon_cb_group_enabled : Dispatcher.Properties.Resources.icon_cb_group_disabled);
case RADIOTYPE.HARRIS:
return (isEnabled ? Dispatcher.Properties.Resources.icon_cb_group_enabled_ha : Dispatcher.Properties.Resources.icon_cb_group_disabled);
default:
return (isEnabled ? Dispatcher.Properties.Resources.icon_cb_group_enabled : Dispatcher.Properties.Resources.icon_cb_group_disabled);
}
}
return (isEnabled ? Dispatcher.Properties.Resources.icon_cb_group_enabled : Dispatcher.Properties.Resources.icon_cb_group_disabled);
}
private void rlComputing_Click(object sender, EventArgs e)
{
}
}
// create a way to get the string from the enum
public sealed class StringEnum
{
/*
radListDataItem5.Text = "OFF";
radListDataItem5.TextWrap = true;
radListDataItem6.Text = "ON";
radListDataItem6.TextWrap = true;
radListDataItem7.Text = "MADE OFF";
radListDataItem7.TextWrap = true;
radListDataItem8.Text = "MADE ON";
*/
private readonly String name;
private readonly int value;
public static readonly StringEnum IN = new StringEnum(1, "IN");//MainForm2.returnLNGString("in"));
public static readonly StringEnum OUT = new StringEnum(2, "OUT");//MainForm2.returnLNGString("out"));
public static readonly StringEnum ON = new StringEnum(1, "ON");//MainForm2.returnLNGString("on"));
public static readonly StringEnum OFF = new StringEnum(2, "OFF");//MainForm2.returnLNGString("off"));
public static readonly StringEnum MADEOFF = new StringEnum(3, "MADE OFF");//MainForm2.returnLNGString("madeoff"));
public static readonly StringEnum MADEON = new StringEnum(4, "MADE ON");//MainForm2.returnLNGString("madeon"));
private StringEnum(int value, String name)
{
this.name = name;
this.value = value;
}
public override String ToString()
{
return name;
}
}
}