?? mainform.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 + -