Example #1
0
 void BindVoteItem(VoteInfo vote)
 {
     int num = 0;
     if (vote != null)
     {
         this.lblVoteName.Text = vote.VoteName;
         IList<VoteItemInfo> voteItems = CommentBrowser.GetVoteItems(this.voteId);
         for (int i = 0; i < voteItems.Count; i++)
         {
             if (vote.VoteCounts != 0)
             {
                 voteItems[i].Percentage = (voteItems[i].ItemCount / vote.VoteCounts) * 100M;
                 num += voteItems[i].ItemCount;
             }
             else
             {
                 voteItems[i].Percentage = 0M;
             }
         }
         this.rptVoteItem.DataSource = voteItems;
         this.rptVoteItem.DataBind();
         if (this.lblTotal != null)
         {
             this.lblTotal.Text = num.ToString();
         }
     }
 }
Example #2
0
 public static int CreateVote(VoteInfo vote)
 {
     int num = 0;
     VoteDao dao = new VoteDao();
     long num2 = dao.CreateVote(vote);
     if (num2 > 0L)
     {
         ReplyInfo reply = new TextReplyInfo {
             Keys = vote.Keys,
             MatchType = MatchType.Equal,
             ReplyType = ReplyType.Vote,
             ActivityId = Convert.ToInt32(num2)
         };
         new ReplyDao().SaveReply(reply);
         num = 1;
         if (vote.VoteItems == null)
         {
             return num;
         }
         foreach (VoteItemInfo info2 in vote.VoteItems)
         {
             info2.VoteId = num2;
             info2.ItemCount = 0;
             num += dao.CreateVoteItem(info2, null);
         }
     }
     return num;
 }
Example #3
0
 private void btnEditVote_Click(object sender, EventArgs e)
 {
     if (SubsiteStoreHelper.GetVoteCounts(voteId) > 0)
     {
         ShowMsg("投票已经开始,不能再对投票选项进行任何操作", false);
     }
     else
     {
         int num;
         VoteInfo vote = new VoteInfo();
         vote.VoteName = Globals.HtmlEncode(txtAddVoteName.Text.Trim());
         vote.VoteId = voteId;
         vote.IsBackup = checkIsBackup.Checked;
         if (int.TryParse(txtMaxCheck.Text.Trim(), out num))
         {
             vote.MaxCheck = num;
         }
         else
         {
             vote.MaxCheck = -2147483648;
         }
         IList<VoteItemInfo> list = null;
         if (!string.IsNullOrEmpty(txtValues.Text.Trim()))
         {
             list = new List<VoteItemInfo>();
             string[] strArray = txtValues.Text.Trim().Replace("\r\n", "\n").Replace("\n", "*").Split(new char[] { '*' });
             for (int i = 0; i < strArray.Length; i++)
             {
                 VoteItemInfo item = new VoteItemInfo();
                 if (strArray[i].Length > 60)
                 {
                     ShowMsg("投票选项长度限制在60个字符以内", false);
                     return;
                 }
                 item.VoteItemName = Globals.HtmlEncode(strArray[i]);
                 list.Add(item);
             }
         }
         else
         {
             ShowMsg("投票选项不能为空", false);
             return;
         }
         vote.VoteItems = list;
         if (ValidationVote(vote))
         {
             if (SubsiteStoreHelper.UpdateVote(vote))
             {
                 ShowMsg("修改投票成功", true);
             }
             else
             {
                 ShowMsg("修改投票失败", false);
             }
         }
     }
 }
Example #4
0
 private bool ValidationVote(VoteInfo vote)
 {
     ValidationResults results = Hishop.Components.Validation.Validation.Validate<VoteInfo>(vote, new string[] { "ValVote" });
     string msg = string.Empty;
     if (!results.IsValid)
     {
         foreach (ValidationResult result in (IEnumerable<ValidationResult>)results)
         {
             msg = msg + Formatter.FormatErrorMessage(result.Message);
         }
         ShowMsg(msg, false);
     }
     return results.IsValid;
 }
