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

📄 mainform.cs

📁 此文件为c#小程序,如果有感兴趣的朋友,请告知
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace MPNumberProject
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtNumber;
		private System.Windows.Forms.Button btnSelect1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtAddress;
		private System.Windows.Forms.Button btnSelecte2;
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.Label lblResult;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.Button btnDataManager;
		DataAccess access=new DataAccess ();

		public MainForm()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.lblResult = new System.Windows.Forms.Label();
			this.btnSelect1 = new System.Windows.Forms.Button();
			this.txtNumber = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.btnSelecte2 = new System.Windows.Forms.Button();
			this.txtAddress = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.btnDataManager = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.AccessibleRole = System.Windows.Forms.AccessibleRole.MenuBar;
			this.groupBox1.Controls.Add(this.lblResult);
			this.groupBox1.Controls.Add(this.btnSelect1);
			this.groupBox1.Controls.Add(this.txtNumber);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(344, 96);
			this.groupBox1.TabIndex = 1;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "号码查归属地";
			// 
			// lblResult
			// 
			this.lblResult.Location = new System.Drawing.Point(16, 56);
			this.lblResult.Name = "lblResult";
			this.lblResult.Size = new System.Drawing.Size(240, 24);
			this.lblResult.TabIndex = 3;
			// 
			// btnSelect1
			// 
			this.btnSelect1.Location = new System.Drawing.Point(256, 24);
			this.btnSelect1.Name = "btnSelect1";
			this.btnSelect1.TabIndex = 2;
			this.btnSelect1.Text = "查询";
			this.btnSelect1.Click += new System.EventHandler(this.btnSelect1_Click);
			// 
			// txtNumber
			// 
			this.txtNumber.Location = new System.Drawing.Point(112, 24);
			this.txtNumber.Name = "txtNumber";
			this.txtNumber.Size = new System.Drawing.Size(128, 21);
			this.txtNumber.TabIndex = 1;
			this.txtNumber.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(80, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "手机号码:";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.listBox1);
			this.groupBox2.Controls.Add(this.btnSelecte2);
			this.groupBox2.Controls.Add(this.txtAddress);
			this.groupBox2.Controls.Add(this.label3);
			this.groupBox2.Location = new System.Drawing.Point(8, 120);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(344, 280);
			this.groupBox2.TabIndex = 1;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "地区查号段";
			// 
			// listBox1
			// 
			this.listBox1.ItemHeight = 12;
			this.listBox1.Location = new System.Drawing.Point(16, 64);
			this.listBox1.Name = "listBox1";
			this.listBox1.Size = new System.Drawing.Size(320, 208);
			this.listBox1.TabIndex = 3;
			// 
			// btnSelecte2
			// 
			this.btnSelecte2.Location = new System.Drawing.Point(264, 24);
			this.btnSelecte2.Name = "btnSelecte2";
			this.btnSelecte2.TabIndex = 2;
			this.btnSelecte2.Text = "查询";
			this.btnSelecte2.Click += new System.EventHandler(this.btnSelecte2_Click);
			// 
			// txtAddress
			// 
			this.txtAddress.Location = new System.Drawing.Point(120, 24);
			this.txtAddress.Name = "txtAddress";
			this.txtAddress.Size = new System.Drawing.Size(128, 21);
			this.txtAddress.TabIndex = 1;
			this.txtAddress.Text = "";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 24);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(88, 16);
			this.label3.TabIndex = 0;
			this.label3.Text = "所属地区";
			// 
			// btnDataManager
			// 
			this.btnDataManager.Location = new System.Drawing.Point(16, 408);
			this.btnDataManager.Name = "btnDataManager";
			this.btnDataManager.TabIndex = 2;
			this.btnDataManager.Text = "数据管理";
			this.btnDataManager.Click += new System.EventHandler(this.btnDataManager_Click);
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(360, 442);
			this.Controls.Add(this.btnDataManager);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.Name = "MainForm";
			this.Text = "手机归属地查询系统";
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new MainForm());
		}

		private void btnSelect1_Click(object sender, System.EventArgs e)
		{
			if(this.txtNumber.Text.Length<7)
			{
				MessageBox.Show("请输入手机号码前七位");

			}
			else
			{
				string sqlString="select Province ,City from MPNumber where Number='"+this.txtNumber.Text+"'";
				DataTable datatable=access.Query("MPNumber",sqlString);
				if(datatable.Rows.Count>0)
				{
				
					this.lblResult.Text="所属地区:"+(string)datatable.Rows[0]["Province"]+" "+datatable.Rows[0]["City"];

				
					 
				}
				else
				{
					MessageBox.Show("没查询到该手机号码的信息");
				}
			}
			
		}

		private void btnSelecte2_Click(object sender, System.EventArgs e)
		{
			string sqlString="select Number from MPNumber where City='"+this.txtAddress.Text+"'";
			DataTable datatable=access.Query("MPNumber",sqlString);
			if(datatable.Rows.Count>0)
			{
				for(int i=0;i<datatable.Rows.Count;i++)
				{
					this.listBox1.Items.Add((string)datatable.Rows[i]["Number"]+"****"+"\n");

				}
				
			}
			else
			{
				MessageBox.Show("没查询到该手机号码的信息");
			}
		}

		private void btnDataManager_Click(object sender, System.EventArgs e)
		{
			frmDataManager objfrmDataManager=new frmDataManager ();
			objfrmDataManager.ShowDialog();

		
		}
	}
}

⌨️ 快捷键说明

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