Exemplo n.º 1
0
    protected void MyInitForUpdate()
    {
        using (SqlConnection conn = new DB().GetConnection())
        {
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select * from UserTags where classify=0 order by ID asc";
            conn.Open();
            SqlDataReader rd = cmd.ExecuteReader();
            UserTag.DataSource     = rd;
            UserTag.DataTextField  = "TagName";
            UserTag.DataValueField = "ID";
            UserTag.DataBind();
            rd.Close();


            cmd.CommandText = "Select * from Articles where RandomID = '" + RandomID.Text + "'";
            rd = cmd.ExecuteReader();
            if (rd.Read())
            {
                IDLabel.Text        = rd["ID"].ToString();
                Title.Text          = rd["Title"].ToString();
                CoverPhoto.ImageUrl = rd["CoverImageURL"].ToString();
                Orders.Text         = rd["Orders"].ToString();
                UserName.Text       = rd["Author"].ToString();
            }
            rd.Close();
        }
    }
Exemplo n.º 2
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();
        }
    }
Exemplo n.º 3
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;
            }
        }
    }