Esempio n. 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Session["RoleID"] == null || Session["UserID"] == null)
         {
             Util.ShowMessage("用户登录超时,请重新登录!", "Login2.aspx");
         }
         else
         {
             int RoleID = Convert.ToInt16(Session["RoleID"].ToString());
             if (RoleID > 1)
             {
                 Util.ShowMessage("对不起,你无权访问该页面!", "User_Center.aspx");
             }
             else
             {
                 using (SqlConnection conn = new DB().GetConnection())
                 {
                     SqlCommand cmd = conn.CreateCommand();
                     cmd.CommandText = "select * from Cats order by Orders desc";
                     conn.Open();
                     SqlDataReader rd = cmd.ExecuteReader();
                     Cats.DataSource     = rd;
                     Cats.DataValueField = "ID";
                     Cats.DataTextField  = "CatName";
                     Cats.DataBind();
                     rd.Close();
                 }
             }
         }
     }
 }
Esempio n. 2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         using (SqlConnection conn = new DB().GetConnection())
         {
             SqlCommand cmd = conn.CreateCommand();
             cmd.CommandText = "select * from Cats order by Orders desc";
             conn.Open();
             SqlDataReader rd = cmd.ExecuteReader();
             Cats.DataSource     = rd;
             Cats.DataValueField = "ID";
             Cats.DataTextField  = "CatName";
             Cats.DataBind();
             rd.Close();
         }
     }
 }
Esempio n. 3
0
    private void MyInitForAdd()
    {
        CDT_TextBox.Text = DateTime.Now.ToString("yyyy-MM-dd");
        using (SqlConnection conn = new DB().GetConnection())
        {
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select * from Cats order by Orders desc";
            conn.Open();
            SqlDataReader rd = cmd.ExecuteReader();
            Cats.DataSource     = rd;
            Cats.DataValueField = "ID";
            Cats.DataTextField  = "CatName";
            Cats.DataBind();
            rd.Close();


            cmd.CommandText = "select * from UserTags order by ID asc";
            rd = cmd.ExecuteReader();
            UserTag.DataSource     = rd;
            UserTag.DataTextField  = "TagName";
            UserTag.DataValueField = "ID";
            UserTag.DataBind();
            rd.Close();


            cmd.CommandText = "select max(Orders) as orders from Articles";
            rd = cmd.ExecuteReader();
            if (rd.Read())
            {
                MaxOrders.Text = rd[0].ToString();
            }
            rd.Close();



            cmd.CommandText = "select * from Subs where CatID = " + Cats.SelectedValue + " order by Orders desc";
            rd = cmd.ExecuteReader();
            Subs.DataSource     = rd;
            Subs.DataTextField  = "SubName";
            Subs.DataValueField = "ID";
            Subs.DataBind();
            rd.Close();
        }
    }
