⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configform.cs

📁 用C#实现的取得CellID和LAC的程序源代码!
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;

using NiceTracker.Libraries;

namespace NiceTracker.Config
{
	/// <summary>
	/// Summary description for ConfigForm.
	/// </summary>
	public class ConfigForm : System.Windows.Forms.Form
	{
		private Microsoft.WindowsCE.Forms.InputPanel inputPanel1;
		private System.Windows.Forms.Label labelTimerFrequency;
		private System.Windows.Forms.NumericUpDown numericUpDownTimerFrequency;
		private System.Windows.Forms.CheckBox checkBoxCollectCells;
		private System.Windows.Forms.CheckBox checkBoxProcessEvents;
		private System.Windows.Forms.Button buttonBrowseFolder;
		private System.Windows.Forms.Label labelDbPath;
		private System.Windows.Forms.TextBox textBoxCellDbPath;
		private System.Windows.Forms.NumericUpDown numericUpDownChartWidth;
		private System.Windows.Forms.Label labelChartWidth;
		private System.Windows.Forms.Button buttonCancel;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox comboBoxComPort;
		private System.Windows.Forms.Button buttonDetect;
		private System.Windows.Forms.CheckBox checkBoxExpandSip;
		private System.Windows.Forms.CheckBox checkBoxShowdBMChart;
		private System.Windows.Forms.CheckBox checkBoxShowdBMValue;
		private System.Windows.Forms.CheckBox checkBoxShowHex;
		private System.Windows.Forms.MainMenu mainMenu1;
	
		public ConfigForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			numericUpDownTimerFrequency.Value = ConfigManager.UpdateFrequency;
			numericUpDownChartWidth.Value = ConfigManager.ChartWrapLimit;
			checkBoxCollectCells.Checked = ConfigManager.CollectCells;
			checkBoxProcessEvents.Checked = ConfigManager.ProcessEvents;
			textBoxCellDbPath.Text = ConfigManager.DBLocation;
			checkBoxExpandSip.Checked = ConfigManager.ExpandSip;
			checkBoxShowdBMChart.Checked = ConfigManager.ShowDBMChart;
			checkBoxShowdBMValue.Checked = ConfigManager.ShowDBMValue;
			checkBoxShowHex.Checked = ConfigManager.ShowLacCiInHex;

