コード例 #1
0
        protected void CheckInsert()
        {
            M_Survey info = surBll.GetSurveyBySid(Sid);
            //判断是否登录
            DateTime SubmitDate = DateTime.Now;
            string   SIP        = Request.UserHostAddress;
            int      UserID     = GetUserID(info);

            //判断是否已参与了该问卷
            if (B_Survey.HasAnswerBySID(Sid, UserID))
            {
                function.WriteErrMsg("您已提交过该问卷!");
            }
            if (info.IPRepeat > 0)
            {
                if (B_Survey.HasAnswerCountIP(Sid, SIP) >= info.IPRepeat)
                {
                    function.WriteErrMsg("于IP:" + SIP + " 提交的问卷次数已达到限定次数:" + info.IPRepeat.ToString() + "次!");
                }
            }
            IList <M_Question> list = new List <M_Question>();

            list = B_Survey.GetQueList(Sid);
            for (int i = 0; i < list.Count; i++)
            {
                M_Answer ans         = new M_Answer();
                string   re          = Request.Form["vote_" + i];
                string[] OptionValue = list[i].QuestionContent.Split(new char[] { '|' });
                if (string.IsNullOrEmpty(re))
                {
                    re = "";
                }
                if (list[i].TypeID == 1)
                {
                    if (list[i].IsNull && string.IsNullOrEmpty(Request.Form["vote_" + i]))
                    {
                        function.WriteErrMsg(list[i].QuestionTitle + ":为必填选项");
                    }
                    //ans.AnswerID = 0;
                    ans.AnswerContent = DataConvert.CStr(re);
                    ans.AnswerScore   = surBll.GetScoreByContent(list[i].QuestionContent, re);
                    ans.QuestionID    = list[i].QuestionID;
                    ans.SurveyID      = Sid;
                    ans.SubmitIP      = SIP;
                    ans.SubmitDate    = SubmitDate;
                    ans.UserID        = UserID;
                    B_Survey.AddAnswer(ans);
                }
                else
                {
                    string[] ReArr = re.Split(new char[] { ',' });
                    for (int s = 0; s < ReArr.Length; s++)
                    {
                        //ans.AnswerID = 0;
                        ans.AnswerContent = DataConvert.CStr(ReArr[s]);
                        ans.QuestionID    = list[i].QuestionID;
                        ans.SurveyID      = Sid;
                        ans.SubmitIP      = SIP;
                        ans.SubmitDate    = SubmitDate;
                        ans.UserID        = UserID;
                        B_Survey.AddAnswer(ans);
                    }
                }
            }
        }
コード例 #2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            M_Survey   info = surveyBll.GetSurveyBySid(Sid);
            M_UserInfo mu   = buser.GetLogin();
            string     SIP  = EnviorHelper.GetUserIP();

            if (info.NeedLogin && mu == null || mu.UserID < 1)
            {
                function.WriteErrMsg("该问卷需登录才能参与问卷,请先登录!");
            }
            if (B_Survey.HasAnswerBySID(Sid, mu.UserID))
            {
                function.WriteErrMsg("您已提交过该问卷!");
            }
            if (info.IPRepeat > 0 && B_Survey.HasAnswerCountIP(Sid, SIP) >= info.IPRepeat)
            {
                function.WriteErrMsg("于IP:" + SIP + " 提交的问卷次数已达到限定次数:" + info.IPRepeat.ToString() + "次!");
            }
            //--------------------------
            IList <M_Question> list = B_Survey.GetQueList(Sid);

            for (int i = 0; i < list.Count; i++)
            {
                M_Answer anMod = new M_Answer();
                anMod.AnswerContent = Request.Form["result_" + list[i].QuestionID];
                anMod.QuestionID    = list[i].QuestionID;
                anMod.SurveyID      = Sid;
                anMod.SubmitIP      = SIP;
                anMod.UserID        = mu.UserID;
                B_Survey.AddAnswer(anMod);
            }
            if (B_Survey.AddAnswerRecord(Sid, mu.UserID, SIP, DateTime.Now, 0))
            {
                function.WriteSuccessMsg("提交成功!感谢您的参与!");
            }
            //for (int i = 0; i < list.Count; i++)
            //{
            //    M_Answer ans = new M_Answer();
            //    string re = Request.Form["txt_" + i];
            //    string[] OptionValue = list[i].QuestionContent.Split(new char[] { '|' });
            //    if (string.IsNullOrEmpty(re))
            //    {
            //        re = OptionValue[0];
            //    }

            //    if (list[i].TypeID == 1)
            //    {
            //        ans.AnswerID = 0;
            //        ans.AnswerContent = re;
            //        ans.QuestionID = list[i].QuestionID;
            //        ans.SurveyID = Sid;
            //        ans.SubmitIP = SIP;
            //        ans.UserID = mu.UserID;
            //        B_Survey.AddAnswer(ans);
            //    }
            //    else
            //    {
            //        string[] ReArr = re.Split(new char[] { ',' });
            //        for (int s = 0; s < ReArr.Length; s++)
            //        {
            //            ans.AnswerID = 0;
            //            ans.AnswerContent = ReArr[s];
            //            ans.QuestionID = list[i].QuestionID;
            //            ans.SurveyID = Sid;
            //            ans.SubmitIP = SIP;
            //            ans.UserID = mu.UserID;
            //            B_Survey.AddAnswer(ans);
            //        }
            //    }
            //}
        }