SafeDispatch/Safedispatch_4_0/maptab/Reports/ReportsControl.cs
2024-06-07 16:20:57 +03:00

3333 lines
158 KiB
C#

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;
using System.Drawing.Drawing2D;
using Dispatcher;
using System.Threading.Tasks;
using ReportsLibrary;
using resources = Dispatcher.Properties.Resources;
namespace Safedispatch_4_0
{
public partial class ReportsControl : UserControl
{
private SMdb_access smdbObj;
private DBReportingManager dbRep;
private String glwhere, msgLimit, msgInteger, msgMustSel, msgInvalidEmail, msgSplitEmail, msgEmailSaved;
private rep_type RepType;
//private ConvertDT convDT;
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
private ArrayList vehicleListNames;
public BindingList<DropListItem> UnitGroupItems = new BindingList<DropListItem>();
public Dictionary<string, ReportDefinition> reportsDefinitions = new Dictionary<string, ReportDefinition>();
private bool isLoaded = false;
private void setLanguage()
{
btSaveEmail.Text = MainForm2.returnLNGString("savemail");
rlIdle.Text = MainForm2.returnLNGString("generate") + " ";
rlComputing.Text = MainForm2.returnLNGString("comp");
hintText = MainForm2.returnLNGString("sepaemail");
string repType = RepType == rep_type.HIST || RepType == rep_type.ENDOFDAY || RepType == rep_type.IDLE || RepType == rep_type.STOP || RepType == rep_type.FLEET ? "unit" : "unitGroup";
rlUnitGroup.Text = MainForm2.returnLNGString(repType);
// 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;
ckComputeAddress.Text = MainForm2.returnLNGString("compAddr");
ckSelectALL.Text = MainForm2.returnLNGString("cbselAllUnits");
//ckStatus.Text = MainForm2.returnLNGString("SMSStatus");
rlIdle.Text = MainForm2.returnLNGString("txIDLE");
btPrintReport.Text = MainForm2.returnLNGString("btShowReport");
btPrintReportInCsv.Text = MainForm2.returnLNGString("btShowReportInCsv");
minval = MainForm2.returnLNGString("min");
toolWindow2.Text = MainForm2.returnLNGString("Report");
rcbFriday.Text = MainForm2.returnLNGString("friday"); //friday Friday
rcbMonday.Text = MainForm2.returnLNGString("monday"); //monday Monday
rlEmailAddressInfo.Text = MainForm2.returnLNGString("rptDaily"); //rptDaily Report to email address on selected days
rgbReport.Text = MainForm2.returnLNGString("rptDailyOpt"); //rptDailyOpt Report Daily Options
rcbSaturday.Text = MainForm2.returnLNGString("saturday"); //saturday Saturday
rcbSunday.Text = MainForm2.returnLNGString("sunday"); //sunday Sunday
rcbThursday.Text = MainForm2.returnLNGString("thursday"); //thursday Thursday
lbFrom.Text = MainForm2.returnLNGString("timeFrom"); //timeFrom Time from
rlUntil.Text = MainForm2.returnLNGString("timeUntil"); //timeUntil Time until
rcbTuesday.Text = MainForm2.returnLNGString("tuesday"); //tuesday Tuesday
//radLabel2.Text = MainForm2.returnLNGString("unitGroup"); //unitGroup Unit/Group
rcbWednesday.Text = MainForm2.returnLNGString("wednesday"); //wednesday Wednesday
rtbEmail.NullText = MainForm2.returnLNGString("emailaddress");
ckCoordinates.Text = MainForm2.returnLNGString("showcoor");
rcbTicketingTime.NullText = MainForm2.returnLNGString("selTimeEventType");
radLabel4.Text = MainForm2.returnLNGString("ticketStatus");
rcbTicketing.NullText = MainForm2.returnLNGString("selTicketStatus");
radLabel6.Text = MainForm2.returnLNGString("ticketTime");
radLabel5.Text = MainForm2.returnLNGString("SMSStatus");
rlMin.Text = MainForm2.returnLNGString("min");
rcbUnitFleet2.NullText = MainForm2.returnLNGString("displayall");
//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;
rdtFrom.CustomFormat = rdtUntil.CustomFormat = Utils.getDayCustomFormat(MainForm2.is24hours, StaticMembers.DayFirst);
//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";
// }
//}
StaticMembers.is24hours = MainForm2.is24hours;
StaticMembers.DayFirst = MainForm2.DayFirst;
}
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());
}
}
private void GetMessagesFromResources()
{
msgLimit = MainForm2.returnLNGString("endtimegreate");
msgInteger = MainForm2.returnLNGString("msgInteger");
msgMustSel = MainForm2.returnLNGString("mustselect");
msgInvalidEmail = MainForm2.returnLNGString("msgInvalidEmail");
msgSplitEmail = MainForm2.returnLNGString("msgSplitEmail");
msgEmailSaved = MainForm2.returnLNGString("msgEmailSaved");
}
public ReportsControl(rep_type _RepType)
{
MainForm2.RestartMEM += 60000000;
smdbObj = new SMdb_access();
dbRep = new DBReportingManager(MainForm2.cfg.DB_IP, MainForm2.cfg.DB_schema, MainForm2.cfg.DB_user, MainForm2.cfg.DB_passwd, MainForm2.cfg.DB_port);
vehicleListNames = new ArrayList();
ZoneListNames = new ArrayList();
//convDT = new ConvertDT();
RepType = _RepType;
InitializeComponent();
// set theme for the Message Box
RadMessageBox.SetThemeName("TelerikMetroBlue");
GetMessagesFromResources();
#region THEMING
btPrintReport.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
labelReportName.ForeColor = MainForm2.LabelColor;
rgbReport.GroupBoxElement.Header.Border.TopColor = MainForm2.ButtonColor;
rgbReport.GroupBoxElement.Header.Border.TopShadowColor = MainForm2.ButtonColor;
rgbReport.GroupBoxElement.Header.TextPrimitive.ForeColor = MainForm2.ButtonColor;
btSaveEmail_EnabledChanged(btSaveEmail, null);
#endregion
// update the UI for the current report type
UpdateUIForReportType(_RepType);
setLanguage();
toolWindow2.ToolCaptionButtons = ToolStripCaptionButtons.AutoHide | ToolStripCaptionButtons.SystemMenu;
toolWindow2.DocumentButtons &= ~DocumentStripButtons.Close;
PopulateDateTimeInterval();
try
{
if (_RepType == rep_type.BATCH_HIST)
{
// populate RadTreeView
PopulateRadTreeView();
}
else
{
//===============
// Units
//===============
PopulateUnits();
// 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 || _RepType == rep_type.HIST))
{
//===============
// Groups
//===============
PopulateGroups();
}
// add the datasource for the vehicles ComboBox
rcbUnitGroup.DataSource = UnitGroupItems;
if (rcbUnitGroup.Items.Count > 1)
rcbUnitGroup.SelectedIndex = 0;
}
//===============
// Geofence
//===============
if (RepType == rep_type.GEOFENC)
{
foreach (Int32 obj in MainForm2.ZoneIDHash.Keys)
ZoneListNames.Add(new VehandID(((ZoneClass)MainForm2.ZoneIDHash[obj]).Name, obj, ""));
}
//===============
// Landmark
//===============
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;
}
//=========
// Fleet
//=========
if (_RepType == rep_type.FLEET)
{
PopulateFleet();
}
//=============
// Ticketing
//=============
if (rcbTicketing != null)
{
PopulateTicketing();
}
//================
// Context menu
//================
ContextMenuService menuService = this.radDock1.GetService<ContextMenuService>();
menuService.ContextMenuDisplaying += menuService_ContextMenuDisplaying;
//this disables the context menu
menuService.AllowActiveWindowListContextMenu = false;
menuService.AllowDocumentContextMenu = false;
menuService.AllowToolContextMenu = false;
// get all reports definitions as in the database
reportsDefinitions = smdbObj.GetReportsForUser(MainForm2.userIDX);
// populate fields in the UI as defined in the DB
CheckValueReporteSaving();
repHashKey = reportid + "-" + unit_ids;
PopulateFields();
isLoaded = true;
EndOfDayDataObj.ReverseGeoOSM = MainForm2.cfg.ReverseGeoOSM;
StopDataObj.ReverseGeoOSM = MainForm2.cfg.ReverseGeoOSM;
}
private void PopulateDateTimeInterval()
{
// Format and populate rdtFrom and rdtUntil
rdtFrom.CustomFormat = rdtUntil.CustomFormat = Utils.getDayCustomFormat(MainForm2.is24hours, StaticMembers.DayFirst);
DateTime now = DateTime.Now;
DateTime beginOfDay = new DateTime(now.Year, now.Month, now.Day);
rdtFrom.Value = beginOfDay;
rdtUntil.Value = now;
}
private void PopulateUnits()
{
foreach (String obj in StaticMembers.vehicleHT.Keys)
{
// get the vehicle for this key
VehicleForReports veh = (VehicleForReports)(StaticMembers.vehicleHT[obj]);
// create the DropList Item and add it to the items list
UnitGroupItems.Add(new DropListItem()
{
Text = veh.busName,
Image = GetIconForCombobox(MainForm2.radioType, "unit", true), //Dispatcher.Properties.Resources.icon_u;
ValueImei = $"'{veh.IMEI}'",
ValueScID = veh.sc_id.ToString()
});
vehicleListNames.Add(new VehandID(veh.busName, veh.sc_id, veh.IMEI));
}
// add units sorted alphabetically into list
List<DropListItem> sortedList = UnitGroupItems.OrderBy(x => x.Text).ToList();
UnitGroupItems = new BindingList<DropListItem>(sortedList);
}
private void PopulateGroups()
{
BindingList<DropListItem> bindingGroupList = new BindingList<DropListItem>();
// add groups into drop list
foreach (DictionaryEntry pair in MainForm2.GroupHash)
{
GroupClass group = (GroupClass)pair.Value;
string scIDs = string.Join<string>(",", group.arrSc_id.ToArray().Select(x => $"{x}"));
if (scIDs.Length > 0)
{
string imeis = string.Join<string>(",", group.arrImei.ToArray().Select(x => $"'{x}'"));
bindingGroupList.Add(new DropListItem()
{
Image = GetIconForCombobox(MainForm2.radioType, "group", true),
Text = group.name,
IsGroup = true,
ValueScID = scIDs,
ValueImei = imeis
});
}
}
// add groups sorted alphabetically into list
List<DropListItem> sortedGroupList = bindingGroupList.OrderBy(x => x.Text).ToList();
// add the temporary list to the main one
foreach (DropListItem ite in sortedGroupList)
UnitGroupItems.Add(ite);
}
private void PopulateTicketing()
{
foreach (DictionaryEntry obj in MainForm2.TicketingStatusesHT)
rcbTicketing.Items.Add(new RadCheckedListDataItem(((TicketingStatus)obj.Value).Status.Trim(), false));
}
private void PopulateFleet()
{
// populate fleet
vehicleListNames.Sort(new VehandIDComparer());
foreach (VehandID obj in vehicleListNames)
rcbUnitFleet2.Items.Add(new RadCheckedListDataItem(obj.Name, false));
}
private void PopulateRadTreeView()
{
foreach (DictionaryEntry pair in MainForm2.GroupHash)
{
GroupClass group = (GroupClass)pair.Value;
RadTreeNode groupNode = radTreeUnits.Nodes.Add(group.name);
groupNode.Tag = group.id;
foreach (Int32 sc_id in group.arrSc_id)
{
if (MainForm2.VehIDHash.ContainsKey(sc_id))
{
string key = (String)MainForm2.VehIDHash[sc_id];
if (MainForm2.vehicleHT.ContainsKey(key))
{
Vehicle vehicle = ((Vehicle)MainForm2.vehicleHT[key]);
RadTreeNode vehicleNode = groupNode.Nodes.Add(vehicle.busName);
vehicleNode.Tag = vehicle.sc_id;
}
}
}
}
}
private void SetResetWeekDays(bool value)
{
rcbMonday.Checked = value;
rcbTuesday.Checked = value;
rcbWednesday.Checked = value;
rcbThursday.Checked = value;
rcbFriday.Checked = value;
rcbSaturday.Checked = value;
rcbSunday.Checked = value;
}
private void PopulateDaysField(string reportDays)
{
String[] days = reportDays.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (String day in days)
{
if (day.Equals("Mo"))
rcbMonday.Checked = true;
else if (day.Equals("Tu"))
rcbTuesday.Checked = true;
else if (day.Equals("We"))
rcbWednesday.Checked = true;
else if (day.Equals("Th"))
rcbThursday.Checked = true;
else if (day.Equals("Fr"))
rcbFriday.Checked = true;
else if (day.Equals("Sa"))
rcbSaturday.Checked = true;
else if (day.Equals("Su"))
rcbSunday.Checked = true;
}
}
private void PopulateFields()
{
// clear previous values
SetResetWeekDays(false);
if (reportsDefinitions.ContainsKey(repHashKey))
{
ReportDefinition report = reportsDefinitions[repHashKey];
// populate email field
rtbEmail.Text = report.Email;
// populate days field
PopulateDaysField(report.Day);
pbReportDaily.Tag = report.IsActive ? "enabled" : "disabled";
// enable or disable the email panel
pbEnableDisable_Click(pbReportDaily, null);
}
else
{
rtbEmail.Text = "";
}
// validate fields in order to enable or disable the save button
ValidateFields();
}
/// <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.Equals("CloseWindow") ||
menuItem.Name.Equals("CloseAllButThis") ||
menuItem.Name.Equals("CloseAll") ||
menuItem.Name.Equals("Floating") ||
menuItem.Name.Equals("Docked") ||
menuItem.Name.Equals("Hidden") ||
menuItem is RadMenuSeparatorItem)
{
menuItem.Visibility = ElementVisibility.Collapsed;
}
}
}
}
private void PopulateFleetListForCheckedItems()
{
StaticMembers.FleetPosList = new ArrayList();
if (pbUnitGroup.Tag.ToString().Equals("enabled"))
{
// checked items
foreach (RadCheckedListDataItem item in rcbUnitFleet2.CheckedItems.Where(x => x.Checked))
{
StaticMembers.FleetPosList.Add(new FleetIdandPos
{
Name = item.Text,
Position = new ArrayList()
});
}
}
}
private void btPrintReport_Click(object sender, EventArgs e)
{
// hide no report panel
if (panelNoReport.Visible)
panelNoReport.Visible = false;
try
{
if (!ButtonStatusCancel)
{
if (RepType == rep_type.FLEET)
{
PopulateFleetListForCheckedItems();
}
if ((RepType == rep_type.HIST && ckComputeAddress.Checked)
|| (RepType == rep_type.BATCH_HIST && ckComputeAddress.Checked)
|| (RepType == rep_type.SPEED && ckComputeAddress.Checked)
/*
|| ((RepType == rep_type.ENDOFDAY) && (ckComputeAddress.Checked))
|| ((RepType == rep_type.IDLE) && (ckComputeAddress.Checked))
|| ((RepType == rep_type.STOP) && (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)) && (rdtFrom.Value.GetSecondsFromDT() > rdtUntil.Value.GetSecondsFromDT()))
{
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;
StaticMembers.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;
}
}
return Valid;
}
private Int32 Hisotry_sc_id = 0;
private void CheckValue()
{
if (RepType == rep_type.BATCH_HIST)
return;
if (rcbUnitGroup.SelectedIndex < 0)
return;
DropListItem dropListItem = UnitGroupItems[rcbUnitGroup.SelectedIndex];
if (dropListItem == null)
return;
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 (RepType != rep_type.HIST)
{
if (glwhere != "") glwhere = glwhere + " and ";
else glwhere = " where ";
}
if (RepType == rep_type.LOG) glwhere = glwhere + " imei IN (" + dropListItem.ValueImei + ") ";
else if (RepType == rep_type.SMS_LOCATION) glwhere = glwhere + " sc_id_sour IN (" + dropListItem.ValueScID + ") ";
else if (RepType == rep_type.JOB_TICKETING) glwhere = glwhere + " jt.sc_id IN (" + dropListItem.ValueScID + ") ";
else if (RepType == rep_type.HIST) Hisotry_sc_id = Convert.ToInt32(dropListItem.ValueScID);
else glwhere = glwhere + " sc_id IN (" + dropListItem.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 (RepType == rep_type.JOB_TICKETING)
{
//get only checked elements from list
string[] FilterTicketingDateList = rcbTicketingTime.Text.Trim().Split(";".ToCharArray());
//
if (FilterTicketingDateList.Count() > 0 && FilterTicketingDateList[0] != "")
{
if (glwhere != "") glwhere = glwhere + " and ";
else glwhere = " where ";
//iterate through list
int counter = 0;
foreach (string item in FilterTicketingDateList)
{
if (item.Trim() == MainForm2.returnLNGString(job_ticketing_date.created.ToString()))
glwhere = glwhere + " jt.creation_time >= " + rdtFrom.Value.GetSecondsFromDT().ConvertLocalToGMT() + " and jt.creation_time <= " + rdtUntil.Value.GetSecondsFromDT().ConvertLocalToGMT();
else if (item.Trim() == MainForm2.returnLNGString(job_ticketing_date.started.ToString()))
glwhere = glwhere + " jt.start_time >= " + rdtFrom.Value.GetSecondsFromDT().ConvertLocalToGMT() + " and jt.start_time <= " + rdtUntil.Value.GetSecondsFromDT().ConvertLocalToGMT();
else if (item.Trim() == MainForm2.returnLNGString(job_ticketing_date.ended.ToString()))
glwhere = glwhere + " jt.end_time >= " + rdtFrom.Value.GetSecondsFromDT().ConvertLocalToGMT() + " and jt.end_time <= " + rdtUntil.Value.GetSecondsFromDT().ConvertLocalToGMT();
else if (item.Trim() == MainForm2.returnLNGString(job_ticketing_date.dueDate.ToString()))
glwhere = glwhere + " jt.end_time_planned >= " + rdtFrom.Value.GetSecondsFromDT().ConvertLocalToGMT() + " and jt.end_time_planned <= " + rdtUntil.Value.GetSecondsFromDT().ConvertLocalToGMT();
else if (item.Trim() == MainForm2.returnLNGString(job_ticketing_date.lastUpdate.ToString()))
glwhere = glwhere + " jtl.modified_date >= " + rdtFrom.Value.GetSecondsFromDT().ConvertLocalToGMT() + " and jtl.modified_date <= " + rdtUntil.Value.GetSecondsFromDT().ConvertLocalToGMT();
if (FilterTicketingDateList.Count() - 2 > counter++) glwhere = glwhere + " and ";
}
}
}
else
{
if (glwhere != "") glwhere = glwhere + " and ";
else glwhere = " where ";
if (RepType != rep_type.HIST) glwhere = glwhere + " timeGMT >= " + rdtFrom.Value.GetSecondsFromDT().ConvertLocalToGMT() + " and timeGMT <= " + rdtUntil.Value.GetSecondsFromDT().ConvertLocalToGMT();
else
{
//Double Stop = 0, Start = 0;
//Start = Hisotry_sc_id * 10000000000 + rdtFrom.Value.GetSecondsFromDT().ConvertLocalToGMT();
//Stop = Hisotry_sc_id * 10000000000 + rdtUntil.Value.GetSecondsFromDT().ConvertLocalToGMT();
//String query = String.Format(" scevtime>{0} and scevtime<{1}", Start, Stop);
//glwhere = glwhere + query;
glwhere = glwhere + " timeGMT >= " + rdtFrom.Value.GetSecondsFromDT().ConvertLocalToGMT() + " and timeGMT <= " + rdtUntil.Value.GetSecondsFromDT().ConvertLocalToGMT();
glwhere += $" AND sc_id = {dropListItem.ValueScID}";
}
}
}
else
{
if (RepType != rep_type.JOB_TICKETING)
{
DateTime now = DateTime.Now;
DateTime beginOfDay = new DateTime(now.Year, now.Month, now.Day);
if (glwhere != "") glwhere = glwhere + " and ";
else glwhere = " where ";
glwhere = glwhere + " timeGMT >= " + beginOfDay.GetSecondsFromDT().ConvertLocalToGMT() + " and timeGMT <= " + now.GetSecondsFromDT().ConvertLocalToGMT();
if (RepType == rep_type.HIST)
{
if (glwhere != "") glwhere = glwhere + " and ";
else glwhere = " where ";
glwhere += " sc_id IN (" + dropListItem.ValueScID + ") ";
}
}
}
if (ckCoordinates.Checked)
{
//// TODO see what needs to be changed here in order for the LAT LNG to be displayed
}
if (ckTicketing.Checked && rcbTicketing.Text != "")
{
string glwhereStatuses = "";
if (glwhere != "") glwhere = glwhere + " and ";
else glwhere = " where ";
foreach (RadCheckedListDataItem item in rcbTicketing.CheckedItems)
{
//statusDescriptor.FilterDescriptors.Add(new FilterDescriptor("status", FilterOperator.Contains, item.Text.ToString()));
if(item.Checked)
glwhereStatuses += string.Format("'{0}',", item.Text);
}
glwhere += string.Format("jts.status in ({0})", glwhereStatuses.Substring(0, glwhereStatuses.Length - 1));
}
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 String repHashKey = "";
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 String TicketStatus = null;
private String TicketDateType = null;
private String reportType = "";
private void CheckValueReporteSaving()
{
unit_ids = "";
startdate = 0;
stopdate = 0;
geo_id = 0;
type = 0;
reportType = "";
idle_time = 0;
reportid = 0;
LatLng = false;
TicketStatus = null;
TicketDateType = null;
if (UnitGroupItems.Count == 0)
return;
DropListItem dropListItem = UnitGroupItems[rcbUnitGroup.SelectedIndex];
if (this.ckUnitGroupFilter.Checked)
{
if (RepType == rep_type.LOG)
unit_ids = dropListItem.ValueImei;
else
unit_ids = dropListItem.ValueScID;
}
type = ((ckSelectALL.Checked) && (RepType == rep_type.HIST)) ? 1 : 0;
if (ckSelectALL.Checked && (RepType == rep_type.HIST || RepType == rep_type.BATCH_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
{
geo_id = 0;
if (rcbStatus.Items.Count > 0)
geo_id = Int16.Parse(dropListItem.ValueScID);
}
}
if (this.ckGeofenceType.Checked)
{
if (RepType == rep_type.LAND || RepType == rep_type.GEOFENC)
{
type = rcbGeoLandType.SelectedIndex + 1;
}
}
if (ckDataFilter.Checked)
{
startdate = rdtFrom.Value.GetSecondsFromDT().ConvertLocalToGMT();
stopdate = rdtUntil.Value.GetSecondsFromDT().ConvertLocalToGMT();
}
if (RepType == rep_type.ENDOFDAY || RepType == rep_type.IDLE || RepType == rep_type.STOP || RepType == rep_type.FLEET)
{
startdate = rdtFrom.Value.GetSecondsFromDT().ConvertLocalToGMT();
stopdate = rdtUntil.Value.GetSecondsFromDT().ConvertLocalToGMT();
}
if ((RepType == rep_type.ENDOFDAY) || (RepType == rep_type.IDLE) || (RepType == rep_type.STOP))
{
unit_ids = dropListItem.ValueScID;
}
//=========
//FLEET
//=========
if (RepType == rep_type.FLEET)
{
idle_time = ckSelectALL.Checked ? 1 : 0;
// get comma separated unit_ids
unit_ids = "";
foreach (FleetIdandPos obj in StaticMembers.FleetPosList)
{
unit_ids += ((VehicleForReports)StaticMembers.vehicleHT[obj.Name]).sc_id.ToString() + ',';
}
}
//=========
// IDLE
//=========
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;
reportType = RepType.ToString();
//==================
// JOB_TICKETING
//==================
if (RepType == rep_type.JOB_TICKETING)
{
if (ckDataFilter.Checked)
{
if (rcbTicketingTime.Items.Count() > 0)
{
// get comma separated values for ticketing
foreach (CustomListDataItem item in rcbTicketingTime.Items)
{
if (item.Checked)
TicketDateType += item.Index + ",";
}
TicketDateType = TicketDateType.Substring(0, TicketDateType.Length - 1);
}
}
if (ckTicketing.Checked)
{
TicketStatus = rcbTicketing.Text.Trim().Substring(0, rcbTicketing.Text.Trim().Length - 1);
}
}
}
private void ckDataFilter_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
rdtFrom.Enabled = rdtUntil.Enabled = ckDataFilter.Checked;
}
private void chStatus_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
this.rcbStatus.Enabled = this.ckStatus.Checked;
}
private void chVehName_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
this.rcbUnitGroup.Enabled = this.ckUnitGroupFilter.Checked;
}
private void backDB_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
e.Result = ComputeDB(worker, e);
}
private SMposition getNearTheTime(object obj)
{
int sc_id = 0, timeGMT = 0;
if (obj is ONOFFData)
{
sc_id = ((ONOFFData)obj).sc_id;
timeGMT = ((ONOFFData)obj).timeGMT;
}
else if (obj is SpeedData)
{
sc_id = ((SpeedData)obj).sc_id;
timeGMT = ((SpeedData)obj).timeGMT;
}
else if (obj is SMS_Location)
{
sc_id = ((SMS_Location)obj).sc_id;
timeGMT = ((SMS_Location)obj).timeGMT;
}
Int32 step = ((VehicleForReports)StaticMembers.vehicleHT[(String)MainForm2.VehIDHash[sc_id]]).gps_interval;
if (step * 2 < 120)
step = 120;
else
step = step * 2;
//gethistory
SMposition neartheTime = null;
ArrayList list = smdbObj.get_HistoryTelem(sc_id, timeGMT - step, timeGMT + step);
if (list.Count > 0)
{
foreach (SMposition obj2 in list)
{
if (neartheTime == null)
neartheTime = obj2;
else if (Math.Abs(neartheTime.m_time - timeGMT) > Math.Abs(obj2.m_time - timeGMT))
neartheTime = obj2;
}
}
return neartheTime;
}
private List<RadTreeNode> GetCheckedNodes(RadTreeNodeCollection nodes)
{
List<RadTreeNode> checkedNodes = new List<RadTreeNode>();
foreach (RadTreeNode node in nodes)
{
if (node.Parent != null && node.Checked)
{
checkedNodes.Add(node); // add node if checked
}
if (node.Nodes.Count > 0)
{
// recursive function call
List<RadTreeNode> childCheckedNodes = GetCheckedNodes(node.Nodes);
if (childCheckedNodes.Count > 0)
{
// append the results from recursive call
checkedNodes.AddRange(childCheckedNodes);
}
}
}
return checkedNodes;
}
async Task<long> ComputeDB(BackgroundWorker worker, DoWorkEventArgs e)
{
try
{
StaticMembers.LATLNGforDinamicReports = false;
ValidReport = true;
StaticMembers.ReportType = RepType;
if (RepType != rep_type.FLEET && RepType != rep_type.ENDOFDAY && RepType != rep_type.STOP && RepType != rep_type.IDLE)
{
CheckValue();
switch (RepType)
{
case rep_type.LOG:
//smdbObj.get_log_view_all(glwhere);
StaticMembers.ONOFFList = dbRep.get_log_view_all(glwhere, StaticMembers.is24hours, StaticMembers.DayFirst, MainForm2.VehIMEIHash);
break;
case rep_type.EMERG:
//smdbObj.get_EMERG(glwhere);
StaticMembers.ONOFFList = dbRep.get_EMERG(glwhere, StaticMembers.is24hours, MainForm2.VehIDHash);
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), StaticMembers.ONOFFList.Count + (Int32)Math.Round(StaticMembers.ONOFFList.Count * 0.25));
foreach (ONOFFData obj in StaticMembers.ONOFFList)
{
if (!ckCoordinates.Checked)
{
Boolean updateDB = false;
if ((obj.Status == "") || (obj.Status == " ") || (obj.Status == "no address"))
{
try
{
SMposition nearTheTime = getNearTheTime(obj);
if (nearTheTime != null)
{
if ((nearTheTime.m_address == "") || (nearTheTime.m_address == " "))
{
// compute addresses only if checked and no coordinates checked
if (/*ckComputeAddress.Checked &&*/ !ckCoordinates.Checked)
{
MainForm2.AddrCnt++;
MainForm2.AddrGISQueue.Enqueue(new AddrAndID(MainForm2.AddrCnt, nearTheTime.m_lat, nearTheTime.m_lng));
StaticMembers.IdReportHS.Add(MainForm2.AddrCnt.ToString(), "no address");
String Idtofind = MainForm2.AddrCnt.ToString();
Boolean retrynew = true;
Int32 cntmax = 0;
while (retrynew)
{
if (this.backDB.CancellationPending)
{
e.Cancel = true;
return -1;
}
cntmax++;
retrynew = false;
if ((String)StaticMembers.IdReportHS[Idtofind] == "no address")
{
System.Threading.Thread.Sleep(200);
SM.Debug("wait 200msec for address");
retrynew = true;
}
else obj.Status = (String)StaticMembers.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))
{
SMposition nearTheTime = getNearTheTime(obj);
if(nearTheTime != null)
obj.Status = "LAT:" + Math.Round(nearTheTime.m_lat, 5).ToString() + " , LNG:" + Math.Round(nearTheTime.m_lng, 5).ToString();
}
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.BATCH_HIST:
string sc_ids = "";
List <RadTreeNode> checkednodes = GetCheckedNodes(radTreeUnits.Nodes);
if( checkednodes != null && checkednodes.Count > 0 )
sc_ids = string.Join<string>(",", checkednodes.Select(x => $"{x.Tag}"));
StaticMembers.BatchHistoryReport = dbRep.getBatchHistory(sc_ids, rdtFrom.Value.GetSecondsFromDT().ConvertLocalToGMT(), rdtUntil.Value.GetSecondsFromDT().ConvertLocalToGMT(), MainForm2.isInMile, MainForm2.is24hours, 20000, ckComputeAddress.Checked, ckKeepValidPositions.Checked);
break;
case rep_type.HIST:
StaticMembers.IdReportHS.Clear();
//TODO
//smdbObj.get_History(glwhere, ckComputeAddress.Checked, ckCoordinates.Checked);
StaticMembers.HistDataReport = dbRep.get_History(glwhere, ckComputeAddress.Checked, ckCoordinates.Checked, StaticMembers.is24hours, MainForm2.isInMile, ref MainForm2.cntaddr, ref MainForm2.AddrGISQueue, ref StaticMembers.IdReportHS);
if (ckComputeAddress.Checked)
{
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), StaticMembers.IdReportHS.Keys.Count + (Int32)Math.Round(StaticMembers.IdReportHS.Keys.Count * 0.25));
GisAddressWorker.RunWorkerAsync();
retrynew = true;
inwhile = false;
int cntmax = 0;
if (StaticMembers.IdReportHS.Keys.Count > 0)
{
Int32 contNR = StaticMembers.IdReportHS.Keys.Count;
if (cntmax >= contNR)
{
retrynew = false;
inwhile = false;
}
while (retrynew)
{
if (this.backDB.CancellationPending)
{
e.Cancel = true;
return -1;
}
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 StaticMembers.HistDataReport)
{
if (StaticMembers.IdReportHS[obj3.Location] != null)
{
obj3.Location = (String)StaticMembers.IdReportHS[obj3.Location];
if (!obj3.Location.Contains("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);
StaticMembers.HistDataReport = dbRep.get_ALLAlarm(glwhere, StaticMembers.is24hours, MainForm2.isInMile, StaticMembers.DayFirst, MainForm2.VehIDHash, MainForm2.ZoneIDHash, MainForm2.LandIDHash, StaticMembers.vehicleHT, MainForm2.milesh, MainForm2.kmh);
break;
case rep_type.GEOFENC:
case rep_type.LAND:
//MainForm2.LandList = dbRep.get_LANDANDZONE(glwhere, RepType);
StaticMembers.LandList = dbRep.get_LANDANDZONE(glwhere, RepType, StaticMembers.is24hours, StaticMembers.DayFirst, MainForm2.VehIDHash, MainForm2.ZoneIDHash, MainForm2.LandIDHash);
break;
case rep_type.TELEMETRY_EVENT:
case rep_type.TELEMETRY_ALARM:
glwhere = string.IsNullOrEmpty(glwhere) ? " where " : glwhere + " and ";
glwhere += (RepType == rep_type.TELEMETRY_ALARM) ? " alarm = 1 " : " alarm >= 0 ";
//smdbObj.get_TelemHist_alarm_event(glwhere);
StaticMembers.SpeedingList = dbRep.get_TelemHist_alarm_event(glwhere, MainForm2.VehIDHash, StaticMembers.vehicleHT);
// progress bar
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), StaticMembers.SpeedingList.Count + (Int32)Math.Round(StaticMembers.SpeedingList.Count * 0.25));
foreach (SpeedData obj in StaticMembers.SpeedingList)
{
if (!ckCoordinates.Checked)
{
Boolean updateDB = false;
if ((obj.Address == "") || (obj.Address == " "))
{
try
{
Int32 step = ((VehicleForReports)StaticMembers.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 (this.backDB.CancellationPending)
{
e.Cancel = true;
return -1;
}
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)
{
if (this.backDB.CancellationPending)
{
e.Cancel = true;
return -1;
}
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))
{
SMposition neartheTime = getNearTheTime(obj);
if (neartheTime != null)
{
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);
StaticMembers.SpeedingList = dbRep.get_Speeding(glwhere, StaticMembers.is24hours, MainForm2.isInMile, MainForm2.VehIDHash);
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), StaticMembers.SpeedingList.Count + (Int32)Math.Round(StaticMembers.SpeedingList.Count * 0.25));
Console.WriteLine("############################################################################");
foreach (SpeedData obj in StaticMembers.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)
{
if (this.backDB.CancellationPending)
{
e.Cancel = true;
return -1;
}
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))
{
SMposition neartheTime = getNearTheTime(obj);
if (neartheTime != null)
{
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);
StaticMembers.SMSLocList = dbRep.get_SMS_Location(glwhere, StaticMembers.is24hours, MainForm2.VehIDHash);
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), StaticMembers.SMSLocList.Count + (Int32)Math.Round(StaticMembers.SMSLocList.Count * 0.25));
foreach (SMS_Location obj in StaticMembers.SMSLocList)
{
if (!ckCoordinates.Checked)
{
Boolean updateDB = false;
if (obj.Address == "no address")
{
try
{
SMposition neartheTime = getNearTheTime(obj);
if (neartheTime != null)
{
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)
{
if (this.backDB.CancellationPending)
{
e.Cancel = true;
return -1;
}
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))
{
SMposition neartheTime = getNearTheTime(obj);
if (neartheTime != null)
{
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;
case rep_type.JOB_TICKETING:
StaticMembers.SpeedingList = dbRep.get_Ticketing(glwhere, StaticMembers.is24hours);
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);
StaticMembers.ShowCoordinates = ckCoordinates.Checked;
StaticMembers.PositionList = dbRep.get_position_for_report((Int32)(rdtFrom.Value.GetSecondsLocalFromDT()), (Int32)(rdtUntil.Value.GetSecondsLocalFromDT()), Int32.Parse(UnitGroupItems[rcbUnitGroup.SelectedIndex].ValueScID));
StaticMembers.NameReport = UnitGroupItems[rcbUnitGroup.SelectedIndex].Text;
StaticMembers.LATLNGforDinamicReports = ckSelectALL.Checked;
int sc_id = 0;
Int32.TryParse( UnitGroupItems[rcbUnitGroup.SelectedIndex].ValueScID, out sc_id);
/*
if (!ckCoordinates.Checked)
{
Boolean updateDB = false;
if (ckComputeAddress.Checked && ckComputeAddress.Enabled)
{
ReverseGeocodingModule.osnServer = MainForm2.cfg.osmIP;
List<String> positions = await ReverseGeocodingModule.CalculateAddressForPositionsAsync(
StaticMembers.PositionList.Cast<PositionData>().ToList());
}
}*/
bool isComputingNeeded = ckComputeAddress.Checked && ckComputeAddress.Enabled;
// get the list of positions that needs to be computed
List<PositionData> toCompute = isComputingNeeded ? StaticMembers.PositionList.Cast<PositionData>()
.Where(d => (d.Address == null || d.Address.Trim().Length < 1)).ToList() : new List<PositionData>();
List<PositionData> notToCompute = isComputingNeeded ? StaticMembers.PositionList.Cast<PositionData>().Where(d => (d.Address != null && d.Address.Trim().Length > 0)).ToList() :
StaticMembers.PositionList.Cast<PositionData>().ToList();
List<String> computedAddresses = new List<string>();
// compute if needed
if (isComputingNeeded && toCompute.Count > 0)
{
ReverseGeocodingModule.osnServer = MainForm2.cfg.ReverseGeoOSM;
computedAddresses = await ReverseGeocodingModule.CalculateAddressForPositionsAsync(toCompute);
}
List<PositionData> allPositions = new List<PositionData>();
allPositions.AddRange(toCompute);
allPositions.AddRange(notToCompute);
allPositions = allPositions.OrderBy(d => d.TimeGMT).ToList();
foreach (PositionData obj in allPositions)
{
if ((!isComputingNeeded && ckCoordinates.Checked))
{
obj.Address = "LAT:" + Math.Round(obj.Lat, 5).ToString() + " , LNG:" + Math.Round(obj.Lng, 5).ToString();
}
}
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), -1);
}
}
else
{
SM.Debug("Not valid Report");
ValidReport = false;
}
if (RepType == rep_type.FLEET)
{
// the display all logic is applied when no unit was selected
if (StaticMembers.FleetPosList.Count == 0)
{
if (rcbUnitFleet2.CheckedItems.Count == 0 || !pbUnitGroup.Tag.ToString().Equals("enabled"))
{
foreach (RadCheckedListDataItem item in rcbUnitFleet2.Items)
{
StaticMembers.FleetPosList.Add( new FleetIdandPos
{
Name = item.Text,
Position = new ArrayList()
});
}
}
}
Int32 from = (Int32)(rdtFrom.Value.GetSecondsLocalFromDT());
Int32 until = (Int32)(rdtUntil.Value.GetSecondsLocalFromDT());
foreach (FleetIdandPos obj in StaticMembers.FleetPosList)
{
int sc_id = ((VehicleForReports)StaticMembers.vehicleHT[obj.Name]).sc_id;
//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 = dbRep.get_position_for_report(from, until, sc_id);
SM.Debug(obj.Name + " " + obj.Position.Count);
}
}
}
}
catch (Exception ex)
{
SM.Debug("Error compute date from DB:" + ex.ToString());
}
return 1;
}
private List<string> CalculateAdresses<T>(List<T> list )
{
ReverseGeocodingModule.osnServer = MainForm2.cfg.ReverseGeoOSM;
return ReverseGeocodingModule.CalculateAddressForPositions(list);
}
private void backDB_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
switch (RepType)
{
case rep_type.LOG:
ONOFFReport tmp = new ONOFFReport();
tmp.timeCaptionTextBox.Value = MainForm2.returnLNGString("SMSMessTime");
tmp.periodTextBox.Value = "";
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;
case RADIOTYPE.SIMOCO:
tmp.titleTextBox.Value = MainForm2.returnLNGString("SMSlogradioSimoco");
break;
case RADIOTYPE.EXCERA:
tmp.titleTextBox.Value = MainForm2.returnLNGString("SMSlogradioExcera");
break;
}
tmp.Name = tmp.titleTextBox.Value;
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
SpeedingReport tmpSpeed = new SpeedingReport();
tmpSpeed.nameCaptionTextBox.Value = MainForm2.returnLNGString("htableVehiclesListColumns1");
tmpSpeed.speedCaptionTextBox.Value = MainForm2.returnLNGString("tablevehiclesListColumns3") + " (" + (MainForm2.isInMile ? MainForm2.milesh : MainForm2.kmh) + ")";
tmpSpeed.timeCaptionTextBox.Value = MainForm2.returnLNGString("alarmsListColumns1");
tmpSpeed.titleTextBox.Value = MainForm2.returnLNGString("speedalarm");
tmpSpeed.Name = tmpSpeed.titleTextBox.Value;
tmpSpeed.dataCaptionTextBox.Value = MainForm2.returnLNGString("rapday");
tmpSpeed.addressCaptionTextBox.Value = MainForm2.returnLNGString("addrOrLatLng");
tmpSpeed.txObeserv.Value = MainForm2.returnLNGString("obsSpeed");
tmpSpeed.graph1.Visible = true;
reportViewer1.ReportSource = tmpSpeed;
if (StaticMembers.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.Name = tmpTelem.titleTextBox.Value;
tmpTelem.dataCaptionTextBox.Value = MainForm2.returnLNGString("rapday");
tmpTelem.addressCaptionTextBox.Value = MainForm2.returnLNGString("addrOrLatLng");
tmpTelem.txObeserv.Value = "";
tmpTelem.graph1.Visible = false;
tmpTelem.reportFooterSection1.Height = Telerik.Reporting.Drawing.Unit.Pixel(1);
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");
tmpZone.Name = tmpZone.titleTextBox.Value;
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");
tmpLand.Name = tmpLand.titleTextBox.Value;
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.Name = tmpEmerg.titleTextBox.Value;
tmpEmerg.statusCaptionTextBox.Value = MainForm2.returnLNGString("addrOrLatLng");
tmpEmerg.nameCaptionTextBox.Value = MainForm2.returnLNGString("htableVehiclesListColumns1");
reportViewer1.ReportSource = tmpEmerg;
break;
case rep_type.BATCH_HIST:
if (ckComputeAddress.Checked)
{
//btPrintReport.Enabled = true;
rlComputing.Visible = false;
rProgressBar.Visible = false;
ckReportDaily.Visible = true;
rtbEmail.Visible = true;
ckComputeAddress.Visible = true;
ckKeepValidPositions.Visible = true;
}
BatchHistoryReport batchHistoryReport = new BatchHistoryReport();
batchHistoryReport.titleTextBox.Value = MainForm2.returnLNGString("BatchHistoryRep");
batchHistoryReport.dateCaptionTextBox.Value = MainForm2.returnLNGString("Date");
batchHistoryReport.timeCaptionTextBox.Value = MainForm2.returnLNGString("Time");
batchHistoryReport.locationCaptionTextBox.Value = MainForm2.returnLNGString("location");
batchHistoryReport.speedCaptionTextBox.Value = MainForm2.returnLNGString("Speed") + " (" + (MainForm2.isInMile ? MainForm2.milesh : MainForm2.kmh) + ")";
reportViewer1.ReportSource = batchHistoryReport;
break;
case rep_type.HIST:
StaticMembers.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)
{
if (StaticMembers.HistDataReport.Count > 10000)
{
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("limit10000"), MainForm2.returnLNGString("info"), MessageBoxButtons.OK, RadMessageIcon.Info);
StaticMembers.HistDataReport.RemoveRange(10000, StaticMembers.HistDataReport.Count - 10000);
}
/// 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");
tmpRep2.Name = tmpRep2.titleTextBox.Value;
// set address
tmpRep2.locationCaptionTextBox.Value = MainForm2.returnLNGString("addrOrLatLng");
// set speed
tmpRep2.durationCaptionTextBox.Value = MainForm2.returnLNGString("tablevehiclesListColumns3") + " (" + (MainForm2.isInMile ? MainForm2.milesh : 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 StaticMembers.HistDataReport)
{
//SpeedData tmpSpeedData = new SpeedData()
//{
// Name = obj.unit_name,
// Speed = obj.Duration,
// Time = obj.Time,
// Data = obj.Data,
// Address = obj.Location
//};
//MainForm2.SpeedingList.Add(tmpSpeedData);
countdata++;
if (countdata > 50000) break;
}
Console.WriteLine("End of transfer DATA");
// SpeedingReport
SpeedingReport tmpGroupHistoryReport = new SpeedingReport();
// set title
tmpGroupHistoryReport.titleTextBox.Value = MainForm2.returnLNGString("HistoryRep") + " " + MainForm2.returnLNGString("forGroup") + " " + rcbUnitGroup.Text;
// set report name
tmpGroupHistoryReport.Name = tmpGroupHistoryReport.titleTextBox.Value;
// set address
tmpGroupHistoryReport.addressCaptionTextBox.Value = MainForm2.returnLNGString("addrOrLatLng");
// set speed
tmpGroupHistoryReport.speedCaptionTextBox.Value = MainForm2.returnLNGString("tablevehiclesListColumns3") + " (" + (MainForm2.isInMile ? MainForm2.milesh : 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:
StaticMembers.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.Name = tmpRep3.titleTextBox.Value;
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");
tmpEND.Name = tmpEND.titleTextBox.Value;
reportViewer1.ReportSource = tmpEND;
}
break;
case rep_type.STOP:
if (ValidReport)
{
StaticMembers.IsHistroyNotStop = false;
StaticMembers.IsIdle = false;
StopReport tmpRep = new StopReport();
tmpRep.titleTextBox.Value = MainForm2.returnLNGString("namesandvehicleSTOP") + " " + rcbUnitGroup.Text;
tmpRep.Name = tmpRep.titleTextBox.Value;
tmpRep.timeCaptionTextBox.Value = MainForm2.returnLNGString("label3");
tmpRep.locationCaptionTextBox.Value = MainForm2.returnLNGString("locationSTOP");
tmpRep.durationCaptionTextBox.Value = MainForm2.returnLNGString("waitingSTOP");
tmpRep.dataCaptionTextBox.Value = MainForm2.returnLNGString("dateSTOP");
tmpRep.graph1.Visible = false;
tmpRep.reportFooterSection1.Height = Telerik.Reporting.Drawing.Unit.Pixel(1);
reportViewer1.ReportSource = tmpRep;
}
break;
case rep_type.IDLE:
if (ValidReport)
{
StaticMembers.IsHistroyNotStop = false;
StaticMembers.IsIdle = true;
StopReport tmpIDLE = new StopReport();
tmpIDLE.titleTextBox.Value = MainForm2.returnLNGString("namesandvehicleSTOPENG") + " " + rcbUnitGroup.Text;
tmpIDLE.Name = tmpIDLE.titleTextBox.Value;
tmpIDLE.timeCaptionTextBox.Value = MainForm2.returnLNGString("label3");
tmpIDLE.locationCaptionTextBox.Value = MainForm2.returnLNGString("locationSTOP");
tmpIDLE.durationCaptionTextBox.Value = MainForm2.returnLNGString("waitingSTOP");
tmpIDLE.dataCaptionTextBox.Value = MainForm2.returnLNGString("dateSTOP");
tmpIDLE.graph1.Visible = false;
tmpIDLE.reportFooterSection1.Height = Telerik.Reporting.Drawing.Unit.Pixel(1);
reportViewer1.ReportSource = tmpIDLE;
}
break;
case rep_type.FLEET:
if (ValidReport)
{
StaticMembers.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.Name = tmpFleet.titleTextBox.Value;
tmpFleet.tripsCaptionTextBox.Value = MainForm2.returnLNGString("nameroute");
reportViewer1.ReportSource = tmpFleet;
}
break;
case rep_type.SMS_LOCATION:
rlComputing.Visible = false;
rProgressBar.Visible = false;
if (ValidReport)
{
StaticMembers.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");
tmpSMSLoc.Name = tmpSMSLoc.titleTextBox.Value;
reportViewer1.ReportSource = tmpSMSLoc;
}
break;
case rep_type.JOB_TICKETING:
//rlComputing.Visible = false;
//rProgressBar.Visible = false;
//ckReportDaily.Visible = true;
//rtbEmail.Visible = true;
//ckComputeAddress.Visible = true;
SpeedingReport tmpTicketing = new SpeedingReport();
tmpTicketing.graph1.Visible = true;
tmpTicketing.txObeserv.Visible = false;
tmpTicketing.nameCaptionTextBox.Value = MainForm2.returnLNGString("htableVehiclesListColumns1");
tmpTicketing.speedCaptionTextBox.Value = MainForm2.returnLNGString("ticketID");
tmpTicketing.timeCaptionTextBox.Value = MainForm2.returnLNGString("SMSStatus");
tmpTicketing.titleTextBox.Value = MainForm2.returnLNGString("jobTicketingReport");
tmpTicketing.Name = tmpTicketing.titleTextBox.Value;
tmpTicketing.dataCaptionTextBox.Value = MainForm2.returnLNGString("startTime");
tmpTicketing.addressCaptionTextBox.Value = MainForm2.returnLNGString("endTime");
reportViewer1.ReportSource = tmpTicketing;
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)
{
foreach (RadCheckedListDataItem item in rcbUnitFleet2.Items)
item.Checked = ckSelectALL.Checked;
//cbVehNameFleet.SelectedItems.Add(((CustomListDataItem)cbVehNameFleet.Items[i]));
}
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 ReverseGeocoding volltmpGo = new ReverseGeocoding(MainForm2.cfg.ReverseGeoOSM);
private volatile Boolean retrynew;
private volatile Boolean inwhile = false;
private void GisAddressWorker_DoWork(object sender, DoWorkEventArgs e)
{
try
{
BackgroundWorker worker = sender as BackgroundWorker;
while (MainForm2.AddrGISQueue.Count > 0)
{
if ((worker.CancellationPending == true))
{
e.Cancel = true;
break;
}
tmpAddrAndID = (AddrAndID)MainForm2.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)
{
// get address from hashtable
tmpAddrAndID.Address = (String)MainForm2.AddrHass[valHash];
findaddress = true;
}
else
{
// get address from database
AddrtmpX = smdbObj.get_address(tmpAddrAndID.LAT, tmpAddrAndID.LNG);
if (AddrtmpX != "")
{
MainForm2.AddrHass.Add(valHash, AddrtmpX);
tmpAddrAndID.Address = AddrtmpX;
findaddress = true;
}
}
}
catch(Exception ex)
{
Utils.WriteLine(ex.ToString(), ConsoleColor.Red);
}
if (!findaddress)
{
// get address from reverse geocoding
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;
// save in hashtable
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); // save in database
}
}
catch (Exception ex)
{
SM.Debug("Error: " + ex.ToString());
}
}
StaticMembers.IdReportHS[tmpAddrAndID.ID.ToString()] = tmpAddrAndID.Address;
if (inwhile)
rProgressBar.Invoke(new UpdateProgressBarCallBack(this.UpdateProgressBar), -1);
}
}
}
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)
{
btSaveEmail.Enabled = (ckReportDaily.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On);
}
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();
String days = "" + (rcbMonday.Checked ? "Mo," : "")
+ (rcbTuesday.Checked ? "Tu," : "")
+ (rcbWednesday.Checked ? "We," : "")
+ (rcbThursday.Checked ? "Th," : "")
+ (rcbFriday.Checked ? "Fr," : "")
+ (rcbSaturday.Checked ? "Sa," : "")
+ (rcbSunday.Checked ? "Su," : "");
days = days.Substring(0, days.Length - 1);
// get report DB ID if exists
Int32 repId = 0;
repHashKey = reportid + "-" + unit_ids;
if (reportsDefinitions.ContainsKey(repHashKey))
repId = reportsDefinitions[repHashKey].Idx;
// insert or update report into DB
ReportDefinition rep = smdbObj.Insert_Report(startdate, stopdate, unit_ids, geo_id, type, idle_time, reportid, rtbEmail.Text, LatLng,TicketStatus,TicketDateType,
days, RepType.ToString(), true, repId);
// update old report or insert the new one into the dictionary
if (reportsDefinitions.ContainsKey(repHashKey))
reportsDefinitions[repHashKey] = rep;
else
reportsDefinitions.Add(repHashKey, rep);
//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>
private Image themeDateTime_Image = Utils.ChangeColor(resources.r_time, MainForm2.ButtonColor);
private Image themeUnitGroup_Image = Utils.ChangeColor(resources.r_user, MainForm2.ButtonColor);
private Image themeEmail_Image = Utils.ChangeColor(resources.r_email, MainForm2.ButtonColor);
private Image themeGeofence_Image = Utils.ChangeColor(resources.r_geofence, MainForm2.ButtonColor);
private Image themeGeoType_Image = Utils.ChangeColor(resources.r_type, MainForm2.ButtonColor);
private Image themeStatus_Image = Utils.ChangeColor(resources.r_status, MainForm2.ButtonColor);
private Image themeTicketing_Image = Utils.ChangeColor(resources.r_ticketing, MainForm2.ButtonColor);
private void pbEnableDisable_Click(object sender, EventArgs e)
{
try
{
if ((PictureBox)sender == pbDateTime)
{
if (pbDateTime.Tag.Equals("disabled"))
{
pbDateTime.Tag = "enabled";
pbDateTime.Image = resources.r_time_d;
rdtFrom.Enabled = true;
rdtUntil.Enabled = true;
ckDataFilter.Checked = true;
//if (RepType == rep_type.JOB_TICKETING)
//{
// rdtFrom.Enabled = rdtUntil.Enabled = ckTicketingTime.Checked;
//}
}
else
{
pbDateTime.Tag = "disabled";
pbDateTime.Image = themeDateTime_Image;
rdtFrom.Enabled = false;
rdtUntil.Enabled = false;
ckDataFilter.Checked = false;
}
}
else if ((PictureBox)sender == pbUnitGroup)
{
if (pbUnitGroup.Tag.Equals("disabled"))
{
pbUnitGroup.Tag = "enabled";
pbUnitGroup.Image = resources.r_user_d;
rcbUnitGroup.Enabled = true;
rcbUnitFleet2.Enabled = true;
ckUnitGroupFilter.Checked = true;
}
else
{
pbUnitGroup.Tag = "disabled";
pbUnitGroup.Image = themeUnitGroup_Image;
rcbUnitGroup.Enabled = false;
rcbUnitFleet2.Enabled = false;
ckUnitGroupFilter.Checked = false;
}
if (!isLoaded)
return;
CheckValueReporteSaving();
repHashKey = reportid + "-" + unit_ids;
PopulateFields();
}
else if ((PictureBox)sender == pbReportDaily)
{
Boolean isActive = false;
if (pbReportDaily.Tag.Equals("disabled"))
{
pbReportDaily.Tag = "enabled";
pbReportDaily.Image = resources.r_email_d;
rgbReport.Enabled = true;
ckReportDaily.Checked = true;
isActive = true;
}
else
{
pbReportDaily.Tag = "disabled";
pbReportDaily.Image = themeEmail_Image;
rgbReport.Enabled = false;
ckReportDaily.Checked = false;
isActive = false;
}
// update the report in the db
if(reportsDefinitions.ContainsKey(repHashKey))
{
ReportDefinition report = reportsDefinitions[repHashKey];
smdbObj.EnableDisableReport(report.Idx, MainForm2.userIDX, isActive);
}
}
// enable or disable Geofence/Landmark Name
else if ((PictureBox)sender == pbGeofenceName)
{
if (pbGeofenceName.Tag.Equals("disabled"))
{
pbGeofenceName.Tag = "enabled";
pbGeofenceName.Image = resources.r_geofence_d;
rcbGeoLandName.Enabled = true;
ckGeofenceName.Checked = true;
}
else
{
pbGeofenceName.Tag = "disabled";
pbGeofenceName.Image = themeGeofence_Image;
rcbGeoLandName.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 = resources.r_type_d;
rcbGeoLandType.Enabled = true;
ckGeofenceType.Checked = true;
}
else
{
pbGeofenceType.Tag = "disabled";
pbGeofenceType.Image = themeGeoType_Image;
rcbGeoLandType.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 = resources.r_status_d;
radPanelStatus.Enabled = true;
ckStatus.Checked = true;
}
else
{
pbStatus.Tag = "disabled";
pbStatus.Image = themeStatus_Image;
radPanelStatus.Enabled = false;
ckStatus.Checked = false;
}
}
// enable or disable Job Ticketing Statuses
else if ((PictureBox)sender == pbTicketing)
{
if (pbTicketing.Tag.Equals("disabled"))
{
pbTicketing.Tag = "enabled";
pbTicketing.Image = resources.r_ticketing_d;
rcbTicketing.Enabled = true;
ckTicketing.Checked = true;
}
else
{
pbTicketing.Tag = "disabled";
pbTicketing.Image = themeTicketing_Image;
rcbTicketing.Enabled = false;
ckTicketing.Checked = false;
}
}
}
catch (Exception ex) { Utils.WriteLine(ex.ToString(), ConsoleColor.Red); }
}
/// <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)
{
// set text for No report panel according to the report type
// = MainForm2.returnLNGString("");
string reportName = "";
pbReportType.Image = GetTextAndImageForReportType(reportType, out reportName);
labelReportDetails.Text = MainForm2.returnLNGString("r_ReportDetails");
labelReportName.Text = reportName;
try
{
List<rep_type> addressPanelVisible = new List<rep_type>() { rep_type.SPEED, rep_type.HIST, rep_type.BATCH_HIST, rep_type.TELEMETRY_ALARM, rep_type.TELEMETRY_EVENT, rep_type.SMS_LOCATION,
/*rep_type.STOP, rep_type.IDLE, rep_type.ENDOFDAY*/ };
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.BATCH_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 };
//remove selectAllPanel for fleet
List<rep_type> selectAllPanelVisible = new List<rep_type>() { /*rep_type.FLEET*/ };
List<rep_type> unitMandatory = new List<rep_type>() { rep_type.HIST, rep_type.BATCH_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.BATCH_HIST, rep_type.TELEMETRY_ALARM, rep_type.TELEMETRY_EVENT };
List<rep_type> ticketingPanelVisible = new List<rep_type>() { rep_type.JOB_TICKETING };
// show hide pannels
ckComputeAddress.Visible = addressPanelVisible.Contains(reportType);
// hide or show lat-lng panel
ckCoordinates.Visible = latLngPanelVisible.Contains(reportType);
// hide or show Landmark/Geofence Panel
if (landmarkPanelVisible.Contains(reportType))
{
/*
rlGeoLanName.Visible = true;
rcbGeoLandName.Visible = true;
rlGeoLanType.Visible = true;
rcbGeoLandType.Visible = true;
pbGeofenceName.Visible = true;
pbGeofenceType.Visible = true;*/
radPanelGeofence.Visible = true;
if (reportType == rep_type.LAND)
{
rlGeoLanName.Text = MainForm2.returnLNGString("landName");
rlGeoLanType.Text = MainForm2.returnLNGString("landType");
}
else if (reportType == rep_type.GEOFENC)
{
rlGeoLanName.Text = MainForm2.returnLNGString("geoName");
rlGeoLanType.Text = MainForm2.returnLNGString("geoType");
}
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;
pbGeofenceType.Visible = false;
rlGeoLanName.Visible = false;
rcbGeoLandName.Visible = false;
rlGeoLanType.Visible = false;
rcbGeoLandType.Visible = false;*/
radPanelGeofence.Visible = false;
}
// make unit mandatory
if (unitMandatory.Contains(reportType))
{
pbUnitGroup.Visible = pbDateTime.Visible = false;
pbUnitGroup.Tag = pbDateTime.Tag = "disabled";
}
else if (!unitMandatory.Contains(reportType))
{
pbUnitGroup.Visible = pbDateTime.Visible = true;
pbUnitGroup.Tag = pbDateTime.Tag = "enabled";
}
pbReportDaily.Tag = pbGeofenceName.Tag = pbGeofenceType.Tag = pbTicketing.Tag = "enabled";
pbEnableDisable_Click(pbUnitGroup, null);
pbEnableDisable_Click(pbDateTime, null);
pbEnableDisable_Click(pbReportDaily, null);
pbEnableDisable_Click(pbGeofenceName, null);
pbEnableDisable_Click(pbGeofenceType, null);
pbEnableDisable_Click(pbTicketing, 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))
{
ckSelectALL.Visible = true;
}
else if (!selectAllPanelVisible.Contains(reportType))
{
ckSelectALL.Visible = false;
}
// show the multi selection combobox if Fleet
if (reportType == rep_type.FLEET)
{
rcbUnitFleet2.Visible = true;
rcbUnitGroup.Visible = false;
}
else
{
rcbUnitFleet2.Visible = false;
rcbUnitGroup.Visible = true;
}
// show hide ticketing
if (ticketingPanelVisible.Contains(reportType))
{
radPanelTicketing.Visible = true;
//iterate through job_ticketing_date enum
foreach (job_ticketing_date item in Enum.GetValues(typeof(job_ticketing_date)))
rcbTicketingTime.Items.Add(new RadCheckedListDataItem(MainForm2.returnLNGString(item.ToString()), false));
}
else
radPanelTicketing.Visible = false;
if (reportType == rep_type.BATCH_HIST)
{
rcbUnitGroup.Visible = false;
pbUnitGroup.Visible = false;
rlUnitGroup.Visible = false;
ckUnitGroupFilter.Visible = false;
radTreeUnits.Visible = true;
btPrintReportInCsv.Visible = true;
ckKeepValidPositions.Visible = true;
}
else
{
radTreeUnits.Visible = false;
btPrintReportInCsv.Visible = false;
ckKeepValidPositions.Visible = false;
}
}
catch (Exception ex) { Utils.WriteLine(ex.ToString(), ConsoleColor.Red); }
}
/// <summary>
/// Get a image representing the type of the report which can be
/// made in the selected tab/ report type
/// </summary>
/// <param name="reportType">Type of the report which is made</param>
/// <param name="reportName">Name of the report passed as a reference</param>
/// <returns>Image representing the type of the report</returns>
private Image GetTextAndImageForReportType(rep_type reportType, out string reportName)
{
if (reportType == rep_type.SPEED)
{
reportName = MainForm2.returnLNGString("r_SpeedingReport");
return Utils.ChangeColor(resources.r_speeding, MainForm2.ButtonColor);
}
else if (reportType == rep_type.STOP)
{
reportName = MainForm2.returnLNGString("r_StopsReport");
return Utils.ChangeColor(resources.r_stops, MainForm2.ButtonColor);
}
else if (reportType == rep_type.TELEMETRY_ALARM)
{
reportName = MainForm2.returnLNGString("r_TelemetryEventReport");
return Utils.ChangeColor(resources.r_telemetry_alarm, MainForm2.ButtonColor);
}
else if (reportType == rep_type.TELEMETRY_EVENT)
{
reportName = MainForm2.returnLNGString("r_TelemetryReport");
return Utils.ChangeColor(resources.r_telemetry, MainForm2.ButtonColor);
}
else if (reportType == rep_type.ALLALARM)
{
reportName = MainForm2.returnLNGString("r_AllAlarmsReport");
return Utils.ChangeColor(resources.r_allalarm, MainForm2.ButtonColor);
}
else if (reportType == rep_type.EMERG)
{
reportName = MainForm2.returnLNGString("r_EmergencyReport");
return Utils.ChangeColor(resources.r_emergency, MainForm2.ButtonColor);
}
else if (reportType == rep_type.ENDOFDAY)
{
reportName = MainForm2.returnLNGString("r_EndOfDayReport");
return Utils.ChangeColor(resources.r_endofday, MainForm2.ButtonColor);
}
else if (reportType == rep_type.FLEET)
{
reportName = MainForm2.returnLNGString("r_FleetReport");
return Utils.ChangeColor(resources.r_fleet, MainForm2.ButtonColor);
}
else if (reportType == rep_type.GEOFENC)
{
reportName = MainForm2.returnLNGString("r_GeofenceReport");
return Utils.ChangeColor(resources.r_geofences, MainForm2.ButtonColor);
}
else if (reportType == rep_type.HIST)
{
reportName = MainForm2.returnLNGString("r_HistoryReport");
return Utils.ChangeColor(resources.r_time, MainForm2.ButtonColor);
}
else if (reportType == rep_type.BATCH_HIST)
{
reportName = MainForm2.returnLNGString("r_BatchHistoryReport");
return Utils.ChangeColor(resources.r_time, MainForm2.ButtonColor);
}
else if (reportType == rep_type.IDLE)
{
reportName = MainForm2.returnLNGString("r_IdlingReport");
return Utils.ChangeColor(resources.r_idling, MainForm2.ButtonColor);
}
else if (reportType == rep_type.JOB_TICKETING)
{
reportName = MainForm2.returnLNGString("r_TicketingReport");
return Utils.ChangeColor(resources.r_tickets, MainForm2.ButtonColor);
}
else if (reportType == rep_type.LAND)
{
reportName = MainForm2.returnLNGString("r_LandmarkReport");
return Utils.ChangeColor(resources.r_landmark, MainForm2.ButtonColor);
}
else if (reportType == rep_type.SMS_LOCATION)
{
reportName = MainForm2.returnLNGString("r_TextMessageLocationReport");
return Utils.ChangeColor(resources.r_textmessaging, MainForm2.ButtonColor);
}
else if (reportType == rep_type.LOG)
{
reportName = MainForm2.returnLNGString("r_OnOffReport");
return Utils.ChangeColor(resources.r_onoff, MainForm2.ButtonColor);
}
reportName = MainForm2.returnLNGString("r_SpeedingReport");
return resources.r_reports;
}
/// <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 = resources.icon_date_enabled_at;
break;
case RADIOTYPE.HARRIS:
pbIconDateTime.Image = resources.icon_date_enabled_ha;
break;
default:
pbIconDateTime.Image = resources.icon_date_enabled;
break;
}
}
else if ((PictureBox)sender == pbIconDateTime && !pbIconDateTime.Enabled)
{
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
case RADIOTYPE.HARRIS:
pbIconDateTime.Image = resources.icon_date_disabled_at;
break;
default:
pbIconDateTime.Image = 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 = resources.icon_unit_enabled_at;
break;
case RADIOTYPE.HARRIS:
pbIconUnitGroup.Image = resources.icon_unit_enabled_ha;
break;
default:
pbIconUnitGroup.Image = resources.icon_unit_enabled;
break;
}
}
else if ((PictureBox)sender == pbIconUnitGroup && !pbIconUnitGroup.Enabled)
{
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
case RADIOTYPE.HARRIS:
pbIconUnitGroup.Image = resources.icon_unit_disabled_at;
break;
default:
pbIconUnitGroup.Image = 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 = resources.icon_email_enabled_at;
break;
case RADIOTYPE.HARRIS:
pbIconReportDaily.Image = resources.icon_email_enabled_ha;
break;
default:
pbIconReportDaily.Image = resources.icon_email_enabled;
break;
}
}
else if ((PictureBox)sender == pbIconReportDaily && !pbIconReportDaily.Enabled)
{
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
case RADIOTYPE.HARRIS:
pbIconReportDaily.Image = resources.icon_email_disabled_at;
break;
default:
pbIconReportDaily.Image = resources.icon_email_disabled;
break;
}
}
*/
}
/// <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)
{
ValidateFields();
}
/// <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;
}
/// <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 ? resources.icon_cb_unit_enabled : resources.icon_cb_unit_disabled);
case RADIOTYPE.HARRIS:
return (isEnabled ? resources.icon_cb_unit_enabled_ha : resources.icon_cb_unit_disabled);
default:
return (isEnabled ? resources.icon_cb_unit_enabled : resources.icon_cb_unit_disabled);
}
}
else if (iconType.Equals("group"))
{
switch (MainForm2.radioType)
{
case RADIOTYPE.ATLAS:
return (isEnabled ? resources.icon_cb_group_enabled : resources.icon_cb_group_disabled);
case RADIOTYPE.HARRIS:
return (isEnabled ? resources.icon_cb_group_enabled_ha : resources.icon_cb_group_disabled);
default:
return (isEnabled ? resources.icon_cb_group_enabled : resources.icon_cb_group_disabled);
}
}
return (isEnabled ? resources.icon_cb_group_enabled : resources.icon_cb_group_disabled);
}
private void rlComputing_Click(object sender, EventArgs e)
{
}
private void ckUnitGroupFilter_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
}
private void rcb_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
// populate fields in the UI as defined in the DB
if (!isLoaded)
return;
CheckValueReporteSaving();
repHashKey = reportid + "-" + unit_ids;
PopulateFields();
}
private void rcbUnitFleet2_ItemCheckedChanged(object sender, RadCheckedListDataItemEventArgs e)
{
}
string GeneratedReportsFolder = "GeneratedReports";
private string formatReportFileName(string folderPath)
{
// format the file name to contain the current date
DateTime now = DateTime.Now;
string date = $"{now.Year.ToString("D2")}{now.Month.ToString("D2")}{now.Day.ToString("D2")}";
string time_with_miliseconds = $"{now.Hour.ToString("D2")}{now.Minute.ToString("D2")}{now.Second.ToString("D2")}_{now.Millisecond}";
string filePath = $"{folderPath}\\BatchHistoryReport_{date}_{time_with_miliseconds}.csv";
return filePath;
}
private void btPrintReportInCsv_Click(object sender, EventArgs e)
{
// display on button "InProgress" until the report is generated
btPrintReportInCsv.Text = MainForm2.returnLNGString("InProgress");
// don't allow another report to be generated meanwhile
btPrintReportInCsv.Enabled = false;
// start fetching report on a new thread
Task.Factory.StartNew(() =>
{
try
{
// get selected nodes as comma separated list
string sc_ids = "";
List<RadTreeNode> checkednodes = GetCheckedNodes(radTreeUnits.Nodes);
if (checkednodes != null && checkednodes.Count > 0)
sc_ids = string.Join<string>(",", checkednodes.Select(x => $"{x.Tag}"));
int startDate = rdtFrom.Value.GetSecondsFromDT().ConvertLocalToGMT();
int endDate = rdtUntil.Value.GetSecondsFromDT().ConvertLocalToGMT();
// Check if the forder where the reports are stored exists => otherwise create it
string reportsFolder = $"{System.IO.Path.GetDirectoryName(Application.ExecutablePath)}\\{GeneratedReportsFolder}";
if (!Directory.Exists(reportsFolder))
Directory.CreateDirectory(reportsFolder);
// format in csv and save the file into the above creatd folder
string filePath = formatReportFileName(reportsFolder);
List<string> excludeFields = new List<string>() { "Address", "Lat", "Lng" };
// save the report into csv
if (!string.IsNullOrEmpty(filePath))
dbRep.saveBatchHistoryToCsv(filePath, excludeFields, sc_ids, startDate, endDate, MainForm2.isInMile, MainForm2.is24hours, Int32.MaxValue, ckComputeAddress.Checked, ckKeepValidPositions.Checked);
}
finally
{
this.Invoke((MethodInvoker)delegate
{
btPrintReportInCsv.Text = MainForm2.returnLNGString("btShowReportInCsv");
btPrintReportInCsv.Enabled = true;
});
}
});
}
/// <summary>
/// Change fore color and background color for the save email button when its state changes
/// </summary>
private void btSaveEmail_EnabledChanged(object sender, EventArgs e)
{
if (btSaveEmail.Enabled)
{
btSaveEmail.ButtonElement.ButtonFillElement.BackColor = Color.White;
btSaveEmail.ButtonElement.TextElement.ForeColor = MainForm2.ButtonColor;
}
else
{
btSaveEmail.ButtonElement.ButtonFillElement.BackColor = Color.WhiteSmoke;
btSaveEmail.ButtonElement.TextElement.ForeColor = Color.Gray;
}
}
/// <summary>
/// Check if all the conditions are meet to enable the Save button
/// </summary>
private void DaysCheckBox_StateChanged(object sender, StateChangedEventArgs args)
{
ValidateFields();
}
private void ValidateFields()
{
bool areEmailsAddressesValid = true;
bool areDaysChecked = false;
string[] emailAddresses = rtbEmail.Text.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
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) || (str.Length > 0 && !IsValidEmail(str)))
{
areEmailsAddressesValid = false;
break;
}
areDaysChecked = (rcbMonday.Checked || rcbTuesday.Checked
|| rcbWednesday.Checked || rcbThursday.Checked
|| rcbFriday.Checked || rcbSaturday.Checked
|| rcbSunday.Checked);
btSaveEmail.Enabled = areEmailsAddressesValid && areDaysChecked;
}
private void pbFilter_MouseEnter(object sender, EventArgs e)
{
PictureBox pbSender = (PictureBox)sender;
String toolTipTitle = "";
String toolTipText = "";
if (pbSender == pbDateTime)
{
toolTipTitle = MainForm2.returnLNGString("timeFilter");
toolTipText = MainForm2.returnLNGString("timeFilterDesc");
}
else if (pbSender == pbUnitGroup)
{
toolTipTitle = MainForm2.returnLNGString("unitemail");
toolTipText = MainForm2.returnLNGString("unitFilterDesc");
}
else if (pbSender == pbReportDaily)
{
toolTipTitle = MainForm2.returnLNGString("repDaily");
toolTipText = MainForm2.returnLNGString("autogenRep");
}
else if (pbSender == pbGeofenceName)
{
toolTipTitle = (RepType == rep_type.GEOFENC ? MainForm2.returnLNGString("geo") : MainForm2.returnLNGString("land")) + MainForm2.returnLNGString("nameFilter");
toolTipText = String.Format( MainForm2.returnLNGString("selDesired") + ((RepType == rep_type.GEOFENC ? MainForm2.returnLNGString("geo") : MainForm2.returnLNGString("land")))
+ System.Environment.NewLine
+ MainForm2.returnLNGString("orGenReportForAll") + (RepType == rep_type.GEOFENC ? MainForm2.returnLNGString("geos") : MainForm2.returnLNGString("lands")));
}
else if (pbSender == pbGeofenceType)
{
toolTipTitle = (RepType == rep_type.GEOFENC ? MainForm2.returnLNGString("geo") : MainForm2.returnLNGString("land")) + MainForm2.returnLNGString("typeFilter");
toolTipText = String.Format(MainForm2.returnLNGString("selDesTypeEvents") + (RepType == rep_type.GEOFENC ? MainForm2.returnLNGString("geo") : MainForm2.returnLNGString("land"))
+ System.Environment.NewLine
+ MainForm2.returnLNGString("orGenReportForAllEvTypes"));
}
else if (pbSender == pbTicketing)
{
toolTipTitle = MainForm2.returnLNGString("ticketTypeFilter");
toolTipText = MainForm2.returnLNGString("selTicketTypes");
}
else if (pbSender == pbStatus)
{
toolTipTitle = MainForm2.returnLNGString("unitStatusFilter");
toolTipText = MainForm2.returnLNGString("selDesiredUnits");
}
toolTipHelp.ToolTipTitle = toolTipTitle + ": " + (pbSender.Tag.Equals("enabled") ? MainForm2.returnLNGString("active") : MainForm2.returnLNGString("inactive"));
toolTipHelp.Show(
String.Format(toolTipText), pbSender, 150000);
}
private void pbFilter_MouseLeave(object sender, EventArgs e)
{
toolTipHelp.Hide((PictureBox)sender);
}
/// <summary>
/// Enable or disable the Compute Address checkbox in order to prevent the possibility
/// of coordinates and addresses displayed in the same time
/// </summary>
private void ckCoordinates_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
ckComputeAddress.Enabled = !ckCoordinates.Checked;
}
}
// 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, MainForm2.returnLNGString("geoIn"));//MainForm2.returnLNGString("in"));
public static readonly StringEnum OUT = new StringEnum(2, MainForm2.returnLNGString("geoOut"));//MainForm2.returnLNGString("out"));
public static readonly StringEnum ON = new StringEnum(1, MainForm2.returnLNGString("on"));//MainForm2.returnLNGString("on"));
public static readonly StringEnum OFF = new StringEnum(2, MainForm2.returnLNGString("off"));//MainForm2.returnLNGString("off"));
public static readonly StringEnum MADEOFF = new StringEnum(3, MainForm2.returnLNGString("madeOff"));//MainForm2.returnLNGString("madeoff"));
public static readonly StringEnum MADEON = new StringEnum(4, MainForm2.returnLNGString("madeOn"));//MainForm2.returnLNGString("madeon"));
private StringEnum(int value, String name)
{
this.name = name;
this.value = value;
}
public override String ToString()
{
return name;
}
}
}