Batch import of mobile phone numbers

Source: Internet
Author: User
Tags dbase string back

Using system;
Using system. drawing;
Using system. collections;
Using system. componentmodel;
Using system. Windows. forms;
Using system. Data;
Using system. Data. sqlclient;

Namespace smsphone
{
/// <Summary>
/// Summary of form1.
/// </Summary>
Public class form1: system. Windows. Forms. Form
{
Private system. Windows. Forms. Button button1;
Private system. Windows. Forms. textbox textbox1;
Private system. Windows. Forms. Label label1;
Private system. Windows. Forms. groupbox groupbox1;
Private system. Windows. Forms. groupbox groupbox2;
Private system. Windows. Forms. textbox textbox2;
Private system. Windows. Forms. textbox textbox3;
Private system. Windows. Forms. Label label2;
Private system. Windows. Forms. Label label3;
Private system. Windows. Forms. textbox textbox4;
Private system. Windows. Forms. Label label4;
Private system. Windows. Forms. Label label5;
Private system. Windows. Forms. textbox textbox5;
Private system. Windows. Forms. Label label6;
Private system. Windows. Forms. Label label7;
Private system. Windows. Forms. Button button2;
Private system. Windows. Forms. textbox textbox6;
Private system. Windows. Forms. textbox textbox7;
/// <Summary>
/// Required designer variables.
/// </Summary>
Private system. componentmodel. Container components = NULL;
Private system. Windows. Forms. Label label8;
Private system. Windows. Forms. Label label9;

Public sqlconnection conn;


Public form1 ()
{
//
// Required for Windows Form Designer support
//
Initializecomponent ();

//
// Todo: add Any constructor code after initializecomponent calls
//
}

/// <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void dispose (bool disposing)
{
If (disposing)
{
If (components! = NULL)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}

# Region code generated by Windows Form Designer
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. button1 = new system. Windows. Forms. Button ();
This. textbox1 = new system. Windows. Forms. Textbox ();
This. label1 = new system. Windows. Forms. Label ();
This. groupbox1 = new system. Windows. Forms. groupbox ();
This. label9 = new system. Windows. Forms. Label ();
This. label3 = new system. Windows. Forms. Label ();
This. label2 = new system. Windows. Forms. Label ();
This. textbox3 = new system. Windows. Forms. Textbox ();
This. textbox2 = new system. Windows. Forms. Textbox ();
This. groupbox2 = new system. Windows. Forms. groupbox ();
This. label8 = new system. Windows. Forms. Label ();
This. textbox7 = new system. Windows. Forms. Textbox ();
This. textbox6 = new system. Windows. Forms. Textbox ();
This. button2 = new system. Windows. Forms. Button ();
This. label7 = new system. Windows. Forms. Label ();
This. label6 = new system. Windows. Forms. Label ();
This. textbox5 = new system. Windows. Forms. Textbox ();
This. label5 = new system. Windows. Forms. Label ();
This. label4 = new system. Windows. Forms. Label ();
This. textbox4 = new system. Windows. Forms. Textbox ();
This. groupbox1.suspendlayout ();
This. groupbox2.suspendlayout ();
This. suspendlayout ();
//
// Button1
//
This. button1.location = new system. Drawing. Point (160, 48 );
This. button1.name = "button1 ";
This. button1.tabindex = 0;
This. button1.text = "batch import ";
This. button1.click + = new system. eventhandler (this. button#click );
//
// Textbox1
//
This. textbox1.location = new system. Drawing. Point (16, 48 );
This. textbox1.name = "textbox1 ";
This. textbox1.tabindex = 1;
This. textbox1.text = "133699 ";
//
// Label1
//
This. label1.location = new system. Drawing. Point (8, 24 );
This. label1.name = "label1 ";
This. label1.size = new system. Drawing. Size (136, 16 );
This. label1.tabindex = 2;
This. label1.text = "Enter the first seven digits of the mobile phone number :";
//
// Groupbox1
//
This. groupbox1.controls. Add (this. label9 );
This. groupbox1.controls. Add (this. label3 );
This. groupbox1.controls. Add (this. label2 );
This. groupbox1.controls. Add (this. textbox3 );
This. groupbox1.controls. Add (this. textbox2 );
This. groupbox1.controls. Add (this. label1 );
This. groupbox1.controls. Add (this. textbox1 );
This. groupbox1.controls. Add (this. button1 );
This. groupbox1.location = new system. Drawing. Point (8,200 );
This. groupbox1.name = "groupbox1 ";
This. groupbox1.size = new system. Drawing. Size (280,168 );
This. groupbox1.tabindex = 3;
This. groupbox1.tabstop = false;
This. groupbox1.text = "batch import mobile phone numbers ";
//
// Label9
//
This. label9.forecolor = system. Drawing. systemcolors. activecaption;
This. label9.location = new system. Drawing. Point (16,136 );
This. label9.name = "label9 ";
This. label9.size = new system. Drawing. Size (240, 23 );
This. label9.tabindex = 7;
//
// Label3
//
This. label3.location = new system. Drawing. Point (128,112 );
This. label3.name = "label3 ";
This. label3.size = new system. Drawing. Size (16, 23 );
This. label3.tabindex = 6;
This. label3.text = "-";
//
// Label2
//
This. label2.location = new system. Drawing. Point (8, 80 );
This. label2.name = "label2 ";
This. label2.size = new system. Drawing. Size (128, 16 );
This. label2.tabindex = 5;
This. label2.text = "the last four digits of the input number segment :";
//
// Textbox3
//
This. textbox3.location = new system. Drawing. Point (144,104 );
This. textbox3.name = "textbox3 ";
This. textbox3.tabindex = 4;
This. textbox3.text = "3 ";
//
// Textbox2
//
This. textbox2.location = new system. Drawing. Point (16,104 );
This. textbox2.name = "textbox2 ";
This. textbox2.size = new system. Drawing. Size (104, 21 );
This. textbox2.tabindex = 3;
This. textbox2.text = "0 ";
//
// Groupbox2
//
This. groupbox2.controls. Add (this. label8 );
This. groupbox2.controls. Add (this. textbox7 );
This. groupbox2.controls. Add (this. textbox6 );
This. groupbox2.controls. Add (this. button2 );
This. groupbox2.controls. Add (this. label7 );
This. groupbox2.controls. Add (this. label6 );
This. groupbox2.controls. Add (this. textbox5 );
This. groupbox2.controls. Add (this. label5 );
This. groupbox2.controls. Add (this. label4 );
This. groupbox2.controls. Add (this. textbox4 );
This. groupbox2.location = new system. Drawing. Point (8, 16 );
This. groupbox2.name = "groupbox2 ";
This. groupbox2.size = new system. Drawing. Size (280,168 );
This. groupbox2.tabindex = 4;
This. groupbox2.tabstop = false;
This. groupbox2.text = "database information ";
//
// Label8
//
This. label8.location = new system. Drawing. Point (120,136 );
This. label8.name = "label8 ";
This. label8.size = new system. Drawing. Size (120, 23 );
This. label8.tabindex = 9;
//
// Textbox7
//
This. textbox7.location = new system. Drawing. Point (136,104 );
This. textbox7.name = "textbox7 ";
This. textbox7.tabindex = 8;
This. textbox7.text = "sa ";
//
// Textbox6
//
This. textbox6.location = new system. Drawing. Point (8,104 );
This. textbox6.name = "textbox6 ";
This. textbox6.tabindex = 7;
This. textbox6.text = "sa ";
//
// Button2
//
This. button2.location = new system. Drawing. Point (8,136 );
This. button2.name = "button2 ";
This. button2.tabindex = 6;
This. button2.text = "test connection ";
This. button2.click + = new system. eventhandler (this. button2_click );
//
// Label7
//
This. label7.location = new system. Drawing. Point (136, 80 );
This. label7.name = "label7 ";
This. label7.size = new system. Drawing. Size (100, 16 );
This. label7.tabindex = 5;
This. label7.text = "Password :";
//
// Label6
//
This. label6.location = new system. Drawing. Point (8, 80 );
This. label6.name = "label6 ";
This. label6.size = new system. Drawing. Size (100, 16 );
This. label6.tabindex = 4;
This. label6.text = "User name :";
//
// Textbox5
//
This. textbox5.location = new system. Drawing. Point (136, 48 );
This. textbox5.name = "textbox5 ";
This. textbox5.tabindex = 3;
This. textbox5.text = "usm_sgip ";
//
// Label5
//
This. label5.location = new system. Drawing. Point (136, 24 );
This. label5.name = "label5 ";
This. label5.size = new system. Drawing. Size (96, 16 );
This. label5.tabindex = 2;
This. label5.text = "Database Name :";
//
// Label4
//
This. label4.location = new system. Drawing. Point (8, 24 );
This. label4.name = "label4 ";
This. label4.size = new system. Drawing. Size (88, 16 );
This. label4.tabindex = 1;
This. label4.text = "server name :";
//
// Textbox4
//
This. textbox4.location = new system. Drawing. Point (8, 48 );
This. textbox4.name = "textbox4 ";
This. textbox4.tabindex = 0;
This. textbox4.text = "USER-41V1A4IKRT // Bulbul ";
//
// Form1
//
This. autoscalebasesize = new system. Drawing. Size (6, 14 );
This. clientsize = new system. Drawing. Size (296,373 );
This. Controls. Add (this. groupbox2 );
This. Controls. Add (this. groupbox1 );
This. Name = "form1 ";
This. Text = "batch import mobile phone numbers to the system ";
This. Load + = new system. eventhandler (this. form#load );
This. groupbox1.resumelayout (false );
This. groupbox2.resumelayout (false );
This. resumelayout (false );

}
# Endregion

/// <Summary>
/// Main entry point of the application.
/// </Summary>
[Stathread]
Static void main ()
{
Application. Run (New form1 ());
}
Private void form1_load (Object sender, system. eventargs E)
{

}

Private void button2_click (Object sender, system. eventargs E)
{

// Database address
String dbserver = This. textbox4.text;
// Database Name
String DBASE = This. textbox5.text;
// Database username
String dbuserid = This. textbox6.text;
// Database Password
String dbuserpsw = This. textbox7.text;
// Connect to the database string
String sqlconn = "Server =" + dbserver + "; database =" + DBASE + "; uid =" + dbuserid + "; Pwd =" + dbuserpsw + "";

Sqlconnection conn = new sqlconnection (sqlconn );
If (conn. State = connectionstate. Closed)
{
Conn. open ();
This. label8.text = "database connection successful! ";
}
Else
{
This. label8.text = "database connection failed. Please check your input! ";
}
}

Private void button#click (Object sender, system. eventargs E)
{

Int I;
String strsql;

// Database address
String dbserver = This. textbox4.text;
// Database Name
String DBASE = This. textbox5.text;
// Database username
String dbuserid = This. textbox6.text;
// Database Password
String dbuserpsw = This. textbox7.text;
// Number segment
String forward = This. textbox2.text;
String back = This. textbox3.text;

String phoneid = This. textbox1.text;
// Connect to the database string
String sqlconn = "Server =" + dbserver + "; database =" + DBASE + "; uid =" + dbuserid + "; Pwd =" + dbuserpsw + "";
// Sqlconnection conn = new sqlconnection ("Server = USER-41V1A4IKRT // Bulbul; database = usm_sgip; uid = sa; Pwd = sa ");

Sqlconnection conn = new sqlconnection (sqlconn );
For (I = int. parse (forward); I <Int. parse (back); I ++)
{
String input;
Input = phoneid + formatkey (object) I). tostring ());
Strsql = "insert into phone (phone) values (" + input + ")";
Sqlcommand cmd = new sqlcommand (strsql, Conn );
Conn. open ();
Cmd. executenonquery ();
Conn. Close ();
}
This. label9.text = "Import successful! ";
}
Private string formatkey (string input)
{
If (input. Length = 1)
{
Input = "000" + input;
}
If (input. Length = 2)
{
Input = "00" + input;
}
If (input. Length = 3)
{
Input = "0" + input;
}
If (input. Length = 4)
{
Input = input;
}
Return input;
}

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.