using System.Data.OleDb;

 

partial class ReportList : System.Web.UI.Page

{

 

    private void Page_Load(System.Object sender, System.EventArgs e)

    {

    }

 

    public string GetReportList()

    {

        string sURLIntegration = GetSetting("URLIntegration");

 

        if (sURLIntegration != "True")

        {

            return "URL Integration is not enabled.  Please go to Admin > Settings > Security";

        }

 

        string sReportType = Request.QueryString["reportType"];

        string sFolderId = Request.QueryString["folderId"];

        bool bShowEdit = (Request.QueryString["edit"] == "1");

 

        string sSql = "SELECT r.ReportId, r.ReportName, r.ReportType, t.DesignImg FROM Report r INNER JOIN ReportType t ON r.ReportType = t.ReportType";

 

        if (!string.IsNullOrEmpty(sFolderId))

        {

            sSql += " WHERE FolderId = " + sFolderId;

        }

        else if (!string.IsNullOrEmpty(sReportType))

        {

            sSql += " WHERE ReportType = " + sReportType;

        }

 

        sSql += " ORDER BY ReportName";

 

        OleDbCommand cmd = new OleDbCommand(sSql, GetConnection());

        OleDbDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

        System.Text.StringBuilder sb = new System.Text.StringBuilder();

 

        sb.Append("<table border=0>\n");

 

        //Details

        while (dr.Read())

        {

            string sReportName = (string) dr.GetValue(dr.GetOrdinal("ReportName"));

            string sDesignImg = (string) dr.GetValue(dr.GetOrdinal("DesignImg")) + "";

            string iReportId = (string) dr.GetValue(dr.GetOrdinal("ReportId"));

 

            string sViewFunction = GetJsFunction(iReportId, 0);

            string sImg = "<IMG SRC='images/ext/" + sDesignImg + "' width=18 height=16 BORDER='0'>";

 

            sb.Append("<tr>\n");

            sb.Append("<td><a href=\"javascript:" + sViewFunction + "\">" + sImg + "</a></td>\n");

            sb.Append("<td><a href=\"javascript:" + sViewFunction + "\">" + sReportName + "</a></td>\n");

 

            if (bShowEdit)

            {

                string sImgEdit = "<IMG SRC='images/edit.gif' width=17 height=14 BORDER='0' title='Edit'>";

                string sDesignFunction = GetJsFunction(iReportId, 1);

                sb.Append("<td><a href=\"javascript:" + sDesignFunction + "\">" + sImgEdit + "</a></td>\n");

            }

 

            sb.Append("</tr>\n");

        }

 

        sb.Append("</table>\n");

 

        dr.Close();

        return sb.ToString();

    }

 

    public string GetSecurityTokenMode()

    {

        return GetSetting("SecurityTokenMode");

    }

 

    private string GetJsFunction(string sReportId, int iViewMode)

    {

        return "GetReport(" + sReportId + "," + iViewMode + ")";

    }

 

    private OleDbConnection GetConnection()

    {

        string sFilePath = Server.MapPath("xmla.udl");

        string sConnectionString = "File Name=" + sFilePath;

        OleDbConnection cn = new OleDbConnection(sConnectionString);

 

        try

        {

            cn.Open();

        }

        catch (Exception ex)

        {

            Response.Write("Could not connect to the database.  Please double click " + sFilePath + " and point it to ReportPortal database.  Make sure to save the connection and check the option to 'Allow saving password'.");

            Response.End();

        }

 

        return cn;

    }

 

    public string GetToken(int iSecurityLevel)

    {

        string sMode = GetSecurityTokenMode();

        if (sMode == "1" | sMode == "2" | sMode == "3")

        {

            string sSql = "exec GetSecurityToken @SecurityLevel=" + iSecurityLevel;

            return GetSingleSqlValue(sSql);

        }

 

        return "";

    }

 

    private string GetSetting(string sKey)

    {

        string sSql = "SELECT ParamValue FROM AppSettings WHERE Param ='" + sKey + "'";

        return GetSingleSqlValue(sSql);

    }

 

    public string GetSingleSqlValue(string sSql)

    {

        string sRet = null;

        OleDbConnection cn = GetConnection();

        OleDbCommand cmd = new OleDbCommand(sSql, cn);

 

        try

        {

            sRet = (string) cmd.ExecuteScalar();

        }

        catch (Exception ex)

        {

            throw new Exception(ex.Message + "; SQL: " + sSql);

        }

 

        cn.Close();

        return sRet;

    }

 

 

}