1
votes

I am new to use DevExpress methods to create a Dashboard for web application on asp.net. I am not getting a good enough example in DashboardLoading method from DevExpress of how to get data directly from MS SQL Server. Have anyone successfully and have a example code for that? It seems like they are using XML, txt, or other kind of files to get data to put in Dashboard. I don't want that. One of them mentioned to use Stream but it required to create a filestream in database and that's not what I am looking for. Here is example from DevExpress that was for xml, http://www.devexpress.com/Support/Center/Example/Details/E4761.

Here is my example so far,

public partial class Viewer : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string uid = AD.GetUserID() + "_p";
        Tin.ActiveDirectory.ADSearch ad = new Tin.ActiveDirectory.ADSearch("tdcc");

        if (ad.Check_If_Member_Of_AD_Functional_Group(uid, "NEACntrlRmAdm-G") | ad.Check_If_Member_Of_AD_Functional_Group(uid, "NEAWinAdm-G"))
        {
            //authorized
        }
        else
        {
            //Response.Redirect("Denied.asp")
        }

        ASPxDashboardViewer1.DashboardId = "MirrorDashboard";

    }

    protected void ASPxDashboardViewer1_DashboardLoading(object sender, 
            DevExpress.DashboardWeb.DashboardLoadingEventArgs e)
    {

        //check the identifier of the required dashboard
        if(e.DashboardId == "MirrorDashboard")
        {

            //To get data from SQL Serve to load the Dashboard

        }

    }

    protected void ASPxDashboardViewer1_ConfigureDataConnection(object sender, DevExpress.DashboardWeb.ConfigureDataConnectionWebEventArgs e)
    {

        //System.Data.SqlClient.SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["GM"].ConnectionString);
        var parameters = e.ConnectionParameters as MsSqlConnectionParameters;


        if (parameters != null)
        {
            parameters.AuthorizationType = MsSqlAuthorizationType.SqlServer;
            parameters.DatabaseName = "GM";
            parameters.ServerName = "*****";
            parameters.UserName="****";
            parameters.Password="****";
        }


    }
}
2
AFAIK, they keep only the database connection settings in the XML file. The data is always loaded from the SQL server. - Uranus

2 Answers

1
votes

You need to understand how Dashboard works. Check out their documentation here. You first have to create the dashboard and wire it up to your SQL Server then copy the XML file to your WEB app.

0
votes

Here is the sample code:

try
        {

            if (e.DashboardId == "ASPxDashboardViewer1")
            {
                string definitionPath = "";
                string dashboardDefinition;

                switch (option)
                {
                    case "A": definitionPath = Server.MapPath("~/A.xml"); break;
                    case "B": definitionPath = Server.MapPath("~/B.xml"); break;
                }

                dashboardDefinition = File.ReadAllText(definitionPath);

                e.DashboardXml = dashboardDefinition;
            }
        }
        catch (Exception ex)
        {
            if (IsCallback)
            {
                DevExpress.Web.ASPxCallback.RedirectOnCallback("Signout.aspx");
            }
            else
            {
                Response.Redirect("Signout.aspx");
            }
        }