protected void Page_Init(object sender, EventArgs e)
    {
        string username = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name;

        if (Session["kechengid"] == null)
        {
            int minkechengid = TeacherInfo.GetTeacherRenke_min_kechengid(username);
            if (minkechengid > 0)
            {
                Session["kechengid"] = minkechengid;
            }
            else if (KechengInfo.GetKechengCount() > 0)
            {
                Session["kechengid"] = KechengInfo.MinKechengid();
            }
            else
            {
                List <string> noneKechengPage = new List <string>();//不需要课程的页面
                noneKechengPage.Add("createcourse.aspx");
                noneKechengPage.Add("help.aspx");
                noneKechengPage.Add("addbanji.aspx");
                noneKechengPage.Add("default.aspx");
                noneKechengPage.Add("studentdaoru.aspx");
                noneKechengPage.Add("wanshanxinxi.aspx");
                noneKechengPage.Add("addstudent.aspx");
                noneKechengPage.Add("editstudent.aspx");
                noneKechengPage.Add("editstudentinfo.aspx");
                noneKechengPage.Add("gerenxinxi.aspx");
                noneKechengPage.Add("kcxianyou.aspx");
                string url     = HttpContext.Current.Request.Url.AbsolutePath;
                string pageurl = url.Substring(url.LastIndexOf("/") + 1).ToLower();
                if (!noneKechengPage.Contains(pageurl))
                {
                    Response.Redirect("createcourse.aspx");
                }
            }
        }
        if (!IsPostBack)
        {
            Literal2.Text = TeacherInfo.TeacherXingMing(username) + "老师.";
            if (Session["kechengid"] != null)
            {
                lbl_kecheng.Text = KechengInfo.getKechengname(DropDownList1.SelectedValue = Session["kechengid"].ToString());
            }
            else
            {
                lbl_kecheng.Text = "未知";
            }
            lbtn_qiehuan.Visible = TeacherInfo.IsManager(username);//是否显示身份切换链接
        }
    }
 protected void Page_Init(object sender, EventArgs e)
 {
     if (Session["kechengid"] == null)
     {
         if (KechengInfo.GetKechengCount() > 0)
         {
             Session["kechengid"] = KechengInfo.MinKechengid().ToString();
         }
         else
         {
             Response.Redirect("default.aspx");
         }
     }
     if (!IsPostBack)
     {
         string stuusername = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name;
         Literalxingming.Text = StudentInfo.GetStuXingming(stuusername);
     }
     lbl_kecheng.Text = KechengInfo.getKechengname(Session["kechengid"].ToString());
     CheckCeshi();//判断学生有无未完成的测试,如果有,不允许进行其他学习活动,只能进行测试
 }
Ejemplo n.º 3
0
 protected void Page_Init(object sender, EventArgs e)
 {
     if (Request.QueryString["kechengid"] != null)
     {
         Session["kechengid"] = Request.QueryString["kechengid"].Trim();
     }
     else
     {
         if (Session["kechengid"] == null)
         {
             if (KechengInfo.GetKechengCount() > 0)
             {
                 Session["kechengid"] = KechengInfo.MinKechengid().ToString();
             }
             else
             {
                 Response.Redirect("../default.aspx");
             }
         }
     }
     literal_kecheng.Text = KechengInfo.getKechengname(Session["kechengid"].ToString());;
 }
    protected void Page_Init(object sender, EventArgs e)
    {
        if (Session["kechengid"] == null)
        {
            if (KechengInfo.GetKechengCount() > 0)
            {
                Session["kechengid"] = KechengInfo.MinKechengid().ToString();
            }
            else
            {
                Response.Redirect("../default.aspx");
            }
        }
        label_kecheng.Text = KechengInfo.getKechengname(Session["kechengid"].ToString());
        string username    = string.Empty;
        string usershenfen = string.Empty;

        try
        {
            username    = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name;
            usershenfen = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.UserData;
        }
        catch
        {
        }
        if (username != string.Empty && usershenfen != string.Empty)
        {
            Literal2.Text       = username;
            user_login.Visible  = false;
            user_logout.Visible = true;
        }
        else
        {
            Literal2.Text       = "游客.";
            user_login.Visible  = true;
            user_logout.Visible = false;
        }
    }
