SafeDispatch/SubscriberAndUserManager/VehiclesForm.cs

2038 lines
89 KiB
C#
Raw 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 SafeMobileLib;
using Telerik.WinControls.UI;
using System.Collections;
using System.Linq;
using System.Threading.Tasks;
namespace SubscriberAndUserManager
{
public partial class VehiclesForm : Telerik.WinControls.UI.RadForm
{
private DBvehiclesManager DB;
private DBgroupsManager DBgrp;
private DBtelemetryManager DBtel;
private DBgatewaysManager DBgateways;
private DBalarmManager DBalarm;
private DBcontactsManager DBcontact = new DBcontactsManager(MainForm.DBServer, MainForm.DBSchema, MainForm.DBUser, MainForm.DBPass, MainForm.DBPort);
private string IDList = "";
private Boolean AdvSettingsCollapse = false;
private bool formTypeEdit = false; //false = add user mode; true = edit user mode
private bool AddRange = false;
Vehicles selVeh;
2024-04-18 15:10:37 +00:00
2024-02-22 16:43:59 +00:00
List<Group> gList;
List<Group> listCategory;
List<Group> listRadioTalk;
List<Group> assignedTalkGroups;
2024-04-18 15:10:37 +00:00
2024-02-22 16:43:59 +00:00
private ArrayList imgList;
private MainForm parrent;
private bool isMultiEdit = false;
internal static MobileVehicles mobile;
internal static bool hasModifiedMobile = false;
internal static bool isNEW = false;
VehiclesMobileForm vmf;
bool isloaded = false;
bool canEditMobile = false;
string initialStatus = "";
string initialGateway = "";
public static Dictionary<string, VehiclesForm> VehiclesCollection = new Dictionary<string, VehiclesForm>();
private void setLanguage()
{
this.Text = MainForm.returnLNGString("unitset");
lbIMEI.Text = MainForm.returnLNGString("radid");
label3.Text = MainForm.returnLNGString("unitname");
label4.Text = MainForm.returnLNGString("user");
lbReportingInterval.Text = MainForm.returnLNGString("gpstime");
lbARSinterval.Text = MainForm.returnLNGString("arstime");
lbSec.Text = radLabel13.Text=radLabel12.Text=radLabel11.Text= MainForm.returnLNGString("sec");
lbGroup.Text = MainForm.returnLNGString("category");
lbIcon.Text = MainForm.returnLNGString("icon");
btnExit.Text = MainForm.returnLNGString("exit");
btnAdd.Text = MainForm.returnLNGString("add");
AdvSettings.Text = MainForm.returnLNGString("advSettings");
lbGPSPOOR.Text = MainForm.returnLNGString("gpspoor");
lbGPSOFF.Text = MainForm.returnLNGString("gpsoff");
lbMADEOFF.Text = MainForm.returnLNGString("madeoff");
radLabel1.Text = MainForm.returnLNGString("IMEIRangeFrom");
radLabel9.Text = MainForm.returnLNGString("RadioTalkGroup");
radLabel6.Text = MainForm.returnLNGString("GWAndRadioGW");
radLabel7.Text = MainForm.returnLNGString("stat");
radLabel8.Text = MainForm.returnLNGString("unittype");
radLabel3.Text = MainForm.returnLNGString("UnitNamePattern");
cbStatus.Items.Clear();
cbStatus.Items.Add(MainForm.returnLNGString("active"));
cbStatus.Items.Add(MainForm.returnLNGString("inactive"));
}
//Add Unit
public VehiclesForm(DBvehiclesManager DB,DBgroupsManager DBgrp, DBgatewaysManager DBgw, DBalarmManager DBalarm, DBtelemetryManager DBtel, List<User> usrList, MainForm _parrent)
{
InitializeComponent();
setLanguage();
this.DB = DB;
this.DBgrp = DBgrp;
this.DBtel = DBtel;
this.DBgateways = DBgw;
this.DBalarm = DBalarm;
AddRange = false;
switch (MainForm.radioType)
{
case RADIOTYPE.HYT:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.SYTADMIN24x;
//this.BackColor = MainForm.HyteraColor;
lbARSinterval.Visible = true;
lbARSintervalSeconds.Visible = true;
tbARSreportingInterval.Visible = true;
break;
case RADIOTYPE.HARRIS:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.visionSmall;
//this.BackColor = MainForm.HarrisColor;
lbARSinterval.Visible = true;
lbARSintervalSeconds.Visible = true;
tbARSreportingInterval.Visible = true;
/*
lbARSinterval.ForeColor = MainForm.HarTextColor;
lbARSintervalSeconds.ForeColor = MainForm.HarTextColor;
lbGroup.ForeColor = MainForm.HarTextColor;
lbIcon.ForeColor = MainForm.HarTextColor;
lbIMEI.ForeColor = MainForm.HarTextColor;
lbReportingInterval.ForeColor = MainForm.HarTextColor;
lbSec.ForeColor = MainForm.HarTextColor;
label3.ForeColor = MainForm.HarTextColor;
label4.ForeColor = MainForm.HarTextColor;*/
break;
case RADIOTYPE.SIMOCO:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.simoco_setup_241;
break;
case RADIOTYPE.EXCERA:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.AXYS_ICON;
break;
case RADIOTYPE.ATLAS:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.ATLASadmin32;
/*this.BackColor = MainForm.HarrisColor;
lbGroup.ForeColor = MainForm.HarTextColor;
lbIcon.ForeColor = MainForm.HarTextColor;
lbIMEI.ForeColor = MainForm.HarTextColor;
lbReportingInterval.ForeColor = MainForm.HarTextColor;
lbSec.ForeColor = MainForm.HarTextColor;
label3.ForeColor = MainForm.HarTextColor;
label4.ForeColor = MainForm.HarTextColor;*/
break;
}
2024-04-18 15:10:37 +00:00
//foreach (User usr in usrList)
//{
// //Telerik.WinControls.Enumerations.SortStyle.None;
// if (usr.UType != USERTYPE.Admin)
// {
// cbUserforImei.Items.Add(new RadListDataItem(usr.UserName));
// }
//}
cbUserforImei.Items.AddRange(usrList.Where(usr => usr.UType != USERTYPE.Admin).Select(usr => new RadListDataItem(usr.UserName)));
2024-02-22 16:43:59 +00:00
if (cbUserforImei.Items.Count != 0)
cbUserforImei.SelectedIndex = 0;
2024-04-18 15:10:37 +00:00
string none = MainForm.returnLNGString("none");
cbGroups.Items.Add(new RadListDataItem(none));
cbTalkGroup.Items.Add(new RadListDataItem(none));
cbGatewayAndRadioGW.Items.Add(new RadListDataItem(none));
2024-02-22 16:43:59 +00:00
gList = DBgrp.GetAllGroups();
2024-04-18 15:10:37 +00:00
listCategory = gList.Where(x => x.Type == GroupType.CATEGORY.value).ToList();
2024-02-22 16:43:59 +00:00
listRadioTalk = gList.Where(x => x.Type == GroupType.RADIOTALK.value).ToList();
2024-04-18 15:10:37 +00:00
// populate category groups
cbGroups.Items.AddRange(listCategory.Select(grp => new RadListDataItem(grp.Name)));
2024-02-22 16:43:59 +00:00
if (cbGroups.Items.Count > 0) cbGroups.SelectedIndex = 0;
2024-04-18 15:10:37 +00:00
// populate talk groups
cbTalkGroup.Items.AddRange(listRadioTalk.Select(grp => new RadListDataItem(grp.Name)));
2024-02-22 16:43:59 +00:00
if (cbTalkGroup.Items.Count > 0) cbTalkGroup.SelectedIndex = 0;
2024-04-18 15:10:37 +00:00
//populate car icons
2024-02-22 16:43:59 +00:00
imgList = DB.get_all_car_picture();
2024-04-18 15:10:37 +00:00
imageList1 = getValidAllPictures(imgList);
2024-02-22 16:43:59 +00:00
cbImageList.DataSource = imgList;
cbImageList.DisplayMember = "DisplayedName";
if (imageList1.Images.Count > 0)
{
pictureBox1.Image = imageList1.Images[0];
}
2024-04-18 15:10:37 +00:00
if (cbStatus.Items.Count != 0) cbStatus.SelectedIndex = 0;
if (cbUnitType.Items.Count != 0) cbUnitType.SelectedIndex = 0;
2024-02-22 16:43:59 +00:00
parrent = _parrent;
}
private String InitialVehName = "";
2024-04-18 15:10:37 +00:00
private ImageList getValidAllPictures(ArrayList imgList)
{
ImageList imageList = new ImageList();
foreach (Car obj in imgList)
{
string filePath = System.Windows.Forms.Application.StartupPath + @"\resource\cars\"
+ (SubscriberAndUserManager.MainForm.iconThemeType == IconTheme.CLASSIC ? "" : "list_")
+ SubscriberAndUserManager.MainForm.iconThemeType + "_" + obj.iconPattern + ".png";
try
{
Bitmap bmp = new Bitmap(filePath);
Image tmp2 = bmp;
imageList.Images.Add(obj.idx.ToString(), tmp2);
}
catch (Exception ex)
{
Utils.WriteLine("\nBmp " + filePath + " exception " + ex.ToString(), ConsoleColor.Red);
}
}
return imageList;
}
private int getImageIndex(ImageList imageList, string key)
{
if (imageList.Images.ContainsKey(key))
return imageList.Images.IndexOfKey(key);
return -1;
}
2024-02-22 16:43:59 +00:00
public static VehiclesForm GetSingleton(DBvehiclesManager DB, DBgroupsManager DBgrp, DBgatewaysManager DBgw, List<User> usrList, EditVehicleParams parms, MainForm _parent)
{
if (!VehiclesCollection.ContainsKey(parms.IdList))
VehiclesCollection.Add(parms.IdList, new VehiclesForm(DB, DBgrp, DBgw, usrList, parms, _parent));
else
{
if (VehiclesCollection[parms.IdList].IsDisposed)
VehiclesCollection[parms.IdList] = new VehiclesForm(DB, DBgrp, DBgw, usrList, parms, _parent);
}
return VehiclesCollection[parms.IdList];
}
public static VehiclesForm GetSingleton(DBvehiclesManager DB, DBgroupsManager DBgrp, DBgatewaysManager DBgw, List<User> usrList, Vehicles selVeh, MainForm _parent)
{
string vehID = selVeh.Id.ToString();
if (!VehiclesCollection.ContainsKey(vehID))
VehiclesCollection.Add(vehID, new VehiclesForm(DB, DBgrp, DBgw, usrList, selVeh, _parent));
else
{
if (VehiclesCollection[vehID].IsDisposed)
VehiclesCollection[vehID] = new VehiclesForm(DB, DBgrp, DBgw, usrList, selVeh, _parent);
}
return VehiclesCollection[vehID];
}
//multiple vehicle edit
public VehiclesForm(DBvehiclesManager DB, DBgroupsManager DBgrp, DBgatewaysManager DBgw, List<User> usrList, EditVehicleParams parms, MainForm _parent)
{
InitializeComponent();
setLanguage();
this.Text = parms.vehicleList + " " + MainForm.returnLNGString("sdset");
this.DB = DB;
this.DBgrp = DBgrp;
this.DBgateways = DBgw;
this.IDList = parms.IdList;
this.Pageview.Controls.Remove(pagRange);
AddRange = false;
isMultiEdit = true;
switch (MainForm.radioType)
{
case RADIOTYPE.HYT:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.SYTADMIN24x;
this.BackColor = MainForm.HyteraColor;
lbARSinterval.Visible = true;
lbARSintervalSeconds.Visible = true;
tbARSreportingInterval.Visible = true;
break;
case RADIOTYPE.HARRIS:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.visionSmall;
this.BackColor = MainForm.HarrisColor;
lbARSinterval.Visible = true;
lbARSintervalSeconds.Visible = true;
tbARSreportingInterval.Visible = true;
break;
case RADIOTYPE.SIMOCO:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.simoco_setup_241;
break;
case RADIOTYPE.EXCERA:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.AXYS_ICON;
break;
case RADIOTYPE.ATLAS:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.ATLASadmin32; //ATLASCHANGE
this.BackColor = MainForm.HarrisColor;
break;
}
foreach (User usr in usrList)
{
//Telerik.WinControls.Enumerations.SortStyle.None;
if (usr.UType != USERTYPE.Admin)
{
2024-04-18 15:10:37 +00:00
cbUserforImei.Items.Add(new RadListDataItem(usr.UserName, usr.Id));
2024-02-22 16:43:59 +00:00
}
}
if (cbUserforImei.Items.Count != 0)
cbUserforImei.SelectedIndex = 0;
formTypeEdit = true;
gList = DBgrp.GetAllGroups();
assignedTalkGroups = DBgrp.getAllTalkGroupsForUnits(IDList);
2024-04-18 15:10:37 +00:00
2024-02-22 16:43:59 +00:00
listCategory = gList.Where(x => x.Type == GroupType.CATEGORY.value).ToList();
listRadioTalk = gList.Where(x => x.Type == GroupType.RADIOTALK.value).ToList();
2024-04-18 15:10:37 +00:00
string none = MainForm.returnLNGString("none");
cbGroups.Items.Add(new RadListDataItem(none));
cbTalkGroup.Items.Add(new RadListDataItem(none));
// populate category groups
cbGroups.Items.AddRange(listCategory.Select(grp => new RadListDataItem(grp.Name)));
2024-02-22 16:43:59 +00:00
if (cbGroups.Items.Count > 0) cbGroups.SelectedIndex = 0;
2024-04-18 15:10:37 +00:00
2024-02-22 16:43:59 +00:00
if (parms.Group == MainForm.returnLNGString("multiple"))
{
cbGroups.Items.Add(MainForm.returnLNGString("multiple"));
cbGroups.SelectedIndex = cbGroups.Items.Count;
}
else
{
2024-04-18 15:10:37 +00:00
int i = getIndex(listCategory, parms.Group);
if (i >= 0)
cbGroups.SelectedIndex = i;
2024-02-22 16:43:59 +00:00
}
2024-04-18 15:10:37 +00:00
// populate talk groups
cbTalkGroup.Items.AddRange(listRadioTalk.Select(grp => new RadListDataItem(grp.Name)));
2024-02-22 16:43:59 +00:00
if (cbTalkGroup.Items.Count > 0) cbTalkGroup.SelectedIndex = 0;
2024-04-18 15:10:37 +00:00
2024-02-22 16:43:59 +00:00
if (assignedTalkGroups.Count > 0)
{
if (assignedTalkGroups.Count() > 1)
{
cbTalkGroup.Items.Add(MainForm.returnLNGString("multiple"));
cbTalkGroup.SelectedIndex = cbGroups.Items.Count;
}
else
{
2024-04-18 15:10:37 +00:00
int i = getIndex(listRadioTalk, assignedTalkGroups[0].Name);
if (i >= 0)
cbTalkGroup.SelectedIndex = i;
2024-02-22 16:43:59 +00:00
}
}
//if (cbTalkGroup.Items.Count > 0) cbTalkGroup.SelectedIndex = 0;
imgList = DB.get_all_car_picture();
2024-04-18 15:10:37 +00:00
imageList1 = getValidAllPictures(imgList);
2024-02-22 16:43:59 +00:00
2024-04-18 15:10:37 +00:00
int idx = getImageIndex(imageList1, parms.Icon);
2024-02-22 16:43:59 +00:00
cbImageList.DataSource = imgList;
cbImageList.DisplayMember = "DisplayedName";
if (parms.Icon == MainForm.returnLNGString("multiple"))
{
cbImageList.Items.Add(MainForm.returnLNGString("multiple"));
cbImageList.SelectedIndex = cbImageList.Items.Count;
pictureBox1.Image = null;
}
else
{
if (imageList1.Images.Count > 0)
{
2024-04-18 15:10:37 +00:00
if (idx < 0) idx = 0;
2024-02-22 16:43:59 +00:00
pictureBox1.Image = imageList1.Images[idx];
cbImageList.SelectedIndex = idx;
}
}
tbImei.Text = parms.imeiList.Replace("'","").Replace("(","").Replace(")","");
tbVehicleName.Text = parms.vehicleList;
tbVehicleName.ReadOnly = true;
btnAdd.Text = MainForm.returnLNGString("save");
radTextBox1.Visible = radTextBox2.Visible = radTextBox3.Visible = radTextBox4.Visible = true;
radTextBox1.NullText = parms.GpsInterval == "0" ? "multiple" : parms.GpsInterval;
if (radTextBox1.NullText == "multiple")
radTextBox2.NullText = radTextBox3.NullText = radTextBox4.NullText = radTextBox1.NullText;
else
{
radTextBox2.NullText = tbMADEOFF.Value.ToString();
radTextBox3.NullText = tbGPSOFF.Value.ToString();
radTextBox4.NullText = tbGPSPOOR.Value.ToString();
}
tbImei.Enabled = false;
label4.Visible = false;
cbUserforImei.Visible = false;
cbUnitType.Enabled = false;
btEditMobile.Enabled = false;
radLabel9.Visible = cbTalkGroup.Visible = false;
//if (cbStatus.Items.Count != 0)
// cbStatus.SelectedIndex = 0;
if (parms.ActiveList == MainForm.returnLNGString("multiple"))
{
cbStatus.Items.Add(MainForm.returnLNGString("multiple"));
cbStatus.SelectedIndex = cbStatus.Items.Count;
}
else
{
cbStatus.SelectedIndex = (parms.ActiveList =="True") ? 0 : 1;
}
if (parms.TypeList == MainForm.returnLNGString("multiple"))
{
cbUnitType.Items.Add(MainForm.returnLNGString("multiple"));
cbUnitType.SelectedIndex = cbStatus.Items.Count;
}
else
{
cbUnitType.SelectedIndex = Convert.ToInt32(parms.TypeList);
}
btEditMobile.Enabled = cbUnitType.SelectedIndex == 1;
parrent = _parent;
}
public VehiclesForm(DBvehiclesManager DB, DBgroupsManager DBgrp, DBgatewaysManager DBgw, List<User> usrList, Vehicles selVeh, MainForm _parent)
{
InitializeComponent();
setLanguage();
this.Text = selVeh.VehName + " " + MainForm.returnLNGString("sdset");
this.DB = DB;
this.DBgrp = DBgrp;
this.DBgateways = DBgw;
this.selVeh = selVeh;
this.Pageview.Controls.Remove(pagRange);
AddRange = false;
switch (MainForm.radioType)
{
case RADIOTYPE.HYT:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.SYTADMIN24x;
//this.BackColor = MainForm.HyteraColor;
lbARSinterval.Visible = true;
lbARSintervalSeconds.Visible = true;
tbARSreportingInterval.Visible = true;
break;
case RADIOTYPE.HARRIS:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.visionSmall;
//this.BackColor = MainForm.HarrisColor;
lbARSinterval.Visible = true;
lbARSintervalSeconds.Visible = true;
tbARSreportingInterval.Visible = true;
break;
case RADIOTYPE.SIMOCO:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.simoco_setup_241;
break;
case RADIOTYPE.EXCERA:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.AXYS_ICON;
break;
case RADIOTYPE.ATLAS:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.ATLASadmin32; //ATLASCHANGE
//this.BackColor = MainForm.HarrisColor;
break;
}
2024-04-18 15:10:37 +00:00
cbUserforImei.Items.AddRange(usrList.Where(usr => usr.UType != USERTYPE.Admin).Select(usr => new RadListDataItem(usr.UserName, usr.Id)));
2024-02-22 16:43:59 +00:00
if (cbUserforImei.Items.Count != 0)
cbUserforImei.SelectedIndex = 0;
2024-04-18 15:10:37 +00:00
2024-02-22 16:43:59 +00:00
formTypeEdit = true;
int count = 0;
foreach (User user in usrList)
{
if (user.UType != USERTYPE.Admin)
{
if (user.UserName == selVeh.UserName)
{
cbUserforImei.SelectedIndex = count;
}
count++;
}
}
2024-04-18 15:10:37 +00:00
string none = MainForm.returnLNGString("none");
cbGroups.Items.Add(new RadListDataItem(none));
cbTalkGroup.Items.Add(new RadListDataItem(none));
cbGatewayAndRadioGW.Items.Add(new RadListDataItem(none));
gList = DBgrp.GetAllGroups();
listCategory = gList.Where(x => x.Type == GroupType.CATEGORY.value).ToList();
2024-02-22 16:43:59 +00:00
listRadioTalk = gList.Where(x => x.Type == GroupType.RADIOTALK.value).ToList();
2024-04-18 15:10:37 +00:00
cbGroups.Items.AddRange(listCategory.Select(grp => new RadListDataItem(grp.Name)));
cbTalkGroup.Items.AddRange(listRadioTalk.Select(grp => new RadListDataItem(grp.Name)));
2024-02-22 16:43:59 +00:00
if (cbGroups.Items.Count > 0) cbGroups.SelectedIndex = 0;
if (cbTalkGroup.Items.Count > 0) cbTalkGroup.SelectedIndex = 0;
//get curent group for unit
int sc_id = DB.getSCID(selVeh.Imei);
Group g = DBgrp.GetGroupForSCID(sc_id,GroupType.CATEGORY.value);
if (g != null)
{
2024-04-18 15:10:37 +00:00
int i = getIndex(listCategory, g.Name);
if (i >= 0)
cbGroups.SelectedIndex = i;
2024-02-22 16:43:59 +00:00
}
g = DBgrp.GetGroupForSCID(sc_id, GroupType.RADIOTALK.value);
if (g != null)
{
2024-04-18 15:10:37 +00:00
int i = getIndex(listRadioTalk, g.Name);
if (i >= 0)
cbTalkGroup.SelectedIndex = i;
2024-02-22 16:43:59 +00:00
}
2024-04-18 15:10:37 +00:00
//get car icons
2024-02-22 16:43:59 +00:00
imgList = DB.get_all_car_picture();
2024-04-18 15:10:37 +00:00
imageList1 = getValidAllPictures(imgList);
2024-02-22 16:43:59 +00:00
2024-04-18 15:10:37 +00:00
int idx = getImageIndex(imageList1, selVeh.ImgID.ToString());
2024-02-22 16:43:59 +00:00
cbImageList.DataSource = imgList;
cbImageList.DisplayMember = "DisplayedName";
2024-04-18 15:10:37 +00:00
2024-02-22 16:43:59 +00:00
if (imageList1.Images.Count > 0)
{
2024-04-18 15:10:37 +00:00
if (idx < 0) idx = 0;
2024-02-22 16:43:59 +00:00
pictureBox1.Image = imageList1.Images[idx];
cbImageList.SelectedIndex = idx;
}
tbImei.Text = selVeh.Imei;
tbVehicleName.Text = selVeh.VehName;
tbEmail.Text = selVeh.Email;
tbPhone.Text = selVeh.Phone;
InitialVehName = selVeh.VehName;
try
{
tbGPSreportingInterval.Value = selVeh.GpsInterval;
}
catch (Exception ex)
{
SM.Debug("Value from DB for GPSreporting out Range:"+ex.ToString());
tbGPSreportingInterval.Value = tbGPSreportingInterval.Minimum;
}
try
{
tbGPSPOOR.Value = selVeh.Gps_poor;
}
catch (Exception ex)
{
SM.Debug("Value from DB for GPSreporting out Range:" + ex.ToString());
tbGPSPOOR.Value = 120;
}
try
{
tbGPSOFF.Value = selVeh.Gps_off;
}
catch (Exception ex)
{
SM.Debug("Value from DB for GPSreporting out Range:" + ex.ToString());
tbGPSOFF.Value = 240;
}
try
{
tbMADEOFF.Value = selVeh.Made_off;
}
catch (Exception ex)
{
SM.Debug("Value from DB for GPSreporting out Range:" + ex.ToString());
tbMADEOFF.Value = 600;
}
try
{
tbARSreportingInterval.Value = selVeh.ArsInterval;
}
catch (Exception ex)
{
SM.Debug("Value from DB for ARSreporting out Range:" + ex.ToString());
tbARSreportingInterval.Value = tbARSreportingInterval.Minimum;
}
btnAdd.Text = MainForm.returnLNGString("save");
tbImei.Enabled = false;
label4.Visible = false;
cbUserforImei.Visible = false;
cbUnitType.Enabled = false;
parrent = _parent;
}
2024-04-18 15:10:37 +00:00
private int getIndex(List<Group> list, string name)
{
for (int i = 0; i < list.Count; i++)
{
if (list[i].Name.Equals(name))
return i;
}
return -1;
}
2024-02-22 16:43:59 +00:00
private String TestUniqueIDinRange(Int32 start, Int32 stop)
{
String toreturn = "";
foreach (String obj in MainForm.ImeiList)
{
for (Int32 i = start; i <= stop; i++)
{
if (obj.ToUpper().CompareTo(i.ToString().ToUpper()) == 0)
{
toreturn = obj;
break;
}
}
}
return toreturn;
}
private String TestUniqueID(Int32 imei)
{
String toreturn = "";
foreach (String obj in MainForm.ImeiList)
{
if (obj.ToUpper().CompareTo(imei.ToString().ToUpper()) == 0)
{
toreturn = obj;
break;
}
}
return toreturn;
}
private String TestUniqueNameinRange(Hashtable newNames)
{
String toreturn = "";
foreach (String obj in MainForm.VehNameList)
{
foreach (Int32 obj2 in newNames.Keys)
{
if (obj.ToUpper().CompareTo(((String)newNames[obj2]).ToUpper()) == 0)
{
toreturn = obj;
break;
}
}
}
return toreturn;
}
private Boolean TestUniqueUnitNane()
{
Boolean toret = false;
if (!formTypeEdit)
{
foreach (String obj in MainForm.VehNameList)
{
if (obj.ToUpper().CompareTo(tbVehicleName.Text.ToUpper()) == 0)
{
toret = true;
break;
}
}
}
else
{
if (InitialVehName.ToUpper().CompareTo(tbVehicleName.Text.ToUpper()) == 0) toret = false;
else
{
foreach (String obj in MainForm.VehNameList)
{
if (obj.ToUpper().CompareTo(tbVehicleName.Text.ToUpper()) == 0)
{
toret = true;
break;
}
}
}
}
return toret;
}
private void btnAdd_Click(object sender, EventArgs e)
{
MainForm.needRestart = true;
#region Disable SIP related features for Simoco
if (MainForm.radioType == RADIOTYPE.SIMOCO)
{
if(cbGatewayAndRadioGW.Items.Count < 2)
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("AddGatewayFirst"), MainForm.returnLNGString("err"));
return;
}
else
{
//it will be only one gateway
cbGatewayAndRadioGW.SelectedIndex = 1;
}
}
#endregion Disable SIP related features for Simoco
try
{
if (!AddRange)
{
if (tbImei.Text != "" && tbVehicleName.Text != "")
{
// check if email is unique
bool isEmailValid = true;
if (tbEmail.Text.Length > 0)
{
Vehicles veh = controlUnit.vehs.FirstOrDefault(d => d.Email == tbEmail.Text);
// if a vehicle with same email exists
if (selVeh != null && veh != null && veh.Id != selVeh.Id)
isEmailValid = false;
else if (selVeh == null && veh != null)
isEmailValid = false;
}
// check if phone is unique
bool isPhoneValid = true;
if (tbPhone.Text.Length > 0)
{
Vehicles veh = controlUnit.vehs.FirstOrDefault(d => d.Phone == tbPhone.Text);
// if a vehicle with same email exists
if (selVeh != null && veh != null && veh.Id != selVeh.Id)
isPhoneValid = false;
else if (selVeh == null && veh != null)
isPhoneValid = false;
}
Int64 temp = 0;
if (!Int64.TryParse(tbImei.Text, out temp) && (!isMultiEdit))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("ImeiNotInt"), MainForm.returnLNGString("err"));
return;
}
else
{
if (temp > 1677721)
{
if (!MainForm.hideLinxFeatures)
CustomMessageBox.Show(CustomMessageBoxType.exclamation, string.Format(MainForm.returnLNGString("ImeiLessThan"), 1677721), MainForm.returnLNGString("warning"));
}
}
if (!isMultiEdit)
{
if (cbUnitType.SelectedItem.Text.ToLower() == DeviceType.SMARTPHONE.ToString().ToLower())
{
if (mobile.SipLogin == null || mobile.SipLogin == "" || mobile.SipPswd == null || mobile.SipPswd == "")
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("invldSiploginPSwd"), MainForm.returnLNGString("err"));
return;
}
if (mobile.SipPswd.Length < 4)
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("linxPswsLength"), MainForm.returnLNGString("err"));
return;
}
}
}
if (((tbImei.Text.Length > 16) || (tbImei.Text.Length == 0)) && (!isMultiEdit))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("limtimei"), MainForm.returnLNGString("err"));
}
else if (TestUniqueUnitNane() && (!isMultiEdit))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("vehNameUnique"), MainForm.returnLNGString("err"));
}
else if (!isEmailValid && (!isMultiEdit))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("vehEmailUnique"), MainForm.returnLNGString("err"));
}
else if (!isPhoneValid && (!isMultiEdit))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("vehPhoneUnique"), MainForm.returnLNGString("err"));
}
else
{
//return;
if (!formTypeEdit)
{
try
{
String testID = TestUniqueID(Convert.ToInt32(tbImei.Text));
if (testID.Length != 0)
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("imeiUnique") + "\n " + MainForm.returnLNGString("wehavedouble") + ":" + testID, MainForm.returnLNGString("err"));
return;
}
}
catch { }
int carID = ((Car)((RadListDataItem)cbImageList.SelectedItem).Value).idx;
int gw_id = 0;
int radio_id = 0;
if (cbGatewayAndRadioGW.SelectedItems.Count == 0 )
{
RadMessageBox.Show("Please select a gateway !", "Unit error", MessageBoxButtons.OK, RadMessageIcon.Error);
return;
}
gw_id = (int)((RadioGateway)cbGatewayAndRadioGW.SelectedItems[0].Value).Gw_id;
radio_id = ((RadioGateway)cbGatewayAndRadioGW.SelectedItems[0].Value).Id;
vehResponse reps =
(MainForm.IS_SIERRA_WIRELESS ?
DB.addVehicleSierraToDb(tbImei.Text, cbUserforImei.Text, tbVehicleName.Text, "", 0, true,
(Int32)tbGPSreportingInterval.Value, carID, (Int32)tbGPSPOOR.Value, (Int32)tbGPSOFF.Value, (Int32)tbMADEOFF.Value,
(Int32)tbARSreportingInterval.Value, tbEmail.Text, tbPhone.Text, gw_id, radio_id, cbStatus.Equals(MainForm.returnLNGString("active")), cbUnitType.SelectedIndex, mobile)
:
DB.addVehicleToDb(tbImei.Text, cbUserforImei.Text, tbVehicleName.Text, "", 0, true,
(Int32)tbGPSreportingInterval.Value, carID, (Int32)tbGPSPOOR.Value, (Int32)tbGPSOFF.Value, (Int32)tbMADEOFF.Value,
(Int32)tbARSreportingInterval.Value, gw_id, radio_id, cbStatus.Text.Equals(MainForm.returnLNGString("active")), cbUnitType.SelectedIndex, mobile));
if (reps != vehResponse.done)
{
RadMessageBox.Show("Unable to insert unit into database!", "Unit error", MessageBoxButtons.OK, RadMessageIcon.Error);
return;
}
//MainForm.CallWebServer(MainForm.RestartSipLink);
//add group relation
int sc_id = DB.getSCID(tbImei.Text);
if (cbGroups.SelectedItem != null)
{
if (cbGroups.Text != MainForm.returnLNGString("none"))
{
int grID = listCategory[cbGroups.SelectedIndex - 1].Id;
DBgrp.AddGroupElement(sc_id, grID, GroupType.CATEGORY.value);
}
}
if (cbTalkGroup.SelectedItem != null)
{
if (cbTalkGroup.Text != MainForm.returnLNGString("none"))
{
int grID = listRadioTalk[cbTalkGroup.SelectedIndex - 1].Id;
DBgrp.AddGroupElement(sc_id, grID, GroupType.RADIOTALK.value);
}
}
//add telemetry objs
if ((MainForm.radioType == RADIOTYPE.MOTO) || (MainForm.radioType == RADIOTYPE.REPEATER_TRBO))
{
for (int i = 1; i < 6; i++)
{
TelemetryObj obj = new TelemetryObj(0, i, "IN", "Low", "Digital " + i, false);
try
{
DBtel.addTelemetryObj(obj, sc_id);
}
catch (Exception ex)
{
SM.Debug("ERROR ADD tel obj for digital " + i);
SM.Debug(ex.ToString());
}
}
}
// add alarm definition entity into the database for the new unit
Alarm alm = new Alarm(0, sc_id, "1", "", "", "", "", "", true, true, true, true, true, true, true, true);
try
{
List<AdminAlerts> alerts = new List<AdminAlerts>() { AdminAlerts.ALARM_ON_EMAIL, AdminAlerts.EMERGENCY, AdminAlerts.EMERGENCY_POPUP,
AdminAlerts.EMERGENCY_SOUND, AdminAlerts.GEOFENCE, AdminAlerts.GEOFENCE_POPUP, AdminAlerts.GEOFENCE_SOUND, AdminAlerts.LANDMARK,
AdminAlerts.LONE_WORKER, AdminAlerts.SPEED, AdminAlerts.SPEED_POPUP, AdminAlerts.SPEED_SOUND, AdminAlerts.TELEMETRY_POPUP, AdminAlerts.TELEMETRY_SOUND};
DBalarm.insertAlarm4ScIds(alm, new List<int>() { sc_id }, alerts);
//resp = DBalarm.deleteAlarm(radioID);
//resp = DBalarm.addAlarm(alm, radioID);
}
catch (Exception ex)
{ Console.WriteLine(ex.ToString()); return; }
HandleResp(reps);
}
else
{
if (!isMultiEdit)
{
int carID = ((Car)((RadListDataItem)cbImageList.SelectedItem).Value).idx;
int gw_id = 0;
int radio_id = 0;
bool isUnitDeleted = DB.isUnitDeleted(selVeh.Id.ToString());
if (cbGatewayAndRadioGW.SelectedItems.Count == 0 )
{
RadMessageBox.Show("Please select a gateway !", "Unit error", MessageBoxButtons.OK, RadMessageIcon.Error);
return;
}
if(cbStatus.Text.Equals(MainForm.returnLNGString("active")) && isUnitDeleted)
{
DialogResult result = RadMessageBox.Show("Setting this unit as active will un-delete it! Are you sure you want to continue?", "Warning!!!",
MessageBoxButtons.YesNo, RadMessageIcon.Info);
if (result == DialogResult.No)
return;
}
gw_id = (int)((RadioGateway)cbGatewayAndRadioGW.SelectedItems[0].Value).Gw_id;
radio_id = ((RadioGateway)cbGatewayAndRadioGW.SelectedItems[0].Value).Id;
//to do: put correct gw_id and radio_gw_id
vehResponse reps =
(MainForm.IS_SIERRA_WIRELESS ?
DB.editVehicleSierra(selVeh.Id.ToString(), tbVehicleName.Text, 0, "", (Int32)tbGPSreportingInterval.Value,
carID, (Int32)tbGPSPOOR.Value, (Int32)tbGPSOFF.Value, (Int32)tbMADEOFF.Value, (Int32)tbARSreportingInterval.Value, tbEmail.Text, tbPhone.Text, gw_id, radio_id, cbStatus.Text.Equals(MainForm.returnLNGString("active")), cbUnitType.SelectedIndex, mobile)
:
DB.editVehicle(selVeh.Id.ToString(), tbVehicleName.Text, 0, "", (Int32)tbGPSreportingInterval.Value,
carID, (Int32)tbGPSPOOR.Value, (Int32)tbGPSOFF.Value, (Int32)tbMADEOFF.Value, gw_id, radio_id, cbStatus.Text.Equals(MainForm.returnLNGString("active")), cbUnitType.SelectedIndex, mobile, (Int32)tbARSreportingInterval.Value));
//MainForm.CallWebServer(MainForm.RestartSipLink);
int sc_id = DB.getSCID(tbImei.Text);
if (cbTalkGroup.SelectedItem != null)
{
if (cbTalkGroup.Text != MainForm.returnLNGString("none"))
{
int grID = listRadioTalk[cbTalkGroup.SelectedIndex - 1].Id;
DBgrp.cleanRadioTalkConnection(grID.ToString());
DBgrp.AddGroupElement(sc_id, grID, GroupType.RADIOTALK.value);
}
else
{
DBgrp.RemoveGroupElement(sc_id, GroupType.RADIOTALK.value);
}
//HandleResp(reps);
}
if (cbGroups.SelectedItem != null)
{
if (cbGroups.Text != MainForm.returnLNGString("none"))
{
int grID = listCategory[cbGroups.SelectedIndex - 1].Id;
DBgrp.AddGroupElement(sc_id, grID, GroupType.CATEGORY.value);
}
else
{
DBgrp.RemoveGroupElement(sc_id, GroupType.CATEGORY.value);
}
HandleResp(reps);
}
}
else
{
EditRangeVehiclesAsync();
}
}
// send restarts
parrent.SendRestart();
}
}
else
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("CompleteRadioIDAndUnitName"), MainForm.returnLNGString("err"));
return;
}
}
else
{
AddRangeVehiclesAsync();
}
}
catch (Exception ex)
{
Utils.WriteLine(ex.Message, ConsoleColor.Red);
}
}
private async void EditRangeVehiclesAsync()
{
btnAdd.Enabled = btnExit.Enabled = false;
await Task.Run(() => EditRangeVehicles());
btnAdd.Enabled = btnExit.Enabled = true;
}
private void EditRangeVehicles()
{
int carID = ((Car)((RadListDataItem)cbImageList.SelectedItem).Value).idx;
2024-06-07 13:20:57 +00:00
string[] idList = IDList.Replace("(", "").Replace(")", "").Split(",".ToCharArray());
2024-02-22 16:43:59 +00:00
bool isUnitDeleted = DB.isUnitDeleted(idList[0]);
if (cbStatus.Text.Equals(MainForm.returnLNGString("active")) && isUnitDeleted)
{
DialogResult result = RadMessageBox.Show("Setting these units as active will un-delete them! Are you sure you want to continue?", "Warning!!!",
MessageBoxButtons.YesNo, RadMessageIcon.Info);
if (result == DialogResult.No)
return;
}
vehResponse reps = DB.editGroupVehicle(IDList, 0, "", (radTextBox1.Text != ""), (Int32)tbGPSreportingInterval.Value,
(cbImageList.Text != MainForm.returnLNGString("multiple")), carID, (radTextBox4.Text != ""), (Int32)tbGPSPOOR.Value, (radTextBox3.Text != ""),
(Int32)tbGPSOFF.Value, (radTextBox2.Text != ""), (Int32)tbMADEOFF.Value, (((RadioGateway)cbGatewayAndRadioGW.SelectedItems[0].Value).Name != initialGateway),
((RadioGateway)cbGatewayAndRadioGW.SelectedItems[0].Value), (cbStatus.Text != initialStatus), cbStatus.Text.Equals(MainForm.returnLNGString("active")), mobile, (Int32)tbARSreportingInterval.Value);
//MainForm.CallWebServer(MainForm.RestartSipLink);
if (cbGroups.SelectedItem != null)
{
if (cbGroups.Text != MainForm.returnLNGString("multiple"))
{
if (cbGroups.Text != MainForm.returnLNGString("none"))
{
int grID = listCategory[cbGroups.SelectedIndex - 1].Id;
try
{
DBgrp.AddGroupElementBulk(IDList, idList, grID, GroupType.CATEGORY.value);
}
catch(Exception ex)
{
Utils.WriteLine("EditRangeVehicles error: " + ex.ToString(), ConsoleColor.Red);
}
}
else
{
try
{
DBgrp.RemoveGroupElementBulk(IDList, GroupType.CATEGORY.value);
}
catch (Exception ex)
{
Utils.WriteLine("EditRangeVehicles error: " + ex.ToString(), ConsoleColor.Red);
}
}
if (cbTalkGroup.Text != MainForm.returnLNGString("none"))
{
int grID = listRadioTalk[cbTalkGroup.SelectedIndex - 1].Id;
try
{
DBgrp.AddGroupElementBulk(IDList, idList, grID, GroupType.RADIOTALK.value);
}
catch (Exception ex)
{
Utils.WriteLine("EditRangeVehicles error: " + ex.ToString(), ConsoleColor.Red);
}
}
else
{
try
{
DBgrp.RemoveGroupElementBulk(IDList, GroupType.RADIOTALK.value);
}
catch (Exception ex)
{
Utils.WriteLine("EditRangeVehicles error: " + ex.ToString(), ConsoleColor.Red);
}
}
}
this.Invoke((MethodInvoker)delegate
{
HandleResp(reps);
});
}
}
private async void AddRangeVehiclesAsync()
{
btnAdd.Enabled = btnExit.Enabled = false;
await Task.Run(() => AddRangeVehicles());
btnAdd.Enabled = btnExit.Enabled = true;
}
private void AddRangeVehicles()
{
if (!tbPattern.Text.Contains("#"))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("unitnamepatternerr"), MainForm.returnLNGString("err"));
return;
}
if (tbImeiEnd.Value - tbImeiStart.Value + 1 + MainForm.numberOfActiveUnits - MainForm.totalUnits > 0 && cbStatus.Text.Equals(MainForm.returnLNGString("active")))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, string.Format(MainForm.returnLNGString("maxUnitsCanAdd"), MainForm.totalUnits - MainForm.numberOfActiveUnits), MainForm.returnLNGString("err"));
return;
}
String testID = TestUniqueIDinRange((Int32)tbImeiStart.Value, (Int32)tbImeiEnd.Value);
if (testID.Length == 0)
{
Hashtable HashOfNames = GetUnitsIdAndNameFromPatter(tbPattern.Text, (Int32)tbImeiStart.Value, (Int32)tbImeiEnd.Value);
String testName = TestUniqueNameinRange(HashOfNames);
if (testName.Length == 0)
{
//We do the insert
int carID = ((Car)((RadListDataItem)cbImageList.SelectedItem).Value).idx;
int gw_id = 0;
int radio_id = 0;
if (cbGatewayAndRadioGW.SelectedItems.Count == 0 )
{
MessageBox.Show("Please select a gateway !");
return;
}
if (((RadioGateway)cbGatewayAndRadioGW.SelectedItems[0].Value) != null)
{
gw_id = (int)((RadioGateway)cbGatewayAndRadioGW.SelectedItems[0].Value).Gw_id;
radio_id = ((RadioGateway)cbGatewayAndRadioGW.SelectedItems[0].Value).Id;
}
vehResponse reps =
(MainForm.IS_SIERRA_WIRELESS ?
DB.addRangeVehicleSierraToDb(HashOfNames, cbUserforImei.Text, "", 0, true,
(Int32)tbGPSreportingInterval.Value, carID, (Int32)tbGPSPOOR.Value,
(Int32)tbGPSOFF.Value, (Int32)tbMADEOFF.Value, (Int32)tbARSreportingInterval.Value, tbEmailPattern.Text, gw_id, radio_id, cbStatus.Text.Equals(MainForm.returnLNGString("active")), cbUnitType.SelectedIndex)
:
DB.addRangeVehicleToDb(HashOfNames, cbUserforImei.Text, "", 0, true,
(Int32)tbGPSreportingInterval.Value, carID, (Int32)tbGPSPOOR.Value,
(Int32)tbGPSOFF.Value, (Int32)tbMADEOFF.Value, (Int32)tbARSreportingInterval.Value, gw_id, radio_id, cbStatus.Text.Equals(MainForm.returnLNGString("active")), cbUnitType.SelectedIndex));
//MainForm.CallWebServer(MainForm.RestartSipLink);
//add group relation
ArrayList listof_Sc_id = DB.getListofSCID(HashOfNames);
List<Int32> scIds = new List<int>();
foreach (Int32 scId in listof_Sc_id)
scIds.Add(scId);
if (cbGroups.SelectedItem != null)
{
if (cbGroups.Text != MainForm.returnLNGString("none"))
{
int grID = listCategory[cbGroups.SelectedIndex - 1].Id;
DBgrp.AddRangeGroupElement(listof_Sc_id, grID, GroupType.CATEGORY.value);
}
}
if (cbTalkGroup.SelectedItem != null)
{
if (cbTalkGroup.Text != MainForm.returnLNGString("none"))
{
int grID = listRadioTalk[cbTalkGroup.SelectedIndex - 1].Id;
DBgrp.AddRangeGroupElement(listof_Sc_id, grID, GroupType.RADIOTALK.value);
}
}
//add telemetry objs
if ( listof_Sc_id.Count > 0 && ((MainForm.radioType == RADIOTYPE.MOTO) || (MainForm.radioType == RADIOTYPE.REPEATER_TRBO) || (((RadListDataItem)cbUnitType.SelectedItem).Text).ToLower() == DeviceType.RADIO.ToString().ToLower()))
{
for (int i = 1; i < 6; i++)
{
TelemetryObj obj = new TelemetryObj(0, i, "IN", "Low", "Digital " + i, false);
try
{
DBtel.addRangeTelemetryObj(obj, listof_Sc_id);
}
catch (Exception ex)
{
SM.Debug("ERROR ADD tel obj for digital " + i);
SM.Debug(ex.ToString());
}
}
}
int sc_id = 0;
if (scIds.Count > 0)
sc_id = scIds[0];
// add Alarm entity in the database for all the units with the default values
Alarm alm = new Alarm(0, sc_id, "1", "", "", "", "", "", true, true, true, true, true, true, true, true);
try
{
if (scIds.Count > 0)
{
List<AdminAlerts> alerts = new List<AdminAlerts>() { AdminAlerts.ALARM_ON_EMAIL, AdminAlerts.EMERGENCY, AdminAlerts.EMERGENCY_POPUP,
AdminAlerts.EMERGENCY_SOUND, AdminAlerts.GEOFENCE, AdminAlerts.GEOFENCE_POPUP, AdminAlerts.GEOFENCE_SOUND, AdminAlerts.LANDMARK,
AdminAlerts.LONE_WORKER, AdminAlerts.SPEED, AdminAlerts.SPEED_POPUP, AdminAlerts.SPEED_SOUND, AdminAlerts.TELEMETRY_POPUP, AdminAlerts.TELEMETRY_SOUND};
DBalarm.insertAlarm4ScIds(alm, scIds, alerts);
}
//resp = DBalarm.deleteAlarm(radioID);
//resp = DBalarm.addAlarm(alm, radioID);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return;
}
this.Invoke((MethodInvoker)delegate
{
HandleResp(reps);
});
// send restarts
parrent.SendRestart();
}
else
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("vehNameUnique") + "\n " + MainForm.returnLNGString("wehavedouble") + ":" + testName, MainForm.returnLNGString("err"));
}
}
else
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("imeiUnique") + "\n " + MainForm.returnLNGString("wehavedouble") + ":" + testID, MainForm.returnLNGString("err"));
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
//utils
private void HandleResp(vehResponse resp)
{
switch (resp)
{
case vehResponse.done:
if (!formTypeEdit)
{
//RadMessageBox.Show("Unit Added to Database", "Done!", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
CustomMessageBox.Show(CustomMessageBoxType.check, MainForm.returnLNGString("unadd"), MainForm.returnLNGString("done"));
this.Close();
}
else
{
//RadMessageBox.Show("Unit edited!", "Done!", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
CustomMessageBox.Show(CustomMessageBoxType.check, MainForm.returnLNGString("unsave"), MainForm.returnLNGString("done"));
clearVehicleInfo();
this.Close();
}
break;
case vehResponse.alreadyInDB:
//RadMessageBox.Show("Unit Already in Database", "error!", MessageBoxButtons.OK, RadMessageIcon.Error);
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("allin"), MainForm.returnLNGString("err"));
break;
case vehResponse.SQLerror:
//RadMessageBox.Show("SQL error", "error!", MessageBoxButtons.OK, RadMessageIcon.Error);
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("dberr"), MainForm.returnLNGString("err"));
break;
case vehResponse.vehNontInDB:
//RadMessageBox.Show("Unit not in DB", "error!", MessageBoxButtons.OK, RadMessageIcon.Error);
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("unitnot"), MainForm.returnLNGString("err"));
break;
}
}
private void clearVehicleInfo()
{
tbImei.Text = "";
tbVehicleName.Text = "";
cbUserforImei.SelectedIndex = 0;
cbGroups.SelectedIndex = 0;
}
private void cbImageList_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
try
{
//multiple edit
if (imageList1.Images.Count < cbImageList.Items.Count && cbImageList.SelectedIndex == cbImageList.Items.Count-1) pictureBox1.Image = null;
else
{
pictureBox1.Image = imageList1.Images[cbImageList.SelectedIndex];
}
}
catch (Exception ex)
{
Console.WriteLine("Erorr load picture " + ex.Message + "::" + ex.StackTrace);
}
}
private void AdvSettings_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (!AdvSettingsCollapse)
{
AdvSettingsCollapse = true;
AdvSettings.Text = MainForm.returnLNGString("hideadvSettings");
this.Size = new Size(this.Size.Width, this.Size.Height + 100);
int startX = panelUnitUI.Location.X + lbReportingInterval.Location.X;
int startY = panelUnitUI.Location.Y + lbReportingInterval.Location.Y;
lbGPSPOOR.Location = new Point(startX, startY + 50);
lbGPSOFF.Location = new Point(startX, startY + 79);
lbMADEOFF.Location = new Point(startX, startY + 104);
lbGPSPOOR.Visible = true;
lbGPSOFF.Visible = true;
lbMADEOFF.Visible = true;
startX = panelUnitUI.Location.X + cbUserforImei.Location.X;
tbGPSPOOR.Location = new Point(startX + 50, startY + 50);
tbGPSOFF.Location = new Point(startX + 50, startY + 75);
tbMADEOFF.Location = new Point(startX + 50, startY + 100);
tbGPSPOOR.Visible = true;
tbGPSOFF.Visible = true;
tbMADEOFF.Visible = true;
radTextBox4.Location = new Point(startX + 50, startY + 50);
radTextBox3.Location = new Point(startX + 50, startY + 75);
radTextBox2.Location = new Point(startX + 50, startY + 100);
radTextBox4.Visible = true;
radTextBox3.Visible = true;
radTextBox2.Visible = true;
lbSecWithOUTPOOR.Location = new Point(lbSec.Location.X - 60, lbSec.Location.Y + 50);
lbSecWithOUTOFF.Location = new Point(lbSec.Location.X - 60, lbSec.Location.Y + 75);
lbSecWithOUTMADEOFF.Location = new Point(lbSec.Location.X - 60, lbSec.Location.Y + 100);
lbSecWithOUTPOOR.Visible = true;
lbSecWithOUTOFF.Visible = true;
lbSecWithOUTMADEOFF.Visible = true;
radLabel11.Location = new Point(lbSec.Location.X, lbSec.Location.Y + 50);
radLabel12.Location = new Point(lbSec.Location.X, lbSec.Location.Y + 75);
radLabel13.Location = new Point(lbSec.Location.X, lbSec.Location.Y + 100);
radLabel11.Visible = true;
radLabel12.Visible = true;
radLabel13.Visible = true;
Int32 valX = 90;
lbGroup.Location = new Point(lbGroup.Location.X, lbGroup.Location.Y + valX);
lbIcon.Location = new Point(lbIcon.Location.X, lbIcon.Location.Y + valX);
lbARSinterval.Location = new Point(lbARSinterval.Location.X, lbARSinterval.Location.Y + valX);
lbARSintervalSeconds.Location = new Point(lbARSintervalSeconds.Location.X, lbARSintervalSeconds.Location.Y + valX);
cbGroups.Location = new Point(cbGroups.Location.X, cbGroups.Location.Y + valX);
cbImageList.Location = new Point(cbImageList.Location.X, cbImageList.Location.Y + valX);
tbARSreportingInterval.Location = new Point(tbARSreportingInterval.Location.X, tbARSreportingInterval.Location.Y + valX);
pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y + valX);
radLabel6.Location = new Point(radLabel6.Location.X, radLabel6.Location.Y + valX);
radLabel7.Location = new Point(radLabel7.Location.X, radLabel7.Location.Y + valX);
radLabel9.Location = new Point(radLabel9.Location.X, radLabel9.Location.Y + valX);
cbGatewayAndRadioGW.Location = new Point(cbGatewayAndRadioGW.Location.X, cbGatewayAndRadioGW.Location.Y + valX);
cbStatus.Location = new Point(cbStatus.Location.X, cbStatus.Location.Y + valX);
cbTalkGroup.Location = new Point(cbTalkGroup.Location.X, cbTalkGroup.Location.Y + valX);
btnAdd.Location = new Point(btnAdd.Location.X, btnAdd.Location.Y + valX);
btnExit.Location = new Point(btnExit.Location.X, btnExit.Location.Y + valX);
}
else
{
AdvSettingsCollapse = false;
AdvSettings.Text = MainForm.returnLNGString("advSettings");
this.Size = new Size(this.Size.Width, this.Size.Height -100);
lbGPSPOOR.Visible = false;
lbGPSOFF.Visible = false;
lbMADEOFF.Visible = false;
tbGPSPOOR.Visible = false;
tbGPSOFF.Visible = false;
tbMADEOFF.Visible = false;
radTextBox2.Visible = false;
radTextBox3.Visible = false;
radTextBox4.Visible = false;
lbSecWithOUTPOOR.Visible = false;
lbSecWithOUTOFF.Visible = false;
lbSecWithOUTMADEOFF.Visible = false;
radLabel11.Visible = false;
radLabel12.Visible = false;
radLabel13.Visible = false;
Int32 valX = - 90;
lbGroup.Location = new Point(lbGroup.Location.X, lbGroup.Location.Y + valX);
lbIcon.Location = new Point(lbIcon.Location.X, lbIcon.Location.Y + valX);
lbARSinterval.Location = new Point(lbARSinterval.Location.X, lbARSinterval.Location.Y + valX);
lbARSintervalSeconds.Location = new Point(lbARSintervalSeconds.Location.X, lbARSintervalSeconds.Location.Y + valX);
cbGroups.Location = new Point(cbGroups.Location.X, cbGroups.Location.Y + valX);
cbImageList.Location = new Point(cbImageList.Location.X, cbImageList.Location.Y + valX);
tbARSreportingInterval.Location = new Point(tbARSreportingInterval.Location.X, tbARSreportingInterval.Location.Y + valX);
pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y + valX);
radLabel6.Location = new Point(radLabel6.Location.X, radLabel6.Location.Y + valX);
radLabel7.Location = new Point(radLabel7.Location.X, radLabel7.Location.Y + valX);
radLabel9.Location = new Point(radLabel9.Location.X, radLabel9.Location.Y + valX);
cbGatewayAndRadioGW.Location = new Point(cbGatewayAndRadioGW.Location.X, cbGatewayAndRadioGW.Location.Y + valX);
cbStatus.Location = new Point(cbStatus.Location.X, cbStatus.Location.Y + valX);
cbTalkGroup.Location = new Point(cbTalkGroup.Location.X, cbTalkGroup.Location.Y + valX);
btnAdd.Location = new Point(btnAdd.Location.X, btnAdd.Location.Y + valX);
btnExit.Location = new Point(btnExit.Location.X, btnExit.Location.Y + valX);
}
}
private void tbGPSreportingInterval_ValueChanged(object sender, EventArgs e)
{
radTextBox1.Text = tbGPSreportingInterval.Value.ToString();
tbGPSPOOR.Value = tbGPSreportingInterval.Value * 2;
tbGPSOFF.Value = tbGPSreportingInterval.Value * 4;
tbMADEOFF.Value = tbGPSreportingInterval.Value * 10;
}
private void VehiclesForm_Load(object sender, EventArgs e)
{
//remove unittype smartphone for simoco
//if (MainForm.radioType == RADIOTYPE.SIMOCO)
if (MainForm.radioType != RADIOTYPE.LINX)
{
if (MainForm.hideLinxFeatures)
cbUnitType.Items.RemoveAt(1);
}
//originalFormSize = this.Size;
this.Size = btEditMobile.Visible ? new Size(644, 545) : new Size(321, 545);
(Pageview.ViewElement as RadPageViewStripElement).ShowItemCloseButton = false;
(Pageview.ViewElement as RadPageViewStripElement).StripButtons = StripViewButtons.Scroll;
pagSingle.Text = MainForm.returnLNGString("SingleUnit");
pagSingle.Image = new Bitmap(Properties.Resources.car_214, new Size(16, 16));
pagRange.Text = MainForm.returnLNGString("RangeofUnits");
pagRange.Image = new Bitmap(Properties.Resources.cars_214, new Size(16, 16));
if (isMultiEdit)
{
pagSingle.Text = MainForm.returnLNGString("editgrp");
pagSingle.Image = new Bitmap(Properties.Resources.cars_214, new Size(16, 16));
}
// create the toolTip that will be displayed when the user sets a pattern
// over the hint pictureBox
toolTipHelp = new ToolTip();
toolTipHelp.ToolTipTitle = MainForm.returnLNGString("IMEIRange");
toolTipHelp.AutoPopDelay = 0;
toolTipHelp.InitialDelay = 0;
toolTipHelp.ReshowDelay = 0;
toolTipHelp.IsBalloon = false;
toolTipHelp.ShowAlways = true;
RefreshSelectedPage();
radioGWList = DBgateways.gelAllGatewaysAndRadioGateways();
radioGWList.Insert(0,new RadioGateway(){Gw_id = -1, Id = -1, Name = MainForm.returnLNGString("none") });
if (!isMultiEdit)
{
//foreach (RadioGateway rg in radioGWList)
//{
// RadListDataItem test2 = new RadListDataItem(grp.Name);
// cbGatewayAndRadioGW.Items.Add(test2);
//}
cbGatewayAndRadioGW.DataSource = radioGWList;
cbGatewayAndRadioGW.DisplayMember = "name";
if (formTypeEdit)
{
cbStatus.SelectedIndex = (selVeh.Active) ? 0 : 1;
cbUnitType.SelectedIndex = selVeh.Type;
cbGatewayAndRadioGW.SelectedIndex = 0;
for(int i = 0 ; i < radioGWList.Count; i++)
{
RadioGateway radio = radioGWList[i];
if (radio.Id == selVeh.Radio_gw_id && radio.Gw_id == selVeh.Gw_id)
{
cbGatewayAndRadioGW.SelectedIndex = i;
break;
}
}
}
else
{
cbGatewayAndRadioGW.SelectedIndex = 0;
}
}
else
{
List<RadioGateway> radioGWListMulti = DBgateways.gelAllGatewaysAndRadioGateways(IDList);
if (radioGWListMulti.Count() > 1)
{
//radioGWList.Insert(0, new RadioGateway() { Gw_id = -1, Id = -1, Name = "none" });
radioGWList.Insert(0, new RadioGateway() { Id = -1, Gw_id = -1, Name = MainForm.returnLNGString("multiple") });
//foreach (RadioGateway grp in radioGWList)
//{
// RadListDataItem test2 = new RadListDataItem(grp.Name);
// cbTalkGroup.Items.Add(test2);
//}
cbGatewayAndRadioGW.DataSource = radioGWList;
cbGatewayAndRadioGW.DisplayMember = "name";
//cbGatewayAndRadioGW.Items.Add("none");
cbGatewayAndRadioGW.SelectedIndex = 0;
}
else if (radioGWListMulti.Count == 1 || radioGWListMulti.Count == 0)
{
//foreach (RadioGateway grp in radioGWList)
//{
// RadListDataItem test2 = new RadListDataItem(grp.Name);
// cbTalkGroup.Items.Add(test2);
//}
//radioGWList.Insert(0, new RadioGateway() { Gw_id = -1, Id = -1, Name = "none" });
cbGatewayAndRadioGW.DataSource = radioGWList;
cbGatewayAndRadioGW.DisplayMember = "name";
//cbGatewayAndRadioGW.Items.Add("none");
if (radioGWListMulti.Count == 1)
{
cbGatewayAndRadioGW.SelectedIndex = 0;
for (int i = 0; i < radioGWList.Count; i++)
{
RadioGateway radio = radioGWList[i];
if (radio.Id == radioGWListMulti[0].Id && radio.Gw_id == radioGWListMulti[0].Gw_id)
{
cbGatewayAndRadioGW.SelectedIndex = i;
break;
}
}
}
}
}
if (!MainForm.IS_SIERRA_WIRELESS)
{
Pageview.Size = new Size(313, 87);
panelUnitUI.Location = new Point(6, 98);
this.Size = new Size(this.Size.Width, this.Size.Height - 53);
}
else if (isMultiEdit)
{
tbEmail.Enabled = false;
tbPhone.Enabled = false;
}
hasModifiedMobile = false;
mobile = new MobileVehicles();
if(selVeh != null)
mobile = DB.getMobileVehicle(selVeh.Id);
isloaded = true;
if (canEditMobile) editMobileButtonVisible();
#region Disable SIP related features for Simoco
//hide gateway and radio gateway for simoco
radLabel6.Visible = cbGatewayAndRadioGW.Visible = (MainForm.radioType != RADIOTYPE.SIMOCO);
//hide radio talk group for simoco
if(radLabel9.Visible==true)
radLabel9.Visible = cbTalkGroup.Visible = (MainForm.radioType != RADIOTYPE.SIMOCO && MainForm.radioType != RADIOTYPE.EXCERA);
if(MainForm.radioType == RADIOTYPE.SIMOCO)
{
radLabel7.Location = radLabel6.Location;
btnExit.Location = new Point(btnExit.Location.X, cbStatus.Location.Y);
btnAdd.Location = new Point(btnAdd.Location.X, cbStatus.Location.Y);
cbStatus.Location = cbGatewayAndRadioGW.Location;
this.Size = new Size(this.Size.Width, this.Size.Height - 100);
}
#endregion Disable SIP related features for Simoco
tbEmail.TabStop = tbPhone.TabStop = MainForm.IS_SIERRA_WIRELESS;
initialGateway = cbGatewayAndRadioGW.Text;
initialStatus = cbStatus.Text;
setGatewayDropDown();
if (MainForm.radioType == RADIOTYPE.LINX)
{
cbUnitType.SelectedIndex = 1;
cbUnitType.Enabled = false;
}
if (MainForm.radioType == RADIOTYPE.LINXB)
{
updateLinxGroup();
}
}
private void updateLinxGroup()
{
if (!isMultiEdit)
{
if (((((RadListDataItem)cbUnitType.SelectedItem).Text).ToLower() == DeviceType.SMARTPHONE.ToString().ToLower()))
{
cbTalkGroup.Items.Clear();
RadListDataItem test5 = new RadListDataItem(MainForm.returnLNGString("none"));
cbTalkGroup.Items.Add(test5);
int currentGrp = -1;
int id = selVeh == null ? -1 : selVeh.Id;
listRadioTalk = DBgrp.getAllTalkGroupsAvailableForLinx(id, out currentGrp);
if (listRadioTalk.Count() > 0)
{
cbTalkGroup.SelectedIndex = 0;
foreach (Group grp in listRadioTalk)
{
test5 = new RadListDataItem(grp.Name);
cbTalkGroup.Items.Add(test5);
}
radLabel9.Visible = cbTalkGroup.Visible = true;
int count = 0;
foreach (Group grp in listRadioTalk)
{
count++;
if (grp.Id == currentGrp)
{
cbTalkGroup.SelectedIndex = count;
}
}
}
}
else
{
radLabel9.Visible = cbTalkGroup.Visible = false;
}
}
}
private void pbHint_MouseEnter(object sender, EventArgs e)
{
DisplayToolTip();
}
private void pbHint_MouseLeave(object sender, EventArgs e)
{
toolTipHelp.Hide(pbHint);
}
private void pbHint_MouseHover(object sender, EventArgs e)
{
DisplayToolTip();
}
private void DisplayToolTip()
{
String unitsExample = "";
if (tbPattern.Text.Contains("#"))
{
for (int i = (Int32)tbImeiStart.Value; i <= (Int32)tbImeiEnd.Value; i++)
{
// add only first 3 values
if (i < (Int32)tbImeiStart.Value + 3 || i > (Int32)tbImeiEnd.Value - 3)
{
string crtUnitName = "";
try
{
Hashtable hash = GetUnitsIdAndNameFromPatter(tbPattern.Text, i, i);
foreach(DictionaryEntry pair in hash)
{
crtUnitName = pair.Value.ToString();
}
}
catch (Exception ex)
{
Console.WriteLine("EXCEPTION EX" + ex.ToString());
continue;
}
unitsExample += "\t" + crtUnitName + Environment.NewLine;
}
else if (i == (Int32)tbImeiStart.Value + 3 && ((Int32)tbImeiEnd.Value - (Int32)tbImeiStart.Value > 5))
{
unitsExample += "\t" + "..." + Environment.NewLine;
}
}
}
// number of seconds for the toolTip to be shown
toolTipHelp.Show(
String.Format(string.Format(MainForm.returnLNGString("toolTipRange"),Environment.NewLine)
+ unitsExample)
, pbHint, 150000);
}
/// <summary>
/// Get the list of units with their corresponding ID based on the patter between the
/// start id and the end id
/// </summary>
/// <returns>A hash list containing the ID as a key and the unit name as the value</returns>
private Hashtable GetUnitsIdAndNameFromPatter(string pattern, Int32 idStart, Int32 idEnd)
{
Hashtable hash = new Hashtable();
// check if the pattern has the desired characters
if (pattern.Contains("#"))
{
int count = 0;
int firstPosition = -1;
// the list of ### sequence and their number of apparences
// the list will be position#number
List<string> apparenceList = new List<string>();
for (int i = 0; i < tbPattern.Text.Length; i++)
{
// check if the current character is a # and count it
if (tbPattern.Text[i].Equals('#'))
{
// i didn't found any # until now
if (firstPosition == -1)
{
firstPosition = i;
count = 1;
}
else
count++;
}
else
{
// add into hash the position of the first apparence and it's count
if (firstPosition != -1)
{
apparenceList.Insert(0, firstPosition + "#" + count);
//apparenceCount.Add(firstPosition, count);
// reset values
firstPosition = -1;
count = 0;
}
}
}
// check if the string is ending in a #
if (firstPosition != -1)
{
apparenceList.Insert(0, firstPosition + "#" + count);
//apparenceCount.Add(firstPosition, count);
// reset values
firstPosition = -1;
count = 0;
}
// for each unit id selected in the number picker I should generate a unit
for (int i = idStart; i <= idEnd; i++)
{
// the current unit name for this ID
string crtUnitName = tbPattern.Text;
// search for all ### sequences
foreach (String str in apparenceList)
{
// split the position - count correspondence for this ### sequence
string[] positionCount = str.Split(new char[] { '#' });
// remove the current ### sequence from the pattern
crtUnitName = crtUnitName.Remove(int.Parse(positionCount[0]), int.Parse(positionCount[1]));
// create the 000 mask for current ### sequence
string mask = "";
for (int j = 0; j < int.Parse(positionCount[1]); j++)
mask += "0";
// insert the unit id on using the desired pattern
crtUnitName = crtUnitName.Insert(int.Parse(positionCount[0]), String.Format("{0:" + mask + "}", i));
}
// add the created unitName to the hash with its ID
if (!hash.ContainsKey(i))
hash.Add(i, crtUnitName);
}
}
return hash;
}
/// <summary>
/// Prevent the Numberic UpDown to past one over the other.
/// Meaning that the start should always be smaller that the End one
/// </summary>
private void numericValueChanged(object sender, EventArgs e)
{
if (sender == tbImeiStart)
{
tbImeiEnd.Minimum = tbImeiStart.Value;
}
else if (sender == tbImeiEnd)
{
//tbImeiStart.Maximum = tbImeiEnd.Value;
}
}
private void Pageview_SelectedPageChanged(object sender, EventArgs e)
{
RefreshSelectedPage();
editMobileButtonVisible();
#region Disable SIP related features for Simoco
if (MainForm.radioType == RADIOTYPE.SIMOCO)
{
radLabel9.Visible = cbTalkGroup.Visible = false;
this.Size = new Size(this.Size.Width, this.Size.Height - 150);
}
#endregion Disable SIP related features for Simoco
}
public void RefreshSelectedPage()
{
try
{
if (Pageview.SelectedPage.Name == "pagRange")
AddRange = true;
else AddRange = false;
}
catch (Exception ex)
{
SM.Debug("radTabStrip1_TabSelected:" + ex.ToString());
}
}
private void pagSingle_Paint(object sender, PaintEventArgs e)
{
}
private void radTextBox_TextChanged(object sender, EventArgs e)
{
switch(((RadTextBox)sender).Name)
{
case "radTextBox1":
if (radTextBox1.Text != "")
{
if (Convert.ToDecimal(radTextBox1.Text) >= 10) tbGPSreportingInterval.Value = Convert.ToDecimal(radTextBox1.Text);
}
break;
case "radTextBox2":
if (radTextBox2.Text != "")
{
if (Convert.ToDecimal(radTextBox2.Text) >= 10) tbMADEOFF.Value = Convert.ToDecimal(radTextBox2.Text);
}
break;
case "radTextBox3":
if (radTextBox3.Text != "")
{
if (Convert.ToDecimal(radTextBox3.Text) >= 10) tbGPSOFF.Value = Convert.ToDecimal(radTextBox3.Text);
}
break;
case "radTextBox4":
if (radTextBox4.Text != "")
{
if (Convert.ToDecimal(radTextBox4.Text) >= 10) tbGPSPOOR.Value = Convert.ToDecimal(radTextBox4.Text);
}
break;
default:
break;
}
}
private void radTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if(char.IsNumber(e.KeyChar))
{ }
else
{
e.Handled = e.KeyChar != (char)Keys.Back;
}
}
private void tbMADEOFF_ValueChanged(object sender, EventArgs e)
{
radTextBox2.Text = tbMADEOFF.Value.ToString();
}
private void tbGPSOFF_ValueChanged(object sender, EventArgs e)
{
radTextBox3.Text = tbGPSOFF.Value.ToString();
}
private void tbGPSPOOR_ValueChanged(object sender, EventArgs e)
{
radTextBox4.Text = tbGPSPOOR.Value.ToString();
}
private void cbUnitType_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
editMobileButtonVisible();
setGatewayDropDown();
}
private void editMobileButtonVisible()
{
if (cbUnitType.SelectedItem == null)
cbUnitType.SelectedItem = cbUnitType.Items[0];
btEditMobile.Visible = canEditMobile = ((((RadListDataItem)cbUnitType.SelectedItem).Text).ToLower() == DeviceType.SMARTPHONE.ToString().ToLower() && !AddRange);
//btEditMobile.Visible = ((((RadListDataItem)cbUnitType.SelectedItem).Text).ToLower() == DeviceType.MOBILE.ToString().ToLower() && formTypeEdit == true && isMultiEdit == false);
//radLabel9.Visible = cbTalkGroup.Visible = ((((RadListDataItem)cbUnitType.SelectedItem).Text).ToLower() == DeviceType.RADIO.ToString().ToLower());
radLabel9.Visible = cbTalkGroup.Visible = false;
this.Size = btEditMobile.Visible ? new Size(644, 545) : new Size(321, 545);
if(isloaded) btEditMobile.PerformClick();
if(cbUnitType.SelectedIndex == 1) cbTalkGroup.SelectedIndex = 0;
btEditMobile.Visible = false;
}
List<RadioGateway> radioGWList = null;
private void setGatewayDropDown()
{
if (radioGWList == null)
return;
if (cbUnitType.SelectedItem.Text.ToUpper() == DeviceType.RADIO.ToString())
{
for (int i = 0; i < cbGatewayAndRadioGW.Items.Count; i++)
{
if (((RadioGateway)((RadListDataItem)cbGatewayAndRadioGW.Items[i]).Value) != null &&
((RadioGateway)((RadListDataItem)cbGatewayAndRadioGW.Items[i]).Value).Type == (int)GatewayType.Broadband)
cbGatewayAndRadioGW.Items.RemoveAt(i);
}
cbGatewayAndRadioGW.Enabled = true;
if(!formTypeEdit)
cbGatewayAndRadioGW.SelectedIndex = 0;
return;
}
else if (cbUnitType.SelectedItem.Text.ToUpper() == DeviceType.SMARTPHONE.ToString())
{
radioGWList = DBgateways.gelAllGatewaysAndRadioGateways();
radioGWList.Insert(0, new RadioGateway() { Gw_id = -1, Id = -1, Name = MainForm.returnLNGString("none") });
cbGatewayAndRadioGW.DataSource = radioGWList;
int count = 0;
cbGatewayAndRadioGW.Enabled = false;
foreach (var item in cbGatewayAndRadioGW.Items)
{
if (((RadioGateway)((RadListDataItem)item).Value).Type == (int)GatewayType.Broadband)
{
cbGatewayAndRadioGW.SelectedIndex = count;
}
count++;
}
}
else
{
var gwList = new List<RadioGateway>();
gwList.Insert(0, new RadioGateway() { Id = -1, Gw_id = -1, Name = MainForm.returnLNGString("multiple") });
//RadListDataItem test2 = new RadListDataItem("Multiple");
cbGatewayAndRadioGW.DataSource = gwList;
cbGatewayAndRadioGW.DisplayMember = "name";
//cbGatewayAndRadioGW.Items.Add("none");
cbGatewayAndRadioGW.SelectedIndex = 0;
//cbGatewayAndRadioGW.Items.Add(test2);
cbGatewayAndRadioGW.Enabled = false;
initialGateway = MainForm.returnLNGString("multiple");
//cbGatewayAndRadioGW.SelectedIndex = 0;
}
}
private void btEditMobile_Click(object sender, EventArgs e)
{
Int64 temp = 0;
//if (!Int64.TryParse(tbImei.Text, out temp) && (!isMultiEdit))
//{
// CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("ImeiNotInt"), MainForm.returnLNGString("err"));
// return;
//}
//else
//{
if (temp > 1677721)
{
if(!MainForm.hideLinxFeatures)
CustomMessageBox.Show(CustomMessageBoxType.exclamation, string.Format(MainForm.returnLNGString("ImeiLessThan"), 1677721), MainForm.returnLNGString("warning"));
}
//}
if (selVeh != null)
{
if (!hasModifiedMobile)
mobile = DB.getMobileVehicle(selVeh.Id);
mobile.Id = selVeh.Id;
isNEW = false;
}
else
{
if (mobile == null) mobile = new MobileVehicles();
isNEW = true;
}
vmf = new VehiclesMobileForm(tbImei.Text, tbVehicleName.Text);
vmf.TopLevel = false;
panelMobileForm.Controls.Add(vmf);
vmf.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
vmf.Show();
}
private void tbImei_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar >= '0' && e.KeyChar <= '9') || e.KeyChar == (char)Keys.Back)
; // ok
else
e.Handled = true;
}
private void tbImei_TextChanged(object sender, EventArgs e)
{
if (vmf != null)
{
vmf.tbRadioIMEI.Text = tbImei.Text;
}
}
}
}