public RemoveStudentForm(Teacher teacher)
        {
            InitializeComponent();

            _teacher = teacher;
            _querey  = new Querey();

            using (_querey.connection = _querey.NewConn) // setting up dropdown menu
            {
                using (_querey.command = _querey.NewComm)
                {
                    _querey.command.CommandText = "SELECT StudentId, Firstname, Secondname FROM TeacherStudent, Users WHERE StudentId = Users.Id AND TeacherId = @id ORDER BY Users.Id ASC;";
                    _querey.AddParameter("@id", _teacher.Id);

                    using (_querey.reader = _querey.command.ExecuteReader())
                    {
                        while (_querey.reader.Read())
                        {
                            int    id   = _querey.reader.GetInt32(0);
                            string name = _querey.reader.GetString(1) + " " + _querey.reader.GetString(2);
                            Students.Items.Add(id + " : " + name);
                        }
                    }
                }
            }

            DeleteBtn.Enabled = false;
        }
Exemplo n.º 2
0
        private void CreateBtn_Click(object sender, EventArgs e)
        {
            Querey querey = new Querey();
            int    count;

            using (querey.connection = querey.NewConn)
            {
                using (querey.command = querey.NewComm)
                {
                    querey.command.CommandText = "SELECT count(Sets.Id) FROM Sets WHERE Sets.OwnerId = @owner;";
                    querey.AddParameter("@owner", _student.Id);

                    querey.command.CommandType = CommandType.Text;
                    count = Convert.ToInt32(querey.command.ExecuteScalar());
                }
            }
            if (count == 50)
            {
                new MessageForm("You've created the maximum number of sets").Show();
            }
            else
            {
                new CreateSetForm(_student).Show();
                this.Close();
            }
        }
Exemplo n.º 3
0
        private void DeleteSetBtn_Click(object sender, EventArgs e)
        {
            ChooseSet.Text = "";
            ChooseSet.Items.Remove(currentSet.SetName);

            Text1.Clear();
            Text2.Clear();
            Title1.Clear();
            Title2.Clear();
            PointerInput.Clear();
            PointerVal.Text = "";

            Querey querey = new Querey();

            using (querey.connection = querey.NewConn)
            {
                string[][] tables = { new string[] { "Sets", "Id" }, new string[] { "Flashcards", "SetId" }, new string[] { "Permissions", "SetId" }, new string[] { "SetProgress", "SetId" } };

                foreach (string[] table in tables)
                {
                    using (querey.command = querey.NewComm)
                    {
                        querey.command.CommandText = "DELETE FROM " + table[0] + " WHERE " + table[1] + "= @setid;";
                        querey.AddParameter("@setid", currentCard.setId);
                        querey.command.ExecuteNonQuery();
                    }
                }
            }

            currentSet = null;

            ChangeEdit(false);
            SaveChanges();
            new MessageForm("deleted").Show();
        }
Exemplo n.º 4
0
        private void DeleteCardBtn_Click(object sender, EventArgs e)
        {
            if (CountFlashcards() == 1)
            {
                MessageForm errorForm = new MessageForm("You cannot have an empty set.");
                errorForm.Show();
            }
            else
            {
                Querey querey = new Querey();
                using (querey.connection = querey.NewConn)
                {
                    using (querey.command = querey.NewComm)
                    {
                        querey.command.CommandText = "DELETE FROM Flashcards WHERE Flashcards.Id = @flashId;";
                        querey.AddParameter("@flashId", currentCard.id);

                        querey.command.ExecuteNonQuery();
                    }
                }

                SaveChanges();
                queue.Dequeue();
                ChangeSetArray();
                PointerVal.Text = queue.Backwards().ToString();
                currentCard     = queue.Load();
                new MessageForm("deleted").Show();
            }
        }
