- 类
using System; using System.Data; using System.Data.OleDb; namespace ClassLibrary1 { /// /// Class1 的摘要说明。 /// public class Class1 { public static OleDbConnection conn; public Class1() { // // TODO: 在此处添加构造函数逻辑 // Connection(); } public void Connection() { try { string a=Environment.CurrentDirectory+"//OESystem.mdb";//连接库 conn=new OleDbConnection("Data Source="+a+";Provider=Microsoft.Jet.OLEDB.4.0");//实例化conn conn.Open(); } catch(Exception aa) { Console.WriteLine(aa.ToString()); } } } }
- 登陆窗体
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.OleDb; using ClassLibrary1; namespace 联机考试系统 { /// /// Form2 的摘要说明。 /// public class Form2 : System.Windows.Forms.Form { private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Data.OleDb.OleDbDataAdapter da=new OleDbDataAdapter(); private System.Data.DataSet ds=new DataSet(); private System.Windows.Forms.Label label3; private System.Windows.Forms.LinkLabel linkLabel1; /// /// 必需的设计器变量。 /// private System.ComponentModel.Container components = null; public int isdown; public int xx; public int yy; public Form2() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// /// 清理所有正在使用的资源。 /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form2)); this.panel1 = new System.Windows.Forms.Panel(); this.button2 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox1 = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.linkLabel1 = new System.Windows.Forms.LinkLabel(); this.panel1.SuspendLayout(); this.SuspendLayout(); // // panel1 // this.panel1.BackColor = System.Drawing.Color.Transparent; this.panel1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel1.BackgroundImage"))); this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panel1.Controls.Add(this.linkLabel1); this.panel1.Controls.Add(this.label3); this.panel1.Controls.Add(this.button2); this.panel1.Controls.Add(this.button1); this.panel1.Controls.Add(this.textBox2); this.panel1.Controls.Add(this.textBox1); this.panel1.Controls.Add(this.label2); this.panel1.Controls.Add(this.label1); this.panel1.ForeColor = System.Drawing.SystemColors.ControlLightLight; this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(448, 328); this.panel1.TabIndex = 0; this.panel1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseUp); this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove); this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown); // // button2 // this.button2.BackColor = System.Drawing.Color.Transparent; this.button2.Font = new System.Drawing.Font("楷体_GB2312", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.button2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText; this.button2.Location = new System.Drawing.Point(312, 240); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(80, 32); this.button2.TabIndex = 5; this.button2.Text = "退出"; this.button2.Click += new System.EventHandler(this.button2_Click); // // button1 // this.button1.BackColor = System.Drawing.Color.Transparent; this.button1.Font = new System.Drawing.Font("楷体_GB2312", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.button1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText; this.button1.Location = new System.Drawing.Point(120, 240); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(72, 32); this.button1.TabIndex = 4; this.button1.Text = "登陆"; this.button1.Click += new System.EventHandler(this.button1_Click); // // textBox2 // this.textBox2.Location = new System.Drawing.Point(232, 144); this.textBox2.Name = "textBox2"; this.textBox2.PasswordChar = '*'; this.textBox2.Size = new System.Drawing.Size(184, 21); this.textBox2.TabIndex = 3; this.textBox2.Text = ""; // // textBox1 // this.textBox1.Location = new System.Drawing.Point(232, 48); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(184, 21); this.textBox1.TabIndex = 2; this.textBox1.Text = ""; // // label2 // this.label2.BackColor = System.Drawing.Color.Transparent; this.label2.Font = new System.Drawing.Font("楷体_GB2312", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText; this.label2.Location = new System.Drawing.Point(160, 144); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(64, 32); this.label2.TabIndex = 1; this.label2.Text = "密码:"; // // label1 // this.label1.BackColor = System.Drawing.Color.Transparent; this.label1.Font = new System.Drawing.Font("楷体_GB2312", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText; this.label1.Location = new System.Drawing.Point(152, 48); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(80, 32); this.label1.TabIndex = 0; this.label1.Text = "用户名:"; // // label3 // this.label3.BackColor = System.Drawing.Color.Transparent; this.label3.Location = new System.Drawing.Point(0, 0); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(448, 24); this.label3.TabIndex = 6; this.label3.MouseUp += new System.Windows.Forms.MouseEventHandler(this.label3_MouseUp); this.label3.MouseMove += new System.Windows.Forms.MouseEventHandler(this.label3_MouseMove); this.label3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.label3_MouseDown); // // linkLabel1 // this.linkLabel1.LinkColor = System.Drawing.Color.White; this.linkLabel1.Location = new System.Drawing.Point(424, 8); this.linkLabel1.Name = "linkLabel1"; this.linkLabel1.Size = new System.Drawing.Size(8, 16); this.linkLabel1.TabIndex = 7; this.linkLabel1.TabStop = true; this.linkLabel1.Text = "X"; this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); // // Form2 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(448, 328); this.Controls.Add(this.panel1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "Form2"; this.Text = "Form2"; this.panel1.ResumeLayout(false); this.ResumeLayout(false); } #endregion private void button1_Click(object sender, System.EventArgs e) { try { da.SelectCommand=new OleDbCommand(); Class1 daAccess=new Class1(); da.SelectCommand.Connection=Class1.conn; da.SelectCommand.CommandText="select * from tbl_User where UsrId='"+this.textBox1.Text.Trim()+"'"; da.SelectCommand.ExecuteNonQuery(); da.Fill(ds,"usr"); } catch(Exception aa) { MessageBox.Show(aa.ToString()); } try { if(ds.Tables["usr"].Rows.Count==0) { MessageBox.Show("用户名错误!"); } else if(ds.Tables["usr"].Rows[0][1].ToString()!=this.textBox2.Text.Trim()) { MessageBox.Show("密码错误!"); } else { Form3 aa=new Form3(); aa.Show(); this.Hide(); //MessageBox.Show("登陆成功!"); } ds.Clear(); Class1.conn.Close(); } catch(Exception aa) { Console.WriteLine(aa.ToString()); } } private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { } private void button2_Click(object sender, System.EventArgs e) { this.Close(); } private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { this.Close(); } private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { } private void panel1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { } private void panel1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { } private void label3_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { this.isdown = 1; this.xx = e.X; this.yy = e.Y; } private void label3_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { this.isdown = 0; } private void label3_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if(this.isdown == 1) // 判断isdown是否为1 为1的话就说明鼠标按下了 { this.Left = this.Left + e.X - this.xx; this.Top = this.Top + e.Y -this.yy; } } } }
C#登陆
最新推荐文章于 2022-08-10 10:39:51 发布