Beispiel #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            int distance;       //for chack integer
            int ID;
            //string illegalfields = null;
            // short flag = 0;     //text box fine
            //-----chacking text box, 0-fine , 1-empty , 2-illegal type, -1 - empty out
            // int distance;       //for chack integer
            //int ID;
            bool   bofl  = true;
            string type  = null;
            int    hours = 0;

            while (bofl)
            {
                //---First name---
                if (string.IsNullOrWhiteSpace(tb_fname.Text))
                {
                    MessageBox.Show("Have empty field.");
                    break;
                }
                else if ((int.TryParse(tb_fname.Text, out distance)))
                {
                    MessageBox.Show("Illegal field is:First name\n");
                    tb_fname.Clear();
                    break;
                }

                //---Last name---
                if (string.IsNullOrWhiteSpace(tb_lname.Text))
                {
                    MessageBox.Show("Have empty field.");
                    break;
                }
                else if (int.TryParse(tb_lname.Text, out distance))
                {
                    MessageBox.Show("Illegal field is:Last name\n");
                    tb_lname.Clear();
                    break;
                }

                //--- ID---
                if (string.IsNullOrWhiteSpace(tb_id.Text))
                {
                    MessageBox.Show("Have empty field.");
                    break;
                }
                else if (!(int.TryParse(tb_id.Text, out distance)))
                {
                    MessageBox.Show("Illegal field is:ID\n");
                    tb_id.Clear();
                    break;
                }
                else
                {
                    ID = int.Parse(tb_id.Text);
                    if ((ID < 100000000 || ID > 999999999))
                    {
                        MessageBox.Show("Illegal field is:ID\n");
                        tb_id.Clear();
                        break;
                    }
                }

                //---Address---
                if (string.IsNullOrWhiteSpace(tb_address.Text))
                {
                    MessageBox.Show("Have empty field.");
                    break;
                }
                else if (int.TryParse(tb_address.Text, out distance))
                {
                    MessageBox.Show("Illegal field is:Address\n");
                    tb_address.Clear();
                    break;
                }

                //---Username---
                if (string.IsNullOrWhiteSpace(tb_username.Text))
                {
                    MessageBox.Show("Have empty field.");
                    break;
                }
                else if (int.TryParse(tb_username.Text, out distance))
                {
                    MessageBox.Show("Illegal field is:Address\n");
                    tb_address.Clear();
                    break;
                }
                //---Password---
                if (string.IsNullOrWhiteSpace(tb_password.Text))
                {
                    MessageBox.Show("Have empty field.");
                    break;
                }
                else if (int.TryParse(tb_password.Text, out distance))
                {
                    if (tb_password.Text.Length != 8)
                    {
                        MessageBox.Show("Illegal field is:Password\n");
                        tb_password.Clear();
                        break;
                    }
                }

                if (lecturers_db.existlecturer_db(tb_username.Text, tb_id.Text))
                {
                    MessageBox.Show("lecture already existe\n");
                    break;
                }


                //--------hour & type
                if (tb_type.Text == "דוקטור")
                {
                    type  = "Doctor";
                    hours = 16;
                }
                else if (tb_type.Text == "פרופסור")
                {
                    type  = "Professor";
                    hours = 12;
                }
                else if (tb_type.Text == "זוטר")
                {
                    type  = "Junior";
                    hours = 32;
                }
                else
                {
                    MessageBox.Show("missing a type or invild type\n");
                    break;
                }

                //------------all good------------------
                bofl = false;
                //-------------put data to db by func---------------
                lecturers_db.insertlecturer_db(tb_username.Text, tb_password.Text, tb_fname.Text, tb_lname.Text, tb_id.Text, tb_address.Text, hours, type);

                //************************ //user_db.-----------------------------------
                //
                user_db.insertUser(tb_username.Text, tb_password.Text, tb_id.Text, "Lecturers");
                //
                //---------------------------------------------
                this.Hide();
            }
        }
Beispiel #2
0
        private void check_Click(object sender, EventArgs e)
        {
            int    flag = 0;
            string numH;
            int    user_check = 0;

            while (flag == 0)
            {
                if (string.IsNullOrWhiteSpace(tb_id.Text))
                {
                    MessageBox.Show("Have empty field.");
                    tb_username.Text = String.Empty;
                    tb_id.Text       = String.Empty;

                    break;
                }

                else if (string.IsNullOrWhiteSpace(tb_username.Text))
                {
                    MessageBox.Show("Have empty field.");
                    tb_id.Text       = String.Empty;
                    tb_username.Text = String.Empty;

                    break;
                }

                //check if the Tutor exist----//check if the lecture exist
                else if ((!tutor_db.existTutors(tb_username.Text, tb_id.Text)) && (!lecturers_db.existlecturer_db(tb_username.Text, tb_id.Text)))
                {
                    // MessageBox.Show("Tutor not existe\n");
                    MessageBox.Show("User not existe\n");

                    tb_id.Text       = String.Empty;
                    tb_username.Text = String.Empty;
                    user_check       = 0;//=1
                    break;
                }
                else if (tutor_db.existTutors(tb_username.Text, tb_id.Text))
                {
                    user_check = 1; //tutors
                    flag       = 1; //out loop
                }
                else
                {
                    user_check = 2; //lecturer
                    flag       = 1; //out loop
                }
            }
            flag = 0;
            if (user_check == 0)
            {
                MessageBox.Show("ERROR:User lecture & Tutor\n");
            }
            if (user_check == 2)
            {
                //lec
                numH = lecturers_db.GetAmauntHours(tb_id.Text);
                if (Convert.ToInt32(numH) < 0)
                {
                    MessageBox.Show("Invildable num of hours for the lecturers\n");
                    flag = 1;
                }
                else if (Convert.ToInt32(numH) == 0)
                {
                    MessageBox.Show("There is no left huors for the lecturers\n");
                    flag = 1;
                }
                if (flag == 0)//all good :)
                {
                    tb_left.Text = numH.ToString();
                }
            }
            if (user_check == 1)
            {
                //tot
                numH = tutor_db.GetAmauntHours(tb_id.Text).ToString();
                if (Convert.ToInt32(numH) < 0)
                {
                    MessageBox.Show("Invildable num of hours for the Tutors\n");
                    flag = 1;
                }
                else if (Convert.ToInt32(numH) == 0)
                {
                    MessageBox.Show("There is no left huors for the Tutors\n");
                    flag = 1;
                }
                if (flag == 0)//all good :)
                {
                    tb_left.Text = numH.ToString();
                }
            }
        }