SafeDispatch/MotoTrbo_GW/controlVoiceMain.cs

140 lines
4.5 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.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Nini.Config;
using SafeMobileLib;
using Telerik.WinControls;
using MotoTRBO_GW;
using System.Collections;
using MotoTRBO_XNL_Cmd;
namespace MotoTrbo_GW
{
public partial class controlVoiceMain : UserControl
{
public List<radioForm> radiosFormList;
public List<dataForm> dataFormList;
private List<RadioGateway> radioGwList;
private IConfigSource source = null;
private int radioNr;
private DBgatewaysManager DBgateways;
public controlVoiceMain()
{
try
{
radiosFormList = new List<radioForm>();
dataFormList = new List<dataForm>();
InitializeComponent();
LoadConfig();
try
{
DBgateways = new DBgatewaysManager(Main.DBServer, Main.DBSchema, Main.DBUser, Main.DBPass, Main.DBPort);
radioGwList = DBgateways.gelAllRadioGateways(Main.GWID, (int)GatewayType.Tier2Radio);
}
catch (Exception ex)
{
SafeMobileLib.Utils.WriteLine("Database failed:" + ex.ToString());
FeedbackRadMessageBox.ShowError("Database connection failed", "Database Error");
//System.Environment.Exit(0);
System.Windows.Forms.Application.Exit();
}
populateRadios4Disp();
DispalayRadios();
}
catch (Exception ex)
{
SafeMobileLib.Utils.WriteLine("Error in controlVoiceMain constructor!!!!" + ex.ToString());
FeedbackRadMessageBox.ShowExclamation("Fatal error in Voice Control !!!!", "Warning");
SafeMobileLib.Utils.WriteLine(ex.ToString());
}
}
private void LoadConfig()
{
try
{
source = new IniConfigSource(Main.CFG_FILE);
radioNr =Convert.ToInt32(source.Configs["Voice"].Get("radioNr"));
}
catch (Exception e)
{
SafeMobileLib.Utils.WriteLine(e.Message + " " + e.StackTrace + " " + e.Source);
}
}
private void SaveConfig()
{
source = new IniConfigSource(Main.CFG_FILE);
source.Configs["Voice"].Set("radioNr", radioNr.ToString());
source.Save();
}
private void populateRadios4Disp()
{
radioForm radioFormVar;
dataForm dataFormVar;
foreach (RadioGateway rg in radioGwList)
{
if (rg.Gw_voice==1)
{
radioFormVar = new radioForm(rg.Id, rg.Ip, rg.Imei);
radioFormVar.ID = rg.Id;
radioFormVar.TopLevel = false;
radioFormVar.Visible = true;
radioFormVar.Dock = DockStyle.Top;
radioFormVar.lbRadName.Text = rg.Ip;
radioFormVar.ChangeState();
radiosFormList.Add(radioFormVar);
Main.gatewayState.Add(rg.Gw_id + "." + rg.Id, false);
}
else
{
dataFormVar = new dataForm(rg.Id, rg.Ip, rg.Imei);
dataFormVar.ID = rg.Id;
dataFormVar.TopLevel = false;
dataFormVar.Visible = true;
dataFormVar.Dock = DockStyle.Top;
dataFormVar.lbRadName.Text = rg.Ip;
dataFormList.Add(dataFormVar);
}
}
}
private void DispalayRadios()
{
panelVoiceMAin.PanelContainer.Controls.Clear();
foreach (dataForm data in dataFormList)
{
panelVoiceMAin.PanelContainer.Controls.Add(data);
}
foreach (radioForm r in radiosFormList)
{
panelVoiceMAin.PanelContainer.Controls.Add(r);
}
}
public void SaveConfigForRadios()
{
foreach (radioForm rd in radiosFormList)
{
if (rd != null)
{
rd.SendClose();
rd.SaveConfig();
}
}
}
}
}