Пример #1
0
    public HtmlTable htbDisplayData(string strQuery, string strWidth)
    {
        HtmlTable    htbReturn        = new HtmlTable();
        HtmlTableRow htrRow           = new HtmlTableRow();
        bool         blnDisplayHeader = false;
        string       strValue         = "";
        int          intRowCount      = 0;

        if (strWidth != "")
        {
            htbReturn.Style.Add("width", strWidth);
        }
        for (int intCount = 0; intCount < arlColumns.Count; intCount++)
        {
            udsColumns objC = (udsColumns)arlColumns[intCount];
            if (objC.strHeaderText.Length > 0)
            {
                blnDisplayHeader = true;
                break;
            }
        }
        if (blnDisplayHeader == true)
        {
            for (int intCount = 0; intCount < arlColumns.Count; intCount++)
            {
                udsColumns    objC    = (udsColumns)arlColumns[intCount];
                HtmlTableCell htcCell = new HtmlTableCell();
                htcCell.InnerText = objC.strHeaderText;
                htcCell.ID        = "tc_" + objC.strHeaderText;
                htcCell.Attributes.Add("class", objC.strHeaderClass);
                htcCell.Attributes.Add("style", "text-align:center");
                htrRow.Controls.Add(htcCell);
            }
            htbReturn.Controls.Add(htrRow);
        }

        if (objDB.blnOpenResultSet(strQuery) == true)
        {
            if (objDB.blnHasRecords == false)
            {
                htrRow = new HtmlTableRow();
                HtmlTableCell tdCell = new HtmlTableCell();
                tdCell.InnerText = "----------------NO RECORD FOUND----------------------";
                tdCell.ColSpan   = arlColumns.Count;
                tdCell.Attributes.Add("style", "text-align:center;color:#FF0000");
                htrRow.Controls.Add(tdCell);
                htbReturn.Controls.Add(htrRow);
                return(htbReturn);
            }
            while (objDB.blnResultsMoveNextRow() == true)
            {
                intRowCount++;
                htrRow = new HtmlTableRow();
                for (int intCount = 0; intCount < arlColumns.Count; intCount++)
                {
                    udsColumns objC = (udsColumns)arlColumns[intCount];
                    strValue = objDB.objResultsValue(objC.strColumnName).ToString();
                    string strBackgroundColor;
                    double dblToAdd = 0;
                    if (objDB.strResultsColName(0) != "BackgroundColor")
                    {
                        strBackgroundColor = "#FFFFFF";
                    }
                    else
                    {
                        strBackgroundColor = objDB.objResultsValue("BackgroundColor").ToString();
                    }
                    switch (objC.strTotal)
                    {
                    case "S":
                        dblToAdd = double.Parse(objDB.objResultsValue(objC.strColumnName).ToString());
                        break;

                    case "C":
                        dblToAdd = 1;
                        break;

                    case "A":
                        dblToAdd = double.Parse(objDB.objResultsValue(objC.strColumnName).ToString());
                        break;
                    }
                    arrTotals[intCount] = arrTotals[intCount] + dblToAdd;
                    if (strValue == "")
                    {
                        strValue = "&nbsp";
                    }
                    htrRow.Controls.Add(htcDisplayRecords(strValue, objC.strDataType, objC.strFormat, objC.strColumnClass, objC.strAlign));
                    htrRow.BgColor = strBackgroundColor;
                    htrRow.Attributes.Add("onmouseover", "this.style.backgroundColor='#CCCCCC';");
                    htrRow.Attributes.Add("onmouseout", "this.style.backgroundColor='" + strBackgroundColor + "';");
                }
                htbReturn.Controls.Add(htrRow);
            }
        }
        objDB.blnCloseConnection();

        if (blnDisplayTotals == true)
        {
            htrRow = new HtmlTableRow();
            for (int intCount = 0; intCount < arlColumns.Count; intCount++)
            {
                udsColumns    objC    = (udsColumns)arlColumns[intCount];
                HtmlTableCell htcCell = new HtmlTableCell();
                switch (objC.strTotal)
                {
                case "S":
                    strValue = arrTotals[intCount].ToString(objC.strFormat);
                    break;

                case "C":
                    strValue = arrTotals[intCount].ToString(objC.strFormat);
                    break;

                case "A":
                    strValue = ((arrTotals[intCount]) / (intRowCount)).ToString(objC.strFormat);
                    break;

                default:
                    strValue = "&nbsp;";
                    break;
                }
                if (intCount == 0)
                {
                    strValue = "Total : ";
                }
                htcCell.InnerHtml = strValue;
                htcCell.ID        = "tc_" + objC.strColumnName;
                htcCell.Attributes.Add("class", objC.strHeaderClass);
                htcCell.Attributes.Add("style", "text-align:center");
                htrRow.Controls.Add(htcCell);
            }
            htbReturn.Controls.Add(htrRow);
        }

        return(htbReturn);
    }