代碼如下:
成都創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),萊山企業(yè)網(wǎng)站建設(shè),萊山品牌網(wǎng)站建設(shè),網(wǎng)站定制,萊山網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷(xiāo),網(wǎng)絡(luò)優(yōu)化,萊山網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專(zhuān)業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
/// summary
/// 連接到窗體:通過(guò)密碼保護(hù)信息找回密碼!
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void lbl_mibao_Click(object sender, EventArgs e)
{
Getbackpwd getbackpwd = new Getbackpwd();
getbackpwd.Show();
}
/// summary
/// 當(dāng)該窗體加載時(shí)從xml文件中讀取用戶信息并加載到combox的Items中
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void Addresslist_Load(object sender, EventArgs e)
{
XmlTextReader reader = new XmlTextReader(@"E:\面向?qū)ο?-C#練習(xí)\通訊錄\address list\address list\user.xml");
while (reader.Read())
{
//if (reader.LocalName.Equals("Name") || reader.LocalName.Equals("Number"))
if (reader.LocalName.Equals("username"))
{
this.cmbUserName.Items.Add(reader.ReadString());
}
//if (reader.LocalName.Equals("Number"))
//{
// this.label2.Text += reader.ReadString() + "\n";\
//}
}
reader.Close();
}
/// summary
/// 保存用戶名到user.xml
/// /summary
//在listcontol上更改SelectedValue時(shí)執(zhí)行從數(shù)據(jù)庫(kù)讀取密碼的事件
private void cmbUserName_SelectedValueChanged(object sender, EventArgs e)
{
string username = cmbUserName.Text.Trim();
string sql = string.Format("select pwd from Admin where Username='{0}'", username);
try
{
SqlCommand command = new SqlCommand(sql, DBHelper.connection);
DBHelper.connection.Open();
SqlDataReader dataReader = command.ExecuteReader();
while (dataReader.Read())
{
txtpwd.Text = (string)dataReader["pwd"];
checkBoxpwd.Checked = true;
}
}
catch
{
MessageBox.Show("數(shù)據(jù)庫(kù)操作出錯(cuò)!");
}
finally
{
DBHelper.connection.Close();
}
}
/// summary
/// 記住密碼操作
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void checkBoxpwd_Enter(object sender, EventArgs e)
{
bool check = true;
check = checkinput(cmbUserName.Text.Trim());
if ((string)cmbUserName.Text.Trim() == "")
{
MessageBox.Show("請(qǐng)輸入用戶名", "輸入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
cmbUserName.Focus();
}
else
{
if (txtpwd.Text.Trim() == "")
{
MessageBox.Show("請(qǐng)輸入密碼", "輸入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtpwd.Focus();
}
else
{
bool isValidUser = false; // 標(biāo)識(shí)是否為合法用戶
string message = ""; // 如果登錄失敗,顯示的消息提示
// 如果驗(yàn)證通過(guò),就顯示相應(yīng)的用戶窗體,并將當(dāng)前窗體設(shè)為不可見(jiàn)
if (ValidateInput())
{
// 調(diào)用用戶驗(yàn)證方法
isValidUser = ValidateUser(cmbUserName.Text, txtpwd.Text, ref message);
// 如果是合法用戶,顯示相應(yīng)的窗體
if (isValidUser)
{
if (check == true)
{
XmlDocument doc = new XmlDocument();
doc.Load(@"E:\面向?qū)ο?-C#練習(xí)\通訊錄\address list\address list\user.xml");//(@"E:\面向?qū)ο?-C#練習(xí)\通訊錄\address list\address list\user.xml");
XmlElement node = doc.CreateElement("user");
XmlNode xnode = (XmlNode)doc.CreateElement("username");
xnode.InnerText = cmbUserName.Text.Trim();
node.AppendChild(xnode);
doc.DocumentElement.InsertAfter(node, doc.DocumentElement.LastChild);
doc.Save(@"E:\面向?qū)ο?-C#練習(xí)\通訊錄\address list\address list\user.xml");
//doc.Load (@"E:\面向?qū)ο?-C#練習(xí)\通訊錄\address list\address list\user.xml");
}
}
// 如果登錄失敗,顯示相應(yīng)的消息
else
{
MessageBox.Show(message, "記住密碼失敗!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
}
/// summary
/// 驗(yàn)證當(dāng)前combox中內(nèi)容是否已經(jīng)存在于xml文件中
/// /summary
/// param name="text"/param
/// returns/returns
private bool checkinput(string text)
{
int count;
bool c = true;
for (count = 0; count cmbUserName.Items.Count;count ++ )
{
if (text ==(string )cmbUserName .Items [count])
{
c=false;
}
}
return c;
}
xml文件內(nèi)容如下:?xml version="1.0" encoding="utf-8"?
person
user
'加入一個(gè)命令按鈕,兩個(gè)文本框,第一個(gè)用來(lái)輸入賬號(hào),第二個(gè)用來(lái)輸入密碼
Private
Sub
Command1_Click()
Dim
vDoc,
vTag
Dim
i
As
Integer
Set
vDoc
=
WebBrowser1.Document
For
i
=
To
vDoc.All.length
-
1
'檢測(cè)所有標(biāo)簽
If
UCase(vDoc.All(i).tagName)
=
"INPUT"
Then
'找到input標(biāo)簽
Set
vTag
=
vDoc.All(i)
If
vTag.Type
=
"text"
Then
'看看是不是我們需要的
If
vTag.Name
=
"username"
Then
vTag.Value
=
Text1.Text
'這里是要搜索的內(nèi)容
End
If
End
If
Next
i
For
i
=
To
vDoc.All.length
-
1
'檢測(cè)所有標(biāo)簽
If
UCase(vDoc.All(i).tagName)
=
"INPUT"
Then
'找到input標(biāo)簽
Set
vTag
=
vDoc.All(i)
If
vTag.Type
=
"password"
Then
vTag.Value
=
Text2.Text
'看看是不是我們需要的
If
vTag.Value
=
"登陸"
Then
vTag.Select
'也可以沒(méi)有這個(gè)
vTag.Click
'點(diǎn)擊提交了,一切都OK了
End
If
Next
i
End
Sub
Private
Sub
Form_Load()
WebBrowser1.Navigate
";tpl=mn"
End
Sub
Private
Sub
Form_Resize()
WebBrowser1.Width
=
Form1.Width
-
500
WebBrowser1.Height
=
Form1.Height
-
1200
End
Sub
,不會(huì)的可以HI我,這是我現(xiàn)在用的。保證沒(méi)問(wèn)題。,復(fù)制代碼即可。
添加一個(gè)webbrowser控件,然后在它的complete事件里添加代碼:
Dim?d?As?Object,?o?As?Object,?pc?As?String
On?Error?Resume?Next
Set?d?=?web.Document
If?d?Is?Nothing?Then?Exit?Sub
Set?o?=?d.getElementById("username")
o.Value?=?"admin"
Set?o?=?d.getElementById("pwd_")
o.Value?=?"123456"
web.Navigate?"javascript:checkLogin();void?0"