Esempio n. 1
0
        private void BtnConfirm_Click(object sender, RoutedEventArgs e)
        {
            string[] data = dtg.GetSelectedData();

            if (data is null)
            {
                Close();
            }

            if (parent is UserControls.ValidatedTextbox tbx)
            {
                tbx.Text = data[0];
            }
            else if (parent is CalandarView calView)
            {
                calView.SelectSpecificAppointment(data);
            }
            else
            {
                throw new NotImplementedException();
            }

            Close();
        }
        /// <summary>
        /// Move the user to editing whichever table they have selected
        /// </summary>
        private void UpdateMode(string newMode)
        {
            // Whenever a new item in the same table is selected:
            if (newMode == mode)
            {
                // Display the contacts/dogs/clients related to the selected item
                if (mode == contactString)
                {
                    string[] selectedData = dtgContacts.GetSelectedData();
                    if (selectedData is null)
                    {
                        return;
                    }
                    if (selectedData[0] != "No Results!")
                    {
                        dtgDogs.ChangeSearch(1, selectedData[1]);
                        dtgClients.ChangeSearch(0, selectedData[1]);
                    }
                }
                else if (mode == dogString)
                {
                    string[] selectedData = dtgDogs.GetSelectedData();
                    if (selectedData is null)
                    {
                        return;
                    }
                    if (selectedData[0] != "No Results!")
                    {
                        dtgContacts.ChangeSearch(1, selectedData[1]);
                        dtgClients.ChangeSearch(0, selectedData[1]);
                    }
                }
                else if (mode == clientString)
                {
                    string[] selectedData = dtgClients.GetSelectedData();
                    if (selectedData is null)
                    {
                        return;
                    }
                    if (selectedData[0] != "No Results!")
                    {
                        dtgContacts.ChangeSearch(1, selectedData[0]);
                        dtgDogs.ChangeSearch(1, selectedData[0]);
                    }
                }
            }
            else
            {
                mode = newMode;

                if (mode == "")
                {
                    return;
                }

                double notSelMax = 200;
                double selMax    = 650;

                lblEditBtn.Content        = $"Editing {mode}";
                lblStartAddingBtn.Content = $"Add New {mode}";

                // Display the selected data
                // Show related items in the other tables
                // Resize the tables

                if (mode == contactString)
                {
                    string[] selectedData = dtgContacts.GetSelectedData();
                    if (selectedData[0] == "No Results!")
                    {
                        return;
                    }
                    dtgContacts.ClearSearch();
                    if (selectedData is null)
                    {
                        return;
                    }
                    dtgDogs.ChangeSearch(1, selectedData[1]);
                    dtgClients.ChangeSearch(0, selectedData[1]);
                    dtgContacts.SetMaxHeight(selMax);
                }
                else if (mode == dogString)
                {
                    string[] selectedData = dtgDogs.GetSelectedData();
                    if (selectedData[0] == "No Results!")
                    {
                        return;
                    }
                    dtgDogs.ClearSearch();
                    if (selectedData is null)
                    {
                        return;
                    }
                    dtgContacts.ChangeSearch(1, selectedData[1]);
                    dtgClients.ChangeSearch(0, selectedData[1]);
                    dtgDogs.SetMaxHeight(selMax);
                }
                else if (mode == clientString)
                {
                    string[] selectedData = dtgClients.GetSelectedData();
                    if (selectedData[0] == "No Results!")
                    {
                        return;
                    }
                    dtgClients.ClearSearch();
                    if (selectedData is null)
                    {
                        return;
                    }
                    dtgContacts.ChangeSearch(1, selectedData[0]);
                    dtgDogs.ChangeSearch(1, selectedData[0]);
                    dtgClients.SetMaxHeight(selMax);
                }

                if (mode != contactString)
                {
                    dtgContacts.SetMaxHeight(notSelMax);
                }
                if (mode != dogString)
                {
                    dtgDogs.SetMaxHeight(notSelMax);
                }
                if (mode != clientString)
                {
                    dtgClients.SetMaxHeight(double.NaN);
                }
            }
        }