Exemplo n.º 5
0
        private void KeyBtn_Click(object sender, EventArgs e)
        {
            if (KeyIn.Text == key)
            {
                Querey insert = new Querey();
                using (insert.connection = insert.NewConn)
                {
                    using (insert.command = insert.NewComm)
                    {
                        Encrypt encrypt = new Encrypt(Password.Text);

                        insert.command.CommandText = "INSERT INTO Users (Firstname, Secondname, Email, Teacher, Password) VALUES (@first, @last, @email, @teacher, @pass);";
                        insert.AddParameter("@first", FirstName.Text);
                        insert.AddParameter("@last", LastName.Text);
                        insert.AddParameter("@email", Email.Text);
                        insert.AddParameter("@teacher", Teacher.Checked ? "1" : "0");
                        insert.AddParameter("@pass", encrypt.Hashed);

                        insert.command.ExecuteNonQuery();
                    }

                    if (Teacher.Checked)
                    {
                        int id;

                        using (insert.command = insert.NewComm)
                        {
                            insert.command.CommandText = "SELECT Id FROM Users ORDER BY Id DESC;";
                            using (insert.reader = insert.command.ExecuteReader())
                            {
                                insert.reader.Read();
                                id = insert.reader.GetInt32(0);
                            }
                        }
                        string key = id.ToString() + "x"; // creating teacher key for connecting to students
                        foreach (char character in FirstName.Text)
                        {
                            key += ((int)character).ToString();
                        }
                        using (insert.command = insert.NewComm)
                        {
                            insert.command.CommandText = "INSERT INTO Teacher (TeacherId, InviteKey) VALUES (@id, @key);";
                            insert.AddParameter("@id", id);
                            insert.AddParameter("@key", key);

                            insert.command.ExecuteNonQuery();
                        }

                        new MessageForm("inserted into teacher table").Show();
                    }
                }
                drive.UploadDatabase();

                LoginForm loginForm = new LoginForm();
                loginForm.Show();
                this.Close();
            }
        }
Exemplo n.º 6
0
        public SndReqForm(Student student)
        {
            InitializeComponent();

            _student           = student;
            IdTxt.Text         = "Your Id :" + _student.Id;
            ConfirmBtn.Enabled = true;
            querey             = new Querey();
        }
Exemplo n.º 7
0
 private void SetIdCommand(Querey getSetId)
 {
     if (getSetId.connection.State == ConnectionState.Closed)
     {
         getSetId.connection.Open();
     }
     getSetId.command.CommandText = "SELECT Id FROM Sets WHERE SetName LIKE @name";
     getSetId.AddParameter("@name", SetName.Text);
 }
Exemplo n.º 8
0
        public LearnForm(Student student)
        {
            InitializeComponent();

            _student = student;
            _querey  = new Querey();
            _first   = true;
            int num = 0;

            using (_querey.connection = _querey.NewConn)
            {
                using (_querey.command = _querey.NewComm)
                {
                    _querey.command.CommandText = "SELECT Sum(i.count) FROM(SELECT count(*) AS COUNT FROM Permissions WHERE UserId = @user UNION ALL SELECT Count(*) AS COUNT FROM Sets WHERE OwnerId = @user) i; ";
                    _querey.AddParameter("@user", _student.Id);
                    _querey.command.CommandType = CommandType.Text;
                    size = Convert.ToInt32(_querey.command.ExecuteScalar());
                }
                _sets = new Set[size];

                using (_querey.command = _querey.NewComm)
                {
                    _querey.command.CommandText = "SELECT Sets.Id, Sets.OwnerId, Sets.SetName, Sets.Title1, Sets.Title2 FROM Sets WHERE Sets.OwnerId = @user;";
                    _querey.AddParameter("@user", _student.Id);

                    Read(ref num);
                }

                using (_querey.command = _querey.NewComm)
                {
                    _querey.command.CommandText = "SELECT Sets.Id, Sets.OwnerId, Sets.SetName, Sets.Title1, Sets.Title2 FROM Sets, Permissions WHERE Sets.Id = Permissions.SetId AND Permissions.UserId = @user;";
                    _querey.AddParameter("@user", _student.Id);
                    Read(ref num);
                }
            }

            QuickSort(_sets, 0, _sets.Length - 1);

            foreach (Set set in _sets)
            {
                double percent = Math.Round((1 - set.Urgency) * 100); // when showing to the user a larger percentage means a greater need to revise
                ChooseSet.Items.Add(set.SetName + " " + percent);
            }

            ReviseBtn.Enabled = false;
            TestBtn.Enabled   = false;
            SwapBtn.Enabled   = false;
            Titles.Enabled    = false;
            Titles.Text       = "";
        }
