SafeDispatch/Safedispatch_4_0/FastCommandWindow.cs

880 lines
36 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 Telerik.WinControls.UI;
using SafeMobileLib;
using System.Text.RegularExpressions;
using System.Threading;
using System.Collections;
using Safedispatch_4_0.Radio;
using Console = SafeMobileLib.Utils;
namespace Safedispatch_4_0
{
public partial class FastCommandWindow : Telerik.WinControls.UI.RadForm
{
private string name;
public String gwandradID = "0.0";
public String IMEI;
private MainForm2 parent;
private EventType popupType = EventType.ALERT;
private int maxCharsNumberForSMS = 0;
private Image themeAlert_Image = Console.ChangeColor(Dispatcher.Properties.Resources.l_menu_alert, MainForm2.ButtonColor);
private Image themeText_Image = Console.ChangeColor(Dispatcher.Properties.Resources.l_menu_text, MainForm2.ButtonColor);
private Image themeVoice_Image = Console.ChangeColor(Dispatcher.Properties.Resources.l_menu_ptt, MainForm2.ButtonColor);
private void setLanguage()
{
try
{
labelAction.Text = MainForm2.returnLNGString("PushtoTalk");
lbSound.Text = MainForm2.returnLNGString("sound") + ':';
//btPTT.Text = MainForm2.returnLNGString("callptt");
AlarmGridView.Columns[0].HeaderText = MainForm2.returnLNGString("type");
AlarmGridView.Columns[1].HeaderText = MainForm2.returnLNGString("alarmsListColumns1");
AlarmGridView.Columns[2].HeaderText = MainForm2.returnLNGString("lbDescript");
}
catch (Exception ex)
{
SM.Debug("Ex:"+ex.ToString());
}
}
public Boolean has_voice { get; set; }
public Boolean has_text { get; set; }
public FastCommandWindow(String _name, String _imei, MainForm2 _parent, EventType popupType, ArrayList predefSMS)
{
InitializeComponent();
// save desired tab
this.popupType = popupType;
// do not draw border for alerts grid
this.AlarmGridView.GridViewElement.DrawBorder = false;
this.AlarmGridView.GridViewElement.GroupPanelElement.DrawBorder = false;
// display maximum number of characters
maxCharsNumberForSMS = SmsUtils.GetMaxNumberOfCharacters(MainForm2.radioType);
if (MainForm2.vehicleHT.Contains(_name))
{
((Vehicle)MainForm2.vehicleHT[_name]).CheckPositionInSystem();
string GatewayAndRadioID = ((Vehicle)MainForm2.vehicleHT[_name]).GwandRadioID;
int gwType = (int)GatewayType.Unknown;
if (MainForm2.radioGwHT[GatewayAndRadioID] != null)
{
gwType = ((RadioGateway)MainForm2.radioGwHT[GatewayAndRadioID]).Type;
maxCharsNumberForSMS = SmsUtils.GetMaxNumberOfCharacters(gwType);
}
}
tbText.MaxLength = maxCharsNumberForSMS;
labelCount.Text = String.Format(MainForm2.returnLNGString("charactersLeft"), (tbText.MaxLength)); ;
rdtpSchedule.Value = DateTime.Now;
// fix background of ptt picture box
pbPTT.BackColor = Color.Transparent;
pbPTT.Parent = pbSpectrum;
pbPTT.Location = new Point(8, 8);
// set prefedSMS
lvPredefinedMessages.DataSource = predefSMS;
// update calling label
labelCalling.Text = String.Format(MainForm2.returnLNGString("privateCallTo"), _name.ToUpper());
try
{
if (MainForm2.is24hours)
{
if (MainForm2.DayFirst)
((GridViewDateTimeColumn)AlarmGridView.Columns[1]).FormatString = "{0:dd/MM/yyyy HH:mm:ss}";
else
((GridViewDateTimeColumn)AlarmGridView.Columns[1]).FormatString = "{0:MM/dd/yyyy HH:mm:ss}";
}
else
{
if (MainForm2.DayFirst)
((GridViewDateTimeColumn)AlarmGridView.Columns[1]).FormatString = "{0:dd/MM/yyyy hh:mm:ss tt}";
else
((GridViewDateTimeColumn)AlarmGridView.Columns[1]).FormatString = "{0:MM/dd/yyyy hh:mm:ss tt}";
}
}
catch (Exception ex)
{
SM.Debug("Error on gridview DateFormat:" + ex.ToString());
}
rlPredefinedMessages.Text = MainForm2.returnLNGString("predefinedMessages");
lbAlerts.Text = MainForm2.returnLNGString("alerts");
lbMessage.Text = MainForm2.returnLNGString("textMessage");
lbCall.Text = MainForm2.returnLNGString("call");
this.Text = String.Format(MainForm2.returnLNGString("fastCommands"), _name.ToUpper());
rlScheduleSending.Text = MainForm2.returnLNGString("schedSending");
btSMS.Text = MainForm2.returnLNGString("sendsms");
//ThemeResolutionService.ApplyThemeToControlTree(this, "ControlDefault");
this.ProgVolum.ProgressBarElement.IndicatorElement1.DrawFill = true;
this.ProgVolum.ProgressBarElement.IndicatorElement1.BackColor3 = System.Drawing.SystemColors.ControlLight;
this.ProgVolum.ProgressBarElement.IndicatorElement1.BackColor4 = System.Drawing.Color.White;
this.ProgVolum.ProgressBarElement.IndicatorElement1.BackColor = System.Drawing.Color.LightGray;
this.ProgVolum.ProgressBarElement.IndicatorElement1.BackColor2 = System.Drawing.SystemColors.ControlLight;
name = _name;
IMEI = _imei;
parent = _parent;
populate();
setLanguage();
if ((MainForm2.radioType != RADIOTYPE.MOTO) && (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.lbSound.ForeColor = MainForm2.HarTextColor;
break;
case RADIOTYPE.ATLAS:
this.Icon = global::Dispatcher.Properties.Resources.ATLICO32; //ATLASCHANGE
this.lbSound.ForeColor = MainForm2.HarTextColor;
break;
case RADIOTYPE.REPEATER_TRBO:
//this.btPTT.Visible = false;
this.lbSound.Visible = false;
this.ProgVolum.Visible = false;
//this.Size = new Size(this.Size.Width, this.Size.Height-35);
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:" + ex.ToString());
}
}
}
/// <summary>
/// Activate the desired tab
/// </summary>
/// <param name="popupType">The tab type which needs to be activated</param>
public void SelectTab(EventType popupType)
{
switch (popupType)
{
case EventType.ALERT: pb_Click(pbMenuAlerts, null); break;
case EventType.TEXT: pb_Click(pbMenuText, null); tbText.Focus(); break;
case EventType.VOICE: pb_Click(pbMenuPTT, null); break;
}
}
public void DisablePTT()
{
//btPTT.Enabled = false;
}
public void EnablePTT()
{
//btPTT.Enabled = true;
ProgVolum.Value1 = ProgVolum.Maximum - 0 + ProgVolum.Minimum;
}
public void checkStatus()
{
try
{
if (!MainForm2.VoiceTabStarted)
{
// Remove picture PTT
panel3.Controls.Remove(pbMenuPTT);
// Remove label Call
this.Controls.Remove(lbCall);
// remove voice tab
documentTabStrip1.Controls.Remove(this.windowPtt);
}
/* if (parent.mainRadioForms != null)
{
foreach (ShapeNew obj in parent.mainRadioForms)
if ((obj.typeRadio) && (obj.gwandradID == gwandradID))
{
if (!obj.isON) DisablePTT();
break;
}
}*/
}
catch (Exception ex)
{
SM.Debug("Unable to checkStatus"+ex.ToString());
}
}
volatile List<DataforAlarmList> ListforAlarmList = new List<DataforAlarmList>();
volatile String volUnitName = "";
volatile String volDesc = "";
public void populate()
{
try
{
SM.Debug("Face populare:" + ((Vehicle)MainForm2.vehicleHT[name]).EventLists.Count);
AlarmGridView.Columns[1].SortOrder = RadSortOrder.None;
ListforAlarmList.Clear();
foreach (Alarms obj in ((Vehicle)MainForm2.vehicleHT[name]).EventLists)
{
switch (obj.type)
{
case rep_type.EMERG:
volUnitName = MainForm2.returnLNGString("emergAlarm");
break;
case rep_type.SPEED:
volUnitName = MainForm2.returnLNGString("alarmSpeed");
break;
case rep_type.GEOFENC:
volUnitName = MainForm2.returnLNGString("zone");
break;
case rep_type.SMSRECIVE:
volUnitName = MainForm2.returnLNGString("recsms");
break;
case rep_type.SMSSEND:
volUnitName = MainForm2.returnLNGString("sendsms");
break;
case rep_type.CALLRECIVE:
volUnitName = MainForm2.returnLNGString("recivecall");
break;
case rep_type.CALLSEND:
volUnitName = MainForm2.returnLNGString("makecall");
break;
case rep_type.TELEMETRY_ALARM:
volUnitName = MainForm2.returnLNGString("tabTelem");
break;
case rep_type.JOB_TICKETING:
volUnitName = MainForm2.returnLNGString("tabTicketing");
break;
}
if (obj.type == rep_type.SPEED)
{
String Speed = obj.descript;
Boolean InMessMile = false;
if (Speed.Contains("_m")) InMessMile = true;
Speed = Speed.Remove(Speed.IndexOf('_'));
if ((MainForm2.isInMile) && (!InMessMile)) Speed = Convert.ToString((int)((Convert.ToInt32(Speed)) * 0.621371192));
else if ((!MainForm2.isInMile) && (InMessMile)) Speed = Convert.ToString((int)((Convert.ToInt32(Speed)) * 1.609344));
if (MainForm2.isInMile) Speed += " " + MainForm2.milesh;
else Speed += " " + MainForm2.kmh;
volDesc = Speed;
}
else if (obj.type == rep_type.JOB_TICKETING)
{
string mess = obj.descript.ToString().Replace("<JTS>", "");
string status = Regex.Replace(mess, "[0-9]", "");
string ticket_id = Regex.Replace(mess, "[a-zA-z]", "");
volDesc = string.Format("{0} - {1}", ticket_id, status);
}
else volDesc = obj.descript;
ListforAlarmList.Add(new DataforAlarmList(volUnitName, obj.time, volDesc));
}
try
{
AlarmGridView.DataSource = null;
AlarmGridView.DataSource = ListforAlarmList;
}
catch (Exception ex)
{
SM.Debug("Error on populate grid" + ex.ToString());
}
AlarmGridView.Columns[1].SortOrder = RadSortOrder.Descending;
AlarmGridView.Refresh();
int iVisibleRows = AlarmGridView.TableElement.RowsPerPage;
if (AlarmGridView.Rows.Count > iVisibleRows)
AlarmGridView.TableElement.ScrollToRow(((Vehicle)MainForm2.vehicleHT[name]).EventLists.Count - iVisibleRows + 3);
}
catch (Exception ex)
{
SM.Debug("Error on populate List:"+ex.ToString());
}
//AlarmGridView.GridElement.ScrollToRow(AlarmGridView.GridElement
// AlarmGridView.GridElement.ScrollToRow(0);
}
private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
try
{
if (e.CellElement.ColumnIndex == 2)
e.CellElement.ForeColor = Color.Green;
}
catch (Exception ex)
{
SM.Debug("Ex:"+ex.ToString());
}
}
public void putPTTON()
{
//btPTT.Enabled = true;
ProgVolum.Value1 = ProgVolum.Maximum - 0 + ProgVolum.Minimum;
}
private void Popupwindow_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
MainForm2.PopupOpen.Remove(IMEI);
// Unregister from the event
parent.OnCallStatusChanged -= parent_OnCallStatusChanged;
}
catch (Exception ex)
{
SM.Debug("Erorr remoeve popup window:"+ex.ToString());
}
}
public void BackVolum(Int32 volum)
{
try
{
if ((volum > 50) && (volum < 10000)) ProgVolum.Value1 = ProgVolum.Maximum - (Int32)((volum - 50) / 100) + ProgVolum.Minimum;
else ProgVolum.Value1 = ProgVolum.Maximum - 0 + ProgVolum.Minimum; ;
}
catch (Exception ex)
{
SM.Debug("Unable to change volume:"+ex.ToString());
}
}
private void btPTT_MouseDown(object sender, MouseEventArgs e)
{
try
{
if (MainForm2.VoiceTabStarted)
{
}
/*if (parent.mainRadioForms != null)
{
foreach (ShapeNew obj in parent.mainRadioForms)
{
if ((obj.typeRadio) && (obj.gwandradID == gwandradID))
{
((radioFrom)obj).Send_Private_PTT(IMEI);
break;
}
}
}*/
}
catch(Exception ex)
{
SM.Debug("Unable to mouseDown:" + ex.ToString());
}
}
System.Threading.Timer tCheckSTATUS=null;
private void btPTT_MouseUp(object sender, MouseEventArgs e)
{
try
{
if (MainForm2.VoiceTabStarted)
{
}
}
catch (Exception ex)
{
SM.Debug("Unable to btPTT_MouseUp:" + ex.ToString());
}
}
private void WaitPPT_Tick(object sender, EventArgs e)
{
try
{
WaitPPT.Stop();
WaitPPT.Enabled = false;
//btPTT.Enabled = true;
}
catch (Exception ex)
{
SM.Debug("Unable to WaitPPT_Tick:" + ex.ToString());
}
}
private void btSMS_Click(object sender, EventArgs e)
{
string sms = tbText.Text;
sms = sms.Replace("\'", "\'\'");
if (tbText.Text.Length > 0)
{
int sc_id = ((Vehicle)MainForm2.vehicleHT[name]).sc_id;
int sched_time = (int)DateTime.Now.ToUniversalTime().DateTo70Format();
if (rcbSchedule.Checked)
sched_time = (int)rdtpSchedule.Value.ToUniversalTime().DateTo70Format();
//((Vehicle)MainForm2.vehicleHT[name]).CheckPositionInSystem();
////String Totrans = "#142#" + ((Vehicle)MainForm2.vehicleHT[name]).GwandRadioID + "." + IMEI + "#" + sms + "#" + sched_time + "#";
//String Totrans = "#142#" + ((Vehicle)MainForm2.vehicleHT[name]).GwandRadioID + "." + IMEI + "#" + sms + "#" + sched_time + "#" + MainForm2.userIDX + "#";
//parent.Send_UDP_cmd(Totrans, 0, 0);
//((Vehicle)MainForm2.vehicleHT[name]).EventLists.Add(new Alarms(rep_type.SMSSEND, DateTime.Now, "", sms));
//parent.DisplayToast(MainForm2.returnLNGString("txtMsgTo") + " " +((Vehicle)MainForm2.vehicleHT[name]).busName,
// string.Format(MainForm2.returnLNGString("MsHTML"), sms));
parent.SendSmsOnMBus(sms, sc_id, sched_time);
populate();
tbText.Text = "";
}
else
{
SM.Debug("Error NewSMSForm /btnSendSMS_Click/ message lenght =0 or no radio selected");
}
}
/// <summary>
/// Detect which menu button was pressed and then activate the desired window
/// from the tabs. In the same time, the UI state will be changed accordingly
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pb_Click(object sender, EventArgs e)
{
if((PictureBox)sender == pbMenuAlerts)
{
radDock.ActivateWindow(windowAlerts);
pbMenuAlerts.Image = themeAlert_Image;
pbMenuText.Image = global::Dispatcher.Properties.Resources.l_menu_text_d;
pbMenuPTT.Image = global::Dispatcher.Properties.Resources.l_menu_ptt_d;
}
else if ((PictureBox)sender == pbMenuText)
{
radDock.ActivateWindow(windowText);
pbMenuAlerts.Image = global::Dispatcher.Properties.Resources.l_menu_alert_d;
pbMenuText.Image = themeText_Image;
pbMenuPTT.Image = global::Dispatcher.Properties.Resources.l_menu_ptt_d;
}
else if ((PictureBox)sender == pbMenuPTT)
{
radDock.ActivateWindow(windowPtt);
pbMenuAlerts.Image = global::Dispatcher.Properties.Resources.l_menu_alert_d;
pbMenuText.Image = global::Dispatcher.Properties.Resources.l_menu_text_d;
pbMenuPTT.Image = themeVoice_Image;
}
}
/// <summary>
/// Update the number of left character when writing a new text message
/// </summary>
private void tbText_KeyUp(object sender, KeyEventArgs e)
{
// send text on click
if (e.KeyCode == Keys.Enter)
btSMS.PerformClick();
}
/// <summary>
/// Focus the text box
/// </summary>
private void windowText_Enter(object sender, EventArgs e)
{
tbText.Focus();
}
#region PTT
private void Voice_PTT_confirmed()
{
try
{
Thread p = new Thread(delegate()
{
while (pttIsPressed)
{
/* this.Invoke((MethodInvoker)delegate()
{*/
try
{
if (pbSpectrum != null)
{
switch (spectrumCount++ % 13)
{
case 1: pbSpectrum.Image = global::Dispatcher.Properties.Resources.r_radial_spectrum_01; break;
case 2: pbSpectrum.Image = global::Dispatcher.Properties.Resources.r_radial_spectrum_02; break;
case 3: pbSpectrum.Image = global::Dispatcher.Properties.Resources.r_radial_spectrum_03; break;
case 4: pbSpectrum.Image = global::Dispatcher.Properties.Resources.r_radial_spectrum_04; break;
case 5: pbSpectrum.Image = global::Dispatcher.Properties.Resources.r_radial_spectrum_05; break;
case 6: pbSpectrum.Image = global::Dispatcher.Properties.Resources.r_radial_spectrum_06; break;
case 7: pbSpectrum.Image = global::Dispatcher.Properties.Resources.r_radial_spectrum_07; break;
case 8: pbSpectrum.Image = global::Dispatcher.Properties.Resources.r_radial_spectrum_08; break;
case 9: pbSpectrum.Image = global::Dispatcher.Properties.Resources.r_radial_spectrum_09; break;
case 10: pbSpectrum.Image = global::Dispatcher.Properties.Resources.r_radial_spectrum_10; break;
case 11: pbSpectrum.Image = global::Dispatcher.Properties.Resources.r_radial_spectrum_11; break;
case 12: pbSpectrum.Image = global::Dispatcher.Properties.Resources.r_radial_spectrum_12; break;
default: pbSpectrum.Image = global::Dispatcher.Properties.Resources.r_radial_spectrum_01; break;
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error on voice pTT confirme"+ex.ToString(),ConsoleColor.Red);
}
// });
Thread.Sleep(50);
}
});
p.Start();
}
catch (Exception ex)
{
Utils.WriteLine("Error on PbPtt_MouseDown:" + ex.ToString(), ConsoleColor.Red);
}
}
bool pttIsPressed = false;
int spectrumCount = 0;
private void pbPTT_MouseDown(object sender, MouseEventArgs e)
{
try
{
if (MainForm2.VoiceTabStarted)
{
parent.RadioTabControl.sendPTT(
new Subscriber()
{
DispatcherName = name,
SubscriberType = SubscriberType.SUBSCRIBER,
ImageKey = "i_classic_bus_02",
IconFilePath = MainForm2.GetIconPathForUnit(name),
Sc_id = 0,
Imei = IMEI,
Gw_and_radioID = parent.RadioTabControl.Valid_GwID_and_RadioID,
IP = String.Format("224.10.{0}", parent.RadioTabControl.Valid_GwID_and_RadioID),
Favorite = false,
canMakeSipCalls = ((Vehicle)MainForm2.vehicleHT[name]).canMakeSipCalls,
SipID = ((Vehicle)MainForm2.vehicleHT[name]).sipID
}, true
);
}
else
{
parent.CheckTabs(track_type.RADIO, parent.GetTabNewRadio);
// Didn't sent PTT, put red picture
pbPTT.Image = Dispatcher.Properties.Resources.r_ptt_end;
System.Threading.Timer t1 = new System.Threading.Timer(Come_back_to_normal_PTT_state, null, 1000, System.Threading.Timeout.Infinite);
return;
}
pbPTT.Image = global::Dispatcher.Properties.Resources.r_ptt_over;
pttIsPressed = true;
}
catch (Exception ex)
{
SM.Debug("Unable to mouseDown:" + ex.ToString());
}
}
private void Come_back_to_normal_PTT_state(object state)
{
try
{
pbPTT.Image = Dispatcher.Properties.Resources.r_ptt;
}
catch (Exception ex)
{
SM.Debug("Ex101:" + ex.ToString());
}
}
private void pbPTT_MouseUp(object sender, MouseEventArgs e)
{
if (!pttIsPressed) // nu s-a trmis Ptt pt ca VoiceTab nu era pornit.
return;
pttIsPressed = false;
Thread.Sleep(60);
pbSpectrum.Image = global::Dispatcher.Properties.Resources.r_radial_spectrum_00;
pbPTT.Image = global::Dispatcher.Properties.Resources.r_ptt;
spectrumCount = 0;
try
{
if (MainForm2.VoiceTabStarted)
{
parent.RadioTabControl.StopPTT(
new Subscriber()
{
DispatcherName = name,
SubscriberType = SubscriberType.SUBSCRIBER,
//SubscriberImage = Dispatcher.Properties.Resources.i_classic_bus_02,
IconFilePath = MainForm2.GetIconPathForUnit(name),
ImageKey = "i_classic_bus_02",
Sc_id = 0,
Imei = IMEI,
Gw_and_radioID = parent.RadioTabControl.Valid_GwID_and_RadioID,
IP = String.Format("224.10.{0}", parent.RadioTabControl.Valid_GwID_and_RadioID),
Favorite = false,
canMakeSipCalls = ((Vehicle)MainForm2.vehicleHT[name]).canMakeSipCalls,
SipID = ((Vehicle)MainForm2.vehicleHT[name]).sipID
}
);
}
}
catch (Exception ex)
{
SM.Debug("Unable to btPTT_MouseUp:" + ex.ToString());
}
}
#endregion
private void Popupwindow_Load(object sender, EventArgs e)
{
// Remove voice tab or text messages if not available
try
{
rdtpSchedule.Visible = rlScheduleSending.Visible = rcbSchedule.Visible = MainForm2.radioType != RADIOTYPE.LINX;
if ((!has_voice) || (!has_text) || !MainForm2.VoiceTabStarted)
{
if (!has_voice || !MainForm2.VoiceTabStarted)
{
// Remove picture PTT
panel3.Controls.Remove(pbMenuPTT);
// Remove label Call
this.Controls.Remove(lbCall);
// remove voice tab
documentTabStrip1.Controls.Remove(this.windowPtt);
}
if (!has_text)
{
// Remove picture text
panel3.Controls.Remove(pbMenuText);
// Remove label Text
this.Controls.Remove(lbMessage);
// Remove Text tab
documentTabStrip1.Controls.Remove(this.windowText);
}
// Rearange the panel that contains the pictures (alerts and message)
panel3.AutoSize = true;
panel3.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
Point oldLocation = panel3.Location;
panel3.Location = new Point(this.Width / 2 - panel3.Width / 2, oldLocation.Y);
}
}
catch (Exception ex)
{
SM.Debug("Error on remove voice tab:" + ex.ToString());
}
// display form on top of all others
this.TopMost = true;
rdtpSchedule.ThemeName = "Office2013Dark";
rcbSchedule.Checked = false;
btSMS.Enabled = false;
// select the desired tab
SelectTab(popupType);
parent.OnCallStatusChanged += parent_OnCallStatusChanged;
}
void parent_OnCallStatusChanged(string unitname, bool inCall,Boolean fromField)
{
Utils.WriteLine("ON call status changed: unit:"+unitname+" incall:"+inCall+" fromField"+fromField,ConsoleColor.DarkGreen);
if (unitname.CompareTo(name) == 0)
{
if (!fromField)
{
if (inCall) Voice_PTT_confirmed();
else
{
if (pttIsPressed)
{
pbPTT.Image = Dispatcher.Properties.Resources.r_ptt_end;
System.Threading.Timer t1 = new System.Threading.Timer(Come_back_to_normal_PTT_state, null, 1000, System.Threading.Timeout.Infinite);
}
}
}
else
{
if (inCall) pbPTT.Image = Dispatcher.Properties.Resources.r_ptt_incoming;
else pbPTT.Image = Dispatcher.Properties.Resources.r_ptt;
}
Utils.WriteLine("CallStatus received",ConsoleColor.Blue);
}
}
/// <summary>
/// Intercept when an item is duble clicked and then set the text to the
/// text box and limit its length if more than maximum allowed sized
/// </summary>
private void lvPredefinedMessages_ItemMouseDoubleClick(object sender, ListViewItemEventArgs e)
{
int maxChar = maxCharsNumberForSMS;
// set text to be full text or trimmed to max length
tbText.Text = e.Item.Text.Substring(0, (e.Item.Text.Length > maxChar) ? maxChar : e.Item.Text.Length);
// update the number of characters
labelCount.Text = String.Format(MainForm2.returnLNGString("charactersLeft"), (maxCharsNumberForSMS - tbText.Text.Length));;
}
/// <summary>
/// Enable or disable the schebule date time picker with the checkbox
/// </summary>
private void rcbSchedule_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
rdtpSchedule.Enabled = rcbSchedule.Checked;
}
/// <summary>
/// Disable send button when the text is empty
/// </summary>
private void tbText_TextChanged(object sender, EventArgs e)
{
btSMS.Enabled = (tbText.Text.Length != 0);
// update the number of characters
labelCount.Text = String.Format(MainForm2.returnLNGString("charactersLeft"), (maxCharsNumberForSMS - tbText.Text.Length));
}
/// <summary>
/// Style button SMS when the enable state changes
/// </summary>
private void btSMS_EnabledChanged(object sender, EventArgs e)
{
if (btSMS.Enabled)
btSMS.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
else
btSMS.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColorDisabled;
}
private void Popupwindow_Shown(object sender, EventArgs e)
{
tbText.Focus();
}
private void AlarmGridView_RowFormatting(object sender, RowFormattingEventArgs e)
{
if (e.RowElement.IsSelected)
{
e.RowElement.DrawFill = true;
e.RowElement.BackColor = MainForm2.GridSelectedRow;
e.RowElement.NumberOfColors = 1;
}
else
{
e.RowElement.DrawFill = false;
}
}
private void lvPredefinedMessages_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
{
if (e.VisualItem.Selected)
{
e.VisualItem.DrawFill = true;
e.VisualItem.BackColor = MainForm2.GridSelectedRow;
e.VisualItem.NumberOfColors = 1;
}
else
e.VisualItem.DrawFill = false;
}
#region KeyIntercept
private void FastCommandWindow_KeyDown(object sender, KeyEventArgs e)
{
if (e.Alt == true && e.KeyCode == Keys.P)
{
e.SuppressKeyPress = true;
e.Handled = true;
if (!pttIsPressed)
{
pbPTT_MouseDown(null, null);
pttIsPressed = true;
}
}
}
private void FastCommandWindow_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.P && pttIsPressed)
{
e.Handled = true;
e.SuppressKeyPress = true;
pbPTT_MouseUp(null, null);
pttIsPressed = false;
}
}
#endregion
private void pbPTT_MouseLeave(object sender, EventArgs e)
{
try
{
if (MainForm2.VoiceTabStarted)
{
parent.RadioTabControl.StopPTT(
new Subscriber()
{
DispatcherName = name,
SubscriberType = SubscriberType.SUBSCRIBER,
//SubscriberImage = Dispatcher.Properties.Resources.i_classic_bus_02,
IconFilePath = MainForm2.GetIconPathForUnit(name),
ImageKey = "i_classic_bus_02",
Sc_id = 0,
Imei = IMEI,
Gw_and_radioID = parent.RadioTabControl.Valid_GwID_and_RadioID,
IP = String.Format("224.10.{0}", parent.RadioTabControl.Valid_GwID_and_RadioID),
Favorite = false,
canMakeSipCalls = ((Vehicle)MainForm2.vehicleHT[name]).canMakeSipCalls,
SipID = ((Vehicle)MainForm2.vehicleHT[name]).sipID
}
);
}
}
catch (Exception ex)
{
Utils.WriteLine("pbPTT_MouseLeave error: " + ex.ToString());
}
}
}
}