コード例 #1
0
        private void setupTextContent(Table table)
        {
            //取得此問卷的所有問答題
            string strSQL = "";

            strSQL = mySQL.getPaperTextContent(strPaperID);
            DataSet dsText = sqldb.getDataSet(strSQL);

            if (dsText.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsText.Tables[0].Rows.Count; i++)
                {
                    //此問題的題號
                    intQuestionNum = intQuestionNum + 1;

                    //取得此問題的內容
                    string strQuestion = "";
                    try
                    {
                        strQuestion = dsText.Tables[0].Rows[i]["cQuestion"].ToString();
                    }
                    catch
                    {
                    }

                    //取得此問題的QID
                    string strQID = "";
                    try
                    {
                        strQID = dsText.Tables[0].Rows[i]["cQID"].ToString();
                    }
                    catch
                    {
                    }

                    //建立問題的TableRow
                    TableRow trQuestion = new TableRow();
                    table.Rows.Add(trQuestion);

                    //建立問題的TableCell
                    TableCell tcQuestion = new TableCell();
                    trQuestion.Cells.Add(tcQuestion);
                    tcQuestion.Text = intQuestionNum.ToString() + ". " + strQuestion;
                    //***如果要顯示學生姓名請改成2
                    tcQuestion.ColumnSpan = 1;

                    //建立問題的CSS
                    trQuestion.Attributes.Add("Class", "header1_table_first_row");
                    trQuestion.ForeColor = System.Drawing.Color.DarkRed;
                    trQuestion.Font.Bold = true;

                    //建立此問題的學生答案
                    this.setupTextAnswer(table, strQID);

                    //間隔的TableRow
                    if (i != (dsText.Tables[0].Rows.Count - 1))
                    {
                        TableRow trEmpty = new TableRow();
                        table.Rows.Add(trEmpty);

                        TableCell tcEmpty = new TableCell();
                        trEmpty.Cells.Add(tcEmpty);

                        Label lbEmpty = new Label();
                        tcEmpty.Controls.Add(lbEmpty);
                        lbEmpty.Text = "";
                        lbEmpty.Style.Add("WIDTH", "0px");
                    }
                }
            }
            else
            {
                //此問卷沒有問答題
            }
            dsText.Dispose();
        }
