📄 login.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace ExamSystem
{
/// <summary>
/// Login 的摘要说明。
/// </summary>
public class Login : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox userName;
private System.Windows.Forms.TextBox password;
private System.Windows.Forms.Label le;
private System.ComponentModel.IContainer components;
private OleDbConnection conn;
public string softType = "CLIENT";
public Login()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
Config.connStr = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Application.StartupPath + @"\ExamItem.EDB";
conn = new OleDbConnection(Config.connStr);
}
/// <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(Login));
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.password = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.userName = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.le = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.password);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.userName);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(328, 48);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
//
// password
//
this.password.Location = new System.Drawing.Point(72, 16);
this.password.Name = "password";
this.password.PasswordChar = '*';
this.password.Size = new System.Drawing.Size(232, 21);
this.password.TabIndex = 3;
this.password.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 24);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(56, 16);
this.label3.TabIndex = 2;
this.label3.Text = "登录口令";
//
// userName
//
this.userName.Location = new System.Drawing.Point(72, 16);
this.userName.Name = "userName";
this.userName.Size = new System.Drawing.Size(232, 21);
this.userName.TabIndex = 1;
this.userName.Text = "119";
this.userName.Visible = false;
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 16);
this.label2.TabIndex = 0;
this.label2.Text = "登录标识";
this.label2.Visible = false;
//
// button1
//
this.button1.Location = new System.Drawing.Point(280, 64);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 23);
this.button1.TabIndex = 2;
this.button1.Text = "退出";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(224, 64);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 23);
this.button2.TabIndex = 3;
this.button2.Text = "登录";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// le
//
this.le.Location = new System.Drawing.Point(16, 104);
this.le.Name = "le";
this.le.Size = new System.Drawing.Size(320, 32);
this.le.TabIndex = 4;
this.le.Text = "运行本系统,显示器分辨率需调到 1024 X 768 ,否则系统界面会显示不完!";
//
// Login
//
this.AcceptButton = this.button2;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(344, 149);
this.Controls.Add(this.le);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Login";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "某单位考试系统";
this.Load += new System.EventHandler(this.Login_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 由此开始运行程序
/// </summary>
[STAThread]
static void Main() {
//Application.Run(new Login());
Application.Run(new MainForm("CLIENT"));
}
/// <summary>
/// 退出程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e) {
Application.Exit();
}
private void button2_Click(object sender, System.EventArgs e) {
string sql = "select * from Admin where userName='"+ this.userName.Text +"' and Password='"+ this.password.Text +"'";
this.conn.Open();
OleDbDataAdapter odp = new OleDbDataAdapter(sql,conn);
DataSet ds = new DataSet();
odp.Fill(ds);
this.conn.Close();
if(ds.Tables[0].Rows.Count >0 ){
MainForm mf = new MainForm("SERVER");
mf.Show();
this.Visible = false;
}else{
MessageBox.Show("标识或密码不正确!");
}
}
private void Login_Load(object sender, System.EventArgs e) {
System.Drawing.Size mSize = SystemInformation.WorkingArea.Size;
int i=mSize.Height;
int j=mSize.Width;
if(i < 680 || j < 950 || i > 800 || j >1100){
MessageBox.Show("运行软件需要 1024 X 768 的分辨率,请调整后再运行本系统,谢谢合作!");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -