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 { /// /// 问卷编号 /// public string nid = string.Empty; /// /// 用户编号 /// public string uid = string.Empty; public string ROWGUID = string.Empty; /// /// 数据库连接字符串 /// 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"); } } } /// /// 动态生成问卷表单 /// /// 问卷项目编号 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("
")); } this.Panel1.Controls.Add(lbl); //this.Panel1.Controls.Add(new LiteralControl("
")); this.Panel1.Controls.Add(rbl); this.Panel1.Controls.Add(new LiteralControl("
")); this.Panel1.Controls.Add(new LiteralControl("
")); 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("
")); } this.Panel1.Controls.Add(lbl2); //this.Panel1.Controls.Add(new LiteralControl("
")); this.Panel1.Controls.Add(cbl); //this.Panel1.Controls.Add(new LiteralControl("
")); 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("
")); } this.Panel1.Controls.Add(lbl3); this.Panel1.Controls.Add(new LiteralControl("
")); this.Panel1.Controls.Add(txb); //this.Panel1.Controls.Add(new LiteralControl("
")); 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(""); // } // else // { string r = this.HiddenField1.Value; int insertan = Naireclass.RecordResult(uids, nids, r); if (insertan > 0) { Response.Write(""); } else { Response.Redirect("404.html"); } // } } else { string r = this.HiddenField1.Value; int insertan = Naireclass.RecordResult(uids, nids, r); if (insertan > 0) { Response.Write(""); } else { Response.Redirect("404.html"); } } } }