资源简介
简单的登陆界面,用到了简单的Access数据库的链接;可以做学习用.大一时候课程设计也找过类似的程序,但是没有满意的,所以按照我的感觉为刚刚开始学习C#的同学做的.
这个小程序除了对登录的用户名和密码进行匹配外,还对登录的身份类型进行了判定;比如,如果是管理员身份则进入管理员界面;如果是普通用户则进入普通用户界面.
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace RG_Soft
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender EventArgs e)
{
}
private void button1_Click_1(object sender EventArgs e)
{
string reportPath = Application.StartupPath.Substring(0 Application.StartupPath.Substring(0 Application.StartupPath
.LastIndexOf(“\\“)).LastIndexOf(“\\“));
reportPath += @“\db_RGS.mdb“;
string ConStr = “Provider=Microsoft.jet.OLEDB.4.0;Data source=“ + reportPath;
//创建Connection 对象
OleDbConnection con = new OleDbConnection(ConStr);
con.Open();
if (con.State==ConnectionState.Open)
{
//MessageBox.Show(“数据库链接成功!“ “链接“);
//判断用户名或密码是否为空
if (textBox1.Text == ““ | textBox2.Text == ““)
{
MessageBox.Show(“用户名或密码不能为空“ “警告“);
}
else
{ //进行身份认证
string tx = “select count(*) FROM [user] where user_id=‘“ + this.textBox1.Text + “‘ and user_pwd=‘“ + this.textBox2.Text + “‘“;
OleDbCommand cmd = new OleDbCommand(txcon);
Int32 id_e = (Int32)cmd.ExecuteScalar();
if (id_e > 0)
{ //判断用户权限
//MessageBox.Show(“登录成功““成功“);
string sql = “select user_type from [user] where user_id=‘“ + this.textBox1.Text + “‘and user_pwd=‘“ + this.textBox2.Text + “‘“;
OleDbDataAdapter da = new OleDbDataAdapter(sqlcon);
DataSet ds = new DataSet();
da.Fill(ds);
this.textBox3.Text = ds.Tables[0].Rows[0][0].ToString();
if ( this.textBox3.Text== “0“)
{ MessageBox.Show(“普通身份登录“ “登录中“); }
else if (this.textBox3.Text == “1“)
{ MessageBox.Show(“管理员身份登录“ “登录中“); }
else
{MessageBox.Show(“数据库内部错误“ “登录中“);}
con.Close();
cmd.Dispose();
}
else
{
MessageBox.Show(“用户名或密码不正确!“ “请重新登录“);
}
}
}
else
{
MessageBox.Show(“数据库链接失败!“ “链接“);
}
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 155648 2009-05-10 14:13 RG Soft\RG Soft\RG Soft\bin\Debug\db_RGS.mdb
文件 114688 2009-05-10 14:58 RG Soft\RG Soft\RG Soft\bin\Debug\RG Soft.exe
文件 24064 2009-05-10 14:58 RG Soft\RG Soft\RG Soft\bin\Debug\RG Soft.pdb
文件 5632 2005-11-11 22:25 RG Soft\RG Soft\RG Soft\bin\Debug\RG Soft.vshost.exe
文件 155648 2009-05-10 15:00 RG Soft\RG Soft\RG Soft\db_RGS.mdb
文件 3089 2009-05-10 15:01 RG Soft\RG Soft\RG Soft\Form1.cs
文件 6749 2009-05-10 14:58 RG Soft\RG Soft\RG Soft\Form1.Designer.cs
文件 144159 2009-05-10 14:58 RG Soft\RG Soft\RG Soft\Form1.resx
文件 842 2009-05-10 14:58 RG Soft\RG Soft\RG Soft\obj\Debug\RG Soft.csproj.GenerateResource.Cache
文件 114688 2009-05-10 14:58 RG Soft\RG Soft\RG Soft\obj\Debug\RG Soft.exe
文件 24064 2009-05-10 14:58 RG Soft\RG Soft\RG Soft\obj\Debug\RG Soft.pdb
文件 92517 2009-05-10 14:58 RG Soft\RG Soft\RG Soft\obj\Debug\RG_Soft.Form1.resources
文件 180 2009-05-09 17:12 RG Soft\RG Soft\RG Soft\obj\Debug\RG_Soft.Properties.Resources.resources
文件 290 2009-05-10 14:58 RG Soft\RG Soft\RG Soft\obj\RG Soft.csproj.FileList.txt
文件 466 2009-05-09 16:47 RG Soft\RG Soft\RG Soft\Program.cs
文件 1172 2009-05-09 16:47 RG Soft\RG Soft\RG Soft\Properties\AssemblyInfo.cs
文件 2868 2009-05-09 16:47 RG Soft\RG Soft\RG Soft\Properties\Resources.Designer.cs
文件 5612 2009-05-09 16:47 RG Soft\RG Soft\RG Soft\Properties\Resources.resx
文件 1090 2009-05-09 16:47 RG Soft\RG Soft\RG Soft\Properties\Settings.Designer.cs
文件 249 2009-05-09 16:47 RG Soft\RG Soft\RG Soft\Properties\Settings.settings
文件 3365 2009-05-10 12:53 RG Soft\RG Soft\RG Soft\RG Soft.csproj
文件 910 2009-05-09 16:47 RG Soft\RG Soft\RG Soft.sln
..A..H. 13312 2009-05-10 15:01 RG Soft\RG Soft\RG Soft.suo
目录 0 2009-05-09 17:05 RG Soft\RG Soft\RG Soft\obj\Debug\Refactor
目录 0 2009-05-09 16:47 RG Soft\RG Soft\RG Soft\obj\Debug\TempPE
目录 0 2009-05-10 12:53 RG Soft\RG Soft\RG Soft\bin\Debug
目录 0 2009-05-10 14:58 RG Soft\RG Soft\RG Soft\obj\Debug
目录 0 2009-05-09 16:47 RG Soft\RG Soft\RG Soft\bin
目录 0 2009-05-09 17:12 RG Soft\RG Soft\RG Soft\obj
目录 0 2009-05-09 16:47 RG Soft\RG Soft\RG Soft\Properties
............此处省略6个文件信息
- 上一篇:俄罗斯方块 c# 俄罗斯方块
- 下一篇:c#设计一个小型的编译器
评论
共有 条评论