Exemplo n.º 9
0
        private void NewCardBtn_Click(object sender, EventArgs e)
        {
            Querey querey = new Querey();

            if (CountFlashcards() == 64)
            {
                MessageForm errorForm = new MessageForm("You already have the maximum numbers of cards in this set.");
                errorForm.Show();
            }
            else
            {
                int flashId = 0;
                using (querey.connection = querey.NewConn)
                {
                    using (querey.command = querey.NewComm)
                    {
                        querey.command.CommandText = "INSERT INTO Flashcards (SetId, Text1, Text2) VALUES (@setId, @text1, @text2);";
                        querey.AddParameter("@setId", currentCard.setId);
                        querey.AddParameter("@text1", Text1.Text);
                        querey.AddParameter("@text2", Text2.Text);

                        querey.command.ExecuteNonQuery();
                    }

                    using (querey.command = querey.NewComm)
                    {
                        querey.command.CommandText = "SELECT Flashcards.Id FROM Flashcards WHERE SetId = @setId AND Text1 = @text1 AND Text2 = @text2;";
                        querey.AddParameter("@setId", currentCard.setId);
                        querey.AddParameter("@text1", Text1.Text);
                        querey.AddParameter("@text2", Text2.Text);

                        using (querey.reader = querey.command.ExecuteReader())
                        {
                            while (querey.reader.Read())
                            {
                                flashId = querey.reader.GetInt32(0);
                            }
                        }
                    }
                }
                SaveChanges();
                new MessageForm("insertion successful").Show();
                queue.Enqueue(new Flashcard(flashId, currentCard.setId, Text1.Text, Text2.Text));
                PointerVal.Text = queue.Forwards().ToString();
                currentCard     = queue.Load();
                ChangeSetArray();
            }
        }
Exemplo n.º 10
0
        private int CountFlashcards()
        {
            int    count  = 0;
            Querey querey = new Querey();

            using (querey.connection = querey.NewConn)
            {
                using (querey.command = querey.NewComm)
                {
                    querey.command.CommandText = "SELECT count(SetId) FROM Flashcards WHERE SetId = @setid;";
                    querey.AddParameter("@setid", currentCard.setId);

                    querey.command.CommandType = CommandType.Text;
                    count = Convert.ToInt32(querey.command.ExecuteScalar());
                }
            }
            return(count);
        }
Exemplo n.º 11
0
        public RemoveConnForm(Student student)
        {
            InitializeComponent();

            _student = student;
            querey   = new Querey();

            using (querey.connection = querey.NewConn) // setting up drop down menu for deleting requests
            {
                using (querey.command = querey.NewComm)
                {
                    querey.command.CommandText = "SELECT FriendRequest.ReceiverId, Users.FirstName, Users.SecondName FROM FriendRequest, Users WHERE FriendRequest.ReceiverId = Users.Id AND FriendRequest.SenderId = @sender ORDER BY Users.Id ASC;";
                    querey.AddParameter("@sender", _student.Id);

                    using (querey.reader = querey.command.ExecuteReader())
                    {
                        while (querey.reader.Read())
                        {
                            int    id   = querey.reader.GetInt32(0);
                            string name = querey.reader.GetString(1) + " " + querey.reader.GetString(2);

                            SelectRequest.Items.Add(id + " : " + name);
                        }
                    }
                }

                using (querey.command = querey.NewComm) // setting up drop down menu for deleting friends
                {
                    querey.command.CommandText = "SELECT Users.Id, Users.Firstname, Users.Secondname FROM Friends,Users WHERE Users.Id = Student1 AND Student2 = @id OR Users.Id = Student2 AND Student1 = @id ORDER BY Users.Id ASC;";
                    querey.AddParameter("@id", _student.Id);
                    using (querey.reader = querey.command.ExecuteReader())
                    {
                        while (querey.reader.Read())
                        {
                            int    id   = querey.reader.GetInt32(0);
                            string name = querey.reader.GetString(1) + " " + querey.reader.GetString(2);
                            SelectFriend.Items.Add(id + " : " + name);
                        }
                    }
                }
            }
            DeleteRequestBtn.Enabled = false;
            DeleteFriendBtn.Enabled  = false;
        }
