Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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();
}

}

}
Posted

1 solution

Simple declare a variable and increase its value for every request from user.and check if its value is more than 3 then do the business logic as your requirement.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900