手機歸屬地查詢程序代碼

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.Configuration;
using System.Data.SqlClient;

namespace 號碼歸屬地查詢
{
        public partial class Form1 : Form
        {
                public Form1()
                {
                        InitializeComponent();
                }

                private void Form1_Load(object sender, EventArgs e)
                {

                }

                private void button1_Click(object sender, EventArgs e)
                {
                     string conn=ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
                     string number,num;
                     number = textBox1.Text.Trim();
                     num = number.Substring(0,7);
                     using (SqlConnection sqlconn = new SqlConnection(conn))
                     {
                             sqlconn.Open();
                             SqlCommand comm = sqlconn.CreateCommand();
                             comm.CommandText = "select * from list where num='"+num+"'";
                             SqlDataReader read = comm.ExecuteReader();
                             if (!read.Read())
                             {
                                     MessageBox.Show("沒有您要找的號碼的歸屬地!");
                             }
                             else
                             {
                                     lb_City.Text = read.GetString(read.GetOrdinal("city"));
                                     lb_num.Text = read.GetString(read.GetOrdinal("code"));
                                     lb_stype.Text = read.GetString(read.GetOrdinal("cardtype"));
                             }
                     }
                }

                private void textBox1_KeyPress(object sender,KeyPressEventArgs e)
                {
                        if (e.KeyChar<='z'&&e.KeyChar>='a')
                        {
                                e.Handled =true;
                        }
                        if (textBox1.Text.Length == 11)
                        {
                                textBox1.ForeColor = System.Drawing.Color.Red;
                        }

                }

                
        }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章