예제 #1
0
파일: Polls.cs 프로젝트: terryxym/DiscuzNT
        /// <summary>
        /// 创建一个投票
        /// </summary>
        /// <param name="tid">关联的主题id</param>
        /// <param name="multiple">投票类型, 0为单选, 1为多选</param>
        /// <param name="itemcount">投票项总数</param>
        /// <param name="itemnamelist">投票项目列表</param>
        /// <param name="itemvaluelist">投票项目结果列表</param>
        /// <param name="usernamelist">用户名列表</param>
        /// <param name="enddatetime">截止日期</param>
        /// <param name="userid">用户id</param>
        /// <param name="maxchoices">最多可选项数</param>
        /// <param name="visible">提交投票后结果才可见, 0为可见, 1为投票后可见</param>
        /// <param name="allowview">是否允许公开投票参与人</param>
        /// <returns>成功则返回true, 否则返回false</returns>
        public static bool CreatePoll(int tid, int multiple, int itemcount, string itemnamelist, string itemvaluelist, string enddatetime, int userid, int maxchoices, int visible, int allowview)
        {
            string[] itemname = Utils.SplitString(itemnamelist, "\r\n");

            if ((itemname.Length != itemcount) || (Utils.SplitString(itemvaluelist, "\r\n").Length != itemcount))
            {
                return(false);
            }

            PollInfo pollinfo = new PollInfo();

            pollinfo.Displayorder = 0;
            pollinfo.Expiration   = Utils.GetStandardDateTime(enddatetime);
            pollinfo.Maxchoices   = maxchoices;
            pollinfo.Multiple     = multiple;
            pollinfo.Tid          = tid;
            pollinfo.Uid          = userid;
            pollinfo.Visible      = visible;
            pollinfo.Allowview    = allowview;

            int pollid = Discuz.Data.Polls.CreatePoll(pollinfo);

            if (pollid > 0)
            {
                for (int i = 0; i < itemcount; i++)
                {
                    PollOptionInfo polloptioninfo = new PollOptionInfo();
                    polloptioninfo.Displayorder = i + 1;
                    polloptioninfo.Pollid       = pollid;
                    polloptioninfo.Polloption   = Utils.GetSubString(itemname[i], 80, "");
                    polloptioninfo.Tid          = tid;
                    polloptioninfo.Voternames   = "";
                    polloptioninfo.Votes        = 0;
                    Discuz.Data.Polls.CreatePollOption(polloptioninfo);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// 通过主题ID获取相应的投票信息
        /// </summary>
        /// <param name="tid">主题id</param>
        /// <returns>投票选项集合</returns>
        public static List <PollOptionInfo> GetPollOptionInfoCollection(int tid)
        {
            List <PollOptionInfo> pollOptionInfoList = new List <PollOptionInfo>();
            IDataReader           idatareader        = DatabaseProvider.GetInstance().GetPollOptionList(tid);
            PollOptionInfo        polloptioninfo;

            while (idatareader.Read())
            {
                polloptioninfo = new PollOptionInfo();
                polloptioninfo.Polloptionid = TypeConverter.ObjectToInt(idatareader["polloptionid"], 0);
                polloptioninfo.Displayorder = TypeConverter.ObjectToInt(idatareader["displayorder"], 0);
                polloptioninfo.Pollid       = TypeConverter.ObjectToInt(idatareader["pollid"], 0);
                polloptioninfo.Polloption   = idatareader["polloption"].ToString().Trim();
                polloptioninfo.Tid          = TypeConverter.ObjectToInt(idatareader["tid"], 0);
                polloptioninfo.Voternames   = idatareader["voternames"].ToString().Trim();
                polloptioninfo.Votes        = TypeConverter.ObjectToInt(idatareader["votes"], 0);
                pollOptionInfoList.Add(polloptioninfo);
            }
            idatareader.Close();
            return(pollOptionInfoList);
        }
예제 #3
0
파일: Polls.cs 프로젝트: object8421/ichari
        /// <summary>
        /// 通过主题ID获取相应的投票信息
        /// </summary>
        /// <param name="tid">主题id</param>
        /// <returns>投票选项集合</returns>
        public static PollOptionInfoCollection GetPollOptionInfoCollection(int tid)
        {
            PollOptionInfoCollection pollinfocoll = new PollOptionInfoCollection();
            IDataReader    idatareader            = DatabaseProvider.GetInstance().GetPollOptionList(tid);
            PollOptionInfo polloptioninfo;

            while (idatareader.Read())
            {
                polloptioninfo = new PollOptionInfo();
                polloptioninfo.Polloptionid = Utils.StrToInt(idatareader["polloptionid"], 0);
                polloptioninfo.Displayorder = Utils.StrToInt(idatareader["displayorder"], 0);
                polloptioninfo.Pollid       = Utils.StrToInt(idatareader["pollid"], 0);
                polloptioninfo.Polloption   = idatareader["polloption"].ToString().Trim();
                polloptioninfo.Tid          = Utils.StrToInt(idatareader["tid"], 0);
                polloptioninfo.Voternames   = idatareader["voternames"].ToString().Trim();
                polloptioninfo.Votes        = Utils.StrToInt(idatareader["votes"], 0);
                pollinfocoll.Add(polloptioninfo);
            }
            idatareader.Close();
            return(pollinfocoll);
        }
예제 #4
0
 /// <summary>
 /// 删除指定的投票项
 /// </summary>
 /// <param name="pollInfoOption">投票项</param>
 /// <returns></returns>
 public static bool DeletePollOption(PollOptionInfo pollInfoOption)
 {
     return(DatabaseProvider.GetInstance().DeletePollOption(pollInfoOption));
 }
예제 #5
0
 /// <summary>
 /// 创建投票项
 /// </summary>
 /// <param name="polloptioninfocoll">投票项</param>
 /// <returns></returns>
 public static void CreatePollOption(PollOptionInfo polloptioninfo)
 {
     DatabaseProvider.GetInstance().CreatePollOption(polloptioninfo);
 }
예제 #6
0
파일: Polls.cs 프로젝트: terryxym/DiscuzNT
        /// <summary>
        /// 更新一个投票
        /// </summary>
        /// <param name="tid">关联的主题id</param>
        /// <param name="multiple">投票类型, 0为单选, 1为多选</param>
        /// <param name="itemcount">投票项总数</param>
        /// <param name="polloptionidlist">投票项id列表</param>
        /// <param name="itemnamelist">投票项目列表</param>
        /// <param name="itemdisplayorderlist">投票项目排列顺序列表</param>
        /// <param name="enddatetime">截止日期</param>
        /// <param name="maxchoices">最多可选项数</param>
        /// <param name="visible">提交投票后结果才可见, 0为可见, 1为投票后可见</param>
        /// <param name="allowview">是否允许公开投票参与人</param>
        /// <returns>成功则返回true, 否则返回false</returns>
        public static bool UpdatePoll(int tid, int multiple, int itemcount, string polloptionidlist, string itemnamelist, string itemdisplayorderlist, string enddatetime, int maxchoices, int visible, int allowview)
        {
            string[] itemname         = Utils.SplitString(itemnamelist, "\r\n");
            string[] itemdisplayorder = Utils.SplitString(itemdisplayorderlist, "\r\n");
            string[] polloptionid     = Utils.SplitString(polloptionidlist, "\r\n");

            if ((itemname.Length != itemcount) || (itemdisplayorder.Length != itemcount))
            {
                return(false);
            }

            PollInfo pollinfo = Discuz.Data.Polls.GetPollInfo(tid);

            pollinfo.Expiration = Utils.GetStandardDateTime(enddatetime);
            pollinfo.Maxchoices = maxchoices;
            pollinfo.Multiple   = multiple;
            pollinfo.Tid        = tid;
            pollinfo.Visible    = visible;
            pollinfo.Allowview  = allowview;

            bool result = false;

            if (pollinfo.Pollid > 0)
            {
                result = Discuz.Data.Polls.UpdatePoll(pollinfo);
            }

            if (result)
            {
                List <PollOptionInfo> pollOptionInfoList = Discuz.Data.Polls.GetPollOptionInfoCollection(pollinfo.Tid);
                int i = 0;

                //先作已存在的投票选项更新及新添加选项的添加操作
                bool optionexist;
                foreach (string optionid in polloptionid)
                {
                    optionexist = false;
                    foreach (PollOptionInfo polloptioninfo in pollOptionInfoList)
                    {
                        if (optionid == polloptioninfo.Polloptionid.ToString())
                        {
                            polloptioninfo.Pollid       = pollinfo.Pollid;
                            polloptioninfo.Polloption   = Utils.GetSubString(itemname[i], 80, "");
                            polloptioninfo.Displayorder = Utils.StrIsNullOrEmpty(itemdisplayorder[i]) ? i + 1 : Utils.StrToInt(itemdisplayorder[i], 0);
                            Discuz.Data.Polls.UpdatePollOption(polloptioninfo);
                            optionexist = true;
                            break;
                        }
                    }
                    if (!optionexist) //如果当前选项不存在,表示该选项为新添选项
                    {
                        PollOptionInfo polloptioninfo = new PollOptionInfo();
                        polloptioninfo.Displayorder = Utils.StrIsNullOrEmpty(itemdisplayorder[i]) ? i + 1 : Utils.StrToInt(itemdisplayorder[i], 0);
                        polloptioninfo.Pollid       = pollinfo.Pollid;
                        polloptioninfo.Polloption   = Utils.GetSubString(itemname[i], 80, "");
                        polloptioninfo.Tid          = tid;
                        polloptioninfo.Voternames   = "";
                        polloptioninfo.Votes        = 0;
                        Discuz.Data.Polls.CreatePollOption(polloptioninfo);
                    }
                    i++;
                }

                foreach (PollOptionInfo polloptioninfo in pollOptionInfoList)
                {
                    //下面代码用于删除已去除的投票项
                    if (("\r\n" + polloptionidlist + "\r\n").IndexOf("\r\n" + polloptioninfo.Polloptionid + "\r\n") < 0)
                    {
                        Discuz.Data.Polls.DeletePollOption(polloptioninfo);
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #7
0
 public void UpdatePollOption(PollOptionInfo objPollOption, int pollId)
 {
     dataProvider.UpdatePollOption(objPollOption.PollOptionId, objPollOption.PollId, objPollOption.OptionName, objPollOption.Priority, objPollOption.LastModifiedOnDate);
     //Caching.ClearPollOptionCache(pollId);
 }
예제 #8
0
 public int AddPollOption(PollOptionInfo objPollOption)
 {
     return(dataProvider.AddPollOption(objPollOption.PollId, objPollOption.OptionName, objPollOption.Priority, objPollOption.CreatedOnDate));
     //Caching.ClearPollOptionCache(objPollOption.PollId);
 }
예제 #9
0
		public void UpdatePollOption(PollOptionInfo objPollOption, int pollId)
		{
			dataProvider.UpdatePollOption(objPollOption.PollOptionId, objPollOption.PollId, objPollOption.OptionName, objPollOption.Priority, objPollOption.LastModifiedOnDate);
			//Caching.ClearPollOptionCache(pollId);
		}
예제 #10
0
		public int AddPollOption(PollOptionInfo objPollOption)
		{
			return dataProvider.AddPollOption(objPollOption.PollId, objPollOption.OptionName, objPollOption.Priority, objPollOption.CreatedOnDate);
			//Caching.ClearPollOptionCache(objPollOption.PollId);
		}