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

📄 vote.aspx.cs

📁 小E单班同学录系统
💻 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 LeeHom.Web.Data;
public partial class Admin_Vote : MyPage
{
    public static string strTitle = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        WebFunction.AdminLogin();
        switch (Request.QueryString["OP"])
        {
            case "Del":
                dbh.Reset();
                dbh.tableName = "Vote";
                dbh.conditionExpress = "ID=@ID";
                dbh.AddConditionParameters("ID", Request.QueryString["ID"]);
                if (dbh.DataDelete() > -1)
                {
                    dbh.Reset();
                    dbh.tableName = "VoteCon";
                    dbh.conditionExpress = "ID=@ID";
                    dbh.AddConditionParameters("VID", Request.QueryString["ID"]);
                    dbh.DataDelete();
                    VoteShow();
                }
                else
                {
                    VoteShow();
                    Alert(this.ltlMessage, "删除失败!请检查系统日志!");
                }
                break;
            case "DelChild":
                dbh.Reset();
                dbh.sqlCommand = "select Coun,VID from VoteCon where ID=@ID";
                dbh.AddSqlCmdParameters("ID", Request.QueryString["CID"]);
                dbh.GetDataReader();
                if (dbh.dr.Read())
                {
                    int voteCount = (int)dbh.dr[0];
                    string voteID = dbh.dr[1].ToString();
                    dbh.Reset();
                    dbh.tableName = "VoteCon";
                    dbh.conditionExpress = "ID=@ID";
                    dbh.AddConditionParameters("ID", Request.QueryString["CID"]);
                    if (dbh.DataDelete() > -1)
                    {
                        dbh.Reset();
                        dbh.tableName = "Vote";
                        dbh.fieldName = "Coun";
                        dbh.conditionExpress = "ID=@ID";
                        dbh.AddConditionParameters("ID", voteID);
                        dbh.CountChange(-voteCount);
                        VoteModify();
                    }
                    else
                    {
                        VoteModify();
                        Alert(this.ltlMessage, "删除失败!请检查系统日志!");
                    }
                }
                else
                {
                    VoteModify();
                }
                break;
            case "Modify":
                VoteModify();
                break;
            case "ModifyChild":
                VoteChildEdit();
                break;
            case "ChildAdd":
                ChildAdd();
                break;
            case "FatherAdd":
                this.divFather.Visible = true;
                this.divModify.Visible = false;
                this.divShow.Visible = false;
                this.divChild.Visible = false;
                break;
            default:
                if (!IsPostBack)
                {
                    VoteShow();
                }
                break;
        }
    }

    void VoteShow()
    {
        this.divFather.Visible = false;
        this.divModify.Visible = false;
        this.divShow.Visible = true;
        this.divChild.Visible = false;

        dbh.Reset();
        dbh.sqlCommand="select * from Vote order by ID desc";
        BinderRepeater br = new BinderRepeater();
        br.repeater = rptVote;
        br.datatable=dbh.GetDataTable();
        br.Bind();
    }

    void VoteModify()
    {
        this.divModify.Visible = true;
        this.divShow.Visible = false;
        this.divChild.Visible = false;

        dbh.Reset();
        dbh.sqlCommand = "select Vote.Title,Vote.Member,VoteCon.* from Vote,VoteCon where VoteCon.VID=@VID and Vote.ID=VoteCon.VID order by VoteCon.ID";
        dbh.AddSqlCmdParameters("VID", Request.QueryString["ID"]);
        BinderRepeater br = new BinderRepeater();
        br.repeater = rptVoteC;
        br.datatable = dbh.GetDataTable();
        br.Bind();
    }

    static int cotemp = 0;

    void VoteChildEdit()
    {
        if (!IsPostBack)
        {
            this.divModify.Visible = false;
            this.divShow.Visible = false;
            this.divChild.Visible = true;

            dbh.Reset();
            dbh.sqlCommand = "select Vote.Title,Vote.Member,VoteCon.* from Vote,VoteCon where VoteCon.VID=@VID and Vote.ID=VoteCon.VID order by VoteCon.ID";
            dbh.AddSqlCmdParameters("VID", Request.QueryString["ID"]);
            dbh.GetDataReader();
            if (dbh.dr.Read())
            {
                this.txtCont.Text = dbh.dr["Cont"].ToString();
                this.txtCoun.Text = dbh.dr["Coun"].ToString();
                strTitle = dbh.dr["Title"].ToString();
                cotemp = (int)dbh.dr["Coun"];
            }
        }
    }

    protected void btnSub_Click(object sender, EventArgs e)
    {
        dbh.Reset();
        dbh.tableName = "VoteCon";
        dbh.AddFieldParameters("Coun", this.txtCoun.Text);
        dbh.AddFieldParameters("Cont", this.txtCont.Text);
        dbh.conditionExpress = "ID=@ID";
        dbh.AddConditionParameters("ID", Request.QueryString["CID"]);
        if (dbh.DataUpdate()>-1)
        {
            int temp;
            temp = Convert.ToInt32(this.txtCoun.Text) - cotemp;
            dbh.Reset();
            dbh.tableName = "Vote";
            dbh.fieldName = "Coun";
            dbh.conditionExpress = "ID=@ID";
            dbh.AddConditionParameters("ID", Request.QueryString["ID"]);
            dbh.CountChange(temp);
            VoteModify();
            Alert(this.ltlMessage,"修改成功!");
        }
    }


    protected void chkMember_CheckedChanged(object sender, EventArgs e)
    {
        for (int i = 0; i < rptVote.Items.Count; i++)
        {
            CheckBox cb = (CheckBox)rptVote.Items[i].FindControl("chkMember");
            Label ltl = (Label)rptVote.Items[i].FindControl("ltlID");
            dbh.Reset();
            dbh.tableName = "Vote";
            int c = 0;
            if (cb.Checked) c = 1;
            dbh.AddFieldParameters("Member", c);
            dbh.conditionExpress = "ID=@ID";
            dbh.AddConditionParameters("ID", ltl.Text);
            dbh.DataUpdate();
        }
        Alert(this.ltlMessage, "修改成功!");
    }

    void ChildAdd()
    {
        dbh.Reset();
        dbh.tableName = "Vote";
        dbh.AddConditionParameters("ID", Request.QueryString["ID"]);
        if (!dbh.DataExists())
        {
            Alert("对不起!数据不存在!", "Vote.aspx");
            return;
        }
        this.divChildAdd.Visible = true;
        VoteModify();
    }

    protected void btnNewCon_Click(object sender, EventArgs e)
    {
        dbh.Reset();
        dbh.tableName = "VoteCon";
        dbh.AddFieldParameters("Cont", LeeHom.Web.Text.HtmlEncode(this.txtNewCon.Text));
        dbh.AddFieldParameters("VID", Request.QueryString["ID"]);

        if (dbh.DataInsert())
        {
            this.txtNewCon.Text = "";
            VoteModify();
        }
        else
        {
            Alert(this.ltlMessage,"添加失败!请检查错误日志!");
        }
    }
    protected void btnNewT_Click(object sender, EventArgs e)
    {
        dbh.Reset();
        dbh.tableName = "Vote";
        dbh.AddFieldParameters("Title", LeeHom.Web.Text.HtmlEncode(this.txtNewT.Text));
        dbh.AddFieldParameters("Member", this.cbNewMember.Checked.ToString().Replace("True", "1").Replace("False", "0"));
        if (dbh.DataInsert())
        {
            VoteShow();
        }
        else
        {
            Alert(this.ltlMessage,"添加失败!请检查错误日志!");
        }
    }
}

⌨️ 快捷键说明

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