コード例 #1
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();
                }
            }
        }
コード例 #2
0
ファイル: addTutor.cs プロジェクト: Haimma/c-Schedule-Project
        private void b_addTutors_Click_Click(object sender, EventArgs e)
        {
            int  distance;      //for check integer
            int  ID;
            bool bofl = true;

            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:Username\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 (tutors_db.existTutors(tb_username.Text, tb_id.Text))
                {
                    MessageBox.Show("Tutors already existe\n");
                    break;
                }


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

                //************************ //user_db.-----------------------------------
                //
                user_db.insertUser(tb_username.Text, tb_password.Text, tb_id.Text, "Tutors");

                //
                //---------------------------------------------
                this.Hide();
            }
        }