Exemplo n.º 1
0
        private void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            //Code that deletes a project from Db
            bool result = CBZ.DeleteFromDb("Enterprises", CBZ.TempEnterprise.Id.ToString());

            CBZ.TempEnterprise = new Enterprise();

            if (result)
            {
                //Show Confirmation
                MessageBox.Show("Entrepriselisten blev slettet", "Entrepriser", MessageBoxButton.OK, MessageBoxImage.Information);
                //Reset Boxes
                TextBoxName.Text                  = "";
                TextBoxElaboration.Text           = "";
                TextBoxOfferList.Text             = "";
                ComboBoxCraftGroup1.SelectedIndex = -1;
                ComboBoxCraftGroup2.SelectedIndex = -1;
                ComboBoxCraftGroup3.SelectedIndex = -1;
                ComboBoxCraftGroup4.SelectedIndex = -1;

                //Update Enterprise List
                RefreshIndexedEnterprises();
                ListBoxEnterprises.ItemsSource = "";
                ListBoxEnterprises.ItemsSource = IndexedEnterprises;
            }
            else
            {
                //Show error
                MessageBox.Show("Databasen returnerede en fejl. Entrepriselisten blev ikke slettet. Prøv igen.", "Entrepriser", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Exemplo n.º 2
0
        private void ButtonErase_Click(object sender, RoutedEventArgs e)
        {
            if (CheckBoxEraseProject.IsChecked == true)
            {
                if (MessageBox.Show("Er du sikker på, at du vil slette projektet? Alle data vil gå tabt!", "Slet Projekt", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK)
                {
                    // Code that changes project status
                    bool result = Bizz.DeleteFromDb("Projects", Bizz.TempProject.Id.ToString());

                    if (result)
                    {
                        foreach (Enterprise enterprise in Bizz.EnterpriseList)
                        {
                            if (enterprise.Project.Id == Bizz.TempProject.CaseId)
                            {
                                foreach (SubEntrepeneur subEntrepeneur in Bizz.SubEntrepeneurs)
                                {
                                    if (subEntrepeneur.EnterpriseList.Id == enterprise.Id)
                                    {
                                        Bizz.DeleteFromDb("Requests", subEntrepeneur.Request.Id.ToString());
                                        Bizz.DeleteFromDb("IttLetters", subEntrepeneur.IttLetter.Id.ToString());
                                        Bizz.DeleteFromDb("Offers", subEntrepeneur.Offer.Id.ToString());
                                        Bizz.DeleteFromDb("SubEntrepeneurs", subEntrepeneur.Id.ToString());
                                    }
                                }
                                Bizz.DeleteFromDb("EnterpriseList", enterprise.Id.ToString());
                            }
                        }

                        //Show Confirmation
                        MessageBox.Show("Projektet blev slettet", "Slet Projekt", MessageBoxButton.OK, MessageBoxImage.Information);

                        //Update list of projects
                        Bizz.RefreshList("Projects");
                        Bizz.RefreshIndexedList("IndexedActiveProjects");
                        Bizz.RefreshIndexedList("IndexableProjects");

                        //Close right UserControl
                        Bizz.UcRightActive = false;
                        UcRight.Content    = new UserControl();
                    }
                    else
                    {
                        //Show error
                        MessageBox.Show("Databasen returnerede en fejl. Projektet blev ikke slettet. Prøv igen.", "Slet Projekt", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
            else
            {
                //Show error
                MessageBox.Show("Du har glemt at markere 'Godkend sletning af projekt'.", "Slet Projekt", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
        /// <summary>
        /// Method, that deletes the selected Contact from Db
        /// </summary>
        /// <returns>bool</returns>
        private bool DeleteContactFromDb()
        {
            bool result = false;

            try
            {
                bool tempResult = CBZ.DeleteFromDb("Contacts", CBZ.TempContact.Id.ToString());

                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(CBZ.TempContact.Person.Name + " kunne ikke slettes, da den er tilknyttet en Entrepenør." + ex, "Kontakter", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return(result);
        }
        private void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            bool allSubEntrepeneursDeleted  = true;
            bool allRequestsDeleted         = true;
            bool allIttLettersDeleted       = true;
            bool allOffersDeleted           = true;
            bool allEnterprisesDeleted      = true;
            bool someSubEntrepeneursDeleted = false;
            bool someRequestsDeleted        = false;
            bool someIttLettersDeleted      = false;
            bool someOffersDeleted          = false;
            bool someEnterprisesDeleted     = false;
            bool result = false;

            if (CheckBoxEraseProject.IsChecked == true)
            {
                if (MessageBox.Show("Er du sikker på, at du vil slette projektet? Alle projektets data inkl. entrepriser & underentrepenører vil gå tabt!", "Projekter", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK)
                {
                    try
                    {
                        foreach (Enterprise enterprise in CBZ.Enterprises)
                        {
                            if (enterprise.Project.Id == CBZ.TempProject.Case)
                            {
                                foreach (SubEntrepeneur subEntrepeneur in CBZ.SubEntrepeneurs)
                                {
                                    if (subEntrepeneur.Enterprise.Id == enterprise.Id)
                                    {
                                        SubEntrepeneur sub = new SubEntrepeneur(subEntrepeneur);
                                        // Code that deletes SubEntrepeneur
                                        bool subEntrepeneurDeleted = CBZ.DeleteFromDb("SubEntrepeneurs", sub.Id.ToString());
                                        if (subEntrepeneurDeleted && !someSubEntrepeneursDeleted)
                                        {
                                            someSubEntrepeneursDeleted = true;

                                            // Code that deletes Request
                                            bool requestDeleted = CBZ.DeleteFromDb("Requests", sub.Request.Id.ToString());
                                            if (requestDeleted && !someRequestsDeleted)
                                            {
                                                someRequestsDeleted = true;
                                            }
                                            else if (!requestDeleted && allRequestsDeleted)
                                            {
                                                allRequestsDeleted = false;
                                            }

                                            // Code that deletes IttLetter
                                            bool ittLetterDeleted = CBZ.DeleteFromDb("IttLetters", sub.IttLetter.Id.ToString());
                                            if (ittLetterDeleted && !someIttLettersDeleted)
                                            {
                                                someIttLettersDeleted = true;
                                            }
                                            else if (!ittLetterDeleted && allIttLettersDeleted)
                                            {
                                                allIttLettersDeleted = false;
                                            }

                                            // Code that deletes Offer
                                            bool offerDeleted = CBZ.DeleteFromDb("Offers", sub.Offer.Id.ToString());
                                            if (offerDeleted && !someOffersDeleted)
                                            {
                                                someOffersDeleted = true;
                                            }
                                            else if (!offerDeleted && allOffersDeleted)
                                            {
                                                allOffersDeleted = false;
                                            }
                                        }
                                        else if (!someSubEntrepeneursDeleted && allSubEntrepeneursDeleted)
                                        {
                                            allSubEntrepeneursDeleted = false;
                                            allRequestsDeleted        = false;
                                            allIttLettersDeleted      = false;
                                            allOffersDeleted          = false;
                                        }
                                    }
                                }

                                // Code that deletes Enterprise
                                if (someSubEntrepeneursDeleted)
                                {
                                    bool enterpriseDeleted = CBZ.DeleteFromDb("Enterprises", enterprise.Id.ToString());
                                    if (enterpriseDeleted && !someEnterprisesDeleted)
                                    {
                                        someEnterprisesDeleted = true;
                                    }
                                    else if (!enterpriseDeleted && allEnterprisesDeleted)
                                    {
                                        allEnterprisesDeleted = false;
                                    }
                                }
                            }

                            if (someEnterprisesDeleted)
                            {
                                // Code that deletes Project
                                result = CBZ.DeleteFromDb("Projects", CBZ.TempProject.Id.ToString());
                                if (result)
                                {
                                    //Show results
                                    ShowDependencystatus(allSubEntrepeneursDeleted, allRequestsDeleted, allIttLettersDeleted, allOffersDeleted, allEnterprisesDeleted, someSubEntrepeneursDeleted, someRequestsDeleted, someIttLettersDeleted, someOffersDeleted, someEnterprisesDeleted);

                                    MessageBox.Show("Projektet blev slettet", "Projekter", MessageBoxButton.OK, MessageBoxImage.Information);
                                }
                                else
                                {
                                    //Show results
                                    ShowDependencystatus(allSubEntrepeneursDeleted, allRequestsDeleted, allIttLettersDeleted, allOffersDeleted, allEnterprisesDeleted, someSubEntrepeneursDeleted, someRequestsDeleted, someIttLettersDeleted, someOffersDeleted, someEnterprisesDeleted);

                                    MessageBox.Show("Projektet blev ikke slettet", "Projekter", MessageBoxButton.OK, MessageBoxImage.Error);
                                }
                            }

                            //Reset form
                            ComboBoxCaseId.SelectedIndex   = -1;
                            CheckBoxEraseProject.IsChecked = false;

                            //Update list of projects
                            CBZ.RefreshIndexedList("SubEntrepeneurs");
                        }
                    }
                    catch (Exception ex)
                    {
                        //Show results
                        ShowDependencystatus(allSubEntrepeneursDeleted, allRequestsDeleted, allIttLettersDeleted, allOffersDeleted, allEnterprisesDeleted, someSubEntrepeneursDeleted, someRequestsDeleted, someIttLettersDeleted, someOffersDeleted, someEnterprisesDeleted);

                        MessageBox.Show("Databasen returnerede en fejl. Projektet blev ikke slettet. Prøv igen.\n" + ex, "Projekter", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            else
            {
                //Show error
                MessageBox.Show("Du har glemt at markere 'Godkend sletning af projekt'.", "Projekter", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }