⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pollmanage.aspx.cs

📁 ASP.NET多线程编程(二),ASP.NET多线程编程(二) .
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 Zeroone.Polls;
using Zeroone.FileSystem;

public partial class Admin_Poll_PollManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string action = Request.QueryString["action"] == null ? "create" : Request.QueryString["action"];
            string path = Request.QueryString["path"];
            string pollName = Request.QueryString["pollName"];
            
            //投票分类
            ddlPllCategoies.DataSource = CategoryController.GetChildCategories("/zeroone-polls/");
            ddlPllCategoies.DataBind();
            ListItem item = new ListItem("不分类", "/zeroone-polls/");
            ddlPllCategoies.Items.Insert(0, item);

            if (action.ToLower() == "update")
            {
                Poll poll = new Poll(path, pollName);
                this.tbName.Text = poll.Name;
                this.tbQuestion.Text = poll.Subject;
                this.cbAllowMultiple.Checked = poll.AllowMultipleVotes;
                ddlPllCategoies.SelectedValue = poll.Path;

                this.rptPollChoices.DataSource = poll.GetPollItems();
                this.rptPollChoices.DataBind();

                this.btnUpdate.Visible = true;
                this.btnCreate.Visible = false;
                lbtnDelete.Visible = true;
            }
            else if (action.ToLower() == "delete")
            {
                Poll poll = new Poll(path, pollName);
                poll.Delete();

                Response.Redirect("polls.aspx");
            }

            this.rptEmptyChoices.DataSource = new int[] { 1, 2, 3, 4, 5 };
            this.rptEmptyChoices.DataBind();
        }
    }
    protected void lbtnDelete_Click(object sender, EventArgs e)
    {
        string path = Request.QueryString["path"];
        string pollName = Request.QueryString["pollName"];

        Poll poll = new Poll(path, pollName);
        poll.Delete();

        Response.Redirect("polls.aspx");
    }
    protected void btnCreate_Click(object sender, EventArgs e)
    {
        Poll p = new Poll();
        p.Path = ddlPllCategoies.SelectedValue;
        p.Subject = tbQuestion.Text;
        p.Name = tbName.Text;
        p.AllowMultipleVotes = cbAllowMultiple.Checked;
        p.Create();

        //增加新的投票选项
        RepeaterItemCollection ric = rptEmptyChoices.Items;
        foreach (RepeaterItem ri in ric)
        {
            if ((ri.ItemType == ListItemType.AlternatingItem) || (ri.ItemType == ListItemType.Item))
            {
                TextBox tbChoice = (TextBox)ri.FindControl("tbChoice");
                if (!string.IsNullOrEmpty(tbChoice.Text))
                {
                    p.CreatePollItem(tbChoice.Text);
                }
            }
        }

        //重新邦定
        Response.Redirect("polls.aspx");
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("polls.aspx");
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        string path = Request.QueryString["path"];
        string pollName = Request.QueryString["pollName"];

        Poll poll = new Poll(path, pollName);
        poll.Subject = tbQuestion.Text;
        poll.Name = tbName.Text;
        poll.Path = ddlPllCategoies.SelectedValue;
        poll.AllowMultipleVotes = cbAllowMultiple.Checked;
        poll.Update();

        //更新投票选项        
        foreach (RepeaterItem ri in this.rptPollChoices.Items)
        {
            if ((ri.ItemType == ListItemType.AlternatingItem) || (ri.ItemType == ListItemType.Item))
            {
                TextBox tbChoice = (TextBox)ri.FindControl("tbChoice");
                TextBox tbPollValue = (TextBox)ri.FindControl("tbPollValue");
                HiddenField hfItemID = (HiddenField)ri.FindControl("hfItemID");

                if (string.IsNullOrEmpty(tbChoice.Text))
                {
                    poll.DeletePollItem(int.Parse(hfItemID.Value));
                }
                else
                {
                    foreach (PollItem pi in poll.GetPollItems())
                    {
                        if (pi.PollItemID == int.Parse(hfItemID.Value))
                        {
                            pi.Title = tbChoice.Text;
                            pi.Value = int.Parse(tbPollValue.Text);
                            poll.UpdatePollItem(pi);

                            break;
                        }
                    }
                }
            }
        }
        
        //增加新的投票选项
        RepeaterItemCollection ric = rptEmptyChoices.Items;
        foreach (RepeaterItem ri in ric)
        {
            if ((ri.ItemType == ListItemType.AlternatingItem) || (ri.ItemType == ListItemType.Item))
            {
                TextBox tbChoice = (TextBox)ri.FindControl("tbChoice");
                if (!string.IsNullOrEmpty(tbChoice.Text))
                {
                    poll.CreatePollItem(tbChoice.Text);
                }
            }
        }

        //重新邦定
        Response.Redirect("polls.aspx");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -