private void setupSelectionAndNumRow(TableCell tcQuestion, TableRow trSelection, TableRow trNum, TableRow trPer, string strQID, TableRow trOutput) { //找出此問題的選項 string strSQL = ""; strSQL = mySQL.getQuestionAndSelection(strQID); DataSet dsSelection = sqldb.getDataSet(strSQL); if (dsSelection.Tables[0].Rows.Count > 0) { //紀錄此選項總共有幾個人選 double dTotalNum = 0; for (int i = 0; i < dsSelection.Tables[0].Rows.Count; i++) { //取得選項的內容 string strSelection = ""; try { strSelection = dsSelection.Tables[0].Rows[i]["cSelection"].ToString(); } catch { } //取得選項的SelectionID string strSelectionID = ""; try { strSelectionID = dsSelection.Tables[0].Rows[i]["cSelectionID"].ToString(); } catch { } //在trSelection建立選項的內容 TableCell tcSelection = new TableCell(); trSelection.Cells.Add(tcSelection); tcSelection.Text = strSelection; tcSelection.HorizontalAlign = HorizontalAlign.Center; //在trSelection建立此選項的人數 TableCell tcNum = new TableCell(); trNum.Cells.Add(tcNum); //依照不同Function呼叫不同的Function switch (strFunction) { case "0": //Author,Case , Class strSQL = mySQL.getSelectionSummaryByCaseClass(strPaperID, strQID, strSelectionID, strCaseID, strClass); break; case "1": //Author , Case , Group strSQL = mySQL.getSelectionSummaryByCaseGroup(strPaperID, strQID, strSelectionID, strCaseID, strGroup); break; case "2": //Author , Case strSQL = mySQL.getSelectionSummaryByCase(strPaperID, strQID, strSelectionID, strCaseID); break; case "3": //Author , Class strSQL = mySQL.getSelectionSummaryByAuthorClass(strPaperID, strQID, strSelectionID, strAuthorID, strClass); break; case "4": //Author , Group strSQL = mySQL.getSelectionSummaryByAuthorGroup(strPaperID, strQID, strSelectionID, strAuthorID, strGroup); break; case "5": //Author strSQL = mySQL.getSelectionSummaryByAuthor(strPaperID, strQID, strSelectionID, strAuthorID); break; case "6": //Case , Class strSQL = mySQL.getSelectionSummaryByCaseClass(strPaperID, strQID, strSelectionID, strCaseID, strClass); break; case "7": //Case , Group strSQL = mySQL.getSelectionSummaryByCaseGroup(strPaperID, strQID, strSelectionID, strCaseID, strGroup); break; case "8": //Case strSQL = mySQL.getSelectionSummaryByCase(strPaperID, strQID, strSelectionID, strCaseID); break; case "9": //Class strSQL = mySQL.getSelectionSummaryByClass(strPaperID, strQID, strSelectionID, strClass); break; case "10": //Group strSQL = mySQL.getSelectionSummaryByGroup(strPaperID, strQID, strSelectionID, strGroup); break; } //設定其內容 DataSet dsNum = sqldb.getDataSet(strSQL); //選題的人數 tcNum.Text = dsNum.Tables[0].Rows.Count.ToString(); //將人數累加進總人數 dTotalNum += dsNum.Tables[0].Rows.Count; //設定tableOutput的人數 TableCell tcOutput = new TableCell(); trOutput.Cells.Add(tcOutput); tcOutput.Text = dsNum.Tables[0].Rows.Count.ToString(); tcOutput.HorizontalAlign = HorizontalAlign.Center; tcNum.ForeColor = System.Drawing.Color.Blue; dsNum.Dispose(); tcNum.HorizontalAlign = HorizontalAlign.Center; } //將已經產生的人數資料行掃描一遍 long intSelectPer1 = 0; long intSelectPer2 = 0; for (int i = 0; i < trNum.Cells.Count; i++) { //將人數的旁邊加入百分比 //取出人數 double dNum = Convert.ToDouble(trNum.Cells[i].Text); //將人數/總人數=百分比 long intPer; if (dTotalNum == 0)//避免除零 { intPer = 0; } else { intPer = Convert.ToInt64((dNum / dTotalNum) * 100); } //紀錄非常同意和同意的百分比 if (i == 0) { intSelectPer1 = intPer; } else if (i == 1) { intSelectPer2 = intPer; } //將百分比加入TableCell trNum.Cells[i].Text = trNum.Cells[i].Text + " " + "(" + intPer.ToString() + "%)"; //設定非常同意與同意的百分比 if (i == 2) { TableCell tcPer = new TableCell(); trPer.Cells.Add(tcPer); tcPer.ColumnSpan = 2; tcPer.HorizontalAlign = HorizontalAlign.Center; long intAgree = intSelectPer1 + intSelectPer2; //tcPer.Text = "非常同意(%) + 同意(%) = " + intAgree.ToString() + "(%)"; tcPer.Text = intAgree.ToString() + "(%)"; TableCell tcEmpty = new TableCell(); trPer.Cells.Add(tcEmpty); tcEmpty.ColumnSpan = 3; } } //調整tcQuestion的ColSpan屬性 tcQuestion.ColumnSpan = dsSelection.Tables[0].Rows.Count; } else { //此問題沒有選項 } dsSelection.Dispose(); }