SafeDispatch/Safedispatch_4_0/TestForm.cs

452 lines
18 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using System.Collections;
using Safedispatch_4_0;
using Telerik.WinControls.UI;
using SafeMobileLib;
namespace Dispatcher
{
public partial class TestForm : Telerik.WinControls.UI.RadForm
{
//private BindingList<VehandID> vehicleListNames = new BindingList<VehandID>();
private ArrayList vehicleListNames = new ArrayList();
private BindingList<DropListItem> dropDownItems = new BindingList<DropListItem>();
public TestForm()
{
InitializeComponent();
radDDReportType.SelectedIndex = 0;
// add units into drop list
foreach (String obj in MainForm2.vehicleHT.Keys)
{
vehicleListNames.Add(new VehandID(((Safedispatch_4_0.Vehicle)MainForm2.vehicleHT[obj]).busName, ((Safedispatch_4_0.Vehicle)MainForm2.vehicleHT[obj]).sc_id, ((Safedispatch_4_0.Vehicle)MainForm2.vehicleHT[obj]).IMEI));
}
vehicleListNames.Sort(new VehandIDComparer());
// create the list with RadListDataItem items
foreach (VehandID veh in vehicleListNames)
{
// create an item which will be added to the drop down list
DropListItem item = new DropListItem();
item.Image = Properties.Resources.user_1_24x;
item.Text = veh.Name;
item.ValueScID = veh.sc_id + "";
item.ValueImei = veh.Imei + "";
// add the item o the list
dropDownItems.Add(item);
}
// add groups into drop list
foreach (DictionaryEntry pair in MainForm2.GroupHash)
{
GroupClass group = (GroupClass)pair.Value;
DropListItem item = new DropListItem();
item.Image = Properties.Resources.group24x;
item.Text = group.name;
string scIDs = "";
foreach(int unitScID in group.arrSc_id)
{
scIDs = scIDs + unitScID + ",";
}
// remove last ,
if(scIDs.Length > 0 && scIDs.Substring(scIDs.Length-1, 1).Equals(","))
scIDs = scIDs.Remove(scIDs.Length-1);
// add group imeis to the data item value
item.ValueScID = scIDs;
// add only groups with units
if(scIDs.Length > 0)
dropDownItems.Add(item);
}
rcbUnitGroup.DataSource = dropDownItems;
//cbVehName.DisplayMember = "Name";
if (rcbUnitGroup.Items.Count > 1)
rcbUnitGroup.SelectedIndex = 0;
}
private void cbVehName_ItemDataBound(object sender, Telerik.WinControls.UI.ListItemDataBoundEventArgs args)
{
RadListDataItem item = (RadListDataItem)args.NewItem.DataBoundItem;
args.NewItem.Text = "<html>" + item.Text + "</html>";
args.NewItem.Image = item.Image;
}
private void cbVehName_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
if (rcbUnitGroup.SelectedIndex >= 0)
{
RadListDataItem item = ((RadListDataItem)rcbUnitGroup.Items[rcbUnitGroup.SelectedIndex]);
//txEmail.Text = item.Value + "";
//txEmail.Text = dropDownItems[e.Position].ValueScID + "";
}
}
private void pbEnableDisable_Click(object sender, EventArgs e)
{
if ((PictureBox)sender == pbDateTime)
{
if (pbDateTime.Tag.Equals("disabled"))
{
pbDateTime.Tag = "enabled";
pbDateTime.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelDateTime.Enabled = true;
ckDataFilter.Checked = true;
}
else
{
pbDateTime.Tag = "disabled";
pbDateTime.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelDateTime.Enabled = false;
ckDataFilter.Checked = false;
}
}
else if ((PictureBox)sender == pbUnitGroup)
{
if (pbUnitGroup.Tag.Equals("disabled"))
{
pbUnitGroup.Tag = "enabled";
pbUnitGroup.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelUnitGroup.Enabled = true;
ckUnitGroupFilter.Checked = true;
}
else
{
pbUnitGroup.Tag = "disabled";
pbUnitGroup.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelUnitGroup.Enabled = false;
ckUnitGroupFilter.Checked = false;
}
}
else if ((PictureBox)sender == pbReportDaily)
{
if (pbReportDaily.Tag.Equals("disabled"))
{
pbReportDaily.Tag = "enabled";
pbReportDaily.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelReportDaily.Enabled = true;
ckReportDaily.Checked = true;
}
else
{
pbReportDaily.Tag = "disabled";
pbReportDaily.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelReportDaily.Enabled = false;
ckReportDaily.Checked = false;
}
}
else if ((PictureBox)sender == pbComputeAddress)
{
if (pbComputeAddress.Tag.Equals("disabled"))
{
pbComputeAddress.Tag = "enabled";
pbComputeAddress.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelComputeAddress.Enabled = true;
ckComputeAddress.Checked = true;
}
else
{
pbComputeAddress.Tag = "disabled";
pbComputeAddress.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelComputeAddress.Enabled = false;
ckComputeAddress.Checked = false;
}
}
else if ((PictureBox)sender == pbCoordinates)
{
if (pbCoordinates.Tag.Equals("disabled"))
{
pbCoordinates.Tag = "enabled";
pbCoordinates.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelLatLng.Enabled = true;
ckCoordinates.Checked = true;
}
else
{
pbCoordinates.Tag = "disabled";
pbCoordinates.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelLatLng.Enabled = false;
ckCoordinates.Checked = false;
}
}
// enable or disable Geofence/Landmark Name
else if ((PictureBox)sender == pbGeofenceName)
{
if (pbGeofenceName.Tag.Equals("disabled"))
{
pbGeofenceName.Tag = "enabled";
pbGeofenceName.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelGeofenceName.Enabled = true;
ckGeofenceName.Checked = true;
}
else
{
pbGeofenceName.Tag = "disabled";
pbGeofenceName.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelGeofenceName.Enabled = false;
ckGeofenceName.Checked = false;
}
}
// enable or disable Geofence/Landmark Type
else if ((PictureBox)sender == pbGeofenceType)
{
if (pbGeofenceType.Tag.Equals("disabled"))
{
pbGeofenceType.Tag = "enabled";
pbGeofenceType.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelGeofenceType.Enabled = true;
ckGeofenceType.Checked = true;
}
else
{
pbGeofenceType.Tag = "disabled";
pbGeofenceType.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelGeofenceType.Enabled = false;
ckGeofenceType.Checked = false;
}
}
// enable or disable Status Panel
else if ((PictureBox)sender == pbStatus)
{
if (pbStatus.Tag.Equals("disabled"))
{
pbStatus.Tag = "enabled";
pbStatus.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelStatus.Enabled = true;
ckStatus.Checked = true;
}
else
{
pbStatus.Tag = "disabled";
pbStatus.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelStatus.Enabled = false;
ckStatus.Checked = false;
}
}
// enable or disable Status Panel
else if ((PictureBox)sender == pbSelectAll)
{
if (pbSelectAll.Tag.Equals("disabled"))
{
pbSelectAll.Tag = "enabled";
pbSelectAll.Image = Dispatcher.Properties.Resources.datepicker_enabled;
radPanelSelectAll.Enabled = true;
ckSelectALL.Checked = true;
}
else
{
pbSelectAll.Tag = "disabled";
pbSelectAll.Image = Dispatcher.Properties.Resources.datepicker_disabled;
radPanelSelectAll.Enabled = false;
ckSelectALL.Checked = false;
}
}
}
private void radDDReportType_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
rep_type[] types = { rep_type.SPEED, rep_type.GEOFENC, rep_type.LAND, rep_type.LOG, rep_type.EMERG, rep_type.ALLALARM, rep_type.HIST,
rep_type.ENDOFDAY, rep_type.IDLE, rep_type.STOP, rep_type.FLEET, rep_type.TELEMETRY_ALARM, rep_type.TELEMETRY_EVENT };
UpdateUIForReportType(types[radDDReportType.SelectedIndex]);
}
private void UpdateUIForReportType(rep_type reportType)
{
List<rep_type> addressPanelVisible = new List<rep_type>() { rep_type.SPEED, rep_type.HIST, rep_type.TELEMETRY_ALARM, rep_type.TELEMETRY_EVENT};
List<rep_type> landmarkPanelVisible = new List<rep_type>() { rep_type.LAND, rep_type.GEOFENC };
List<rep_type> latLngPanelVisible = new List<rep_type>() { rep_type.SPEED, rep_type.EMERG, rep_type.HIST, rep_type.ENDOFDAY, rep_type.IDLE,
rep_type.STOP, rep_type.TELEMETRY_ALARM, rep_type.TELEMETRY_EVENT };
List<rep_type> statusPanelVisible = new List<rep_type>() { rep_type.LOG };
List<rep_type> idlePanelVisible = new List<rep_type>() { rep_type.IDLE };
List<rep_type> selectAllPanelVisible = new List<rep_type>() { rep_type.FLEET };
List<rep_type> unitMandatory = new List<rep_type>() { rep_type.HIST, rep_type.ENDOFDAY, rep_type.IDLE, rep_type.STOP, rep_type.FLEET };
List<rep_type> dateMandatory = new List<rep_type>() { rep_type.ENDOFDAY, rep_type.IDLE, rep_type.STOP, rep_type.FLEET };
List<rep_type> progressBarSpace = new List<rep_type>() { rep_type.SPEED, rep_type.HIST, rep_type.TELEMETRY_ALARM, rep_type.TELEMETRY_EVENT };
if (progressBarSpace.Contains(reportType))
{
btPrintReport.Size = new Size(105, 95);
}
else
{
btPrintReport.Size = new Size(105, 127);
}
// show hide pannels
if (addressPanelVisible.Contains(reportType))
{
pbComputeAddress.Visible = true;
radPanelComputeAddress.Visible = true;
}
else if (!addressPanelVisible.Contains(reportType))
{
pbComputeAddress.Visible = false;
radPanelComputeAddress.Visible = false;
}
// hide or show lat-lng panel
if (latLngPanelVisible.Contains(reportType))
{
pbCoordinates.Visible = true;
radPanelLatLng.Visible = true;
}
else if (!latLngPanelVisible.Contains(reportType))
{
pbCoordinates.Visible = false;
radPanelLatLng.Visible = false;
}
// hide or show Landmark/Geofence Panel
if (landmarkPanelVisible.Contains(reportType))
{
pbGeofenceName.Visible = true;
radPanelGeofenceName.Visible = true;
pbGeofenceType.Visible = true;
radPanelGeofenceType.Visible = true;
if (reportType == rep_type.LAND)
{
radLabelGeofenceName.Text = "Landmark Name";
radLabelGeofenceType.Text = "Landmark Type";
}
else if (reportType == rep_type.GEOFENC)
{
radLabelGeofenceName.Text = "Geofence Name";
radLabelGeofenceType.Text = "Geofence Type";
}
}
else if (!landmarkPanelVisible.Contains(reportType))
{
pbGeofenceName.Visible = false;
radPanelGeofenceName.Visible = false;
pbGeofenceType.Visible = false;
radPanelGeofenceType.Visible = false;
}
// make unit mandatory
if (unitMandatory.Contains(reportType))
{
pbUnitGroup.Visible = false;
pbUnitGroup.Tag = "disabled";
pbEnableDisable_Click(pbUnitGroup, null);
}
else if (!unitMandatory.Contains(reportType))
{
pbUnitGroup.Visible = true;
pbUnitGroup.Tag = "enabled";
pbEnableDisable_Click(pbUnitGroup, null);
}
// make date mandatory
if (dateMandatory.Contains(reportType))
{
pbDateTime.Visible = false;
pbDateTime.Tag = "disabled";
pbEnableDisable_Click(pbDateTime, null);
}
else if (!dateMandatory.Contains(reportType))
{
pbDateTime.Visible = true;
pbDateTime.Tag = "enabled";
pbEnableDisable_Click(pbDateTime, null);
}
// hide or show LOG [ON/OFF] panel
if (statusPanelVisible.Contains(reportType))
{
pbStatus.Visible = true;
radPanelStatus.Visible = true;
}
else if (!statusPanelVisible.Contains(reportType))
{
pbStatus.Visible = false;
radPanelStatus.Visible = false;
}
// hide or show Idle panel
if (idlePanelVisible.Contains(reportType))
{
radPanelIdle.Visible = true;
}
else if (!idlePanelVisible.Contains(reportType))
{
radPanelIdle.Visible = false;
}
// hide or show SELECT ALL panel
if (selectAllPanelVisible.Contains(reportType))
{
pbSelectAll.Visible = true;
radPanelSelectAll.Visible = true;
}
else if (!selectAllPanelVisible.Contains(reportType))
{
pbSelectAll.Visible = false;
radPanelSelectAll.Visible = false;
}
// show the multi selection combobox if Fleet
if (reportType == rep_type.FLEET)
{
rcbUnitFleet.Visible = true;
rcbUnitGroup.Visible = false;
}
else
{
rcbUnitFleet.Visible = false;
rcbUnitGroup.Visible = true;
}
}
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)
pbIconDateTime.Image = Dispatcher.Properties.Resources.icon_date_enabled;
else if ((PictureBox)sender == pbIconDateTime && !pbIconDateTime.Enabled)
pbIconDateTime.Image = Dispatcher.Properties.Resources.icon_date_disabled;
// set if icon of the Unit Icon picture box according to its state
if ((PictureBox)sender == pbIconUnitGroup && pbIconUnitGroup.Enabled)
pbIconUnitGroup.Image = Dispatcher.Properties.Resources.icon_unit_enabled;
else if ((PictureBox)sender == pbIconUnitGroup && !pbIconUnitGroup.Enabled)
pbIconUnitGroup.Image = Dispatcher.Properties.Resources.icon_unit_disabled;
// set if icon of the Report Daily Icon picture box according to its state
if ((PictureBox)sender == pbIconReportDaily && pbIconReportDaily.Enabled)
pbIconReportDaily.Image = Dispatcher.Properties.Resources.icon_email_enabled;
else if ((PictureBox)sender == pbIconReportDaily && !pbIconUnitGroup.Enabled)
pbIconReportDaily.Image = Dispatcher.Properties.Resources.icon_email_disabled;
}
}
}