Example #5
0
 public override long CreateVote(VoteInfo vote)
 {
     DbCommand storedProcCommand = database.GetStoredProcCommand("cp_Votes_Create");
     database.AddInParameter(storedProcCommand, "VoteName", DbType.String, vote.VoteName);
     database.AddInParameter(storedProcCommand, "IsBackup", DbType.Boolean, vote.IsBackup);
     database.AddInParameter(storedProcCommand, "MaxCheck", DbType.Int32, vote.MaxCheck);
     database.AddOutParameter(storedProcCommand, "VoteId", DbType.Int64, 8);
     long parameterValue = 0;
     if (database.ExecuteNonQuery(storedProcCommand) > 0)
     {
         parameterValue = (long)database.GetParameterValue(storedProcCommand, "VoteId");
     }
     return parameterValue;
 }
Example #6
0
 public long CreateVote(VoteInfo vote)
 {
     DbCommand storedProcCommand = this.database.GetStoredProcCommand("cp_Votes_Create");
     this.database.AddInParameter(storedProcCommand, "VoteName", DbType.String, vote.VoteName);
     this.database.AddInParameter(storedProcCommand, "IsBackup", DbType.Boolean, vote.IsBackup);
     this.database.AddInParameter(storedProcCommand, "MaxCheck", DbType.Int32, vote.MaxCheck);
     this.database.AddInParameter(storedProcCommand, "ImageUrl", DbType.String, vote.ImageUrl);
     this.database.AddInParameter(storedProcCommand, "StartDate", DbType.DateTime, vote.StartDate);
     this.database.AddInParameter(storedProcCommand, "EndDate", DbType.DateTime, vote.EndDate);
     this.database.AddInParameter(storedProcCommand, "Keys", DbType.String, vote.Keys);
     this.database.AddOutParameter(storedProcCommand, "VoteId", DbType.Int64, 8);
     long parameterValue = 0L;
     if (this.database.ExecuteNonQuery(storedProcCommand) > 0)
     {
         parameterValue = (long) this.database.GetParameterValue(storedProcCommand, "VoteId");
     }
     return parameterValue;
 }
Example #7
0
 public static int CreateVote(VoteInfo vote)
 {
     int num = 0;
     long num2 = StoreProvider.Instance().CreateVote(vote);
     if (num2 > 0)
     {
         num = 1;
         if (vote.VoteItems == null)
         {
             return num;
         }
         foreach (VoteItemInfo info in vote.VoteItems)
         {
             info.VoteId = num2;
             info.ItemCount = 0;
             num += StoreProvider.Instance().CreateVoteItem(info, null);
         }
     }
     return num;
 }
Example #8
0
 public bool UpdateVote(VoteInfo vote, DbTransaction dbTran)
 {
     DbCommand sqlStringCommand = this.database.GetSqlStringCommand("UPDATE Hishop_Votes SET VoteName = @VoteName, MaxCheck = @MaxCheck, ImageUrl=@ImageUrl, StartDate=@StartDate, EndDate=@EndDate WHERE VoteId = @VoteId; UPDATE vshop_Reply SET Keys = @Keys WHERE ActivityId = @VoteId AND [ReplyType] = @ReplyType");
     this.database.AddInParameter(sqlStringCommand, "VoteName", DbType.String, vote.VoteName);
     this.database.AddInParameter(sqlStringCommand, "MaxCheck", DbType.Int32, vote.MaxCheck);
     this.database.AddInParameter(sqlStringCommand, "ImageUrl", DbType.String, vote.ImageUrl);
     this.database.AddInParameter(sqlStringCommand, "StartDate", DbType.DateTime, vote.StartDate);
     this.database.AddInParameter(sqlStringCommand, "EndDate", DbType.DateTime, vote.EndDate);
     this.database.AddInParameter(sqlStringCommand, "Keys", DbType.String, vote.Keys);
     this.database.AddInParameter(sqlStringCommand, "ReplyType", DbType.Int32, 0x80);
     this.database.AddInParameter(sqlStringCommand, "VoteId", DbType.Int64, vote.VoteId);
     return (this.database.ExecuteNonQuery(sqlStringCommand, dbTran) > 0);
 }
Example #9
0
 public static VoteInfo PopulateVote(IDataRecord reader)
 {
     VoteInfo info = new VoteInfo {
         VoteId = (long) reader["VoteId"],
         VoteName = (string) reader["VoteName"],
         IsBackup = (bool) reader["IsBackup"],
         MaxCheck = (int) reader["MaxCheck"]
     };
     if (reader["ImageUrl"] != DBNull.Value)
     {
         info.ImageUrl = (string) reader["ImageUrl"];
     }
     info.StartDate = (DateTime) reader["StartDate"];
     info.EndDate = (DateTime) reader["EndDate"];
     info.VoteCounts = (int) reader["VoteCounts"];
     if (reader["Keys"] != DBNull.Value)
     {
         info.Keys = (string) reader["Keys"];
     }
     return info;
 }
