示例#1
0
        private void btnCancelProfile_Click(object sender, EventArgs e)
        {
            ZAMsettings.RollbackCachedConfiguration();

            errorProvider.Clear();

            if (lvUserProfiles.SelectedItems.Count > 0)
            {
                UserProfileListViewItem itemBeingEdited = (UserProfileListViewItem)lvUserProfiles.SelectedItems[0];
                UserProfile             userBeingEdited = itemBeingEdited.UserProfile;

                // If a newly added row, remove it and select the first one in list
                if (userBeingEdited.UniqueId.Length == 0)
                {
                    lvUserProfiles.Items.Remove(itemBeingEdited);
                    if (lvUserProfiles.Items.Count > 0)
                    {
                        lvUserProfiles.Items[0].Selected = true;
                        lvUserProfiles.Items[0].Focused  = true;
                    }
                }
                else
                {
                    // Refresh user from rolled back configuration
                    UserProfile refreshUser = ZAMsettings.Settings.UserProfiles[userBeingEdited.UniqueId];
                    UserProfiles_LoadFields(refreshUser);

                    // This will clone the UserProfile so that the listview doesn't have a direct link to the configuration
                    itemBeingEdited.UserProfile = refreshUser;
                }
            }

            EditingUserProfiles = false;
        }
示例#2
0
        private void btnRemoveProfile_Click(object sender, EventArgs e)
        {
            if (lvUserProfiles.SelectedItems.Count > 0)
            {
                UserProfileListViewItem itemBeingEdited = (UserProfileListViewItem)lvUserProfiles.SelectedItems[0];
                UserProfile             userBeingEdited = itemBeingEdited.UserProfile;

                if (MessageBox.Show(this, $"Delete user ({userBeingEdited.Name}), are you sure?", "Deletion Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    try
                    {
                        ZAMsettings.BeginCachedConfiguration();

                        ZAMsettings.Settings.DeleteUserProfile(userBeingEdited);

                        ZAMsettings.CommitCachedConfiguration();

                        lvUserProfiles.BeginUpdate();
                        lvUserProfiles.Items.Remove(itemBeingEdited);

                        if (lvUserProfiles.Items.Count > 0)
                        {
                            lvUserProfiles.Items[0].Focused  = true;
                            lvUserProfiles.Items[0].Selected = true;
                        }
                        lvUserProfiles.EndUpdate();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Exception occurred: " + ex.ToString(), "Error deleting User Profile", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
示例#3
0
        private void btnAddProfile_Click(object sender, EventArgs e)
        {
            UserProfileListViewItem item = new UserProfileListViewItem();

            lvUserProfiles.Items.Add(item);
            item.Selected = true;
            item.Focused  = true;

            ZAMsettings.BeginCachedConfiguration();
            EditingUserProfiles = true;
        }
示例#4
0
        private void btnSaveProfile_Click(object sender, EventArgs e)
        {
            bool errorOccurred = false;

            // this should not happen
            if (lvUserProfiles.SelectedItems.Count < 1)
            {
                ZAMsettings.RollbackCachedConfiguration();
                EditingUserProfiles = false;
                return;
            }

            UserProfileListViewItem itemBeingEdited = (UserProfileListViewItem)lvUserProfiles.SelectedItems[0];
            UserProfile             userBeingEdited = itemBeingEdited.UserProfile;

            errorOccurred = (errorOccurred || ValidateUserProfiles(tbName));
            errorOccurred = (errorOccurred || ValidateUserProfiles(ckbDefault));
            errorOccurred = (errorOccurred || ValidateUserProfiles(tbWeight));
            errorOccurred = (errorOccurred || ValidateUserProfiles(rbLbs));
            errorOccurred = (errorOccurred || ValidateUserProfiles(rbKgs));
            errorOccurred = (errorOccurred || ValidateUserProfiles(nPowerThreshold));
            errorOccurred = (errorOccurred || ValidateUserProfiles(tbEmailAddr));
            //errorOccurred = (errorOccurred || ValidateUserProfiles(clbCollectors));

            if (!errorOccurred)
            {
                try
                {
                    // Add or Update the UserProfile dictionary in the configuration.
                    ZAMsettings.Settings.UpsertUserProfile(userBeingEdited);

                    ZAMsettings.CommitCachedConfiguration();

                    lvUserProfiles.BeginUpdate();

                    // Refresh the fields and the list view
                    UserProfiles_LoadFields(userBeingEdited);
                    itemBeingEdited.Refresh();

                    //UserProfileListViewItem lvi = new UserProfileListViewItem(userBeingEdited);
                    //lvUserProfiles.Items.Add(lvi);
                    //lvi.Selected = true;

                    //lvUserProfiles.Items.Remove(itemBeingEdited);

                    foreach (UserProfileListViewItem item in lvUserProfiles.Items)
                    {
                        bool isDefault = (item.UserProfile.UniqueId == ZAMsettings.Settings.DefaultUserProfile);

                        if (item.UserProfile.Default != isDefault)
                        {
                            item.UserProfile.Default = isDefault;
                            item.Refresh();
                        }
                    }

                    lvUserProfiles.EndUpdate();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Exception occurred: " + ex.ToString(), "Error saving User Profile", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    errorOccurred = true;
                }
                finally
                {
                    EditingUserProfiles = false;
                }
            }
        }