Exemplo n.º 1
0
        /// <summary>
        /// Login worker.
        /// Use this for testing log in
        /// </summary>
        /// <returns></returns>
        public bool auth()
        {
            if (!IsDigits(this.id_textbox.Text))
            {
                throw new Exception("Make sure that your id contains only digits");
            }
            if (!SqlWorker.CheckForInternetConnection())
            {
                throw new Exception("There is no internet connection.\nPlease try again later.");
            }

            string f_id  = this.id_textbox.Text.ToString();
            string f_pwd = this.pwd_textbox.Text.ToString();


            User usr = SqlWorker.GetUser(f_id);

            // check if we found it and if pwds much
            if (usr == null || usr.Pwd != f_pwd)
            {
                throw new Exception("User not found or Password is incorrect");
            }

            //  set session user
            Globals._session = usr;
            return(true);
        }
Exemplo n.º 2
0
        public bool SaveUser()
        {
            if (this.name_input.Text != "" &&
                this.id_input.Text != "" &&
                this.sem_sbox.Text != "")
            {
                try
                {
                    DataTable users_list = SqlWorker.GetUsersList();
                    Student   student    = new Student();
                    student.Type     = "Student";
                    student.Name     = this.name_input.Text;
                    student.ID       = this.id_input.Text;
                    student.Pwd      = this.pwd_input.Text;
                    student.SemCount = int.Parse(this.sem_sbox.Text);

                    foreach (DataRow row in users_list.Rows)
                    {
                        if ((row["id"].ToString()) == this.id_input.Text)
                        {
                            if (row["Type"].ToString() == "Student")
                            {
                                // Configure the message box to be displayed
                                string messageBoxText = "Student with that ID is already in system. Do you want to update?";
                                string caption        = "Confirme Update";

                                if (MessageBox.Show(messageBoxText, caption, MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                                {
                                    Student DbStudent = (Student)SqlWorker.GetUser(student.ID.ToString());
                                    student.ActiveLects    = DbStudent.ActiveLects;
                                    student.ActivePracLabs = DbStudent.ActivePracLabs;
                                    student.Constraints    = DbStudent.Constraints;

                                    if (SqlWorker.SaveUser(student))
                                    {
                                        return(true);
                                    }
                                }
                                return(false);
                            }
                            else
                            {
                                MessageBox.Show("User with that ID is already in system");
                                return(false);
                            }
                        }
                    }

                    if (SqlWorker.AddStudent(student))
                    {
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                throw new Exception("Fields can't be empty!");
            }
            return(false);
        }