/// <summary> /// Sets the edit value from IEntity.Id value /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="id">The identifier.</param> public void SetEditValueFromEntityId(Control control, Dictionary <string, ConfigurationValue> configurationValues, int?id) { var item = new FinancialStatementTemplateService(new RockContext()).Get(id ?? 0); var guidValue = item != null?item.Guid.ToString() : string.Empty; SetEditValue(control, configurationValues, guidValue); }
/// <summary> /// Handles the Click event of the lbEdit 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 lbEdit_Click(object sender, EventArgs e) { var financialStatementTemplateService = new FinancialStatementTemplateService(new RockContext()); var statementTemplate = financialStatementTemplateService.Get(hfStatementTemplateId.ValueAsInt()); ShowEditDetails(statementTemplate); }
/// <summary> /// Gets the edit value as the IEntity.Id /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <returns></returns> public int?GetEditValueAsEntityId(Control control, Dictionary <string, ConfigurationValue> configurationValues) { var guid = GetEditValue(control, configurationValues).AsGuid(); var item = new FinancialStatementTemplateService(new RockContext()).Get(guid); return(item != null ? item.Id : ( int? )null); }
/// <summary> /// Returns breadcrumbs specific to the block that should be added to navigation /// based on the current page reference. This function is called during the page's /// oninit to load any initial breadcrumbs. /// </summary> /// <param name="pageReference">The <see cref="Rock.Web.PageReference" />.</param> /// <returns> /// A <see cref="System.Collections.Generic.List{BreadCrumb}" /> of block related <see cref="Rock.Web.UI.BreadCrumb">BreadCrumbs</see>. /// </returns> public override List <BreadCrumb> GetBreadCrumbs(PageReference pageReference) { var breadCrumbs = new List <BreadCrumb>(); int?statementTemplateId = PageParameter(pageReference, PageParameterKey.StatementTemplateId).AsIntegerOrNull(); if (statementTemplateId != null) { var statementTemplate = new FinancialStatementTemplateService(new RockContext()).Get(statementTemplateId.Value); if (statementTemplate != null) { breadCrumbs.Add(new BreadCrumb(statementTemplate.Name, pageReference)); } else { breadCrumbs.Add(new BreadCrumb("New Template", pageReference)); } } else { // don't show a breadcrumb if we don't have a pageparam to work with } return(breadCrumbs); }
/// <summary> /// Handles the Click event of the lbCancel 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 lbCancel_Click(object sender, EventArgs e) { var statementTemplateId = hfStatementTemplateId.Value.AsIntegerOrNull(); if (statementTemplateId.HasValue && statementTemplateId > 0) { var service = new FinancialStatementTemplateService(new RockContext()); var statementTemplate = service.Get(statementTemplateId.Value); ShowReadonlyDetails(statementTemplate); } else { NavigateToParentPage(); } }
/// <summary> /// Shows the detail. /// </summary> /// <param name="statementTemplateId">The statement template identifier.</param> public void ShowDetail(int statementTemplateId) { FinancialStatementTemplate financialStatementTemplate = null; bool editAllowed = UserCanEdit; if (!statementTemplateId.Equals(0)) { financialStatementTemplate = new FinancialStatementTemplateService(new RockContext()).Get(statementTemplateId); editAllowed = editAllowed || financialStatementTemplate.IsAuthorized(Authorization.EDIT, CurrentPerson); pdAuditDetails.SetEntity(financialStatementTemplate, ResolveRockUrl("~")); } if (financialStatementTemplate == null) { financialStatementTemplate = new FinancialStatementTemplate(); // hide the panel drawer that show created and last modified dates pdAuditDetails.Visible = false; } hfStatementTemplateId.Value = financialStatementTemplate.Id.ToString(); bool readOnly = false; nbEditModeMessage.Text = string.Empty; if (!editAllowed) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(FinancialStatementTemplate.FriendlyTypeName); } if (readOnly) { ShowReadonlyDetails(financialStatementTemplate); } else { if (financialStatementTemplate.Id > 0) { ShowReadonlyDetails(financialStatementTemplate); } else { ShowEditDetails(financialStatementTemplate); } } }
/// <summary> /// Returns the field's current value(s) /// </summary> /// <param name="parentControl">The parent control.</param> /// <param name="value">Information about the value</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param> /// <returns></returns> public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed) { string formattedValue = string.Empty; Guid?financialStatementTemplateGuid = value.AsGuidOrNull(); if (financialStatementTemplateGuid.HasValue) { using (var rockContext = new RockContext()) { formattedValue = new FinancialStatementTemplateService(rockContext).GetSelect(financialStatementTemplateGuid.Value, s => s.Name); } } return(base.FormatValue(parentControl, formattedValue, null, condensed)); }
/// <summary> /// Sets the value. /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="value">The value.</param> public override void SetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues, string value) { var picker = control as FinancialStatementTemplatePicker; if (picker != null) { int? itemId = null; Guid?itemGuid = value.AsGuidOrNull(); if (itemGuid.HasValue) { using (var rockContext = new RockContext()) { itemId = new FinancialStatementTemplateService(rockContext).Queryable().Where(a => a.Guid == itemGuid.Value).Select(a => ( int? )a.Id).FirstOrDefault(); } } picker.SetValue(itemId); } }
/// <summary> /// Reads new values entered by the user for the field /// </summary> /// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param> /// <param name="configurationValues">The configuration values.</param> /// <returns></returns> public override string GetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues) { var picker = control as FinancialStatementTemplatePicker; if (picker != null) { int? itemId = picker.SelectedValue.AsIntegerOrNull(); Guid?itemGuid = null; if (itemId.HasValue) { using (var rockContext = new RockContext()) { itemGuid = new FinancialStatementTemplateService(rockContext).Queryable().AsNoTracking().Where(a => a.Id == itemId.Value).Select(a => ( Guid? )a.Guid).FirstOrDefault(); } } return(itemGuid?.ToString() ?? string.Empty); } return(null); }
/// <summary> /// Handles the Delete event of the gList control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param> protected void gList_DeleteClick(object sender, RowEventArgs e) { var rockContext = new RockContext(); var financialStatementTemplateService = new FinancialStatementTemplateService(rockContext); var financialStatementTemplate = financialStatementTemplateService.Get(e.RowKeyId); if (financialStatementTemplate != null) { string errorMessage; if (!financialStatementTemplateService.CanDelete(financialStatementTemplate, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } financialStatementTemplateService.Delete(financialStatementTemplate); rockContext.SaveChanges(); } BindGrid(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var rockContext = new RockContext(); var financialStatementTemplateService = new FinancialStatementTemplateService(rockContext); // Use AsNoTracking() since these records won't be modified, and therefore don't need to be tracked by the EF change tracker var qry = financialStatementTemplateService.Queryable().AsNoTracking(); // name filter string nameFilter = rFilter.GetUserPreference(UserPreferenceKey.Name); if (!string.IsNullOrEmpty(nameFilter)) { qry = qry.Where(a => a.Name.Contains(nameFilter)); } bool showInactiveAccounts = rFilter.GetUserPreference(UserPreferenceKey.IncludeInactive).AsBoolean(); if (!showInactiveAccounts) { qry = qry.Where(a => a.IsActive == true); } SortProperty sortProperty = gList.SortProperty; if (sortProperty != null) { qry = qry.Sort(sortProperty); } else { qry = qry.OrderBy(a => a.Name); } gList.EntityTypeId = EntityTypeCache.Get <FinancialStatementTemplate>().Id; gList.SetLinqDataSource(qry); gList.DataBind(); }
/// <summary> /// Handles the Click event of the lbSave 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 lbSave_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } var rockContext = new RockContext(); var financialStatementTemplateService = new FinancialStatementTemplateService(rockContext); var statementTemplateId = hfStatementTemplateId.Value.AsIntegerOrNull(); FinancialStatementTemplate financialStatementTemplate = null; if (statementTemplateId.HasValue) { financialStatementTemplate = financialStatementTemplateService.Get(statementTemplateId.Value); } var isNew = financialStatementTemplate == null; if (isNew) { financialStatementTemplate = new FinancialStatementTemplate(); financialStatementTemplateService.Add(financialStatementTemplate); } financialStatementTemplate.Name = tbName.Text; financialStatementTemplate.Description = tbDescription.Text; financialStatementTemplate.IsActive = cbIsActive.Checked; financialStatementTemplate.ReportTemplate = ceReportTemplate.Text; financialStatementTemplate.FooterSettings.HtmlFragment = ceFooterTemplateHtmlFragment.Text; financialStatementTemplate.ReportSettings.PDFSettings.MarginTopMillimeters = nbMarginTopMillimeters.IntegerValue; financialStatementTemplate.ReportSettings.PDFSettings.MarginBottomMillimeters = nbMarginBottomMillimeters.IntegerValue; financialStatementTemplate.ReportSettings.PDFSettings.MarginLeftMillimeters = nbMarginLeftMillimeters.IntegerValue; financialStatementTemplate.ReportSettings.PDFSettings.MarginRightMillimeters = nbMarginRightMillimeters.IntegerValue; financialStatementTemplate.ReportSettings.PDFSettings.PaperSize = ddlPaperSize.SelectedValueAsEnumOrNull <FinancialStatementTemplatePDFSettingsPaperSize>() ?? FinancialStatementTemplatePDFSettingsPaperSize.Letter; var transactionSetting = new FinancialStatementTemplateTransactionSetting(); transactionSetting.CurrencyTypesForCashGiftGuids = dvpCurrencyTypesCashGifts.SelectedValuesAsInt.Select(a => DefinedValueCache.Get(a)?.Guid).Where(a => a.HasValue).Select(a => a.Value).ToList(); transactionSetting.CurrencyTypesForNonCashGuids = dvpCurrencyTypesNonCashGifts.SelectedValuesAsInt.Select(a => DefinedValueCache.Get(a)?.Guid).Where(a => a.HasValue).Select(a => a.Value).ToList(); transactionSetting.TransactionTypeGuids = dvpTransactionType.SelectedValuesAsInt.Select(a => DefinedValueCache.Get(a)?.Guid).Where(a => a.HasValue).Select(a => a.Value).ToList(); transactionSetting.HideRefundedTransactions = cbHideRefundedTransactions.Checked; transactionSetting.HideCorrectedTransactionOnSameData = cbHideModifiedTransactions.Checked; if (rbAllTaxDeductibleAccounts.Checked) { transactionSetting.AccountSelectionOption = FinancialStatementTemplateTransactionSettingAccountSelectionOption.AllTaxDeductibleAccounts; } else if (cbIncludeChildAccountsCustom.Checked) { transactionSetting.AccountSelectionOption = FinancialStatementTemplateTransactionSettingAccountSelectionOption.SelectedAccountsIncludeChildren; } else { transactionSetting.AccountSelectionOption = FinancialStatementTemplateTransactionSettingAccountSelectionOption.SelectedAccounts; } transactionSetting.SelectedAccountIds = apTransactionAccountsCustom.SelectedIds.ToList(); financialStatementTemplate.ReportSettings.TransactionSettings = transactionSetting; var pledgeSetting = new FinancialStatementTemplatePledgeSettings(); pledgeSetting.IncludeGiftsToChildAccounts = cbIncludeGiftsToChildAccounts.Checked; pledgeSetting.IncludeNonCashGifts = cbIncludeNonCashGifts.Checked; pledgeSetting.AccountIds = apPledgeAccounts.SelectedIds.ToList(); financialStatementTemplate.ReportSettings.PledgeSettings = pledgeSetting; int?existingLogoId = null; if (financialStatementTemplate.LogoBinaryFileId != imgTemplateLogo.BinaryFileId) { existingLogoId = financialStatementTemplate.LogoBinaryFileId; financialStatementTemplate.LogoBinaryFileId = imgTemplateLogo.BinaryFileId; } rockContext.SaveChanges(); var queryParams = new Dictionary <string, string>(); queryParams.Add(PageParameterKey.StatementTemplateId, financialStatementTemplate.Id.ToStringSafe()); NavigateToCurrentPage(queryParams); }