Exemplo n.º 12
0
        public Teacher(int id, string email, string firstName, string lastName, List <int> ids) : base(id, email, firstName, lastName, ids)
        {
            _students = ids;
            Querey getKey = new Querey();

            using (getKey.connection = getKey.NewConn)
            {
                using (getKey.command = getKey.NewComm)
                {
                    getKey.command.CommandText = "SELECT InviteKey FROM Teacher WHERE TeacherId = @id";
                    getKey.AddParameter("@id", id);

                    using (getKey.reader = getKey.command.ExecuteReader())
                    {
                        getKey.reader.Read();
                        _key = getKey.reader.GetString(0);
                    }
                }
            }

            _lastName = lastName;
        }
Exemplo n.º 13
0
        private void SaveTitleBtn_Click(object sender, EventArgs e)
        {
            Querey querey = new Querey();

            using (querey.connection = querey.NewConn)
            {
                using (querey.command = querey.NewComm)
                {
                    querey.command.CommandText = "UPDATE Sets SET Title1 = @title1, Title2 = @title2 WHERE Id = @id;";
                    querey.AddParameter("@title1", Title1.Text);
                    querey.AddParameter("@title2", Title2.Text);
                    querey.AddParameter("@id", currentCard.setId);

                    querey.command.ExecuteNonQuery();
                }
            }

            currentSet.Title1 = Title1.Text;
            currentSet.Title2 = Title2.Text;

            SaveChanges();
        }
