WinForm Right-click Import phone number

Source: Internet
Author: User

Private voidImport Phone number Toolstripmenuitem_click (Objectsender, EventArgs e) {            using(OpenFileDialog Openfile =NewOpenFileDialog ()) {Openfile.filter="text Files |*.txt"; Openfile.multiselect=false; if(Openfile.showdialog () = =DialogResult.OK) {Thread threadfile=NewThread (() =ReadFile (openfile.filename)); Threadfile. IsBackground=true; Threadfile.                Start (); }            }        }        Private voidReadFile (stringfilename) {Txtlog. Invoke (NewAction (() ={Txtlog. AppendText ("start reading mobile phone number".            Setlog ());            })); varFile =file.open (filename, filemode.open); intnum =0; intGoods =0; intrepeat =0; using(varstream =NewStreamReader (file)) {                 while(!Stream. Endofstream) {Lock(lock_send) {if(Sendlist. Count > About)                        {                             Break; }} num++; stringLinetemp =Stream. ReadLine ().                    Trim (); if(Istel (linetemp)) {Lock(lock_send) {vardata = Sendlist. Where (m = M.tel = =linetemp).                            FirstOrDefault (); if(Data! =NULL) {Repeat++; Continue; }} Goods++; Sendtel _send=NewSendtel (); _send. Tel=linetemp; _send.sms_status=status. Pending delivery; _send.send_time=NULL; ListViewItem Item=NewListViewItem (_send.                        Tel); Item. SubItems.Add (_send.sms_status.                        ToString ()); Item.                        SubItems.Add (_send.send_time); Item. SubItems.Add (""); Listsend.invoke (NewAction (() ={ListViewItem Backitem=LISTSEND.ITEMS.ADD (item); Dic. ADD (_send.                        Tel, Backitem);                        })); Lock(lock_send) {sendlist.                        ADD (_send); }}}} txtlog. Invoke (NewAction (() =            {                stringLog =string. Format ("Add complete! Valid data is: {0}, filter duplicate data: {1}, total data: {2}", goods. ToString (), repeat. ToString (), Num.                ToString ()); Txtlog. AppendText (log.            Setlog ());        })); }        /// <summary>        ///Verify that the phone number is legal/// </summary>        /// <param name= "Tel" ></param>        /// <returns></returns>         Public Static BOOLIstel (stringTel) {            Try            {                if(string. IsNullOrEmpty (tel) | | Tel. Length! = One)                {                    return false; }                returnSystem.Text.RegularExpressions.Regex.IsMatch (tel,@"^[1]+[3,4,5,6,7,8]+\d{9}"); }            Catch(Exception ex) {return false; }        }

A long time ago wrote the code, read the TXT file, a line of a mobile phone number,

It seems to require TXT text file must be UTF8 format, otherwise read out will be garbled.

WinForm Right-click Import phone number

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.