SafeDispatch/Safedispatch_4_0/NewSmsForm.cs

937 lines
40 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 Telerik.WinControls.UI;
using SafeMobileLib;
using Dispatcher.maptab.UIClasses;
namespace Safedispatch_4_0
{
public enum SMSmode
{
New4Unit, Reply, Forward, New
}
public partial class NewSmsForm : Telerik.WinControls.UI.RadForm
{
private const int MESSAGES_PER_SECOND = 5;
private enum MessageType { PRIVATE = 0, GROUP = 1, UNKNOWN = 2 };
private static MessageType msgType = MessageType.UNKNOWN;
private SMdb_access smdbObj;
private Hashtable VehNameHash;
//private ConvertDT convDT;
private SMSmode Smode;
private SMSuserControl parent;
ArrayList arVehSCID;
ArrayList arSelSCID;
public static Hashtable htGroupsKeyNAmeValueID;
private int maxCharsNumberForSMS = 0;
private RadTreeNode nodeToDisplayOnReply = null;
internal static NewSmsForm Instance;
private void setLanguage()
{
this.Text = MainForm2.returnLNGString("newSMS");
btnSend.Text = MainForm2.returnLNGString("send").FirstLetterToUpper();
labelPredefined.Text = MainForm2.returnLNGString("AddPred1");
labelSend.Text = MainForm2.returnLNGString("sendTo");
radLabel1.Text = MainForm2.returnLNGString("unit2BSent");
searchTextBox.NullText = MainForm2.returnLNGString("Typetosearchunit");
rcbSavePredefined.Text = MainForm2.returnLNGString("SaveAsPredSMS");
rcbCloseWindow.Text = MainForm2.returnLNGString("doNotCloseWinAfterSending");
labelText.Text = MainForm2.returnLNGString("textMessage");
rtbTextMessage.NullText = MainForm2.returnLNGString("write text message here");
radLabel9.Text = MainForm2.returnLNGString("schedSending");
labelCount.Text = String.Format(MainForm2.returnLNGString("charactersLeft"), maxCharsNumberForSMS);
//lbPredefineSMS.Text = MainForm2.returnLNGString("AddPred");
//gbAdressBook.Text = MainForm2.returnLNGString("AddrBook");
//lbAdreesBookHelp.Text = MainForm2.returnLNGString("clickTo");
//lbGroups.Text = MainForm2.returnLNGString("GrpGroups") + ':';
//lbUnits.Text = MainForm2.returnLNGString("GrpUnits") + ':';
//cbPredefineSMS.Text = MainForm2.returnLNGString("selpredadd");
}
public static NewSmsForm GetSingleton(SMSuserControl parent, SMSmode _smode, Hashtable htVehID, Hashtable htVehName, string selectedUnitOrGroupName, string text, SMdb_access db)
{
if (Instance == null)
Instance = new NewSmsForm(parent, _smode, htVehID, htVehName, selectedUnitOrGroupName, text, db);
else
{
if (Instance.IsDisposed)
Instance = new NewSmsForm(parent, _smode, htVehID, htVehName, selectedUnitOrGroupName, text, db);
}
Instance.Show();
Instance.BringToFront();
if (Instance.WindowState == FormWindowState.Minimized)
Instance.WindowState = FormWindowState.Normal;
return Instance;
}
public NewSmsForm(SMSuserControl parent, SMSmode _smode, Hashtable htVehID, Hashtable htVehName, string selectedUnitOrGroupName, string text, SMdb_access db)
{
this.parent = parent;
Smode = _smode;
InitializeComponent();
if (MainForm2.radioType != RADIOTYPE.MOTO)
{
pbGroups.Visible = false;
}
// set theme for the Message Box
RadMessageBox.SetThemeName("TelerikMetroBlue");
#region THEMING
btnSend.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
labelSend.ForeColor = labelText.ForeColor
= labelPredefined.ForeColor = MainForm2.LabelColor;
pbDelete.Image = Utils.ChangeColor(global::Dispatcher.Properties.Resources.trash_activ, MainForm2.ButtonColor);
// populate colors in the hashtable for private and group message
if (!MainForm2.imagesDictionary.ContainsKey("icon_cb_unit_enabled"))
MainForm2.imagesDictionary.Add("icon_cb_unit_enabled",
Utils.ChangeColor(Dispatcher.Properties.Resources.icon_cb_unit_enabled_ha, MainForm2.ButtonColor));
if (!MainForm2.imagesDictionary.ContainsKey("icon_cb_unit_disabled"))
MainForm2.imagesDictionary.Add("icon_cb_unit_disabled", Dispatcher.Properties.Resources.icon_cb_unit_disabled);
if (!MainForm2.imagesDictionary.ContainsKey("icon_cb_group_enabled"))
MainForm2.imagesDictionary.Add("icon_cb_group_enabled",
Utils.ChangeColor(Dispatcher.Properties.Resources.icon_cb_group_enabled_ha, MainForm2.ButtonColor));
if (!MainForm2.imagesDictionary.ContainsKey("icon_cb_group_disabled"))
MainForm2.imagesDictionary.Add("icon_cb_group_disabled", Dispatcher.Properties.Resources.icon_cb_group_disabled);
// get the last option selected for private or group text message
if (MainForm2.HashVal.ContainsKey("defaultTextMessageType") && msgType == MessageType.UNKNOWN)
{
if (MainForm2.HashVal["defaultTextMessageType"].ToString().Equals("GROUP"))
msgType = MessageType.GROUP;
else
msgType = MessageType.PRIVATE;
}
else
msgType = MessageType.PRIVATE;
// change UI according to the type of message that will be sent
pbMessageTypeClick(msgType == MessageType.PRIVATE ? pbPrivate : pbGroups, null);
rgbLeft.GroupBoxElement.Header.Border.TopColor = MainForm2.ButtonColor;
rgbLeft.GroupBoxElement.Header.Border.TopShadowColor = MainForm2.ButtonColor;
rgbRight.GroupBoxElement.Header.Border.TopColor = MainForm2.ButtonColor;
rgbRight.GroupBoxElement.Header.Border.TopShadowColor = MainForm2.ButtonColor;
#endregion
setLanguage();
btnSend.Enabled = false;
smdbObj = db;
VehNameHash = htVehName;
//convDT = new ConvertDT();
arVehSCID = new ArrayList();
arSelSCID = new ArrayList();
htGroupsKeyNAmeValueID = new Hashtable();
RefreshPredefinedText();
rtbTextMessage.Text += text;
// save current text message value
currentText = rtbTextMessage.Text;
/* if (!MainForm2.is24hours)
radDateTimePicker1.CustomFormat = "MM/dd/yyyy, hh:mm tt";*/
switch (Smode)
{
case SMSmode.New:
this.Text = MainForm2.returnLNGString("writenewSMS");
// TODO uncomment after group sms is done
if (MainForm2.radioType == RADIOTYPE.MOTO)
pbGroups.Visible = true;
pbPrivate.Visible = true;
break;
case SMSmode.New4Unit:
this.Text = MainForm2.returnLNGString("writenewSMS");
// message type if private for forward
msgType = MessageType.PRIVATE;
break;
case SMSmode.Forward:
this.Text = MainForm2.returnLNGString("FWmsg");
// TODO uncomment after group sms is done
if (MainForm2.radioType == RADIOTYPE.MOTO)
pbGroups.Visible = true;
pbPrivate.Visible = true;
break;
case SMSmode.Reply:
this.Text = MainForm2.returnLNGString("rpl") + selectedUnitOrGroupName;
//rtbTextMessage.Text += selectedUnitOrGroupName + ";";
//tbTO.Text += selectedUnitOrGroupName;
// message type if private for reply
msgType = MessageType.PRIVATE;
break;
}
PopulateTreeView(msgType);
// select the unit for which the reply if made
if (selectedUnitOrGroupName != null && selectedUnitOrGroupName.Length > 0)
{
// go through each group node
foreach (RadTreeNode groupNode in treeViewUnits.Nodes)
{
bool found = false;
// go through each unit node
foreach (RadTreeNode unitNode in groupNode.Nodes)
{
if (unitNode.Text.Equals(selectedUnitOrGroupName))
{
unitNode.Checked = true;
unitNode.Selected = true;
// save the desired node
nodeToDisplayOnReply = unitNode;
found = true;
break;
}
}
// collapse the group if the units is not in this one
//if (!found)
//groupNode.Collapse();
}
}
rdtpSchedule.CustomFormat = Utils.getDayCustomFormat(MainForm2.is24hours, MainForm2.DayFirst);
//if (MainForm2.is24hours)
//{
// if (MainForm2.DayFirst)
// rdtpSchedule.CustomFormat = "dd/MM/yyyy HH:mm";
// else
// rdtpSchedule.CustomFormat = "MM/dd/yyyy HH:mm";
//}
//else
//{
// if (MainForm2.DayFirst)
// rdtpSchedule.CustomFormat = "dd/MM/yyyy hh:mm tt";
// else
// rdtpSchedule.CustomFormat = "MM/dd/yyyy hh:mm tt";
//}
rdtpSchedule.Value = DateTime.Now;
if ((MainForm2.radioType != RADIOTYPE.MOTO) && (MainForm2.radioType != RADIOTYPE.LINX) && (MainForm2.radioType != RADIOTYPE.LINXB) && (MainForm2.radioType != RADIOTYPE.TETRA) && (MainForm2.radioType != RADIOTYPE.CONECTPLUS) && (MainForm2.radioType != RADIOTYPE.REPEATER_TRBO))
{
try
{
switch (MainForm2.radioType)
{
case RADIOTYPE.HYT:
this.Icon = global::Dispatcher.Properties.Resources.HytSmall24;
this.BackColor = MainForm2.HyteraColor;
break;
case RADIOTYPE.HARRIS:
this.Icon = global::Dispatcher.Properties.Resources.HarrisSmall;
//this.lbGroups.ForeColor = MainForm2.HarTextColor;
//this.lbUnits.ForeColor = MainForm2.HarTextColor;
break;
case RADIOTYPE.ATLAS:
this.Icon = global::Dispatcher.Properties.Resources.ATLICO32; //ATLASCHANGE
//this.lbGroups.ForeColor = MainForm2.HarTextColor;
//this.lbUnits.ForeColor = MainForm2.HarTextColor;
break;
case RADIOTYPE.SIMOCO:
this.Icon = global::Dispatcher.Properties.Resources.simoco_dispatch_24;
break;
case RADIOTYPE.EXCERA:
this.Icon = global::Dispatcher.Properties.Resources.AXYS_ICON;
break;
}
}
catch (Exception ex)
{
SM.Debug("Error on change color hytera/harris:" + ex.ToString());
}
}
}
private void btnSendSMS_Click(object sender, EventArgs e)
{
// disable the button
btnSend.Enabled = false;
searchTextBox.Text = "";
string sms = rtbTextMessage.Text;
sms = sms.Replace("\'", "\'\'");
if (rtbTextMessage.Text.Length > 0)
{
if (treeViewUnits.CheckedNodes.Count > 0 && msgType == MessageType.GROUP)
{
// go through each group and get the checked ones
foreach (RadTreeNode groupNode in treeViewUnits.CheckedNodes)
{
Group grp = ((Group)MainForm2.TalkGroups[(int)groupNode.Tag]);
if (grp.Type == (int)SafeMobileLib.GroupType.MOBILETALK.value)
{
parent.parent.SendSocketIoSMS("1234"/*change this!!*/, MainForm2.userIDX, grp.SipID, grp.CPS_Id, sms, true);
parent.parent.DisplayToast(MainForm2.returnLNGString("txtMsgToGrp") + " " + grp.Name, string.Format(MainForm2.returnLNGString("grpMSgHTML"), sms));
}
else
{
Int32 sched_time = (int)DateTime.Now.ToUniversalTime().DateTo70Format();
// get the scheduled time if needed
if (rcbSchedule.Checked)
sched_time = (int)rdtpSchedule.Value.ToUniversalTime().DateTo70Format();
// here is the new logic
if (grp.CPS_Id != 0)
{
InsertOneSMSinDB4Groups_with_cpsID(grp.CPS_Id, sms, sched_time);
parent.parent.DisplayToast(MainForm2.returnLNGString("txtMsgTo") + " " + groupNode.Text, string.Format(MainForm2.returnLNGString("MsHTML"), sms));
}
// old logic code is here, it was ment to work with groups without CPS id for MOTO or with cps id
else
{
//if (groupNode.Checked)
//{
//test if its a group
GroupClass g = new GroupClass();
foreach (int i in MainForm2.GroupHash.Keys)
{
g = (GroupClass)MainForm2.GroupHash[i];
if (g.name.ToLower().Equals(groupNode.Text.ToLower()))
{
// add a specific time if more than 10 messages needs to be sent in the same time
//if (shouldScheduleSomeMessages)
// sched_time += ((++scheduleDelayCount) / MESSAGES_PER_SECOND);
if ((MainForm2.radioType != RADIOTYPE.MOTO) && (MainForm2.radioType != RADIOTYPE.LINX) && (MainForm2.radioType != RADIOTYPE.ATLAS) && (MainForm2.radioType != RADIOTYPE.TETRA)
&& (MainForm2.radioType != RADIOTYPE.CONECTPLUS) && (MainForm2.radioType != RADIOTYPE.REPEATER_TRBO))
InsertOneSMSinDB4Groups_with_cpsID(g.cps_id, sms, sched_time);
else
{
if (MainForm2.radioType == RADIOTYPE.MOTO)
{
//if (g.cps_id!=0) parent.SendSMSGroupMotorola(sms, g.cps_id, sched_time, (Int32)g.arrSc_id[0]);
if (g.cps_id != 0)
{
InsertOneSMSinDB4Groups_with_cpsID(g.cps_id, sms, sched_time);
parent.parent.DisplayToast(MainForm2.returnLNGString("txtMsgTo") + " " + groupNode.Text, string.Format(MainForm2.returnLNGString("MsHTML"), sms));
}
else
{
InsertOneSMSinDB4Groups(g.arrSc_id, sms, sched_time);
parent.parent.DisplayToast(MainForm2.returnLNGString("txtMsgToGrp") + " " + g.arrSc_id, string.Format(MainForm2.returnLNGString("grpMSgHTML"), sms));
}
}
else
{
InsertOneSMSinDB4Groups(g.arrSc_id, sms, sched_time);
parent.parent.DisplayToast(MainForm2.returnLNGString("txtMsgToGrp") + " " + g.arrSc_id, string.Format(MainForm2.returnLNGString("grpMSgHTML"), sms));
}
}
}
// }
}
}
}
}
if (rcbSavePredefined.Checked)
{
// save the message as a predefined one
string preDef = rtbTextMessage.Text;
preDef = preDef.Replace("\'", "\'\'");
if (!rddlPredefined.Items.Contains(preDef))
{
bool b = smdbObj.Insert_Define_SMS(preDef);
if (b)
{
// add predefined text to the list and select it
rddlPredefined.Items.Add(preDef);
rddlPredefined.Text = preDef;
}
}
}
// close the window if no more message needs to be added
if (!rcbCloseWindow.Checked)
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
else
{
// MessageBox.Show("Message sent successfully");
rcbSavePredefined.Checked = false;
}
}
else if (treeViewUnits.CheckedNodes.Count > 0 && msgType == MessageType.PRIVATE)
{
//string dest = tbTO.Text;
//string[] units = dest.Split(';');
List<Int32> assignedUnitsIds = new List<Int32>();
List<String> assignedUnits = new List<string>();
// check all group nodes to see which one is checked
foreach (RadTreeNode groupNode in treeViewUnits.Nodes)
{
// skip groups with no unit checked
if (groupNode.CheckState == Telerik.WinControls.Enumerations.ToggleState.Off)
continue;
// go through each unit and get the checked ones
foreach (RadTreeNode unitNode in groupNode.Nodes)
{
if (unitNode.Checked)
{
assignedUnits.Add(unitNode.Name);
assignedUnitsIds.Add((Int32)unitNode.Tag);
}
}
}
String mess15 = MainForm2.returnLNGString("info");
String message = MainForm2.returnLNGString("limitSMSto10");
String question = MainForm2.returnLNGString("contorlessunits");
Boolean execute = false;
//test if you have more that 10
Int32 numberofInits = 0;
foreach (string unitNameOrGroup in assignedUnits)
{
try
{
if (VehNameHash.ContainsKey(unitNameOrGroup))
numberofInits++;
else
{
//test if its a group
GroupClass g = new GroupClass();
foreach (int i in MainForm2.GroupHash.Keys)
{
g = (GroupClass)MainForm2.GroupHash[i];
if (g.name == unitNameOrGroup)
{
if ((MainForm2.radioType != RADIOTYPE.ATLAS) && (MainForm2.radioType != RADIOTYPE.TETRA)
&& (MainForm2.radioType != RADIOTYPE.CONECTPLUS)
&& (MainForm2.radioType != RADIOTYPE.REPEATER_TRBO))
numberofInits++;
else
numberofInits += g.arrSc_id.Count;
}
}
}
}
catch (Exception ex)
{
SM.Debug("Ex:" + ex.ToString());
}
}
if ((numberofInits > 10) && ((MainForm2.radioType == RADIOTYPE.MOTO) || (MainForm2.radioType == RADIOTYPE.LINX) || (MainForm2.radioType == RADIOTYPE.LINXB) || (MainForm2.radioType == RADIOTYPE.ATLAS) || (MainForm2.radioType == RADIOTYPE.TETRA) || (MainForm2.radioType == RADIOTYPE.CONECTPLUS) || (MainForm2.radioType == RADIOTYPE.REPEATER_TRBO)))
{
execute = true;
}
else execute = true;
if (execute)
{
if (rcbSavePredefined.Checked)
{
// save the message as a predefined one
string preDef = rtbTextMessage.Text;
preDef = preDef.Replace("\'", "\'\'");
if (!rddlPredefined.Items.Contains(preDef))
{
bool b = smdbObj.Insert_Define_SMS(preDef);
if (b)
{
// add predefined text to the list and select it
rddlPredefined.Items.Add(preDef);
rddlPredefined.Text = preDef;
}
}
}
foreach (string unitNameOrGroup in assignedUnits)
{
try
{
if (VehNameHash.ContainsKey(unitNameOrGroup))
{
Int32 sched_time = (int)DateTime.Now.ToUniversalTime().DateTo70Format();
// get the scheduled time if needed
if (rcbSchedule.Checked)
sched_time = (int)rdtpSchedule.Value.ToUniversalTime().DateTo70Format();
InsertOneSMSinDB4units(unitNameOrGroup, sms, sched_time);
parent.parent.DisplayToast(MainForm2.returnLNGString("txtMsgTo") + " " + unitNameOrGroup, string.Format(MainForm2.returnLNGString("HTMLmessageToGW"), sms));
}
else
{
}
}
catch (Exception ex)
{
SM.Debug("Ex:" + ex.ToString());
}
}
// close the window if no more message needs to be added
if (!rcbCloseWindow.Checked)
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
else
{
rcbSavePredefined.Checked = false;
}
}
}
else
{
SM.Debug("Error NewSMSForm /btnSendSMS_Click/ message lenght =0 or no radio selected");
}
}
else
{
SM.Debug("Error NewSMSForm /btnSendSMS_Click/ message lenght =0 or no radio selected");
}
// enable the button
btnSend.Enabled = true;
}
private void InsertOneSMSinDB4units(string unitName, string sms, Int32 sched_time)
{
if (unitName != "")
{
if (VehNameHash.ContainsKey(unitName))
{
SM.Debug("Adding SMS to DB for unit:" + unitName);
int sc_id = ((Vehicle)MainForm2.vehicleHT[unitName]).sc_id;
parent.SendSMS(sms, sc_id, sched_time);
}
else
{
SM.Debug("Error NewSMSForm /InsertOneSMSinDB/ selected item(" + unitName + ") not in hashtable");
}
}
}
private void InsertOneSMSinDB4Groups(ArrayList scIDarray, string sms, Int32 sched_time)
{
if (scIDarray.Count > 0)
{
foreach (int scID in scIDarray)
{
SM.Debug("Adding SMS to DB for unit with scid:" + scID);
parent.SendSMS(sms, scID, sched_time);
}
}
}
private void InsertOneSMSinDB4Groups_with_cpsID(Int32 cps_id, string sms, Int32 sched_time)
{
try
{
SM.Debug("Adding SMS to DB for group with cpsid:" + cps_id);
//if (scIDarray.Count>0) parent.SendSMSGroup(sms,cps_id, sched_time,(Int32)scIDarray[0]);
parent.SendSMSGroup(sms, cps_id, sched_time);
}
catch (Exception ex)
{
SM.Debug("Exception on InsertOneSMSinDB4Groups_with_cpsID:" + ex.ToString());
}
}
private void RefreshPredefinedText()
{
rddlPredefined.Items.Clear();
rddlPredefined.Items.Add(MainForm2.returnLNGString("currCfg"));
try
{
ArrayList ar = smdbObj.get_all_DefSMS();
foreach (string sms in ar)
{
rddlPredefined.Items.Add(sms);
}
}
catch (Exception ex)
{
SM.Debug("Error in load predefine SMS\n\r" + ex.ToString());
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void cbPredefineSMS_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
rtbTextMessage.Text = "";
rtbTextMessage.Text += rddlPredefined.SelectedText;
}
/// <summary>
/// Update the number of left character when writing a new text message
/// </summary>
private void rtbTextMessage_KeyUp(object sender, KeyEventArgs e)
{
labelCount.Text = String.Format(MainForm2.returnLNGString("charactersLeft"), maxCharsNumberForSMS - rtbTextMessage.Text.Length);
currentText = rtbTextMessage.Text;
if (rddlPredefined.SelectedIndex != 0)
{
rddlPredefined.SelectedIndex = 0;
rtbTextMessage.Focus();
}
}
/// <summary>
/// Fix the bug of schedule date time picker and set the number of charachets left
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void NewSmsForm_Load(object sender, EventArgs e)
{
rdtpSchedule.MinDate = DateTime.Now;
rdtpSchedule.ThemeName = "Office2013Dark";
maxCharsNumberForSMS = SmsUtils.GetMaxNumberOfCharacters(MainForm2.radioType);
rtbTextMessage.MaxLength = maxCharsNumberForSMS;
labelCount.Text = String.Format(MainForm2.returnLNGString("charactersLeft"), maxCharsNumberForSMS - rtbTextMessage.Text.Length);
rcbSchedule.Checked = false;
rddlPredefined.SelectedIndex = 0;
// display the selected node in case of reply form
if (nodeToDisplayOnReply != null)
treeViewUnits.BringIntoView(nodeToDisplayOnReply);
rdtpSchedule.Visible = radLabel9.Visible = rcbSchedule.Visible = MainForm2.radioType != RADIOTYPE.LINX;
}
/// <summary>
/// Add the Groups as Nodes inside the Tree View
/// </summary>
private void populateListBoxGroup()
{
GroupClass g = new GroupClass();
if (msgType == MessageType.PRIVATE)
// for each group add a tree node
{
foreach (int i in MainForm2.GroupHash.Keys)
{
g = (GroupClass)MainForm2.GroupHash[i];
AddTreeGroup(g.name, g.id);
}
}
if (msgType == MessageType.GROUP)
{
Group grp = new Group();
foreach (int i in MainForm2.TalkGroups.Keys)
{
grp = (Group)MainForm2.TalkGroups[i];
AddTreeGroup(grp.Name, grp.Id);
}
}
}
/// <summary>
/// Add a Group Node to the Tree View
/// </summary>
/// <param name="groupName">Group name which needs to be added to the Tree Node</param>
/// <param name="groupID">Group ID which will be set as a tag for this group node</param>
/// <returns>Returns the inserted Tree Node</returns>
private RadTreeNode AddTreeGroup(string groupName, Int32 groupID)
{
RadTreeNode groupNode = new RadTreeNode(groupName.ToUpper());
groupNode.Font = new Font(
new FontFamily("Segoe UI"),
13,
FontStyle.Bold,
GraphicsUnit.Pixel);
groupNode.Tag = groupID;
groupNode.CheckState = Telerik.WinControls.Enumerations.ToggleState.Off;
groupNode.Expanded = true;
groupNode.Image = Utils.ChangeColor(global::Dispatcher.Properties.Resources.s_group, MainForm2.ButtonColor);
// add the node to the tree view
treeViewUnits.Nodes.Add(groupNode);
return groupNode;
}
private bool DefaultGroupAdded = false;
/// <summary>
/// Add Units to the groups nodes in the Tree View
/// </summary>
private void populateListBoxUnits()
{
// for each Unit defined in the hash table
foreach (DictionaryEntry de in MainForm2.vehicleHT)
{
Vehicle veh = de.Value as Vehicle;
if (veh != null)
{
RadTreeNode unitNode = new RadTreeNode(veh.busName);
unitNode.Tag = veh.sc_id;
Car crtCar = ((Car)MainForm2.carlist[((Vehicle)MainForm2.vehicleHT[veh.busName]).IconID]);
if (crtCar != null)
{
String iconPath = crtCar.listFilePath;
try
{
Bitmap bmp = new Bitmap(iconPath);
Image tmp2 = bmp; //tmp.ToBitmap();
tmp2.Tag = crtCar.listFilePath;
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey(crtCar.listFilePath + "_16"))
MainForm2.imagesDictionary.Add(crtCar.listFilePath + "_16", Utils.ScaleImage(tmp2, 16, 16));
// set the icon for the unit
unitNode.Image = MainForm2.imagesDictionary[crtCar.listFilePath + "_16"];
}
catch (Exception)
{
SM.Debug("Grid icon could not be found [" + iconPath + "]");
unitNode.Image = global::Dispatcher.Properties.Resources.subscriber;
}
}
// check to see if the unit is assigned to a group
if (veh.group != null && veh.group.Id != 0)
{
// the group already exists
}
else
{
// create Unassigned group if not created until now
if (!DefaultGroupAdded)
{
AddTreeGroup(MainForm2.returnLNGString("otherunit"), 0);
DefaultGroupAdded = true;
}
}
// search the group in which the unit will be added
foreach (RadTreeNode groupNode in treeViewUnits.Nodes)
{
Int32 groupID = (Int32)groupNode.Tag;
if (groupID == veh.group.Id)
groupNode.Nodes.Add(unitNode);
}
}
}
}
/// <summary>
/// Enable or disable the schedule date time picker
/// </summary>
private void rcbSchedule_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if ((RadCheckBox)sender == rcbSchedule)
rdtpSchedule.Enabled = rcbSchedule.Checked;
}
/// <summary>
/// Change the text of the text message based on the predefined one
/// </summary>
private string currentText = "";
private void rddlPredefined_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
if (rddlPredefined.SelectedIndex == 0)
{
pbDelete.Cursor = Cursors.Default;
pbDelete.Image = global::Dispatcher.Properties.Resources.trash_disabled;
pbDelete.Visible = false;
rtbTextMessage.Text = currentText;
}
else
{
pbDelete.Cursor = Cursors.Hand;
pbDelete.Image = global::Dispatcher.Properties.Resources.trash_activ;
pbDelete.Visible = true;
rtbTextMessage.Text = rddlPredefined.Text;
}
}
/// <summary>
/// Delete the selected predefined text message
/// </summary>
private void pbDelete_Click(object sender, EventArgs e)
{
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("addpred"), MainForm2.returnLNGString("confirm"), MessageBoxButtons.YesNo, RadMessageIcon.Exclamation);
if (dr == DialogResult.Yes)
{
try
{
string msgForDel = rddlPredefined.Text;
msgForDel = msgForDel.Replace("\'", "\'\'");
smdbObj.Delete_Define_SMS(msgForDel);
// remove old message and select first index
rddlPredefined.Items.RemoveAt(rddlPredefined.SelectedIndex);
rddlPredefined.SelectedIndex = 0;
}
catch (Exception ex)
{
SM.Debug("EX:" + ex.ToString());
}
}
}
/// <summary>
/// Enable or disable UI elements depending on the number of characters
/// </summary>
private void rtbTextMessage_TextChanged(object sender, EventArgs e)
{
if (treeViewUnits.CheckedNodes.Count > 0 && rtbTextMessage.Text.Length > 0)
btnSend.Enabled = true;
else
btnSend.Enabled = false;
}
/// <summary>
/// Change background color of the button when it becomes enable or disabled
/// </summary>
private void btnSend_EnabledChanged(object sender, EventArgs e)
{
if (btnSend.Enabled)
btnSend.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
else
btnSend.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColorDisabled;
}
/// <summary>
/// Change background color for the row according to its state and theme
/// </summary>
private void treeViewUnits_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
{
if (e.NodeElement.IsSelected)
{
e.NodeElement.DrawFill = true;
e.NodeElement.BackColor = MainForm2.GridSelectedRow;
e.NodeElement.NumberOfColors = 1;
}
else
e.NodeElement.DrawFill = false;
}
/// <summary>
/// Filter the tree node based on the text from the search box
/// </summary>
private void searchTextBox_TextChanged(object sender, EventArgs e)
{
treeViewUnits.Filter = null;
treeViewUnits.Filter = searchTextBox.Text;
}
/// <summary>
/// Validate form when a node is checked or unckhcked. This is done to prevent
/// the case when no unit is selected or text message is not filled
/// </summary>
private void treeViewUnits_NodeCheckedChanged(object sender, TreeNodeCheckedEventArgs e)
{
if (treeViewUnits.CheckedNodes.Count > 0 && rtbTextMessage.Text.Length > 0)
btnSend.Enabled = true;
else
btnSend.Enabled = false;
}
private void pbMessageTypeClick(object sender, EventArgs e)
{
// change the text message
labelSend.Text = (sender == pbPrivate ? MainForm2.returnLNGString("sendPrivateMessage") : MainForm2.returnLNGString("sendGroupMessage"));
// change icons for the picture box
pbPrivate.Image = (sender == pbPrivate ? MainForm2.imagesDictionary["icon_cb_unit_enabled"] : MainForm2.imagesDictionary["icon_cb_unit_disabled"]);
pbGroups.Image = (sender == pbGroups ? MainForm2.imagesDictionary["icon_cb_group_enabled"] : MainForm2.imagesDictionary["icon_cb_group_disabled"]);
// change message type and store it to settings in the db
VisualSettings.InsertUpdateHTforVisualItems("defaultTextMessageType", sender == pbPrivate ? "PRIVATE" : "GROUP");
msgType = (sender == pbPrivate ? MessageType.PRIVATE : MessageType.GROUP);
// reload tree view
PopulateTreeView(msgType);
}
private void PopulateTreeView(MessageType type)
{
// remove all nodes
treeViewUnits.Nodes.Clear();
DefaultGroupAdded = false;
// set the groups and the units in the tree view
populateListBoxGroup();
if (type == MessageType.PRIVATE)
populateListBoxUnits();
if (Smode != SMSmode.New && Smode != SMSmode.Forward)
{
treeViewUnits.Enabled = false;
searchTextBox.Enabled = false;
}
}
}
}