Example #10
0
 public static bool UpdateVote(VoteInfo vote)
 {
     bool flag;
     using (DbConnection connection = DatabaseFactory.CreateDatabase().CreateConnection())
     {
         connection.Open();
         DbTransaction dbTran = connection.BeginTransaction();
         try
         {
             if (!StoreProvider.Instance().UpdateVote(vote, dbTran))
             {
                 dbTran.Rollback();
                 return false;
             }
             if (!StoreProvider.Instance().DeleteVoteItem(vote.VoteId, dbTran))
             {
                 dbTran.Rollback();
                 return false;
             }
             int num = 0;
             if (vote.VoteItems != null)
             {
                 foreach (VoteItemInfo info in vote.VoteItems)
                 {
                     info.VoteId = vote.VoteId;
                     info.ItemCount = 0;
                     num += StoreProvider.Instance().CreateVoteItem(info, dbTran);
                 }
                 if (num < vote.VoteItems.Count)
                 {
                     dbTran.Rollback();
                     return false;
                 }
             }
             dbTran.Commit();
             flag = true;
         }
         catch
         {
             dbTran.Rollback();
             flag = false;
         }
         finally
         {
             connection.Close();
         }
     }
     return flag;
 }
Example #11
0
 public abstract bool UpdateVote(VoteInfo vote, DbTransaction dbTran);
Example #12
0
 public abstract long CreateVote(VoteInfo vote);
Example #13
0
 public static VoteInfo PopulateVote(IDataRecord reader)
 {
     VoteInfo info = new VoteInfo();
     info.VoteId = (long) reader["VoteId"];
     info.VoteName = (string) reader["VoteName"];
     info.IsBackup = (bool) reader["IsBackup"];
     info.MaxCheck = (int) reader["MaxCheck"];
     info.VoteCounts = (int) reader["VoteCounts"];
     return info;
 }
Example #14
0
 void Vote(VoteInfo vote)
 {
     HttpCookie cookie = HiContext.Current.Context.Request.Cookies[this.voteId.ToString()];
     if (cookie == null)
     {
         if (this.Page.Request.Params["VoteItemId"] != null)
         {
             string str = this.Page.Request.Params["VoteItemId"];
             if (!string.IsNullOrEmpty(str))
             {
                 string[] strArray = str.Split(new char[] { ',' });
                 for (int i = 0; i < strArray.Length; i++)
                 {
                     if (!string.IsNullOrEmpty(strArray[i]) && ((i + 1) <= vote.MaxCheck))
                     {
                         long voteItemId = Convert.ToInt64(strArray[i]);
                         VoteItemInfo voteItemById = CommentBrowser.GetVoteItemById(voteItemId);
                         if (vote.VoteId == voteItemById.VoteId)
                         {
                             CommentBrowser.Vote(voteItemId);
                         }
                     }
                 }
                 cookie = new HttpCookie(this.voteId.ToString());
                 cookie.Expires = DateTime.Now.AddYears(100);
                 cookie.Value = this.voteId.ToString();
                 HiContext.Current.Context.Response.Cookies.Add(cookie);
                 this.ShowMessage("投票成功", true);
             }
         }
     }
     else if ((cookie != null) && !string.IsNullOrEmpty(this.Page.Request.QueryString["VoteItemId"].ToString()))
     {
         this.ShowMessage("该用户已经投过票了", false);
     }
 }
Example #15
0
 public override bool UpdateVote(VoteInfo vote, DbTransaction dbTran)
 {
     DbCommand sqlStringCommand = database.GetSqlStringCommand("UPDATE distro_Votes SET VoteName = @VoteName, IsBackup = @IsBackup, MaxCheck = @MaxCheck WHERE VoteId = @VoteId AND DistributorUserId=@DistributorUserId");
     database.AddInParameter(sqlStringCommand, "VoteName", DbType.String, vote.VoteName);
     database.AddInParameter(sqlStringCommand, "IsBackup", DbType.Boolean, vote.IsBackup);
     database.AddInParameter(sqlStringCommand, "MaxCheck", DbType.Int32, vote.MaxCheck);
     database.AddInParameter(sqlStringCommand, "DistributorUserId", DbType.Int32, HiContext.Current.User.UserId);
     database.AddInParameter(sqlStringCommand, "VoteId", DbType.Int64, vote.VoteId);
     return (database.ExecuteNonQuery(sqlStringCommand, dbTran) == 1);
 }
