问题描述
使用System;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Linq;
使用System.Text;
使用System.Windows.Forms ;
使用System.Configuration;
使用System.Data.SqlClient;
使用System.Reflection;
使用System.Data.Sql;
使用System.Runtime.CompilerServices;
使用System.Runtime.InteropServices;
名称空间Cloths_Inventory
{
公共部分类frmLogin:表格
{
public frmLogin()
{
InitializeComponent();
}
private void btnOK_Click(object sender,EventArgs e)
{
if(cmbUsertype.Text ==)
{
MessageBox.Show(请选择用户类型,错误,MessageBoxButtons.OK,MessageBoxIcon.Error);
cmbUsertype.Focus();
return;
}
if(txtUserName.Text ==)
{
MessageBox.Show(请输入用户name,Error,MessageBoxButtons.OK,MessageBoxIcon.Error);
txtUserName.Focus();
return;
}
if(txtPassword.Text ==)
{
MessageBox.Show(请输入密码,错误,MessageBoxButtons。好的,MessageBoxIcon.Error);
txtPassword.Focus();
返回;
}
尝试
{
SqlConnection myConnection = d efault(SqlConnection);
myConnection = new SqlConnection(Data Source = .\\SqlExpress;综合安全=真; AttachDbFilename = | DataDirectory目录| \\Garment.mdf; User Instance = true;);
SqlCommand myCommand = default(SqlCommand);
myCommand = new SqlCommand(SELECT UserName,User_Password,Role FROM Users WHERE Role = @usertype AND UserName = @username AND User_Password = @UserPassword,myConnection);
SqlParameter uType = new SqlParameter(@ usertype ,SqlDbType.NVarChar);
SqlParameter uName = new SqlParameter(@ username,SqlDbType.NVarChar);
SqlParameter uPassword = new SqlParameter(@ UserPassword,SqlDbType.NVarChar);
uType.Value = cmbUsertype.Text;
uName.Value = txtUserName.Text;
uPassword.Value = txtPassword.Text;
myCommand.Parameters.Add(uType) ;
myCommand.Parameters.Add(uName);
m yCommand.Parameters.Add(uPassword);
myCommand.Connection.Open();
SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
if(myReader.Read()== true)
{
int i;
ProgressBar1.Visible = true;
ProgressBar1.Maximum = 5000;
ProgressBar1.Minimum = 0;
ProgressBar1.Value = 4;
ProgressBar1.Step = 1;
for(i = 0;我< = 5000; i ++)
{
ProgressBar1.PerformStep();
}
this.Hide();
frmMainMenu frm = new frmMainMenu();
frm.lblUser.Text = txtUserName.Text;
//frm.UserType.Text = cmbUsertype。文字;
AssemblyCompanyAttribute acb = new AssemblyCompanyAttribute(CompanyName);
frm.lblCompany.Text = acb.Company;
frm.Show() ;
//以下是用户定义的方法禁用调用
//忽略绿色亮点
if(cmbUsertype.SelectedItem ==Manager)frm.disable();
if(cmbUsertype.SelectedItem ==Employee)frm.disable1();
}
else
{
MessageBox.Show(登录失败......再试一次!,登录拒绝,MessageBoxButtons.OK,MessageBoxIcon.Error);
txtUserName.Clear();
txtPassword.Clear();
txtUserName.Focus();
}
if(myConnection.State == ConnectionState.Open)
{
myConnection.Dispose();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,Error,MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void Form_1(object sender,EventArgs e)
{
ProgressBar1.Visible = false;
cmbUsertype.Focus();
}
private void btnCancel_Click(object sender,EventArgs e)
{
关闭();
}
private void Form1_FormClosing(对象发送者,FormClosingEventArgs e)
{
返回;
}
private void linkLabel1_LinkClicked(object sender,LinkLabelLinkClickedEventArgs e)
{
this.Hide();
frmChangePassword frm = new frmChangePassword();
frm.Show();
frm.txtUserName.Text =;
frm.txtNewPassword.Text =;
frm.txtOldPassword.Text =;
f rm.txtConfirmPassword.Text =;
}
private void linkLabel3_LinkClicked(object sender,LinkLabelLinkClickedEventArgs e)
{
this.Hide();
frmRecoveryPassword frm = new frmRecoveryPassword();
frm.txtEmail.Focus();
frm.Show();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
using System.Reflection;
using System.Data.Sql;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Cloths_Inventory
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
private void btnOK_Click(object sender, EventArgs e)
{
if (cmbUsertype.Text == "")
{
MessageBox.Show("Please select user type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
cmbUsertype.Focus();
return;
}
if (txtUserName.Text == "")
{
MessageBox.Show("Please enter user name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUserName.Focus();
return;
}
if (txtPassword.Text == "")
{
MessageBox.Show("Please enter password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtPassword.Focus();
return;
}
try
{
SqlConnection myConnection = default(SqlConnection);
myConnection = new SqlConnection("Data Source=.\\SqlExpress; Integrated Security=True; AttachDbFilename=|DataDirectory|\\Garment.mdf; User Instance=true;");
SqlCommand myCommand = default(SqlCommand);
myCommand = new SqlCommand("SELECT UserName,User_Password,Role FROM Users WHERE Role = @usertype AND UserName = @username AND User_Password = @UserPassword", myConnection);
SqlParameter uType = new SqlParameter("@usertype", SqlDbType.NVarChar);
SqlParameter uName = new SqlParameter("@username", SqlDbType.NVarChar);
SqlParameter uPassword = new SqlParameter("@UserPassword", SqlDbType.NVarChar);
uType.Value = cmbUsertype.Text;
uName.Value = txtUserName.Text;
uPassword.Value = txtPassword.Text;
myCommand.Parameters.Add(uType);
myCommand.Parameters.Add(uName);
myCommand.Parameters.Add(uPassword);
myCommand.Connection.Open();
SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
if (myReader.Read() == true)
{
int i;
ProgressBar1.Visible = true;
ProgressBar1.Maximum = 5000;
ProgressBar1.Minimum = 0;
ProgressBar1.Value = 4;
ProgressBar1.Step = 1;
for (i = 0; i <= 5000; i++)
{
ProgressBar1.PerformStep();
}
this.Hide();
frmMainMenu frm = new frmMainMenu();
frm.lblUser.Text = txtUserName.Text;
//frm.UserType.Text = cmbUsertype.Text;
AssemblyCompanyAttribute acb = new AssemblyCompanyAttribute(CompanyName);
frm.lblCompany.Text = acb.Company;
frm.Show();
//The following is user defined call for method disable
//ignore the green highlight
if (cmbUsertype.SelectedItem == "Manager") frm.disable();
if (cmbUsertype.SelectedItem == "Employee") frm.disable1();
}
else
{
MessageBox.Show("Login is Failed...Try again !", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUserName.Clear();
txtPassword.Clear();
txtUserName.Focus();
}
if (myConnection.State == ConnectionState.Open)
{
myConnection.Dispose();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void Form_1(object sender, EventArgs e)
{
ProgressBar1.Visible = false;
cmbUsertype.Focus();
}
private void btnCancel_Click(object sender, EventArgs e)
{
Close();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
return;
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
this.Hide();
frmChangePassword frm = new frmChangePassword();
frm.Show();
frm.txtUserName.Text = "";
frm.txtNewPassword.Text = "";
frm.txtOldPassword.Text = "";
frm.txtConfirmPassword.Text = "";
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
this.Hide();
frmRecoveryPassword frm = new frmRecoveryPassword();
frm.txtEmail.Focus();
frm.Show();
}
}
}
推荐答案
这篇关于如果三个登录注册失败,如何退出应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!