Beispiel #1
0
        protected void btnSaveValue_Click(object sender, EventArgs e)
        {
            using (new Rock.Data.UnitOfWorkScope())
            {
                int metricValueId = (hfIdValue.Value) != null?Int32.Parse(hfIdValue.Value) : 0;

                var metricValueService = new Rock.Model.MetricValueService();
                Rock.Model.MetricValue metricValue;

                if (metricValueId == 0)
                {
                    metricValue          = new Rock.Model.MetricValue();
                    metricValue.IsSystem = false;
                    metricValue.MetricId = Int32.Parse(hfIdMetric.Value);
                    metricValueService.Add(metricValue, CurrentPersonId);
                }
                else
                {
                    metricValue = metricValueService.Get(metricValueId);
                }

                metricValue.Value       = tbValue.Text;
                metricValue.Description = tbValueDescription.Text;
                metricValue.xValue      = tbXValue.Text;
                metricValue.Label       = tbLabel.Text;
                metricValue.isDateBased = cbIsDateBased.Checked;
                metricValue.MetricId    = Int32.Parse(ddlMetricFilter.SelectedValue);
                metricValueService.Save(metricValue, CurrentPersonId);
            }

            BindGridValue();

            modalValue.Hide();
            pnlValueList.Visible = true;
        }
Beispiel #2
0
        protected void rGridValue_Delete(object sender, RowEventArgs e)
        {
            var metricValueService = new Rock.Model.MetricValueService();

            Rock.Model.MetricValue metricValue = metricValueService.Get((int)rGridValue.DataKeys[e.RowIndex]["id"]);
            if (metricValue != null)
            {
                metricValueService.Delete(metricValue, CurrentPersonId);
                metricValueService.Save(metricValue, CurrentPersonId);
            }

            BindGridValue();
        }
        /// <summary>
        /// Handles the Delete event of the gMetricValues 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 gMetricValues_Delete( object sender, RowEventArgs e )
        {
            var rockContext = new RockContext();
            MetricValueService metricValueService = new MetricValueService( rockContext );
            MetricValue metricValue = metricValueService.Get( e.RowKeyId );
            if ( metricValue != null )
            {
                string errorMessage;
                if ( !metricValueService.CanDelete( metricValue, out errorMessage ) )
                {
                    mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                    return;
                }

                metricValueService.Delete( metricValue );
                rockContext.SaveChanges();
            }

            BindGrid();
        }
