| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class Naire : System.Web.UI.Page
- {
- /// <summary>
- /// 问卷编号
- /// </summary>
- public string nid = string.Empty;
- /// <summary>
- /// 用户编号
- /// </summary>
- public string uid = string.Empty;
- public string ROWGUID = string.Empty;
- /// <summary>
- /// 数据库连接字符串
- /// </summary>
- private string constr = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["constr"].ToString();
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- try
- {
- if (Request.Params["uid"].ToString() != null && Request.Params["uid"].ToString().Trim() != "")
- {
- uid = Request.Params["uid"].ToString();
- this.uids.Value=uid;
- }
- if (Request.Params["ROWGUID"].ToString() != null && Request.Params["ROWGUID"].ToString().Trim() != "")
- {
- ROWGUID = Request.Params["ROWGUID"].ToString();
- this.ROWGUIDs.Value = ROWGUID;
- //绑定题目
- if (Naireclass.CheckROWGUID(ROWGUID) != "0")
- {
- BindNaire(Naireclass.CheckROWGUID(ROWGUID));
- }
- else
- {
- Response.Redirect("404.html");
- }
- }
- }
- catch
- {
- Response.Redirect("404.html");
- }
- }
- }
- /// <summary>
- /// 动态生成问卷表单
- /// </summary>
- /// <param name="id">问卷项目编号</param>
- private void BindNaire(string id)
- {
- SqlConnection con = new SqlConnection(constr);
- con.Open();
- DataTable dt = new DataTable();
- DataTable dt2 = new DataTable();
- 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);
- sda.Fill(dt);
- 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);
- sda2.Fill(dt2);
- lbltitle.Text = dt.Rows[0]["Title"].ToString();
- //lbldescr.Text = dt.Rows[0]["Descr"].ToString();
- int sid = 1;//单选题序号
- int mid = 1;//多选题序号
- int aid = 1;//问答题序号
- if (dt2.Rows.Count > 0)
- {
- foreach (DataRow dr in dt2.Rows)
- {
- switch (dr["TypeName"].ToString())
- {
- case "单选题":
- Label lbl = new Label();
- lbl.Style["style"] = "line-height: 40px;color: #168dd9;font-size:16px;";
- lbl.Text = dr["Title"].ToString();
- RadioButtonList rbl = new RadioButtonList();
- rbl.RepeatDirection = RepeatDirection.Horizontal;
- rbl.ID = dr["Pid"].ToString();
- DataRow[] drs = dt.Select("Pid=" + dr["Pid"] + "");
- foreach (DataRow drc in drs)
- {
- ListItem li1 = new ListItem();
- li1.Text = drc["OptionValue"].ToString();
- li1.Value = drc["Oid"].ToString();
- rbl.Items.Add(li1);
- }
- if (sid == 1)
- {
- Label lblss = new Label();
- lblss.Text = "";
- lblss.Font.Bold = true;
- this.Panel1.Controls.Add(lblss);
- //this.Panel1.Controls.Add(new LiteralControl("<br/>"));
- }
- this.Panel1.Controls.Add(lbl);
- //this.Panel1.Controls.Add(new LiteralControl("<br/>"));
- this.Panel1.Controls.Add(rbl);
- this.Panel1.Controls.Add(new LiteralControl("<div class='adbd'></div>"));
- this.Panel1.Controls.Add(new LiteralControl("<br/>"));
- sid = sid + 1;
- break;
- case "多选题":
- Label lbl2 = new Label();
- lbl2.Style["style"] = "line-height: 40px;color: #168dd9;font-size:16px;";
- lbl2.Text = dr["Title"].ToString();
- CheckBoxList cbl = new CheckBoxList();
- cbl.RepeatDirection = RepeatDirection.Horizontal;
- cbl.ID = dr["Pid"].ToString();
- DataRow[] drs2 = dt.Select("Pid=" + dr["Pid"] + "");
- foreach (DataRow drc in drs2)
- {
- ListItem li2 = new ListItem();
- li2.Text = drc["OptionValue"].ToString();
- li2.Value = drc["Oid"].ToString();
- cbl.Items.Add(li2);
- }
- if (mid == 1)
- {
- Label lblms = new Label();
- lblms.Text = "";
- lblms.Font.Bold = true;
- this.Panel1.Controls.Add(lblms);
- // this.Panel1.Controls.Add(new LiteralControl("<br/>"));
- }
- this.Panel1.Controls.Add(lbl2);
- //this.Panel1.Controls.Add(new LiteralControl("<br/>"));
- this.Panel1.Controls.Add(cbl);
- //this.Panel1.Controls.Add(new LiteralControl("<br/>"));
- mid = mid + 1;
- break;
- case "问答题":
- Label lbl3 = new Label();
- lbl3.Style["style"] = "line-height: 40px;color: #168dd9;font-size:16px;";
- lbl3.Text = dr["Title"].ToString();
- TextBox txb = new TextBox();
- txb.ID = dr["Pid"].ToString();
- txb.TextMode = TextBoxMode.MultiLine;
- //txb.Width = Unit.Pixel(350);
- //txb.Height = Unit.Pixel(100);
- if (aid == 1)
- {
- Label lblas = new Label();
- lblas.Text = "";
- lblas.Font.Bold = true;
- this.Panel1.Controls.Add(lblas);
- //this.Panel1.Controls.Add(new LiteralControl("<br/>"));
- }
- this.Panel1.Controls.Add(lbl3);
- this.Panel1.Controls.Add(new LiteralControl("<br/>"));
- this.Panel1.Controls.Add(txb);
- //this.Panel1.Controls.Add(new LiteralControl("<br/>"));
- aid = aid + 1;
- break;
- }
- }
- }
- //关闭连接 释放资源
- con.Close();
- Dispose();
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- string uids = this.uids.Value;
- string nids = Naireclass.CheckROWGUID(this.ROWGUIDs.Value);
- if (nids != "1")
- {
- //bool isright = Naireclass.IsHasCarry(uids, nids);
- //if (isright)
- //{
- // Response.Write("<script>alert('您已经评价过了,不用重复提交!');location.href='Naire.aspx?uid=" + uids + "&ROWGUID=" + this.ROWGUIDs.Value + "';</script>");
- // }
- // else
- // {
- string r = this.HiddenField1.Value;
- int insertan = Naireclass.RecordResult(uids, nids, r);
- if (insertan > 0)
- {
- Response.Write("<script>alert('您已经评价成功!');location.href='Naire.aspx?uid=" + uids + "&ROWGUID=" + this.ROWGUIDs.Value + "';</script>");
- }
- else
- {
- Response.Redirect("404.html");
- }
- // }
- }
- else
- {
- string r = this.HiddenField1.Value;
- int insertan = Naireclass.RecordResult(uids, nids, r);
- if (insertan > 0)
- {
- Response.Write("<script>alert('您已经成功提交建议,谢谢您的参与!');location.href='Naire.aspx?uid=" + uids + "&ROWGUID=" + this.ROWGUIDs.Value + "';</script>");
- }
- else
- {
- Response.Redirect("404.html");
- }
- }
-
- }
- }
|