private void SaveAgency_Click(object sender, EventArgs e)
        {
            if (agency == null)
            {
                agency = new Agency();
            }
            //Check
            bool flag = true;

            ValidateItems(NameBox);
            if (NameBox.Text.Length > 50 || NameBox.Text.Length < 4)
            {
                NameBox.BackColor = Color.Red;
                MessageBox.Show("The Length of name isn't inconsonant. \n The name is belong from 4 to 50 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                NameBox.Text      = string.Empty;
                NameBox.BackColor = Color.White;
                flag = false;
            }
            else
            {
                for (int i = 0; i < NameBox.Text.Length; i++)
                {
                    if (NameBox.Text[i] >= '0' && NameBox.Text[i] <= '9')
                    {
                        NameBox.BackColor = Color.Red;
                        MessageBox.Show("The Name Just Contains Number ??? \n The Name Should be Include Number and Characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        NameBox.Text      = string.Empty;
                        NameBox.BackColor = Color.White;
                        flag = false;
                        break;
                    }
                }
            }
            agency.Name = NameBox.Text;

            ValidateItems(DescriptionBox);
            if (DescriptionBox.Text.Length > 1000 || DescriptionBox.Text.Length < 12)
            {
                DescriptionBox.BackColor = Color.Red;
                MessageBox.Show("The Length of Description isn't inconsonant. \n The Description is belong from 12 to 1000 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                DescriptionBox.BackColor = Color.White;
                DescriptionBox.Text      = string.Empty;
            }
            else if (DescriptionBox.Text == null)
            {
                DescriptionBox.BackColor = Color.Red;
                MessageBox.Show("Please Something Into Blank space", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                DescriptionBox.Text      = string.Empty;
                DescriptionBox.BackColor = Color.White;
            }

            agency.Description = DescriptionBox.Text;



            agency.Image = pictureBox1.Image;
            bool AlreadyExist = false;

            if (agency.Image == null)
            {
                pictureBox1.BackColor = Color.Gray;
                MessageBox.Show("Have You Choose The Picture ???", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                pictureBox1.BackColor = Color.White;
                flag = false;
            }
            foreach (Agency a in vietTravel.Agencies)
            {
                if (a.Name == agency.Name && Odd == false)
                {
                    AlreadyExist = true;
                    break;
                }
                else
                {
                    AlreadyExist = false;
                }
            }

            if (AlreadyExist == true)
            {
                NameBox.BackColor = Color.Red;
                MessageBox.Show("This Name Already Exist \n Please Try Again With Another Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                NameBox.Text      = string.Empty;
                NameBox.BackColor = Color.White;
                flag = false;
            }
            if (agency.Portions.Count == 0)
            {
                MessageBox.Show("Please add some trips! It`s impossible to send agency without any trips to the client!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                flag = false;
            }
            else
            {
                agency.Portions = new List <Portion>();
                agency.Portions = (List <Portion>)portionBindingSource.DataSource;
                foreach (Portion p in agency.Portions)
                {
                    p.Agency_Name = agency.Name;
                }
                agency.Amount = agency.Portions.Count;
                portionBindingSource.DataSource = agency.Portions;
                portionBindingSource.ResetBindings(false);
            }
            if (agency.Name == "Hendrichs Cullen" || agency.Description == "Victoria City, Melbourne" || agency.Image == null || agency.Portions.Count == 0 || AlreadyExist == true)
            {
                flag = false;
            }
            if (agency.Name == "Christopher Rohit" || agency.Description == "Stuttgart , Germany" || agency.Image == null || agency.Portions.Count == 0 || AlreadyExist == true)
            {
                flag = false;
            }
            if (flag == false)
            {
                SendButton.Show();
                SaveAgency.Hide();
            }
            else
            {
                MessageBox.Show("Do you missed something !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SaveAgency.Show();
                SendButton.Hide();
            }
        }
示例#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();
            }
        }