private void setUpdateState()
        {
            int id = System.Convert.ToInt32(txt_TB_ID.Text);

            courseSelected = dal.courses.Find(id);

            string strErrorMassage = "";

            string str_name = txt_TB_Name.Text.ToString();

            if (str_name.Trim().Length > 0)
            {
                str_name            = GeneralFuntion.CapitalizeFirstLetterEachWord(str_name);
                courseSelected.Name = str_name;
            }
            else
            {
                strErrorMassage += "* Name field is invalid          : 'empty' .\n";
            }

            string ys = txt_TB_YSemester.Text.ToString();

            char[] array = txt_TB_YSemester.Text.ToString().ToCharArray();

            if (array.Length == 2 && char.IsDigit(array[0]) && array[0] >= '1' && array[0] <= '4' && array[1] >= 'A' && array[1] <= 'C')
            {
                courseSelected.year           = System.Convert.ToInt32(array[0].ToString());
                courseSelected.Study_semester = array[1].ToString();
            }
            else
            {
                strErrorMassage += "* Year-Semester field is invalid          : should be [1-4][A-C]  .\n";
            }

            courseSelected.weeklyHoursLecture  = System.Convert.ToInt32(txt_TB_HL.Text.ToString());
            courseSelected.weeklyHoursPractise = System.Convert.ToInt32(txt_TB_HT.Text.ToString());
            courseSelected.Points = System.Convert.ToInt32(txt_TB_Points.Text.ToString());

            string str_syllabus = txt_TB_Syllabus.Text.ToString();

            if (str_syllabus.Trim().Length > 0)
            {
                courseSelected.syllabus = str_syllabus;
            }
            else
            {
                strErrorMassage += "* Syllabus field is invalid               : 'empty' .\n";
            }

            if (!strErrorMassage.Equals(""))
            {
                MessageBox.Show("There is some invalid values: \n\n" + strErrorMassage + "\nAdd a student with NULL value at thes fields.");
                return;
            }
        }
        private bool validDetailsOfRequiredFields()
        {
            bool   flag            = true;
            string strErrorMassage = "";

            staffSelected = new StaffMember();
            try
            {
                staffSelected.ID = System.Convert.ToInt32(txt_TB_ID.Text.ToString());
            }
            catch (Exception) { flag = false; }

            if (txt_CB_Gender.Text.Length > 0)
            {
                staffSelected.Gender = txt_CB_Gender.Text.ToString();
            }
            else
            {
                flag             = false;
                strErrorMassage += "* Gender field is invalid      : 'empty' .\n";
            }

            if (txt_CB_Type.Text.Length > 0)
            {
                staffSelected.Type = txt_CB_Type.Text.ToString();
            }
            else
            {
                flag             = false;
                strErrorMassage += "* Type field is invalid         : 'empty' .\n";
            }


            string str_name = txt_TB_Name.Text.ToString();

            if (str_name.Trim().Length > 0)
            {
                str_name           = GeneralFuntion.CapitalizeFirstLetterEachWord(str_name);
                staffSelected.Name = str_name;
            }
            else
            {
                strErrorMassage += "* Name field is invalid          : 'empty' .\n";
            }

            DateTime date;
            bool     parseResult = DateTime.TryParse(txt_TB_Date.Text.ToString(), out date);

            if (parseResult)
            {
                //parse was successful, continue
                DateTime now = DateTime.Today;

                if (date.Year < now.Year && (now.Year - date.Year) < 120 && (now.Year - date.Year) > 0)
                {
                    staffSelected.BirthDate = date;
                    int age = now.Year - staffSelected.BirthDate.GetValueOrDefault().Year;
                    if (now < staffSelected.BirthDate.GetValueOrDefault().AddYears(age))
                    {
                        age--;
                    }

                    if (age >= 0 && age <= 120)
                    {
                        staffSelected.Age = age;
                    }
                    else
                    {
                        staffSelected.Age = -1;
                    }
                }
                else
                {
                    strErrorMassage += "* Birth-Date field is invalid : '" + txt_TB_Date.Text + "' .\n";
                }
            }
            else
            {
                if (txt_TB_Date.TextLength == 0)
                {
                    strErrorMassage += "* Birth-Date field is invalid : 'empty' .\n";
                }
                else
                {
                    strErrorMassage += "* Birth-Date field is invalid : '" + txt_TB_Date.Text + "' .\n";
                }
            }


            string str_phoneNumber = txt_TB_Phone.Text.ToString();

            if (GeneralFuntion.ValidPhone(str_phoneNumber) && str_phoneNumber.Length > 0)
            {
                staffSelected.Phone = str_phoneNumber;
            }
            else
            {
                if (str_phoneNumber.Equals(""))
                {
                    strErrorMassage += "* PhoneNumber field is invalid : 'empty' .\n";
                }
                else
                {
                    strErrorMassage += "* PhoneNumber field is invalid : '" + str_phoneNumber + "' .\n";
                }
            }

            if (txt_TB_Password.TextLength == 0)
            {
                strErrorMassage += "* Password field is invalid : 'empty' (default password: '******').\n";
            }

            if (dal.users.Where(x => x.email.Equals(txt_TB_Email.Text)).FirstOrDefault() != null)
            {
                strErrorMassage  += "* Email field is invalid : Already exist student with this email.\n";
                txt_TB_Email.Text = "";
            }

            if (!strErrorMassage.Equals(""))
            {
                MessageBox.Show("There is some invalid values: \n\n" + strErrorMassage + "\nAdd a " + staffSelected.Type + " with NULL value at thes fields.");
            }

            return(flag);
        }
        private bool setUpdateState()
        {
            int id;

            try
            {
                id = System.Convert.ToInt32(txt_TB_ID.Text);
            }
            catch (Exception) { MessageBox.Show("ID field is invalid"); return(false); }

            userSelected = dal.users.Find(id);
            //staffSelected = dal.secretaries.Find(id);

            if (txt_CB_Gender.Text.Length > 0)
            {
                staffSelected.Gender = txt_CB_Gender.Text;
            }


            string str_name = txt_TB_Name.Text.ToString();

            if (str_name.Trim().Length > 0)
            {
                str_name           = GeneralFuntion.CapitalizeFirstLetterEachWord(str_name);
                staffSelected.Name = str_name;
            }

            DateTime date;
            bool     parseResult = DateTime.TryParse(txt_TB_Date.Text.ToString(), out date);

            if (parseResult)
            {
                //parse was successful, continue
                DateTime now = DateTime.Today;

                if (date.Year < now.Year)
                {
                    if ((now.Year - date.Year) < 120 && (now.Year - date.Year) > 0)
                    {
                        staffSelected.BirthDate = date;
                        int age = now.Year - staffSelected.BirthDate.GetValueOrDefault().Year;
                        if (now < staffSelected.BirthDate.GetValueOrDefault().AddYears(age))
                        {
                            age--;
                        }

                        if (age >= 0 && age <= 120)
                        {
                            staffSelected.Age = age;
                        }
                        else
                        {
                            MessageBox.Show("The date field is invalid: the date indecate that your age is not between (1 - 120).");
                            staffSelected.Age = -1;
                            return(false);
                        }
                    }
                    else
                    {
                        MessageBox.Show("The date field is invalid: the date must be after the year " + (now.Year - 120) + ".");
                        return(false);
                    }
                }
                else
                {
                    MessageBox.Show("The date field is invalid: the date must be before the current year " + now.Year + ".");
                    return(false);
                }
            }
            else
            {
                MessageBox.Show("The date field is invalid: the format date is invalid.");
                return(false);
            }


            string str_phoneNumber = txt_TB_Phone.Text.ToString();

            if (GeneralFuntion.ValidPhone(str_phoneNumber) && str_phoneNumber.Length > 0)
            {
                staffSelected.Phone = str_phoneNumber;
            }
            else if (str_phoneNumber.Length == 0 || str_phoneNumber.Length < 10 || str_phoneNumber.Length > 12)
            {
                staffSelected.Phone = "";
            }

            if (txt_TB_Password.TextLength != 0)
            {
                userSelected.password = txt_TB_Password.Text.ToString();
            }

            User userFromEmail = dal.users.Where(x => x.email.Equals(txt_TB_Email.Text)).FirstOrDefault();

            if (txt_TB_Email.TextLength > 0 && userFromEmail != null && userFromEmail.ID != id)
            {
                MessageBox.Show("The Email field is invalid: already exists user with this email");
                return(false);
            }
            else
            {
                userSelected.email = txt_TB_Email.Text;
            }


            return(true);
        }
        private void btn_add_Click(object sender, EventArgs e)
        {
            if (filledAll())
            {
                try
                {
                    string strErrorMassage = "";
                    courseSelected    = new Course();
                    courseSelected.ID = System.Convert.ToInt32(txt_TB_ID.Text.ToString());

                    string str_name = txt_TB_Name.Text.ToString();
                    if (str_name.Trim().Length > 0)
                    {
                        str_name            = GeneralFuntion.CapitalizeFirstLetterEachWord(str_name);
                        courseSelected.Name = str_name;
                    }
                    else
                    {
                        strErrorMassage += "* Name field is invalid          : 'empty' .\n";
                    }

                    string ys    = txt_TB_YSemester.Text.ToString();
                    char[] array = txt_TB_YSemester.Text.ToString().ToCharArray();

                    if (array.Length == 2 && char.IsDigit(array[0]) && array[0] >= '1' && array[0] <= '4' && array[1] >= 'A' && array[1] <= 'C')
                    {
                        courseSelected.year           = System.Convert.ToInt32(array[0].ToString());
                        courseSelected.Study_semester = array[1].ToString();
                    }
                    else
                    {
                        strErrorMassage += "* Year-Semester field is invalid  : should be [1-4][A-C]  .\n";
                    }

                    courseSelected.weeklyHoursLecture  = System.Convert.ToInt32(txt_TB_HL.Text.ToString());
                    courseSelected.weeklyHoursPractise = System.Convert.ToInt32(txt_TB_HT.Text.ToString());
                    courseSelected.weeklyHoursLab      = System.Convert.ToInt32(txt_TB_HT.Text.ToString());

                    try
                    {
                        courseSelected.Points = (float)Convert.ToDouble(txt_TB_Points.Text.ToString());
                        if (courseSelected.Points % 0.5 != 0 || courseSelected.Points < 3 || courseSelected.Points > 6)
                        {
                            throw new Exception("");
                        }
                    }
                    catch (Exception) { strErrorMassage += "* Point feild is invalid : should be [3.0 - 6.0] in steps of 0.5  .\n"; };

                    string str_syllabus = txt_TB_Syllabus.Text.ToString();
                    if (str_syllabus.Trim().Length > 0)
                    {
                        courseSelected.syllabus = str_syllabus;
                    }
                    else
                    {
                        strErrorMassage += "* Syllabus field is invalid        : 'empty' .\n";
                    }

                    if (!strErrorMassage.Equals(""))
                    {
                        MessageBox.Show("There is some invalid values: \n\n" + strErrorMassage + "\nAdd a Course with NULL value at thes fields.");
                    }

                    if (secretary != null)
                    {
                        secretary.addNewCourse(courseSelected);
                    }
                    else if (admin != null)
                    {
                        admin.addNewCourse(courseSelected);
                    }

                    btn_search_Click(sender, e);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Exception Create Object:\n\n" + ex + "\n\nSome exeption with the object Course!");
                    return;
                }
            }
            else
            {
                btn_add.Enabled = false;
            }
        }