Advertisement
Guest User

errorC#

a guest
May 15th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.73 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Data.SqlClient;
  4. using MDLL;
  5.  
  6. namespace Company
  7. {
  8.     public partial class FrmCompanyLogin : Form
  9.     {
  10.  
  11.  
  12.         public string currentBatch;
  13.         public string checker;
  14.  
  15.  
  16.    
  17.         //Connection c = new Connection();
  18.        
  19.         public FrmCompanyLogin()
  20.         {
  21.            
  22.             InitializeComponent();
  23.            
  24.  
  25.         }
  26.  
  27.        
  28.  
  29.         private void btnConfirm_Click(object sender, EventArgs e)
  30.         {
  31.  
  32.             if (txtUsername.TextLength == 0 || txtPassword.TextLength == 0)
  33.             {
  34.                 MessageBox.Show("Please Fill All The Fields", "Job Fair", MessageBoxButtons.OK, MessageBoxIcon.Information);
  35.             }
  36.                  
  37.             else
  38.             {
  39.  
  40.          
  41.  
  42.               if (restriction())
  43.                 {
  44.                     SqlCon.Open();      
  45.  
  46.                     SqlCommand cmd = new SqlCommand("Select * from Company where Username = @UserName And Password = @Password", SqlCon.con);
  47.                     cmd.Parameters.AddWithValue("@username", txtUsername.Text);
  48.                     cmd.Parameters.AddWithValue("@password", txtPassword.Text);
  49.                     SqlDataReader dr = cmd.ExecuteReader();
  50.  
  51.                     if (dr.Read())
  52.                     {                  
  53.                         Global.companyID = dr[0].ToString();
  54.                         Global.companyName = dr[1].ToString();
  55.                         SqlCon.Close();
  56.                         dr.Close();
  57.  
  58.                     }
  59.                     else
  60.                     {
  61.                         MessageBox.Show("Username or password is incorrect", "Job Fair", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  62.                         txtUsername.Clear();
  63.                         txtPassword.Clear();
  64.                         SqlCon.Close();
  65.                     }
  66.  
  67.                     MessageBox.Show("Update your company representative. No representative is registered in your account", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
  68.                     FrmAddCompany frm = new FrmAddCompany();
  69.                     frm.Show();
  70.                     txtUsername.Clear();
  71.                     txtPassword.Clear();
  72.  
  73.                  
  74.                 }
  75.                  
  76.  
  77.  
  78.                 else
  79.                 {
  80.  
  81.                     Login();
  82.                 }
  83.  
  84.  
  85.  
  86.             }
  87.         }
  88.  
  89.         private void Login()
  90.         {
  91.             SqlCon.Open();
  92.            
  93.             SqlCommand cmd = new SqlCommand("Select * from Company where Username = @UserName And Password = @Password", SqlCon.con);
  94.             cmd.Parameters.AddWithValue("@username", txtUsername.Text);
  95.             cmd.Parameters.AddWithValue("@password", txtPassword.Text);
  96.             SqlDataReader dr = cmd.ExecuteReader();
  97.            
  98.              if(dr.Read())
  99.              {
  100.  
  101.  
  102.  
  103.  
  104.  
  105.                  if (restriction3())
  106.                  {
  107.  
  108.                      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);
  109.  
  110.                  }
  111.                
  112.  
  113.                  else
  114.                  {
  115.                      Global.companyID = dr[0].ToString();
  116.                      Global.companyName = dr[1].ToString();
  117.                      this.Hide();
  118.                      EditFrmRepresentative frm = new EditFrmRepresentative();
  119.                      frm.TopLevel = false;
  120.                      frm.Parent = this.Parent;
  121.                      frm.Show();
  122.                      SqlCon.Close();
  123.                      dr.Close();
  124.                  }
  125.                    
  126.      
  127.              
  128.             }
  129.             else
  130.             {
  131.  
  132.                 MessageBox.Show("Username or passsword is incorrect", "Job Fair", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  133.                 txtUsername.Clear();
  134.                 txtPassword.Clear();
  135.                 SqlCon.Close();
  136.             }
  137.  
  138.         }
  139.  
  140.         private void button1_Click(object sender, EventArgs e)
  141.         {
  142.            
  143.             FrmAddCompany frm = new FrmAddCompany();
  144.             frm.ShowDialog();
  145.  
  146.         }
  147.  
  148.  
  149.         private bool restriction()
  150.         {
  151.             SqlCon.Open();
  152.             string id1 = "";
  153.             SqlCommand cmd = new SqlCommand("Select * from VwAttendance where (Username = '"+txtUsername.Text+"' And Password = '"+txtPassword.Text+"') And (RepName = '"+""+"' OR RepName = '"+"N/A"+"') ", SqlCon.con);
  154.             SqlDataReader dr = cmd.ExecuteReader();
  155.             while (dr.Read())
  156.             {
  157.                 id1 = dr[1].ToString();
  158.                 SqlCon.Close();
  159.                 return true;
  160.  
  161.                
  162.             }
  163.             SqlCon.Close();
  164.             return false;
  165.  
  166.  
  167.         }
  168.  
  169.  
  170.         private bool restriction2()
  171.         {
  172.            
  173.             //SqlCon.Open();
  174.             //string id1 = "";
  175.             //SqlCommand cmd = new SqlCommand("Select * from Company where (Username = '" + txtUsername.Text + "' And Password = '" + txtPassword.Text + "') And Confirmation = '"+"Inactive"+"'", SqlCon.con);
  176.             //SqlDataReader dr = cmd.ExecuteReader();
  177.             //while (dr.Read())
  178.             //{
  179.             //    id1 = dr[1].ToString();
  180.             //    SqlCon.Close();
  181.             //    return true;
  182.             //}
  183.             //SqlCon.Close();
  184.             //return false;
  185.  
  186.             string username = txtUsername.Text.ToString();
  187.             string password = txtPassword.Text.ToString();
  188.             string year = DateTime.UtcNow.Year.ToString();
  189.             string comstate = "Active";
  190.  
  191.            
  192.  
  193.             SqlCon.Open();
  194.             SqlCommand cmd1 = new SqlCommand("Select B1Month1,B1Month2,B2Month1,B2Month2 from Settings", SqlCon.con);
  195.             SqlDataReader dr = cmd1.ExecuteReader();
  196.  
  197.             if (dr.Read())
  198.             {
  199.  
  200.  
  201.                 if (DateTime.Now.Month >= Int32.Parse(dr[0].ToString()) && DateTime.Now.Month <= Int32.Parse(dr[1].ToString()))
  202.                 {
  203.                     currentBatch = "1st";
  204.            
  205.                        
  206.  
  207.                 }
  208.                 else if (DateTime.Now.Month >= Int32.Parse(dr[2].ToString()) && DateTime.Now.Month <= Int32.Parse(dr[3].ToString()))
  209.                 {
  210.  
  211.                     currentBatch = "2nd";
  212.        
  213.                  
  214.  
  215.                 }
  216.             }
  217.            
  218.             dr.Close();
  219.  
  220.             SqlCon.Close();
  221.            
  222.             SqlCon.Open();
  223.  
  224.             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);
  225.             cmd2.Parameters.AddWithValue("@USERNAME", username);
  226.             cmd2.Parameters.AddWithValue("@PASSWORD", password);
  227.             cmd2.Parameters.AddWithValue("@BATCH", currentBatch);
  228.             cmd2.Parameters.AddWithValue("@YEAR", year);
  229.             cmd2.Parameters.AddWithValue("@COMSTATE", comstate);
  230.  
  231.             int returnValue = (int)cmd2.ExecuteScalar();
  232.  
  233.             if (returnValue >= 1)
  234.             {
  235.  
  236.                 return false;
  237.                
  238.             }
  239.  
  240.              SqlCon.Close();      
  241.             return true;
  242.  
  243.  
  244.            // MessageBox.Show(currentBatch+username+password+year+comstate1+ "", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);          
  245.    
  246.            
  247.        
  248.        
  249. }
  250.  
  251.         private bool restriction3()
  252.         {
  253.  
  254.             //SqlCon.Open();
  255.             //string id1 = "";
  256.             //SqlCommand cmd = new SqlCommand("Select * from Company where (Username = '" + txtUsername.Text + "' And Password = '" + txtPassword.Text + "') And Confirmation = '"+"Inactive"+"'", SqlCon.con);
  257.             //SqlDataReader dr = cmd.ExecuteReader();
  258.             //while (dr.Read())
  259.             //{
  260.             //    id1 = dr[1].ToString();
  261.             //    SqlCon.Close();
  262.             //    return true;
  263.             //}
  264.             //SqlCon.Close();
  265.             //return false;
  266.  
  267.             string username = txtUsername.Text;
  268.             string password = txtPassword.Text;
  269.             string year = DateTime.UtcNow.Year.ToString();
  270.             string comstate = "Active";
  271.  
  272.  
  273.  
  274.             SqlCon.Open();
  275.             SqlCommand cmd1 = new SqlCommand("Select MB1Month1,MB1Month2,MB2Month1,MB2Month2 from MockSettings", SqlCon.con);
  276.             SqlDataReader dr = cmd1.ExecuteReader();
  277.  
  278.             if (dr.Read())
  279.             {
  280.  
  281.  
  282.                 if (DateTime.Now.Month >= Int32.Parse(dr[0].ToString()) && DateTime.Now.Month <= Int32.Parse(dr[1].ToString()))
  283.                 {
  284.                     currentBatch = "1st";
  285.  
  286.  
  287.  
  288.                 }
  289.                 else if (DateTime.Now.Month >= Int32.Parse(dr[2].ToString()) && DateTime.Now.Month <= Int32.Parse(dr[3].ToString()))
  290.                 {
  291.  
  292.                     currentBatch = "2nd";
  293.  
  294.  
  295.  
  296.                 }
  297.             }
  298.  
  299.             dr.Close();
  300.  
  301.             SqlCon.Close();
  302.  
  303.             SqlCon.Open();
  304.  
  305.             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);
  306.             cmd2.Parameters.AddWithValue("@USERNAME", username);
  307.             cmd2.Parameters.AddWithValue("@PASSWORD", password);
  308.             cmd2.Parameters.AddWithValue("@BATCH", currentBatch);
  309.             cmd2.Parameters.AddWithValue("@YEAR", year);
  310.             cmd2.Parameters.AddWithValue("@COMSTATE", comstate);
  311.  
  312.             int returnValue = (int)cmd2.ExecuteScalar();
  313.  
  314.             if (returnValue >= 1)
  315.             {
  316.  
  317.                 return false;
  318.  
  319.             }
  320.  
  321.             SqlCon.Close();
  322.             return true;
  323.  
  324.  
  325.             // MessageBox.Show(currentBatch+username+password+year+comstate1+ "", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);          
  326.  
  327.  
  328.  
  329.  
  330.         }
  331.  
  332.    
  333.  
  334.         private void btnLogout_Click(object sender, EventArgs e)
  335.         {
  336.            
  337.             Global.loginmode = "";
  338.             this.Hide();
  339.             frmChoose frm = new frmChoose();
  340.             frm.TopLevel = false;
  341.             frm.Parent = this.Parent;
  342.             frm.Show();
  343.         }
  344.  
  345.         private void FrmCompanyLogin_Load(object sender, EventArgs e)
  346.         {
  347.             Global.login = this;
  348.             if (Global.loginmode == "Mock")
  349.             {
  350.                 lblType.Text = "Mock Interview";
  351.  
  352.             }
  353.             else
  354.             {
  355.                 lblType.Text = "Job Fair";
  356.             }
  357.  
  358.         }
  359.  
  360.      
  361.     }
  362. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement