Private?Sub?BtOk_Click(ByVal?sender?As?Object,?ByVal?e?As?System.EventArgs)?Handles?Btok.Click

創(chuàng)新互聯(lián)建站堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的和政網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
Dim?con?As?OleDbConnection?=?New?OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data?Source=Admin.accdb;Persist?Security?Info=True")
Dim?com?As?OleDbCommand?=?New?OleDbCommand("select?*?from?用戶名",?con)
con.Open()
Dim?h1?As?OleDbDataReader
Dim?table?As?New?DataTable
h1?=?com.ExecuteReader()
table.Load(h1)
If?txtName.Text?=?""?Then
MsgBox("請(qǐng)輸入用戶名",?MsgBoxStyle.OkCancel?+?MsgBoxStyle.Exclamation,?"錯(cuò)誤提示")
ElseIf?txtName.Text??""?And?txtPasswd.Text?=?""?Then
MsgBox("請(qǐng)輸入密碼",?MsgBoxStyle.OkCancel?+?MsgBoxStyle.Exclamation,?"錯(cuò)誤提示")
ElseIf?table.Select("用戶名='"??txtName.Text??"'").Length??0?Then
If?table.Select("用戶名='"??txtName.Text??"'")(0)("密碼").ToString?=?txtPasswd.Text?Then
MsgBox("成功登陸",?MsgBoxStyle.OkCancel?+?MsgBoxStyle.Exclamation,?"錯(cuò)誤提示")?Then
Form1.Show()
Me.Visible?=?False
Exit?Sub
Else
MsgBox("密碼錯(cuò)誤",?MsgBoxStyle.OkCancel?+?MsgBoxStyle.Exclamation,?"錯(cuò)誤提示")
End?If
Else
MsgBox("用戶名不存在",?MsgBoxStyle.OkCancel?+?MsgBoxStyle.Exclamation,?"錯(cuò)誤提示")
Exit?Sub
End?If
table.Clear()
h1.Close()
con.Close()
End?Sub
代碼如下:
/// 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
首先要把Label1的屬性Visible設(shè)置為false,然后雙擊button1輸入:
Dim rs As New Data.DataView()
Dim rs As New DataView()
conn.DataFile = "users.mdb"
conn.SelectCommand = "select top 1 * from users where name='" txtUserName.Text "'and pass='" txtPassword.Text "'"
rs = conn.Select(DataSourceSelectArguments.Empty)
if rs.Count Then
Label1.Visible=true
Session("name") = Trim(txtUserName.Text)
Session("pass") = Trim( txtPassword.Text)
MsgBox("登錄成功", MsgBoxStyle.SystemModal)
Response.Redirect("")
Else
MsgBox("對(duì)不起!用戶名和密碼不正確,請(qǐng)重新輸入。", MsgBoxStyle.SystemModal)
End If
Private Sub SendBlogTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendBlogTimer.Tick
Dim textboxUserId As HtmlElement
Dim textboxPassword As HtmlElement
Dim buttonSubmit As HtmlElement
textboxUserId = SendBlogBrowser.Document.All("username")'獲取用戶名輸入框
textboxPassword = SendBlogBrowser.Document.All("password")'獲取密碼輸入框
buttonSubmit = SendBlogBrowser.Document.All("btnLogin")'獲取登陸按鈕
textboxUserId.SetAttribute("value","用戶名")'給用戶名輸入框賦值
textboxPassword.SetAttribute("value","密碼")'給密碼框賦值
buttonSubmit.InvokeMember("click")’執(zhí)行登陸按鈕的單擊
End Sub
其中的SendBlogBrowser為WebBrowser控件
做不到,access數(shù)據(jù)庫(kù)是本地?cái)?shù)據(jù)庫(kù),不支持網(wǎng)絡(luò)訪問(wèn),建議你換成sql server或者mysql之類的數(shù)據(jù)庫(kù)。
注:如果一定要遠(yuǎn)程訪問(wèn)access也不是不行,有兩種辦法,一個(gè)是服務(wù)器如果跟你在同一個(gè)局域網(wǎng),可以把數(shù)據(jù)庫(kù)文件夾共享出來(lái),當(dāng)做共享文件訪問(wèn)。另一種是在那臺(tái)服務(wù)器上裝個(gè)sql server數(shù)據(jù)庫(kù),sql server可以創(chuàng)建出鏈接數(shù)據(jù)庫(kù)鏈接到那個(gè)access.
網(wǎng)頁(yè)標(biāo)題:vbnet登錄,vbnet登錄界面
文章分享:http://chinadenli.net/article21/dsgjgjd.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、網(wǎng)站排名、全網(wǎng)營(yíng)銷推廣、自適應(yīng)網(wǎng)站、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)