Esempio n. 4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        LabelUserID.Text   = Request.QueryString["ID"];
        LabelRandomID.Text = Request.QueryString["RandomID"];
        if (!IsPostBack)
        {
            string username = Convert.ToString(Session["UserName"]);
            string userid   = Convert.ToString(Session["UserID"]);
            int    RoleID   = Convert.ToInt16(Session["RoleID"].ToString());
            if (!string.IsNullOrEmpty(LabelUserID.Text) && RoleID <= 1)
            {
                PlaceHolder1.Visible = false;
                PlaceHolder2.Visible = true;
                PlaceHolder3.Visible = false;
                PlaceHolder4.Visible = true;
            }
            else if (!string.IsNullOrEmpty(LabelRandomID.Text) && RoleID <= 1)
            {
                PlaceHolder1.Visible = false;
                PlaceHolder2.Visible = false;
                PlaceHolder3.Visible = true;
                PlaceHolder4.Visible = false;
            }
            else
            {
                PlaceHolder1.Visible = true;
                PlaceHolder2.Visible = false;
                PlaceHolder3.Visible = false;
                PlaceHolder4.Visible = false;
            }
            if (Session["RoleID"] == null || Session["UserID"] == null)
            {
                Util.ShowMessage("用户登录超时,请重新登录!", "Login2.aspx");
            }
            //else if ( username != LabelUserID.Text)
            //{
            //    Util.ShowMessage("您没有访问该页面的权限!", "Login2.aspx");
            //}
            else
            {
                //int updateavatar = Util.UpdateAvatar(username);
                //Image1.ImageUrl = Session["Avatar"].ToString();
                if (Session["RoleID"] != null && !String.IsNullOrEmpty(Session["RoleID"].ToString()) && (Session["RoleID"].ToString() == "1"))
                {
                    Role.Enabled          = true;
                    PasswordPanel.Visible = true;
                    init();
                }
                else
                {
                    Role.Enabled          = false;
                    RolePanel.Visible     = false;
                    PasswordPanel.Visible = false;
                    ValidPanel.Visible    = false;
                }
                using (SqlConnection conn = new DB().GetConnection())
                {
                    string     sql = "select * from Roles order by ID asc";
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    conn.Open();
                    SqlDataReader rd = cmd.ExecuteReader();
                    Role.DataSource     = rd;
                    Role.DataTextField  = "RoleName";
                    Role.DataValueField = "ID";
                    Role.DataBind();
                    rd.Close();

                    cmd.CommandText = "select * from Cats";
                    rd = cmd.ExecuteReader();
                    Cats.DataSource     = rd;
                    Cats.DataValueField = "ID";
                    Cats.DataTextField  = "CatName";
                    Cats.DataBind();
                    rd.Close();
                    Cats.Items.Insert(0, new ListItem("状态", ""));

                    cmd.CommandText = "select UserName from Users where ID = @ID ";
                    cmd.Parameters.AddWithValue("@ID", LabelUserID.Text);
                    rd = cmd.ExecuteReader();
                    if (rd.Read())
                    {
                        LabelUserName.Text = rd["UserName"].ToString();
                    }
                    rd.Close();



                    cmd.CommandText = "select UserName from Users where RandomID = @RandomID2  ";
                    cmd.Parameters.AddWithValue("@RandomID2", LabelRandomID.Text);
                    rd = cmd.ExecuteReader();
                    if (rd.Read())
                    {
                        LabelUserName2.Text = rd["UserName"].ToString();
                    }
                    rd.Close();



                    cmd.CommandText = "Select * from [Users] where ID = @UserID2";
                    cmd.Parameters.AddWithValue("@UserID2", userid);
                    rd = cmd.ExecuteReader();
                    if (rd.Read())
                    {
                        Label1.Text      = rd["UserName"].ToString();
                        TrueName.Text    = rd["TrueName"].ToString();
                        Email.Text       = rd["Email"].ToString();
                        OldPassword.Text = Password.Text = rd["Password"].ToString();
                        Image1.ImageUrl  = rd["Avatar"].ToString();
                        TelePhone.Text   = rd["TelePhone"].ToString();
                        string roleID = rd["RoleID"].ToString();
                        if (Role.Items.FindByValue(roleID) != null)
                        {
                            Role.ClearSelection();
                            Role.Items.FindByValue(roleID).Selected = true;
                        }
                        int valid = Convert.ToInt32(rd["Valid"]);
                        if (valid == 1)
                        {
                            true1.Checked = true;
                        }
                        else
                        {
                            false1.Checked = true;
                        }

                        Status.Text            = rd["Status"].ToString();
                        RegisterDateTime.Text  = rd["RegisterDateTime"].ToString();
                        LastLoginDateTime.Text = rd["LastLoginDateTime"].ToString();
                    }
                    rd.Close();


                    if (RoleID <= 1)
                    {
                        cmd.CommandText = "Select * from [Users] where ID = @UserID";
                        cmd.Parameters.AddWithValue("@UserID", LabelUserID.Text);
                        rd = cmd.ExecuteReader();
                        if (rd.Read())
                        {
                            Label1.Text      = rd["UserName"].ToString();
                            TrueName.Text    = rd["TrueName"].ToString();
                            Email.Text       = rd["Email"].ToString();
                            OldPassword.Text = Password.Text = rd["Password"].ToString();
                            Image1.ImageUrl  = rd["Avatar"].ToString();
                            TelePhone.Text   = rd["TelePhone"].ToString();
                            string roleID = rd["RoleID"].ToString();
                            if (Role.Items.FindByValue(roleID) != null)
                            {
                                Role.ClearSelection();
                                Role.Items.FindByValue(roleID).Selected = true;
                            }
                            int valid = Convert.ToInt32(rd["Valid"]);
                            if (valid == 1)
                            {
                                true1.Checked = true;
                            }
                            else
                            {
                                false1.Checked = true;
                            }

                            Status.Text            = rd["Status"].ToString();
                            RegisterDateTime.Text  = rd["RegisterDateTime"].ToString();
                            LastLoginDateTime.Text = rd["LastLoginDateTime"].ToString();
                        }
                        rd.Close();
                    }

                    if (RoleID <= 1)
                    {
                        cmd.CommandText = "Select * from [Users] where RandomID = @RandomID";
                        cmd.Parameters.AddWithValue("@RandomID", LabelRandomID.Text);
                        rd = cmd.ExecuteReader();
                        if (rd.Read())
                        {
                            Label1.Text      = rd["UserName"].ToString();
                            TrueName.Text    = rd["TrueName"].ToString();
                            Email.Text       = rd["Email"].ToString();
                            OldPassword.Text = Password.Text = rd["Password"].ToString();
                            Image1.ImageUrl  = rd["Avatar"].ToString();
                            TelePhone.Text   = rd["TelePhone"].ToString();
                            string roleID = rd["RoleID"].ToString();
                            if (Role.Items.FindByValue(roleID) != null)
                            {
                                Role.ClearSelection();
                                Role.Items.FindByValue(roleID).Selected = true;
                            }
                            int valid = Convert.ToInt32(rd["Valid"]);
                            if (valid == 1)
                            {
                                true1.Checked = true;
                            }
                            else
                            {
                                false1.Checked = true;
                            }

                            Status.Text            = rd["Status"].ToString();
                            RegisterDateTime.Text  = rd["RegisterDateTime"].ToString();
                            LastLoginDateTime.Text = rd["LastLoginDateTime"].ToString();
                        }
                        rd.Close();
                    }
                }
            }
        }
    }
