using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Net;
using Telerik.WinControls;
namespace MotoTrbo_GW
{
public partial class SettingsForm : Form
{
[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 const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
private int seqID = 1;
private static AudioDriverType audioDriverType = AudioDriverType.Unknown;
public SettingsForm()
{
InitializeComponent();
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
private void pictureBoxClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// Intercept mouse move on all the items of the form
///
/// UI object which raised the event
/// Mouse event parameters
private void SettingsForm_MouseMove(object sender, MouseEventArgs e)
{
// move form window if mouse moved with mouse pressed
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
///
/// Event handler for when the from is loaded. It will update the UI
/// elements to the value stored in the config file
///
private void SettingsForm_Load(object sender, EventArgs e)
{
// set if sms should be ack or not
cbRequestACK.Checked = Main.wait4ack;
// set sms sending interval
numericSMSInterval.Value = Main.sms_sending_interval > 0
&& Main.sms_sending_interval < numericSMSInterval.Maximum ? Main.sms_sending_interval : 1200;
// set number of retries for each message
numericRetries.Value = Main.number_of_retries >= 0
&& Main.number_of_retries <= numericRetries.Maximum ? Main.number_of_retries : 5;
numericRetryInterval.Value = Main.retry_interval_sec >= 0
&& Main.retry_interval_sec <= numericRetryInterval.Maximum ? Main.retry_interval_sec : 180;
nupARSPort.Value = Main.ARSServicePort >= 0
&& Main.ARSServicePort <= nupARSPort.Maximum ? Main.ARSServicePort : 4005;
nupSMSPort.Value = Main.SMSServicePort >= 0
&& Main.SMSServicePort <= nupSMSPort.Maximum ? Main.SMSServicePort : 4007;
nupLocationPort.Value = Main.LocationServicePort >= 0
&& Main.LocationServicePort <= nupLocationPort.Maximum ? Main.LocationServicePort : 4001;
nupTallysmanPort.Value = Main.TallysmanServicePort >= 0
&& Main.TallysmanServicePort <= nupTallysmanPort.Maximum ? Main.TallysmanServicePort : 4010;
nupCheckInterval.Value = Main.TallysmanRequestInterval >= 0
&& Main.TallysmanRequestInterval <= nupCheckInterval.Maximum ? Main.TallysmanRequestInterval : 0;
if (audioDriverType == AudioDriverType.Unknown)
audioDriverType = Main.AudioDriver;
if (audioDriverType == AudioDriverType.Windows)
cbAudioDriver.SelectedIndex = 0;
else
cbAudioDriver.SelectedIndex = 1;
cbAudioDriver.SelectedIndexChanged += cbAudioDriver_SelectedIndexChanged;
}
private void btSave_Click(object sender, EventArgs e)
{
Main.sms_sending_interval = (int)numericSMSInterval.Value;
Main.wait4ack = cbRequestACK.Checked;
Main.UpdateConfigParameter("SMS", "wait4ack", cbRequestACK.Checked ? "true" : "false");
Main.UpdateConfigParameter("SMS", "sending_interval", (int)numericSMSInterval.Value + "");
Main.UpdateConfigParameter("SMS", "number_of_retries", (int)numericRetries.Value + "");
Main.UpdateConfigParameter("SMS", "retry_interval_sec", (int)numericRetryInterval.Value + "");
Main.UpdateConfigParameter("Gateway", "arsPort", (int)nupARSPort.Value + "");
Main.UpdateConfigParameter("Gateway", "smsPort", (int)nupSMSPort.Value + "");
Main.UpdateConfigParameter("Gateway", "locationPort", (int)nupLocationPort.Value + "");
Main.UpdateConfigParameter("Tallysman", "port", (int)nupTallysmanPort.Value + "");
Main.UpdateConfigParameter("Tallysman", "checkInterval", (int)nupCheckInterval.Value + "");
Main.wait4ack = cbRequestACK.Checked;
Main.number_of_retries = (int)numericRetries.Value;
Main.sms_sending_interval = (int)numericSMSInterval.Value;
Main.retry_interval_sec = (int)numericRetryInterval.Value;
Main.ARSServicePort = (Int32)nupARSPort.Value;
Main.SMSServicePort = (Int32)nupSMSPort.Value;
Main.LocationServicePort = (Int32)nupLocationPort.Value;
Main.TallysmanServicePort = (Int32)nupTallysmanPort.Value;
Main.TallysmanRequestInterval = (Int32)nupCheckInterval.Value;
Main.resetTallysmanCheckTimer((Int32)nupCheckInterval.Value);
/*
DialogResult dr = MessageBox.Show("Settings saved succesfully. You need to restart gateway " +
"for the changes to take effect." + System.Environment.NewLine +
System.Environment.NewLine + " Do you wish to restart now?", "Settings saved",
MessageBoxButtons.YesNo);
if (dr == System.Windows.Forms.DialogResult.Yes)
{
// restart gateway
if (OnRestartSelected != null)
OnRestartSelected();
this.Close();
}
else
{
// user decided to do nothing
}*/
this.Close();
}
private void cbAudioDriver_SelectedIndexChanged(object sender, EventArgs e)
{
Main.UpdateConfigParameter("Voice", "driver", cbAudioDriver.Text.ToLower());
audioDriverType = cbAudioDriver.Text.ToLower().Contains("asio") ? AudioDriverType.Asio : AudioDriverType.Windows;
RadMessageBox.Instance.Dispose();
RadMessageBox.SetThemeName("TelerikMetroBlue");
RadMessageBox.Instance.TopMost = true;
RadMessageBox.Instance.TopLevel = true;
FeedbackRadMessageBox.ShowInfo("Info: You need to restart gateway to work with selected driver", "Restart required");
RadMessageBox.Instance.TopMost = false;
RadMessageBox.Instance.TopLevel = false;
}
//public delegate void RestartSelected();
//public event RestartSelected OnRestartSelected;
}
}