Example #1
0
        public ActionResult EditPost(ReportViewModel model)
        {
            if (!this.services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to list Reports")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (!this.ModelState.IsValid)
            {
                model = model ?? new ReportViewModel();
                this.FillRelatedData(model);
                return(this.View("Edit", model));
            }

            ReportRecord report = this.reportRepository.Get(model.ReportId);

            if (report == null)
            {
                if (!this.ModelState.IsValid)
                {
                    this.ModelState.AddModelError("ReportId", T("There is no report with the given Id").Text);
                    this.FillRelatedData(model);
                    return(this.View("Edit", model));
                }
            }

            var groupByDescriptor = this.DecodeGroupByCategoryAndType(model.CategoryAndType);

            if (groupByDescriptor == null)
            {
                this.ModelState.AddModelError("CategoryAndType", T("There is no GroupBy field matched with the given parameters").Text);
                this.FillRelatedData(model);
                return(this.View("Edit", model));
            }

            AggregateMethods selectedAggregate = (AggregateMethods)model.AggregateMethod;

            if (!groupByDescriptor.AggregateMethods.Any(c => c == selectedAggregate))
            {
                this.ModelState.AddModelError("AggregateMethod", T("The selected field does't support the selected Aggregate method").Text);
                this.FillRelatedData(model);
                return(this.View("Edit", model));
            }

            report.State = model.State;
            report.Title = model.Title;
            report.Name  = model.Name;
            report.Query = model.QueryId.HasValue ? new QueryPartRecord {
                Id = model.QueryId.Value
            } : null;
            report.GroupByCategory = groupByDescriptor.Category;
            report.GroupByType     = groupByDescriptor.Type;
            report.ChartType       = model.ChartTypeId;
            report.AggregateMethod = model.AggregateMethod;

            this.reportRepository.Update(report);
            this.reportRepository.Flush();

            return(this.RedirectToAction("Index"));
        }
        public int GetCount(ReportRecord report, IContent container)
        {
            if (report == null)
            {
                throw new ArgumentNullException("report");
            }
            if (report.Query == null)
            {
                throw new ArgumentException("There is no QueryRecord associated with the Report");
            }

            var descriptors = this.DescribeGroupByFields();
            var descriptor  = descriptors.SelectMany(c => c.Descriptors).FirstOrDefault(c => c.Category == report.GroupByCategory && c.Type == report.GroupByType);

            if (descriptor == null)
            {
                throw new ArgumentOutOfRangeException("There is no GroupByDescriptor for the given category and type");
            }

            var queryRecord = this.queryRepository.Get(report.Query.Id);

            var contentQueries = this.GetContentQueries(queryRecord, queryRecord.SortCriteria, container);

            return(contentQueries.Sum(c => c.Count()));
        }
Example #3
0
        private void ProcessFile(List <ReportRecord> lstRecords, string recordType)
        {
            var lstDestinationRecords = new List <ReportRecord>();

            foreach (var record in lstRecords)
            {
                var path            = recordType == "FundRequest" ? @"C:\Users\rachavarria\Documents\CCIAttachments\Fund Requests\Version 2\" + record.FileName : @"C:\Users\rachavarria\Documents\CCIAttachments\Fund Claim\Version 2\" + record.FileName;
                var destinationPath = recordType == "FundRequest" ? @"C:\Users\rachavarria\Documents\CCIAttachments\Fund Requests\Attachments\" : @"C:\Users\rachavarria\Documents\CCIAttachments\Fund Claims\";

                if (File.Exists(path))
                {
                    var destinationFile = destinationPath + record.Name + "_" + record.FileName;

                    destinationFile = CheckFileExistance(record, destinationPath, destinationFile);

                    File.Copy(path, destinationFile);

                    var item = new ReportRecord
                    {
                        Id       = record.Id,
                        Name     = record.Name,
                        FileName = record.Name + "_" + record.FileName
                    };
                    lstDestinationRecords.Add(item);
                }
                Console.Write(lstDestinationRecords.Count);
            }

            // WRITE TO EXCEL
            WriteOnFile(lstDestinationRecords, recordType);
        }
Example #4
0
        protected void CreateDataReport(string queryName, string name, string title, ChartTypes chartType, string groupByCategory, string groupByType, AggregateMethods aggregateMethod)
        {
            var query = this.GetQuery(queryName);

            if (query == null)
            {
                return;
            }

            var queryPart = query.As <QueryPart>();

            ReportRecord newReport = new ReportRecord
            {
                Name            = name,
                Title           = title,
                Query           = queryPart.Record,
                ChartType       = (int)chartType,
                GroupByCategory = groupByCategory,
                GroupByType     = groupByType,
                AggregateMethod = (int)aggregateMethod
            };

            this.reportRepository.Create(newReport);
            this.reportRepository.Flush();
        }
Example #5
0
        private static void BuildDB()
        {
            UserRecord u = new UserRecord();

            u.Drop(); u.Create();
            AllianceRecord a = new AllianceRecord();

            a.Drop(); a.Create();
            PlanetRecord p = new PlanetRecord();

            p.Drop(); p.Create();
            ReportRecord r = new ReportRecord();

            r.Drop(); r.Create();
            ResourceRecord res = new ResourceRecord();

            res.Drop(); res.Create();
            BuildingRecord b = new BuildingRecord();

            b.Drop(); b.Create();
            ResearchRecord re = new ResearchRecord();

            re.Drop(); re.Create();
            FleetRecord f = new FleetRecord();

            f.Drop(); f.Create();
            DefenceRecord d = new DefenceRecord();

            d.Drop(); d.Create();
        }
Example #6
0
        public Report GetReport(int telephoneNumber)
        {
            var calls = this._info.GetInfoList()
                        .Where(x => x.MyNumber == telephoneNumber || x.CalledNumber == telephoneNumber)
                        .ToList();

            var report = new Report();

            foreach (var call in calls)
            {
                CallType callType;
                int      number;
                if (call.MyNumber == telephoneNumber)
                {
                    callType = CallType.OutgoingCall;
                    number   = call.CalledNumber;
                }
                else
                {
                    callType = CallType.IncomingCall;
                    number   = call.MyNumber;
                }
                var record = new ReportRecord(callType, number, call.BeginCall, new DateTime((call.EndCall - call.BeginCall).Ticks), call.Cost); // TimeSpan.FromTicks((call.EndCall - call.BeginCall).Ticks) .TotalMinutes
                report.AddRecord(record);
            }
            return(report);
        }
Example #8
0
        public static bool ParseReport(string html, ReportRecord report)
        {
            try
            {
                if (html.Contains("Nie znaleziono"))
                {
                    report.Status     = "Brak";
                    report.LastUpdate = DateTime.Now;
                }
                else
                {
                    report.Status = "Jest";
                    //report.LastUpdate = ParseDate(html);
                }

                ResourceRecord resource = new ResourceRecord {
                    Id = report.Id
                };
                BuildingRecord building = new BuildingRecord {
                    Id = report.Id
                };
                ResearchRecord research = new ResearchRecord {
                    Id = report.Id
                };
                DefenceRecord defence = new DefenceRecord {
                    Id = report.Id
                };
                FleetRecord fleet = new FleetRecord {
                    Id = report.Id
                };

                Resource r = ReportResourceParser.ParseResource(html);
                if (r != null)
                {
                    r.ToDB(resource);
                }
                Building b = ReportBuildingParser.ParseBuilding(html);
                if (b != null)
                {
                    ObjectDumper.Dump(b, building);
                }
                Research s = ReportResearchParser.ParseResearch(html);
                if (s != null)
                {
                    ObjectDumper.Dump(s, research);
                }
                Fleet f = ReportFleetParser.ParseFleet(html);
                ObjectDumper.Dump(f, fleet);

                Defence d = ReportDefenceParser.ParseDefence(html);
                ObjectDumper.Dump(d, defence);
            }catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            return(true);
        }
Example #9
0
        public ActionResult CreatePost(ReportViewModel model)
        {
            if (!this.services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to list Reports")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (!this.ModelState.IsValid)
            {
                model = model ?? new ReportViewModel();
                this.FillRelatedData(model);
                return(this.View("Create", model));
            }

            var groupByDescriptor = this.DecodeGroupByCategoryAndType(model.CategoryAndType);

            if (groupByDescriptor == null)
            {
                this.ModelState.AddModelError("CategoryAndType", T("There is no GroupBy field matched with the given parameters").Text);
                this.FillRelatedData(model);
                return(this.View("Create", model));
            }

            AggregateMethods selectedAggregate = (AggregateMethods)model.AggregateMethod;

            if (!groupByDescriptor.AggregateMethods.Any(c => c == selectedAggregate))
            {
                this.ModelState.AddModelError("AggregateMethod", T("The selected field does't support the selected Aggregate method").Text);
                this.FillRelatedData(model);
                return(this.View("Create", model));
            }

            ReportRecord newReport = new ReportRecord
            {
                Title = model.Title,
                State = model.State,
                Name  = model.Name,
                Guid  = Guid.NewGuid().ToString(),
                Query = new QueryPartRecord {
                    Id = model.QueryId.Value
                },
                ChartType       = model.ChartTypeId,
                GroupByCategory = groupByDescriptor.Category,
                GroupByType     = groupByDescriptor.Type,
                AggregateMethod = model.AggregateMethod
            };

            this.reportRepository.Create(newReport);
            this.reportRepository.Flush();

            var aggregateReportContent = services.ContentManager.Create(ContentTypes.AggregateReportType);

            aggregateReportContent.As <ReportPart>().ReportId = newReport.Id;
            services.ContentManager.Publish(aggregateReportContent);

            return(this.RedirectToAction("Index"));
        }
Example #10
0
        private void AddTask(string strName, string strFile)
        {
            m_iNumber++;

            ReportRecordItem Item;
            ReportRecord     Record = axReportControl.Records.Insert(0);

            Item = Record.AddItem(m_iNumber);
            Item = Record.AddItem(strName);
            Item = Record.AddItem(strFile);
        }
Example #11
0
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            Records.Clear();
            ReportRecord r = da.GetAssociationData(MFTextBox.Text, MBTextBox.Text, ISTextBox.Text, CSTextBox.Text, ROTextBox.Text);

            if (r == null)
            {
                MessageBox.Show("No Record Found", "Search Info", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            Records.Add(r);
        }
Example #12
0
        private static string CheckFileExistance(ReportRecord record, string destinationPath, string destinationFile)
        {
            if (File.Exists(destinationFile))
            {
                destinationFile = destinationPath + record.Name + "_" + record.FileName.Split('.')[0] + "_2." + record.FileName.Split('.')[1];

                if (File.Exists(destinationFile))
                {
                    destinationFile = destinationPath + record.Name + "_" + record.FileName.Split('.')[0] + "_3." + record.FileName.Split('.')[1];

                    if (File.Exists(destinationFile))
                    {
                        destinationFile = destinationPath + record.Name + "_" + record.FileName.Split('.')[0] + "_4." + record.FileName.Split('.')[1];

                        if (File.Exists(destinationFile))
                        {
                            destinationFile = destinationPath + record.Name + "_" + record.FileName.Split('.')[0] + "_5." + record.FileName.Split('.')[1];

                            if (File.Exists(destinationFile))
                            {
                                destinationFile = destinationPath + record.Name + "_" + record.FileName.Split('.')[0] + "_6." + record.FileName.Split('.')[1];

                                if (File.Exists(destinationFile))
                                {
                                    destinationFile = destinationPath + record.Name + "_" + record.FileName.Split('.')[0] + "_7." + record.FileName.Split('.')[1];

                                    if (File.Exists(destinationFile))
                                    {
                                        destinationFile = destinationPath + record.Name + "_" + record.FileName.Split('.')[0] + "_8." + record.FileName.Split('.')[1];

                                        if (File.Exists(destinationFile))
                                        {
                                            destinationFile = destinationPath + record.Name + "_" + record.FileName.Split('.')[0] + "_9." + record.FileName.Split('.')[1];

                                            if (File.Exists(destinationFile))
                                            {
                                                destinationFile = destinationPath + record.Name + "_" + record.FileName.Split('.')[0] + "_10." + record.FileName.Split('.')[1];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(destinationFile);
        }
        public ReportResult RunReport(ReportRecord report, IContent container)
        {
            if (report == null)
            {
                throw new ArgumentNullException("report");
            }
            if (report.Query == null)
            {
                throw new ArgumentException("There is no QueryRecord associated with the Report");
            }

            var descriptors = this.DescribeGroupByFields();
            var descriptor  = descriptors.SelectMany(c => c.Descriptors).FirstOrDefault(c => c.Category == report.GroupByCategory && c.Type == report.GroupByType);

            if (descriptor == null)
            {
                throw new ArgumentOutOfRangeException("There is no GroupByDescriptor for the given category and type");
            }

            var queryRecord = this.queryRepository.Get(report.Query.Id);

            var contentQueries = this.GetContentQueries(queryRecord, queryRecord.SortCriteria, container);

            Dictionary <string, AggregationResult> result = new Dictionary <string, AggregationResult>();

            foreach (var contentQuery in contentQueries)
            {
                var dictionary = descriptor.Run(contentQuery, (AggregateMethods)report.AggregateMethod, report.State);

                foreach (var item in dictionary)
                {
                    if (result.ContainsKey(item.Label))
                    {
                        var previousItem = result[item.Label];
                        previousItem.AggregationValue += item.AggregationValue;
                        result[item.Label]             = previousItem;
                    }
                    else
                    {
                        result[item.Label] = item;
                    }
                }
            }

            ReportResult returnValue1 = new ReportResult();

            returnValue1.Items.AddRange(result.Values);
            return(returnValue1);
        }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        lblSearchSummary.Text = "";
        List <ReportRecord> searchResults = ReportRecord.SearchRecords(ParseSelected(lbEmpName), ParseSelected(lbYRQ));

        gvSearchResults.DataSource = searchResults;
        gvSearchResults.DataBind();

        if (gvSearchResults.Rows.Count > 0) //apply THEAD tags so we can use jQuery TableSorter
        {
            gvSearchResults.UseAccessibleHeader    = true;
            gvSearchResults.HeaderRow.TableSection = TableRowSection.TableHeader;
            gvSearchResults.FooterRow.TableSection = TableRowSection.TableFooter;
        }
    }
Example #15
0

        
Example #16
0
        public ActionResult Remove(int reportId)
        {
            if (!this.services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to list Reports")))
            {
                return(new HttpUnauthorizedResult());
            }

            ReportRecord report = this.reportRepository.Get(reportId);

            if (report == null)
            {
                if (!this.ModelState.IsValid)
                {
                    this.ModelState.AddModelError("ReportId", T("There is no report with the given Id").Text);
                    var reports = this.reportRepository.Table.ToList();
                    var model   = reports.Select(c => new ReportViewModel
                    {
                        ReportId = c.Id,
                        Name     = c.Title
                    }).ToList();

                    return(this.View(model));
                }
            }

            this.reportRepository.Delete(report);
            this.reportRepository.Flush();

            // delete associated contentType
            var aggregateReport = services.ContentManager.Query <ReportPart>().List().FirstOrDefault(c => c.ReportId == report.Id);

            if (aggregateReport != null)
            {
                services.ContentManager.Remove(aggregateReport.ContentItem);
            }

            return(this.RedirectToAction("Index"));
        }
Example #17
0
        protected override void Importing(DataReportViewerPart part, ImportContentContext context)
        {
            var root      = context.Data.Element(part.PartDefinition.Name);
            var chartType = root.Attribute("ChartType");

            if (chartType != null)
            {
                part.Record.ChartType = Convert.ToInt32(chartType.Value);
            }
            var containerTagCssClass = root.Attribute("ContainerTagCssClass");

            if (containerTagCssClass != null)
            {
                part.Record.ContainerTagCssClass = containerTagCssClass.Value;
            }
            var chartTagCssClass = root.Attribute("ChartTagCssClass");

            if (chartTagCssClass != null)
            {
                part.Record.ChartTagCssClass = chartTagCssClass.Value;
            }
            var colorStyle = root.Attribute("ColorStyle");

            if (colorStyle != null)
            {
                part.Record.ColorStyle = Convert.ToInt32(colorStyle.Value);
            }
            var startColor = root.Attribute("StartColor");

            if (startColor != null)
            {
                part.Record.StartColor = Convert.ToInt32(startColor.Value);
            }
            var report = root.Element("Report");

            if (report != null)
            {
                ReportRecord reportRecord = null;
                if (part.Record.Report == null)
                {
                    reportRecord = new ReportRecord();
                }
                else
                {
                    reportRecord = part.Record.Report;
                }
                var name = report.Attribute("Name");
                if (name != null)
                {
                    reportRecord.Name = name.Value;
                }
                var title = report.Attribute("Title");
                if (title != null)
                {
                    reportRecord.Title = title.Value;
                }
                var state = report.Attribute("State");
                if (state != null)
                {
                    reportRecord.State = string.IsNullOrEmpty(state.Value) ? null : state.Value;
                }
                var groupByCategory = report.Attribute("GroupByCategory");
                if (groupByCategory != null)
                {
                    reportRecord.GroupByCategory = groupByCategory.Value;
                }
                var groupByType = report.Attribute("GroupByType");
                if (groupByType != null)
                {
                    reportRecord.GroupByType = groupByType.Value;
                }
                var aggregateMethod = report.Attribute("AggregateMethod");
                if (aggregateMethod != null)
                {
                    reportRecord.AggregateMethod = Convert.ToInt32(aggregateMethod.Value);
                }
                var queryId = report.Attribute("QueryId");
                if (queryId != null)
                {
                    var ciQuery = _contentManager.ResolveIdentity(new ContentIdentity(queryId.Value));
                    if (ciQuery != null)
                    {
                        reportRecord.Query    = new QueryPartRecord();
                        reportRecord.Query.Id = ciQuery.Id;
                    }
                }
                if (part.Record.Report == null)
                {
                    part.Record.Report = reportRecord;
                    reportRepository.Create(reportRecord);
                }
                else
                {
                    reportRepository.Update(reportRecord);
                }
            }
        }
        public IEnumerable <AggregationResult> RunHqlReport(ReportRecord report, IContent container, bool multiColumnTable = false)
        {
            if (report == null)
            {
                throw new ArgumentNullException("report");
            }
            if (report.Query == null)
            {
                throw new ArgumentException("There is no QueryRecord associated with the Report");
            }

            var queryRecord  = contentManager.Get(report.Query.Id);
            var contentQuery = queryRecord.Parts.FirstOrDefault(x => x.PartDefinition.Name == "MyCustomQueryPart");

            if (contentQuery == null)
            {
                throw new ArgumentOutOfRangeException("HQL query not valid.");
            }
            var    queryField    = contentQuery.Get(typeof(TextField), "QueryString") as TextField;
            string parameters    = (contentQuery.Get(typeof(TextField), "QueryParameterValues") as TextField).Value;
            bool   hasParameters = !string.IsNullOrWhiteSpace(parameters); // before tokens substitution because tokens can result in an empty value
            var    sqlField      = contentQuery.Get(typeof(BooleanField), "IsSQL") as BooleanField;
            var    isSql         = sqlField == null
                ? false
                : sqlField.Value.HasValue ? sqlField.Value.Value : false;
            var query = queryField.Value.Trim();
            // tokens replacement
            Dictionary <string, object> contextDictionary = new Dictionary <string, object>();

            if (container != null)
            {
                contextDictionary.Add("Content", container);
            }
            query      = _tokenizer.Replace(query, contextDictionary);
            parameters = _tokenizer.Replace(parameters, contextDictionary);
            IQuery hql = null;
            Dictionary <string, AggregationResult> returnValue = new Dictionary <string, AggregationResult>();
            IEnumerable result = null;
            // check on query: must start with the word "select"
            var startsWithSelect = query
                                   // TrimStart() removes all whitespace from the beginning of the query,
                                   // including newline characters
                                   .TrimStart()
                                   .StartsWith("select", StringComparison.InvariantCultureIgnoreCase)
                                   // select is followed by whitespace
                                   && char.IsWhiteSpace(query.TrimStart(), 6);

            if (!startsWithSelect)
            {
                throw new ArgumentOutOfRangeException("HQL query not valid: please specify select clause with at least 2 columns (the first for labels, the second for values).");
            }
            try {
                var session = _transactionManager.GetSession();
                if (isSql)
                {
                    // SQL Query
                    hql = session.CreateSQLQuery(query);
                }
                else
                {
                    // HQL Query
                    hql = session.CreateQuery(query);
                    if (hql.ReturnAliases.Count() < 2)
                    {
                        throw new ArgumentOutOfRangeException("HQL query not valid: please specify select clause with at least 2 columns (the first for labels, the second for values).");
                    }
                }
                hql.SetCacheable(true);
                if (hasParameters)
                {
                    // Parse parameters:
                    // The correct way to input parameters in the text area is to have one parameter
                    // per line and end each line with a comma.
                    var splitParameters = parameters.Split(
                        new string[] { ",\n", "," + Environment.NewLine },
                        StringSplitOptions.None); // keep empty entries
                                                  // we don't trim values in case whitespace is desired.
                                                  // Parameters are always assumed to be strings.

                    foreach (var kvp in splitParameters.Select((val, i) => new { i, val }))
                    {
                        hql.SetParameter("param" + kvp.i, kvp.val);
                    }
                }
                result = hql.SetResultTransformer(Transformers.AliasToEntityMap).List();
            } catch (Exception ex) {
                Log.Error(ex, "RunHqlReport error - query: " + query);
                throw new Exception("RunHqlReport error - query: " + query, ex);
            }

            string[] columnTitles = null;
            if (!string.IsNullOrWhiteSpace(report.ColumnAliases))
            {
                // try to use the given aliases as column names
                var aliases = report.ColumnAliases
                              .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                              .Select(s => s.Trim()).ToArray();
                if (aliases.Any())
                {
                    columnTitles = aliases;
                }
            }
            if (columnTitles == null)
            {
                if (isSql)
                {
                    var list = (IEnumerable <object>)result;
                    if (list.Any())
                    {
                        var tmp = list.First() as Hashtable;
                        columnTitles = new string[tmp.Keys.Count];
                        int i = 0;
                        foreach (var key in tmp.Keys)
                        {
                            columnTitles[i++] = key.ToString();
                        }
                    }
                    else
                    {
                        columnTitles = new string[] { T("No results found for your search.").Text };
                    }
                }
                else
                {
                    columnTitles = hql.ReturnAliases;
                }
            }

            if (multiColumnTable)
            {
                var columnOps = columnTitles
                                .Select(ct => new ColumnParser(ct));
                returnValue.Add("0", new AggregationResult {
                    AggregationValue = 0,
                    Label            = "",
                    GroupingField    = "",
                    Other            = columnOps.Select(co => co.Alias).ToArray()
                });
                int rownum = 0;
                foreach (var record in result)
                {
                    var row = new List <object>();
                    var ht  = record as Hashtable;
                    foreach (var recordOp in columnOps)
                    {
                        if (ht.ContainsKey(recordOp.Alias))
                        {
                            recordOp.Action(row, ht[recordOp.Alias]);
                        }
                        else
                        {
                            row.Add(null);
                        }
                    }
                    rownum++;
                    returnValue.Add(rownum.ToString(), new AggregationResult {
                        AggregationValue = 0,
                        Label            = "",
                        GroupingField    = "",
                        Other            = row.ToArray()
                    });
                }
            }
            else
            {
                foreach (var record in result)
                {
                    var    ht    = record as Hashtable;
                    string key   = Convert.ToString(ht[columnTitles[0]]);
                    double value = 0;
                    double.TryParse(Convert.ToString(ht[columnTitles[1]]), out value);
                    if (returnValue.ContainsKey(key))
                    {
                        var previousItem = returnValue[key];
                        previousItem.AggregationValue += value;
                        returnValue[key] = previousItem;
                    }
                    else
                    {
                        returnValue[key] = new AggregationResult {
                            AggregationValue = value,
                            Label            = key,
                            GroupingField    = columnTitles[0],
                            Other            = null
                        };
                    }
                }
            }
            return(returnValue.Values);
        }
        protected override void Importing(DataReportViewerPart part, ImportContentContext context)
        {
            var root      = context.Data.Element(part.PartDefinition.Name);
            var chartType = root.Attribute("ChartType");

            if (chartType != null)
            {
                part.Record.ChartType = Convert.ToInt32(chartType.Value);
            }
            var containerTagCssClass = root.Attribute("ContainerTagCssClass");

            if (containerTagCssClass != null)
            {
                part.Record.ContainerTagCssClass = containerTagCssClass.Value;
            }
            var chartTagCssClass = root.Attribute("ChartTagCssClass");

            if (chartTagCssClass != null)
            {
                part.Record.ChartTagCssClass = chartTagCssClass.Value;
            }
            var colorStyle = root.Attribute("ColorStyle");

            if (colorStyle != null)
            {
                part.Record.ColorStyle = Convert.ToInt32(colorStyle.Value);
            }
            var startColor = root.Attribute("StartColor");

            if (startColor != null)
            {
                part.Record.StartColor = Convert.ToInt32(startColor.Value);
            }
            var report = root.Element("Report");

            if (report != null)
            {
                var          guid         = report.Attribute("GUID")?.Value ?? "";
                ReportRecord reportRecord = null;
                // match report record based on GUID
                bool newReportRecord = false;
                if (!string.IsNullOrWhiteSpace(guid))
                {
                    reportRecord = reportRepository.Table.FirstOrDefault(r => r.GUID == guid);
                }
                if (reportRecord == null)
                {
                    newReportRecord = true;
                    reportRecord    = new ReportRecord()
                    {
                        GUID = string.IsNullOrWhiteSpace(guid)
                            ? Guid.NewGuid().ToString()
                            : guid
                    };
                }

                var name = report.Attribute("Name");
                if (name != null)
                {
                    reportRecord.Name = name.Value;
                }
                var title = report.Attribute("Title");
                if (title != null)
                {
                    reportRecord.Title = title.Value;
                }
                var state = report.Attribute("State");
                if (state != null)
                {
                    reportRecord.State = string.IsNullOrEmpty(state.Value) ? null : state.Value;
                }
                var groupByCategory = report.Attribute("GroupByCategory");
                if (groupByCategory != null)
                {
                    reportRecord.GroupByCategory = groupByCategory.Value;
                }
                var groupByType = report.Attribute("GroupByType");
                if (groupByType != null)
                {
                    reportRecord.GroupByType = groupByType.Value;
                }
                var aggregateMethod = report.Attribute("AggregateMethod");
                if (aggregateMethod != null)
                {
                    reportRecord.AggregateMethod = Convert.ToInt32(aggregateMethod.Value);
                }
                var columnAliases = report.Attribute("ColumnAliases");
                if (columnAliases != null)
                {
                    reportRecord.ColumnAliases = columnAliases.Value;
                }
                var queryId = report.Attribute("QueryId");
                if (queryId != null)
                {
                    var ciQuery = _contentManager.ResolveIdentity(new ContentIdentity(queryId.Value));
                    if (ciQuery != null)
                    {
                        reportRecord.Query    = new QueryPartRecord();
                        reportRecord.Query.Id = ciQuery.Id;
                    }
                }
                if (part.Record.Report == null)
                {
                    part.Record.Report = reportRecord;
                }
                if (newReportRecord)
                {
                    reportRepository.Create(reportRecord);
                }
                else
                {
                    reportRepository.Update(reportRecord);
                }
            }
        }
        public IEnumerable <AggregationResult> RunHqlReport(ReportRecord report, IContent container, bool multiColumnTable = false)
        {
            if (report == null)
            {
                throw new ArgumentNullException("report");
            }
            if (report.Query == null)
            {
                throw new ArgumentException("There is no QueryRecord associated with the Report");
            }

            var queryRecord  = contentManager.Get(report.Query.Id);
            var contentQuery = queryRecord.Parts.FirstOrDefault(x => x.PartDefinition.Name == "MyCustomQueryPart");

            if (contentQuery == null)
            {
                throw new ArgumentOutOfRangeException("HQL query not valid.");
            }
            var queryField = contentQuery.Get(typeof(TextField), "QueryString") as TextField;
            var query      = queryField.Value.Trim();
            // tokens replacement
            Dictionary <string, object> contextDictionary = new Dictionary <string, object>();

            if (container != null)
            {
                contextDictionary.Add("Content", container);
            }
            query = _tokenizer.Replace(query, contextDictionary);
            IQuery hql = null;
            Dictionary <string, AggregationResult> returnValue = new Dictionary <string, AggregationResult>();
            IEnumerable result = null;
            // check on hql query: must start with the word "select"
            var startsWithSelect = new Regex(@"^select\s", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

            if (startsWithSelect.IsMatch(query) == false)
            {
                throw new ArgumentOutOfRangeException("HQL query not valid: please specify select clause with at least 2 columns (the first for labels, the second for values).");
            }
            try {
                hql = _transactionManager.GetSession().CreateQuery(query);
                if (hql.ReturnAliases.Count() < 2)
                {
                    throw new ArgumentOutOfRangeException("HQL query not valid: please specify select clause with at least 2 columns (the first for labels, the second for values).");
                }
                result = hql.SetResultTransformer(Transformers.AliasToEntityMap).Enumerable();
            } catch (Exception ex) {
                Log.Error(ex, "RunHqlReport error - query: " + query);
                throw new ArgumentOutOfRangeException("HQL query not valid: please specify select clause with at least 2 columns (the first for labels, the second for values).");
            }

            if (multiColumnTable)
            {
                returnValue.Add("0", new AggregationResult {
                    AggregationValue = 0,
                    Label            = "",
                    GroupingField    = "",
                    Other            = hql.ReturnAliases
                });
                int rownum = 0;
                foreach (var record in result)
                {
                    var row = new List <object>();
                    var ht  = record as Hashtable;
                    foreach (var alias in hql.ReturnAliases)
                    {
                        row.Add(ht[alias]);
                    }
                    rownum++;
                    returnValue.Add(rownum.ToString(), new AggregationResult {
                        AggregationValue = 0,
                        Label            = "",
                        GroupingField    = "",
                        Other            = row.ToArray()
                    });
                }
            }
            else
            {
                foreach (var record in result)
                {
                    var    ht    = record as Hashtable;
                    string key   = Convert.ToString(ht[hql.ReturnAliases[0]]);
                    double value = 0;
                    double.TryParse(Convert.ToString(ht[hql.ReturnAliases[1]]), out value);
                    if (returnValue.ContainsKey(key))
                    {
                        var previousItem = returnValue[key];
                        previousItem.AggregationValue += value;
                        returnValue[key] = previousItem;
                    }
                    else
                    {
                        returnValue[key] = new AggregationResult {
                            AggregationValue = value,
                            Label            = key,
                            GroupingField    = hql.ReturnAliases[0],
                            Other            = null
                        };
                    }
                }
            }
            return(returnValue.Values);
        }
Example #21
0
        private void axReportControl_MouseDownEvent(object sender, AxXtremeReportControl._DReportControlEvents_MouseDownEvent e)
        {
            if (axReportControl.HeaderRows.Count > 0)
            {
                int l, t, r, b;
                l = t = r = b = 0;

                axReportControl.HeaderRows[0].GetRect(ref l, ref t, ref r, ref b);

                // Whether the mouse click is beyond the header row
                if (e.y > b)
                {
                    if (Convert.ToString(axReportControl.HeaderRecords[0][COLUMN_NAME].Value) == string.Empty)
                    {
                        axReportControl.HeaderRecords[0][COLUMN_NAME].Value = NEW_ITEM_NAME;
                    }

                    if (Convert.ToString(axReportControl.HeaderRecords[0][COLUMN_FILE].Value) == string.Empty)
                    {
                        axReportControl.HeaderRecords[0][COLUMN_FILE].Value = NEW_ITEM_FILE;
                    }
                    else
                    {
                        AddNewRecord();
                    }
                }
                else
                {
                    int l2, t2, r2, b2;
                    l2 = t2 = r2 = b2 = 0;

                    // ..or on the header row
                    if (Convert.ToString(axReportControl.HeaderRecords[0][COLUMN_NAME].Value) == NEW_ITEM_NAME)
                    {
                        ReportRecord Record = axReportControl.HeaderRecords[0];
                        axReportControl.HeaderRows[0].GetItemRect(Record[COLUMN_NAME], ref l2, ref t2, ref r2, ref b2);

                        if (e.y > t2 && e.y < b2 && e.x > l2 && e.x < r2)
                        {
                            Record[COLUMN_NAME].Value = "";

                            if (Convert.ToString(axReportControl.HeaderRecords[0][COLUMN_FILE].Value) == string.Empty)
                            {
                                Record[COLUMN_FILE].Value = NEW_ITEM_FILE;
                            }
                        }
                    }

                    if (Convert.ToString(axReportControl.HeaderRecords[0][COLUMN_FILE].Value) == NEW_ITEM_FILE)
                    {
                        ReportRecord Record = axReportControl.HeaderRecords[0];
                        axReportControl.HeaderRows[0].GetItemRect(Record[COLUMN_FILE], ref l2, ref t2, ref r2, ref b2);
                        if (e.y > t2 && e.y < b2 && e.x > l2 && e.x < r2)
                        {
                            Record[COLUMN_FILE].Value = "";

                            if (Convert.ToString(axReportControl.HeaderRecords[0][COLUMN_NAME].Value) == string.Empty)
                            {
                                Record[COLUMN_NAME].Value = NEW_ITEM_NAME;
                            }
                        }
                    }
                }
            }
        }
Example #22
0

        
        protected override void Importing(ReportPart part, ImportContentContext context)
        {
            // Don't do anything if the tag is not specified.
            if (context.Data.Element(part.PartDefinition.Name) == null)
            {
                return;
            }

            string guid = string.Empty;

            context.ImportAttribute(part.PartDefinition.Name, "Guid", g => guid = g);

            var reportRecord = this.reportRecordRepository.Table.FirstOrDefault(c => c.Guid == guid);

            bool isNew = false;

            if (reportRecord == null)
            {
                isNew        = true;
                reportRecord = new ReportRecord {
                    Guid = guid
                };
            }

            // ChartType
            context.ImportAttribute(part.PartDefinition.Name, "ChartType", chartType => reportRecord.ChartType = int.Parse(chartType));

            // State
            context.ImportAttribute(part.PartDefinition.Name, "State", state => reportRecord.State = state);

            // Name
            context.ImportAttribute(part.PartDefinition.Name, "Name", name => reportRecord.Name = name);

            // Title
            context.ImportAttribute(part.PartDefinition.Name, "Title", title => reportRecord.Title = title);

            // State
            context.ImportAttribute(part.PartDefinition.Name, "State", state => reportRecord.State = state);

            // GroupByCategory
            context.ImportAttribute(part.PartDefinition.Name, "GroupByCategory", groupByCategory => reportRecord.GroupByCategory = groupByCategory);

            // GroupByType
            context.ImportAttribute(part.PartDefinition.Name, "GroupByType", groupByType => reportRecord.GroupByType = groupByType);

            // AggregateMethod
            context.ImportAttribute(part.PartDefinition.Name, "AggregateMethod", aggregateMethod => reportRecord.AggregateMethod = int.Parse(aggregateMethod));

            var queryId = context.Attribute(part.PartDefinition.Name, "QueryId");

            if (queryId != null)
            {
                var query = context.GetItemFromSession(queryId);
                if (query != null)
                {
                    reportRecord.Query = query.As <QueryPart>().Record;
                }
            }
            else
            {
                throw new ArgumentNullException("QueryId is null");
            }

            if (isNew)
            {
                this.reportRecordRepository.Create(reportRecord);
            }

            this.reportRecordRepository.Flush();

            part.ReportId = reportRecord.Id;
        }