Esempio n. 1
0
        public static void addNewTask(string TaskName, string TaskDescription, double TaskLength, int ProjectID, int Priority, DateTime StartDate)
        {
            /*
             * This method acts similarly to the one above, however is used if a task with priotiy 1 needs to be added (with a start date)
             */
            string SQL = "INSERT INTO tblTask(TaskName, TaskDescription, TaskLength, ProjectID, Priority, StartDate) VALUES(@TN,@TD,@TL,@PID,@PR,@SD)";

            //Populate command object
            command = new MySqlCommand(SQL, Conn);
            try
            {
                //Add SQL param values
                command.Parameters.AddWithValue("@TN", TaskName);
                command.Parameters.AddWithValue("@TD", TaskDescription);
                command.Parameters.AddWithValue("@TL", TaskLength);
                command.Parameters.AddWithValue("@PID", ProjectID);
                command.Parameters.AddWithValue("@PR", Priority);
                command.Parameters.AddWithValue("@SD", TimeHandler.ConvertToAccessDateTime(StartDate));
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to bind project information to SQL variables");
            }

            /*Open the connection and execute the insert-into command. This method will return the number of rows that have been affected (in this case, added)
             * therefore, if affectedRows>0, insertion has been completed successfully*/
            Conn.Open();
            if (command.ExecuteNonQuery() > 0)
            {
                MessageBox.Show("Task added successfully");
            }
            else
            {
                //If the code gets this far, it means that there has not been an in-code syntax error, instead a data entry error (v.likely to be user-related)
                MessageBox.Show("Task addition failed - check that all task criteria have a correct entry");
            }
            //Close the connection to reduce resource usage and prevent other changes to database from other users (and this software)
            Conn.Close();

            //Update project length
            updateProjectLength(ProjectID);
        }
Esempio n. 2
0
        public static void editProject(string ProjectName, string ProjectDescription, DateTime StartDate, Project ProjectToEdit)
        {
            /*
             * Takes new project information and syncs these changes to the database
             */
            string SQL = "UPDATE tblProject SET ProjectName = @PN, ProjectDescription = @PDN, DateStarted = @SD WHERE ProjectID = @PID";

            //Create command
            command = new MySqlCommand(SQL, Conn);
            try
            {
                //Add param values
                command.Parameters.AddWithValue("@PN", ProjectName);
                command.Parameters.AddWithValue("@PDN", ProjectDescription);
                command.Parameters.AddWithValue("@SD", TimeHandler.ConvertToAccessDateTime(StartDate));
                command.Parameters.AddWithValue("@PID", ProjectToEdit.ID);
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to bind information to SQL variables");
            }

            /*Open the connection and execute the insert-into command. This method will return the number of rows that have been affected (in this case, added)
             * therefore, if affectedRows>0, insertion has been completed successfully*/
            Conn.Open();
            if (command.ExecuteNonQuery() > 0)
            {
                MessageBox.Show("Project information updated");
            }
            else
            {
                //If the code gets this far, it means that there has not been an in-code syntax error, instead a data entry error (v.likely to be user-related)
                MessageBox.Show("Project edit failed - check that all criteria have a correct entry");
            }
            //Close the connection to reduce resource usage and prevent other changes to database from other users (and this software)
            Conn.Close();
        }
Esempio n. 3
0
        public static void addNewUser(string Username, string Password, string FirstName, string Surname, DateTime DateOfBirth, string EMail)
        {
            //Generate SQL (with params) and populate the commmand object
            string SQL = "INSERT INTO tbluser(Username, Password, FirstName, Surname, DateOfBirth, EMail) VALUES(@UN, @PW, @FN, @SN, @DOB, @EM)";

            command = new MySqlCommand(SQL, Conn);
            try
            {
                //Add the paramater values to the command objects
                command.Parameters.AddWithValue("@UN", Username);
                command.Parameters.AddWithValue("@PW", Password);
                command.Parameters.AddWithValue("@FN", FirstName);
                command.Parameters.AddWithValue("@SN", Surname);
                command.Parameters.AddWithValue("@DOB", TimeHandler.ConvertToAccessDateTime(DateOfBirth));
                command.Parameters.AddWithValue("@EM", EMail);
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to bind user information to SQL variables");
            }

            /*Open the connection and execute the insert-into command. This method will return the number of rows that have been affected (in this case, added)
             * therefore, if affectedRows>0, insertion has been completed successfully*/
            Conn.Open();
            if (command.ExecuteNonQuery() > 0)
            {
                MessageBox.Show("User Registered Successfuly");
            }
            else
            {
                //If the code gets this far, it means that there has not been an in-code syntax error, instead a data entry error (v.likely to be user-related)
                MessageBox.Show("User registration failed - check that all project criteria have a correct entry");
            }
            //Close the connection to reduce resource usage and prevent other changes to database from other users (and this software)
            Conn.Close();
        }
Esempio n. 4
0
        public static void addNewProject(string Username, string ProjectName, string ProjectDescription, DateTime DateStarted, DateTime prjDueDate)
        {
            //Generate SQL (with params) and populate the commmand object
            string SQL = "INSERT INTO tblproject(Username,ProjectName,ProjectDescription,ProjectLength,DateStarted,DateDue) VALUES(@UN,@PN,@PD,@PL,@DS,@DD)";

            command = new MySqlCommand(SQL, Conn);
            try
            {
                //Add the paramater values to the command objects
                command.Parameters.AddWithValue("@UN", Username);
                command.Parameters.AddWithValue("@PN", ProjectName);
                command.Parameters.AddWithValue("@PD", ProjectDescription);
                command.Parameters.AddWithValue("@PL", 1);
                command.Parameters.AddWithValue("@DS", TimeHandler.ConvertToAccessDateTime(DateStarted));
                command.Parameters.AddWithValue("@DD", TimeHandler.ConvertToAccessDateTime(prjDueDate));
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to bind project information to SQL variables");
            }

            /*Open the connection and execute the insert-into command. This method will return the number of rows that have been affected (in this case, added)
             * therefore, if affectedRows>0, insertion has been completed successfully*/
            Conn.Open();
            if (command.ExecuteNonQuery() > 0)
            {
                MessageBox.Show("Project Added Successfuly");
            }
            else
            {
                //If the code gets this far, it means that there has not been an in-code syntax error, instead a data entry error (v.likely to be user-related)
                MessageBox.Show("New project failed - check that all project criteria have a correct entry");
            }
            //Close the connection to reduce resource usage and prevent other changes to database from other users (and this software)
            Conn.Close();
        }