loan.cs
来自「我做的题库管理系统。大家看看吧」· CS 代码 · 共 270 行
CS
270 行
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace timuku
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.RadioButton optongxue;
private System.Windows.Forms.RadioButton opguanliyuan;
private System.Windows.Forms.TextBox txtadmin;
private System.Windows.Forms.TextBox txtpass;
private OleDbConnection conn = null;
private OleDbCommand comm=null;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.button1 = new System.Windows.Forms.Button();
this.optongxue = new System.Windows.Forms.RadioButton();
this.txtadmin = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.txtpass = new System.Windows.Forms.TextBox();
this.opguanliyuan = new System.Windows.Forms.RadioButton();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.Color.Transparent;
this.button1.Location = new System.Drawing.Point(24, 104);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 27);
this.button1.TabIndex = 12;
this.button1.Text = "确定 ";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// optongxue
//
this.optongxue.BackColor = System.Drawing.Color.Transparent;
this.optongxue.Location = new System.Drawing.Point(32, 80);
this.optongxue.Name = "optongxue";
this.optongxue.Size = new System.Drawing.Size(64, 24);
this.optongxue.TabIndex = 10;
this.optongxue.Text = "同学";
this.optongxue.CheckedChanged += new System.EventHandler(this.optongxue_CheckedChanged);
//
// txtadmin
//
this.txtadmin.Location = new System.Drawing.Point(80, 24);
this.txtadmin.Name = "txtadmin";
this.txtadmin.Size = new System.Drawing.Size(174, 21);
this.txtadmin.TabIndex = 8;
this.txtadmin.Text = "";
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(0, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 24);
this.label1.TabIndex = 5;
this.label1.Text = "用户名";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.BackColor = System.Drawing.Color.Transparent;
this.label2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.Location = new System.Drawing.Point(0, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 24);
this.label2.TabIndex = 6;
this.label2.Text = "密 码";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// txtpass
//
this.txtpass.Location = new System.Drawing.Point(80, 56);
this.txtpass.Name = "txtpass";
this.txtpass.PasswordChar = '*';
this.txtpass.Size = new System.Drawing.Size(174, 21);
this.txtpass.TabIndex = 7;
this.txtpass.Text = "";
//
// opguanliyuan
//
this.opguanliyuan.BackColor = System.Drawing.Color.Transparent;
this.opguanliyuan.Location = new System.Drawing.Point(160, 80);
this.opguanliyuan.Name = "opguanliyuan";
this.opguanliyuan.Size = new System.Drawing.Size(64, 24);
this.opguanliyuan.TabIndex = 9;
this.opguanliyuan.Text = "管理员";
this.opguanliyuan.CheckedChanged += new System.EventHandler(this.opguanliyuan_CheckedChanged);
//
// button2
//
this.button2.BackColor = System.Drawing.Color.Transparent;
this.button2.Location = new System.Drawing.Point(160, 104);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 27);
this.button2.TabIndex = 11;
this.button2.Text = "退出";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(256, 133);
this.Controls.Add(this.button1);
this.Controls.Add(this.optongxue);
this.Controls.Add(this.txtadmin);
this.Controls.Add(this.label1);
this.Controls.Add(this.label2);
this.Controls.Add(this.txtpass);
this.Controls.Add(this.opguanliyuan);
this.Controls.Add(this.button2);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "登陆";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
if(opguanliyuan.Checked)
{
string pass=txtpass.Text;
this.conn=new OleDbConnection();
conn.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb ";
string sqlstring="Select count(*) as num From passworld where 用户名='admin'and 密码='"+pass+"'";
this.comm=new OleDbCommand(sqlstring,conn);
conn.Open();
OleDbDataReader dr=comm.ExecuteReader();
dr.Read();
txtpass.Text="";
int cc=(int)(dr["num"]);
if (cc==0)
{
MessageBox.Show("用户名或者密码输入错误!请重新输入!");
}
else
{
guanliyuan gly=new guanliyuan();
gly.Show();
}
conn.Close();
}
if(optongxue.Checked)
{
string user=txtadmin.Text; //定义用户名
string pass=txtpass.Text;//定义密码
this.conn=new OleDbConnection(); //连接数据库
conn.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb "; //连接数据库score表
string sqlstring="Select count(*) as num From passworld where 用户名='"+user+"'and 密码='"+pass+"'";//利用SQL里面的语言进行控制用户名和密码
this.comm=new OleDbCommand(sqlstring,conn);//数据库识别器
conn.Open();//打开
OleDbDataReader dr=comm.ExecuteReader();//重载数据源
dr.Read(); //开始读记录
txtpass.Text="";
int ss=(int)(dr["num"]); //控制刚才的记录
if (ss==0)//输入的记录是否和数据库表里的记录相等
{
MessageBox.Show("用户名或者密码输入错误!请重新输入!");
}
else
{//正确跳转到xuesheng窗体界面中
xuesheng r=new xuesheng();
r.Show();
}
conn.Close();//关闭数据库连接
}
}
private void opguanliyuan_CheckedChanged(object sender, System.EventArgs e)
{
txtadmin.Text="admin"; //显示管理员的名称
}
private void optongxue_CheckedChanged(object sender, System.EventArgs e)
{
txtadmin.Text="齐凯琴";
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close(); //关闭窗体
}
private void label3_Click(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?