			comboBoxComPort.Items.Clear();
			for ( int i = 0; i<=9; i++ )
				comboBoxComPort.Items.Add( "COM" + i.ToString() + ":" );
			comboBoxComPort.SelectedIndex = ConfigManager.ComPort;
			
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.inputPanel1 = new Microsoft.WindowsCE.Forms.InputPanel();
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.labelTimerFrequency = new System.Windows.Forms.Label();
			this.numericUpDownTimerFrequency = new System.Windows.Forms.NumericUpDown();
			this.checkBoxCollectCells = new System.Windows.Forms.CheckBox();
			this.checkBoxProcessEvents = new System.Windows.Forms.CheckBox();
			this.buttonBrowseFolder = new System.Windows.Forms.Button();
			this.labelDbPath = new System.Windows.Forms.Label();
			this.textBoxCellDbPath = new System.Windows.Forms.TextBox();
			this.numericUpDownChartWidth = new System.Windows.Forms.NumericUpDown();
			this.labelChartWidth = new System.Windows.Forms.Label();
			this.buttonCancel = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.comboBoxComPort = new System.Windows.Forms.ComboBox();
			this.buttonDetect = new System.Windows.Forms.Button();
			this.checkBoxExpandSip = new System.Windows.Forms.CheckBox();
			this.checkBoxShowdBMChart = new System.Windows.Forms.CheckBox();
			this.checkBoxShowdBMValue = new System.Windows.Forms.CheckBox();
			this.checkBoxShowHex = new System.Windows.Forms.CheckBox();
			// 
			// labelTimerFrequency
			// 
			this.labelTimerFrequency.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular);
			this.labelTimerFrequency.Location = new System.Drawing.Point(0, 8);
			this.labelTimerFrequency.Size = new System.Drawing.Size(96, 16);
			this.labelTimerFrequency.Text = "Update Freq. (secs)";
			// 
			// numericUpDownTimerFrequency
			// 
			this.numericUpDownTimerFrequency.Location = new System.Drawing.Point(104, 6);
			this.numericUpDownTimerFrequency.Minimum = new System.Decimal(new int[] {
																						5,
																						0,
																						0,
																						0});
			this.numericUpDownTimerFrequency.Size = new System.Drawing.Size(56, 20);
			this.numericUpDownTimerFrequency.Value = new System.Decimal(new int[] {
																					  5,
																					  0,
																					  0,
																					  0});
			// 
			// checkBoxCollectCells
			// 
			this.checkBoxCollectCells.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular);
			this.checkBoxCollectCells.Location = new System.Drawing.Point(8, 128);
			this.checkBoxCollectCells.Size = new System.Drawing.Size(104, 20);
			this.checkBoxCollectCells.Text = "Collect cells";
			// 
			// checkBoxProcessEvents
			// 
			this.checkBoxProcessEvents.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular);
			this.checkBoxProcessEvents.Location = new System.Drawing.Point(8, 152);
			this.checkBoxProcessEvents.Size = new System.Drawing.Size(104, 20);
			this.checkBoxProcessEvents.Text = "Process events";
			// 
			// buttonBrowseFolder
			// 
			this.buttonBrowseFolder.Location = new System.Drawing.Point(208, 64);
			this.buttonBrowseFolder.Size = new System.Drawing.Size(24, 20);
			this.buttonBrowseFolder.Text = "...";
			this.buttonBrowseFolder.Click += new System.EventHandler(this.buttonBrowseFolder_Click);
			// 
			// labelDbPath
			// 
			this.labelDbPath.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular);
			this.labelDbPath.Location = new System.Drawing.Point(0, 67);
			this.labelDbPath.Size = new System.Drawing.Size(96, 16);
			this.labelDbPath.Text = "Cell DB Path:";
			// 
			// textBoxCellDbPath
			// 
			this.textBoxCellDbPath.Location = new System.Drawing.Point(104, 64);
			this.textBoxCellDbPath.Size = new System.Drawing.Size(104, 20);
			this.textBoxCellDbPath.Text = "";
			// 
			// numericUpDownChartWidth
			// 
			this.numericUpDownChartWidth.Location = new System.Drawing.Point(104, 32);
			this.numericUpDownChartWidth.Size = new System.Drawing.Size(56, 20);
			// 
			// labelChartWidth
			// 
			this.labelChartWidth.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular);
			this.labelChartWidth.Location = new System.Drawing.Point(0, 35);
			this.labelChartWidth.Size = new System.Drawing.Size(96, 16);
			this.labelChartWidth.Text = "Chart width";
			// 
			// buttonCancel
			// 
			this.buttonCancel.Location = new System.Drawing.Point(160, 240);
			this.buttonCancel.Size = new System.Drawing.Size(72, 24);
			this.buttonCancel.Text = "Cancel";
			this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular);
			this.label1.Location = new System.Drawing.Point(0, 99);
			this.label1.Size = new System.Drawing.Size(96, 16);
			this.label1.Text = "COM Port:";
			// 
			// comboBoxComPort
			// 
			this.comboBoxComPort.Location = new System.Drawing.Point(104, 96);
			this.comboBoxComPort.Size = new System.Drawing.Size(80, 21);
			// 
			// buttonDetect
			// 
			this.buttonDetect.Location = new System.Drawing.Point(184, 96);
			this.buttonDetect.Size = new System.Drawing.Size(48, 20);
			this.buttonDetect.Text = "Detect";
			this.buttonDetect.Click += new System.EventHandler(this.buttonDetect_Click);
			// 
			// checkBoxExpandSip
			// 
			this.checkBoxExpandSip.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular);
			this.checkBoxExpandSip.Location = new System.Drawing.Point(112, 128);
			this.checkBoxExpandSip.Size = new System.Drawing.Size(120, 20);
			this.checkBoxExpandSip.Text = "Expand input panel";
			// 
			// checkBoxShowdBMChart
			// 
			this.checkBoxShowdBMChart.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular);
			this.checkBoxShowdBMChart.Location = new System.Drawing.Point(8, 176);
			this.checkBoxShowdBMChart.Size = new System.Drawing.Size(104, 20);
			this.checkBoxShowdBMChart.Text = "Show dbM on chart";
			// 
			// checkBoxShowdBMValue
			// 
			this.checkBoxShowdBMValue.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular);
			this.checkBoxShowdBMValue.Location = new System.Drawing.Point(112, 152);
			this.checkBoxShowdBMValue.Size = new System.Drawing.Size(120, 20);
			this.checkBoxShowdBMValue.Text = "Show dbM value";
			// 
			// checkBoxShowHex
			// 
			this.checkBoxShowHex.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular);
			this.checkBoxShowHex.Location = new System.Drawing.Point(112, 176);
			this.checkBoxShowHex.Size = new System.Drawing.Size(120, 20);
			this.checkBoxShowHex.Text = "Show LAC/CI in Hex";
			// 
			// ConfigForm
			// 
			this.Controls.Add(this.checkBoxShowHex);
			this.Controls.Add(this.checkBoxShowdBMValue);
			this.Controls.Add(this.checkBoxShowdBMChart);
			this.Controls.Add(this.checkBoxExpandSip);
			this.Controls.Add(this.buttonDetect);
			this.Controls.Add(this.comboBoxComPort);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.buttonCancel);
			this.Controls.Add(this.labelChartWidth);
			this.Controls.Add(this.numericUpDownChartWidth);
			this.Controls.Add(this.textBoxCellDbPath);
			this.Controls.Add(this.labelDbPath);
			this.Controls.Add(this.buttonBrowseFolder);
			this.Controls.Add(this.checkBoxProcessEvents);
			this.Controls.Add(this.checkBoxCollectCells);
			this.Controls.Add(this.numericUpDownTimerFrequency);
			this.Controls.Add(this.labelTimerFrequency);
			this.Menu = this.mainMenu1;
			this.Text = "Settings";

		}
		#endregion

		public void UpdateChanges()
		{
			ConfigManager.UpdateFrequency = Convert.ToInt32( numericUpDownTimerFrequency.Value );
			ConfigManager.ChartWrapLimit = Convert.ToInt32( numericUpDownChartWidth.Value );
			ConfigManager.CollectCells = checkBoxCollectCells.Checked;
			ConfigManager.ProcessEvents = checkBoxProcessEvents.Checked;
			ConfigManager.ComPort = comboBoxComPort.SelectedIndex;
			ConfigManager.ExpandSip = checkBoxExpandSip.Checked;
			ConfigManager.ShowDBMChart = checkBoxShowdBMChart.Checked;
			ConfigManager.ShowDBMValue = checkBoxShowdBMValue.Checked;
			ConfigManager.ShowLacCiInHex = checkBoxShowHex.Checked;

			if ( textBoxCellDbPath.Text != ConfigManager.DBLocation )
			{
				string fromFolder = ConfigManager.DBLocation;
				string toFolder = textBoxCellDbPath.Text;

				if ( fromFolder.Substring( fromFolder.Length - 1, 1 ) == "\\" )
					fromFolder = fromFolder.Substring( 0, fromFolder.Length - 1 );

				if ( toFolder.Substring( toFolder.Length - 1, 1 ) == "\\" && toFolder.Length > 1 )
					toFolder = toFolder.Substring( 0, fromFolder.Length - 1 );

				if ( Directory.Exists( fromFolder ) )
					if ( Directory.Exists( toFolder ) )
						File.Move( fromFolder + "\\" + CellDB.Filename, toFolder + "\\" + CellDB.Filename );
					else
						MessageBox.Show( "New folder does not exist : \n\n" + toFolder );

				else
					MessageBox.Show( "Original folder does not exist" );
			}

			ConfigManager.DBLocation = textBoxCellDbPath.Text;

		}

		private void buttonBrowseFolder_Click(object sender, System.EventArgs e)
		{
			FolderDialog fd = new FolderDialog();
			fd.SelectedPath = textBoxCellDbPath.Text;
			if ( fd.ShowDialog() == DialogResult.OK )
			{
				textBoxCellDbPath.Text = fd.SelectedPath;
			}

		}

		private void buttonCancel_Click(object sender, System.EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}

		private void buttonDetect_Click(object sender, System.EventArgs e)
		{
			int detectedPort = -1;

			try
			{
				buttonDetect.Enabled = false;

				detectedPort = GSMLib.DetectModem();
			}
			catch ( Exception )
			{				
			}
			finally
			{
				buttonDetect.Enabled = true;
			}

			if ( detectedPort != -1 )
			{
				MessageBox.Show( "Modem found on " + "COM" + detectedPort.ToString() + ":" );
				this.comboBoxComPort.SelectedIndex = detectedPort;
			}
			else
			{				
				MessageBox.Show( "Modem not found, please restart the application and try again." );
			}
			
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -