private void Btn_teacher_save_Click(object sender, EventArgs e)
        {
            AcademyMngtSystem.Model.Teacher tch = new AcademyMngtSystem.Model.Teacher();
            Regex regexName    = new Regex("[A-z]");
            Regex regexSurname = new Regex("[A-z]");
            //Regex regexSpeciality = new Regex("[A-z]");
            Regex regexEmail = new Regex(@"[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$");

            //Regex regexPhone = new Regex(@"(\+[0-9]{3})([0-9]{9})");


            if (!regexEmail.IsMatch(frm2txtbx_email.Text))
            {
                MessageBox.Show("Email is not true !");
            }
            else if (!regexName.IsMatch(frm2txtbx_name.Text))
            {
                MessageBox.Show("Fill in the form");
            }
            else if (!regexSurname.IsMatch(frm2txtbx_surname.Text))
            {
                MessageBox.Show("Fill in the form");
            }
            //else if (!regexSpeciality.IsMatch(frm2cmbbx_spclty.Text))
            //{
            //    MessageBox.Show("Fill in the form");
            //}

            //else if (!regexPhone.IsMatch(frm2txtbx_phn.Text))
            //{
            //    MessageBox.Show("Please Enter Correct Phone Number !");
            //}
            else
            {
                using (AcademyEntities aem = new AcademyEntities())
                {
                    AcademyMngtSystem.Model.Education edctn = aem.Educations.FirstOrDefault(x => x.Id == selectedId);

                    tch.Education = edctn;
                    tch.Name      = frm2txtbx_name.Text;
                    tch.Surname   = frm2txtbx_surname.Text;
                    tch.Email     = frm2txtbx_email.Text;
                    tch.Phone     = frm2txtbx_phn.Text;
                    aem.Teachers.Add(tch);
                    teacher_datagridview.DataSource = aem.Teachers.ToList();
                    aem.SaveChanges();
                }
            }
        }
예제 #2
0
        private void Btn_edctn_save_Click(object sender, EventArgs e)
        {
            Education edctn    = new Education();
            Regex     rgxName  = new Regex("[A-z]");
            Regex     rgxPrice = new Regex(@"\[0\-9\]\{0,15\}");

            if (!rgxName.IsMatch(frm_edctn_name.Text))
            {
                MessageBox.Show("Fill in the form");
            }
            else if (!rgxPrice.IsMatch(frm_edctn_price.Text))
            {
                MessageBox.Show("Not enter Letters");
            }
            else
            {
                using (AcademyEntities aem = new AcademyEntities())
                {
                    AcademyMngtSystem.Model.Group   grp  = aem.Groups.FirstOrDefault(x => x.Id == selectedId);
                    AcademyMngtSystem.Model.Teacher tchr = aem.Teachers.FirstOrDefault(t => t.Id == selectedId);
                    if (grp != null)
                    {
                        edctn.Groups.Add(grp);
                    }
                    if (tchr != null)
                    {
                        edctn.Teachers.Add(tchr);
                    }
                    edctn.Name  = frm_edctn_name.Text;
                    edctn.Price = Convert.ToInt32(frm_edctn_price.Text);
                    aem.Educations.Add(edctn);
                    edctn_datagridview.DataSource = aem.Educations.ToList();
                    aem.SaveChanges();
                }
            }
        }