private void dashboardViewer1_DataLoading(object sender, DataLoadingEventArgs e)
        {
            if (e.DataSourceName.StartsWith("ods|"))
            {
                string[] names = e.DataSourceName.Split("|".ToCharArray());
                DashboardSqlDataSource dataSource = dataSources.First(ds => ds.ComponentName == names[1]);
                SqlQuery query = dataSource.Queries.First(q => q.Name == names[2]);

                XElement      dsXML = dataSource.SaveToXml();
                SqlDataSource sqlDS = new SqlDataSource();
                sqlDS.LoadFromXml(dsXML);
                sqlDS.ConnectionName = "Connection";
                sqlDS.Fill(query.Name);

                ResultSet   rSet   = ((IListSource)sqlDS).GetList() as ResultSet;
                ResultTable rTable = rSet.Tables.First(t => t.TableName == query.Name);

                if (query.Name == "Invoices")
                {
                    var dt = ConvertResultTableToDataTable(rTable);
                    for (int i = dt.Rows.Count - 1; i >= 0; i--)
                    {
                        if (((DateTime)dt.Rows[i]["OrderDate"]).Year < 2016)
                        {
                            dt.Rows.RemoveAt(i);
                        }
                    }
                    e.Data = dt;
                }
                else
                {
                    e.Data = rTable;
                }
            }
        }
Example #2
0
 public void CreateDataSourceFromXml()
 {
     try
     {
         XElement root = XElement.Parse(DataSourceXml);
         if (root?.Name?.ToString().ToLower()?.Contains("excel") ?? false)
         {
             var newDataSource = new ExcelDataSource();
             newDataSource.LoadFromXml(root);
             DataSource = newDataSource;
         }
         if (root?.FirstNode?.ToString()?.ToLower().Contains("sql") ?? false)
         {
             var newDataSource = new SqlDataSource();
             newDataSource.LoadFromXml(root);
             DataSource = newDataSource;
         }
     }
     catch (Exception)
     {
         /// rame logi ro movifiqreb
         DataSource = null;
     }
 }