Function:
1. Verification Code Automatic Identification
2. Connect mobile phone Xiang Teacher Online learning assistant
3. Automatically login and simulate to start online learning
4. Automatic control of the study time of each subject. , here are the effects diagram and the main code
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 Devexpress.skins;
Using Devexpress.xtrabars; namespace Teacherstudy {public partial class FrmMain:DevExpress.XtraEditors.XtraForm {Usercontrols.cousestudy
Cousestudy;
dal.teacheredu client {get; set;}
Public Frmmain (dal.teacheredu client) {this.client = client;
InitializeComponent (); } private void Frmmain_load (object sender, EventArgs e) {DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName
= Client.user.skinName; Client.
OnEvent + = new Dal.teacheredu.jackEventHandler (client_onevent);
Initskins (); Notifyicon1.text = this.
Text; This. Text = string.
Format (' {0} ({1}) ', Client.user.Nick.Split (' (') [0], client.user.Workplace); Lbltime.text = "Learned:" + client.user.totalTime.Replace ("", "").
Trim ();
Lblnick.text = Client.user.Nick; NotifYicon1.text = Client.user.Nick;
Cousestudy = new Usercontrols.cousestudy (client); Cousestudy.
Dock = DockStyle.Fill;
XTRATABPAGE1.CONTROLS.ADD (Cousestudy);
Barmenu.additem (Barbuttonitemexit);
Barmenu.additem (Barbuttonitemmain);
Barmenu.additem (Barskin);
Barmenu.additem (Barconfig);
Barmenu.additem (Barreg);
Barmenu.additem (Barrandomnextcouse); } void Client_onevent (object sender, Dal.eventargs e) {if (!e.message.contains (update after seconds)) {Log1.
Addlog (E.message);
} cousestudy.gridView1.RefreshData ();
lblMessage.Caption = E.message;
private void Initskins () {barmanager1.forceinitialize (); foreach (Skincontainer cnt in SkinManager.Default.Skins) {Barbuttonitem item = new Barbuttonitem (BarManager1, CNT.
Skinname);
Barskin.additem (item); Item.
ItemClick + = new DevExpress.XtraBars.ItemClickEventHandler (Skinbtn_itemclick);
} void Skinbtn_itemclick (object sender, DevExpress.XtraBars.ItemClickEventArgs e) {if (e.item.caption!= null)
{DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = e.item.caption;
Client.user.skinName = e.item.caption; New Dal.jackinifile ().
Savemodel (Client.user); } private void Notifyicon1_mousedoubleclick (object sender, MouseEventArgs e) {this.
topmost = true; This.
Visible = true; This.
Show (); This.
WindowState = Formwindowstate.normal; This.
topmost = false;
} private void Notifyicon1_mouseclick (object sender, MouseEventArgs e) {if (E.button = = mousebuttons.right) {
Popupmenu1.showpopup (mouseposition);
}} private void Frmmain_formclosing (object sender, FormClosingEventArgs e) {e.cancel = true; This.
Hide (); } private void Barbuttonitemexit_itemclick (object sender, Itemclickeventargs e) {if (DevExpress.XtraEditors.XtraMe Ssagebox.show (Confirm that you want to exit.)
"," Warning ", Messageboxbuttons.yesno, messageboxicon.warning) = = Dialogresult.yes) {application.exitthread ();
Application.exit (); }} private void Barconfig_itemclick (object sender, Itemclickeventargs e) {new Frmconfig (client).
ShowDialog (); private void Barreg_itemclick (object sender, Itemclickeventargs e) {new Frmreg ().
ShowDialog ();
} private void Barrandomnextcouse_itemclick (object sender, Itemclickeventargs e) {if (cousestudy.bgWork.IsBusy)
{cousestudy.appruntime = Datetime.minvalue; else {cousestudy.
Setrandomnextcouse ();
}
}
}
}
Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Drawing;
Using System.Text.RegularExpressions; Namespace Teacherstudy.dal {public class teacheredu {public int waitingseconds = 60*11;//Update server time minutes public dele
Gate void Jackeventhandler (object sender, EventArgs e);
public event Jackeventhandler OnEvent;
public virtual void Onjackevent (EventArgs e) {if (OnEvent!= null) OnEvent (this, e);
public delegate void Couseupdateeventhandler (Object Sender,model.couse e);
public event Couseupdateeventhandler Couseupdateevent;
public virtual void Onupdateevent (Model.couse e) {if (couseupdateevent!= null) couseupdateevent (this, e);
Public Model.user User {get; set;} private string BaseURL = String.
Empty;
Jackwebclient client = new Jackwebclient (); <summary>///Account Login///</summary>///<param name= "UID" ></param>///<param name= "p Assword "></param>///<retuRns></returns> public bool Login (string username, string Password,bool _360hours) {if (_360hours) {BA
Seurl = "2015SQJXJYC";
else {BaseURL = "2015sqjxjyb"; user = new Dal.jackinifile ().
Getmodel (username); Waitingseconds = new Random ().
Next (650, 1100);
if (user = null) user = new Model.user (); User.
UserName = UserName; User.
Password = Password;
User._360hours = _360hours;
int errorcount = 5;
Recheck:bitmap bmp = New Bitmap (2, 20);
String Verifycode=getverifycode (ref BMP); String postdata = "u=" + user. UserName + "&p=" +user.
Password+ "&c=" +verifycode+ "&i=0"; String Html = client. PostData ("http://" +baseurl+ ". Fxl.teacheredu.cn/guopeiadmin/login/checkuserlogin.aspx", PostData, "http://
2015sqjxjyb.fxl.teacheredu.cn/guopeiadmin/login/loginindex.aspx# ");
errorcount--;
if (Html = = "0") {//devexpress.xtraeditors.xtramessagebox.show ("Authenticode error");
Onjackevent (New EventArgs ("Authenticode Error")); if (Errorcount > 0) {goto ReCHeck
return false; } if (Html = = "1") {DevExpress.XtraEditors.XtraMessageBox.Show ("User name or password is incorrect.")
"); Onjackevent (The new EventArgs ("User name or password is incorrect.)
"));
return false; } if (Html = = "3") {DevExpress.XtraEditors.XtraMessageBox.Show ("Login failed.")
"); Onjackevent (New EventArgs ("Login failed.")
"));
return false;
} if (Html.contains ("main.aspx")) {user.logintime = DateTime.Now; Html = client.
Gethtml ("http://" + BaseURL + ". fxl.teacheredu.cn/guopeiadmin/main.aspx");
if (Html.contains ("Exit")) {htmlagilitypack.htmldocument doc = new htmlagilitypack.htmldocument (); Doc.
Loadhtml (Html); User.
Uid = stringhelper.cuthtml (Html, "userid=", "'"); User. Nick = doc. getElementById ("Span_user"). Innertext.replace ("", "").
Trim (); Html = client.
Gethtml ("http://" + BaseURL + ". fxl.teacheredu.cn/guopeiadmin/user/updateuserinfo.aspx"); Doc.
Loadhtml (Html); User. Workplace = doc. getElementById ("Txtworkplace").
Getattributevalue ("Value", ""); Updatehasstudytime ()//Update total learning time long onjackevent (newEventArgs ("Landing Success"));
return true;
} onjackevent (New EventArgs ("Login Failed"));
return false; public void Updatehasstudytime () {string Html = client.
Gethtml ("http://" + BaseURL + ". fxl.teacheredu.cn/guopeiadmin/statistics/studentquery_studentinfo.aspx");
Htmlagilitypack.htmldocument doc = new htmlagilitypack.htmldocument (); Doc.
Loadhtml (Html); User.totaltime = doc. getElementById ("Sp_duration").
InnerText; } internal string Getverifycode (ref System.Drawing.Bitmap Bitmap) {//need to verify picture string verifyurl = "http://" + baseur L + ". Fxl.teacheredu.cn/guopeiadmin/login/imagelog.aspx?time=" + DateTime.Now.Day + getintfromtime (datetime.now).
ToString ();; Stream img = client.
GetStream (Verifyurl, "get");
Frmverifyimage frm = new Frmverifyimage ();
Frm.picVerifyCode.Image = new System.Drawing.Bitmap (IMG);
Frm.imgurl = Verifyurl;
frm.client = client; if (frm. ShowDialog () = = System.Windows.Forms.DialogResult.OK) {return frm.
Getverifycode (); RetUrn "";
Public long Getintfromtime (DateTime dt) {Long lleft = 621355968000000000; DateTime dt1 = dt.
ToUniversalTime (); Long sticks = (dt1.
Ticks-lleft)/10000000;
return sticks;
Public list<model.couse> getlist () {onjackevent (new EventArgs ("Get Course ...")); Client.
Accept = "text/html, Application/xhtml+xml, */*";
list<model.couse> list = new list<model.couse> (); String Html = client. Gethtml ("http://" + BaseURL + ". Fxl.teacheredu.cn/guopeiadmin/studyplan/studentbookshelf.aspx", "http://
2015sqjxjyb.fxl.teacheredu.cn/guopeiadmin/main.aspx ");
HTML = stringhelper.cuthtml (HTML, "Selected course name", ""); Html = new Regex ("<!--. *?-->", regexoptions.ignorecase).
Replace (Html, ""); System.Text.RegularExpressions.Regex Regex = new System.Text.RegularExpressions.Regex ("<tr>[\\s\\s]*?</tr
> ", System.Text.RegularExpressions.RegexOptions.IgnoreCase); foreach (System.Text.RegularExpressions.Match tr in regex. Matches (Html)) {Model. Couse model = Getregexmodel (tr.
Value); if (model.cousename!= "" &&model.time!= "") {list.
ADD (model); } onjackevent (New EventArgs ("Get +list.")
count+ ")");
return list; } model.couse Getregexmodel (string trhtml) {trhtml = Trhtml.replace ("\ r \ n", "").
Replace ("T", "");
int i = 0;
Model.couse model = new Model.couse (); System.Text.RegularExpressions.Regex Regex = new System.Text.RegularExpressions.Regex ("<td .*?>" (. *?)
</td> ", System.Text.RegularExpressions.RegexOptions.IgnoreCase); foreach (System.Text.RegularExpressions.Match item in regex.
Matches (trhtml)) {i++; switch (i) {Case 1: {model.cousename = Stringhelper.replacehtmltag (item. Groups[0].
Value); Model. Studyplanbookid = stringhelper.cuthtml (item.
Value, "OpenBook (", ",");
} break; Case 2:model.time = Stringhelper.replacehtmltag (item. Groups[0]. Value). Replace ("", ""). Trim ();
Break Case 3:model.status = Stringhelper.replacehtmltag (item. Groups[0]. Value). ReplAce ("", ""). Trim ();
Break Case 4:model.action = Stringhelper.replacehtmltag (item. Groups[0]. Value). Replace ("", ""). Trim ();
Break
} model.action = Model.action.Trim ();
if (Model.action.Trim ()!= "compulsory") Model.action = "Elective";
return model;
public string Enterstudypage (ref Model.couse Model) {model.log = "Enter the Learning page";
Onjackevent (New EventArgs ("Enter the Learning page")); String baseurl = "http://" + BaseURL + ". fxl.teacheredu.cn/guopeiadmin/coursestudy/studyfrmnew.aspx? Studyplanbookid= "+ model.
Studyplanbookid; String Html = client.
Gethtml (BaseURL);
String url = "Recordtimenew.aspx" + stringhelper.cuthtml (Html, "recordtimenew.aspx", "\");
url = System.Web.HttpUtility.HtmlDecode (URL); url = new Uri (new Uri (baseurl), url).
ToString ();
return URL; } public void SetFieldValue (string url,ref model.couse Model) {string Html = client.
gethtml (URL);
Htmlagilitypack.htmldocument doc = new htmlagilitypack.htmldocument (); Doc.
Loadhtml (Html); User. Uid = doc. GetElementbyid ("Txtuserid").
Getattributevalue ("Value", "");
User.recordtime = DateTime.Now; Model. Studyplanbookid = doc. getElementById ("Txtbookid").
Getattributevalue ("Value", ""); User.start = doc. getElementById ("Txtstart").
Getattributevalue ("Value", ""); public bool Updatetimeforstudy (ref Model.couse Model) {client. Accept = "application/x-www-form-urlencoded;
Charset=utf-8 "; String postdata = "uid=" + user. Uid + "&bid=" + model. Studyplanbookid + "&second=" + (Datetime.now-user.recordtime).
Totalseconds.tostring ("0") + "&start=" + user.start; String Html = client. PostData ("http://" + BaseURL + ". Fxl.teacheredu.cn/guopeiadmin/coursestudy/updatetimeforstudy.aspx", PostData, "http ://2015sqjxjyb.fxl.teacheredu.cn/guopeiadmin/coursestudy/recordtimenew.aspx?bookid=172&studyplanbookid=161
");
if (Html.split (', ') [1] = = "true") {Model.log = "update statistic time succeeded";
Onjackevent (New EventArgs ("Update statistic Time Successful"));
return true;
else {model.log = "Update statistic time failed";
Onjackevent (New EventArgs ("Update statistic Time Failed"));
return false;
}
}
}
}