Esempio n. 1
0
        private void JumpBtn_Click(object sender, EventArgs e)
        {
            if (PointerInput.Text == "")
            {
                MessageForm errorForm = new MessageForm("Please enter which card you want to go to");
                errorForm.Show();
            }
            else if (int.Parse(PointerInput.Text) < 0 || int.Parse(PointerInput.Text) > queue.GetQueue.Length)
            {
                MessageForm errorForm = new MessageForm("Please enter a value within the range of your flashcards");
                errorForm.Show();
            }
            else if (queue.GetQueue[int.Parse(PointerInput.Text) - 1] == null)
            {
                MessageForm errorForm = new MessageForm("Your set does not have that many flashcards");
                errorForm.Show();
            }
            else
            {
                int  difference = int.Parse(PointerVal.Text) - int.Parse(PointerInput.Text);
                bool back       = false;
                if (difference < 0)
                {
                    difference = -difference;
                    back       = true;
                }

                for (int i = 0; i < difference; i++)
                {
                    PointerVal.Text = (back ? queue.Forwards() : queue.Backwards()).ToString();
                }

                currentCard = queue.Load();
            }
            PointerInput.Clear();
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
0
        private void Fail(string errorMsg)
        {
            MessageForm errorForm = new MessageForm(errorMsg);

            errorForm.Show();
        }
Esempio n. 4
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();
                        }
                    }
                }
            }
        }