SafeDispatch/Safedispatch_4_0/maptab/Radio/CallsForm.cs

348 lines
12 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using SafeMobileLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
namespace Safedispatch_4_0.Radio
{
public partial class CallsForm : Telerik.WinControls.UI.RadForm
{
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
public Int32 callStatus;
public string _IP;
private Int64 id = 0;
internal String name = "";
private Int32 groupID = 0;
private Cmd_type_callForm type_of_message = Cmd_type_callForm.End_call;
private SubscriberType subsType = SubscriberType.SUBSCRIBER;
private String Imei = "";
private String ip = "";
bool pttIsPressed = false;
internal static int positionY = 0;
internal static int positionX = 0;
public string Title
{
get
{
return label_name.Text;
}
set
{
label_name.Text = value;
base.Text = value;
}
}
public string GatewayName
{
get
{
return gatewayName;
}
set
{
lbGatewayName.Text = value;
gatewayName = value;
}
}
private string gatewayName;
public CallsForm(long ID,String Name_to_Display,Int32 groupID,Int32 callType,Int32 _callStatus, string ip)
{
InitializeComponent();
this.id = ID;
this.name = Name_to_Display;
this.groupID = groupID;
Imei = id.ToString();
this.ip = string.Format("224.20.{0}.1", id);
_IP = ip;
if (MainForm2.radioType == RADIOTYPE.SIMOCO)
label_name.Text = "Simoco";
//if (MainForm2.radioType == RADIOTYPE.EXCERA)
// label_name.Text = "Excera";
lbName.Text = Name_to_Display;
switch (callType)
{
case 101:
lbCallType.Text = MainForm2.returnLNGString("allcall");
picBoxCallType.Image = Dispatcher.Properties.Resources.r_call_received_all;
subsType = SubscriberType.ALL;
break;
case 102:
lbCallType.Text = MainForm2.returnLNGString("privateCall");
picBoxCallType.Image = Dispatcher.Properties.Resources.r_call_received_private;
subsType = SubscriberType.SUBSCRIBER;
break;
case 103:
string groupName = MainForm2.GroupCPSIDOnlyHashWithoutCategory.ContainsKey(groupID + RadioTab.responseGW) ? " - " + MainForm2.GroupCPSIDOnlyHashWithoutCategory[groupID + RadioTab.responseGW].Name + " ": "";
lbCallType.Text = String.Format(MainForm2.returnLNGString("groupcallWithInfo"), groupName, groupID);
picBoxCallType.Image = Dispatcher.Properties.Resources.r_call_received_group;
subsType = SubscriberType.GROUP;
Imei = groupID.ToString();
break;
case 201:
lbCallType.Text = MainForm2.returnLNGString("dispatcherCall");
picBoxCallType.Image = Dispatcher.Properties.Resources.r_call_received_dispatcher;
subsType = SubscriberType.DISPATCHER;
break;
case 162:
lbCallType.Text = MainForm2.returnLNGString("remoteMonitor");
picBoxCallType.Image = Dispatcher.Properties.Resources.r_call_received_remote;
break;
}
callStatus = _callStatus;
//this.TopLevel = true;
//this.TopMost = true;
this.Location = new Point(Screen.PrimaryScreen.Bounds.X + positionX , //should be (0,0)
Screen.PrimaryScreen.Bounds.Y + positionY);
this.TopMost = true;
this.StartPosition = FormStartPosition.Manual;
}
#region KeyIntercept
private void CallsForm_KeyDown(object sender, KeyEventArgs e)
{
if (e.Alt == true && e.KeyCode == Keys.P)
{
e.SuppressKeyPress = true;
e.Handled = true;
if (!pttIsPressed)
{
callButton_MouseDown(null, null);
pttIsPressed = true;
}
}
}
private void CallsForm_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.P && pttIsPressed)
{
e.Handled = true;
e.SuppressKeyPress = true;
callButton_MouseUp(null, null);
pttIsPressed = false;
}
}
#endregion
public void UpdateCallStatus(Int32 _callStatus)
{
callStatus = _callStatus;
callButton.Image = Dispatcher.Properties.Resources.r_ptt;
}
public bool RequestForClosing()
{
if (type_of_message != Cmd_type_callForm.Start_PTT)
{
this.Close();
return true;
}
else
return false;
}
internal void SetMute(bool Status)
{
this.pbHeadset.Image = !Status ? Dispatcher.Properties.Resources.r_headset_d: Dispatcher.Properties.Resources.r_headset;
this.pbHeadset.Tag = Status.ToString().ToLower();
}
internal void SetEmergencyColorBackground()
{
this.BackgroundImage = Dispatcher.Properties.Resources.frame_calls_emergency;
}
private void pbClose_Click(object sender, EventArgs e)
{
type_of_message = Cmd_type_callForm.End_call;
if (_onPlay_Click != null)
_onPlay_Click(pbHeadset, new ToggleClickEventArgs()
{
IMEI = lbCallType.Text == MainForm2.returnLNGString("allCall") ? "0" : Imei,
isActive = true,
SubsType = subsType,
IP = this._IP,
Type_of_message = type_of_message,
CallerName = this.name
});
this.Close();
}
private void CallsForm_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
private void callButton_MouseDown(object sender, MouseEventArgs e)
{
if (callStatus == 2)
{
type_of_message = Cmd_type_callForm.Start_PTT;
}
else
{
//send Dekey or Close
// send end_call just for Simoco
if (MainForm2.radioType == RADIOTYPE.SIMOCO || MainForm2.radioType == RADIOTYPE.EXCERA)
{
type_of_message = Cmd_type_callForm.End_call;
}
else
type_of_message = Cmd_type_callForm.Dekey;
//if ((MainForm2.radioType == RADIOTYPE.MOTO) || (MainForm2.radioType == RADIOTYPE.REPEATER_TRBO))
//{
// type_of_message = Cmd_type_callForm.Dekey;
//}
//else
//{
// type_of_message = Cmd_type_callForm.End_call;
//}
}
// trigger event for when click is done
if (_onPlay_Click != null)
_onPlay_Click(pbHeadset, new ToggleClickEventArgs()
{
IMEI = Imei,
isActive = true,
SubsType = subsType,
IP = this._IP,
Type_of_message = type_of_message,
CallerName = this.name
});
}
private void pbHeadset_MouseUp(object sender, MouseEventArgs e)
{
Console.WriteLine("FAV Click");
if (this.pbHeadset.Tag.Equals("false"))
{
this.pbHeadset.Image = Dispatcher.Properties.Resources.r_headset;
this.pbHeadset.Tag = "true";
}
else
{
this.pbHeadset.Image = Dispatcher.Properties.Resources.r_headset_d;
this.pbHeadset.Tag = "false";
}
// trigger event for when click is done
if (_onHeadset_Click != null)
_onHeadset_Click(pbHeadset, new ToggleClickEventArgs()
{
IMEI = Imei,
isActive = true,
SubsType = subsType,
IP = this._IP,
Type_of_message = type_of_message,
CallerName = this.name
});
}
public enum Cmd_type_callForm
{
End_call = 0,
Dekey,
Start_PTT,
Stop_PTT,
Sound_OFF,
Sound_ON
};
private void callButton_MouseUp(object sender, MouseEventArgs e)
{
if (callStatus == 2)
type_of_message = Cmd_type_callForm.Stop_PTT;
// trigger event for when click is done
if (_onPlay_Click != null)
_onPlay_Click(pbHeadset, new ToggleClickEventArgs()
{
IMEI = Imei,
isActive = true,
SubsType = subsType,
IP = this._IP,
Type_of_message = type_of_message,
CallerName = this.name
});
this.Close();
}
#region CELL CLICK EVENTS
public class ToggleClickEventArgs : EventArgs
{
public String IMEI { get; set; }
public String IP { get; set; }
public String CallerName { get; set; }
public Boolean isActive { get; set; }
public SubscriberType SubsType { get; set; }
public Cmd_type_callForm Type_of_message { get; set; }
}
private object _lockHeadsetClick = new object();
private event EventHandler<ToggleClickEventArgs> _onHeadset_Click;
public event EventHandler<ToggleClickEventArgs> OnHeadset_Click
{
add { lock (_lockHeadsetClick) { _onHeadset_Click += value; } }
remove { lock (_lockHeadsetClick) { _onHeadset_Click -= value; } }
}
private object _lockPlayClick = new object();
private event EventHandler<ToggleClickEventArgs> _onPlay_Click;
public event EventHandler<ToggleClickEventArgs> OnPlay_Click
{
add { lock (_lockPlayClick) { _onPlay_Click += value; } }
remove { lock (_lockPlayClick) { _onPlay_Click -= value; } }
}
private object _lockFormClosing = new object();
private event EventHandler<FormClosingEventArgs> _onForm_Closing;
public event EventHandler<FormClosingEventArgs> OnForm_Closing
{
add { lock (_lockFormClosing) { _onForm_Closing += value; } }
remove { lock (_lockFormClosing) { _onForm_Closing -= value; } }
}
#endregion
private void CallsForm_FormClosing(object sender, FormClosingEventArgs e)
{
_onForm_Closing?.Invoke(sender, e);
}
}
}