Ejemplo n.º 5
0
    protected void Buttonloginin_Click(object sender, EventArgs e)
    {
        Labelerror.Text = "";
        bool          yonghukeyong = true;
        string        username     = TextBoxusername.Text.Trim();
        string        password     = TextBoxpassword.Text.Trim();
        string        shenfen      = RadioButtonListshenfen.SelectedValue.ToString().Trim();
        SqlConnection conn         = new SqlConnection();

        conn.ConnectionString = ConfigurationManager.ConnectionStrings["kecheng2012ConnectionString"].ConnectionString;
        SqlCommand    comm      = conn.CreateCommand();
        bool          chenggong = false;
        SqlDataReader sdr;

        conn.Open();
        if (shenfen == "teacher")
        {
            comm.CommandText = "select [password],[keyong] from [tb_teacher] where [username]=@username";
            comm.Parameters.AddWithValue("@username", username);
            sdr = comm.ExecuteReader();
            if (sdr.Read())
            {
                if (sdr.GetString(0).Trim() == password)
                {
                    chenggong = true;
                }
                if (sdr.GetString(1).Trim() == "否")
                {
                    yonghukeyong = false;
                }
            }
            sdr.Close();
        }
        else if (shenfen == "student")
        {
            comm.CommandText = "select [password] from [tb_Student] where [username]= @username";
            comm.Parameters.AddWithValue("@username", username);
            sdr = comm.ExecuteReader();
            if (sdr.Read())
            {
                if (sdr.GetString(0).Trim() == password)
                {
                    chenggong = true;
                }
            }
            sdr.Close();
        }
        else//管理员
        {
            comm.CommandText = "select [password],[manager],[keyong] from [tb_teacher] where [username]=@username";
            comm.Parameters.AddWithValue("@username", username);
            sdr = comm.ExecuteReader();
            if (sdr.Read())
            {
                string userpassword = sdr.GetString(0);
                if (!sdr.IsDBNull(1))
                {
                    string ismanager = sdr.GetString(1);
                    if (userpassword == password && (ismanager == "manager" || ismanager == "supermanager"))
                    {
                        chenggong = true;
                    }
                }
                if (sdr.GetString(2).Trim() == "否")
                {
                    yonghukeyong = false;
                }
            }
            sdr.Close();
        }
        conn.Close();
        comm.Dispose();
        //创建认证票据
        if (chenggong && yonghukeyong)
        {
            FormsAuthentication.Initialize();
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                1,                                                                         //票据版本号
                username,                                                                  //票据持有者
                DateTime.Now,                                                              //分配票据的时间
                DateTime.Now.AddHours(3),                                                  //失效时间
                true,                                                                      //需要用户的cookie
                shenfen,                                                                   //用户的角色
                FormsAuthentication.FormsCookiePath);                                      //cookie有效路径
            string     hash   = FormsAuthentication.Encrypt(ticket);                       //加密
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); //加密之后的cookie
            cookie.Expires = ticket.Expiration;
            //添加cookie到页面请求响应中
            Response.Cookies.Add(cookie);
            string returnurl = "";
            if (shenfen == "teacher")
            {
                returnurl = "teacher/Default.aspx";
            }
            else if (shenfen == "student")
            {
                if (KechengInfo.GetKechengCount() > 0)
                {
                    Session["kechengid"] = KechengInfo.MinKechengid();
                }
                returnurl = "student/Default.aspx";
            }
            else if (shenfen == "manager")
            {
                returnurl = "manager/tianjiabanji.aspx";
            }
            Response.Redirect(returnurl);
        }
        else
        {
            if (!yonghukeyong)
            {
                Labelerror.Text = "该用户已被禁用,请与管理员联系!";
            }
            else
            {
                Labelerror.Text = "用户名或密码错误!请重试!";
            }
        }
    }