Esempio n. 5
0
    // 修改文章函数
    private void MyInitForUpdate()
    {
        using (SqlConnection conn = new DB().GetConnection())
        {
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select * from Cats order by Orders desc";
            conn.Open();
            SqlDataReader rd = cmd.ExecuteReader();
            Cats.DataSource     = rd;
            Cats.DataValueField = "ID";
            Cats.DataTextField  = "CatName";
            Cats.DataBind();
            rd.Close();



            cmd.CommandText = "select * from UserTags order by ID asc";
            rd = cmd.ExecuteReader();
            UserTag.DataSource     = rd;
            UserTag.DataTextField  = "TagName";
            UserTag.DataValueField = "ID";
            UserTag.DataBind();
            rd.Close();


            int RoleID = Convert.ToInt16(Session["RoleID"].ToString());
            if (RoleID > 2)
            {
                cmd.Parameters.AddWithValue("@Status", 0); //状态:新投稿/待审核=0,审核已过=1,审核未过=2
            }
            else
            {
                cmd.Parameters.AddWithValue("@Status", 1); //状态:新投稿/待审核=0,审核已过=1,审核未过=2
            }

            cmd.CommandText = "select max(Orders) as orders from Articles";
            rd = cmd.ExecuteReader();
            if (rd.Read())
            {
                MaxOrders.Text = rd[0].ToString();
            }

            rd.Close();


            string SubID = "";
            cmd.CommandText = "select * from Articles where ID =" + IDLabel.Text;
            rd = cmd.ExecuteReader();
            if (rd.Read())
            {
                TitleTB.Text = rd["Title"].ToString();
                Summary.Text = rd["Summary"].ToString();

                string UserTagID = rd["TagID"].ToString();
                if (UserTag.Items.FindByValue(UserTagID) != null)
                {
                    UserTag.ClearSelection();
                    UserTag.Items.FindByValue(UserTagID).Selected = true;
                }

                string CatID = rd["CatID"].ToString();
                if (Cats.Items.FindByValue(CatID) != null)
                {
                    Cats.ClearSelection();
                    Cats.Items.FindByValue(CatID).Selected = true;
                }

                SubID               = rd["SubID"].ToString();
                CDT_TextBox.Text    = String.Format("{0:yyyy-MM-dd}", rd["CDT"]);
                Orders.Text         = rd["Orders"].ToString();
                Editor1.Text        = rd["Content"].ToString();
                CoverPhoto.ImageUrl = rd["CoverImageURL"].ToString();

                RandomID.Text = rd["RandomID"].ToString();
                RandomIDCD    = RandomID.Text;
                int PC1 = Convert.ToInt32(rd["PC"]);
                if (PC1 == 1)
                {
                    PC.Checked = true;
                }
                int Phone1 = Convert.ToInt32(rd["Phone"]);
                if (Phone1 == 1)
                {
                    Phone.Checked = true;
                }
                int Wechat1 = Convert.ToInt32(rd["Wechat"]);
                if (Wechat1 == 1)
                {
                    Wechat.Checked = true;
                }
                int iPad1 = Convert.ToInt32(rd["iPad"]);
                if (iPad1 == 1)
                {
                    iPad.Checked = true;
                }
                int APP1 = Convert.ToInt32(rd["APP"]);
                if (APP1 == 1)
                {
                    APP.Checked = true;
                }
                int TV1 = Convert.ToInt32(rd["TV"]);
                if (TV1 == 1)
                {
                    TV.Checked = true;
                }
            }
            rd.Close();



            cmd.CommandText = "select * from Subs where CatID = " + Cats.SelectedValue + " order by Orders desc";
            rd = cmd.ExecuteReader();
            Subs.DataSource     = rd;
            Subs.DataTextField  = "SubName";
            Subs.DataValueField = "ID";
            Subs.DataBind();
            rd.Close();


            if (Subs.Items.Count > 0)
            {
                Subs.Visible = true;
                if (Subs.Items.FindByValue(SubID) != null)
                {
                    Subs.ClearSelection();
                    Subs.Items.FindByValue(SubID).Selected = true;
                }
            }
            else
            {
                Subs.Visible = false;
            }
        }
    }