Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- using MDLL;
- namespace Company
- {
- public partial class FrmCompanyLogin : Form
- {
- public string currentBatch;
- public string checker;
- //Connection c = new Connection();
- public FrmCompanyLogin()
- {
- InitializeComponent();
- }
- private void btnConfirm_Click(object sender, EventArgs e)
- {
- if (txtUsername.TextLength == 0 || txtPassword.TextLength == 0)
- {
- MessageBox.Show("Please Fill All The Fields", "Job Fair", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- if (restriction())
- {
- SqlCon.Open();
- SqlCommand cmd = new SqlCommand("Select * from Company where Username = @UserName And Password = @Password", SqlCon.con);
- cmd.Parameters.AddWithValue("@username", txtUsername.Text);
- cmd.Parameters.AddWithValue("@password", txtPassword.Text);
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- Global.companyID = dr[0].ToString();
- Global.companyName = dr[1].ToString();
- SqlCon.Close();
- dr.Close();
- }
- else
- {
- MessageBox.Show("Username or password is incorrect", "Job Fair", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- txtUsername.Clear();
- txtPassword.Clear();
- SqlCon.Close();
- }
- MessageBox.Show("Update your company representative. No representative is registered in your account", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
- FrmAddCompany frm = new FrmAddCompany();
- frm.Show();
- txtUsername.Clear();
- txtPassword.Clear();
- }
- else
- {
- Login();
- }
- }
- }
- private void Login()
- {
- SqlCon.Open();
- SqlCommand cmd = new SqlCommand("Select * from Company where Username = @UserName And Password = @Password", SqlCon.con);
- cmd.Parameters.AddWithValue("@username", txtUsername.Text);
- cmd.Parameters.AddWithValue("@password", txtPassword.Text);
- SqlDataReader dr = cmd.ExecuteReader();
- if(dr.Read())
- {
- if (restriction3())
- {
- MessageBox.Show("You are not allowed to login because you are not included to the current job fair company list", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- Global.companyID = dr[0].ToString();
- Global.companyName = dr[1].ToString();
- this.Hide();
- EditFrmRepresentative frm = new EditFrmRepresentative();
- frm.TopLevel = false;
- frm.Parent = this.Parent;
- frm.Show();
- SqlCon.Close();
- dr.Close();
- }
- }
- else
- {
- MessageBox.Show("Username or passsword is incorrect", "Job Fair", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- txtUsername.Clear();
- txtPassword.Clear();
- SqlCon.Close();
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- FrmAddCompany frm = new FrmAddCompany();
- frm.ShowDialog();
- }
- private bool restriction()
- {
- SqlCon.Open();
- string id1 = "";
- SqlCommand cmd = new SqlCommand("Select * from VwAttendance where (Username = '"+txtUsername.Text+"' And Password = '"+txtPassword.Text+"') And (RepName = '"+""+"' OR RepName = '"+"N/A"+"') ", SqlCon.con);
- SqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- id1 = dr[1].ToString();
- SqlCon.Close();
- return true;
- }
- SqlCon.Close();
- return false;
- }
- private bool restriction2()
- {
- //SqlCon.Open();
- //string id1 = "";
- //SqlCommand cmd = new SqlCommand("Select * from Company where (Username = '" + txtUsername.Text + "' And Password = '" + txtPassword.Text + "') And Confirmation = '"+"Inactive"+"'", SqlCon.con);
- //SqlDataReader dr = cmd.ExecuteReader();
- //while (dr.Read())
- //{
- // id1 = dr[1].ToString();
- // SqlCon.Close();
- // return true;
- //}
- //SqlCon.Close();
- //return false;
- string username = txtUsername.Text.ToString();
- string password = txtPassword.Text.ToString();
- string year = DateTime.UtcNow.Year.ToString();
- string comstate = "Active";
- SqlCon.Open();
- SqlCommand cmd1 = new SqlCommand("Select B1Month1,B1Month2,B2Month1,B2Month2 from Settings", SqlCon.con);
- SqlDataReader dr = cmd1.ExecuteReader();
- if (dr.Read())
- {
- if (DateTime.Now.Month >= Int32.Parse(dr[0].ToString()) && DateTime.Now.Month <= Int32.Parse(dr[1].ToString()))
- {
- currentBatch = "1st";
- }
- else if (DateTime.Now.Month >= Int32.Parse(dr[2].ToString()) && DateTime.Now.Month <= Int32.Parse(dr[3].ToString()))
- {
- currentBatch = "2nd";
- }
- }
- dr.Close();
- SqlCon.Close();
- SqlCon.Open();
- SqlCommand cmd2 = new SqlCommand("SELECT COUNT(*) as myCount from vwRestrictionState where Username = @USERNAME and Password = @PASSWORD and comBatch = @BATCH and comYear = @YEAR and comState = @COMSTATE ", SqlCon.con);
- cmd2.Parameters.AddWithValue("@USERNAME", username);
- cmd2.Parameters.AddWithValue("@PASSWORD", password);
- cmd2.Parameters.AddWithValue("@BATCH", currentBatch);
- cmd2.Parameters.AddWithValue("@YEAR", year);
- cmd2.Parameters.AddWithValue("@COMSTATE", comstate);
- int returnValue = (int)cmd2.ExecuteScalar();
- if (returnValue >= 1)
- {
- return false;
- }
- SqlCon.Close();
- return true;
- // MessageBox.Show(currentBatch+username+password+year+comstate1+ "", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- private bool restriction3()
- {
- //SqlCon.Open();
- //string id1 = "";
- //SqlCommand cmd = new SqlCommand("Select * from Company where (Username = '" + txtUsername.Text + "' And Password = '" + txtPassword.Text + "') And Confirmation = '"+"Inactive"+"'", SqlCon.con);
- //SqlDataReader dr = cmd.ExecuteReader();
- //while (dr.Read())
- //{
- // id1 = dr[1].ToString();
- // SqlCon.Close();
- // return true;
- //}
- //SqlCon.Close();
- //return false;
- string username = txtUsername.Text;
- string password = txtPassword.Text;
- string year = DateTime.UtcNow.Year.ToString();
- string comstate = "Active";
- SqlCon.Open();
- SqlCommand cmd1 = new SqlCommand("Select MB1Month1,MB1Month2,MB2Month1,MB2Month2 from MockSettings", SqlCon.con);
- SqlDataReader dr = cmd1.ExecuteReader();
- if (dr.Read())
- {
- if (DateTime.Now.Month >= Int32.Parse(dr[0].ToString()) && DateTime.Now.Month <= Int32.Parse(dr[1].ToString()))
- {
- currentBatch = "1st";
- }
- else if (DateTime.Now.Month >= Int32.Parse(dr[2].ToString()) && DateTime.Now.Month <= Int32.Parse(dr[3].ToString()))
- {
- currentBatch = "2nd";
- }
- }
- dr.Close();
- SqlCon.Close();
- SqlCon.Open();
- SqlCommand cmd2 = new SqlCommand("SELECT COUNT(*) as myCount from vwmRestrictionState where Username = @USERNAME and Password = @PASSWORD and mcomBatch = @BATCH and mcomYear = @YEAR and mcomState = @COMSTATE ", SqlCon.con);
- cmd2.Parameters.AddWithValue("@USERNAME", username);
- cmd2.Parameters.AddWithValue("@PASSWORD", password);
- cmd2.Parameters.AddWithValue("@BATCH", currentBatch);
- cmd2.Parameters.AddWithValue("@YEAR", year);
- cmd2.Parameters.AddWithValue("@COMSTATE", comstate);
- int returnValue = (int)cmd2.ExecuteScalar();
- if (returnValue >= 1)
- {
- return false;
- }
- SqlCon.Close();
- return true;
- // MessageBox.Show(currentBatch+username+password+year+comstate1+ "", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- private void btnLogout_Click(object sender, EventArgs e)
- {
- Global.loginmode = "";
- this.Hide();
- frmChoose frm = new frmChoose();
- frm.TopLevel = false;
- frm.Parent = this.Parent;
- frm.Show();
- }
- private void FrmCompanyLogin_Load(object sender, EventArgs e)
- {
- Global.login = this;
- if (Global.loginmode == "Mock")
- {
- lblType.Text = "Mock Interview";
- }
- else
- {
- lblType.Text = "Job Fair";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement