Esempio n. 1
0
        protected void Register_Click(object sender, EventArgs e)
        {
            if (!isValidEmail(inputEmail.Text))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Invalid Email Address!')", true);
            }

            // invalid email

            else
            {
                String t;
                if (radio_student.Checked)
                {
                    t = "student";
                }
                else
                {
                    t = "teacher";
                }


                using (var db = new webProjectEntities())
                {
                    var newUser = new tableUsers()
                    {
                        ID               = inputid.Text,
                        Email            = inputEmail.Text,
                        Password         = inputPassword.Text,
                        Fullname         = inputFullname.Text,
                        Algebra          = "",
                        Algorithms       = "",
                        Datamining       = "",
                        WebDev           = "",
                        Calculus         = "",
                        OperatinsSystems = "",
                        type             = t
                    };

                    try
                    {
                        db.tableUsers.Add(newUser);
                        db.SaveChanges();
                        RegisteredSuccess.Visible       = true;
                        RequiredFieldValidator.Visible  = false;
                        RequiredFieldValidator1.Visible = false;
                        RequiredFieldValidator2.Visible = false;
                        gotoLogin.Visible   = true;
                        backToLogin.Visible = false;
                    }
                    catch (Exception ex)
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ID already exists')", true);
                    }
                }
            }
        }
Esempio n. 2
0
        private bool checkGrades(tableUsers user)
        {
            int grade;

            if (user.Algebra.Length > 0 && (!Int32.TryParse(user.Algebra, out grade) || grade < 0 || grade > 100))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Algebra grade must be a number in range 0-100')", true);
                return(false);
            }
            else if (user.Algorithms.Length > 0 && (!Int32.TryParse(user.Algorithms, out grade) || grade < 0 || grade > 100))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Algorithms grade must be a number in range 0-100')", true);
                return(false);
            }
            else if (user.Datamining.Length > 0 && (!Int32.TryParse(user.Datamining, out grade) || grade < 0 || grade > 100))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Data mining grade must be a number in range 0-100')", true);
                return(false);
            }
            else if (user.WebDev.Length > 0 && (!Int32.TryParse(user.WebDev, out grade) || grade < 0 || grade > 100))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Web Development grade must be a number in range 0-100')", true);
                return(false);
            }
            else if (user.Calculus.Length > 0 && (!Int32.TryParse(user.Calculus, out grade) || grade < 0 || grade > 100))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Calculus grade must be a number in range 0-100')", true);
                return(false);
            }
            else if (user.OperatinsSystems.Length > 0 && (!Int32.TryParse(user.OperatinsSystems, out grade) || grade < 0 || grade > 100))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Operating Systems grade must be a number in range 0-100')", true);
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
        protected void addNewStudent(object sender, EventArgs e)
        {
            Session["returnToPage"] = "6";
            toStudentTbl.Visible    = false;
            if (newStudentEmail.Text.Length == 0 || newStudentID.Text.Length == 0 || newStudentPassword.Text.Length == 0) // mandatory fields are empty
            {
                addStudent_lbl.Visible = true;
            }

            else // form is filled OK
            {
                if (!isValidEmail(newStudentEmail.Text))
                {
                    addStudent_lbl.Visible = false;
                    toStudentTbl.Visible   = false;
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Invalid Email Address!')", true);
                }
                else
                {
                    using (var db = new webProjectEntities())
                    {
                        var newUser = new tableUsers()
                        {
                            ID               = newStudentID.Text,
                            Email            = newStudentEmail.Text,
                            Password         = newStudentPassword.Text,
                            Fullname         = newStudentFullname.Text.Length == 0 ? "" : newStudentFullname.Text,
                            Algebra          = "",
                            Algorithms       = "",
                            Datamining       = "",
                            WebDev           = "",
                            Calculus         = "",
                            OperatinsSystems = "",
                            type             = "student"
                        };

                        newStudentEmail.Text    = "";
                        newStudentID.Text       = "";
                        newStudentPassword.Text = "";
                        newStudentFullname.Text = "";

                        try
                        {
                            db.tableUsers.Add(newUser);
                            db.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ID already exists')", true);
                            addStudent_lbl.Visible = false;
                            toStudentTbl.Visible   = false;
                            return;
                        }
                    }
                    addStudent_lbl.ForeColor = System.Drawing.Color.Green;
                    addStudent_lbl.Text      = "New Student Added Successfully";
                    addStudent_lbl.Visible   = true;
                    toStudentTbl.Attributes.Add("style", "margin-left: 25px;");
                    toStudentTbl.Visible = true;
                }
            }
        }