예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!this.CheckPage()) return;
                service.Open();
                Dictionary<Question, AnswerMapTitle> questionSV = service.getQuestion(this.page);
                AddForm form = new AddForm("panel-body");
                ViewState["Page"] = this.page;
                int i = 1;
                int questionId = 0;
                StringBuilder strSeq = new StringBuilder();
                if (Session["answer"] != null)
                {
                    sess = Session["answer"] as Dictionary<string, string>;
                }

                if (questionSV.Count > 0)
                {
                    if (questionSV.First().Key.Seq <= 33)
                    {
                        Label1.Text = "ส่วนที่ 1 : ชุดคำถามหลัก";
                    }
                    else
                    {
                        Label1.Text = "ส่วนที่ 2: ชุดคำถามเพิ่มเติม";
                    }
                }
                foreach (KeyValuePair<Question, AnswerMapTitle> q in questionSV)
                {
                    Question question = q.Key;
                    AnswerMapTitle map = q.Value;
                    string remark = "";
                    if (q.Value.remark != null)
                    {
                        remark = "<div class='panel panel-primary'>"
                                      + "<div class='panel-body'>"
                                      + "<div class='row'>"
                                      + "<div class='col-sm-1'>"
                                      + "<div style='font-weight:bold;'>หมายเหตุ</div>"
                                      + "</div>"
                                      + "<div class='col-sm-11'>"
                                      + q.Value.remark.RemarkDetail
                                      + "</div></div></div></div>";
                    }
                    if (!question.Type.Equals("SLIDE") && !question.Type.Equals("TABLESEQUENE"))
                    {
                        if (q.Value.remark != null)
                        {
                            if (q.Value.remark.UpDown.ToString().Equals("Y"))
                            {
                                form.Controls.Add(new LiteralControl(remark));
                            }
                        }
                        if (question.QuestionId == 22)
                        {
                            foreach (var isess in sess)
                            {
                                if (isess.Key.ToUpper().IndexOf("QPROD1_C") != -1)
                                {
                                    if (!string.IsNullOrEmpty(isess.Value))
                                    {
                                        if (Convert.ToInt32(isess.Value) > 0)
                                        {
                                            question.Visible = "Y";
                                        }
                                    }
                                }
                            }
                        }
                        if (question.QuestionId == 1046 || question.QuestionId == 1047 || question.QuestionId == 1048 || question.QuestionId == 1049)
                        {
                            if (sess.ContainsKey("Qprod1_b_18") || sess.ContainsKey("Qprod1_b_19"))
                            {
                                question.Visible = "Y";
                            }
                        }

                        form.Controls.Add(new LiteralControl("<div id='num-" + question.QuestionId + "' class='num-cl' type-div='" + question.Type + "'" + (question.Visible.Equals("Y") ? "" : "style='display:none;'") + ">"));
                        form.Controls.Add(new LiteralControl("<label>" + question.Seq + ". " + question.QuestionName + "</label>"));
                        if(!string.IsNullOrEmpty(remark))
                        {
                            if (q.Value.remark.UpDown.ToString().Equals("N"))
                            {
                                form.Controls.Add(new LiteralControl(remark));
                            }
                        }
                    }
                    strSeq.Append(question.Seq).Append(",");
                    List<ListItem> listItem = new List<ListItem>();
                    int cntVal = map.ListAns.Length;
                    if (question.Type.Equals("CHECKBOX"))
                    {
                        HiddenField hid = new HiddenField();
                        hid.Value = question.No;
                        form.Controls.Add(hid);
                        foreach (Answer ans in map.ListAns)
                        {
                            if (string.IsNullOrEmpty(ans.Script))
                            {
                                form.AddCheckbox(ans.AnswerName, ans.Point.ToString(), ans.SubAnswer, getValueSessCheckbox(ans));
                            }
                            else
                            {
                                form.AddCheckbox(ans.AnswerName, ans.Point.ToString(), ans.SubAnswer, ans.Script, getValueSessCheckbox(ans));
                            }
                        }
                    }
                    else if (question.Type.Equals("RADIO"))
                    {
                        foreach (Answer ans in map.ListAns)
                        {
                            form.AddRadio(ans.AnswerName, ans.VarId);
                        }
                    }
                    else if (question.Type.Equals("RADIOLIST"))
                    {
                        int j = 1;
                        string index = "";
                        foreach (Answer ans in map.ListAns)
                        {
                            ListItem Litem = new ListItem();
                            if (ans.SubAnswer != null)
                            {
                                switch (ans.SubAnswer.SubAnswerType)
                                {
                                    case "TEXTBOX":
                                        string valsub = (sess.ContainsKey(ans.SubAnswer.SubVarId)) ? sess[ans.SubAnswer.SubVarId].ToString() : "";
                                        string scriptsub = (ans.SubAnswer.Script != null) ? "onkeyup='" + ans.SubAnswer.Script + "'" : "";
                                        Litem.Text = ans.AnswerName + " (" + ans.SubAnswer.SubAnswerName + " <input type='text' id='" + ans.SubAnswer.SubVarId + "' value='" + valsub + "'name='" + ans.SubAnswer.SubVarId + "' " + scriptsub + "> )";
                                        break;
                                }
                            }
                            else
                            {
                                Litem.Text = ans.AnswerName;
                            }

                            Litem.Value = ans.Point.ToString();
                            listItem.Add(Litem);
                            if (sess.ContainsKey(ans.VarId))
                            {
                                if(!string.IsNullOrEmpty(sess[ans.VarId]))
                                {
                                    if(Convert.ToInt32(sess[ans.VarId]) == ans.Point)
                                    {
                                        index = (j - 1).ToString();
                                    }
                                }

                            }
                            if (cntVal == j)
                            {
                                if (string.IsNullOrEmpty(ans.Script))
                                {
                                    form.AddRadioList(listItem, ans.VarId, index);
                                }
                                else
                                {
                                    form.AddRadioList(listItem, ans.VarId, ans.Script, index);
                                }
                            }
                            j++;
                        }
                    }
                    else if (question.Type.Equals("TEXTBOX"))
                    {
                        foreach (Answer ans in map.ListAns)
                        {
                            string valtext = "";
                            if (sess.ContainsKey(ans.VarId))
                            {
                                valtext = sess[ans.VarId].ToString();
                            }
                            if (string.IsNullOrEmpty(ans.Script))
                            {
                                form.AddTextbox(ans.VarId, ans.CssClass, valtext);
                            }
                            else
                            {
                                form.AddTextbox(ans.VarId, ans.CssClass, ans.Script, valtext);
                            }
                        }
                    }
                    else if (question.Type.Equals("DROPDOWNANDRADIOLIST"))
                    {
                        int j = 1;
                        string index = "";
                        foreach (Answer ans in map.ListAns)
                        {
                            if (ans.AnswerType.Equals("DROPDOWN"))
                            {
                                Item[] dropdown = service.getDropdown(ans.AnswerName);
                                string selected = "";
                                if (sess.ContainsKey(ans.VarId))
                                {
                                    int k = 0;
                                    foreach (Item it in dropdown)
                                    {
                                        if (it.value.Equals(sess[ans.VarId]))
                                        {
                                            selected = k.ToString();
                                        }
                                        k++;
                                    }
                                }
                                form.AddDropDown(dropdown, "col-sm-3", ans.Script, selected);
                            }
                            else
                            {
                                int p = 0;
                                ListItem item = new ListItem();
                                item.Text = ans.AnswerName;
                                item.Value = ans.Point.ToString();
                                listItem.Add(item);
                                if (sess.ContainsKey(ans.VarId))
                                {
                                    if (!string.IsNullOrEmpty(sess[ans.VarId]))
                                    {
                                        if (Convert.ToInt32(sess[ans.VarId]) == ans.Point)
                                        {
                                            index = p.ToString();
                                        }
                                    }

                                }
                                p++;
                                if (cntVal == j)
                                {
                                    if (string.IsNullOrEmpty(ans.Script))
                                    {
                                        form.AddRadioList(listItem, ans.VarId, index);
                                    }
                                    else
                                    {
                                        form.AddRadioList(listItem, ans.VarId, ans.Script, index);
                                    }
                                }
                            }
                            j++;
                        }
                    }
                    else if (question.Type.Equals("TEXTBOXANDRADIOLIST"))
                    {
                        int j = 1;
                        string index = "";
                        int k = 0;
                        foreach (Answer ans in map.ListAns)
                        {
                            if (ans.AnswerType.Equals("TEXTBOX"))
                            {
                                string valtext = "";
                                if (sess.ContainsKey(ans.VarId))
                                {
                                    valtext = sess[ans.VarId].ToString();
                                }
                                if (string.IsNullOrEmpty(ans.Script))
                                {
                                    form.AddTextbox(ans.VarId, ans.CssClass, valtext);
                                }
                                else
                                {
                                    form.AddTextbox(ans.VarId, ans.CssClass, ans.Script, valtext);
                                }
                            }
                            else
                            {
                                ListItem item = new ListItem();
                                item.Text = ans.AnswerName;
                                item.Value = ans.Point.ToString();
                                listItem.Add(item);
                                if (sess.ContainsKey(ans.VarId))
                                {
                                    if (!string.IsNullOrEmpty(sess[ans.VarId]))
                                    {
                                        if (Convert.ToInt32(sess[ans.VarId]) == ans.Point)
                                        {
                                            index = k.ToString();
                                        }
                                    }

                                }
                                if (cntVal == j)
                                {
                                    if (string.IsNullOrEmpty(ans.Script))
                                    {
                                        form.AddRadioList(listItem, ans.VarId, index);
                                    }
                                    else
                                    {
                                        form.AddRadioList(listItem, ans.VarId, ans.Script, index);
                                    }
                                }
                                k++;
                            }
                            j++;
                        }
                    }
                    else if (question.Type.Equals("TABLE"))
                    {
                        string table = "";
                        table += "<div class='row'>";
                        table += "<div class='" + question.CssClass + "'>";
                        switch (question.QuestionId)
                        {
                            case 24:
                            case 1033:

                                table += "<table class='table table-bordered'>";
                                table += "<thead>";
                                table += "<tr>";
                                table += "<th></th>";
                                table += "<th>เห็นด้วยอย่างมาก</th>";
                                table += "<th>เห็นด้วย</th>";
                                table += "<th>ปานกลาง</th>";
                                table += "<th>ไม่เห็นด้วย</th>";
                                table += "<th>ไม่เห็นด้วยอย่างมาก</th>";
                                table += "<th align='center'>ไม่ทราบ</th>";
                                table += "</tr>";
                                table += "<tbody>";
                                foreach (Answer ans in map.ListAns)
                                {
                                    string select_1 = "", select_2 = "", select_3 = "", select_4 = "", select_5 = "", select_97 = "";
                                    if (sess.ContainsKey(ans.VarId))
                                    {
                                        if (sess[ans.VarId].ToString() != "")
                                        {
                                            if (sess[ans.VarId].ToString().Equals("1"))
                                            {
                                                select_1 = "checked";
                                            }
                                            else if (sess[ans.VarId].ToString().Equals("2"))
                                            {
                                                select_2 = "checked";
                                            }
                                            else if (sess[ans.VarId].ToString().Equals("3"))
                                            {
                                                select_3 = "checked";
                                            }
                                            else if (sess[ans.VarId].ToString().Equals("4"))
                                            {
                                                select_4 = "checked";
                                            }
                                            else if (sess[ans.VarId].ToString().Equals("5"))
                                            {
                                                select_5 = "checked";
                                            }
                                            else if (sess[ans.VarId].ToString().Equals("-97"))
                                            {
                                                select_97 = "checked";
                                            }
                                        }
                                    }
                                    table += "<tr>";
                                    table += "<td class='pointer' data-name='" + ans.VarId + "'>" + ans.AnswerName + "</td>";
                                    table += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='1' " + select_1 + "></td>";
                                    table += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='2' " + select_2 + "></td>";
                                    table += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='3' " + select_3 + "></td>";
                                    table += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='4' " + select_4 + "></td>";
                                    table += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='5' " + select_5 + "></td>";
                                    table += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='-97' " + select_97 + "></td>";
                                    table += "</tr>";
                                }
                                table += "</tbody>";
                                table += "</table>";
                                break;
                            case 1027:
                            case 1028:
                                table += "<table class='table table-bordered'>";
                                table += "<thead>";
                                table += "<tr>";
                                table += "<th></th>";
                                table += "<th align='center'>ถูกต้อง</th>";
                                table += "<th align='center'>ไม่ถูกต้อง</th>";
                                table += "<th align='center'>ไม่ทราบ</th>";
                                table += "<th align='center'>ปฏิเสธการตอบ</th>";
                                table += "</tr>";
                                table += "<tbody>";
                                foreach (Answer ans in map.ListAns)
                                {
                                    string select_1 = "", select_0 = "", select_97 = "", select_99 = "";
                                    if (sess.ContainsKey(ans.VarId))
                                    {
                                        if (sess[ans.VarId].ToString() != "")
                                        {
                                            if (sess[ans.VarId].ToString().Equals("1"))
                                            {
                                                select_1 = "checked";
                                            }
                                            else if (sess[ans.VarId].ToString().Equals("0"))
                                            {
                                                select_0 = "checked";
                                            }
                                            else if (sess[ans.VarId].ToString().Equals("-97"))
                                            {
                                                select_97 = "checked";
                                            }
                                            else if (sess[ans.VarId].ToString().Equals("-99"))
                                            {
                                                select_99 = "checked";
                                            }
                                        }
                                    }
                                    table += "<tr>";
                                    table += "<td class='pointer' data-name='" + ans.VarId + "'>" + ans.AnswerName + "</td>";
                                    table += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='1' " + select_1 + "></td>";
                                    table += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='0' " + select_0 + "></td>";
                                    table += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='-97' " + select_97 + "></td>";
                                    table += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='-99' " + select_99 + "></td>";
                                    table += "</tr>";
                                }
                                table += "</tbody>";
                                table += "</table>";
                                break;
                        }
                        table += "</div>";
                        table += "</div>";
                        form.Controls.Add(new LiteralControl(table));
                    }
                    else if (question.Type.Equals("YESORNO"))
                    {
                        string table = "";
                        table += "<div class='row'>";
                        table += "<div class='" + question.CssClass + "'>";
                        table += "<table class='table table-bordered'>";
                        table += "<thead>";
                        table += "<tr>";
                        table += "<th style='width:70px;text-align:center;'>ใช่/ไม่ใช่</th>";
                        table += "<th></th>";
                        table += "</tr>";
                        table += "</thead>";
                        table += "<tbody>";
                        int j = 0;
                        if (map.ListTitle.Length > 0)
                        {
                            Dictionary<TitleAnswer, List<Answer>> tmp = arrTitleAnswer(map);
                            foreach (var item in tmp)
                            {
                                table += "<tr><th></th><th colspan='2'>" + item.Key.TiTleName + "</th></tr>";
                                foreach (Answer ans in item.Value)
                                {
                                    table += "<tr class='pointer' data-name='" + ans.VarId + "' data-num='" + ans.QuestionId + "'>";
                                    string check = "";
                                    if (sess.ContainsKey(ans.VarId))
                                    {
                                        if (!string.IsNullOrEmpty(sess[ans.VarId]) && sess[ans.VarId].ToString() != "0")
                                        {
                                            check = "checked";
                                        }
                                    }
                                    table += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='" + ans.Point + "' " + check + "></td>";
                                    if (ans.SubAnswer != null)
                                    {
                                        string valsub = (sess.ContainsKey(ans.SubAnswer.SubVarId)) ? sess[ans.SubAnswer.SubVarId].ToString() : "";
                                        string scriptsub = (ans.SubAnswer.Script != null) ? "onkeyup='" + ans.SubAnswer.Script + "'" : "";
                                        table += "<td>" + ans.AnswerName + " (" + ans.SubAnswer.SubAnswerName + " <input type='text' id='" + ans.SubAnswer.SubVarId + "' value='" + valsub + "' name='" + ans.SubAnswer.SubVarId + "' " + scriptsub + "> )</td>";
                                    }
                                    else
                                    {
                                        table += "<td>" + ans.AnswerName + "</td>";
                                    }
                                    table += "</tr>";
                                    j++;
                                }
                            }
                        }
                        else
                        {
                            foreach (Answer ans in map.ListAns)
                            {
                                table += "<tr class='pointer' data-name='" + ans.VarId + "'>";
                                string check = "";
                                if (sess.ContainsKey(ans.VarId))
                                {
                                    if (!string.IsNullOrEmpty(sess[ans.VarId]) && sess[ans.VarId].ToString() != "0")
                                    {
                                        check = "checked";
                                    }
                                }
                                table += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='" + ans.Point + "' " + check + "></td>";
                                if (ans.SubAnswer != null)
                                {
                                    string valsub = (sess.ContainsKey(ans.SubAnswer.SubVarId)) ? sess[ans.SubAnswer.SubVarId].ToString() : "";
                                    string scriptsub = (ans.SubAnswer.Script != null) ? "onkeyup='" + ans.SubAnswer.Script + "'" : "";
                                    table += "<td>" + ans.AnswerName + " (" + ans.SubAnswer.SubAnswerName + " <input type='text' id='" + ans.SubAnswer.SubVarId + "' value='" + valsub + "' name='" + ans.SubAnswer.SubVarId + "' " + scriptsub + "'> )</td>";
                                }
                                else
                                {
                                    table += "<td>" + ans.AnswerName + "</td>";
                                }
                                table += "</tr>";
                            }
                        }

                        table += "</tbody>";
                        table += "</table>";
                        table += "</div>";
                        table += "</div>";
                        form.Controls.Add(new LiteralControl(table));
                    }
                    else if (question.Type.Equals("SLIDE"))
                    {
                        Dictionary<string, int> quesionNameForSlideDefault = new Dictionary<string, int>();
                        string str = "";
                        str += "<div class='row' id='row-slide'>";
                        str += "<div id='num-" + question.QuestionId + "' class='num-cl' type-div='" + question.Type + "'" + (question.Visible.Equals("Y") ? "" : "style='display:none;") + "'>";
                        str += "<div class='" + question.CssClass + "'>";
                        str += "<div id='slider' class='form'>";
                        str += remark;
                        str += "<div data-id='slider" + question.QuestionId + "'>";
                        str += "<label>" + question.Seq + ". " + question.QuestionName + "</label>";
                        str += "<table class='table table-bordered'>";
                        str += "<thead><tr>";
                        str += "<th style='width:70px;text-align:center;'>ใช่/ไม่ใช่</th>";
                        str += "<th></th>";
                        str += "</tr></thead>";
                        str += "<tbody>";
                        foreach (Answer ans in map.ListAns)
                        {
                            string check = "";
                            if (question.QuestionId == 1051 || question.QuestionId == 1052 || question.QuestionId == 1053)
                            {
                                if (sess.ContainsKey("Qprod1_a_" + ans.Seq))
                                {
                                    if (!sess["Qprod1_a_" + ans.Seq].ToString().Equals("0"))
                                    {
                                        str += "<tr class='pointer' data-name='" + ans.VarId + "' data-num='" + ans.QuestionId + "'>";
                                        if (sess.ContainsKey(ans.VarId))
                                        {
                                            if (!string.IsNullOrEmpty(sess[ans.VarId]) && sess[ans.VarId].ToString() != "0")
                                            {
                                                check = "checked";
                                            }
                                        }
                                        str += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='" + ans.Point + "' " + check + " ></td>";
                                        if (ans.SubAnswer != null)
                                        {
                                            string valsub = (sess.ContainsKey("Qprod1_a_20_txt")) ? sess["Qprod1_a_20_txt"] : "";
                                            valsub = (sess.ContainsKey(ans.SubAnswer.SubVarId)) ? sess[ans.SubAnswer.SubVarId].ToString() : valsub;
                                            string scriptsub = (ans.SubAnswer.Script != null) ? "onkeyup='" + ans.SubAnswer.Script + "'" : "";
                                            str += "<td>" + ans.AnswerName + " (" + ans.SubAnswer.SubAnswerName + " <input type='text' id='" + ans.SubAnswer.SubVarId + "' value='" + valsub + "' name='" + ans.SubAnswer.SubVarId + "' " + scriptsub + "'> )</td>";
                                        }
                                        else
                                        {
                                            str += "<td>" + ans.AnswerName + "</td>";
                                        }
                                        str += "</tr>";
                                    }
                                }
                                else
                                {
                                    if (ans.Point == -98)
                                    {
                                        str += "<tr class='pointer' data-name='" + ans.VarId + "' data-num='" + ans.QuestionId + "'>";
                                        if (sess.ContainsKey(ans.VarId))
                                        {
                                            if (!string.IsNullOrEmpty(sess[ans.VarId]) && sess[ans.VarId].ToString() != "0")
                                            {
                                                check = "checked";
                                            }
                                        }
                                        str += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='" + ans.Point + "' " + check + "></td>";
                                        if (ans.SubAnswer != null)
                                        {
                                            string valsub = (sess.ContainsKey(ans.SubAnswer.SubVarId)) ? sess[ans.SubAnswer.SubVarId].ToString() : "";
                                            string scriptsub = (ans.SubAnswer.Script != null) ? "onkeyup='" + ans.SubAnswer.Script + "'" : "";
                                            str += "<td>" + ans.AnswerName + " (" + ans.SubAnswer.SubAnswerName + " <input type='text' id='" + ans.SubAnswer.SubVarId + "' value='" + valsub + "' name='" + ans.SubAnswer.SubVarId + "' " + scriptsub + "'> )</td>";
                                        }
                                        else
                                        {
                                            str += "<td>" + ans.AnswerName + "</td>";
                                        }
                                        str += "</tr>";
                                    }
                                }
                            }
                            else
                            {
                                str += "<tr class='pointer' data-name='" + ans.VarId + "' data-num='" + ans.QuestionId + "'>";
                                if (sess.ContainsKey(ans.VarId))
                                {
                                    if (!string.IsNullOrEmpty(sess[ans.VarId]) && sess[ans.VarId].ToString() != "0")
                                    {
                                        check = "checked";
                                    }
                                }
                                str += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='" + ans.Point + "' " + check + "></td>";
                                if (ans.SubAnswer != null)
                                {
                                    string valsub = (sess.ContainsKey(ans.SubAnswer.SubVarId)) ? sess[ans.SubAnswer.SubVarId].ToString() : "";
                                    string scriptsub = (ans.SubAnswer.Script != null) ? "onkeyup='" + ans.SubAnswer.Script + "'" : "";
                                    str += "<td>" + ans.AnswerName + " (" + ans.SubAnswer.SubAnswerName + " <input type='text' id='" + ans.SubAnswer.SubVarId + "' value='" + valsub + "'name='" + ans.SubAnswer.SubVarId + "' " + scriptsub + "'> )</td>";
                                }
                                else
                                {
                                    str += "<td>" + ans.AnswerName + "</td>";
                                }
                                str += "</tr>";
                            }
                        }
                        str += "</tbody>";
                        str += "</table>";
                        str += "</div>";
                        str += "</div>";
                        str += "</div>";
                        str += "</div>";
                        str += "</div>";
                        form.Controls.Add(new LiteralControl(str));
                    }
                    else if (question.Type.Equals("TABLESEQUENE"))
                    {
                        string str = "";
                        str += "<div class='row' id='row-sequene'>";
                        str += "<div id='num-" + question.QuestionId + "' class='num-cl' type-div='" + question.Type + "'" + (question.Visible.Equals("Y") ? "" : "style='display:none;") + "'>";
                        str += "<div class='" + question.CssClass + "'>";
                        str += "<div id='slider' class='form'>";
                        str += "<div data-id='slider" + question.QuestionId + "'>";
                        str += "<label>" + question.Seq + ". " + question.QuestionName + "</label>";
                        str += "<table class='table table-bordered'>";
                        str += "<thead><tr>";
                        str += "<th style='width:70px;text-align:center;'>ใช่/ไม่ใช่</th>";
                        str += "<th></th>";
                        str += "</tr></thead>";
                        str += "<tbody>";
                        if (question.QuestionId == 1040)
                        {
                            Dictionary<TitleAnswer, List<Answer>> tmp = arrTitleAnswer(map);
                            foreach (var item in tmp)
                            {
                                str += "<tr><th></th><th colspan='2'>" + item.Key.TiTleName + "</th></tr>";
                                foreach(Answer ans in item.Value)
                                {
                                    str += "<tr class='pointer' data-name='" + ans.VarId + "' data-num='" + ans.QuestionId + "'>";
                                    string check = "";
                                    if (sess.ContainsKey(ans.VarId))
                                    {
                                        if (!string.IsNullOrEmpty(sess[ans.VarId]) && sess[ans.VarId].ToString() != "0")
                                        {
                                            check = "checked";
                                        }
                                    }
                                    str += "<td align='center'><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='" + ans.Point + "' " + check + "></td>";
                                    if (ans.SubAnswer != null)
                                    {
                                        string valsub = (sess.ContainsKey(ans.SubAnswer.SubVarId)) ? sess[ans.SubAnswer.SubVarId].ToString() : "";
                                        string scriptsub = (ans.SubAnswer.Script != null) ? "onkeyup='" + ans.SubAnswer.Script + "'" : "";
                                        str += "<td>" + ans.AnswerName + " (" + ans.SubAnswer.SubAnswerName + " <input type='text' id='" + ans.SubAnswer.SubVarId + "' value='" + valsub + "' name='" + ans.SubAnswer.SubVarId + "' " + scriptsub + "'> )</td>";
                                    }
                                    else
                                    {
                                        str += "<td>" + ans.AnswerName + "</td>";
                                    }
                                    str += "</tr>";
                                }
                            }
                        }
                        else if (question.QuestionId == 1041)
                        {
                            int check = 0;
                            foreach (var item in map.ListAns)
                            {
                                string[] x = item.VarId.Split('_');
                                if (sess.ContainsKey("QA11_" + x.Last()))
                                {
                                    if (Convert.ToInt32(sess["QA11_" + x.Last()]) == 1)
                                    {
                                        check++;
                                        if (check > 2) break;
                                    }
                                }
                            }
                            Dictionary<TitleAnswer, List<Answer>> tmp = arrTitleAnswer(map);
                            foreach (var item in tmp)
                            {
                                string tmpTitle = "<tr><th></th><th colspan='2'>" + item.Key.TiTleName + "</th></tr>";
                                string tmpStr = "";

                                foreach (Answer ans in item.Value)
                                {
                                    string[] x = ans.VarId.Split('_');
                                    if (sess.ContainsKey("QA11_" + x.Last()))
                                    {
                                        if (!string.IsNullOrEmpty(sess["QA11_" + x.Last()]))
                                        {
                                            if (Convert.ToInt32(sess["QA11_" + x.Last()]) == 1)
                                            {
                                                tmpStr += "<tr>";
                                                string select_1 = "", select_2 = "", select_3 = "";
                                                if (sess.ContainsKey(ans.VarId))
                                                {
                                                    if (sess[ans.VarId].ToString() != "0" && sess[ans.VarId].ToString() != "")
                                                    {
                                                        if (sess[ans.VarId].ToString().Equals("1"))
                                                        {
                                                            select_1 = "selected";
                                                        }
                                                        else if (sess[ans.VarId].ToString().Equals("2"))
                                                        {
                                                            select_2 = "selected";
                                                        }
                                                        else if (sess[ans.VarId].ToString().Equals("3"))
                                                        {
                                                            select_3 = "selected";
                                                        }
                                                    }
                                                }
                                                tmpStr += "<td align='center'><select onchange=selectNum('" + question.QuestionId + "',this); id='" + ans.VarId + "' name='" + ans.VarId + "'>";
                                                tmpStr += "<option value=''>-- เลือกลำดับ --</option>";
                                                tmpStr += "<option value='1' " + select_1 + ">1</option>";
                                                tmpStr += "<option value='2' " + select_2 + ">2</option>";
                                                if (check > 2) tmpStr += "<option value='3' " + select_3 + ">3</option>";
                                                tmpStr += "</select>";
                                                tmpStr += "</td>";
                                                if (ans.SubAnswer != null)
                                                {
                                                    string valsub = (sess.ContainsKey(ans.SubAnswer.SubVarId)) ? sess[ans.SubAnswer.SubVarId].ToString() : "";
                                                    string scriptsub = (ans.SubAnswer.Script != null) ? "onkeyup='" + ans.SubAnswer.Script + "'" : "";
                                                    tmpStr += "<td>" + ans.AnswerName + " (" + ans.SubAnswer.SubAnswerName + " <input type='text' id='" + ans.SubAnswer.SubVarId + "' value='" + valsub + "' name='" + ans.SubAnswer.SubVarId + "' " + scriptsub + "'> )</td>";
                                                }
                                                else
                                                {
                                                    tmpStr += "<td>" + ans.AnswerName + "</td>";
                                                }
                                                tmpStr += "</tr>";
                                            }
                                        }
                                    }
                                }
                                if (!string.IsNullOrEmpty(tmpStr))
                                {
                                    str += tmpTitle + tmpStr;
                                }
                            }
                        }
                        str += "</tbody>";
                        str += "</table>";
                        str += "</div>";
                        str += "</div>";
                        str += "</div>";
                        str += "</div>";
                        str += "</div>";
                        form.Controls.Add(new LiteralControl(str));
                    }
                    else if (question.Type.Equals("SEQUENE"))
                    {
                        string str = "";
                        str += "<div class='row'>";
                        str += "<div class='" + question.CssClass + "'>";
                        str += "<div id='slider' class='form'>";
                        str += "<div data-id='slider" + question.QuestionId + "'>";
                        str += "<table class='table table-bordered'>";
                        str += "<thead><tr>";
                        str += "<th></th>";
                        str += "<th align='center'>ลำดับ</th>";
                        str += "</tr></thead>";
                        str += "<tbody>";
                        foreach (Answer ans in map.ListAns)
                        {
                            str += "<tr>";
                            if (ans.SubAnswer != null)
                            {
                                string valsub = (sess.ContainsKey(ans.SubAnswer.SubVarId)) ? sess[ans.SubAnswer.SubVarId].ToString() : "";
                                string scriptsub = (ans.SubAnswer.Script != null) ? "onkeyup='" + ans.SubAnswer.Script + "'" : "";
                                str += "<td>" + ans.AnswerName + " (" + ans.SubAnswer.SubAnswerName + " <input type='text' id='" + ans.SubAnswer.SubVarId + "' value='" + valsub + "' name='" + ans.SubAnswer.SubVarId + "' " + scriptsub + "'> )</td>";
                            }
                            else
                            {
                                str += "<td>" + ans.AnswerName + "</td>";
                            }
                            string select_1 = "", select_2 = "", select_3 = "";
                            if (sess.ContainsKey(ans.VarId))
                            {
                                if (sess[ans.VarId].ToString() != "0" && sess[ans.VarId].ToString() != "")
                                {
                                    if (sess[ans.VarId].ToString().Equals("1"))
                                    {
                                        select_1 = "selected";
                                    }
                                    else if (sess[ans.VarId].ToString().Equals("2"))
                                    {
                                        select_2 = "selected";
                                    }
                                    else if (sess[ans.VarId].ToString().Equals("3"))
                                    {
                                        select_3 = "selected";
                                    }
                                }
                            }
                            str += "<td align='center'><select onchange=selectNum('" + question.QuestionId + "',this); id='" + ans.VarId + "' name='" + ans.VarId + "'>";
                            str += "<option value=''>-- เลือกลำดับ --</option>";
                            str += "<option value='1' " + select_1 + ">1</option>";
                            str += "<option value='2' " + select_2 + ">2</option>";
                            str += "<option value='3' " + select_3 + ">3</option>";
                            str += "</select>";
                            str += "</tr>";
                        }
                        str += "</tbody>";
                        str += "</table>";
                        str += "</div>";
                        str += "</div>";
                        str += "</div>";
                        str += "</div>";
                        form.Controls.Add(new LiteralControl(str));
                    }
                    else if (question.Type.Equals("FLOW"))
                    {
                        switch (question.QuestionId)
                        {
                            case 9:
                                HiddenField hid = new HiddenField();
                                hid.Value = question.No;
                                form.Controls.Add(hid);
                                form.Controls.Add(new LiteralControl("<div class='form-group left-15'><label>เลือกพื้นที่จังหวัดของท่าน</label>"));
                                Item[] dropdown = service.getDropdown("PROVINCEGOID");
                                string selected = "";
                                if (Session["province"] != null)
                                {
                                    int k = 0;
                                    foreach (Item it in dropdown)
                                    {
                                        if (it.value.Equals(Session["province"]))
                                        {
                                            selected = k.ToString();
                                        }
                                        k++;
                                    }
                                }
                                form.AddDropDown(dropdown, "col-sm-3", "checkFlow(9,this);", selected);
                                form.Controls.Add(new LiteralControl("</div>"));
                                string str = "";
                                str += "<div class='form-group left-15'>";
                                str += "<label>เลือกเขตที่พักอาศัยของท่าน</label>";
                                str += "<div>";
                                Dictionary<TitleAnswer, List<Answer>> tmp = arrTitleAnswer(map);
                                string district = "";
                                if (Session["district"] != null)
                                {
                                    district = Session["district"].ToString();
                                }
                                int p = 1;
                                foreach (var title in tmp)
                                {
                                    str += "<label class='radio-inline disabled'>";
                                    if (string.IsNullOrEmpty(district))
                                    {
                                        str += "<input type='radio' name='district' value='" + title.Key.Seq + "' disabled> " + title.Key.TiTleName;
                                    }
                                    else
                                    {
                                        if (district.Equals(p.ToString()))
                                        {
                                            str += "<input type='radio' name='district' value='" + title.Key.Seq + "' checked> " + title.Key.TiTleName;
                                        }
                                        else
                                        {
                                            if (district.Equals("2") || district.Equals("3"))
                                            {
                                                if (p == 2 || p == 3)
                                                {
                                                    str += "<input type='radio' name='district' value='" + title.Key.Seq + "'> " + title.Key.TiTleName;
                                                }
                                                else
                                                {
                                                    str += "<input type='radio' name='district' value='" + title.Key.Seq + "' disabled> " + title.Key.TiTleName;
                                                }
                                            }
                                            else
                                            {
                                                str += "<input type='radio' name='district' value='" + title.Key.Seq + "' disabled> " + title.Key.TiTleName;
                                            }
                                        }
                                    }
                                    p++;
                                    str += "</label>";

                                }
                                str += "</div>";
                                str += "</div>";
                                str += "<div class='form-group left-15'>";
                                str += "<label>เลือกระดับรายได้ของท่าน</label>";
                                bool chkVar = true;
                                string income = "";
                                if (sess.ContainsKey(question.No))
                                {
                                    income = sess[question.No];
                                }
                                p = 1;
                                foreach (var item in tmp)
                                {
                                    string display = "";
                                    string check = "";
                                    if (!string.IsNullOrEmpty(district))
                                    {
                                        display = (district.Equals(p.ToString())) ? "show" : "hidden";
                                        p++;
                                    }
                                    else
                                    {
                                        display = (chkVar) ? "show" : "hidden";
                                        chkVar = false;
                                    }
                                    int n = 1;
                                    foreach (Answer ans in item.Value)
                                    {
                                        str += "<div class='radio disabled left-15 " + display + "' name='" + ans.VarId + ans.TitleId + "'>";
                                        if (!string.IsNullOrEmpty(district))
                                        {
                                            check = (!string.IsNullOrEmpty(income) && display.Equals("show") && income.Equals(n.ToString())) ? "checked" : "";
                                            str += "<label><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='" + ans.Point + "' " + check + ">" + ans.AnswerName + "</label>";
                                        }
                                        else
                                        {
                                            str += "<label><input type='radio' id='" + ans.VarId + "' name='" + ans.VarId + "' value='" + ans.Point + "' disabled>" + ans.AnswerName + "</label>";
                                        }
                                        str += "</div>";
                                        n++;
                                    }
                                }

                                str += "</div>";
                                form.Controls.Add(new LiteralControl(str));
                                break;
                        }
                    }
                    if (!question.Type.Equals("SLIDE") && !question.Type.Equals("TABLESEQUENE"))
                    {
                        form.Controls.Add(new LiteralControl("</div>"));
                    }
                    questionId = q.Key.QuestionId;
                    i++;
                }
                int last = service.getLastQuestion();
                string button = "";
                ViewState["lastFlag"] = false;
                string percent = service.getPercentage(this.page);
                string width = (Convert.ToDouble(percent) > 5) ? percent : "5";
                if (last == questionId)
                {
                    button += "<div class='row'>";
                    button += "<div style='display:table-row;'>";
                    button += "<div class='prev-block'><input type='button' style='float:left;' value='ก่อนหน้า' class='btn btn-warning' onclick='Back(" + this.page + ");'></div>";
                    button += "<div class='progress-block'>";
                    button += "<div class='progress'>";
                    button += "<div class='progress-bar progress-bar-striped active'  aria-valuenow='" + percent + "' aria-valuemin='0' aria-valuemax='100' style='min-width: " + width + "%'>";
                    button += percent + "%";
                    button += "</div>";
                    button += "</div>";
                    button += "</div>";
                    button += "<div class='next-block'><input type='button' style='float:right;' value='ส่งคำตอบ' class='btn btn-primary' onclick='saveAnswer();'></div>";
                    button += "</div>";
                    button += "</div>";
                    ViewState["lastFlag"] = true;
                }
                else
                {
                    button += "<div class='row'>";
                    button += "<div style='display:table-row;'>";
                    button += "<div class='prev-block'>";
                    if (this.page > 1)
                    {
                        button += "<input type='button' style='float:left;' value='ก่อนหน้า' class='btn btn-warning' onclick='Back(" + this.page + ");'>";
                    }
                    button += "</div>";
                    button += "<div class='progress-block'>";
                    button += "<div class='progress'>";
                    button += "<div class='progress-bar progress-bar-striped active'  aria-valuenow='" + percent + "' aria-valuemin='0' aria-valuemax='100' style='min-width: " + width + "%'>";
                    button += percent + "%";
                    button += "</div>";
                    button += "</div>";
                    button += "</div>";
                    button += "<div class='next-block'><input type='button' style='float:right;' value='ถัดไป' class='btn btn-primary' onclick='sendAnswer(" + this.page + ");'></div>";
                    button += "</div>";
                    button += "</div>";
                }
                form.Controls.Add(new LiteralControl(button));
                PlaceHolder1.Controls.Add(form);
                if (strSeq.Length > 0)
                {
                    string s = strSeq.ToString();
                    s = s.Substring(0, s.Length - 1);
                    ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>seq = '" + s + "';\ncurrentPage = " + this.page + ";</script>");
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {
                service.Close();
            }
        }