using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AppExample
{
public partial class FormLogin : Form
{
private readonly object txtUserPwd;
public FormLogin()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
prive void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if(txtUserName.Text.Trim()=="")
{
MessageBox.Show("用戶名不能為空!", "錯誤");
txtUserName.Focus();
return;
}
else if(txtUserPwd.Text.Trim()=="")
{
MessageBox.Show("密碼不能為空!", "錯誤");
txtUserPwd.Focus();
return;
}
string psw = CPublic.GetMd5Str(txtUserPwd.Text.Trim());//加密
string strSql = "SELECT username,userpwd,userpuryiew FROW tb_user"
+ "WHERE userid=" + txtUserName.Text.Trim() + ";
this.Text = "正在驗證..."; //登錄視窗的標題
this.Cursor = Cursors.WaitCursor; //游標形狀
DataTable dt = CDataBase.GetDataFromDB(strSql);
if(dt==null)
{
MessageBox.Show("用戶名錯誤,請重新輸入!", "錯誤提示");
this.Cursor = Cursors.Arrow; //游標形狀
this.Text = "登錄";
txtUserName.Text = "";
txtUserPwd.Text = "";
txtUserName.Focus();
}
else
{
if (dt.Rows[0][1].ToString().Trim()==psw.Trim())
{
CPublic.userInfo[0] = dt.Rows[0][1].ToString().Trim();//用戶姓名
CPublic.userInfo[1] = dt.Rows[0][2].ToString().Trim();//權限
CPublic.userInfo[2] = txtUserName.Text.Trim();//用戶ID
this.Cursor = Cursor.Arrow;
this.DialogResult = DialogResult.OK; //回傳一個登錄成功的對話框狀態
this.Close(); //關閉登錄視窗
}
else
{
MessageBox.Show("密碼錯誤,請重新輸入!", "錯誤");
this.Cursor = Cursor.Arrow;
this.Text = "登錄";
txtUserPwd.Text = "";
txtUserPwd.Focus();
}
}
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit(); //退出應用程式,釋放資源
}
private void label2_Click(object sender, EventArgs e)
{
}
}
}
uj5u.com熱心網友回復:
錯誤是找不到前臺定義的控制元件名稱,你清理下解決方案在重新生成下。看在后臺能不能取到前臺定義的控制元件名稱uj5u.com熱心網友回復:
private readonly object txtUserPwd;
uj5u.com熱心網友回復:
40 行錯誤:txtUserPwd 是個 object 型別,它沒有 Text 這個屬性,應改為 TextBox 型別69 行錯誤:Cursor 應改為 Cursors。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/102062.html
標籤:C#
上一篇:CefSharp不彈窗的問題
下一篇:wcf通訊報錯
