private void SaveData()
        {
            if (ServiceLock != null)
            {
                ServiceLock.Enabled = Enabled.Checked;

                ServiceLockConfigurationController controller = new ServiceLockConfigurationController();
                DateTime scheduledDate = DateTime.ParseExact(ScheduleDate.Text, CalendarExtender.Format, null);

                if (ScheduleTime.Text.Contains("_") == false)
                {
                    try
                    {
                        DateTime scheduleTime = DateTime.ParseExact(ScheduleTime.Text, TIME_FORMAT, null);
                        scheduledDate = scheduledDate.Add(scheduleTime.TimeOfDay);
                    }
                    catch (Exception)
                    {
                        //Ignore this exception since the time is not fully typed in or in an incorrect format,
                        //that will be validated when the user presses apply.
                    }
                }               
                
                if (controller.UpdateServiceLock(ServiceLock.GetKey(), Enabled.Checked, scheduledDate))
                {
                    if (ServiceLockUpdated != null)
                        ServiceLockUpdated(ServiceLock);
                }
                else
                {
                    ErrorMessageBox.Message = SR.ServiceLockUpdateFailed_ContactAdmin;
                    ErrorMessageBox.MessageType =
                        MessageBox.MessageTypeEnum.ERROR;
                    ErrorMessageBox.Show();
                }
            }

        }
Example #2
0
        /// <summary>
        /// Load the devices for the partition based on the filters specified in the filter panel.
        /// </summary>
        /// <remarks>
        /// This method only reloads and binds the list bind to the internal grid.
        /// </remarks>
        public void LoadServiceLocks()
        {
            ServiceLockSelectCriteria criteria = new ServiceLockSelectCriteria();

            ServiceLockConfigurationController controller = new ServiceLockConfigurationController();

            if (TypeDropDownList.SelectedValue != SR.All)
            {
                criteria.ServiceLockTypeEnum.EqualTo(ServiceLockTypeEnum.GetEnum(TypeDropDownList.SelectedValue));
            }
            
            if (StatusFilter.SelectedIndex != 0)
            {
                if (StatusFilter.SelectedIndex == 1)
                    criteria.Enabled.EqualTo(true);
                else
                    criteria.Enabled.EqualTo(false);
            }

            if (FileSystemFilter.SelectedIndex != -1)
            {
                FileSystemsConfigurationController fsController = new FileSystemsConfigurationController();
                List<ServerEntityKey> fileSystemKeys = new List<ServerEntityKey>();
                foreach (ListItem fileSystem in FileSystemFilter.Items)
                {
                    if (fileSystem.Selected)
                    {
                        fileSystemKeys.Add(new ServerEntityKey("FileSystem", fileSystem.Value));
                    }
                }

                IList<Model.Filesystem> fs = fsController.GetFileSystems(fileSystemKeys);

                if(fs != null)
                {
                    List<ServerEntityKey> entityKeys = new List<ServerEntityKey>();
                    foreach(Filesystem f in fs)
                    {
                        entityKeys.Add(f.Key);
                    }
                    criteria.FilesystemKey.In(entityKeys);    
                }                
            }

            IList<ServiceLock> services = controller.GetServiceLocks(criteria);

        	List<ServiceLock> sortedServices =
        		CollectionUtils.Sort(services, delegate(ServiceLock a, ServiceLock b)
        		                               	{
        		                               		if (a == null)
        		                               		{
        		                               			if (b == null)
        		                               			{
        		                               				// If both null, they're equal. 
        		                               				return 0;
        		                               			}
        		                               			else
        		                               			{
        		                               				// If x is null and y is not null, y
        		                               				// is greater. 
        		                               				return -1;
        		                               			}
        		                               		}
        		                               		else
        		                               		{
        		                               			// If a is not null...
        		                               			if (b == null)
        		                               			{
															// ...and b is null, x is greater.
															return 1;
        		                               			}
        		                               			else
        		                               			{
        		                               				// just compare
															if (a.Filesystem == null || b.Filesystem == null)
																return a.ServiceLockTypeEnum.Description.CompareTo(b.ServiceLockTypeEnum.Description);

															int retVal =
        		                               					a.Filesystem.Description.CompareTo(
        		                               						b.Filesystem.Description);
															if (retVal == 0)
																return a.ServiceLockTypeEnum.Description.CompareTo(b.ServiceLockTypeEnum.Description);
        		                               				return retVal;
        		                               			}
        		                               		}
        		                               	});

			
            ServiceLockCollection items = new ServiceLockCollection();
            items.Add(sortedServices);

            ServiceLockGridViewControl.ServiceLocks = items;

            ServiceLockGridViewControl.RefreshCurrentPage();
        }