public static bool Update(int surveyId, SurveyFieldInfo info) { int num = -1; IList <SurveyFieldInfo> fieldList = GetFieldList(surveyId); for (int i = 0; i < fieldList.Count; i++) { if (fieldList[i].QuestionId == info.QuestionId) { num = i; break; } } if (num == -1) { return(false); } fieldList[num] = info; if (info.Settings != null) { SurveyVote.Delete(surveyId, info.QuestionId); SurveyVote.Add(surveyId, info.QuestionId, info.Settings.Count); } return(dal.Update(surveyId, SerializeFieldList(fieldList))); }
public static bool BatchDelete(int surveyId, string questionIds) { bool flag = false; if (!string.IsNullOrEmpty(questionIds)) { XmlManage manage = XmlManage.Instance(GetXmlFieldBySurveyId(surveyId), XmlType.Content); string[] strArray = questionIds.Split(new char[] { ',' }); for (int i = 0; i < strArray.Length; i++) { SurveyFieldInfo fieldInfoById = new SurveyFieldInfo(); fieldInfoById = GetFieldInfoById(surveyId, DataConverter.CLng(strArray[i])); manage.Remove(GetNodePath(DataConverter.CLng(strArray[i]))); DeleteColumn(DataConverter.CLng(strArray[i]), surveyId); if (((fieldInfoById.QuestionType == 2) || (fieldInfoById.QuestionType == 3)) && (fieldInfoById.InputType != 0)) { DeleteInputColumn(DataConverter.CLng(strArray[i]), surveyId); } } flag = dal.Update(surveyId, manage.Xml); if (flag) { SurveyVote.Delete(surveyId, questionIds); } } return(flag); }
public static bool Delete(int surveyId, int questionId) { SurveyFieldInfo fieldInfoById = new SurveyFieldInfo(); fieldInfoById = GetFieldInfoById(surveyId, questionId); XmlManage manage = XmlManage.Instance(GetXmlFieldBySurveyId(surveyId), XmlType.Content); manage.Remove(GetNodePath(questionId)); bool flag = dal.Delete(surveyId, manage.Xml); if (flag) { SurveyVote.Delete(surveyId, questionId); DeleteColumn(questionId, surveyId); if ((fieldInfoById.QuestionType != 2) && (fieldInfoById.QuestionType != 3)) { return(flag); } if (fieldInfoById.InputType != 0) { DeleteInputColumn(questionId, surveyId); } } return(flag); }
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); } } }
private void CheckForm(SurveyFieldInfo fieldInfo, string answer) { switch (fieldInfo.QuestionType) { case 0: case 1: if (!string.IsNullOrEmpty(answer) || !fieldInfo.EnableNull) { break; } DynamicPage.WriteErrMsg(fieldInfo.QuestionContent + "不能为空!"); return; case 2: case 3: case 4: case 5: case 7: if (!string.IsNullOrEmpty(answer) || !fieldInfo.EnableNull) { break; } DynamicPage.WriteErrMsg("请选择" + fieldInfo.QuestionContent); return; case 6: DateTime time; if (fieldInfo.EnableNull && string.IsNullOrEmpty(answer)) { DynamicPage.WriteErrMsg(fieldInfo.QuestionContent + "不能为空!"); } if (DateTime.TryParse(answer, out time)) { break; } DynamicPage.WriteErrMsg(fieldInfo.QuestionContent + " 填写的日期格式不正确!"); return; case 8: if (DataValidator.IsNumber(answer) || !fieldInfo.EnableNull) { break; } DynamicPage.WriteErrMsg(fieldInfo.QuestionContent + "中输入的不是数字!"); return; case 9: if (!DataValidator.IsEmail(answer) && fieldInfo.EnableNull) { DynamicPage.WriteErrMsg("请选择正确的Emial地址!"); } break; default: return; } }
private static void ContentLengthJS(SurveyFieldInfo info, StringBuilder tempFormJs, string otherName) { if ((0 < info.ContentLength) && (info.ContentLength <= 0xff)) { tempFormJs.Append(string.Concat(new object[] { "if (document.myform.", otherName, ".value.length>255||document.myform.", otherName, ".value.length>", info.ContentLength, ")\n" })); tempFormJs.Append("{flag=false;alert('填写的内容过长');\n"); tempFormJs.Append("document.myform." + otherName + ".focus();return flag}\n"); } }
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"); } }
private static void EnableNullJS(SurveyFieldInfo info, StringBuilder tempFormJs, string problemName) { if (info.EnableNull) { tempFormJs.Append("if (document.myform." + problemName + ".value=='')\n"); tempFormJs.Append("{flag=false;"); tempFormJs.Append("alert('" + info.QuestionContent + "不能为空');\n"); tempFormJs.Append("document.myform." + problemName + ".focus();\n"); tempFormJs.Append("return flag}\n"); } }
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(); } }
public static bool Add(int surveyId, SurveyFieldInfo info) { IList <SurveyFieldInfo> fieldList = GetFieldList(surveyId); info.QuestionId = SurveyManager.GetSurveyById(surveyId).QuestionMaxId + 1; fieldList.Add(info); if (info.Settings != null) { SurveyVote.Add(surveyId, info.QuestionId, info.Settings.Count); } return(dal.Add(surveyId, SerializeFieldList(fieldList))); }
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; } }
public bool AddFieldToTable(SurveyFieldInfo surveyFieldInfo, string tableName) { string addColumnToTableSql = GetAddColumnToTableSql(surveyFieldInfo, tableName); try { DBHelper.ExecuteNonQuerySql(addColumnToTableSql); return(true); } catch { return(false); } }
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 RptSurveyQuestion_ItemDataBound(object sender, RepeaterItemEventArgs e) { this.rowNumber1++; if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) { SurveyFieldInfo dataItem = e.Item.DataItem as SurveyFieldInfo; Label label = e.Item.FindControl("LblQuestion") as Label; label.Text = " " + this.rowNumber1.ToString() + "、" + dataItem.QuestionContent; Label label2 = e.Item.FindControl("LblOptions") as Label; StringBuilder builder = new StringBuilder(""); if (((dataItem.QuestionType == 2) || (dataItem.QuestionType == 3)) || (((dataItem.QuestionType == 4) || (dataItem.QuestionType == 5)) || (dataItem.QuestionType == 7))) { for (int i = 0; i < dataItem.Settings.Count; i++) { builder.Append(" " + dataItem.Settings[i]); } label2.Text = builder.ToString(); } else { switch (dataItem.QuestionType) { case 0: label2.Text = " 此题为单行填空"; return; case 1: label2.Text = " 此题为多行填空"; return; case 6: label2.Text = " 此题为日期时间"; return; case 7: return; case 8: label2.Text = " 此题为数字"; return; case 9: label2.Text = " 此题为Email"; return; } } } }
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; } }
private static void RptShowCountDataBind(Repeater rptShowCountData, IList <SurveyFieldInfo> surveyFieldInfoList) { int num = 1; for (int i = 0; i < surveyFieldInfoList.Count; i++) { if (((surveyFieldInfoList[i].QuestionType == 2) || (surveyFieldInfoList[i].QuestionType == 3)) && (surveyFieldInfoList[i].InputType != 0)) { surveyFieldInfoList[i].QuestionContent = num + "、" + surveyFieldInfoList[i].QuestionContent; i++; SurveyFieldInfo item = new SurveyFieldInfo(); item.QuestionContent = "填空"; surveyFieldInfoList.Insert(i, item); } else { surveyFieldInfoList[i].QuestionContent = num + "、" + surveyFieldInfoList[i].QuestionContent; } num++; } rptShowCountData.DataSource = surveyFieldInfoList; rptShowCountData.DataBind(); }
public static string GetAddColumnToTableSql(SurveyFieldInfo surveyFieldInfo, string tableName) { int questionType = surveyFieldInfo.QuestionType; StringBuilder builder = new StringBuilder(); builder.Append("ALTER TABLE ["); builder.Append(DBHelper.FilterBadChar(tableName)); builder.Append("] ADD ["); builder.Append("Q" + surveyFieldInfo.QuestionId); builder.Append("] "); switch (questionType) { case 0: builder.Append("[nvarchar] (255)"); break; case 1: builder.Append("[ntext]"); break; case 2: builder.Append("[nvarchar] (5)"); switch (surveyFieldInfo.InputType) { case 1: builder.Append(", ["); builder.Append("Q" + surveyFieldInfo.QuestionId + "Input"); builder.Append("] "); builder.Append("[nvarchar] (255)"); break; case 2: builder.Append(", ["); builder.Append("Q" + surveyFieldInfo.QuestionId + "Input"); builder.Append("] "); builder.Append("[ntext]"); break; } break; case 3: builder.Append("[nvarchar] (50)"); switch (surveyFieldInfo.InputType) { case 1: builder.Append(", ["); builder.Append("Q" + surveyFieldInfo.QuestionId + "Input"); builder.Append("] "); builder.Append("[nvarchar] (255)"); break; case 2: builder.Append(", ["); builder.Append("Q" + surveyFieldInfo.QuestionId + "Input"); builder.Append("] "); builder.Append("[ntext]"); break; } break; case 4: builder.Append("[nvarchar] (5)"); break; case 5: builder.Append("[nvarchar] (50)"); break; case 6: builder.Append("[nvarchar] (50)"); break; case 7: builder.Append("[nvarchar] (5)"); break; case 8: builder.Append("[nvarchar] (255)"); break; case 9: builder.Append("[nvarchar] (255)"); break; } return(builder.ToString()); }
public static bool AddFieldToTable(SurveyFieldInfo surveyFieldInfo, string tableName) { return(dal.AddFieldToTable(surveyFieldInfo, DataSecurity.FilterBadChar(tableName))); }
private static string GetFormJS(SurveyFieldInfo info) { StringBuilder tempFormJs = new StringBuilder(); tempFormJs.Append(""); string problemName = "Q" + info.QuestionId.ToString(); string otherName = "Q" + info.QuestionId.ToString() + "Input"; info.QuestionContent = DataSecurity.HtmlEncode(info.QuestionContent); switch (info.QuestionType) { case 0: EnableNullJS(info, tempFormJs, problemName); ContentLengthJS(info, tempFormJs, problemName); break; case 1: EnableNullJS(info, tempFormJs, problemName); break; case 2: if (info.EnableNull) { tempFormJs.Append("var Input1=false\n"); tempFormJs.Append("for (i=0;i<document.myform." + problemName + ".length;i++) \n"); tempFormJs.Append("{Input1=Input1||document.myform." + problemName + "[i].checked;} \n"); tempFormJs.Append("if (Input1==false){alert('请选择" + info.QuestionContent + "');\n"); tempFormJs.Append("document.myform." + problemName + "[0].focus();\n"); tempFormJs.Append("return Input1};\n"); } if (info.InputType == 1) { ContentLengthJS(info, tempFormJs, otherName); } break; case 3: if (info.EnableNull) { tempFormJs.Append("var Input2=false\n"); tempFormJs.Append("for (i=0;i<document.myform." + problemName + ".length;i++) \n"); tempFormJs.Append("{Input2=Input2||document.myform." + problemName + "[i].checked;} \n"); tempFormJs.Append("document.myform." + problemName + "[0].focus();\n"); tempFormJs.Append("if (Input2==false){alert('请选择" + info.QuestionContent + "');\n"); tempFormJs.Append("return Input2};\n"); } if (info.InputType == 1) { ContentLengthJS(info, tempFormJs, otherName); } break; case 4: if (info.EnableNull) { tempFormJs.Append("if (document.myform." + problemName + ".selectedIndex==-1)\n"); tempFormJs.Append("{flag=false;alert('请选择" + info.QuestionContent + "');\n"); tempFormJs.Append("document.myform." + problemName + ".focus();return flag}\n"); } break; case 6: EnableNullJS(info, tempFormJs, problemName); break; case 7: if (info.EnableNull) { tempFormJs.Append("var Input1=false\n"); tempFormJs.Append("for (i=0;i<document.myform." + problemName + ".length;i++) \n"); tempFormJs.Append("{Input1=Input1||document.myform." + problemName + "[i].checked;} \n"); tempFormJs.Append("if (Input1==false){alert('请选择" + info.QuestionContent + "');\n"); tempFormJs.Append("document.myform." + problemName + "[0].focus();\n"); tempFormJs.Append("return Input1};\n"); } break; case 8: EnableNullJS(info, tempFormJs, problemName); tempFormJs.Append("if (document.myform." + problemName + ".value!=''&&isNaN(myform." + problemName + ".value))\n"); tempFormJs.Append("{alert('请用数字填写" + info.QuestionContent + "');\n"); tempFormJs.Append("flag=false;\n"); tempFormJs.Append("document.myform." + problemName + ".focus();\n"); tempFormJs.Append("return flag}\n"); break; case 9: EnableNullJS(info, tempFormJs, problemName); tempFormJs.Append("if (myform." + problemName + ".value!='') \n"); tempFormJs.Append("{if (myform." + problemName + ".value.length<6) {\n"); tempFormJs.Append("flag=false;\n"); tempFormJs.Append("alert('您所填的Email太短!');\n"); tempFormJs.Append("document.myform." + problemName + ".focus();\n"); tempFormJs.Append("return flag}\n"); tempFormJs.Append("if (myform." + problemName + ".value.indexOf('@')==-1||myform." + problemName + ".value.indexOf('.')==-1)\n"); tempFormJs.Append("{flag=false;\n"); tempFormJs.Append("alert('Email格式有问题,是否包含了@和.');\n"); tempFormJs.Append("document.myform." + problemName + ".focus();\n"); tempFormJs.Append("return flag}}\n"); break; } return(tempFormJs.ToString()); }
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(); } } }