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. threading; namespace mywifi {public partial class mywifi: FORM {public mywifi () {initializecomponent ();} system. diagnostics. stopwatch SW ;/// /// Start /// /// /// Private void button#click (Object sender, eventargs e) {// time record Sw = new system. diagnostics. stopwatch (); Sw. start (); timer1.start (); // multithreading thread onc = new thread (New threadstart (nonpametrrun); onc. start ();}/// /// Start time /// /// /// Private void timereffectick (Object sender, eventargs e) {timespan Ts = Sw. elapsed; Shijian. TEXT = string. format ("{0} day {1} hour {2} minute {3} second {4} millisecond", ts. days, ts. hours, ts. minutes, ts. seconds, ts. milliseconds );}/// /// Import data by thread /// Public void nonpametetrrun () {datatable dt = new datatable ("date"); datatable DS = new datatable ("date"); datatable BS = new datatable ("date "); BS. columns. add ("router_cmac", type. getType ("system. string "); BS. columns. add ("device_mac", type. getType ("system. string "); BS. columns. add ("create_time", type. getType ("system. string "); // BS. columns. add ("xiaxian_time", type. getType ("system. string "); BS. columns. add ("ID", type. getType ("system. string "); BS. columns. add ("ap_mac", type. getType ("system. string "); BS. columns. add ("singal", type. getType ("system. string "); try {// group query string SQL =" select router_mac, device_mac from macs_20140707 group by router_mac, device_mac "; dt = dbhelpermysql. getdatatable (SQL); For (INT I = 0; I <DT. rows. count; I ++) {// query the information of each user by group string sql1 = "select create_time, ID, ap_mac, singal from macs_20140707 where router_mac = '" + dt. rows [I] ["router_mac"] + "'and device_mac ='" + dt. rows [I] ["device_mac"] + "'order by create_time ASC"; DS = dbhelpermysql. getdatatable (sql1); For (int c = 0; C <Ds. rows. count; C ++) {// when the able is greater than 1, it can enter if (c-1> 0) {// datetime lasttime = datetime. parse (Ds. rows [C-1] [0]. tostring (); datetime currenttime = datetime. parse (Ds. rows [C] [0]. tostring (); timespan span = currenttime-lasttime; // you can specify 10 if (span. minutes> = 10) {BS. rows. add (new object [] {DT. rows [I] [0], DT. rows [I] [1], DS. rows [C] [0], DS. rows [C] [1], DS. rows [C] [2], DS. rows [C] [3]}) ;}} else if (c-1 <0) {BS. rows. add (new object [] {DT. rows [I] [0], DT. rows [I] [1], DS. rows [C] [0], DS. rows [C] [1], DS. rows [C] [2], DS. rows [C] [3]});} else if (I = DT. rows. count & C = Ds. rows. count) {for (int d = 0; D <BS. rows. count; D ++) {string STR = "insert into mydatewifi (router_mac, device_mac, create_time, ID, ap_mac, singal) values ('" + BS. rows [d] ["router_cmac"]. tostring () + "','" + BS. rows [d] ["device_mac"]. tostring () + "','" + datetime. parse (BS. rows [d] ["create_time"]. tostring () + "','" + Int. parse (BS. rows [d] ["ID"]. tostring () + "','" + BS. rows [d] ["ap_mac"] + "','" + Int. parse (BS. rows [d] ["singal"]. tostring () + "')"; dbhelper. executecommand (STR); If (D = BS. rows. count) {// time to stop SW. stop (); timespan Ts = Sw. elapsed ;}} max (Int. parse (Ds. rows [C] [1]. tostring (); setcatred (Ds. rows. count);} maxtat (I); setcatre (DT. rows. count) ;}} catch (exception ex) {Throw new exception (ex. message);} thread. sleep (600 );}////// Delegate to obtain the maximum number /// /// Public Delegate void sett (INT resp); Private void setcatre (INT resp) {If (label2.invokerequired = true) {sett set = new sett (setcatre); label2.invoke (set, new object [] {resp});} else {label2.text = resp. tostring ();}}/// /// Total number of delegates obtained /// /// Public Delegate void sett1 (INT respd); Private void setcatred (INT respd) {If (shulang. invokerequired = true) {sett1 set = new sett1 (setcatred); shulang. invoke (set, new object [] {respd});} else {shulang. TEXT = respd. tostring ();}}/// /// Number of times the delegate obtains the total number of cycles /// /// Public Delegate void sett2 (INT respd); Private void maxtat (INT respd) {If (label5.invokerequired = true) {sett2 set = new sett2 (maxtat); label5.invoke (set, new object [] {respd});} else {label5.text = respd. tostring ();}}/// /// Obtain the number of requests /// /// Public Delegate void sett3 (INT respd); Private void max (INT respd) {If (label6.invokerequired = true) {sett3 set = new sett3 (max); label6.invoke (set, new object [] {respd});} else {label6.text = respd. tostring ();}}}}
Write at work