C# 一个登陆代码

发布时间:2009年06月04日      浏览次数:688 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace login
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
private void FrmMain_Load(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "当前时间:" + System.DateTime.Now.ToString("D") + " 当前用户:" + FrmLogin.userName + " 用户类型:" + FrmLogin.degree;
}
}
}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.OleDb;
namespace login
{
public partial class FrmLogin : Form
{
public static string userName;
public static string degree;
public static FrmMain frmMain;
public FrmLogin()
{
InitializeComponent();
}
private void FrmLogin_Load(object sender, EventArgs e)
{
this.Opacity = 0;
}
private void button1_Click(object sender, EventArgs e)
{
//if (textBox1.Text.Trim() == "")
//{
// MessageBox.Show("用户名不能为空!");
// textBox1.Focus();
//}
// else
if (userPass.Text.Trim() == "")
{
MessageBox.Show("请输入密码!");
userPass.Focus();
}
else
{
string ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Info.mdb";
OleDbConnection Conn = new OleDbConnection(ConnString);
Conn.Open();
string sql = "select * from manager where username='" + comboBox1.Text.Trim() + "' and userpass='" + userPass.Text.Trim() + "' and iflock=0";
OleDbCommand cmd = new OleDbCommand(sql, Conn);
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
userName = comboBox1.Text.Trim();
degree = dr["degree"].ToString();
this.Hide();
frmMain = new FrmMain();
frmMain.Show();
}
dr.Close();
Conn.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (this.Opacity < 1)
{
this.Opacity += 0.05;
}
else
{
timer1.Enabled = false;
}
}
}
}

用户登陆窗体的代码::
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.OleDb;
namespace login
{
public partial class FrmLogin : Form
{

public static string userName;
public static string degree;
public static FrmMain frmMain;

public FrmLogin()
{
InitializeComponent();
}

private void FrmLogin_Load(object sender, EventArgs e)
{
this.Opacity = 0;
}

private void button1_Click(object sender, EventArgs e)
{
//if (textBox1.Text.Trim() == "")
//{
// MessageBox.Show("用户名不能为空!");
// textBox1.Focus();
//}
// else
if (userPass.Text.Trim() == "")
{
MessageBox.Show("请输入密码!");
userPass.Focus();
}
else
{
string ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Info.mdb";
OleDbConnection Conn = new OleDbConnection(ConnString);
Conn.Open();
string sql = "select * from manager where username='" + comboBox1.Text.Trim() + "' and userpass='" + userPass.Text.Trim() + "' and iflock=0";
OleDbCommand cmd = new OleDbCommand(sql, Conn);
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
userName = comboBox1.Text.Trim();
degree = dr["degree"].ToString();
this.Hide();
frmMain = new FrmMain();
frmMain.Show();
}
dr.Close();
Conn.Close();

}
}

private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}

private void timer1_Tick(object sender, EventArgs e)
{
if (this.Opacity < 1)
{
this.Opacity += 0.05;
}
else
{
timer1.Enabled = false;
}
}
}
}
主窗体代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace login
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}

private void FrmMain_Load(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "当前时间:" + System.DateTime.Now.ToString("D") + " 当前用户:" + FrmLogin.userName + " 用户类型:" + FrmLogin.degree;
}
}
}
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!