Naire.aspx.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. public partial class Naire : System.Web.UI.Page
  10. {
  11. /// <summary>
  12. /// 问卷编号
  13. /// </summary>
  14. public string nid = string.Empty;
  15. /// <summary>
  16. /// 用户编号
  17. /// </summary>
  18. public string uid = string.Empty;
  19. public string ROWGUID = string.Empty;
  20. /// <summary>
  21. /// 数据库连接字符串
  22. /// </summary>
  23. private string constr = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["constr"].ToString();
  24. protected void Page_Load(object sender, EventArgs e)
  25. {
  26. if (!Page.IsPostBack)
  27. {
  28. try
  29. {
  30. if (Request.Params["uid"].ToString() != null && Request.Params["uid"].ToString().Trim() != "")
  31. {
  32. uid = Request.Params["uid"].ToString();
  33. this.uids.Value=uid;
  34. }
  35. if (Request.Params["ROWGUID"].ToString() != null && Request.Params["ROWGUID"].ToString().Trim() != "")
  36. {
  37. ROWGUID = Request.Params["ROWGUID"].ToString();
  38. this.ROWGUIDs.Value = ROWGUID;
  39. //绑定题目
  40. if (Naireclass.CheckROWGUID(ROWGUID) != "0")
  41. {
  42. BindNaire(Naireclass.CheckROWGUID(ROWGUID));
  43. }
  44. else
  45. {
  46. Response.Redirect("404.html");
  47. }
  48. }
  49. }
  50. catch
  51. {
  52. Response.Redirect("404.html");
  53. }
  54. }
  55. }
  56. /// <summary>
  57. /// 动态生成问卷表单
  58. /// </summary>
  59. /// <param name="id">问卷项目编号</param>
  60. private void BindNaire(string id)
  61. {
  62. SqlConnection con = new SqlConnection(constr);
  63. con.Open();
  64. DataTable dt = new DataTable();
  65. DataTable dt2 = new DataTable();
  66. SqlDataAdapter sda = new SqlDataAdapter("SELECT b.ID AS Nid,b.Title,b.Descr,a.ID AS Pid,a.Title,d.TypeName,c.ID AS Oid,c.OptionValue FROM dbo.Q_Problem a LEFT JOIN dbo.Q_Naire b ON a.Nid=b.ID LEFT JOIN dbo.Q_Options c ON a.ID=c.Pid LEFT JOIN dbo.Q_ProblmeType d ON a.Tid=d.ID WHERE b.ID=" + id + "", con);
  67. sda.Fill(dt);
  68. SqlDataAdapter sda2 = new SqlDataAdapter("SELECT a.ID as Pid,a.Title,a.Nid,a.Tid,b.TypeName,b.Descr FROM dbo.Q_Problem a LEFT JOIN dbo.Q_ProblmeType b ON a.Tid=b.ID WHERE a.Nid=" + id + " ORDER BY a.Tid ASC", con);
  69. sda2.Fill(dt2);
  70. lbltitle.Text = dt.Rows[0]["Title"].ToString();
  71. //lbldescr.Text = dt.Rows[0]["Descr"].ToString();
  72. int sid = 1;//单选题序号
  73. int mid = 1;//多选题序号
  74. int aid = 1;//问答题序号
  75. if (dt2.Rows.Count > 0)
  76. {
  77. foreach (DataRow dr in dt2.Rows)
  78. {
  79. switch (dr["TypeName"].ToString())
  80. {
  81. case "单选题":
  82. Label lbl = new Label();
  83. lbl.Style["style"] = "line-height: 40px;color: #168dd9;font-size:16px;";
  84. lbl.Text = dr["Title"].ToString();
  85. RadioButtonList rbl = new RadioButtonList();
  86. rbl.RepeatDirection = RepeatDirection.Horizontal;
  87. rbl.ID = dr["Pid"].ToString();
  88. DataRow[] drs = dt.Select("Pid=" + dr["Pid"] + "");
  89. foreach (DataRow drc in drs)
  90. {
  91. ListItem li1 = new ListItem();
  92. li1.Text = drc["OptionValue"].ToString();
  93. li1.Value = drc["Oid"].ToString();
  94. rbl.Items.Add(li1);
  95. }
  96. if (sid == 1)
  97. {
  98. Label lblss = new Label();
  99. lblss.Text = "";
  100. lblss.Font.Bold = true;
  101. this.Panel1.Controls.Add(lblss);
  102. //this.Panel1.Controls.Add(new LiteralControl("<br/>"));
  103. }
  104. this.Panel1.Controls.Add(lbl);
  105. //this.Panel1.Controls.Add(new LiteralControl("<br/>"));
  106. this.Panel1.Controls.Add(rbl);
  107. this.Panel1.Controls.Add(new LiteralControl("<div class='adbd'></div>"));
  108. this.Panel1.Controls.Add(new LiteralControl("<br/>"));
  109. sid = sid + 1;
  110. break;
  111. case "多选题":
  112. Label lbl2 = new Label();
  113. lbl2.Style["style"] = "line-height: 40px;color: #168dd9;font-size:16px;";
  114. lbl2.Text = dr["Title"].ToString();
  115. CheckBoxList cbl = new CheckBoxList();
  116. cbl.RepeatDirection = RepeatDirection.Horizontal;
  117. cbl.ID = dr["Pid"].ToString();
  118. DataRow[] drs2 = dt.Select("Pid=" + dr["Pid"] + "");
  119. foreach (DataRow drc in drs2)
  120. {
  121. ListItem li2 = new ListItem();
  122. li2.Text = drc["OptionValue"].ToString();
  123. li2.Value = drc["Oid"].ToString();
  124. cbl.Items.Add(li2);
  125. }
  126. if (mid == 1)
  127. {
  128. Label lblms = new Label();
  129. lblms.Text = "";
  130. lblms.Font.Bold = true;
  131. this.Panel1.Controls.Add(lblms);
  132. // this.Panel1.Controls.Add(new LiteralControl("<br/>"));
  133. }
  134. this.Panel1.Controls.Add(lbl2);
  135. //this.Panel1.Controls.Add(new LiteralControl("<br/>"));
  136. this.Panel1.Controls.Add(cbl);
  137. //this.Panel1.Controls.Add(new LiteralControl("<br/>"));
  138. mid = mid + 1;
  139. break;
  140. case "问答题":
  141. Label lbl3 = new Label();
  142. lbl3.Style["style"] = "line-height: 40px;color: #168dd9;font-size:16px;";
  143. lbl3.Text = dr["Title"].ToString();
  144. TextBox txb = new TextBox();
  145. txb.ID = dr["Pid"].ToString();
  146. txb.TextMode = TextBoxMode.MultiLine;
  147. //txb.Width = Unit.Pixel(350);
  148. //txb.Height = Unit.Pixel(100);
  149. if (aid == 1)
  150. {
  151. Label lblas = new Label();
  152. lblas.Text = "";
  153. lblas.Font.Bold = true;
  154. this.Panel1.Controls.Add(lblas);
  155. //this.Panel1.Controls.Add(new LiteralControl("<br/>"));
  156. }
  157. this.Panel1.Controls.Add(lbl3);
  158. this.Panel1.Controls.Add(new LiteralControl("<br/>"));
  159. this.Panel1.Controls.Add(txb);
  160. //this.Panel1.Controls.Add(new LiteralControl("<br/>"));
  161. aid = aid + 1;
  162. break;
  163. }
  164. }
  165. }
  166. //关闭连接 释放资源
  167. con.Close();
  168. Dispose();
  169. }
  170. protected void Button1_Click(object sender, EventArgs e)
  171. {
  172. string uids = this.uids.Value;
  173. string nids = Naireclass.CheckROWGUID(this.ROWGUIDs.Value);
  174. if (nids != "1")
  175. {
  176. //bool isright = Naireclass.IsHasCarry(uids, nids);
  177. //if (isright)
  178. //{
  179. // Response.Write("<script>alert('您已经评价过了,不用重复提交!');location.href='Naire.aspx?uid=" + uids + "&ROWGUID=" + this.ROWGUIDs.Value + "';</script>");
  180. // }
  181. // else
  182. // {
  183. string r = this.HiddenField1.Value;
  184. int insertan = Naireclass.RecordResult(uids, nids, r);
  185. if (insertan > 0)
  186. {
  187. Response.Write("<script>alert('您已经评价成功!');location.href='Naire.aspx?uid=" + uids + "&ROWGUID=" + this.ROWGUIDs.Value + "';</script>");
  188. }
  189. else
  190. {
  191. Response.Redirect("404.html");
  192. }
  193. // }
  194. }
  195. else
  196. {
  197. string r = this.HiddenField1.Value;
  198. int insertan = Naireclass.RecordResult(uids, nids, r);
  199. if (insertan > 0)
  200. {
  201. Response.Write("<script>alert('您已经成功提交建议,谢谢您的参与!');location.href='Naire.aspx?uid=" + uids + "&ROWGUID=" + this.ROWGUIDs.Value + "';</script>");
  202. }
  203. else
  204. {
  205. Response.Redirect("404.html");
  206. }
  207. }
  208. }
  209. }