Example #1
0
    /// <summary>
    /// 重命名和删除
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void dt_VotePic_ItemCommand(object source, DataListCommandEventArgs e)
    {
        string cmd = e.CommandName;

        if (cmd == "UP")
        {
            //获取图片的编号
            int Vote_Id = Convert.ToInt32(e.CommandArgument);
            Tunnel.BLL.Vote_Info   voteInfoBLL   = new Tunnel.BLL.Vote_Info();
            Tunnel.Model.Vote_Info voteInfoModel = voteInfoBLL.GetModel(Vote_Id);
            //修改图片的标题
            TextBox tb = (TextBox)e.Item.FindControl("txtName");
            voteInfoModel.v_title = tb.Text.ToString();
            voteInfoBLL.Update(voteInfoModel);
            ClientScript.RegisterStartupScript(GetType(), "确定", "<script>alert('更新成功!');</script>");
            DataLoad(24, 1);
        }
        else if (cmd == "DEL")
        {
            //获取图片的编号
            int    id     = Convert.ToInt32(e.CommandArgument);
            Button btnDel = (Button)e.Item.FindControl("btn_DeleteVote");
            btnDel.Attributes.Add("OnClientClick", "javascript:return confirm('确认要删除此项投票吗?');");
            Tunnel.BLL.Vote_Info voteInfoBLL = new Tunnel.BLL.Vote_Info();
            voteInfoBLL.Delete(id);

            Tunnel.BLL.VoteLog voteLogBLL = new Tunnel.BLL.VoteLog();
            //删除该投票选项的投票记录
            voteLogBLL.DeleteByVote_ID(id);
            //重新绑定页面
            DataLoad(24, 1);
            ClientScript.RegisterStartupScript(GetType(), "确定", "<script>alert('删除图片成功!');</script>");
        }
    }
Example #2
0
    /// <summary>
    /// 投票事件
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        string cmd = e.CommandName;

        if (cmd == "Ed")
        {
            int id = Convert.ToInt32(e.CommandArgument);

            Tunnel.BLL.UserLogin ul = new Tunnel.BLL.UserLogin();
            int UID = Convert.ToInt32(ul.LoginID);

            Tunnel.Model.VoteLog voteLog    = new Tunnel.Model.VoteLog();
            Tunnel.BLL.VoteLog   voteLogBll = new Tunnel.BLL.VoteLog();

            IList <Tunnel.Model.VoteLog> list_VoteLog = new List <Tunnel.Model.VoteLog>();

            list_VoteLog = (new Tunnel.BLL.VoteLog()).GetModelList("vg_userId=" + UID + " and vg_voteId=" + id);

            //获取投票记录项
            if (list_VoteLog.Count > 0)
            {
                voteLog = list_VoteLog[list_VoteLog.Count - 1];
            }

            switch (VoteType)
            {
            case "1":
                #region 每人一天可以投一次
                if (list_VoteLog.Count == 0)
                {
                    //添加一条投票记录
                    voteLogModel.vg_setDate = DateTime.Now;
                    voteLogModel.vg_userId  = UID;
                    voteLogModel.vg_voteId  = id;
                    voteLogBll.Add(voteLogModel);

                    String Update_VoteCount = string.Format("update Vote_Info set v_count =v_count+1 where v_id={0} ", id);
                    String Add_Date_Sys     = String.Format("insert into  Date_Sys values('{0}','{1}','{2}','{3}')", UID, DateTime.Now, DateTime.Now, null);

                    //更新票数,对票数进行加1
                    int result = Tunnel.Data.DbHelperSQL.ExecuteSql(Update_VoteCount);
                    //第一次投票
                    int Result = Tunnel.Data.DbHelperSQL.ExecuteSql(Add_Date_Sys);

                    Label lb      = (Label)e.Item.FindControl("lblCount");
                    int   v_count = Convert.ToInt32(lb.Text.ToString());
                    v_count++;
                    lb.Text = v_count.ToString();

                    ClientScript.RegisterStartupScript(GetType(), "确定", "<script>alert('投票成功!');</script>");
                }
                else if (voteLog.vg_setDate.Date != DateTime.Now.Date)
                {
                    //添加一条投票记录
                    voteLogModel.vg_setDate = DateTime.Now;
                    voteLogModel.vg_userId  = UID;
                    voteLogModel.vg_voteId  = id;
                    voteLogBll.Add(voteLogModel);
                    String Update_VoteCount = string.Format("update Vote_Info set v_count =v_count+1 where v_id={0} ", id);
                    String Update_VoteLog   = string.Format("update VoteLog  set vg_setDate ='{0}' where vg_id='{1}' and vg_userId='{2}'", DateTime.Now, id, UID);
                    String Update_VoteDate  = string.Format("update Date_Sys set d_endPoll_Date='{0}'where d_userId={1} ", DateTime.Now, UID);
                    //更新票数,对票数进行加1
                    int result = Tunnel.Data.DbHelperSQL.ExecuteSql(Update_VoteCount);
                    //更新投票的时间,最后一次投票的时间
                    int   count   = Tunnel.Data.DbHelperSQL.ExecuteSql(Update_VoteDate);
                    int   record  = Tunnel.Data.DbHelperSQL.ExecuteSql(Update_VoteLog);
                    Label lb      = (Label)e.Item.FindControl("lblCount");
                    int   v_count = Convert.ToInt32(lb.Text.ToString());
                    v_count++;
                    lb.Text = v_count.ToString();

                    ClientScript.RegisterStartupScript(GetType(), "确定", "<script>alert('投票成功!');</script>");
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "确定", "<script>alert('每张图片,一天可以投一次!');</script>");
                }

                #endregion
                break;

            case "0":
                #region   限定每人只能投一次票

                if (list_VoteLog.Count == 0)
                {
                    //添加一条投票记录
                    voteLogModel.vg_setDate = DateTime.Now;
                    voteLogModel.vg_userId  = UID;
                    voteLogModel.vg_voteId  = id;
                    voteLogBll.Add(voteLogModel);

                    String Update_VoteCount = string.Format("update Vote_Info set v_count =v_count+1 where v_id={0} ", id);
                    String Add_Date_Sys     = String.Format("insert into  Date_Sys values('{0}','{1}','{2}','{3}')", UID, DateTime.Now, DateTime.Now, null);

                    //更新票数,对票数进行加1
                    int result = Tunnel.Data.DbHelperSQL.ExecuteSql(Update_VoteCount);
                    //第一次投票
                    int   Result  = Tunnel.Data.DbHelperSQL.ExecuteSql(Add_Date_Sys);
                    Label lb      = (Label)e.Item.FindControl("lblCount");
                    int   v_count = Convert.ToInt32(lb.Text.ToString());
                    v_count++;
                    lb.Text = v_count.ToString();
                }
                else
                {
                    Tunnel.Common.Message.Show("每人每张只能投一次票");
                }

                #endregion
                break;
            }
        }
    }