Example #16
0
 private void btnAddVote_Click(object sender, EventArgs e)
 {
     if (ReplyHelper.HasReplyKey(this.txtKeys.Text.Trim()))
     {
         this.ShowMsg("关键字重复!", false);
     }
     else
     {
         string str = string.Empty;
         if (!this.fileUpload.HasFile)
         {
             this.ShowMsg("请上传一张封面图", false);
         }
         else
         {
             try
             {
                 str = StoreHelper.UploadVoteImage(this.fileUpload.PostedFile);
             }
             catch
             {
                 this.ShowMsg("图片上传失败,您选择的不是图片类型的文件,或者网站的虚拟目录没有写入文件的权限", false);
                 return;
             }
             if (this.calendarStartDate.SelectedDate.HasValue)
             {
                 if (!this.calendarEndDate.SelectedDate.HasValue)
                 {
                     this.ShowMsg("请选择活动结束时间", false);
                 }
                 else
                 {
                     VoteInfo vote = new VoteInfo {
                         VoteName = Globals.HtmlEncode(this.txtAddVoteName.Text.Trim()),
                         Keys = this.txtKeys.Text.Trim(),
                         IsBackup = this.checkIsBackup.Checked
                     };
                     int result = 1;
                     if (int.TryParse(this.txtMaxCheck.Text.Trim(), out result))
                     {
                         vote.MaxCheck = result;
                     }
                     vote.ImageUrl = str;
                     vote.StartDate = this.calendarStartDate.SelectedDate.Value;
                     vote.EndDate = this.calendarEndDate.SelectedDate.Value;
                     IList<VoteItemInfo> list = null;
                     if (!string.IsNullOrEmpty(this.txtValues.Text.Trim()))
                     {
                         list = new List<VoteItemInfo>();
                         string[] strArray = this.txtValues.Text.Trim().Replace("\r\n", "\n").Replace("\n", "*").Split(new char[] { '*' });
                         for (int i = 0; i < strArray.Length; i++)
                         {
                             VoteItemInfo item = new VoteItemInfo();
                             if (strArray[i].Length > 60)
                             {
                                 this.ShowMsg("投票选项长度限制在60个字符以内", false);
                                 return;
                             }
                             item.VoteItemName = Globals.HtmlEncode(strArray[i]);
                             list.Add(item);
                         }
                     }
                     else
                     {
                         this.ShowMsg("投票选项不能为空", false);
                         return;
                     }
                     vote.VoteItems = list;
                     if (this.ValidationVote(vote))
                     {
                         if (StoreHelper.CreateVote(vote) > 0)
                         {
                             this.ShowMsg("成功的添加了一个投票", true);
                             this.txtAddVoteName.Text = string.Empty;
                             this.checkIsBackup.Checked = false;
                             this.txtMaxCheck.Text = string.Empty;
                             this.txtValues.Text = string.Empty;
                         }
                         else
                         {
                             this.ShowMsg("添加投票失败", false);
                         }
                     }
                 }
             }
             else
             {
                 this.ShowMsg("请选择活动开始时间", false);
             }
         }
     }
 }
Example #17
0
 public override bool UpdateVote(VoteInfo vote, DbTransaction dbTran)
 {
     DbCommand sqlStringCommand = database.GetSqlStringCommand("UPDATE Hishop_Votes SET VoteName = @VoteName, MaxCheck = @MaxCheck WHERE VoteId = @VoteId");
     database.AddInParameter(sqlStringCommand, "VoteName", DbType.String, vote.VoteName);
     database.AddInParameter(sqlStringCommand, "MaxCheck", DbType.Int32, vote.MaxCheck);
     database.AddInParameter(sqlStringCommand, "VoteId", DbType.Int64, vote.VoteId);
     return (database.ExecuteNonQuery(sqlStringCommand, dbTran) == 1);
 }