Click here to Skip to main content
15,917,005 members

Comments by Member 9962877 (Top 1 by date)

Member 9962877 11-Apr-13 0:36am View    
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{

SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=admin;database=projeval");
SqlCommand cmd = new SqlCommand();
SqlCommand cmd1 = new SqlCommand();
SqlCommand cmd2 = new SqlCommand();
SqlCommand cmd3 = new SqlCommand();
SqlDataAdapter ada = new SqlDataAdapter();
DataTable dt = new DataTable();
DataTable dt1 = new DataTable();
SqlDataAdapter ada3 = new SqlDataAdapter();
DataTable dt3 = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

cmd.Connection = con;
cmd.CommandText = "select *from logindate";
ada.SelectCommand = cmd;
ada.Fill(dt);
if (dt.Rows[0][0].ToString() == DateTime.Now.ToShortDateString())
{
Literal1.Visible = true;
}
else
{
Literal1.Visible = false;
}


}
}
protected void Button1_Click(object sender, EventArgs e)
{
cmd.Connection = con;
cmd.CommandText = "sp_login";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@uname", TextBox1.Text);
cmd.Parameters.AddWithValue("@pwd", TextBox2.Text);
SqlParameter p = new SqlParameter("@val", SqlDbType.Int);
p.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(p);
SqlParameter p1 = new SqlParameter("@uid", SqlDbType.Int);
p1.Direction = ParameterDirection.Output;
cmd.Parameters.Add(p1);
SqlParameter p2 = new SqlParameter("@type", SqlDbType.VarChar ,90);
p2.Direction = ParameterDirection.Output;
cmd.Parameters.Add(p2);
con.Open();
cmd.ExecuteNonQuery();
con.Close();


if(p.Value.ToString()=="1")
{
Session["uid"]=p1.Value.ToString();
Session["type"] = p2.Value.ToString();
switch(p2.Value.ToString())
{
case "student":
dt.Clear();
cmd1.Connection = con;
cmd1.CommandText = "select * from login where uid=" + p1.Value.ToString();
ada.SelectCommand = cmd1;
ada.Fill(dt);
if (dt.Rows[0][4].ToString() == "yes")
{
cmd2.Connection = con;
cmd2.CommandText = "select grpname from grouplogin where uid=" + p1.Value.ToString();
ada.SelectCommand = cmd2;
ada.Fill(dt1);
Session["studentgpname"] = dt1.Rows[0][0].ToString();

Response.Redirect("studenthome.aspx");
}
else
{
Label5.Text = "Not approved";
}
con.Open();
cmd1.ExecuteNonQuery();
con.Close();
break;
case "admin":
Response.Redirect("adminhome.aspx");
break;

case "HOD":
Response.Redirect("HodAssignStaff.aspx");
break;
case "Staff":
dt.Clear();
cmd1.Connection = con;
cmd1.CommandText = "select * from login where uid=" + p1.Value.ToString();
ada.SelectCommand = cmd1;
ada.Fill(dt);
if (dt.Rows[0][4].ToString() == "yes")
{
String staff = dt.Rows[0][1].