Beispiel #4
0
        /// <summary>
        /// Handles the Click event of the btnSaveValue 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 btnSaveValue_Click( object sender, EventArgs e )
        {
            using ( new Rock.Data.UnitOfWorkScope() )
            {
                int metricValueId = hfMetricValueId.ValueAsInt();
                var metricValueService = new MetricValueService();
                MetricValue metricValue;

                if ( metricValueId == 0 )
                {
                    metricValue = new MetricValue();
                    metricValue.IsSystem = false;
                    metricValue.MetricId = hfMetricId.ValueAsInt();
                    metricValueService.Add( metricValue, CurrentPersonId );
                }
                else
                {
                    metricValue = metricValueService.Get( metricValueId );
                }

                metricValue.Value = tbValue.Text;
                metricValue.Description = tbValueDescription.Text;
                metricValue.xValue = tbXValue.Text;
                metricValue.Label = tbLabel.Text;
                metricValue.isDateBased = cbIsDateBased.Checked;
                metricValue.MetricId = Int32.Parse(ddlMetricFilter.SelectedValue);

                if ( metricValue.IsValid )
                {
                    metricValueService.Save( metricValue, CurrentPersonId );
                    BindGrid();
                    hfMetricValueId.Value = string.Empty;
                    mdValueDialog.Hide();
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Handles the Delete event of the gMetricValues 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 gMetricValues_Delete( object sender, RowEventArgs e )
        {
            var metricValueService = new MetricValueService();

            MetricValue metricValue = metricValueService.Get( (int)e.RowKeyValue );
            if ( metricValue != null )
            {
                metricValueService.Delete( metricValue, CurrentPersonId );
                metricValueService.Save( metricValue, CurrentPersonId );
            }

            BindGrid();
        }
Beispiel #6
0
        /// <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 )
        {
            MetricValue metricValue;
            var rockContext = new RockContext();
            MetricValueService metricValueService = new MetricValueService( rockContext );

            int metricValueId = int.Parse( hfMetricValueId.Value );

            if ( metricValueId == 0 )
            {
                metricValue = new MetricValue();
                metricValueService.Add( metricValue );
                metricValue.MetricId = hfMetricId.ValueAsInt();
                metricValue.Metric = metricValue.Metric ?? new MetricService( rockContext ).Get( metricValue.MetricId );
            }
            else
            {
                metricValue = metricValueService.Get( metricValueId );
            }

            metricValue.MetricValueType = ddlMetricValueType.SelectedValueAsEnum<MetricValueType>();
            metricValue.XValue = tbXValue.Text;
            metricValue.YValue = tbYValue.Text.AsDecimalOrNull();
            metricValue.Note = tbNote.Text;
            metricValue.MetricValueDateTime = dpMetricValueDateTime.SelectedDate;

            // Get EntityId from EntityType UI controls
            var metricEntityType = EntityTypeCache.Read( metricValue.Metric.EntityTypeId ?? 0 );
            Control entityTypeEditControl = phEntityTypeEntityIdValue.FindControl( "entityTypeEditControl" );
            if ( metricEntityType != null && metricEntityType.SingleValueFieldType != null && metricEntityType.SingleValueFieldType.Field is IEntityFieldType )
            {
                metricValue.EntityId = ( metricEntityType.SingleValueFieldType.Field as IEntityFieldType ).GetEditValueAsEntityId( entityTypeEditControl, new Dictionary<string, ConfigurationValue>() );
            }
            else
            {
                metricValue.EntityId = null;
            }

            if ( !metricValue.IsValid )
            {
                // Controls will render the error messages
                return;
            }

            rockContext.SaveChanges();

            var qryParams = new Dictionary<string, string>();
            qryParams.Add( "MetricId", hfMetricId.Value );
            qryParams.Add( "MetricCategoryId", hfMetricCategoryId.Value );
            qryParams.Add( "ExpandedIds", PageParameter( "ExpandedIds" ) );
            NavigateToParentPage( qryParams );
        }
        /// <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 )
        {
            MetricValue metricValue;
            var rockContext = new RockContext();
            MetricValueService metricValueService = new MetricValueService( rockContext );

            int metricValueId = int.Parse( hfMetricValueId.Value );

            if ( metricValueId == 0 )
            {
                metricValue = new MetricValue();
                metricValueService.Add( metricValue );
                metricValue.MetricId = hfMetricId.ValueAsInt();
                metricValue.Metric = metricValue.Metric ?? new MetricService( rockContext ).Get( metricValue.MetricId );
                metricValue.MetricValuePartitions = new List<MetricValuePartition>();
            }
            else
            {
                metricValue = metricValueService.Get( metricValueId );
            }

            metricValue.MetricValueType = ddlMetricValueType.SelectedValueAsEnum<MetricValueType>();
            metricValue.XValue = tbXValue.Text;
            metricValue.YValue = tbYValue.Text.AsDecimalOrNull();
            metricValue.Note = tbNote.Text;
            metricValue.MetricValueDateTime = dpMetricValueDateTime.SelectedDate;

            // Get EntityId from EntityType UI controls
            foreach ( var metricPartition in metricValue.Metric.MetricPartitions )
            {
                var metricPartitionEntityType = EntityTypeCache.Read( metricPartition.EntityTypeId ?? 0 );
                var controlId = string.Format( "metricPartition{0}_entityTypeEditControl", metricPartition.Id );
                Control entityTypeEditControl = phMetricValuePartitions.FindControl( controlId );
                var metricValuePartition = metricValue.MetricValuePartitions.FirstOrDefault( a => a.MetricPartitionId == metricPartition.Id );
                if ( metricValuePartition == null )
                {
                    metricValuePartition = new MetricValuePartition();
                    metricValuePartition.MetricPartitionId = metricPartition.Id;
                    metricValue.MetricValuePartitions.Add( metricValuePartition );
                }

                if ( metricPartitionEntityType != null && metricPartitionEntityType.SingleValueFieldType != null && metricPartitionEntityType.SingleValueFieldType.Field is IEntityFieldType )
                {
                    metricValuePartition.EntityId = ( metricPartitionEntityType.SingleValueFieldType.Field as IEntityFieldType ).GetEditValueAsEntityId( entityTypeEditControl, new Dictionary<string, ConfigurationValue>() );
                }
                else
                {
                    metricValuePartition.EntityId = null;
                }

                if ( metricPartition.IsRequired && metricPartitionEntityType != null && !metricValuePartition.EntityId.HasValue )
                {
                    nbValueRequired.Text = string.Format( "A value for {0} is required", metricPartition.Label ?? metricPartitionEntityType.FriendlyName );
                    nbValueRequired.Dismissable = true;
                    nbValueRequired.Visible = true;
                    return;
                }
            }

            if ( !metricValue.IsValid )
            {
                // Controls will render the error messages
                return;
            }

            rockContext.SaveChanges();

            var qryParams = new Dictionary<string, string>();
            qryParams.Add( "MetricId", hfMetricId.Value );
            qryParams.Add( "MetricCategoryId", hfMetricCategoryId.Value );
            qryParams.Add( "ExpandedIds", PageParameter( "ExpandedIds" ) );
            NavigateToParentPage( qryParams );
        }
Beispiel #8
0
        public void SaveMetric(DateTime dt, int metric, Decimal value, int campus, string notes, int type)
        {
            int metricValueId = 0;
            RockContext rockContext = new RockContext();
            MetricValue metricValue;
            MetricValueService metricValueService = new MetricValueService(rockContext);

            //Does this metric already exist?
            var existingMetric = metricValueService
                .Queryable(
                    ).FirstOrDefault(a => a.MetricId == metric && a.MetricValueDateTime == dt && a.EntityId == campus);

            if (existingMetric != null)
            {
                metricValueId = existingMetric.Id;
            }

            if (metricValueId == 0)
            {
                metricValue = new MetricValue();
                metricValueService.Add(metricValue);
                metricValue.MetricId = metric;
                metricValue.Metric = metricValue.Metric ?? new MetricService(rockContext).Get(metricValue.MetricId);
            }
            else
            {
                metricValue = metricValueService.Get(metricValueId);
            }

            metricValue.MetricValueType = (MetricValueType)type;
            metricValue.XValue = null;
            metricValue.YValue = value;
            metricValue.Note = notes;
            metricValue.MetricValueDateTime = dt;
            metricValue.EntityId = campus;

            rockContext.SaveChanges();
        }