Exemplo n.º 14
0
        public void Initialise() // written as a procedure so that I wouldn't need to write the same code out in both constructors
        {
            _sets = new Set[50];

            ChangeEdit(false);

            Querey getSets = new Querey();

            using (getSets.connection = getSets.NewConn)
            {
                using (getSets.command = getSets.NewComm)
                {
                    getSets.command.CommandText = "SELECT Sets.Id, Sets.SetName, Sets.Title1, Sets.Title2 FROM Sets, Users WHERE Sets.OwnerId = Users.Id AND Sets.OwnerId = @userId;";
                    getSets.AddParameter("@userId", userId);


                    using (getSets.reader = getSets.command.ExecuteReader())
                    {
                        int    i       = 0;
                        int    setId   = 0;
                        string setName = "";
                        string title1  = "";
                        string title2  = "";
                        while (getSets.reader.Read())
                        {
                            setId   = getSets.reader.GetInt32(0);
                            setName = getSets.reader.GetString(1);
                            title1  = getSets.reader.GetString(2);
                            title2  = getSets.reader.GetString(3);

                            _sets[i] = new Set(setId, userId, setName, title1, title2);
                            ChooseSet.Items.Add(_sets[i].SetName);
                            i++;
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
        public Student(int id, string email, string firstName, string lastName, List <int> ids) : base(id, email, firstName, lastName, ids)
        {
            friends = ids;


            Querey getTeacherLink = new Querey();

            using (getTeacherLink.connection = getTeacherLink.NewConn)
            {
                using (getTeacherLink.command = getTeacherLink.NewComm)
                {
                    getTeacherLink.command.CommandText = "SELECT TeacherId, FirstName, SecondName FROM Users, TeacherStudent WHERE StudentId = " + id + " AND StudentId = Users.Id;";
                    getTeacherLink.reader = getTeacherLink.command.ExecuteReader();
                    using (getTeacherLink.reader)
                    {
                        if (getTeacherLink.reader.Read())
                        {
                            teacherConn = new Tuple <int, string>(getTeacherLink.reader.GetInt32(0), getTeacherLink.reader.GetString(1) + " " + getTeacherLink.reader.GetString(2));
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        public Set(int id, int ownerId, string setName, string title1, string title2)
        {
            _id        = id;
            _ownerId   = ownerId;
            _setName   = setName;
            _title1    = title1;
            _title2    = title2;
            _querey    = new Querey();
            _strengths = new double[] { 2.10, 3.48, 13.63, 59.16, 104.30, 153.92, 209.57, 313.04, 417.10, 521.39, 625.55 };

            using (_querey.connection = _querey.NewConn)
            {
                using (_querey.command = _querey.NewComm)
                {
                    _querey.command.CommandText = "SELECT count(SetId) FROM Flashcards WHERE SetId = @setid;";
                    _querey.AddParameter("@setid", _id);
                    int length = Convert.ToInt32(_querey.command.ExecuteScalar());
                    _flashcards = new Flashcard[length];
                }

                using (_querey.command = _querey.NewComm)
                {
                    _querey.command.CommandText = "SELECT Flashcards.Id, Flashcards.Text1, Flashcards.Text2 FROM Flashcards, Sets WHERE Flashcards.SetId = Sets.Id AND Flashcards.SetId = @id;";
                    _querey.AddParameter("@id", id);
                    using (_querey.reader = _querey.command.ExecuteReader())
                    {
                        int i = 0;
                        while (_querey.reader.Read())
                        {
                            _flashcards[i] = new Flashcard(_querey.reader.GetInt32(0), id, _querey.reader.GetString(1), _querey.reader.GetString(2));
                            i++;
                        }
                    }
                }
            }
        }
Exemplo n.º 17
0
        private void SaveCardsBtn_Click(object sender, EventArgs e)
        {
            currentCard.text1 = Text1.Text;
            currentCard.text2 = Text2.Text;
            Querey querey = new Querey();

            foreach (Flashcard card in currentSet.Flashcards)
            {
                using (querey.connection = querey.NewConn)
                {
                    using (querey.command = querey.NewComm)
                    {
                        querey.command.CommandText = "UPDATE Flashcards SET Text1 = @text1, Text2 = @text2 WHERE Flashcards.Id = @flashId;";
                        querey.AddParameter("@text1", currentCard.text1);
                        querey.AddParameter("@text2", currentCard.text2);
                        querey.AddParameter("@flashId", currentCard.id);

                        querey.command.ExecuteNonQuery();
                    }
                }
            }
            SaveChanges();
            new MessageForm("changes saved").Show();
        }
Exemplo n.º 18
0
        private void Insert_Click(object sender, EventArgs e) // inserts set into database and then updates cloud
        {
            Querey getSetId = new Querey();
            bool   used;

            using (getSetId.connection = getSetId.NewConn)
            {
                using (getSetId.command = getSetId.NewComm)
                {
                    SetIdCommand(getSetId);
                    using (getSetId.reader = getSetId.command.ExecuteReader())
                    {
                        used = getSetId.reader.Read();
                    }
                }
            }

            if (SetName.Text == "")
            {
                MessageForm errorForm = new MessageForm("Please enter a set name.");
                errorForm.Show();
            }
            else if (!used)
            {
                if (Title1.Text == "" || Title2.Text == "")
                {
                    MessageForm errorForm = new MessageForm("Please enter titles for your sets.");
                    errorForm.Show();
                }
                else
                {
                    Querey insert = new Querey();
                    using (insert.connection = insert.NewConn)
                    {
                        using (insert.command = insert.NewComm)
                        {
                            insert.command.CommandText = "INSERT INTO Sets (OwnerId, SetName, Title1, Title2) VALUES (@owner, @name, @title1, @title2);";
                            insert.AddParameter("@owner", _userId);
                            insert.AddParameter("@name", SetName.Text);
                            insert.AddParameter("@title1", Title1.Text);
                            insert.AddParameter("@title2", Title2.Text);
                            if (insert.connection.State != ConnectionState.Open)
                            {
                                insert.connection.Open();
                            }
                            insert.command.ExecuteNonQuery();
                            insert.Close();
                        }
                    }

                    getSetId = new Querey();
                    int setId;
                    using (getSetId.connection = getSetId.NewConn)
                    {
                        using (getSetId.command = getSetId.NewComm)
                        {
                            SetIdCommand(getSetId);
                            using (getSetId.reader = getSetId.command.ExecuteReader())
                            {
                                getSetId.reader.Read();
                                setId = getSetId.reader.GetInt32(0);
                            }
                        }
                    }

                    insert = new Querey();
                    using (insert.connection = insert.NewConn)
                    {
                        int count = 0;
                        while (count < 64 && _data[count, 0] != null)
                        {
                            using (insert.command = insert.NewComm)
                            {
                                insert.command.CommandText = "INSERT INTO Flashcards (SetId, Text1, Text2) VALUES (@setId, @text1, @text2);";
                                insert.AddParameter("@setId", setId);
                                insert.AddParameter("@text1", _data[count, 0]);
                                insert.AddParameter("@text2", _data[count, 1]);
                                insert.command.ExecuteNonQuery();
                                count++;
                            }
                        }

                        string[] tables = { "Permissions", "SetProgress" }; // done this way to allow easier error checking and make queries more readable
                        for (int i = 0; i < tables.Length; i++)
                        {
                            using (insert.command = insert.NewComm)
                            {
                                if (_student != null)
                                {
                                    insert.command.CommandText = "INSERT INTO " + tables[i] + " (UserId, SetId) SELECT Users.Id, Sets.Id FROM Users, Sets, Friends WHERE Student1 = @id AND Sets.Id = @setId AND Sets.OwnerId = Student1 AND Users.Id = Student2 OR Student2 = @id AND Sets.Id = @setId AND Sets.OwnerId = Student2 AND Users.Id = Student1;";
                                }
                                else
                                {
                                    insert.command.CommandText = "INSERT INTO " + tables[i] + " (UserId, SetId) SELECT Users.Id, Sets.Id FROM Users, Sets, TeacherStudent WHERE TeacherId = @id AND Sets.Id = @setId AND Sets.OwnerId = TeacherId AND Users.Id = StudentId;";
                                }
                                insert.AddParameter("@id", _userId);
                                insert.AddParameter("@setId", setId);
                                insert.command.ExecuteNonQuery();
                                new MessageForm("inserted").Show();
                            }
                        }

                        using (insert.command = insert.NewComm)
                        {
                            insert.command.CommandText = "INSERT INTO SetProgress (UserId, SetId) SELECT OwnerId, Id FROM Sets WHERE id = @setId;";
                            insert.AddParameter("setId", setId);
                            insert.command.ExecuteNonQuery();
                        }

                        using (insert.command = insert.NewComm)
                        {
                            double initialStrength = 2.10;
                            insert.command.CommandText = "UPDATE SetProgress SET LastReview = @now, Strength = @strength WHERE SetId = @set;";
                            insert.AddParameter("@now", DateTime.Now.ToString());
                            insert.AddParameter("@strength", initialStrength);
                            insert.AddParameter("@set", setId);

                            insert.command.ExecuteNonQuery();
                        }
                    }

                    GDrive drive = new GDrive();
                    drive.UploadDatabase();

                    ConfirmMsg.Enabled = false;
                    OpenFile.Reset();
                    SetName.Clear();
                    Title1.Clear();
                    Title2.Clear();
                    OpenFile.Reset();
                    FileName.Text = "";
                }
            }
            else
            {
                MessageForm errorForm = new MessageForm("This set name has already been used. Please choose a different one.");
                errorForm.Show();
            }
        }
Exemplo n.º 19
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool   success        = false;
            Querey getUserDetails = new Querey();

            using (getUserDetails.connection = getUserDetails.NewConn)
            {
                using (getUserDetails.command = getUserDetails.NewComm)
                {
                    getUserDetails.command.CommandText = "SELECT Id, Email, Firstname, Secondname, Password, Teacher FROM Users WHERE Email LIKE @email AND Password = @pass;";
                    Encrypt encrypt = new Encrypt(Password.Text);
                    getUserDetails.AddParameter("@email", Email.Text);
                    getUserDetails.AddParameter("@pass", encrypt.Hashed);

                    getUserDetails.reader = getUserDetails.command.ExecuteReader();
                    using (getUserDetails.reader)
                    {
                        if (getUserDetails.reader.Read()) // getting user details
                        {
                            id        = getUserDetails.reader.GetInt32(0);
                            email     = getUserDetails.reader.GetString(1);
                            firstName = getUserDetails.reader.GetString(2);
                            lastName  = getUserDetails.reader.GetString(3);
                            password  = getUserDetails.reader.GetString(4);
                            teacher   = (getUserDetails.reader.GetString(5) == "1"); // if the value stored is 1 then teacher will be set to true

                            success = true;
                        }
                    }
                }
            }

            if (!success)
            {
                MessageForm errorForm = new MessageForm("Username or password is incorrect");
                errorForm.Show();
            }
            else
            {
                List <int> ids = new List <int> {
                };

                Querey getIds = new Querey();
                using (getIds.connection = getIds.NewConn)
                {
                    using (getIds.command = getIds.NewComm)
                    {
                        if (teacher)
                        {
                            getIds.command.CommandText = "SELECT StudentId FROM TeacherStudent, Users WHERE TeacherId = Users.Id AND TeacherId = @id";
                            getIds.AddParameter("@id", id);

                            getIds.reader = getIds.command.ExecuteReader();
                            using (getIds.reader)
                            {
                                while (getIds.reader.Read())
                                {
                                    ids.Add(getIds.reader.GetInt32(0));
                                    MessageForm errorForm = new MessageForm(getIds.reader.GetInt32(0).ToString());
                                    errorForm.Show();
                                }
                            }

                            Teacher teacherAcc = new Teacher(id, email, firstName, lastName, ids);
                            new TeacherMainMenu(teacherAcc).Show();
                            this.Close();
                        }
                        else
                        {
                            getIds.command.CommandText = "SELECT Student1 FROM Friends WHERE Student2 = @id;";
                            getIds.AddParameter("@id", id);

                            getIds.reader = getIds.command.ExecuteReader();
                            using (getIds.reader)
                            {
                                while (getIds.reader.Read())
                                {
                                    ids.Add(getIds.reader.GetInt32(0));
                                }
                            }

                            getIds.command.CommandText = "SELECT Student2 FROM Friends WHERE Student1 = @id;";
                            getIds.AddParameter("@id", id);
                            getIds.reader = getIds.command.ExecuteReader();

                            using (getIds.reader)
                            {
                                while (getIds.reader.Read())
                                {
                                    ids.Add(getIds.reader.GetInt32(0));
                                }
                            }

                            Student         studentAcc      = new Student(id, email, firstName, lastName, ids);
                            StudentMainMenu studentMainMenu = new StudentMainMenu(studentAcc);
                            studentMainMenu.Show();
                            this.Close();
                        }
                    }
                }
            }
        }
Exemplo n.º 20
0
        private void Register_Click(object sender, EventArgs e)
        {
            string errormsg = "";
            string pattern  = @"^([A-Za-z0-9]+[!#$%&'*+\-/=?^_`{|.(),:;[\]]?)+@[A-Za-z0-9-.]+([-.]\w+)*\.\w+([-.]\w+)*$"; // regex

            if (FirstName.Text == "")
            {
                errormsg += "Please enter your first name.\n\n";
            }
            if (LastName.Text == "")
            {
                errormsg += "Please enter your second name.\n\n";
            }
            if (Email.Text == "")
            {
                errormsg += "Please enter your email address.\n\n";
            }
            else if (!Regex.IsMatch(Email.Text, pattern))
            {
                errormsg += "Please enter a valid email address.\n\n";
            }
            if (Password.Text == "")
            {
                errormsg += "Please enter your password.\n\n";
            }
            if (RepPassword.Text == "")
            {
                errormsg += "Please re-enter your password.\n\n";
            }
            if (errormsg != "")
            {
                Fail(errormsg);
            }
            else
            {
                if (Password.Text != RepPassword.Text)
                {
                    Fail("The passwords do not match.");
                }
                else
                {
                    Querey checkEmail = new Querey();
                    using (checkEmail.connection = checkEmail.NewConn)
                    {
                        using (checkEmail.command = checkEmail.NewComm)
                        {
                            checkEmail.command.CommandText = "SELECT Email FROM Users WHERE Email LIKE @email;";
                            checkEmail.AddParameter("@email", Email.Text);
                            checkEmail.reader = checkEmail.command.ExecuteReader();

                            using (checkEmail.reader)
                            {
                                if (checkEmail.reader.Read())
                                {
                                    Fail("This email address is already linked to an account.");
                                }
                                else
                                {
                                    Random rnd = new Random();
                                    for (int i = 0; i < 20; i++)
                                    {
                                        key += (char)rnd.Next(33, 127);
                                    }

                                    SendKey();
                                    KeyBtn.Enabled = true;
                                    Resend.Enabled = true;
                                }
                            }
                        }
                    }
                }
            }
        }