Esempio n. 1
0
 private void EditAgency_Load(object sender, EventArgs e)
 {
     portionBindingSource.DataSource = Agency.Portions;
     portionBindingSource.ResetBindings(false);
     if (tripGridView.Rows.Count > 0)
     {
         tripGridView.Rows[0].Selected = true;
     }
     SendButt.Hide();
 }
Esempio n. 2
0
        private void SaveAgency_Click(object sender, EventArgs e)
        {
            if (Agency == null)
            {
                Agency = new Agency();
            }
            //Validation.
            bool flag = true;

            ValidateItems(DescriptionBox);
            if (DescriptionBox.Text.Length > 50 || DescriptionBox.Text.Length < 11)
            {
                MessageBox.Show("Inappropriate length for the Description. Description should be longer than 10 less than 50 (letters)");
                DescriptionBox.BackColor = Color.MediumSeaGreen;
                MessageBox.Show("Fill in the blank space,please!");
                DescriptionBox.Text      = string.Empty;
                DescriptionBox.BackColor = Color.FromArgb(253, 236, 138);
                flag = false;
            }

            Agency.Description = DescriptionBox.Text;



            ValidateItems(NameBox);
            if (NameBox.Text.Length > 20 || NameBox.Text.Length < 4)
            {
                MessageBox.Show("Inappropriate length for the name. Name should be longer than 4 less than 20 (letters)");
                NameBox.BackColor = Color.MediumSeaGreen;
                NameBox.Text      = string.Empty;
                NameBox.BackColor = Color.FromArgb(253, 236, 138);
                flag = false;
            }

            else
            {
                for (int i = 0; i < NameBox.Text.Length; i++)
                {
                    if (NameBox.Text[i] >= '0' && NameBox.Text[i] <= '9')
                    {
                        NameBox.BackColor = Color.MediumSeaGreen;
                        MessageBox.Show("Name contains numbers");
                        NameBox.Text      = string.Empty;
                        NameBox.BackColor = Color.FromArgb(253, 236, 138);
                        flag = false;
                        break;
                    }
                }
            }


            Agency.Name = NameBox.Text;


            Agency.Image = imageBox.Image;
            bool SuchAgencyExists = false;

            if (Agency.Image == null)
            {
                imageBox.BackColor = Color.MediumSeaGreen;
                MessageBox.Show("You didn`t choose the picture!");
                imageBox.BackColor = Color.FromArgb(253, 236, 138);
                flag = false;
            }
            foreach (Agency a in Store.Agencies)
            {
                if (a.Name == Agency.Name && OldAgency == false)
                {
                    SuchAgencyExists = true;
                    break;
                }
                else
                {
                    SuchAgencyExists = false;
                }
            }

            if (SuchAgencyExists == true)
            {
                MessageBox.Show("Agency with such name already exists!"); NameBox.BackColor = Color.MediumSeaGreen;
                NameBox.Text      = string.Empty;
                NameBox.BackColor = Color.FromArgb(253, 236, 138);
                flag = false;
            }

            if (Agency.Portions.Count == 0)
            {
                MessageBox.Show("Add some trips! It`s impossible to send agency without any trips to the client!");
                flag = false;
            }
            else
            {
                Agency.Portions = new List <Portion>();
                Agency.Portions = (List <Portion>)portionBindingSource.DataSource;
                foreach (Portion p in Agency.Portions)
                {
                    p.AgencyName = Agency.Name;
                }
                Agency.AmountOfTrips            = Agency.Portions.Count;
                portionBindingSource.DataSource = Agency.Portions;
                portionBindingSource.ResetBindings(false);
            }
            if (Agency.Name == "Hello" || Agency.Description == "I`m going to hell" || Agency.Image == null ||
                Agency.Portions.Count == 0 || SuchAgencyExists == true)
            {
                flag = false;
            }



            if (flag == true)
            {
                SendButt.Show();
                SaveAgency.Hide();
            }
            else
            {
                MessageBox.Show("You missed something!");
                SaveAgency.Show();
                SendButt.Hide();
            }
        }