Example #1
0
        private void AddQueryListItem(string modelId, QueryListItem item)
        {
            var items = GetQueryListItems(modelId);

            items.Add(item);
            SaveQueryListItems(modelId, items);
        }
Example #2
0
        private void UpdateQueryListItem(string modelId, QueryListItem item)
        {
            var items = GetQueryListItems(modelId);

            foreach (var it in items)
            {
                if (it.id == item.id)
                {
                    it.name        = item.name;
                    it.description = item.description;
                    break;
                }
            }
            SaveQueryListItems(modelId, items);
        }
Example #3
0
        public EasyReportController(IHostingEnvironment env, IConfiguration config)
        {
            eqService = new EqServiceProviderDb();

            eqService.Paging.Enabled    = true;
            eqService.DefaultModelId    = "NWindSQL";
            eqService.UserId            = "TestUser";
            eqService.StoreModelInCache = true;
            eqService.StoreQueryInCache = true;


            //EqServiceProvider needs to know where to save/load queries to/from

            eqService.Formats.SetDefaultFormats(FormatType.MsSqlServer);
            eqService.Formats.UseSchema = true;

            string dataPath = System.IO.Path.Combine(env.ContentRootPath, "App_Data");

            eqService.DataPath = dataPath;

            eqService.ConnectionResolver = () => {
                return(new SqlConnection(config.GetConnectionString("EqDemoDb")));
            };


            //You can set DbConnection directly (without using ConfigurationManager)
            //eqService.Connection = new SqlCeConnection("Data Source=" + System.IO.Path.Combine(dataPath, "Northwind.sdf"));

            //to support saving/loading models and queries to/from Session
            eqService.CacheGetter = (key) => HttpContext.Session.GetString(key);
            eqService.CacheSetter = (key, value) => HttpContext.Session.SetString(key, value.ToString());


            //The following four handlers (QuerySaver, QueryLoader, QueryRemover and QueryListResolver) are overrided in order to don't save to the server the changes user make - all changed/added queries are stored in Session object
            //This is for demo purpose only, you may freely delete this code or modify to your notice
            // --- begining of overrided handlers ---

            eqService.QuerySaver = (query, queryId) => {
                if (!string.IsNullOrEmpty(queryId))
                {
                    HttpContext.Session.SetString("query" + queryId, query.SaveToString());

                    List <QueryListItem> queries = HttpContext.Session.GetObject <List <QueryListItem> >("queryList");
                    if (queries != null)
                    {
                        QueryListItem item = queries.Find(x => x.id.Equals(queryId));
                        if (item == null)
                        {
                            item = new QueryListItem(query.ID, query.QueryName);
                            queries.Add(item);
                        }
                        item.name        = query.QueryName;
                        item.description = query.QueryDescription;

                        HttpContext.Session.SetObject("queryList", queries);
                    }
                }
            };

            eqService.QueryLoader = (query, queryId) => {
                if (!string.IsNullOrEmpty(queryId))
                {
                    string queryString = HttpContext.Session.GetString("query" + queryId);
                    if (String.IsNullOrWhiteSpace(queryString))
                    {
                        eqService.DefaultQueryLoader(query, queryId);
                        HttpContext.Session.SetString("query" + queryId, query.SaveToString());
                    }
                    else
                    {
                        query.LoadFromString(queryString);
                    }
                }
            };

            eqService.QueryRemover = (queryId) => {
                if (!string.IsNullOrEmpty(queryId))
                {
                    HttpContext.Session.Remove("query" + queryId);

                    List <QueryListItem> queries = HttpContext.Session.GetObject <List <QueryListItem> >("queryList");
                    if (queries != null)
                    {
                        QueryListItem item = queries.Find(x => x.id.Equals(queryId));
                        if (item != null)
                        {
                            queries.Remove(item);
                        }
                    }
                }
            };

            eqService.QueryListResolver = (modelId) => {
                List <QueryListItem> queryItems = HttpContext.Session.GetObject <List <QueryListItem> >("queryList");

                if (queryItems == null)
                {
                    queryItems = eqService.DefaultQueryListResolver(modelId) as List <QueryListItem>;

                    HttpContext.Session.SetObject("queryList", queryItems);
                }

                return(queryItems);
            };

            // --- end of overrided handlers ---


            //Uncomment in case you need to implement your own model loader or add some changes to existing one
            // eqService.ModelLoader = (model, modelName) => {
            //   model.LoadFromConnection(eqService.Connection, FillModelOptions.Default);
            //   model.
            // };

            //Custom lists resolver
            eqService.ValueListResolver = (listname) => {
                if (listname == "ListName")
                {
                    return(new List <ListItem> {
                        new ListItem("ID1", "Item 1"),
                        new ListItem("ID2", "Item 2")
                    });
                }
                return(Enumerable.Empty <ListItem>());
            };
        }