Пример #1
0
        /// <summary>Handles the process of re-linking an already existing User in this UserTrace to a new parent</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LinkButton_Click(object sender, EventArgs e)
        {
            if (GetSelectedIndex() == -1)
            {
                return;
            }

            if (MyTrace.AllUsers[GetSelectedIndex()].Equals(MyTrace.RootUser))
            {
                MessageBox.Show("You cannot re-link the Root User.", "no", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            UserLinkerForm Linker = new UserLinkerForm(MyTrace.AllUsers[GetSelectedIndex()], MyTrace.AllUsers);

            if (Linker.ShowDialog() != DialogResult.OK)
            {
                PreviewPictureBox.Refresh(); return;
            }


            //find the parent and link it.
            //Delink the user from the old parent
            MyTrace.AllUsers[GetSelectedIndex()].Parent?.RemoveChild(MyTrace.AllUsers[GetSelectedIndex()]);
            MyTrace.AllUsers[GetSelectedIndex()].Parent = null;

            //Link the new parent.
            MyTrace.AllUsers[GetSelectedIndex()].Parent = MyTrace.AllUsers[Linker.ListIndex];
            MyTrace.AllUsers[Linker.ListIndex].AddChild(MyTrace.AllUsers[GetSelectedIndex()]);
            GeneratePreview();
            PopulateListview();
            Modified = true;
        }
Пример #2
0
        //-[Buttons]------------------------------------------------------------------------------------------------------------------------------------------

        //You know maybe all of this logic should've been put *in* the UserTrace object.... oh well. It works, so it works

        /// <summary>Handles the adding of a new user to the UserTrace</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddButton_Click(object sender, EventArgs e)
        {
            User NewUser = new User();

            if (MyTrace.AllUsers.Count == 0)
            {
                MessageBox.Show("Since this is the first user, this will be the root user.\n\nThis can be changed later, but you may lose users before the root user if you save", "Root User Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if ("TRC".Equals(sender) || AddUnder())
                {
                    if (GetSelectedIndex() == -1)
                    {
                        return;
                    }
                    NewUser.Parent = MyTrace.AllUsers[GetSelectedIndex()];
                }
                else
                {
                    UserLinkerForm Linker = new UserLinkerForm(NewUser, MyTrace.AllUsers);
                    if (Linker.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    NewUser.Parent = MyTrace.AllUsers[Linker.ListIndex];
                    PreviewPictureBox.Refresh();
                }
            }


            UserForm TheForm = new UserForm(NewUser);

            if (TheForm.ShowDialog() != DialogResult.OK)
            {
                PreviewPictureBox.Refresh();  return;
            }

            while (MyTrace.AllUsers.Contains(NewUser))
            {
                MessageBox.Show("A user with the name " + NewUser.Name + " already exists! Please use a different name.", "Two people?", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (TheForm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }


            NewUser = TheForm.MyUser;
            if (MyTrace.AllUsers.Count == 0)
            {
                MyTrace.RootUser = NewUser;
            }
            MyTrace.AllUsers.Add(NewUser);
            NewUser.Parent?.AddChild(NewUser);

            GeneratePreview();
            PopulateListview();
        }