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

📄 form1.cs

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

namespace NiceTracker
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private DataSet dsData = new DataSet( "data" );
		private DataTable dtCells = null;
		private DataView dvCells = null;
		private System.Windows.Forms.Timer timerUpdate;
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem menuItemMain;
		private System.Windows.Forms.MenuItem menuItemExit;
		private System.Windows.Forms.Label labelLAC;
		private System.Windows.Forms.Label labelCI;
		private System.Windows.Forms.TextBox textBoxLAC;
		private System.Windows.Forms.TextBox textBoxCI;
		private System.Windows.Forms.ListBox listBox2;
		private CellTrack c = new CellTrack();
		private System.Windows.Forms.TabControl tabControl1;
		private System.Windows.Forms.TabPage tabPageStats;
		private System.Windows.Forms.MenuItem menuItemSave;
		private System.Windows.Forms.MenuItem menuItemExport;
		private System.Windows.Forms.Label labelModemHist;
		private System.Windows.Forms.TabPage tabPageCellDB;
		private System.Windows.Forms.DataGrid dataGridCellDB;
		private System.Windows.Forms.Label labelLocation;
		private System.Windows.Forms.TextBox textBoxDBDescription;
		private System.Windows.Forms.Button buttonDBSave;
		private System.Windows.Forms.TextBox textBoxLocation;		

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}
		/// <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.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.menuItemMain = new System.Windows.Forms.MenuItem();
			this.menuItemSave = new System.Windows.Forms.MenuItem();
			this.menuItemExport = new System.Windows.Forms.MenuItem();
			this.menuItemExit = new System.Windows.Forms.MenuItem();
			this.timerUpdate = new System.Windows.Forms.Timer();
			this.labelLAC = new System.Windows.Forms.Label();
			this.labelCI = new System.Windows.Forms.Label();
			this.textBoxLAC = new System.Windows.Forms.TextBox();
			this.textBoxCI = new System.Windows.Forms.TextBox();
			this.listBox2 = new System.Windows.Forms.ListBox();
			this.tabControl1 = new System.Windows.Forms.TabControl();
			this.tabPageStats = new System.Windows.Forms.TabPage();
			this.textBoxLocation = new System.Windows.Forms.TextBox();
			this.labelLocation = new System.Windows.Forms.Label();
			this.labelModemHist = new System.Windows.Forms.Label();
			this.tabPageCellDB = new System.Windows.Forms.TabPage();
			this.buttonDBSave = new System.Windows.Forms.Button();
			this.textBoxDBDescription = new System.Windows.Forms.TextBox();
			this.dataGridCellDB = new System.Windows.Forms.DataGrid();
			// 
			// mainMenu1
			// 
			this.mainMenu1.MenuItems.Add(this.menuItemMain);
			// 
			// menuItemMain
			// 
			this.menuItemMain.MenuItems.Add(this.menuItemSave);
			this.menuItemMain.MenuItems.Add(this.menuItemExport);
			this.menuItemMain.MenuItems.Add(this.menuItemExit);
			this.menuItemMain.Text = "Main";
			// 
			// menuItemSave
			// 
			this.menuItemSave.Text = "Save";
			this.menuItemSave.Click += new System.EventHandler(this.menuItemSave_Click);
			// 
			// menuItemExport
			// 
			this.menuItemExport.Text = "Export";
			// 
			// menuItemExit
			// 
			this.menuItemExit.Text = "Exit";
			this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click);
			// 
			// timerUpdate
			// 
			this.timerUpdate.Enabled = true;
			this.timerUpdate.Interval = 30000;
			this.timerUpdate.Tick += new System.EventHandler(this.timerUpdate_Tick);
			// 
			// labelLAC
			// 
			this.labelLAC.Location = new System.Drawing.Point(80, 32);
			this.labelLAC.Size = new System.Drawing.Size(32, 20);
			this.labelLAC.Text = "LAC:";
			// 
			// labelCI
			// 
			this.labelCI.Location = new System.Drawing.Point(160, 32);
			this.labelCI.Size = new System.Drawing.Size(24, 20);
			this.labelCI.Text = "CI: ";
			// 
			// textBoxLAC
			// 
			this.textBoxLAC.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular);
			this.textBoxLAC.Location = new System.Drawing.Point(112, 30);
			this.textBoxLAC.ReadOnly = true;
			this.textBoxLAC.Size = new System.Drawing.Size(40, 18);
			this.textBoxLAC.Text = "";
			// 
			// textBoxCI
			// 
			this.textBoxCI.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular);
			this.textBoxCI.Location = new System.Drawing.Point(184, 30);
			this.textBoxCI.ReadOnly = true;
			this.textBoxCI.Size = new System.Drawing.Size(40, 18);
			this.textBoxCI.Text = "";
			// 
			// listBox2
			// 
			this.listBox2.Location = new System.Drawing.Point(8, 80);
			this.listBox2.Size = new System.Drawing.Size(216, 158);
			// 
			// tabControl1
			// 
			this.tabControl1.Controls.Add(this.tabPageStats);
			this.tabControl1.Controls.Add(this.tabPageCellDB);
			this.tabControl1.SelectedIndex = 0;
			this.tabControl1.Size = new System.Drawing.Size(240, 272);
			// 
			// tabPageStats
			// 
			this.tabPageStats.Controls.Add(this.textBoxLocation);
			this.tabPageStats.Controls.Add(this.labelLocation);
			this.tabPageStats.Controls.Add(this.labelModemHist);
			this.tabPageStats.Controls.Add(this.labelLAC);
			this.tabPageStats.Controls.Add(this.labelCI);
			this.tabPageStats.Controls.Add(this.textBoxLAC);
			this.tabPageStats.Controls.Add(this.textBoxCI);
			this.tabPageStats.Controls.Add(this.listBox2);
			this.tabPageStats.Location = new System.Drawing.Point(4, 4);
			this.tabPageStats.Size = new System.Drawing.Size(232, 246);
			this.tabPageStats.Text = "Stats";
			// 
			// textBoxLocation
			// 
			this.textBoxLocation.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular);
			this.textBoxLocation.Location = new System.Drawing.Point(64, 5);
			this.textBoxLocation.ReadOnly = true;
			this.textBoxLocation.Size = new System.Drawing.Size(160, 23);
			this.textBoxLocation.Text = "";
			// 
			// labelLocation
			// 
			this.labelLocation.Location = new System.Drawing.Point(8, 8);
			this.labelLocation.Size = new System.Drawing.Size(48, 20);
			this.labelLocation.Text = "Location:";
			// 
			// labelModemHist
			// 
			this.labelModemHist.Location = new System.Drawing.Point(8, 56);
			this.labelModemHist.Size = new System.Drawing.Size(48, 20);
			this.labelModemHist.Text = "History";
			// 
			// tabPageCellDB
			// 
			this.tabPageCellDB.Controls.Add(this.buttonDBSave);
			this.tabPageCellDB.Controls.Add(this.textBoxDBDescription);
			this.tabPageCellDB.Controls.Add(this.dataGridCellDB);
			this.tabPageCellDB.Location = new System.Drawing.Point(4, 4);
			this.tabPageCellDB.Size = new System.Drawing.Size(232, 246);
			this.tabPageCellDB.Text = "CellDB";
			// 
			// buttonDBSave
			// 
			this.buttonDBSave.Location = new System.Drawing.Point(184, 3);
			this.buttonDBSave.Size = new System.Drawing.Size(48, 20);
			this.buttonDBSave.Text = "Save";
			this.buttonDBSave.Click += new System.EventHandler(this.buttonDBSave_Click);
			// 
			// textBoxDBDescription
			// 
			this.textBoxDBDescription.Location = new System.Drawing.Point(0, 3);
			this.textBoxDBDescription.Size = new System.Drawing.Size(184, 20);
			this.textBoxDBDescription.Text = "";
			// 
			// dataGridCellDB
			// 
			this.dataGridCellDB.Location = new System.Drawing.Point(0, 24);
			this.dataGridCellDB.Size = new System.Drawing.Size(232, 224);
			this.dataGridCellDB.Text = "CellDB";
			// 
			// Form1
			// 
			this.Controls.Add(this.tabControl1);
			this.Menu = this.mainMenu1;
			this.Text = "NiceTracker";
			this.Load += new System.EventHandler(this.Form1_Load);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>

		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{			
			loadCellDB();

			dataGridCellDB.Width = tabPageCellDB.Width;
			dataGridCellDB.CurrentCellChanged +=new EventHandler(dataGridCellDB_CurrentCellChanged);

			c.CellChanged += new EventHandler(c_CellChanged);
			

			refreshCellData();
		}

		private void timerUpdate_Tick(object sender, System.EventArgs e)
		{
			refreshCellData();
		}

		private void refreshCellData()
		{
			c.Update();
			
			listBox2.Items.Add( DateTime.Now.ToShortTimeString() + " " + c.ATResponse );		
		}

		private void loadCellDB()
		{			
			if ( !File.Exists( "cells.xml" ) )
			{			
				dtCells = setupCellDB( dsData );

				dsData.WriteXml( "cells.xml" );
			}
			else
			{
				dsData.ReadXml( "cells.xml" );
				
				dtCells = setupCellDB( dsData );				
			}

			dvCells = new DataView( dtCells );
			dvCells.AllowEdit = true;			
			dvCells.AllowNew = true;
			dataGridCellDB.DataSource = dvCells;
		}

		private DataTable setupCellDB( DataSet ds )
		{
			DataTable dt = null;
			
			if ( ds.Tables.Contains( "cells" ) )
				dt = ds.Tables[ "cells" ];
			else
			{
				dt = new DataTable( "cells" );
				ds.Tables.Add( dt );
			}

			if ( !dt.Columns.Contains( "description" ) )
				dt.Columns.Add( "description", typeof( string ) );
			if ( !dt.Columns.Contains( "lac" ) )
				dt.Columns.Add( "lac", typeof( string ) );
			if ( !dt.Columns.Contains( "ci" ) )
				dt.Columns.Add( "ci", typeof( string ) );

			return dt;
		}

		private void menuItemExit_Click(object sender, System.EventArgs e)
		{
			Application.Exit();
		}

		private void c_CellChanged(object sender, EventArgs e)
		{
			textBoxLAC.Text = c.LAC;
			textBoxCI.Text = c.CI;
			textBoxLocation.Text = getDescription( c.LAC, c.CI );

			if ( newCell( c.LAC, c.CI ) )
			{
				DataTable dtCells = dsData.Tables[ "cells" ];
				DataRow dr = dtCells.NewRow();
				dr[ "lac" ] = c.LAC;
				dr[ "ci" ] = c.CI;
				dtCells.Rows.Add( dr );
			}
		}

		private bool newCell( string LAC, string CI )
		{
			DataTable dtCells = dsData.Tables[ "cells" ];
			DataRow[] rows = dtCells.Select( "lac=" + LAC + " and ci=" + CI );
			return ( rows.Length == 0 );
		}

		
		private string getDescription( string LAC, string CI )
		{
			DataTable dtCells = dsData.Tables[ "cells" ];
			DataRow[] rows = dtCells.Select( "lac=" + LAC + " and ci=" + CI );
			
			if ( rows.Length > 1 )
				return rows[0]["description"].ToString();
			else
				return "Unknown";
		}

		private void menuItemSave_Click(object sender, System.EventArgs e)
		{
			dsData.WriteXml( "cells.xml" );
		}

		private void buttonDBSave_Click(object sender, System.EventArgs e)
		{
			DataGridCell currentCell = dataGridCellDB.CurrentCell;
			dvCells[ currentCell.RowNumber ][ "description" ] = textBoxDBDescription.Text;
		}

		private void dataGridCellDB_CurrentCellChanged(object sender, EventArgs e)
		{
			DataGridCell currentCell = dataGridCellDB.CurrentCell;
			textBoxDBDescription.Text = dvCells[ currentCell.RowNumber ][ "description" ].ToString();
		}
	}
}

⌨️ 快捷键说明

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