コード例 #1
0
        private void setDefault()
        {
            if (editMode == ByStaff)
            {
                try
                {
                    if (EntitiesTo.SelectedItems == null)
                    {
                        MessageFunctions.Error("Error setting default Entity: no Entity selected.", null);
                    }
                    else if (EntitiesTo.SelectedItems.Count > 1)
                    {
                        MessageFunctions.InvalidMessage("Cannot set default Entity. Please ensure only one Entity is selected.", "Multiple Entities selected");
                    }
                    else
                    {
                        EntityProxy thisRecord = (EntityProxy)EntitiesTo.SelectedItem;
                        if (thisRecord.Default == false)
                        {
                            int  entityID = thisRecord.ID;
                            bool success  = StaffFunctions.ChangeDefault(entityID, selectedStaffID);
                            if (success)
                            {
                                refreshEntitySummaries(false);
                                CommitButton.IsEnabled = true;
                            }
                        }
                    }
                }
                catch (Exception generalException)
                {
                    MessageFunctions.Error("Error setting default Entity", generalException);
                }
            }
            else
            {
                try
                {
                    if (StaffTo.SelectedItems != null)
                    {
                        List <StaffProxySmall> defaultList = new List <StaffProxySmall>();
                        foreach (var selectedRow in StaffTo.SelectedItems)
                        {
                            defaultList.Add((StaffProxySmall)selectedRow);
                        }

                        bool success = StaffFunctions.MakeDefault(defaultList, selectedEntity);
                        if (success)
                        {
                            refreshStaffSummaries(false);
                            CommitButton.IsEnabled = true;
                        }
                    }
                    else
                    {
                        MessageFunctions.Error("Error setting default Entity: no staff selected.", null);
                    }
                }
                catch (Exception generalException)
                {
                    MessageFunctions.Error("Error setting default Entity", generalException);
                }
            }
        }