Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data.OleDb;
  8. using System.Configuration;
  9.  
  10. namespace WebApplication1
  11. {
  12.     public partial class login : System.Web.UI.Page
  13.     {
  14.         protected void Page_Load(object sender, EventArgs e)
  15.         {
  16.  
  17.         }
  18.  
  19.         protected void Button1_Click(object sender, EventArgs e)
  20.         {
  21.             int result = 0;
  22.             OleDbConnection cn = new OleDbConnection();
  23.             cn.ConnectionString = ConfigurationManager.ConnectionStrings["smConnectionString"].ToString();
  24.             cn.Open();
  25.             OleDbCommand cmd = new OleDbCommand("SELECT login_ID, utype FROM employee WHERE login_ID = @loginid AND pass_word= @password",cn);
  26.             cmd.Parameters.AddWithValue("@loginid", TextBox1.Text);
  27.             cmd.Parameters.AddWithValue("@password", TextBox2.Text);
  28.             try
  29.             {
  30.                 result = (int)cmd.ExecuteScalar();
  31.             if (result > 0)
  32.             {
  33.                 OleDbDataReader reader = cmd.ExecuteReader();
  34.                
  35.                     while (reader.Read())
  36.                     {
  37.                         string ulevel = reader["utype"].ToString();
  38.                         Session["empID"] = reader["login_ID"].ToString();
  39.                        
  40.                         Label1.Text = ulevel;
  41.                     }
  42.                     if (Label1.Text == "admin")
  43.                     {
  44.                          Response.RedirectPermanent("emp_viewsl.aspx?='" + Session["empID"] + "'");
  45.                         Label1.Text = "Admin";
  46.                     }
  47.                     else if (Label1.Text == "accountant")
  48.                     {
  49.                         //Response.RedirectPermanent("");
  50.                         Label1.Text = "accountat";
  51.                     }
  52.                     else
  53.                     {
  54.                         //Response.RedirectPermanent("");
  55.                         Label1.Text = "user";
  56.                        
  57.                     }
  58.                
  59.                
  60.             }
  61.             else
  62.             {
  63.                 Label2.Text = "Invalid credentials";
  64.             }
  65.             }
  66.             catch (Exception ex)
  67.             {
  68.                 Label2.Text = ex.Message;
  69.                 Label2.Visible = true;
  70.             }
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement