using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;

namespace IntranetApp
{
	/// <summary>
	/// Summary description for EmployeeLogin.
	/// </summary>
	public partial class EmployeeLogin : System.Web.UI.Page
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			Label5.Text="";
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		SqlConnection con=new SqlConnection(ConfigurationSettings.AppSettings.Get("con"));
		protected void Button2_Click(object sender, System.EventArgs e)
		{
			txtUserId.Text="";
			txtPwd.Text="";
			ddlDesg.SelectedIndex=0;
		}

		protected void Button1_Click(object sender, System.EventArgs e)
		{
			try
			{
				if (con.State==ConnectionState.Closed) con.Open();	
					SqlCommand cmd=new SqlCommand("select deptno,branchno,role from emp where empno=" + txtUserId.Text + " and pwd='" + txtPwd.Text + "' and role='"+ddlDesg.SelectedValue+"'",con);
					SqlDataReader  dr;
					dr=cmd.ExecuteReader();
				
				if (dr.Read())
					{							
						Session["eid"]=txtUserId.Text;
						Session["dno"]=dr.GetValue(0);
						Session["bno"]=dr.GetValue(1);

						if (dr.GetValue(2).ToString().ToLower()=="manager")
						{
							Response.Redirect("ManagerHome.aspx");
						}
						else
						{
							Response.Redirect("EmpHome.aspx");
						}
					}					
					else
						Label5.Text="Insufficient Data. Plz give correct Data";
				
			}
			catch (Exception ex)
			{
				Label5.Text = ex.Message;
			}
		}

		protected void txtPwd_TextChanged(object sender, System.EventArgs e)
		{
		
		}

		protected void ddlDesg_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		
		}
	}
}
