C# 登录窗口代码

发布时间:2009年05月31日      浏览次数:742 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class login : Form
{
SqlConnection sqlConnection1;
SqlDataAdapter sqlDataAdapter1;
DataSet DS;
DataTable DT;
public login()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string st;
st = comboBox1.Text.ToString();
string strPwd = "";
strPwd = textBox1.Text.ToString();
for (int i = 0; i < DT.Rows.Count; i++)
{
if (st.Trim() == DT.Rows[i]["用户姓名"].ToString().Trim())
{
if (strPwd.Trim() == DT.Rows[i]["密码"].ToString().Trim())
{
this.DialogResult = DialogResult.OK;//成功
//在Program.cs中写
// static void Main()
//{
//Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);
// login fm = new login();
//if (fm.ShowDialog() == DialogResult.OK)
// {
// Application.Run(new FrmMain());
// }
//login form1 = new login ();
//form1.Close();
//FrmMain form2 = new FrmMain ();
//form2.Show();
}
else
{
MessageBox.Show("你的用户名或密码不正确,请重新输入!");
return;
}
}
//comboBox1.Items.Add(DT.Rows[i]["用户姓名"]);
}
}
private void login_Load(object sender, EventArgs e)
{
string strConn = "Data Source=HOMEWELL-25A668;Initial Catalog=building;Integrated Security=True";
string sql = " select * from 权限信息表 ";
sqlConnection1 = new SqlConnection(strConn);
sqlDataAdapter1 = new SqlDataAdapter(sql, sqlConnection1);
DS = new DataSet("TableTmp");
sqlDataAdapter1.Fill(DS, "TableTmp");
DT = DS.Tables["TableTmp"];
for (int i = 0; i < DT.Rows.Count; i++)
{
comboBox1.Items.Add(DT.Rows[i]["用户姓名"]);
comboBox1.SelectedIndex = 0;//显示数据库的第一行数据
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!