frmenter.cs
来自「小区物业管理:管理小区的费用、小区工作人员的编排和工资管理、小区的运作、对住户资」· CS 代码 · 共 281 行
CS
281 行
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data .SqlClient ;
using System.Timers ;
namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class frmEnter : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnEnter;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Timer tmrTimer;
private System.Windows.Forms.Label lbltime1;
private System.ComponentModel.IContainer components;
private SqlCommand objSqlCommand;
private SqlCommand objSqlCommand1;
private SqlConnection objConn;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.TextBox txtName;
public frmEnter()
{
//
// 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()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmEnter));
this.txtName = new System.Windows.Forms.TextBox();
this.txtPassword = new System.Windows.Forms.TextBox();
this.btnEnter = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.tmrTimer = new System.Windows.Forms.Timer(this.components);
this.lbltime1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// txtPassword
//
this.txtPassword.AcceptsReturn = true;
this.txtPassword.Location = new System.Drawing.Point(152, 160);
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(152, 21);
this.txtPassword.TabIndex = 10;
this.txtPassword.Text = "";
//
// btnEnter
//
this.btnEnter.BackColor = System.Drawing.Color.AliceBlue;
this.btnEnter.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnEnter.BackgroundImage")));
this.btnEnter.Location = new System.Drawing.Point(104, 208);
this.btnEnter.Name = "btnEnter";
this.btnEnter.Size = new System.Drawing.Size(104, 40);
this.btnEnter.TabIndex = 7;
this.btnEnter.Click += new System.EventHandler(this.btnEnter_Click);
//
// btnExit
//
this.btnExit.BackColor = System.Drawing.Color.AliceBlue;
this.btnExit.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnExit.BackgroundImage")));
this.btnExit.Location = new System.Drawing.Point(232, 208);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(104, 40);
this.btnExit.TabIndex = 8;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// tmrTimer
//
this.tmrTimer.Interval = 1000;
this.tmrTimer.Tick += new System.EventHandler(this.tmrTimer_Tick);
//
// lbltime1
//
this.lbltime1.AutoSize = true;
this.lbltime1.ForeColor = System.Drawing.SystemColors.ControlText;
this.lbltime1.Location = new System.Drawing.Point(0, 232);
this.lbltime1.Name = "lbltime1";
this.lbltime1.Size = new System.Drawing.Size(0, 17);
this.lbltime1.TabIndex = 1;
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(152, 88);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(152, 21);
this.txtName.TabIndex = 4;
this.txtName.Text = "";
//
// frmEnter
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(384, 288);
this.Controls.Add(this.txtName);
this.Controls.Add(this.lbltime1);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnEnter);
this.Controls.Add(this.txtPassword);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false;
this.Name = "frmEnter";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "登录";
this.Closing += new System.ComponentModel.CancelEventHandler(this.frmEnter_Closing);
this.Load += new System.EventHandler(this.frmEnter_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close ();
}
private void btnRem_Click(object sender, System.EventArgs e)
{
this.txtName.Clear();
this.txtPassword.Clear();
this.txtName.Focus ();
}
private void btnEnter_Click(object sender, System.EventArgs e)
{
try
{
objConn=new SqlConnection ("database=atorregulate;uid=sa;password=;SERVER=(local)");
objConn.Open ();
string sql="select count(*) from adminuser where Auid like '"+this.txtName .Text+"'and Apassword like '"+this.txtPassword .Text+"'";
objSqlCommand=new SqlCommand (sql,objConn);
int flag=(int)objSqlCommand.ExecuteScalar();
objConn.Close ();
if(flag>0)
{
string eclass=this.txtName.Text;
objConn.Open ();
string cal="select Auid from adminuser where Aclass = 2";
objSqlCommand1=new SqlCommand (cal,objConn);
this.objSqlCommand.ExecuteNonQuery();
System.Data.SqlClient.SqlDataReader objSqlDataReader;
objSqlDataReader=objSqlCommand1.ExecuteReader ();
while(objSqlDataReader.Read ())
{
eclass=objSqlDataReader["Auid"].ToString();
}
objSqlDataReader.Close();
objConn.Close();
if(this.txtName.Text==eclass)
{
MessageBox.Show("管理员您好!欢迎光临!","欢迎使用");
frmpasswordset objfrmpasswordset=new frmpasswordset(this.txtName.Text);
frmsuper frmAC=new frmsuper (this.txtName.Text);
this.Hide();
frmAC.ShowDialog();
}
else
{
MessageBox.Show("您好! "+this.txtName.Text+"! 欢迎光临!","欢迎使用");
frmsuper objfrmsuper=new frmsuper (this.txtName.Text);
this.Hide();
objfrmsuper.ShowDialog ();
}
}
else
{
MessageBox.Show("用户名或密码不正确!","服务器驳回");
this.txtName .Text="";
this.txtPassword .Text="";
txtName.Focus();
}
}
catch(SqlException ee)
{
MessageBox.Show(ee.Message);
}
}
private void frmEnter_Load(object sender, System.EventArgs e)
{
this.lbltime1.BackColor = System.Drawing.Color.Transparent;
this.lbltime1.Font = new System.Drawing.Font("隶书", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.lbltime1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.lbltime1.Location = new System.Drawing.Point(8,256);
this.lbltime1.Name = "label1";
this.lbltime1.TabIndex = 11;
//连接数据库
//objConn=new SqlConnection ("database=atorregulate;user id=sa;password=;SERVER=(LOCAL)");
//时间
//txtTime.Text+=System.DateTime .Now .ToString("yyyy-MM-dd")+" "+System.DateTime .Now .TimeOfDay .ToString ().Substring (0,8);;
tmrTimer.Start ();
//用户
//objConn.Open ();
//cboName.Items .Clear ();
//string str ="select Auid from adminuser";
//this.objSqlCommand = new SqlCommand(str,this.objConn);
//this.objSqlDataReader = this.objSqlCommand.ExecuteReader();
//while(this.objSqlDataReader.Read())
//{
// this.cboName.Items.Add(this.objSqlDataReader.GetValue(0));
//}
//this.objSqlDataReader.Close();
}
private void tmrTimer_Tick(object sender, System.EventArgs e)
{
string a="当前时间:";
this.lbltime1 .Text =a+System.DateTime .Now .TimeOfDay .ToString ().Substring (0,8);
}
private void frmEnter_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
this.txtName.Focus();
Application.Exit ();
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?