?? login.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OracleClient;
namespace Reset
{
/// <summary>
/// Login 的摘要說明。
/// </summary>
public class Login : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
public string usrname,usrpwd;
public string idgrp,idusrgrp,usrgrpname;
private System.Windows.Forms.TextBox txtUsrpwd;
private System.Windows.Forms.TextBox txtUsrname;
private System.Data.OracleClient.OracleConnection oracleConnection1;
/// <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 );
}
public bool Logined
{
get { return _logined; }
}
private bool _logined = false;
#region Windows 窗體設計器生成的代碼
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.txtUsrname = new System.Windows.Forms.TextBox();
this.txtUsrpwd = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.oracleConnection1 = new System.Data.OracleClient.OracleConnection();
this.SuspendLayout();
//
// txtUsrname
//
this.txtUsrname.Location = new System.Drawing.Point(120, 24);
this.txtUsrname.Name = "txtUsrname";
this.txtUsrname.Size = new System.Drawing.Size(200, 21);
this.txtUsrname.TabIndex = 0;
this.txtUsrname.Text = "";
//
// txtUsrpwd
//
this.txtUsrpwd.Location = new System.Drawing.Point(120, 56);
this.txtUsrpwd.Name = "txtUsrpwd";
this.txtUsrpwd.PasswordChar = '*';
this.txtUsrpwd.Size = new System.Drawing.Size(200, 21);
this.txtUsrpwd.TabIndex = 1;
this.txtUsrpwd.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 24);
this.label1.Name = "label1";
this.label1.TabIndex = 2;
this.label1.Text = "用戶名";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 56);
this.label2.Name = "label2";
this.label2.TabIndex = 3;
this.label2.Text = "密碼";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// button1
//
this.button1.Location = new System.Drawing.Point(56, 96);
this.button1.Name = "button1";
this.button1.TabIndex = 4;
this.button1.Text = "確定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(200, 96);
this.button2.Name = "button2";
this.button2.TabIndex = 5;
this.button2.Text = "取消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// oracleConnection1
//
this.oracleConnection1.ConnectionString = "user id=telbizusr;data source=orcl;password=njtu";
//
// Login
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(343, 127);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtUsrpwd);
this.Controls.Add(this.txtUsrname);
this.MaximizeBox = false;
this.Name = "Login";
this.Text = "登錄...";
this.Load += new System.EventHandler(this.Login_Load);
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
txt_check();
//usrgroup_check();
}
private void txt_check()
{
if(txtUsrname.Text==""||txtUsrpwd.Text=="")
{
MessageBox.Show("用戶名或密碼不能為空");
}
else
{
usrname=txtUsrname.Text;
usrpwd=txtUsrpwd.Text;
usrgroup_check();
}
}
private void usrgroup_check()
{
idgrp=null;
idusrgrp=null;
usrgrpname=null;//初始化全局變量
oracleConnection1.Open();
//OracleCommand cmd = new OracleCommand("select count(*) from TB_USER where USERNAME='" + usrname +"'and USERPASSWORD='" + usrpwd + "'", oracleConnection1);
//int count =Convert.ToInt32( cmd.ExecuteScalar());
//if (count > 0)
//{
string select = "select IDOFUSER from TB_USER where USERNAME='"+txtUsrname.Text+"' and USERPASSWORD='"+txtUsrpwd.Text+"'";
OracleCommand cmd = new OracleCommand(select,oracleConnection1);
//OracleDataAdapter da = new OracleDataAdapter(txt,oracleConnection1);
//DataSet myset = new DataSet();
//da.Fill(myset);
OracleDataReader sr = cmd.ExecuteReader();
while(sr.Read())
{
idgrp = sr["IDOFUSER"].ToString();
}
//int i = myset.Tables[0].Rows.Count;
//idgrp = myset.Tables[0].Rows[0]["IDOFUSER"].ToString();
string select1= "select IDOFUSERGROUP from TB_USER_IN_GROUP where IDOFUSER='"+idgrp+"'";
OracleCommand cmd1 = new OracleCommand(select1,oracleConnection1);
OracleDataReader sr1 = cmd1.ExecuteReader();
while(sr1.Read())
{
idusrgrp = sr1["IDOFUSERGROUP"].ToString();
}
string select2= "select USERGROUPNAME from TB_USERGROUP where IDOFUSERGROUP='"+idusrgrp+"'";
OracleCommand cmd2 = new OracleCommand(select2,oracleConnection1);
OracleDataReader sr2 = cmd2.ExecuteReader();
while(sr2.Read())
{
usrgrpname = sr2["USERGROUPNAME"].ToString();
}
//MessageBox.Show("您的身份是"usrgrpname);
if (usrgrpname=="管理員")
{
this.DialogResult = DialogResult.OK;
}
else
{
MessageBox.Show("請您確定您的權限", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
//this.DialogResult = DialogResult. Cancel;
txtUsrname.Text="";txtUsrpwd.Text="";
}
oracleConnection1.Close();
}
private void button2_Click(object sender, System.EventArgs e)
{
_logined = false;
this.Close();
}
private void Login_Load(object sender, System.EventArgs e)
{
}
private void oracleConnection1_InfoMessage(object sender, System.Data.OracleClient.OracleInfoMessageEventArgs e)
{
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -