private void DrawElementRowItem(Report report, ReportField reportField, out string startTag, out string endTag) { startTag = ""; endTag = ""; if (reportField.ReportFIeldEventTypeID == ReportFIeldEventType.a) { startTag += $"<a href=\"{reportField.FieldEvent}${reportField.FieldName.ToUpper()}$\">"; startTag += "<div"; startTag += (string.IsNullOrEmpty(reportField.Class)) ? "" : $" class=\"{reportField.Class}\""; startTag += ">"; endTag += "</div>"; endTag += "</a>"; } else { startTag += "<span"; startTag += (string.IsNullOrEmpty(report.Class)) ? "" : $" class=\"{report.Class}-row-item\""; startTag += ">"; startTag += $"${reportField.FieldName.ToUpper()}$"; endTag += "</span>"; } }
/// <summary> /// Add a DataSelect field to the report. /// </summary> /// <param name="componentName">The fully-qualified name of the DataSelect component that provides the field content.</param> /// <param name="settings">Delimited string or JSON data that represents custom settings used by the DataSelect component to generate the field content.</param> /// <param name="columnName">The display name for the column.</param> /// <returns></returns> public ReportField AddDataSelectField(string componentName, object settings, string columnName = null) { var reportField = new ReportField(); // Add property field reportField.ReportFieldType = ReportFieldType.DataSelectComponent; // TODO: Resolve field name if unqualified. reportField.DataSelectComponentEntityTypeId = EntityTypeCache.GetId(componentName); if (settings != null) { reportField.Selection = settings.ToJson(); } reportField.ShowInGrid = true; if (columnName != null) { reportField.ColumnHeaderText = columnName; } _Report.ReportFields.Add(reportField); return(reportField); }
public ReportFieldCollection GetFields() { var fields = new ReportFieldCollection(); var itemType = GetItemType(); var properties = GetProperties(itemType); if (properties == null) { return(fields); } var fieldsOrder = new Dictionary <ReportField, int>(); foreach (var propInfo in properties) { var reportField = new ReportField(propInfo.Name, propInfo.PropertyType); var order = SetReportFieldProperties(itemType, propInfo, reportField); fieldsOrder.Add(reportField, order); } // Add the fields with the requested order foreach (var field in fieldsOrder.OrderBy(kv => kv.Value).Select(kv => kv.Key)) { fields.Add(field); } return(fields); }
public void DeleteReportField(int id) { ReportField reportField = db.ReportFields.Include(r => r.FieldOption).FirstOrDefault(x => x.ReportFieldID == id); db.FieldOptions.Remove(reportField.FieldOption); db.ReportFields.Remove(reportField); db.SaveChanges(); }
public ActionResult DeleteConfirmed(int id) { ReportField reportField = db.ReportFields.Find(id); db.ReportFields.Remove(reportField); db.SaveChanges(); return(RedirectToAction("Index")); }
public void ReportFieldTest1() { ReportField reportField; int id; using (var db = new ApplicationDbContext("DefaultConnection")) { var ctrl = new MedHairController(db); reportField = new ReportField { Name = "name", FieldType = FieldType.Conclusion, FieldOption = new FieldOption { Text = "Text", Selected = true, Title = "title", } }; id = ctrl.CreateReportField(reportField); var reportFieldRes = ctrl.GetReportField(id); Assert.IsNotNull(reportFieldRes); Assert.AreEqual("name", reportFieldRes.Name); Assert.AreEqual(FieldType.Conclusion, reportFieldRes.FieldType); Assert.AreEqual("title", reportFieldRes.FieldOption.Title); Assert.AreEqual("Text", reportFieldRes.FieldOption.Text); } using (var db = new ApplicationDbContext("DefaultConnection")) { var ctrl = new MedHairController(db); reportField.ReportFieldID = id; reportField.Name = "nameName"; reportField.FieldOption.Text = "textText"; ctrl.EditReportField(reportField); var reportFieldRes = ctrl.GetReportField(id); Assert.IsNotNull(reportFieldRes); Assert.AreEqual("nameName", reportFieldRes.Name); Assert.AreEqual(FieldType.Conclusion, reportFieldRes.FieldType); Assert.AreEqual(true, reportFieldRes.FieldOption.Selected); Assert.AreEqual("textText", reportFieldRes.FieldOption.Text); } using (var db = new ApplicationDbContext("DefaultConnection")) { var ctrl = new MedHairController(db); ctrl.DeleteReportField(reportField.ReportFieldID); var reportFieldRes = ctrl.GetReportField(id); Assert.IsNull(reportFieldRes); } }
public static string GetReportField(RestCommand command, int reportFieldID) { ReportField reportField = ReportFields.GetReportField(command.LoginUser, reportFieldID); if (reportField.OrganizationID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.Unauthorized); } return(reportField.GetXml("ReportField", true)); }
public ActionResult EditReportField(ReportField reportField) { if (!ModelState.IsValid) { return(View(reportField)); } _reportFieldFactory.UpdateReportField(reportField); return(RedirectToAction("Edit", "Reports", new { area = "Reports", id = reportField.ReportID })); }
public string this[ReportField key] { get { return(this[key.ToString()]); } set { _innerDictionary[key.ToString()] = value; } }
public ActionResult Edit([Bind(Include = "ReportFieldID,Name,FieldType,FieldOptionID")] ReportField reportField) { if (ModelState.IsValid) { db.Entry(reportField).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FieldOptionID = new SelectList(db.FieldOptions, "FieldOptionID", "Title", reportField.FieldOptionID); return(View(reportField)); }
public ActionResult Create([Bind(Include = "ReportFieldID,Name,FieldType,FieldOptionID")] ReportField reportField) { if (ModelState.IsValid) { db.ReportFields.Add(reportField); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FieldOptionID = new SelectList(db.FieldOptions, "FieldOptionID", "Title", reportField.FieldOptionID); return(View(reportField)); }
private void DrawElementRowContainer(Report report, ReportField reportField, out string startTag, out string endTag) { startTag = ""; endTag = ""; startTag += "<div"; startTag += (string.IsNullOrEmpty(report.Class)) ? "" : $" class=\"{report.Class}-row-container"; startTag += (reportField.ContainerWidth > 0) ? $" width{reportField.ContainerWidth}\"" : "\""; startTag += ">"; endTag += "</div>"; }
public ActionResult CreateReportField(ReportField reportField) { if (!ModelState.IsValid) { return(View(reportField)); } var report = _reportFactory.GetReportTemplate(reportField.ReportID.Value); reportField.FieldNumber = report.ReportFields.Count() + 1; _reportFieldFactory.CreateReportField(reportField); return(RedirectToAction("Edit", "Reports", new { area = "Reports", id = reportField.ReportID })); }
public static ReportDefinition Load(Api api, string fileName) { if (api == null) { throw new ArgumentNullException(nameof(api)); } if (fileName == null) { throw new ArgumentNullException(nameof(fileName)); } var doc = XDocument.Load(fileName); if (doc.Root.Name != Ns + "report") { throw new ArgumentException("Invalid report"); } var root = doc.Root; var result = new ReportDefinition(); result.Entity = api.GetEntitySchema(root.Attribute("entity").Value); var filters = root.Element(Ns + "filters"); if (filters != null) { result.Filters.AddRange(FormatUtil.DeserializeFilters(result.Entity, filters)); } var fields = root.Element(Ns + "fields"); if (fields != null) { foreach (var field in fields.Elements(Ns + "field")) { var fieldPath = EntityMemberPath.Parse(api, result.Entity, field.Attribute("path").Value); if (fieldPath == null) { continue; } var reportField = new ReportField(fieldPath); reportField.Type = (ReportFieldType)Enum.Parse(typeof(ReportFieldType), field.Attribute("type").Value, true); reportField.Transform = (ReportFieldTransform)Enum.Parse(typeof(ReportFieldTransform), field.Attribute("transform").Value, true); result.Fields.Add(reportField); } } return(result); }
// GET: ReportFields/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ReportField reportField = db.ReportFields.Find(id); if (reportField == null) { return(HttpNotFound()); } return(View(reportField)); }
private void fieldsTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { ReportField field = e.Node.Tag as ReportField; if (field == null) { return; } if (fieldsVM.Any(fv => fv.Name == field.Name)) { MessageBox.Show("Поле уже добавлено", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } fieldsVM.Add(new FieldViewModel(field)); }
// GET: ReportFields/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ReportField reportField = db.ReportFields.Find(id); if (reportField == null) { return(HttpNotFound()); } ViewBag.FieldOptionID = new SelectList(db.FieldOptions, "FieldOptionID", "Title", reportField.FieldOptionID); return(View(reportField)); }
private IReadOnlyDictionary <string, Type> ConvertTables(Report report) { var graph = new PXGraph(); var tableTypes = new Dictionary <string, Type>(StringComparer.OrdinalIgnoreCase); foreach (var table in Base.Tables.Select().RowCast <GITable>() .Where(t => !String.IsNullOrEmpty(t.Name) && !String.IsNullOrEmpty(t.Alias))) { Type type = PXBuildManager.GetType(table.Name, false); if (type == null) { continue; } tableTypes[table.Alias] = type; } foreach (var type in tableTypes.Values.Distinct()) { var reportTable = new ReportTable(type.Name) { FullName = type.FullName, }; PXCache cache = graph.Caches[type]; foreach (string field in cache.Fields) { var fieldInfo = ApiFieldInfo.Create(cache, field); if (fieldInfo == null) { continue; } var reportField = new ReportField(field); TypeCode typeCode = Type.GetTypeCode(fieldInfo.DataType); if (typeCode != TypeCode.Empty) { reportField.DataType = typeCode; } reportTable.Fields.Add(reportField); } report.Tables.Add(reportTable); } return(tableTypes); }
/// <summary> /// Add a Property of the reporting entity as a report field. /// </summary> /// <param name="propertyName"></param> /// <param name="columnName">The display name for the column.</param> /// <returns></returns> public ReportField AddPropertyField(string propertyName, string columnName = null) { var reportField = new ReportField(); reportField.ReportFieldType = ReportFieldType.Property; reportField.Selection = propertyName; reportField.ShowInGrid = true; if (columnName != null) { reportField.ColumnHeaderText = columnName; } _Report.ReportFields.Add(reportField); return(reportField); }
/// <summary> /// Add a custom Attribute of the reporting entity as a report field. /// </summary> /// <param name="attributeGuid"></param> /// <param name="columnName">The display name for the column.</param> /// <returns></returns> public ReportField AddAttributeField(Guid attributeGuid, string columnName = null) { var reportField = new ReportField(); reportField.ReportFieldType = ReportFieldType.Attribute; reportField.Selection = attributeGuid.ToString(); reportField.ShowInGrid = true; if (columnName != null) { reportField.ColumnHeaderText = columnName; } _Report.ReportFields.Add(reportField); return(reportField); }
public bool ContainsKey(ReportField key) { return(ContainsKey(key.ToString())); }
/// <summary> /// Sets the report field properties based on the item type attributes (data annotations). /// </summary> /// <param name="itemType">Type of the item.</param> /// <param name="propInfo">The prop info.</param> /// <param name="reportField">The report field.</param> /// <returns>The order number for the field.</returns> private static int SetReportFieldProperties(Type itemType, PropertyInfo propInfo, ReportField reportField) { var metadataTypeAttribute = itemType.GetAttribute <MetadataTypeAttribute>(); MemberInfo memberInfo; if (metadataTypeAttribute != null) { memberInfo = itemType.GetProperty(propInfo.Name, BindingFlags.Public | BindingFlags.Instance) ?? (MemberInfo)itemType.GetField(propInfo.Name, BindingFlags.Public | BindingFlags.Instance); } else { memberInfo = propInfo; } if (memberInfo != null) { var dataTypeAttribute = memberInfo.GetAttribute <DataTypeAttribute>(); var displayFormatAttribute = dataTypeAttribute != null ? dataTypeAttribute.DisplayFormat : memberInfo.GetAttribute <DisplayFormatAttribute>(); if (displayFormatAttribute != null) { reportField.FormatAs <object>(o => o != null ? string.Format(displayFormatAttribute.DataFormatString, o) : displayFormatAttribute.NullDisplayText); } var displayNameAttribute = memberInfo.GetAttribute <DisplayNameAttribute>(); if (displayNameAttribute != null) { reportField.HeaderText = displayNameAttribute.DisplayName; } #if !NET35 var displayAttribute = memberInfo.GetAttribute <DisplayAttribute>(); if (displayAttribute != null) { reportField.HeaderText = displayAttribute.GetShortName(); return(displayAttribute.GetOrder() ?? MaxColumn); } #endif } return(MaxColumn); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { Report report = null; var rockContext = new RockContext(); ReportService service = new ReportService( rockContext ); ReportFieldService reportFieldService = new ReportFieldService( rockContext ); int reportId = int.Parse( hfReportId.Value ); if ( reportId == 0 ) { report = new Report(); report.IsSystem = false; } else { report = service.Get( reportId ); } report.Name = tbName.Text; report.Description = tbDescription.Text; report.CategoryId = cpCategory.SelectedValueAsInt(); report.EntityTypeId = etpEntityType.SelectedEntityTypeId; report.DataViewId = ddlDataView.SelectedValueAsInt(); report.FetchTop = nbFetchTop.Text.AsIntegerOrNull(); if ( !Page.IsValid ) { return; } if ( !report.IsValid ) { // Controls will render the error messages return; } // delete all the reportFields so we can cleanly add them foreach ( var reportField in report.ReportFields.ToList() ) { var field = reportFieldService.Get( reportField.Guid ); reportFieldService.Delete( field ); } report.ReportFields.Clear(); var allPanelWidgets = phReportFields.ControlsOfTypeRecursive<PanelWidget>(); int columnOrder = 0; foreach ( var panelWidget in allPanelWidgets ) { string ddlFieldsId = panelWidget.ID + "_ddlFields"; RockDropDownList ddlFields = phReportFields.ControlsOfTypeRecursive<RockDropDownList>().First( a => a.ID == ddlFieldsId ); ReportFieldType reportFieldType = ReportFieldType.Property; string fieldSelection = string.Empty; string fieldSelectionValue = ddlFields.SelectedItem.Value; string[] fieldSelectionValueParts = fieldSelectionValue.Split( '|' ); if ( fieldSelectionValueParts.Count() == 2 ) { reportFieldType = fieldSelectionValueParts[0].ConvertToEnum<ReportFieldType>(); fieldSelection = fieldSelectionValueParts[1]; } else { // skip over fields that have nothing selected in ddlFields continue; } ReportField reportField = new ReportField(); reportField.ReportFieldType = reportFieldType; string showInGridCheckBoxId = string.Format( "{0}_showInGridCheckBox", panelWidget.ID ); RockCheckBox showInGridCheckBox = phReportFields.ControlsOfTypeRecursive<RockCheckBox>().First( a => a.ID == showInGridCheckBoxId ); reportField.ShowInGrid = showInGridCheckBox.Checked; string columnHeaderTextTextBoxId = string.Format( "{0}_columnHeaderTextTextBox", panelWidget.ID ); RockTextBox columnHeaderTextTextBox = phReportFields.ControlsOfTypeRecursive<RockTextBox>().First( a => a.ID == columnHeaderTextTextBoxId ); reportField.ColumnHeaderText = columnHeaderTextTextBox.Text; reportField.ColumnOrder = columnOrder++; if ( reportFieldType == ReportFieldType.DataSelectComponent ) { reportField.DataSelectComponentEntityTypeId = fieldSelection.AsIntegerOrNull(); string placeHolderId = string.Format( "{0}_phDataSelectControls", panelWidget.ID ); var placeHolder = phReportFields.ControlsOfTypeRecursive<PlaceHolder>().FirstOrDefault( a => a.ID == placeHolderId ); var dataSelectComponent = this.GetDataSelectComponent( rockContext, reportField.DataSelectComponentEntityTypeId ?? 0 ); if ( dataSelectComponent != null ) { reportField.Selection = dataSelectComponent.GetSelection( placeHolder.Controls.OfType<Control>().ToArray() ); } } else { reportField.Selection = fieldSelection; } reportField.Guid = panelWidget.ID.Replace( "reportFieldWidget_", string.Empty ).AsGuid(); report.ReportFields.Add( reportField ); } int sortOrder = 0; foreach ( var itemPair in kvSortFields.Value.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries ).Select( a => a.Split( '^' ) ) ) { var reportFieldGuid = itemPair[0].AsGuidOrNull(); var sortDirection = itemPair[1].ConvertToEnum<SortDirection>( SortDirection.Ascending ); var reportField = report.ReportFields.FirstOrDefault( a => a.Guid == reportFieldGuid ); if ( reportField != null ) { reportField.SortOrder = sortOrder++; reportField.SortDirection = sortDirection; } } var adding = report.Id.Equals( 0 ); if ( adding ) { service.Add( report ); } rockContext.SaveChanges(); if ( adding ) { // add EDIT and ADMINISTRATE to the person who added the report Rock.Security.Authorization.AllowPerson( report, Authorization.EDIT, this.CurrentPerson, rockContext ); Rock.Security.Authorization.AllowPerson( report, Authorization.ADMINISTRATE, this.CurrentPerson, rockContext ); } var qryParams = new Dictionary<string, string>(); qryParams["ReportId"] = report.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
public void Add(ReportField key, string value) { Add(key.ToString(), value); }
/// <summary> /// Populates the field panel widget. /// </summary> /// <param name="panelWidget">The panel widget.</param> /// <param name="reportField">The report field.</param> /// <param name="reportFieldType">Type of the report field.</param> /// <param name="fieldSelection">The field selection.</param> /// <param name="rockContext">The rock context.</param> private void PopulateFieldPanelWidget( PanelWidget panelWidget, ReportField reportField, ReportFieldType reportFieldType, string fieldSelection, RockContext rockContext ) { int entityTypeId = etpEntityType.SelectedEntityTypeId ?? 0; if ( entityTypeId == 0 ) { return; } string defaultColumnHeaderText = null; DataSelectComponent dataSelectComponent = null; bool fieldDefined = false; switch ( reportFieldType ) { case ReportFieldType.Property: var entityType = EntityTypeCache.Read( entityTypeId, rockContext ).GetEntityType(); var entityField = EntityHelper.GetEntityFields( entityType ).FirstOrDefault( a => a.Name == fieldSelection ); if ( entityField != null ) { defaultColumnHeaderText = entityField.Title; fieldDefined = true; } break; case ReportFieldType.Attribute: var attribute = AttributeCache.Read( fieldSelection.AsGuid(), rockContext ); if ( attribute != null ) { defaultColumnHeaderText = attribute.Name; fieldDefined = true; } break; case ReportFieldType.DataSelectComponent: dataSelectComponent = this.GetDataSelectComponent( rockContext, fieldSelection.AsInteger() ); if ( dataSelectComponent != null ) { defaultColumnHeaderText = dataSelectComponent.ColumnHeaderText; fieldDefined = true; } break; } // Show the common field properties. string fieldTitle = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? defaultColumnHeaderText : reportField.ColumnHeaderText; panelWidget.Title = fieldTitle; RockCheckBox showInGridCheckBox = panelWidget.ControlsOfTypeRecursive<RockCheckBox>().FirstOrDefault( a => a.ID == panelWidget.ID + "_showInGridCheckBox" ); showInGridCheckBox.Checked = reportField.ShowInGrid; RockTextBox columnHeaderTextTextBox = panelWidget.ControlsOfTypeRecursive<RockTextBox>().FirstOrDefault( a => a.ID == panelWidget.ID + "_columnHeaderTextTextBox" ); columnHeaderTextTextBox.Text = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? defaultColumnHeaderText : reportField.ColumnHeaderText; // Show settings that are specific to the field type. if ( !fieldDefined ) { // return if we can't determine field return; } RockDropDownList ddlFields = panelWidget.ControlsOfTypeRecursive<RockDropDownList>().FirstOrDefault( a => a.ID == panelWidget.ID + "_ddlFields" ); if ( reportField.ReportFieldType == ReportFieldType.Attribute ) { var selectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, reportField.Selection ); if ( ddlFields.Items.OfType<ListItem>().Any( a => a.Value == selectedValue ) ) { ddlFields.SelectedValue = selectedValue; } else { // if this EntityField is not available for the current person, but this reportField already has it configured, let them keep it var attribute = AttributeCache.Read( fieldSelection.AsGuid(), rockContext ); ddlFields.Items.Add( new ListItem( attribute.Name, selectedValue ) ); ddlFields.SelectedValue = selectedValue; } } else if ( reportField.ReportFieldType == ReportFieldType.Property ) { ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, reportField.Selection ); } else if ( reportField.ReportFieldType == ReportFieldType.DataSelectComponent ) { ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, dataSelectComponent.TypeId ); } if ( dataSelectComponent != null ) { PlaceHolder phDataSelectControls = panelWidget.ControlsOfTypeRecursive<PlaceHolder>().FirstOrDefault( a => a.ID == panelWidget.ID + "_phDataSelectControls" ); if ( phDataSelectControls != null ) { var dataSelectControls = phDataSelectControls.Controls.OfType<Control>().ToArray(); dataSelectComponent.SetSelection( dataSelectControls, reportField.Selection ?? string.Empty ); } } }
public int UpdateReportTemplate(Dictionary <string, string> data) { //var intKeys = new[] { // "Field1","Field2","Field3","Field4","Field5","Field6","XAxis1","XAxis2","XAxis3","YAxis1","YAxis2","YAxis3","ZAxis1","ZAxis2","ZAxis3" }; var stringKeys = new[] { "Name", "ReportType" }; var dateKeys = new[] { "StartDate", "EndDate" }; //var functionKeys = new[]{ // "Field1Function","Field2Function","Field3Function","Field4Function","Field5Function","Field6Function","XAxis1Function","XAxis2Function", // "XAxis3Function","YAxis1Function","YAxis2Function","YAxis3Function","ZAxis1Function","ZAxis2Function","ZAxis3Function" //}; var reportTemplate1 = new ReportTemplate(); if (data != null) { if (data.Keys.Contains("NumberofRecords")) { reportTemplate1.NumberofRecords = Convert.ToInt32(data["NumberofRecords"]); data.Remove("NumberofRecords"); } if (data.Keys.Contains("OrderDirection")) { reportTemplate1.OrderDirection = data["OrderDirection"]; data.Remove("OrderDirection"); } } foreach (var key in stringKeys) { if (data != null) { if (data.Keys.Contains(key)) { if (!String.IsNullOrEmpty(data[key])) { reportTemplate1.GetType().GetProperty(key).SetValue(reportTemplate1, data[key]); } data.Remove(key); } } } foreach (var key in dateKeys) { if (data != null) { if (data.Keys.Contains(key)) { if (!String.IsNullOrEmpty(data[key])) { reportTemplate1.GetType().GetProperty(key).SetValue(reportTemplate1, Convert.ToDateTime(data[key])); } data.Remove(key); } } } _db.ReportTemplates.Add(reportTemplate1); _db.SaveChanges(); var reportTemplateId = reportTemplate1.ReportID; if (data != null && data.Keys.Any()) { foreach (string key in data.Keys) { var reportField = new ReportField(); reportField.ReportID = reportTemplateId; var value = data[key]; var valueArray = value.Split(','); reportField.FieldId = Convert.ToInt32(valueArray[3]); reportField.Func = valueArray[1]; _db.ReportFields.Add(reportField); } } _db.SaveChanges(); return(reportTemplate1.ReportID); }
/// <summary> /// Creates an item used to describe the sort order of a report. /// </summary> /// <param name="column">The column containing the data.</param> /// <param name="sortOrder">The direction (ascending or descending) of the ordered data.</param> public SortItem(ReportField column, SortOrder sortOrder) { // Initialize the object this.Column = column; this.SortOrder = sortOrder; }
/// <summary> /// Handles the SelectedIndexChanged event of the ddlFields control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void ddlFields_SelectedIndexChanged( object sender, EventArgs e ) { RockDropDownList ddlFields = sender as RockDropDownList; PanelWidget panelWidget = ddlFields.Parent as PanelWidget; ReportFieldType reportFieldType = ReportFieldType.Property; string fieldSelection = string.Empty; string fieldSelectionValue = ddlFields.SelectedItem.Value; string[] fieldSelectionValueParts = fieldSelectionValue.Split( '|' ); if ( fieldSelectionValueParts.Count() == 2 ) { reportFieldType = fieldSelectionValueParts[0].ConvertToEnum<ReportFieldType>(); fieldSelection = fieldSelectionValueParts[1]; } Guid reportFieldGuid = new Guid( panelWidget.ID.Replace( "reportFieldWidget_", string.Empty ) ); ReportField reportField = new ReportField { ShowInGrid = true, ReportFieldType = reportFieldType }; if ( reportFieldType == ReportFieldType.DataSelectComponent ) { reportField.Selection = string.Empty; } else { reportField.Selection = fieldSelection; } var reportFieldInfo = ReportFieldsDictionary.First( a => a.Guid == reportFieldGuid ); if ( reportFieldInfo.ReportFieldType != reportFieldType || reportFieldInfo.FieldSelection != fieldSelection ) { CreateFieldTypeSpecificControls( reportFieldType, fieldSelection, panelWidget ); reportFieldInfo.ReportFieldType = reportFieldType; reportFieldInfo.FieldSelection = fieldSelection; PopulateFieldPanelWidget( panelWidget, reportField, reportFieldType, fieldSelection ); } }
/// <summary> /// Collects crash data. /// </summary> /// <param name="context"><see cref="Context"/> for the application being reported.</param> /// <param name="reportFields"><see cref="Array"/> of <see cref="ReportField"/> to include in report</param> /// <param name="appStartDate"><see cref="Time"/> of application start</param> /// <param name="initialConfiguration">Application initial configuration</param> /// <param name="th"><see cref="Java.Lang.Throwable"/> that caused the crash.</param> /// <param name="isSilentReport">Whether to report this report as being sent silently.</param> /// <returns>Builded report data</returns> public static ReportData BuildReportData(Context context, ReportField[] reportFields, Time appStartDate, string initialConfiguration, Java.Lang.Throwable th, bool isSilentReport) { var crashReportData = new ReportData(); try { crashReportData.Add(ReportField.StackTrace, th.StackTrace); crashReportData.Add(ReportField.UserAppStartDate, appStartDate.Format3339(false)); if (isSilentReport) { crashReportData.Add(ReportField.IsSilent, "true"); } if (reportFields.Contains(ReportField.ReportID)) { crashReportData.Add(ReportField.ReportID, Guid.NewGuid().ToString()); } if (reportFields.Contains(ReportField.InstallationID)) { crashReportData.Add(ReportField.InstallationID, Installation.Id(context)); } if (reportFields.Contains(ReportField.InitialConfiguration)) { crashReportData.Add(ReportField.InitialConfiguration, initialConfiguration); } if (reportFields.Contains(ReportField.CrashConfiguration)) { crashReportData.Add(ReportField.CrashConfiguration, ReportUtils.GetCrashConfiguration(context)); } if (reportFields.Contains(ReportField.DumpsysMeminfo)) { crashReportData.Add(ReportField.DumpsysMeminfo, DumpSysCollector.CollectMemInfo()); } if (reportFields.Contains(ReportField.PackageName)) { crashReportData.Add(ReportField.PackageName, context.PackageName); } if (reportFields.Contains(ReportField.Build)) { crashReportData.Add(ReportField.Build, ReflectionCollector.CollectStaticProperties(typeof(Build))); } if (reportFields.Contains(ReportField.PhoneModel)) { crashReportData.Add(ReportField.PhoneModel, Build.Model); } if (reportFields.Contains(ReportField.AndroidVersion)) { crashReportData.Add(ReportField.AndroidVersion, Build.VERSION.Release); } if (reportFields.Contains(ReportField.Brand)) { crashReportData.Add(ReportField.Brand, Build.Brand); } if (reportFields.Contains(ReportField.Product)) { crashReportData.Add(ReportField.Product, Build.Product); } if (reportFields.Contains(ReportField.TotalMemSize)) { crashReportData.Add(ReportField.TotalMemSize, ReportUtils.TotalInternalMemorySize.ToString()); } if (reportFields.Contains(ReportField.AvailableMemSize)) { crashReportData.Add(ReportField.AvailableMemSize, ReportUtils.AvailableInternalMemorySize.ToString()); } if (reportFields.Contains(ReportField.FilePath)) { crashReportData.Add(ReportField.FilePath, ReportUtils.GetApplicationFilePath(context)); } if (reportFields.Contains(ReportField.Display)) { crashReportData.Add(ReportField.Display, ReportUtils.GetDisplayDetails(context)); } if (reportFields.Contains(ReportField.UserCrashDate)) { var curDate = new Time(); curDate.SetToNow(); crashReportData.Add(ReportField.UserCrashDate, curDate.Format3339(false)); } if (reportFields.Contains(ReportField.DeviceFeatures)) { crashReportData.Add(ReportField.DeviceFeatures, DeviceFeaturesCollector.GetFeatures(context)); } if (reportFields.Contains(ReportField.Environment)) { crashReportData.Add(ReportField.Environment, ReflectionCollector.CollectStaticProperties(typeof(Environment))); } if (reportFields.Contains(ReportField.SettingsSystem)) { crashReportData.Add(ReportField.SettingsSystem, SettingsCollector.CollectSystemSettings(context)); } if (reportFields.Contains(ReportField.SettingsSecure)) { crashReportData.Add(ReportField.SettingsSecure, SettingsCollector.CollectSecureSettings(context)); } if (reportFields.Contains(ReportField.SharedPreferences)) { crashReportData.Add(ReportField.SharedPreferences, SharedPreferencesCollector.Collect(context)); } var pm = new PackageManagerWrapper(context); var pi = pm.GetPackageInfo(); if (pi != null) { if (reportFields.Contains(ReportField.AppVersionCode)) { crashReportData.Add(ReportField.AppVersionCode, pi.VersionCode.ToString()); } if (reportFields.Contains(ReportField.AppVersionName)) { crashReportData.Add(ReportField.AppVersionName, pi.VersionName ?? "not set"); } } else { crashReportData.Add(ReportField.AppVersionName, "Package info unavailable"); } if (reportFields.Contains(ReportField.DeviceID) && pm.HasPermission(Manifest.Permission.ReadPhoneState)) { var deviceId = ReportUtils.GetDeviceId(context); if (deviceId != null) { crashReportData.Add(ReportField.DeviceID, deviceId); } } if (pm.HasPermission(Manifest.Permission.ReadLogs)) { Log.Info(Constants.LOG_TAG, "READ_LOGS granted! Crasher can include LogCat and DropBox data."); if (reportFields.Contains(ReportField.Logcat)) { crashReportData.Add(ReportField.Logcat, LogCatCollector.CollectLogCat(null)); } if (reportFields.Contains(ReportField.Eventslog)) { crashReportData.Add(ReportField.Eventslog, LogCatCollector.CollectLogCat("events")); } if (reportFields.Contains(ReportField.Radiolog)) { crashReportData.Add(ReportField.Radiolog, LogCatCollector.CollectLogCat("radio")); } } else { Log.Info(Constants.LOG_TAG, "READ_LOGS not allowed. Crasher will not include LogCat and DropBox data."); } } catch (Java.Lang.RuntimeException e) { Log.Error(Constants.LOG_TAG, e, "Error while retrieving crash data"); } return crashReportData; }
public int CreateReportField(ReportField reportField) { db.ReportFields.Add(reportField); db.SaveChanges(); return(reportField.ReportFieldID); }
/// <summary> /// Adds the field panel widget. /// </summary> /// <param name="reportFieldGuid">The report field unique identifier.</param> /// <param name="reportFieldType">Type of the report field.</param> /// <param name="fieldSelection">The field selection.</param> /// <param name="showExpanded">if set to <c>true</c> [show expanded].</param> /// <param name="setReportFieldValues">if set to <c>true</c> [set report field values].</param> /// <param name="reportField">The report field.</param> private void AddFieldPanelWidget( Guid reportFieldGuid, ReportFieldType reportFieldType, string fieldSelection, bool showExpanded, bool setReportFieldValues = false, ReportField reportField = null ) { int entityTypeId = ddlEntityType.SelectedValueAsInt() ?? 0; if (entityTypeId == 0) { return; } PanelWidget panelWidget = new PanelWidget(); panelWidget.ID = string.Format( "reportFieldWidget_{0}", reportFieldGuid.ToString( "N" ) ); string fieldTitle = null; DataSelectComponent dataSelectComponent = null; switch ( reportFieldType ) { case ReportFieldType.Property: var entityType = EntityTypeCache.Read( entityTypeId ).GetEntityType(); var entityField = EntityHelper.GetEntityFields( entityType ).FirstOrDefault( a => a.Name == fieldSelection ); if ( entityField != null ) { fieldTitle = entityField.Title; } break; case ReportFieldType.Attribute: var attribute = AttributeCache.Read( fieldSelection.AsInteger() ?? 0 ); if ( attribute != null ) { fieldTitle = attribute.Name; } break; case ReportFieldType.DataSelectComponent: string dataSelectComponentTypeName = EntityTypeCache.Read( fieldSelection.AsInteger() ?? 0 ).GetEntityType().FullName; dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent( dataSelectComponentTypeName ); if ( dataSelectComponent != null ) { fieldTitle = dataSelectComponent.GetTitle( null ); } break; } if ( fieldTitle == null ) { // return if we can't determine field return; } panelWidget.Title = fieldTitle; panelWidget.ShowDeleteButton = true; panelWidget.DeleteClick += FieldsPanelWidget_DeleteClick; panelWidget.ShowReorderIcon = true; panelWidget.Expanded = showExpanded; HiddenField hfReportFieldType = new HiddenField(); hfReportFieldType.ID = panelWidget.ID + "_hfReportFieldType"; hfReportFieldType.Value = reportFieldType.ConvertToString(); panelWidget.Controls.Add( hfReportFieldType ); HiddenField hfFieldSelection = new HiddenField(); hfFieldSelection.ID = panelWidget.ID + "_hfFieldSelection"; hfFieldSelection.Value = fieldSelection; panelWidget.Controls.Add( hfFieldSelection ); RockCheckBox showInGridCheckBox = new RockCheckBox(); showInGridCheckBox.ID = panelWidget.ID + "_showInGridCheckBox"; showInGridCheckBox.Text = "Show in Grid"; if ( setReportFieldValues ) { showInGridCheckBox.Checked = reportField.ShowInGrid; } panelWidget.Controls.Add( showInGridCheckBox ); RockTextBox columnHeaderTextTextBox = new RockTextBox(); columnHeaderTextTextBox.ID = panelWidget.ID + "_columnHeaderTextTextBox"; columnHeaderTextTextBox.Label = "Column Label"; if ( setReportFieldValues ) { columnHeaderTextTextBox.Text = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? fieldTitle : reportField.ColumnHeaderText; } panelWidget.Controls.Add( columnHeaderTextTextBox ); if ( dataSelectComponent != null ) { PlaceHolder phDataSelectControls = new PlaceHolder(); phDataSelectControls.ID = panelWidget.ID + "_phDataSelectControls"; panelWidget.Controls.Add( phDataSelectControls ); var dataSelectControls = dataSelectComponent.CreateChildControls( phDataSelectControls ); if ( setReportFieldValues ) { dataSelectComponent.SetSelection( dataSelectControls, reportField.Selection ); } } phReportFields.Controls.Add( panelWidget ); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { Report report = null; using ( new UnitOfWorkScope() ) { ReportService service = new ReportService(); ReportFieldService reportFieldService = new ReportFieldService(); int reportId = int.Parse( hfReportId.Value ); if ( reportId == 0 ) { report = new Report(); report.IsSystem = false; } else { report = service.Get( reportId ); } report.Name = tbName.Text; report.Description = tbDescription.Text; report.CategoryId = cpCategory.SelectedValueAsInt(); report.EntityTypeId = ddlEntityType.SelectedValueAsInt(); report.DataViewId = ddlDataView.SelectedValueAsInt(); if ( !Page.IsValid ) { return; } if ( !report.IsValid ) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction( () => { // delete all the reportFields so we can cleanly add them foreach ( var reportField in report.ReportFields.ToList() ) { var field = reportFieldService.Get( reportField.Guid ); reportFieldService.Delete( field, this.CurrentPersonId ); reportFieldService.Save( field, this.CurrentPersonId ); } report.ReportFields.Clear(); var allPanelWidgets = phReportFields.ControlsOfTypeRecursive<PanelWidget>(); int displayOrder = 0; foreach ( var panelWidget in allPanelWidgets ) { string hfReportFieldTypeID = panelWidget.ID + "_hfReportFieldType"; HiddenField hfReportFieldType = phReportFields.ControlsOfTypeRecursive<HiddenField>().First( a => a.ID == hfReportFieldTypeID ); string hfFieldSelectionID = panelWidget.ID + "_hfFieldSelection"; HiddenField hfFieldSelection = phReportFields.ControlsOfTypeRecursive<HiddenField>().First( a => a.ID == hfFieldSelectionID ); ReportFieldType reportFieldType = hfReportFieldType.Value.ConvertToEnum<ReportFieldType>(); string fieldSelection = hfFieldSelection.Value; ReportField reportField = new ReportField(); reportField.ReportFieldType = reportFieldType; string showInGridCheckBoxId = string.Format( "{0}_showInGridCheckBox", panelWidget.ID ); RockCheckBox showInGridCheckBox = phReportFields.ControlsOfTypeRecursive<RockCheckBox>().First( a => a.ID == showInGridCheckBoxId ); reportField.ShowInGrid = showInGridCheckBox.Checked; string columnHeaderTextTextBoxId = string.Format( "{0}_columnHeaderTextTextBox", panelWidget.ID ); RockTextBox columnHeaderTextTextBox = phReportFields.ControlsOfTypeRecursive<RockTextBox>().First( a => a.ID == columnHeaderTextTextBoxId ); reportField.ColumnHeaderText = columnHeaderTextTextBox.Text; reportField.Order = displayOrder++; if ( reportFieldType == ReportFieldType.DataSelectComponent ) { reportField.DataSelectComponentEntityTypeId = fieldSelection.AsInteger(); string dataSelectComponentTypeName = EntityTypeCache.Read( reportField.DataSelectComponentEntityTypeId ?? 0 ).GetEntityType().FullName; DataSelectComponent dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent( dataSelectComponentTypeName ); string placeHolderId = string.Format( "{0}_phDataSelectControls", panelWidget.ID ); var placeHolder = phReportFields.ControlsOfTypeRecursive<PlaceHolder>().Where( a => a.ID == placeHolderId ).FirstOrDefault(); reportField.Selection = dataSelectComponent.GetSelection( placeHolder.Controls.OfType<Control>().ToArray() ); } else { reportField.Selection = fieldSelection; } report.ReportFields.Add( reportField ); } if ( report.Id.Equals( 0 ) ) { service.Add( report, CurrentPersonId ); } service.Save( report, CurrentPersonId ); } ); } var qryParams = new Dictionary<string, string>(); qryParams["ReportId"] = report.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
/// <summary> /// Add a table to the report. /// If a field list is supplied, exactly those fields are added. /// Otherwise the id of the first table is added as an essential field, and all other non foreign key fields are added /// If table is preceded by "!", its id is also added as an essential field /// For Journal table, Credit & Debit are also added, as an alternative to Amount. /// </summary> void addTable(string table, params string[] fields) { bool essential = _fields.FirstOrDefault(f => f.Essential) == null; if (table.StartsWith("!")) { table = table.Substring(1); essential = false; } Table t = Database.TableFor(table); foreach (Field f in fields.Length == 0 ? t.Fields.Where(f => (essential || f != t.PrimaryKey) && f.ForeignKey == null) : fields.Select(f => t.FieldFor(f))) { ReportField r = new ReportField(t.Name, f); if (essential) { r.Essential = true; if(Array.IndexOf(fields, f.Name) < 0) r.Hidden = true; essential = false; } _fields.Add(r); if (table == "Journal" && f.Name == "Amount") { ReportField rf = new ReportField(t.Name, f, "Debit"); rf.Name = "Debit"; rf["type"] = "debit"; _fields.Add(rf); rf = new ReportField(t.Name, f, "Credit"); rf.Name = "Credit"; rf["type"] = "credit"; _fields.Add(rf); } } }
/// <summary> /// Populates the field panel widget. /// </summary> /// <param name="panelWidget">The panel widget.</param> /// <param name="reportField">The report field.</param> /// <param name="reportFieldType">Type of the report field.</param> /// <param name="fieldSelection">The field selection.</param> private void PopulateFieldPanelWidget( PanelWidget panelWidget, ReportField reportField, ReportFieldType reportFieldType, string fieldSelection ) { int entityTypeId = etpEntityType.SelectedEntityTypeId ?? 0; if ( entityTypeId == 0 ) { return; } string defaultColumnHeaderText = null; DataSelectComponent dataSelectComponent = null; bool fieldDefined = false; switch ( reportFieldType ) { case ReportFieldType.Property: var entityType = EntityTypeCache.Read( entityTypeId ).GetEntityType(); var entityField = EntityHelper.GetEntityFields( entityType ).FirstOrDefault( a => a.Name == fieldSelection ); if ( entityField != null ) { defaultColumnHeaderText = entityField.Title; fieldDefined = true; } break; case ReportFieldType.Attribute: var attribute = AttributeCache.Read( fieldSelection.AsGuid() ); if ( attribute != null ) { defaultColumnHeaderText = attribute.Name; fieldDefined = true; } break; case ReportFieldType.DataSelectComponent: string dataSelectComponentTypeName = EntityTypeCache.Read( fieldSelection.AsInteger() ).GetEntityType().FullName; dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent( dataSelectComponentTypeName ); if ( dataSelectComponent != null ) { defaultColumnHeaderText = dataSelectComponent.ColumnHeaderText; fieldDefined = true; } break; } if ( !fieldDefined ) { // return if we can't determine field return; } RockDropDownList ddlFields = panelWidget.ControlsOfTypeRecursive<RockDropDownList>().FirstOrDefault( a => a.ID == panelWidget.ID + "_ddlFields" ); if ( reportField.ReportFieldType == ReportFieldType.Attribute ) { ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, reportField.Selection ); } else if ( reportField.ReportFieldType == ReportFieldType.Property ) { ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, reportField.Selection ); } else if ( reportField.ReportFieldType == ReportFieldType.DataSelectComponent ) { ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, dataSelectComponent.TypeId ); } string fieldTitle = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? defaultColumnHeaderText : reportField.ColumnHeaderText; panelWidget.Title = fieldTitle; RockCheckBox showInGridCheckBox = panelWidget.ControlsOfTypeRecursive<RockCheckBox>().FirstOrDefault( a => a.ID == panelWidget.ID + "_showInGridCheckBox" ); showInGridCheckBox.Checked = reportField.ShowInGrid; RockTextBox columnHeaderTextTextBox = panelWidget.ControlsOfTypeRecursive<RockTextBox>().FirstOrDefault( a => a.ID == panelWidget.ID + "_columnHeaderTextTextBox" ); columnHeaderTextTextBox.Text = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? defaultColumnHeaderText : reportField.ColumnHeaderText; if ( dataSelectComponent != null ) { PlaceHolder phDataSelectControls = panelWidget.ControlsOfTypeRecursive<PlaceHolder>().FirstOrDefault( a => a.ID == panelWidget.ID + "_phDataSelectControls" ); if ( phDataSelectControls != null ) { var dataSelectControls = phDataSelectControls.Controls.OfType<Control>().ToArray(); dataSelectComponent.SetSelection( dataSelectControls, reportField.Selection ?? string.Empty ); } } }
public void EditReportField(ReportField reportField) { db.Entry(reportField).State = EntityState.Modified; db.Entry(reportField.FieldOption).State = EntityState.Modified; db.SaveChanges(); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { Report report = null; var rockContext = new RockContext(); ReportService service = new ReportService( rockContext ); ReportFieldService reportFieldService = new ReportFieldService( rockContext ); int reportId = int.Parse( hfReportId.Value ); if ( reportId == 0 ) { report = new Report(); report.IsSystem = false; } else { report = service.Get( reportId ); } report.Name = tbName.Text; report.Description = tbDescription.Text; report.CategoryId = cpCategory.SelectedValueAsInt(); report.EntityTypeId = etpEntityType.SelectedEntityTypeId; report.DataViewId = ddlDataView.SelectedValueAsInt(); report.FetchTop = nbFetchTop.Text.AsIntegerOrNull(); if ( !Page.IsValid ) { return; } if ( !report.IsValid ) { // Controls will render the error messages return; } // delete all the reportFields so we can cleanly add them foreach ( var reportField in report.ReportFields.ToList() ) { var field = reportFieldService.Get( reportField.Guid ); reportFieldService.Delete( field ); } report.ReportFields.Clear(); var allPanelWidgets = phReportFields.ControlsOfTypeRecursive<PanelWidget>(); int displayOrder = 0; foreach ( var panelWidget in allPanelWidgets ) { string ddlFieldsId = panelWidget.ID + "_ddlFields"; RockDropDownList ddlFields = phReportFields.ControlsOfTypeRecursive<RockDropDownList>().First( a => a.ID == ddlFieldsId ); ReportFieldType reportFieldType = ReportFieldType.Property; string fieldSelection = string.Empty; string fieldSelectionValue = ddlFields.SelectedItem.Value; string[] fieldSelectionValueParts = fieldSelectionValue.Split( '|' ); if ( fieldSelectionValueParts.Count() == 2 ) { reportFieldType = fieldSelectionValueParts[0].ConvertToEnum<ReportFieldType>(); fieldSelection = fieldSelectionValueParts[1]; } else { // skip over fields that have nothing selected in ddlFields continue; } ReportField reportField = new ReportField(); reportField.ReportFieldType = reportFieldType; string showInGridCheckBoxId = string.Format( "{0}_showInGridCheckBox", panelWidget.ID ); RockCheckBox showInGridCheckBox = phReportFields.ControlsOfTypeRecursive<RockCheckBox>().First( a => a.ID == showInGridCheckBoxId ); reportField.ShowInGrid = showInGridCheckBox.Checked; string columnHeaderTextTextBoxId = string.Format( "{0}_columnHeaderTextTextBox", panelWidget.ID ); RockTextBox columnHeaderTextTextBox = phReportFields.ControlsOfTypeRecursive<RockTextBox>().First( a => a.ID == columnHeaderTextTextBoxId ); reportField.ColumnHeaderText = columnHeaderTextTextBox.Text; reportField.Order = displayOrder++; if ( reportFieldType == ReportFieldType.DataSelectComponent ) { reportField.DataSelectComponentEntityTypeId = fieldSelection.AsIntegerOrNull(); string dataSelectComponentTypeName = EntityTypeCache.Read( reportField.DataSelectComponentEntityTypeId ?? 0 ).GetEntityType().FullName; DataSelectComponent dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent( dataSelectComponentTypeName ); string placeHolderId = string.Format( "{0}_phDataSelectControls", panelWidget.ID ); var placeHolder = phReportFields.ControlsOfTypeRecursive<PlaceHolder>().Where( a => a.ID == placeHolderId ).FirstOrDefault(); reportField.Selection = dataSelectComponent.GetSelection( placeHolder.Controls.OfType<Control>().ToArray() ); } else { reportField.Selection = fieldSelection; } report.ReportFields.Add( reportField ); } if ( report.Id.Equals( 0 ) ) { service.Add( report ); } rockContext.SaveChanges(); var qryParams = new Dictionary<string, string>(); qryParams["ReportId"] = report.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
public bool Remove(ReportField key) { return(Remove(key.ToString())); }
/// <summary> /// Adds the field panel widget. /// </summary> /// <param name="reportFieldGuid">The report field unique identifier.</param> /// <param name="reportFieldType">Type of the report field.</param> /// <param name="fieldSelection">The field selection.</param> /// <param name="showExpanded">if set to <c>true</c> [show expanded].</param> /// <param name="setReportFieldValues">if set to <c>true</c> [set report field values].</param> /// <param name="reportField">The report field.</param> private void AddFieldPanelWidget( Guid reportFieldGuid, ReportFieldType reportFieldType, string fieldSelection, bool showExpanded, bool setReportFieldValues = false, ReportField reportField = null ) { PanelWidget panelWidget = new PanelWidget(); panelWidget.ID = string.Format( "reportFieldWidget_{0}", reportFieldGuid.ToString( "N" ) ); panelWidget.ShowDeleteButton = true; panelWidget.DeleteClick += FieldsPanelWidget_DeleteClick; panelWidget.ShowReorderIcon = true; panelWidget.Expanded = showExpanded; Label lbFields = new Label(); lbFields.Text = "Field Type"; RockDropDownList ddlFields = new RockDropDownList(); panelWidget.Controls.Add( ddlFields ); ddlFields.ID = panelWidget.ID + "_ddlFields"; ddlFields.AutoPostBack = true; ddlFields.SelectedIndexChanged += ddlFields_SelectedIndexChanged; panelWidget.HeaderControls = new Control[2] { lbFields, ddlFields }; this.LoadFieldsDropDown( ddlFields ); RockCheckBox showInGridCheckBox = new RockCheckBox(); showInGridCheckBox.ID = panelWidget.ID + "_showInGridCheckBox"; showInGridCheckBox.Text = "Show in Grid"; panelWidget.Controls.Add( showInGridCheckBox ); RockTextBox columnHeaderTextTextBox = new RockTextBox(); columnHeaderTextTextBox.ID = panelWidget.ID + "_columnHeaderTextTextBox"; columnHeaderTextTextBox.Label = "Column Label"; columnHeaderTextTextBox.CssClass = "js-column-header-textbox"; panelWidget.Controls.Add( columnHeaderTextTextBox ); phReportFields.Controls.Add( panelWidget ); CreateFieldTypeSpecificControls( reportFieldType, fieldSelection, panelWidget ); if ( setReportFieldValues ) { PopulateFieldPanelWidget( panelWidget, reportField, reportFieldType, fieldSelection ); } }
public bool TryGetValue(ReportField key, out string value) { return(TryGetValue(key.ToString(), out value)); }
public object BalanceSheetPost(JObject json) { _total = false; initialiseReport(json); addTable("!AccountType"); addTable("Account", "idAccount", "AccountCode", "AccountName", "AccountDescription"); fieldFor("idAccount").Hide(); fieldFor("AccountName")["sClass"] = "sa"; fieldFor("Heading").MakeEssential(); fieldFor("Negate").MakeEssential().Hide(); fieldFor("BalanceSheet").MakeEssential().Hide(); DateFilter date = new DateFilter("DocumentDate", DateRange.LastYear); ReportField cp = new ReportField("CurrentPeriod", "decimal", "Current Period"); _fields.Add(cp); ReportField lp = new ReportField("PreviousPeriod", "decimal", "Previous Period"); _fields.Add(lp); _filters.Add(date); setDefaultFields(json, "Heading", "AcctType", "AccountName", "CurrentPeriod", "PreviousPeriod"); _sortOrder = "AcctType"; setFilters(json); // Balance sheet needs 2 period buckets for the 2 columns DateTime[] cPeriod = date.CurrentPeriod(); cp["heading"] = date.PeriodName(cPeriod); DateTime[] lPeriod = date.PreviousPeriod(); lp["heading"] = date.PeriodName(lPeriod); string[] sort = new string[] { "AccountTypeId", "AccountCode", "AccountName" }; string[] fields = _fields.Where(f => f.Include || f.Essential || _sortFields.Contains(f.Name)).Select(f => f.FullFieldName).Distinct().ToArray(); // We want one record per account, with totals for each bucket, and an Old value // which is sum of all transactions before first bucket (opening balance) JObjectEnumerable report = Database.Query("SELECT " + string.Join(",", fields) + @", Old FROM AccountType LEFT JOIN Account ON Account.AccountTypeId = AccountType.idAccountType JOIN (SELECT AccountId, SUM(CASE WHEN DocumentDate < " + Database.Quote(cPeriod[1]) + " AND DocumentDate >= " + Database.Quote(cPeriod[0]) + @" THEN Amount ELSE 0 END) AS CurrentPeriod, SUM(CASE WHEN DocumentDate < " + Database.Quote(lPeriod[1]) + " AND DocumentDate >= " + Database.Quote(lPeriod[0]) + @" THEN Amount ELSE 0 END) AS PreviousPeriod, SUM(CASE WHEN DocumentDate < " + Database.Quote(lPeriod[0]) + @" THEN Amount ELSE 0 END) AS Old FROM Journal LEFT JOIN Document ON Document.idDocument = Journal.DocumentId WHERE DocumentDate < " + Database.Quote(cPeriod[1]) + @" GROUP BY AccountId ) AS Summary ON AccountId = idAccount ORDER BY " + string.Join(",", sort.Select(s => s + (_sortDescending ? " DESC" : "")).ToArray()) ); _sortFields = new string[] { "Heading", "AcctType", "AccountCode", "AccountName" }; // Report now needs further processing to: // Calculate retained earnings account // Add investment gains // Consolidate P & L accounts and produce totals return reportJson(json, fixBalanceSheet(addInvestmentGains(addRetainedEarnings(report), "Old", lPeriod[0], "PreviousPeriod", cPeriod[0], "CurrentPeriod", cPeriod[1])), "AccountType", "Account"); }
public object AgeingPost(JObject json) { initialiseReport(json); // Can select Sales or Purchases JObject [] accountSelect = new JObject[] { new JObject().AddRange("id", (int)Acct.SalesLedger, "value", "Sales Ledger"), new JObject().AddRange("id", (int)Acct.PurchaseLedger, "value", "Purchase Ledger") }; ReportField acct = new ReportField("AccountId", "select", "Account"); acct["selectOptions"] = new JArray(accountSelect); acct.Essential = true; _fields.Add(acct); _fields.Add(new ReportField("NameAddressId", "int", "NameAddressId").Hide().MakeEssential()); _fields.Add(new ReportField("Name", "string", "Name")); // Fields for each ageing bucket _fields.Add(new ReportField("SUM(CASE WHEN age BETWEEN 0 AND 29 THEN Outstanding ELSE 0 END) AS Current", "decimal", "Current")); for(int i = 1; i < 90; i += 30) _fields.Add(new ReportField("SUM(CASE WHEN age BETWEEN " + (i + 29) + " AND " + (i + 58) + " THEN Outstanding ELSE 0 END) AS b" + i, "decimal", i + "-" + (i + 29))); _fields.Add(new ReportField("SUM(CASE WHEN age > 120 THEN Outstanding ELSE 0 END) AS old", "decimal", ">90")); _fields.Add(new ReportField("SUM(Outstanding) AS Total", "decimal", "Total")); RecordFilter account = new RecordFilter("Account", "Journal.AccountId", accountSelect); account.Apply = false; _filters.Add(account); _sortOrder = ""; _total = true; setDefaultFields(json, "AccountId", "Name", "Current", "b1", "b31", "b61", "old", "Total"); setFilters(json); // we account filter value setting now string where = account.Active ? account.Where() : "AccountId IN (1, 2)"; return finishReport(json, @"(SELECT AccountId, NameAddressId, Name, Outstanding, DATEDIFF(" + Database.Quote(Utils.Today) + @", DocumentDate) AS age FROM Journal JOIN Document ON idDocument = DocumentId JOIN NameAddress ON idNameAddress = NameAddressId WHERE " + where + @" AND Outstanding <> 0 ) AS DaysDue", "AccountId,Name", "GROUP BY AccountId, Name"); }
public List <ReportField> GetReport(string userName, string strategyName, DateTime startDate, DateTime endDate) { var result = new List <ReportField>(); using (var aConnection = new SqlConnection(_connectionString)) { var cmd = new SqlCommand( "SELECT o.Symbol, o.Type, o.Status, o.TIF, o.ExecutedQuantity, s.SignalName, s.Date as SignalDate," + " s.DataBaseEntry as SignalDBDate, o.Date, o.FilledDate, o.DataBaseEntry as OrderDBDate" + " FROM[dbo].[Orders] o" + " LEFT JOIN[dbo].[Signals] s ON o.SignalID = s.SignalID" + " WHERE s.UserLogin = @userLogin AND s.SignalName = @signalName AND s.Date BETWEEN @startDate AND @endDate", aConnection); cmd.Parameters.AddWithValue("userLogin", userName); cmd.Parameters.AddWithValue("signalName", strategyName); cmd.Parameters.AddWithValue("startDate", startDate); cmd.Parameters.AddWithValue("endDate", endDate); SqlTransaction transaction = null; try { aConnection.Open(); transaction = aConnection.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted, "Orders Select"); cmd.Transaction = transaction; using (var reader = cmd.ExecuteReader()) { if (!reader.HasRows) { return(result); } while (reader.Read()) { try { var qty = (decimal)reader["ExecutedQuantity"]; var field = new ReportField { Symbol = (string)reader["Symbol"], TradeType = DBConverters.ParseOrderType((string)reader["Type"]), Status = DBConverters.ParseOrderStatus((string)reader["Status"]), TimeInForce = DBConverters.ParseTif((string)reader["TIF"]), Quantity = qty, Side = qty > 0 ? Side.Buy : Side.Sell, SignalName = (string)reader["SignalName"], SignalGeneratedDateTime = (DateTime)reader["SignalDate"], OrderFilledDate = (DateTime)reader["FilledDate"], OrderGeneratedDate = (DateTime)reader["Date"], DBOrderEntryDate = (DateTime)reader["OrderDBDate"], DBSignalEntryDate = (DateTime)reader["SignalDBDate"] }; field.CalculateDiff(); result.Add(field); } catch (Exception ex) { Logger.Error("Failed to parse report field", ex); } } } transaction.Commit(); } catch (Exception e) { Logger.Error("Failed to load report", e); transaction?.Rollback(); return(result); } } return(result); }
public object ProfitAndLossPost(JObject json) { _total = false; initialiseReport(json); addTable("!AccountType"); addTable("Account", "idAccount", "AccountCode", "AccountName", "AccountDescription"); fieldFor("idAccount").Hide(); fieldFor("AccountName")["sClass"] = "sa"; fieldFor("Heading").MakeEssential().Hide(); fieldFor("Negate").MakeEssential().Hide(); fieldFor("BalanceSheet").MakeEssential().Hide(); DateFilter date = new DateFilter("DocumentDate", DateRange.LastYear); ReportField cp = new ReportField("SUM(Amount) AS CurrentPeriod", "decimal", "Current Period"); _fields.Add(cp); ReportField lp = new ReportField("SUM(Amount) AS PreviousPeriod", "decimal", "Previous Period"); _fields.Add(lp); _filters.Add(date); setDefaultFields(json, "AcctType", "AccountName", "CurrentPeriod", "PreviousPeriod"); _sortOrder = "AcctType"; setFilters(json); // P & L needs 2 period buckets for the 2 columns DateTime[] cPeriod = date.CurrentPeriod(); cp.FullFieldName = "SUM(CASE WHEN DocumentDate >= " + Database.Quote(cPeriod[0]) + " AND DocumentDate < " + Database.Quote(cPeriod[1]) + " THEN Amount ELSE 0 END) AS CurrentPeriod"; cp["heading"] = date.PeriodName(cPeriod); DateTime[] lPeriod = date.PreviousPeriod(); lp.FullFieldName = "SUM(CASE WHEN DocumentDate >= " + Database.Quote(lPeriod[0]) + " AND DocumentDate < " + Database.Quote(lPeriod[1]) + " THEN Amount ELSE 0 END) AS PreviousPeriod"; lp["heading"] = date.PeriodName(lPeriod); string [] sort = new string[] { "AccountTypeId", "AccountCode", "AccountName" }; string[] fields = _fields.Where(f => f.Include || f.Essential || _sortFields.Contains(f.Name)).Select(f => f.FullFieldName).Distinct().ToArray(); JObjectEnumerable report = Database.Query("SELECT " + string.Join(",", fields) + @" FROM AccountType LEFT JOIN Account ON Account.AccountTypeId = AccountType.idAccountType JOIN Journal ON Journal.AccountId = Account.idAccount LEFT JOIN Document ON Document.idDocument = Journal.DocumentId " + "\r\nWHERE BalanceSheet = 0" + "\r\nAND ((DocumentDate >= " + Database.Quote(lPeriod[0]) + "\r\nAND DocumentDate < " + Database.Quote(cPeriod[1]) + ")" + "\r\nOR Account.AccountTypeId = " + (int)AcctType.Security + ")" + "\r\nGROUP BY idAccount" + "\r\nORDER BY " + string.Join(",", sort.Select(s => s + (_sortDescending ? " DESC" : "")).ToArray()) ); // Needs further processing to add investment gains // total, etc. return reportJson(json, fixProfitAndLoss(addInvestmentGains(report.ToList(), "Old", lPeriod[0], "PreviousPeriod", cPeriod[0], "CurrentPeriod", cPeriod[1])), "AccountType", "Account"); }