Example #1
0
        private void LabelMoveProfileDown_Click(object sender, EventArgs args)
        {
            try
            {
                if (listViewProfile.SelectedItems[0].Index == listViewProfile.Items.Count - 1)
                {
                    return;
                }

                ListViewItem selectedItem      = listViewProfile.SelectedItems[0];
                ListViewItem nextItem          = listViewProfile.Items[selectedItem.Index + 1];
                int          selectedItemIndex = selectedItem.Index;
                int          nextItemIndex     = nextItem.Index;

                Profile selectedProfile = null;
                Profile nextProfile     = null;

                try
                {
                    selectedProfile = Profiles.Find(x => x.Id == int.Parse(selectedItem.Tag.ToString()));
                    selectedProfile.ListViewIndex = nextItemIndex;
                    DBAccess.UpdateProfileListViewIndex(selectedProfile);

                    nextProfile = Profiles.Find(x => x.Id == int.Parse(nextItem.Tag.ToString()));
                    nextProfile.ListViewIndex = selectedItemIndex;
                    DBAccess.UpdateProfileListViewIndex(nextProfile);
                }
                catch (Exception)
                {
                    try
                    {
                        selectedProfile.ListViewIndex = selectedItem.Index;
                        nextProfile.ListViewIndex     = nextItem.Index;
                        DBAccess.UpdateProfileListViewIndex(selectedProfile);
                        DBAccess.UpdateProfileListViewIndex(nextProfile);
                    }
                    catch (Exception) {}
                    throw;
                }

                ListViewItem selectedItemClone = (ListViewItem)selectedItem.Clone();
                ListViewItem nextItemClone     = (ListViewItem)nextItem.Clone();

                listViewProfile.Items[selectedItemIndex] = nextItemClone;
                listViewProfile.Items[nextItemIndex]     = selectedItemClone;

                listViewProfile.Items[nextItemIndex].Selected = true;
            }
            catch (ArgumentOutOfRangeException) { }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Example #2
0
        private void LabelMoveProfileUp_Click(object sender, EventArgs args)
        {
            try
            {
                if (listViewProfile.SelectedItems[0].Index == 0)
                {
                    return;
                }

                ListViewItem selectedItem      = listViewProfile.SelectedItems[0];
                ListViewItem previousItem      = listViewProfile.Items[selectedItem.Index - 1];
                int          selectedItemIndex = selectedItem.Index;
                int          previousItemIndex = previousItem.Index;

                Profile selectedProfile = null;
                Profile previousProfile = null;

                try
                {
                    selectedProfile = Profiles.Find(x => x.Id == int.Parse(selectedItem.Tag.ToString()));
                    selectedProfile.ListViewIndex = selectedItem.Index - 1;
                    DBAccess.UpdateProfileListViewIndex(selectedProfile);

                    previousProfile = Profiles.Find(x => x.Id == int.Parse(previousItem.Tag.ToString()));
                    previousProfile.ListViewIndex = selectedItem.Index;
                    DBAccess.UpdateProfileListViewIndex(previousProfile);
                }
                catch (Exception)
                {
                    selectedProfile.ListViewIndex = selectedItem.Index;
                    previousProfile.ListViewIndex = previousItem.Index;
                    DBAccess.UpdateProfileListViewIndex(selectedProfile);
                    DBAccess.UpdateProfileListViewIndex(previousProfile);
                    throw;
                }

                ListViewItem selectedItemClone = (ListViewItem)selectedItem.Clone();
                ListViewItem previousItemClone = (ListViewItem)previousItem.Clone();

                listViewProfile.Items[selectedItemIndex] = previousItemClone;
                listViewProfile.Items[previousItemIndex] = selectedItemClone;

                listViewProfile.Items[previousItemIndex].Selected = true;
            }
            catch (ArgumentOutOfRangeException) { }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Example #3
0
        //public void UpdateListViewItem(Profile profile)
        //{
        //    foreach (ListViewItem i in listViewProfile.Items)
        //        if ((int)i.Tag == profile.Id)
        //        {
        //            EditListViewItem(profile, i);
        //            return;
        //        }
        //}

        private void UpdateProfileListViewIndexes()
        {
            foreach (ListViewItem item in listViewProfile.Items)
            {
                Profile profile = Profiles.Find(o => o.Id == (int)item.Tag);

                if (profile.ListViewIndex != item.Index)
                {
                    profile.ListViewIndex = item.Index;
                    profile.GroupName     = item.Group.Header;
                    DBAccess.UpdateProfileListViewIndex(profile);
                }
            }
        }