예제 #1
0
        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            Employee employee  = null;
            bool     canUpdate = false;

            string workdate = cboDay.Text + " " + cboMonth.Text + " " + cboYear.Text;

            try
            {
                var tID        = txtID.Text;
                var tFirstName = MyString.FirstLetterToUpper(txtFirstName.Text);
                var tLastName  = MyString.FirstLetterToUpper(txtLastName.Text);
                var tGender    = (Gender._Gender)cboGender.SelectedItem;
                var tAge       = int.Parse(txtAge.Text);
                var tSalary    = double.Parse(txtSalary.Text);
                var tWorkDate  = workdate;

                // If user want to update last Care Taker record to Security record
                if (temp.Position == "Care Taker" &&
                    Employee.Employees.Where(x => x.Position == "Care Taker").Count() <= 1 &&
                    cboPosition.Text != "Care Taker")
                {
                    throw new Exception("Cannot change position of this employee. " +
                                        "Please add another Care Taker if you want to change position of this employee");
                }

                // If user want to update Care Taker record that have up to 1 animal in the list
                if (temp.Position == "Care Taker" &&
                    (temp as CareTaker).ListAnimals.Count() > 0 &&
                    cboPosition.Text != "Care Taker")
                {
                    throw new Exception(string.Format("Cannot change position of this care taker. " +
                                                      "This care taker is currently have {0} animal to take care.", (temp as CareTaker).ListAnimals.Count()));
                }

                canUpdate = true;

                if (cboPosition.Text == "Care Taker")
                {
                    employee = new CareTaker();
                }

                if (cboPosition.Text == "Security")
                {
                    employee = new Security();
                }

                employee.ID        = tID;
                employee.FirstName = tFirstName;
                employee.LastName  = tLastName;
                employee.Gender    = tGender;
                employee.Age       = tAge;
                employee._Salary   = tSalary;
                employee.WorkDate  = tWorkDate;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }

            if (canUpdate)
            {
                if (Modified != null)
                {
                    Modified(this, employee);
                }

                MessageBox.Show("Record Updated");
            }
        }
예제 #2
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            Employee careTaker = new CareTaker();
            Animal   animal    = null;

            bool canCreate = false;

            try
            {
                // Split IDAndName property and take only ID of Care Taker
                string   IDAndName   = cboCareTaker.Text;
                string[] caretakerID = IDAndName.Split(null);

                foreach (Employee t in Employee.Employees)
                {
                    if (t.ID == caretakerID[0])
                    {
                        careTaker = (CareTaker)t;
                        break;
                    }
                }

                var tID     = MyString.FirstLetterToUpper(txtID.Text);
                var tName   = MyString.FirstLetterToUpper(txtName.Text);
                var tGender = (Gender._Gender)cboGender.SelectedItem;
                var tAge    = new Age()
                {
                    Year = int.Parse(txtAgeYear.Text), Month = int.Parse(cboAgeMonth.Text)
                };
                var tWeight     = double.Parse(txtWeight.Text);
                var tTypeOfFood = MyString.FirstLetterToUpper(txtTypeOfFood.Text);
                var tRegion     = (MyRegion.From)cboRegion.SelectedItem;
                var tCageType   = (Cage.Type)cboCageType.SelectedItem;
                var tCareTaker  = (CareTaker)careTaker;

                // If ID already have
                foreach (Animal aml in Animal.Animals)
                {
                    if (aml.ID.Equals(tID))
                    {
                        throw new Exception(string.Format("Duplicate ID: {0}", tID));
                    }
                }

                canCreate = true;

                if (cboSpecies.Text == "Lion")
                {
                    animal = new Lion();
                }

                if (cboSpecies.Text == "Tiger")
                {
                    animal = new Tiger();
                }

                if (cboSpecies.Text == "Elephant")
                {
                    animal = new Elephant();
                }

                if (cboSpecies.Text == "Penguin")
                {
                    animal = new Penguin();
                }

                if (cboSpecies.Text == "Peocock")
                {
                    animal = new Peocock();
                }

                if (cboSpecies.Text == "Cichild")
                {
                    animal = new Cichild();
                }

                animal.ID         = tID;
                animal.Name       = tName;
                animal.Gender     = tGender;
                animal._Age       = tAge;
                animal._Weight    = tWeight;
                animal.TypeOfFood = tTypeOfFood;
                animal._Region    = tRegion;
                animal.CageType   = tCageType;
                animal.CareTaker  = tCareTaker;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }

            if (canCreate)
            {
                if (Create != null)
                {
                    Create(this, animal);
                }

                MessageBox.Show("Record Added");

                ResetControl();
            }
        }
예제 #3
0
        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            Employee careTaker = new CareTaker();
            Animal   animal    = null;

            bool canUpdate = false;

            try
            {
                // Split IDAndName property and take only ID of Care Taker
                string   IDAndName   = cboCareTaker.Text;
                string[] caretakerID = IDAndName.Split(null);

                foreach (Employee t in Employee.Employees)
                {
                    if (t.ID == caretakerID[0])
                    {
                        careTaker = (CareTaker)t;
                        break;
                    }
                }

                var tID     = MyString.FirstLetterToUpper(txtID.Text);
                var tName   = MyString.FirstLetterToUpper(txtName.Text);
                var tGender = (Gender._Gender)cboGender.SelectedItem;
                var tAge    = new Age()
                {
                    Year = int.Parse(txtAgeYear.Text), Month = int.Parse(cboAgeMonth.Text)
                };
                var tWeight             = double.Parse(txtWeight.Text);
                var tTypeOfFood         = MyString.FirstLetterToUpper(txtTypeOfFood.Text);
                var tRegion             = (MyRegion.From)cboRegion.SelectedItem;
                var tCageType           = (Cage.Type)cboCageType.SelectedItem;
                var tCareTaker          = (CareTaker)careTaker;
                var tConservationStatus = (Conservation.Status)cboConservationStatus.SelectedIndex;

                canUpdate = true;

                if (cboSpecies.Text == "Lion")
                {
                    animal = new Lion();
                }

                if (cboSpecies.Text == "Tiger")
                {
                    animal = new Tiger();
                }

                if (cboSpecies.Text == "Elephant")
                {
                    animal = new Elephant();
                }

                if (cboSpecies.Text == "Penguin")
                {
                    animal = new Penguin();
                }

                if (cboSpecies.Text == "Peocock")
                {
                    animal = new Peocock();
                }

                if (cboSpecies.Text == "Cichild")
                {
                    animal = new Cichild();
                }

                animal.ID                 = tID;
                animal.Name               = tName;
                animal.Gender             = tGender;
                animal._Age               = tAge;
                animal._Weight            = tWeight;
                animal.TypeOfFood         = tTypeOfFood;
                animal.ConservationStatus = tConservationStatus;
                animal._Region            = tRegion;
                animal.CageType           = tCageType;
                animal.CareTaker          = tCareTaker;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }

            if (canUpdate)
            {
                if (Modified != null)
                {
                    Modified(this, animal);
                }

                MessageBox.Show("Record Updated");
            }
        }