protected void RptShowCountData_ItemDataBound(object sender, RepeaterItemEventArgs e) { this.rowCount++; if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) { SurveyFieldInfo dataItem = e.Item.DataItem as SurveyFieldInfo; Label label = e.Item.FindControl("LblQuestionContent") as Label; HyperLink link = e.Item.FindControl("LnkListAnswer") as HyperLink; PlaceHolder ph = e.Item.FindControl("PlhQuestion") as PlaceHolder; this.m_QuestionType = dataItem.QuestionType; label.Text = " " + this.rowCount.ToString() + "、(" + SurveyField.GetQuestionType(dataItem.QuestionType) + ")"; link.NavigateUrl = "AnswerList.aspx?SurveyID=" + this.HdnSurveyId.Value + "&QuestionID=" + dataItem.QuestionId.ToString(); link.Text = dataItem.QuestionContent; link.ToolTip = "[" + dataItem.QuestionContent + "]回答详情"; if (((dataItem.QuestionType == 0) || (dataItem.QuestionType == 1)) || (((dataItem.QuestionType == 6) || (dataItem.QuestionType == 8)) || (dataItem.QuestionType == 9))) { Literal child = new Literal(); child.Text = "<div class='border tdbg' style='width:99%; padding:5px 0 5px 0;'><a href='AnswerList.aspx?SurveyID=" + this.HdnSurveyId.Value + "&QuestionID=" + dataItem.QuestionId.ToString() + "'> 内容</a></div>"; ph.Controls.Add(child); } else { this.Show(dataItem.Settings, ph, dataItem.QuestionId); } } }
protected void Page_Load(object sender, EventArgs e) { this.surveyId = DataConverter.CLng(base.Request.QueryString["SurveyID"]); SurveyInfo surveyById = SurveyManager.GetSurveyById(this.surveyId); this.SmpNavigator.AdditionalNode = "<b>[</b><font color=red>" + DataSecurity.HtmlEncode(surveyById.SurveyName) + "</font><b>]</b>题目列表"; this.isOpen = surveyById.IsOpen; if (this.isOpen == 1) { this.EgvQuestion.Columns[3].Visible = false; this.BtnAddQuestion.Visible = false; this.BtnSetOrderId.Visible = false; this.BtnDel.Visible = false; this.EgvQuestion.AutoGenerateCheckBoxColumn = false; } if (!base.IsPostBack) { int questionId = DataConverter.CLng(base.Request.QueryString["QuestionId"]); string str = base.Request.QueryString["Action"]; if (str == "Delete") { SurveyField.Delete(this.surveyId, questionId); } } }
protected void RptShowCountList_ItemDataBound(object sender, RepeaterItemEventArgs e) { if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) { Repeater rptShowCountData = (Repeater)e.Item.FindControl("RptShowCountData"); IList <SurveyFieldInfo> surveyFieldInfoList = new List <SurveyFieldInfo>(); surveyFieldInfoList = SurveyField.GetFieldList(this.m_SurveyId); if (surveyFieldInfoList != null) { RptShowCountDataBind(rptShowCountData, surveyFieldInfoList); int i = 0; DataTable dataTable = new DataTable(); dataTable = ((SurveyRecordInfo)e.Item.DataItem).Answer; foreach (RepeaterItem item in rptShowCountData.Controls) { if (item.ItemType == ListItemType.Header) { Label label = (Label)item.FindControl("LblIP"); Label label2 = (Label)item.FindControl("LblSubmitTime"); label.Text = ((SurveyRecordInfo)e.Item.DataItem).IP; label2.Text = ((SurveyRecordInfo)e.Item.DataItem).SubmitTime.ToString(); } else if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem)) { Label label3 = (Label)item.FindControl("LblAnswer"); label3.Text = GetAnswer(surveyFieldInfoList, i, dataTable); i++; } } } } }
protected void BtnOrderId_Click(object sender, EventArgs e) { IList <SurveyFieldInfo> fieldList = SurveyField.GetFieldList(this.surveyId); Dictionary <int, SurveyFieldInfo> temdic = new Dictionary <int, SurveyFieldInfo>(); int count = fieldList.Count; int num2 = 0; foreach (GridViewRow row in this.EgvQuestion.Rows) { if (row.RowType == DataControlRowType.DataRow) { int key = DataConverter.CLng(((DropDownList)row.FindControl("DropOrderId")).SelectedValue); temdic.Add(key, fieldList[num2]); num2++; } } if (SurveyField.Update(this.surveyId, this.Sort(temdic, count))) { AdminPage.WriteSuccessMsg("保存排序成功!", "QuestionManage.aspx?SurveyID=" + this.surveyId); } else { AdminPage.WriteErrMsg("保存排序失败!"); } }
protected void BtnSubmit_Click(object sender, EventArgs e) { if (this.Page.IsValid) { bool flag = false; SurveyFieldInfo info = new SurveyFieldInfo(); int num = DataConverter.CLng(this.RadlQuestionType.SelectedValue); switch (num) { case 2: case 3: case 4: case 5: { string[] settings = this.TxtSettings.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); info.CopyToSettings(settings); break; } case 7: info.CopyToSettings(new string[] { "0", "1" }); break; default: info.CopyToSettings(new string[] { "" }); break; } info.QuestionContent = this.TxtQuestionContent.Text; info.QuestionType = num; info.EnableNull = DataConverter.CBoolean(this.RadlEnableNull.SelectedValue); info.InputType = DataConverter.CLng(this.RadlInputType.SelectedValue); info.ContentLength = DataConverter.CLng(this.TxtContentLength.Text); if (this.m_Action == "modify") { info.QuestionId = DataConverter.CLng(this.HdnQuestionId.Value); flag = SurveyField.Update(this.m_SurveyId, info); } else { flag = SurveyField.Add(this.m_SurveyId, info); if (DataConverter.CLng(this.HdnIsOpen.Value) == 2) { string tableName = "PE_SurveyRecord" + this.m_SurveyId; flag = flag && SurveyField.AddFieldToTable(info, tableName); } } if (flag) { AdminPage.WriteSuccessMsg("保存题目信息成功!", "QuestionManage.aspx?SurveyID=" + this.m_SurveyId); } else { AdminPage.WriteErrMsg("<li>保存题目信息失败!</li>"); } } }
protected void EgvQuestionDetail_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { SurveyFieldInfo dataItem = e.Row.DataItem as SurveyFieldInfo; e.Row.Cells[0].Text = Convert.ToString((int)(((this.EgvQuestionDetail.PageIndex * this.EgvQuestionDetail.PageCount) + e.Row.RowIndex) + 1)); e.Row.Cells[2].Text = SurveyField.GetQuestionType(dataItem.QuestionType); e.Row.Cells[3].Text = BasePage.RequestString("SurveyName"); } }
protected void Page_Load(object sender, EventArgs e) { this.surveyId = BasePage.RequestInt32("SurveyID"); this.questionId = BasePage.RequestInt32("QuestionID"); if ((this.surveyId != 0) && (this.questionId != 0)) { this.fieldInfo = SurveyField.GetFieldInfoById(this.surveyId, this.questionId); this.LblTitle.Text = "当前问卷:" + SurveyManager.GetSurveyById(this.surveyId).SurveyName + " / 当前问题:" + this.fieldInfo.QuestionContent; this.BindData(); } }
protected void BtnDel_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.EgvQuestion.SelectList.ToString())) { AdminPage.WriteErrMsg("请指定要删除的问题ID"); } else if (SurveyField.BatchDelete(this.surveyId, this.EgvQuestion.SelectList.ToString())) { AdminPage.WriteSuccessMsg("删除问题成功!", "QuestionManage.aspx?SurveyID=" + this.surveyId); } }
protected void Page_Load(object sender, EventArgs e) { this.questionType = BasePage.RequestInt32("QuestionType"); this.questionId = BasePage.RequestInt32("QuestionID"); this.surveyId = BasePage.RequestInt32("SurveyID"); this.questionInfo = SurveyField.GetFieldInfoById(this.surveyId, this.questionId); this.ShowQuestionContent(); if (DataConverter.CLng(base.Request.QueryString["IsOpen"]) == 1) { this.DivModify.Visible = false; } }
private IList <SurveyFieldInfo> GetDataSource() { if (string.IsNullOrEmpty(BasePage.RequestString("SurveyID"))) { return(null); } if ((((IList <SurveyFieldInfo>)base.Cache["SurveyFieldInfoList"]) == null) || (this.HdnSurveyId.Value != BasePage.RequestString("SurveyID"))) { base.Cache["SurveyFieldInfoList"] = SurveyField.GetFieldList(BasePage.RequestInt32("SurveyID")); this.HdnSurveyId.Value = BasePage.RequestString("SurveyID"); } return(base.Cache["SurveyFieldInfoList"] as IList <SurveyFieldInfo>); }
protected void EgvQuestion_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { SurveyFieldInfo dataItem = e.Row.DataItem as SurveyFieldInfo; if (this.EgvQuestion.AutoGenerateCheckBoxColumn) { e.Row.Cells[2].Text = SurveyField.GetQuestionType(dataItem.QuestionType); } else { e.Row.Cells[1].Text = SurveyField.GetQuestionType(dataItem.QuestionType); } } }
protected void Page_Load(object sender, EventArgs e) { this.surveyId = BasePage.RequestInt32("SurveyID"); this.questionId = BasePage.RequestInt32("QuestionID"); if ((this.surveyId != 0) && (this.questionId != 0)) { this.fieldInfo = SurveyField.GetFieldInfoById(this.surveyId, this.questionId); this.LblTitle.Text = "当前问题:" + this.fieldInfo.QuestionContent; this.SmpNavigator.CurrentNode = "当前问卷:" + SurveyManager.GetSurveyById(this.surveyId).SurveyName; if ((this.fieldInfo.QuestionType == 2) || (this.fieldInfo.QuestionType == 3)) { this.IsThree = true; } this.BindData(); } if (!base.IsPostBack) { this.Pager.PageSize = 10; } }
public ActionResult Edit(int id, List<QuestionPost> questions ) { var survey = Repository.OfType<Survey>().GetNullableById(id); var types = Repository.OfType<SurveyFieldType>().GetAll(); if (survey.RegistrationSurveys.Any()) { Message = "Cannot edit this survey because there are already responses."; return RedirectToAction("Index"); } // get the list of distinct question ids, figure out what to delete var ids = questions.Where(a => a.Id > 0).Select(a => a.Id).ToList(); var toDelete = survey.SurveyFields.Where(a => !ids.Contains(a.Id)).ToList(); foreach (var d in toDelete) survey.SurveyFields.Remove(d); for (var i = 0; i < questions.Count; i++) { var q = questions[i]; SurveyField sf = null; // editing existing question if (q.Id > 0) { sf = survey.SurveyFields.Single(a => a.Id == q.Id); sf.Prompt = q.Prompt; sf.Order = i; // empty the lists, they'll get repopulated shortly sf.SurveyFieldOptions.Clear(); sf.SurveyFieldValidators.Clear(); } // adding new question else { var type = types.First(a => a.Id == q.FieldTypeId); sf = new SurveyField() { Prompt = q.Prompt, SurveyFieldType = type, Order = i }; } if (sf.SurveyFieldType.HasOptions && q.Options != null) { foreach (var o in q.Options.Distinct()) { sf.AddFieldOption(new SurveyFieldOption() { Name = o }); } } if (q.ValidatorIds != null) { foreach (var v in q.ValidatorIds.Distinct()) { sf.SurveyFieldValidators.Add(Repository.OfType<SurveyFieldValidator>().GetById(v)); } } if (q.Id <= 0) { survey.AddSurveyField(sf); } } Repository.OfType<Survey>().EnsurePersistent(survey); Message = "Survey updated."; return View(SurveyCreateViewModel.Create(Repository, survey)); }
public ActionResult Create(string name, List<QuestionPost> questions ) { var survey = new Survey() {Name = name}; var types = Repository.OfType<SurveyFieldType>().GetAll(); for (var i = 0; i < questions.Count; i++ ) { var q = questions[i]; var type = types.First(a => a.Id == q.FieldTypeId); var field = new SurveyField() { Prompt = q.Prompt, SurveyFieldType = type, Order = i}; if (type.HasOptions && q.Options != null) { foreach (var o in q.Options.Distinct()) { field.AddFieldOption(new SurveyFieldOption() { Name = o }); } } if (q.ValidatorIds != null) { foreach (var v in q.ValidatorIds.Distinct()) { field.SurveyFieldValidators.Add(Repository.OfType<SurveyFieldValidator>().GetById(v)); } } survey.AddSurveyField(field); } Repository.OfType<Survey>().EnsurePersistent(survey); Message = "Survey has been created"; return RedirectToAction("Index"); }
private void SaveSurveyRecord(int surveyId) { if (surveyId == 0) { DynamicPage.WriteErrMsg("问卷调查ID错误!"); } else { SurveyInfo surveyById = SurveyManager.GetSurveyById(surveyId); if (surveyById.IsOpen != 1) { DynamicPage.WriteErrMsg("问卷调查尚未启用!!!"); } if (surveyById.EndTime != null)//.HasValue) { DateTime?endTime = surveyById.EndTime; DateTime now = DateTime.Now; if (endTime.HasValue ? (endTime.GetValueOrDefault() < now) : false) { DynamicPage.WriteErrMsg("问卷调查已经结束!!!"); } } if (!SurveyManager.CheckLockUrl(base.Request.ServerVariables["HTTP_REFERER"], surveyById)) { DynamicPage.WriteErrMsg("不允许从外部链接地址提交!!!"); } if (SurveyManager.CheckRepeatIP(PEContext.Current.UserHostAddress, surveyId, surveyById)) { DynamicPage.WriteErrMsg("同一用户不允许填写问卷调查超过" + surveyById.IPRepeat.ToString() + "次!!!"); } if (!string.IsNullOrEmpty(surveyById.SetPassword) && (surveyById.SetPassword != base.Request.Form["SurveyPassword"].ToString())) { DynamicPage.WriteErrMsg("问卷密码错误!!!"); } if (SurveyManager.CheckIPLock(PEContext.Current.UserHostAddress, surveyById)) { DynamicPage.WriteErrMsg("对不起!您的IP(" + PEContext.Current.UserHostAddress + ")被系统限定,您可以和站长联系。"); } if (surveyById.NeedLogin == 1) { if (PEContext.Current.User.Identity.IsAuthenticated) { if (surveyById.PresentPoint != 0) { int userId = PEContext.Current.User.UserInfo.UserId; Users.Update(userId, "UserPoint", (PEContext.Current.User.UserInfo.UserPoint + surveyById.PresentPoint).ToString()); UserPointLogInfo userPointLogInfo = new UserPointLogInfo(); userPointLogInfo.IncomePayOut = 1; userPointLogInfo.InfoId = 0; userPointLogInfo.Inputer = "System"; userPointLogInfo.IP = PEContext.Current.UserHostAddress; userPointLogInfo.LogId = UserPointLog.GetTotalInComeAndPayOutAll().Count; userPointLogInfo.LogTime = DateTime.Now; userPointLogInfo.Memo = ""; userPointLogInfo.ModuleType = 9; userPointLogInfo.Point = surveyById.PresentPoint; userPointLogInfo.Remark = "参与“" + surveyById.SurveyName + "”--问卷调查获得奖励点数"; userPointLogInfo.Times = 1; userPointLogInfo.UserName = PEContext.Current.User.UserInfo.UserName; UserPointLog.Add(userPointLogInfo); } } else { string absoluteUri = HttpContext.Current.Request.Url.AbsoluteUri; BasePage.ResponseRedirect("../User/Login.aspx?ReturnUrl=" + HttpUtility.UrlEncode(absoluteUri)); } } IList <SurveyFieldInfo> fieldList = SurveyField.GetFieldList(surveyId); SurveyRecordInfo surveyrecordinfo = new SurveyRecordInfo(); DataTable table = new DataTable(); table.Columns.Add("Option", typeof(string)); table.Columns.Add("Input", typeof(string)); table.Columns.Add("QuestionType", typeof(int)); table.Columns.Add("InputType", typeof(int)); table.Columns.Add("QuestionId", typeof(int)); foreach (SurveyFieldInfo info4 in fieldList) { string answer = DataSecurity.FilterBadChar(base.Request.Form["Q" + info4.QuestionId]); this.CheckForm(info4, answer); DataRow row = table.NewRow(); row["Option"] = answer; row["QuestionType"] = info4.QuestionType; row["InputType"] = info4.InputType; row["QuestionId"] = info4.QuestionId; if (info4.InputType > 0) { string str3 = DataSecurity.FilterBadChar(base.Request.Form["Q" + info4.QuestionId + "Input"]); row["Input"] = str3; } if (((info4.QuestionType == 2) || (info4.QuestionType == 4)) || (info4.QuestionType == 7)) { SurveyVote.Vote(surveyId, info4.QuestionId, DataConverter.CLng(answer)); } if ((info4.QuestionType == 3) || (info4.QuestionType == 5)) { foreach (string str4 in answer.Split(new char[] { ',' })) { SurveyVote.Vote(surveyId, info4.QuestionId, DataConverter.CLng(str4)); } } table.Rows.Add(row); } surveyrecordinfo.Answer = table; surveyrecordinfo.UserName = PEContext.Current.User.UserInfo.UserName; surveyrecordinfo.IP = PEContext.Current.UserHostAddress; surveyrecordinfo.SubmitTime = DateTime.Now; surveyrecordinfo.SurveyId = surveyId; if (!SurveyRecord.SaveSurveyRecord(surveyrecordinfo)) { DynamicPage.WriteErrMsg("提交问卷失败!"); } else { DynamicPage.WriteSuccessMsg("提交问卷成功!", ""); } } }
protected void ModifyInitialize() { SurveyFieldInfo fieldInfoById = new SurveyFieldInfo(); fieldInfoById = SurveyField.GetFieldInfoById(this.m_SurveyId, DataConverter.CLng(this.HdnQuestionId.Value)); if (fieldInfoById.IsNull) { AdminPage.WriteErrMsg("<li>找不到对应的问卷题目信息</li>"); } else { SurveyInfo info2 = new SurveyInfo(); int isOpen = SurveyManager.GetSurveyById(this.m_SurveyId).IsOpen; if (isOpen != 0) { this.RadlQuestionType.Enabled = false; } this.RadlEnableNull.SelectedValue = fieldInfoById.EnableNull.ToString(); this.TxtQuestionContent.Text = fieldInfoById.QuestionContent; this.RadlQuestionType.SelectedValue = fieldInfoById.QuestionType.ToString(); switch (fieldInfoById.QuestionType) { case 0: this.PnlText.Visible = true; this.PnlChoice.Visible = false; this.PnlInputType.Visible = false; break; case 1: this.PnlText.Visible = false; this.PnlChoice.Visible = false; this.PnlInputType.Visible = false; break; case 2: this.PnlText.Visible = false; this.PnlChoice.Visible = true; this.PnlInputType.Visible = true; break; case 3: this.PnlText.Visible = false; this.PnlChoice.Visible = true; this.PnlInputType.Visible = true; break; case 4: this.PnlText.Visible = false; this.PnlChoice.Visible = true; this.PnlInputType.Visible = false; break; case 5: this.PnlText.Visible = false; this.PnlChoice.Visible = true; this.PnlInputType.Visible = false; break; case 6: this.PnlText.Visible = false; this.PnlChoice.Visible = false; this.PnlInputType.Visible = false; break; case 7: this.PnlText.Visible = false; this.PnlChoice.Visible = false; this.PnlInputType.Visible = false; break; case 8: this.PnlText.Visible = true; this.PnlChoice.Visible = false; this.PnlInputType.Visible = false; break; case 9: this.PnlText.Visible = true; this.PnlChoice.Visible = false; this.PnlInputType.Visible = false; break; } if (this.PnlChoice.Visible) { if (fieldInfoById.Settings != null) { StringBuilder builder = new StringBuilder(); foreach (string str in fieldInfoById.Settings) { builder.Append(str); builder.Append("\n"); } this.TxtSettings.Text = builder.ToString(); } if (isOpen != 0) { this.TxtSettings.ReadOnly = true; this.RadlInputType.Enabled = false; } if (this.PnlInputType.Visible) { this.RadlInputType.SelectedValue = fieldInfoById.InputType.ToString(); if (fieldInfoById.InputType == 1) { this.PnlText.Visible = true; } } else { this.PnlText.Visible = false; } } if (this.PnlText.Visible) { this.TxtContentLength.Text = fieldInfoById.ContentLength.ToString(); } } }