Ejemplo n.º 1
0
        private void AnimalForm_Load(object sender, EventArgs e)
        {
            LoadeAllItemsInComboBox();
            BossController.Instance().animalController.GetSpecies();
            if (animal != null)
            {
                animal_owner.Text     = "Ejer: " + customer.name;
                AnimalName_Label.Text = animal.name;

                animalSpecies_label.Text = animal.Species.speciesName.ToString();

                animal_name.Text            = animal.name;
                animal_bdate.Text           = Convert.ToString(animal.birthYear);
                animal_species.Text         = Convert.ToString(animal.Species.speciesName);
                animal_weight.Text          = Convert.ToString(animal.weight);
                animal_gender.SelectedIndex = Convert.ToInt32(animal.gender);
                if (animal.Employee != null)
                {
                    animal_employee.Text = Convert.ToString(animal.Employee.name);
                }
                try
                {
                    prescriptions = BossController.Instance().animalController.GetAllPrescriptionByAnimal(animal.animalID);

                    animal.AddPrescriptionList(prescriptions);

                    animal_prescription.DataSource = prescriptions;

                    for (int i = 0; i < prescriptions.Count; i++)
                    {
                        Prescription tmpprescription = prescriptions[i];

                        animal_prescription.Rows[i].Cells["name"].Value   = tmpprescription.item.name;
                        animal_prescription.Rows[i].Cells["date"].Value   = tmpprescription.prescriptionDay;
                        animal_prescription.Rows[i].Cells["amount"].Value = tmpprescription.amount;
                    }
                }
                catch (Exception exception)
                {
                    string errorMessage = ErrorManager.Instance().GetErrorMessage(exception);
                    MessageBox.Show(errorMessage);
                    return;
                }
                try
                {
                    medicalRecords = BossController.Instance().animalController.GetAllMedicalRecordByAnimal(animal);

                    animal.AddMedicalRecordEntryList(medicalRecords);

                    animal_medicalRecords.DataSource = medicalRecords;

                    for (int i = 0; i < medicalRecords.Count; i++)
                    {
                        MedicalRecord tmpMedicalRecord = medicalRecords[i];

                        animal_medicalRecords.Rows[i].Cells["title"].Value   = tmpMedicalRecord.treatment.headline;
                        animal_medicalRecords.Rows[i].Cells["MR_date"].Value = tmpMedicalRecord.treatment.startTime;
                    }
                }
                catch (Exception exception)
                {
                    string errorMessage = ErrorManager.Instance().GetErrorMessage(exception);
                    MessageBox.Show(errorMessage);
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        private void button_opret_Click(object sender, EventArgs e)
        {
            //  Tjekker for at se om emailen er gyldig.

            if (CheckForValidEmail(textBox_email.Text.ToString()) == false)
            {
                MessageBox.Show("Ugyldig E-mailadresse");
                return;
            }
            if (CheckEmtyTextBoxes() == false)
            {
                MessageBox.Show("Alle felterne skal være udfyldt");
                return;
            }


            // tjekker om cvrnummeret består af tal
            string cvr = textBox_cvr.Text;

            //opretter en ny int og sætter den til 0
            int cvrint = 0;

            if (checkBox_erhverskunde.Checked == true && CheckForCVRdegit(cvr) == false)
            {
                //Hvis ikke cvr-nummeret består af noget bliver det lavet om til inten cvrint som er 0.

                if (cvr.ToString().Length == 8)
                {
                    //hvis cvrboxen er checket af og tallet er i orden erstattes nullet med det nye cvr-nummer
                    cvrint = Convert.ToInt32(textBox_cvr.Text);
                }
                else
                {
                    MessageBox.Show("CVR-nummeret skal bestå af 8 tal.");
                    return;
                }

                MessageBox.Show("CVR-nummer må kun bestå af tal");
                return;
            }
            //Hvis kunden er en erhverskunde og cvr-nummer er gyldigt bliver et cvr sendt over som parameter
            //Dette bliver senere brugt til at oprette en businesscustomer

            if (checkBox_erhverskunde.Checked == true && CheckForCVRdegit(cvr) == true)
            {
                cvrint = Convert.ToInt32(textBox_cvr.Text);
            }



            //Ellers bliver cvr-nummeret bare sendt over som 0, som senere bliver brugt til at oprette en privatecustomer
            customer = CustomerFactory.Instance().CreateCustomer(textBox_navn.Text.ToString(), textBox_adresse.Text.ToString(), textBox_phonenumber.Text.ToString(), textBox_email.Text.ToString(), true, cvrint);

            try
            {
                //her skriver vi den oprettede kunde ind i databasen
                customer = BossController.Instance().customerController.CreateCustomer(customer);

                MessageBox.Show("Kunde oprettet");

                button_dyr.Enabled            = true;
                button_rediger.Enabled        = true;
                button_slet.Enabled           = true;
                button_opret.Enabled          = false;
                label_headline.Text           = textBox_navn.Text.ToString().ToString();
                checkBox_erhverskunde.Enabled = false;
                textBox_cvr.Enabled           = false;
                label_underheader.Text        = "Ret, slet, se dyr eller Tilføj dyr";
            }
            catch (Exception exception)
            {
                string errorMessage = ErrorManager.Instance().GetErrorMessage(exception);
                MessageBox.Show(errorMessage);
                return;
            }
        }