ae微信小视频制作软件:求用户登录C#源代码

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 09:20:27
windows界面小的cs源代码,输入用户名,密码进行登录

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data .OleDb ;

namespace LOginForm
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Login : System.Windows.Forms.Form
{
public static string username;//定义全局变量传递用户名
public static string bz;//定义全局变量传递用户权限
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox psd;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox name;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Data.OleDb.OleDbConnection oleDbConnection1;
private System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
private System.Data.DataSet dataSet1;
private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
private System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
private System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
private System.Data.OleDb.OleDbConnection oleDbConnection2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Login()
{

//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Login));
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.psd = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.name = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbConnection2 = new System.Data.OleDb.OleDbConnection();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.dataSet1 = new System.Data.DataSet();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
this.SuspendLayout();
//
// button2
//
this.button2.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject

("button2.BackgroundImage")));
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button2.Location = new System.Drawing.Point(152, 144);
this.button2.Name = "button2";
this.button2.TabIndex = 20;
this.button2.Text = "取消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject

("button1.BackgroundImage")));
this.button1.Cursor = System.Windows.Forms.Cursors.Hand;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button1.Location = new System.Drawing.Point(48, 144);
this.button1.Name = "button1";
this.button1.TabIndex = 19;
this.button1.Text = "登录";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// psd
//
this.psd.Location = new System.Drawing.Point(136, 96);
this.psd.Name = "psd";
this.psd.PasswordChar = '*';
this.psd.TabIndex = 18;
this.psd.Text = "";
//
// label3
//
this.label3.BackColor = System.Drawing.Color.Transparent;
this.label3.Font = new System.Drawing.Font("宋体", 11F);
this.label3.Location = new System.Drawing.Point(32, 96);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(72, 16);
this.label3.TabIndex = 17;
this.label3.Text = "口令:";
//
// name
//
this.name.Location = new System.Drawing.Point(136, 56);
this.name.Name = "name";
this.name.TabIndex = 16;
this.name.Text = "";
//
// label2
//
this.label2.BackColor = System.Drawing.Color.Transparent;
this.label2.Font = new System.Drawing.Font("宋体", 11F);
this.label2.Location = new System.Drawing.Point(32, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 16);
this.label2.TabIndex = 15;
this.label2.Text = "管理员:";
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Cursor = System.Windows.Forms.Cursors.Arrow;
this.label1.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular,

System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.Color.Black;
this.label1.Location = new System.Drawing.Point(72, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(136, 24);
this.label1.TabIndex = 14;
this.label1.Text = "系统登录页面";
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User

ID=Admin;Data Source=.\dbo.mdb;Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet

OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet

OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create

System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without

Replica Repair=False;Jet OLEDB:SFP=False";
//
// oleDbDataAdapter1
//
this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;
this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;
this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {

new System.Data.Common.DataTableMapping

("Table", "admin", new System.Data.Common.DataColumnMapping[] {

new System.Data.Common.DataColumnMapping("bz", "bz"),

new System.Data.Common.DataColumnMapping("id", "id"),

new System.Data.Common.DataColumnMapping("name", "name"),

new System.Data.Common.DataColumnMapping("psd", "psd")})});
this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;
//
// oleDbDeleteCommand1
//
this.oleDbDeleteCommand1.CommandText = "DELETE FROM admin WHERE (id = ?) AND (bz = ? OR ? IS NULL AND

bz IS NULL) AND (na" +
"me = ? OR ? IS NULL AND name IS NULL) AND (psd = ? OR ? IS NULL AND psd IS NULL)" +
"";
this.oleDbDeleteCommand1.Connection = this.oleDbConnection2;
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_id",

System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)),

"id", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_bz",

System.Data.OleDb.OleDbType.VarWChar, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)),

"bz", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_bz1",

System.Data.OleDb.OleDbType.VarWChar, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)),

"bz", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_name",

System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)

(0)), "name", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_name1",

System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)

(0)), "name", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_psd",

System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)

(0)), "psd", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_psd1",

System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)

(0)), "psd", System.Data.DataRowVersion.Original, null));
//
// oleDbConnection2
//
this.oleDbConnection2.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User

ID=Admin;Data Source=dbo.mdb;Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry

Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial

Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System

Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without

Replica Repair=False;Jet OLEDB:SFP=False";
//
// oleDbInsertCommand1
//
this.oleDbInsertCommand1.CommandText = "INSERT INTO admin(bz, name, psd) VALUES (?, ?, ?)";
this.oleDbInsertCommand1.Connection = this.oleDbConnection2;
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("bz",

System.Data.OleDb.OleDbType.VarWChar, 2, "bz"));
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("name",

System.Data.OleDb.OleDbType.VarWChar, 50, "name"));
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("psd",

System.Data.OleDb.OleDbType.VarWChar, 50, "psd"));
//
// oleDbSelectCommand1
//
this.oleDbSelectCommand1.CommandText = "SELECT bz, id, name, psd FROM admin";
this.oleDbSelectCommand1.Connection = this.oleDbConnection2;
//
// oleDbUpdateCommand1
//
this.oleDbUpdateCommand1.CommandText = "UPDATE admin SET bz = ?, name = ?, psd = ? WHERE (id = ?) AND

(bz = ? OR ? IS NUL" +
"L AND bz IS NULL) AND (name = ? OR ? IS NULL AND name IS NULL) AND (psd = ? OR ?" +
" IS NULL AND psd IS NULL)";
this.oleDbUpdateCommand1.Connection = this.oleDbConnection2;
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("bz",

System.Data.OleDb.OleDbType.VarWChar, 2, "bz"));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("name",

System.Data.OleDb.OleDbType.VarWChar, 50, "name"));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("psd",

System.Data.OleDb.OleDbType.VarWChar, 50, "psd"));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_id",

System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)),

"id", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_bz",

System.Data.OleDb.OleDbType.VarWChar, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)),

"bz", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_bz1",

System.Data.OleDb.OleDbType.VarWChar, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)),

"bz", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_name",

System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)

(0)), "name", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_name1",

System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)

(0)), "name", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_psd",

System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)

(0)), "psd", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_psd1",

System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)

(0)), "psd", System.Data.DataRowVersion.Original, null));
//
// dataSet1
//
this.dataSet1.DataSetName = "NewDataSet";
this.dataSet1.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// Login
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(272, 189);
this.Controls.AddRange(new System.Windows.Forms.Control[] {

this.button2,

this.button1,

this.psd,

this.label3,

this.name,

this.label2,

this.label1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "Login";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "登录";
this.Resize += new System.EventHandler(this.Login_Resize);
this.Load += new System.EventHandler(this.Form1_Load);
this.LocationChanged += new System.EventHandler(this.Login_LocationChanged);
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Login());
}

private void Form1_Load(object sender, System.EventArgs e)
{

}

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

private void button1_Click(object sender, System.EventArgs e)
{
try
{
if(name.Text !="" & psd.Text !="")
{
//定义SQL语句
string select="select * from admin where name='"+name.Text +"' and psd='"+psd.Text

+"'";
//初始化OleDbCommand
OleDbCommand comm=new OleDbCommand (select,oleDbConnection1);
comm.Connection .Open ();
//初始化OleDbDataAdapter
OleDbDataReader reader=comm.ExecuteReader ();
if(reader.Read ())
{
aForm af=new aForm ();
af.Show ();
this.Visible =false;
Login.username =this.name .Text ;
}
else
{
MessageBox.Show ("非法管理员","警告",MessageBoxButtons.OK

,MessageBoxIcon.Hand );
Application.Exit ();
}
}
else
{
MessageBox.Show ("请把信息填写完整!","提示",MessageBoxButtons.OK

,MessageBoxIcon.Warning );
}
}
catch(Exception error)
{
MessageBox.Show ("登录错误:"+error.Message ,"提示",MessageBoxButtons.OK

,MessageBoxIcon.Warning );
if(this.oleDbConnection1 .State ==ConnectionState.Open )
{
this.oleDbConnection1 .Close();
}
}
}

private void Login_Resize(object sender, System.EventArgs e)
{
this.Width =280;
this.Height =216;
}

private void Login_LocationChanged(object sender, System.EventArgs e)
{
}
}
}