Example #1
0
 public Main()
 {
     InitializeComponent();
     createResource        = new ResourceMenu();
     createTask            = new TaskMenu();
     formUtilities         = new FormUtilities();
     createdEventsOverview = new List <Event>();
     calendarFunctions     = new GoogleCalendarSync();
 }
Example #2
0
        public void parseTaskDatabaseData(TaskMenu form, bool deadlineFilled, string taskName, string taskDetails, string taskPhase, string deadline = "")
        {
            // Add new task to list
            data = new TaskData(taskName, taskDetails, taskPhase, deadline);
            form.tasks.Add(data);

            // Create database connection to parse data
            using (SqlConnection openConnection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Tobias\source\repos\FUN12 Project\Killerapp-FUN12\ProjectManager\ProjectManagerData.mdf;Integrated Security=True"))
            {
                string saveQuery = "INSERT into Tasks (Name,Details,Phase,Deadline) VALUES (@Name,@Details,@Phase,@Deadline)";

                using (SqlCommand cmd = new SqlCommand(saveQuery, openConnection))
                {
                    cmd.Connection = openConnection;
                    cmd.Parameters.Add("@Name", SqlDbType.Text).Value    = taskName;
                    cmd.Parameters.Add("@Details", SqlDbType.Text).Value = taskDetails;
                    cmd.Parameters.Add("@Phase", SqlDbType.Text).Value   = taskPhase;

                    // If date has been filled, then parse it
                    if (deadlineFilled)
                    {
                        cmd.Parameters.Add("@Deadline", SqlDbType.Date).Value = deadline;
                    }
                    else
                    {
                        cmd.Parameters.Add("@Deadline", SqlDbType.Date).Value = DBNull.Value;
                    }

                    // Error handle the connection
                    try
                    {
                        openConnection.Open();
                        int recordsAdded = cmd.ExecuteNonQuery();
                        MessageBox.Show(recordsAdded + " rows have been touched!");
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show("Something went wrong with an SQL action....", "SQL-related exception");
                        MessageBox.Show(ex.ToString());
                    }
                    // Catch any other exception other then sql
                    catch (Exception ex)
                    {
                        MessageBox.Show("Something went wrong....", "General exception");
                        MessageBox.Show(ex.ToString());
                    }
                    finally
                    {
                        openConnection.Close();
                    }
                }
            }
            form.clearFormState();
            form.Hide();
        }