Пример #1
0
    private void MyInit()
    {
        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();
            CatsDDL.DataSource     = rd;
            CatsDDL.DataValueField = "ID";
            CatsDDL.DataTextField  = "CatName";
            CatsDDL.DataBind();
            rd.Close();
            CatsDDL.Items.Insert(0, new ListItem("所有分类", "-1"));
            SubsDDL.Items.Insert(0, new ListItem("二级分类", "-1"));

            //if (CatsDDL.Items.Count > 1)
            //{
            //    CatsDDL.SelectedIndex = 1;
            //}

            cmd.CommandText = "select * from Subs where CatID = @CatID order by Orders desc;";
            cmd.Parameters.AddWithValue("@CatID", CatsDDL.SelectedValue);
            rd = cmd.ExecuteReader();
            SubsDDL.DataSource     = rd;
            SubsDDL.DataValueField = "ID";
            SubsDDL.DataTextField  = "SubName";
            SubsDDL.DataBind();
            rd.Close();
            SubsDDL.Items.Insert(0, new ListItem("二级分类", "-1"));

            // RoleID=1,2,3,4,分别对应Administrator,Editor,Contributor,Author
            int RoleID = Convert.ToInt16(Session["RoleID"].ToString());
            if (RoleID == 1 || RoleID == 2)
            {
                // 只有Administrator和Editor才可以看到所有作者的文章
                AuthorDDL.Items.Clear();
                cmd.CommandText = "select * from Users order by ID desc";
                rd = cmd.ExecuteReader();
                AuthorDDL.DataSource     = rd;
                AuthorDDL.DataValueField = "ID";
                AuthorDDL.DataTextField  = "UserName";
                AuthorDDL.DataBind();
                rd.Close();
                AuthorDDL.Items.Insert(0, new ListItem("所有用户", "-1"));
            }
            else
            {
                // Contributor和Author只能看到自己的文章
                AuthorDDL.Items.Clear();
                AuthorDDL.Items.Insert(0, new ListItem(Session["UserName"].ToString(), Session["UserID"].ToString()));
            }
        }
    }
Пример #2
0
    private void MyInit()
    {
        using (SqlConnection conn = new DB().GetConnection())
        {
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select distinct typename as typename from ResourceTypes";
            conn.Open();
            SqlDataReader rd = cmd.ExecuteReader();
            ResourceTypeDDL.DataSource     = rd;
            ResourceTypeDDL.DataValueField = "typename";
            ResourceTypeDDL.DataTextField  = "typename";
            ResourceTypeDDL.DataBind();
            rd.Close();
            ResourceTypeDDL.Items.Insert(0, new ListItem("所有资源类型", ""));

            cmd.CommandText = "Select * from ResourceFolders where ParentFolderID = '0' order by ID asc";
            rd = cmd.ExecuteReader();
            FolderDDL.DataSource     = rd;
            FolderDDL.DataValueField = "ID";
            FolderDDL.DataTextField  = "FolderName";
            FolderDDL.DataBind();
            rd.Close();
            FolderDDL.Items.Insert(0, new ListItem("所有文件夹", "-1"));

            // RoleID=1,2,3,4,分别对应Administrator,Editor,Contributor,Author
            int RoleID = Convert.ToInt16(Session["RoleID"].ToString());
            if (RoleID == 1 || RoleID == 2)
            {
                // 只有Administrator和Editor才可以看到所有作者的文章
                AuthorDDL.Items.Clear();
                cmd.CommandText = "select * from Users order by ID desc";
                rd = cmd.ExecuteReader();
                AuthorDDL.DataSource     = rd;
                AuthorDDL.DataValueField = "ID";
                AuthorDDL.DataTextField  = "UserName";
                AuthorDDL.DataBind();
                rd.Close();
                AuthorDDL.Items.Insert(0, new ListItem("所有用户", "-1"));
            }
            else
            {
                // Contributor和Author只能看到自己的文章
                AuthorDDL.Items.Clear();
                AuthorDDL.Items.Insert(0, new ListItem(Session["UserName"].ToString(), Session["UserID"].ToString()));
            }
        }
    }
Пример #3
0
    private void MyInit()
    {
        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();
            CatsDDL.DataSource     = rd;
            CatsDDL.DataValueField = "ID";
            CatsDDL.DataTextField  = "CatName";
            CatsDDL.DataBind();
            rd.Close();
            CatsDDL.Items.Insert(0, new ListItem("所有分类", "-1"));
            SubsDDL.Items.Insert(0, new ListItem("二级分类", "-1"));

            if (CatsDDL.Items.Count > 1)
            {
                CatsDDL.SelectedIndex = 1;
            }

            cmd.CommandText = "select * from Subs where CatID = " + CatsDDL.SelectedValue + " order by Orders desc;";
            rd = cmd.ExecuteReader();
            SubsDDL.DataSource     = rd;
            SubsDDL.DataValueField = "ID";
            SubsDDL.DataTextField  = "SubName";
            SubsDDL.DataBind();
            rd.Close();
            SubsDDL.Items.Insert(0, new ListItem("二级分类", "-1"));


            int RoleID = Convert.ToInt16(Session["RoleID"].ToString());
            AuthorDDL.Items.Clear();
            cmd.CommandText = "select * from Users order by ID desc";
            rd = cmd.ExecuteReader();
            AuthorDDL.DataSource     = rd;
            AuthorDDL.DataValueField = "ID";
            AuthorDDL.DataTextField  = "UserName";
            AuthorDDL.DataBind();
            rd.Close();
            AuthorDDL.Items.Insert(0, new ListItem("所有用户", "-1"));
        }
    }