Beispiel #1
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 )
        {
            Device Device;
            DeviceService DeviceService = new DeviceService();
            AttributeService attributeService = new AttributeService();

            int DeviceId = int.Parse( hfDeviceId.Value );

            if ( DeviceId == 0 )
            {
                Device = new Device();
                DeviceService.Add( Device, CurrentPersonId );
            }
            else
            {
                Device = DeviceService.Get( DeviceId );
            }

            Device.Name = tbName.Text;
            Device.Description = tbDescription.Text;
            Device.IPAddress = tbIpAddress.Text;
            Device.DeviceTypeValueId = ddlDeviceType.SelectedValueAsInt().Value;
            Device.PrintToOverride = (PrintTo)System.Enum.Parse( typeof( PrintTo ), ddlPrintTo.SelectedValue );
            Device.PrinterDeviceId = ddlPrinter.SelectedValueAsInt();
            Device.PrintFrom = (PrintFrom)System.Enum.Parse( typeof( PrintFrom ), ddlPrintFrom.SelectedValue );

            if ( Device.Location == null )
            {
                Device.Location = new Location();
            }
            Device.Location.GeoPoint = gpGeoPoint.SelectedValue;
            Device.Location.GeoFence = gpGeoFence.SelectedValue;

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

            DeviceService.Save( Device, CurrentPersonId );

            NavigateToParentPage();
        }
Beispiel #2
0
        /// <summary>
        /// Handles the Delete event of the gDevice 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 gDevice_Delete( object sender, RowEventArgs e )
        {
            RockTransactionScope.WrapTransaction( () =>
            {
                DeviceService DeviceService = new DeviceService();
                Device Device = DeviceService.Get( (int)e.RowKeyValue );

                if ( Device != null )
                {
                    string errorMessage;
                    if ( !DeviceService.CanDelete( Device, out errorMessage ) )
                    {
                        mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                        return;
                    }

                    DeviceService.Delete( Device, CurrentPersonId );
                    DeviceService.Save( Device, CurrentPersonId );
                }
            } );

            BindGrid();
        }