コード例 #2
0
        private void setupHintsQuestionTable()
        {
            Table table = new Table();

            table.CellSpacing = 0;
            table.CellPadding = 2;
            table.BorderStyle = BorderStyle.Solid;
            table.BorderWidth = Unit.Pixel(1);
            table.BorderColor = System.Drawing.Color.Black;
            table.GridLines   = GridLines.None;
            table.Width       = Unit.Percentage(100);

            intQuestionIndex = 0;

            //取出此問卷的選擇題內容
            string  strSQL         = mySQLString.getPaperSelectionContent(strPaperID);
            DataSet dsQuestionList = sqldb.getDataSet(strSQL);

            if (dsQuestionList.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsQuestionList.Tables[0].Rows.Count; i++)
                {
                    //取得QuestionType
                    string strQuestionType = "1";
                    try
                    {
                        strQuestionType = dsQuestionList.Tables[0].Rows[i]["cQuestionType"].ToString();
                    }
                    catch
                    {
                    }

                    //取得QID
                    string strQID = "";
                    try
                    {
                        strQID = dsQuestionList.Tables[0].Rows[i]["cQID"].ToString();
                    }
                    catch
                    {
                    }

                    //設定Selection row的CSS所設定的變數
                    int intQuestionCount = 0;

                    //取得問題的SQL
                    strSQL = mySQLString.getSingleQuestionInformation(strQID);
                    DataSet dsQuestion = sqldb.getDataSet(strSQL);

                    if (dsQuestion.Tables[0].Rows.Count > 0)
                    {
                        //建立問題的內容
                        TableRow trQuestion = new TableRow();
                        table.Rows.Add(trQuestion);

                        intQuestionIndex += 1;

                        //問題的題號
                        string strQuestionNum = "Q" + intQuestionIndex.ToString() + ": ";

                        //問題的內容
                        string strQuestion = "";
                        try
                        {
                            strQuestion = dsQuestion.Tables[0].Rows[0]["cQuestion"].ToString();
                        }
                        catch
                        {
                        }
                        TableCell tcQuestion = new TableCell();
                        trQuestion.Cells.Add(tcQuestion);
                        tcQuestion.Text = strQuestionNum + strQuestion;
                        double dQuestionWidth = tcQuestion.Width.Value;

                        //建立問題的CSS
                        trQuestion.Attributes.Add("Class", "TableTitle");
                        trQuestion.ForeColor = System.Drawing.Color.DarkRed;
                        trQuestion.Font.Bold = true;

                        //建立選項
                        TableRow trSelection = new TableRow();
                        table.Rows.Add(trSelection);

                        int intColSpan = 0;
                        strSQL = mySQLString.getAllSelections(strQID);
                        DataSet dsSelection = sqldb.getDataSet(strSQL);
                        if (dsSelection.Tables[0].Rows.Count > 0)
                        {
                            for (int j = 0; j < dsSelection.Tables[0].Rows.Count; j++)
                            {
                                intQuestionCount += 1;

                                //SelectionID
                                string strSelectionID = "";
                                try
                                {
                                    strSelectionID = dsSelection.Tables[0].Rows[j]["cSelectionID"].ToString();
                                }
                                catch
                                {
                                }

                                //Seq
                                string strSeq = "";
                                try
                                {
                                    strSeq = dsSelection.Tables[0].Rows[j]["sSeq"].ToString();
                                }
                                catch
                                {
                                }

                                //Selection
                                string strSelection = "";
                                try
                                {
                                    strSelection = dsSelection.Tables[0].Rows[j]["cSelection"].ToString();
                                }
                                catch
                                {
                                }

                                //bCaseSelect
                                bool bCaseSelect = false;
                                try
                                {
                                    bCaseSelect = Convert.ToBoolean(dsSelection.Tables[0].Rows[j]["bCaseSelect"]);
                                }
                                catch
                                {
                                }

                                //選項內容與RadioButton
                                TableCell tcSelection = new TableCell();
                                trSelection.Cells.Add(tcSelection);

                                RadioButton rbSelection = new RadioButton();
                                tcSelection.Controls.Add(rbSelection);
                                rbSelection.Text      = strSelection;
                                rbSelection.GroupName = strQID;
                                string strID = "rb-" + strQID + "-" + strSelectionID;
                                rbSelection.ID = strID;
                                try
                                {
                                    if (Request.Form[strQID] != null)
                                    {
                                        if (Request.Form[strQID].ToString() == strID)
                                        {
                                            rbSelection.Checked = true;
                                        }
                                    }
                                }
                                catch
                                {
                                }
                                intColSpan += 1;
                            }
                            tcQuestion.ColumnSpan = intColSpan;
                        }
                        else
                        {
                            //此問題沒有選項
                        }
                        dsSelection.Dispose();
                    }
                    else
                    {
                        //此問題沒有選項
                    }
                    dsQuestion.Dispose();
                }
            }
            else
            {
                //此問卷沒有選擇題的情況
            }
            dsQuestionList.Dispose();

            int intMaxColSpan = 0;

            //調整table的TableCell寬度
            int intSelectionIndex = 0;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (i % 2 != 0)
                {
                    for (int j = 0; j < table.Rows[i].Cells.Count; j++)
                    {
                        double dPercentage = Convert.ToDouble(100) / Convert.ToDouble(table.Rows[i].Cells.Count);
                        //將每個SelectionCell的寬度設成QuestionCell的寬度/tcSelection的個數
                        table.Rows[i].Cells[j].Width = Unit.Percentage(dPercentage);

                        if (table.Rows[i].Cells.Count > intMaxColSpan)
                        {
                            intMaxColSpan = table.Rows[i].Cells.Count;
                        }
                    }
                    //建立選項的CSS
                    if ((Convert.ToInt32(intSelectionIndex) % 2) != 0)
                    {
                        table.Rows[i].Attributes.Add("Class", "TableOddRow");
                    }
                    else
                    {
                        table.Rows[i].Attributes.Add("Class", "TableEvenRow");
                    }
                    intSelectionIndex += 1;
                }
            }

            //建立屬於此問卷的問答題
            strSQL = mySQLString.getPaperTextContent(strPaperID);
            DataSet dsTextList   = sqldb.getDataSet(strSQL);
            int     intTextCount = 0;

            if (dsTextList.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsTextList.Tables[0].Rows.Count; i++)
                {
                    intQuestionIndex += 1;

                    //取得此問題的QID
                    string strQID = "";
                    try
                    {
                        strQID = dsTextList.Tables[0].Rows[i]["cQID"].ToString();
                    }
                    catch
                    {
                    }

                    TableRow trQuestion = new TableRow();
                    table.Rows.Add(trQuestion);

                    //Question number
                    string strQuestionNum = "Q" + intQuestionIndex.ToString() + ": ";

                    //Question
                    TableCell tcQuestion = new TableCell();
                    trQuestion.Cells.Add(tcQuestion);
                    tcQuestion.ColumnSpan = intMaxColSpan;
                    string strQuestion = "";
                    try
                    {
                        strQuestion = dsTextList.Tables[0].Rows[i]["cQuestion"].ToString();
                    }
                    catch
                    {
                    }
                    tcQuestion.Text = strQuestionNum + strQuestion;

                    //加入CSS
                    intTextCount += 1;
                    trQuestion.Attributes.Add("Class", "TableTitle");
                    trQuestion.ForeColor = System.Drawing.Color.DarkRed;
                    trQuestion.Font.Bold = true;

                    //加入答案TableRow
                    TableRow trAnswer = new TableRow();
                    table.Rows.Add(trAnswer);


                    TableCell tcAnswer = new TableCell();
                    trAnswer.Cells.Add(tcAnswer);
                    tcAnswer.ColumnSpan = intMaxColSpan;

                    //加入TextArea
                    HtmlTextArea txtAnswer = new HtmlTextArea();
                    tcAnswer.Controls.Add(txtAnswer);
                    string strTxtID = "txt-" + strQID;
                    txtAnswer.ID   = strTxtID;
                    txtAnswer.Cols = 80;
                    txtAnswer.Rows = 5;
                    txtAnswer.Style.Add("WIDTH", "100%");
                    try
                    {
                        if (Request.Form[strTxtID] != null)
                        {
                            txtAnswer.Value = Request.Form[strTxtID].ToString();
                        }
                    }
                    catch
                    {
                    }

                    hiddenTextID.Value   += strTxtID + ";";
                    hiddenTextCount.Value = Convert.ToString(Convert.ToInt32(hiddenTextCount.Value) + 1);

                    //套用CSS
                    if ((intTextCount % 2) != 0)
                    {
                        trAnswer.Attributes.Add("Class", "TableOddRow");
                    }
                    else
                    {
                        trAnswer.Attributes.Add("Class", "TableEvenRow");
                    }
                }
            }
            else
            {
                //此問卷沒有問答題的情形
            }
            dsTextList.Dispose();

            //加入Empty TableRow
            int a = 0;

            for (int i = table.Rows.Count - 1; i >= 1; i--)
            {
                if (a == 1)
                {
                    TableRow tr1 = new TableRow();
                    table.Rows.AddAt(i, tr1);

                    TableCell tc1 = new TableCell();
                    tr1.Cells.Add(tc1);
                    tc1.ForeColor = System.Drawing.Color.Transparent;
                    tc1.Font.Size = FontUnit.Parse("0");
                    tc1.Text      = "1";

                    TableRow tr2 = new TableRow();
                    table.Rows.AddAt(i, tr2);

                    TableCell tc2 = new TableCell();
                    tr2.Cells.Add(tc2);
                    tc2.ForeColor = System.Drawing.Color.Transparent;
                    tc2.Font.Size = FontUnit.Parse("0");
                    tc2.Text      = "1";

                    a = 0;
                }
                else
                {
                    a += 1;
                }
            }

            phQuestion.Controls.Clear();
            phQuestion.Controls.Add(table);
        }