示例#1
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <Tunnel.Model.VoteLog> DataTableToList(DataTable dt)
        {
            List <Tunnel.Model.VoteLog> modelList = new List <Tunnel.Model.VoteLog>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                Tunnel.Model.VoteLog model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Tunnel.Model.VoteLog();
                    if (dt.Rows[n]["vg_id"].ToString() != "")
                    {
                        model.vg_id = int.Parse(dt.Rows[n]["vg_id"].ToString());
                    }
                    if (dt.Rows[n]["vg_setDate"].ToString() != "")
                    {
                        model.vg_setDate = DateTime.Parse(dt.Rows[n]["vg_setDate"].ToString());
                    }
                    if (dt.Rows[n]["vg_userId"].ToString() != "")
                    {
                        model.vg_userId = int.Parse(dt.Rows[n]["vg_userId"].ToString());
                    }
                    if (dt.Rows[n]["vg_voteId"].ToString() != "")
                    {
                        model.vg_voteId = int.Parse(dt.Rows[n]["vg_voteId"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return(modelList);
        }
示例#2
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public void Update(Tunnel.Model.VoteLog model)
 {
     dal.Update(model);
 }
示例#3
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public void Add(Tunnel.Model.VoteLog model)
 {
     dal.Add(model);
 }
示例#4
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;
            }
        }
    }