问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Xml;usingmshtml;namespaceWindowsApplication1{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();textBox_url.Text="http://bbs.jznews.com.cn/portal.php";InitListView();LoadUserData();}//privatevoidherfclick(stringurl)//{//for(inti=0;i<webBrowser1.Document.All.Count;i++)//{//if(webBrowser1.Document.All[i].TagName=="A"&&webBrowser1.Document.All[i].GetAttribute("href").ToString().Trim()==url)//{//webBrowser1.Document.All[i].InvokeMember("click");//引发”CLICK”事件//break;//}//}//}privatevoidwebBrowser1_DocumentCompleted(objectsender,WebBrowserDocumentCompletedEventArgse){webBrowser1.ScriptErrorsSuppressed=true;if((e.Url.ToString().ToLower().Equals("http://bbs.jznews.com.cn/portal.php"))//登陆页面||(e.Url.ToString().ToLower().Equals(""))){HtmlElementtextboxUserId=this.webBrowser1.Document.GetElementById("ls_username");//如果没有ID,用Name获取//HtmlElementtextboxUserId=this.webBrowser1.Document.All["登录用户名文本框的Name"];HtmlElementtextboxPassword=this.webBrowser1.Document.GetElementById("ls_password");//如果没有ID,用Name获取//HtmlElementtextboxPassword=this.webBrowser1.Document.All["登录密码框的Name"];//HtmlElementbuttonSubmit=this.webBrowser1.Document.GetElementById("ls_cookietime");//如果没有ID,用Name获取//HtmlElementbuttonSubmit=this.webBrowser1.Document.All["ls_cookietime"];for(inti=this.listView_usr.SelectedItems.Count-1;i>=0;i--){ListViewItemitem=this.listView_usr.SelectedItems[i];//this.listView_usr.Items.Remove(item);stringstrUsr=item.SubItems[0].Text;stringstrPwd=item.SubItems[1].Text;textboxUserId.InnerText=strUsr;//填写帐号textboxPassword.InnerText=strPwd;//填写密码}//触发登录事件HtmlElementCollectionelements=this.webBrowser1.Document.GetElementsByTagName("button");//Request.ServerVariables("HTTP_REFERER");foreach(HtmlElementiteminelements){if(item.GetAttribute("className").Equals("pnvm")&&item.GetAttribute("type").Equals("submit")){//continue;item.InvokeMember("click");}//elseif(item!=textBox_url.Text)//{//item.InvokeMember("click");//}}}//elseif((e.Url.ToString().ToLower().Equals("http://bbs.jznews.com.cn/portal.php"))//||(e.Url.ToString().ToLower().Equals("http://bbs.jznews.com.cn/")))//{//HtmlElementCollectionlinks=webBrowser1.Document.Links;//foreach(HtmlElementlinkinlinks)//{//if(null==link.InnerText)//{//continue;//}//if(link.InnerText.Equals(""))//{//link.InvokeMember("click");//激发链接的点击事件//}//}//}}privatevoidwebBrowser1_NewWindow(objectsender,CancelEventArgse){e.Cancel=true;//取消使用系统的IE打开超链接webBrowser1.Navigate((senderasWebBrowser).Document.ActiveElement.GetAttribute("href"));//继续在窗体中打开页面}privatevoidwebBrowserQuit(){if(null==webBrowser1.Document){return;}webBrowser1.Document.Cookie="";HtmlElementCollectionlinks=webBrowser1.Document.Links;if(null==links){return;}foreach(HtmlElementlinkinlinks){if(null==link.InnerText){continue;}if(link.InnerText.Equals("退出")){link.InvokeMember("click");//激发链接的点击事件break;}}}privatevoidbutton1_Click(objectsender,EventArgse){if(""!=textBox_url.Text){webBrowserQuit();//if(null==webBrowser1.Url)//{webBrowser1.Url=newUri(textBox_url.Text);//}}}privatevoidInitListView(){listView_usr.GridLines=true;listView_usr.FullRowSelect=true;listView_usr.View=View.Details;listView_usr.Scrollable=true;listView_usr.MultiSelect=false;listView_usr.HeaderStyle=ColumnHeaderStyle.Nonclickable;listView_usr.Columns.Add("用户名",100,HorizontalAlignment.Right);listView_usr.Columns.Add("密码",100,HorizontalAlignment.Left);}privatevoidLoadUserData(){XmlDocumentXMLDom=newXmlDocument();stringstrPath=System.Environment.CurrentDirectory+"/user.xml";XMLDom.Load(strPath);XmlNodeListnewXMLNodes=XMLDom.SelectNodes("/users/user");listView_usr.Items.Clear();foreach(XmlElementxninnewXMLNodes){//XmlElement*pstElememt=(XmlElement*)&XmlNode;stringstrId=xn.GetAttribute("id");stringstrPwd=xn.GetAttribute("pwd");ListViewItemli=newListViewItem();li.SubItems.Clear();li.SubItems[0].Text=strId;li.SubItems.Add(strPwd);listView_usr.Items.Add(li);//MessageBox.Show(title);}}privatevoidlistView_usr_SelectedIndexChanged(objectsender,EventArgse){if(""!=textBox_url.Text){webBrowserQuit();webBrowser1.Url=newUri(textBox_url.Text);}}privatevoidlistView_usr_DoubleClick(objectsender,EventArgse){if(""!=textBox_url.Text){webBrowserQuit();if(null==webBrowser1.Url){webBrowser1.Url=newUri(textBox_url.Text);}}}privatevoidbutton_addusr_Click(objectsender,EventArgse){XmlDocumentXMLDom=newXmlDocument();stringstrPath=System.Environment.CurrentDirectory+"/user.xml";XMLDom.Load(strPath);XmlElementtheUser=XMLDom.CreateElement("user");theUser.SetAttribute("id",textBox_usr.Text);theUser.SetAttribute("pwd",textBox_pwd.Text);XMLDom.DocumentElement.AppendChild(theUser);XMLDom.Save(strPath);LoadUserData();}privatevoidbutton_delusr_Click(objectsender,EventArgse){XmlDocumentXMLDom=newXmlDocument();stringstrPath=System.Environment.CurrentDirectory+"/user.xml";XMLDom.Load(strPath);for(inti=this.listView_usr.SelectedItems.Count-1;i>=0;i--){ListViewItemitem=this.listView_usr.SelectedItems[i];//this.listView_usr.Items.Remove(item);stringstrUsr=item.SubItems[0].Text;stringstrItemPath="/users/user[@id=""+strUsr+""]";XmlElementtheUser=(XmlElement)XMLDom.SelectSingleNode(strItemPath);if(null!=theUser){theUser.ParentNode.RemoveChild(theUser);}}XMLDom.Save(strPath);LoadUserData();}privatevoidForm1_Load(objectsender,EventArgse){}}}
解决方案
解决方案二:
该回复于2011-12-08 11:03:09被版主删除
解决方案三:
我晕哦,怎么被删除了,