private void btn_AddAllTasks_Click(object sender, RoutedEventArgs e) { FillAvailableTasks(); string s_ConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data " + "Source=|DataDirectory|\\CloseoutApp.accdb"; using (OleDbConnection AccessConn = new OleDbConnection(s_ConnString)) { using (OleDbCommand AccessCmd = AccessConn.CreateCommand()) { foreach (TaskForMilestone t in GlobalVars.AvailableTasksForMilestone) { AccessCmd.CommandText = "INSERT INTO Tasks (TaskID, ContractID, MilestoneID) " + "VALUES (@TID, @CID, @MID);"; AccessCmd.Parameters.Clear(); AccessCmd.Parameters.Add("TID", OleDbType.Integer).Value = t.TaskID; AccessCmd.Parameters.Add("CID", OleDbType.Integer).Value = GlobalVars.SelectedContract; AccessCmd.Parameters.Add("MID", OleDbType.Integer).Value = GlobalVars.SelectedMilestone; try { AccessConn.Open(); AccessCmd.ExecuteNonQuery(); AccessConn.Close(); } catch (Exception except) { MessageBox.Show("Database error: " + except.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } } // Update the Global list of tasks for the selected milestone for that contract. ContractStatus cts = new ContractStatus(); cts.UpdateTasksForMilestoneList(GlobalVars.SelectedMilestone); // Head back to the contract status screen. NavigationService nav = NavigationService.GetNavigationService(this); nav.Navigate(new System.Uri("ContractStatus.xaml", UriKind.RelativeOrAbsolute)); }
private void btn_Save_Click(object sender, RoutedEventArgs e) { /* btn_Save_Click * If the New Task button was clicked and there is an available * task selected in the ComboBox... * 1. Sets up the parameterized SQL command. * 2. Adds the TaskID, ContractID, and MilestoneID parameters to the query. * 3. Attempts the query, popping a message box if successful or if an error was thrown. * 4. Updates the global list of tasks for that milestone. * 5. Automatically returns to the contract status screen. * * If there was no task selected, throws an error. * If New Task wasn't clicked, they shouldn't be able to click save anyway. * * */ if (NewTask == true) { if (cb_TasksPicker.SelectedIndex != -1) { string s_ConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data " + "Source=|DataDirectory|\\CloseoutApp.accdb"; using (OleDbConnection AccessConn = new OleDbConnection(s_ConnString)) { using (OleDbCommand AccessCmd = AccessConn.CreateCommand()) { string command = "INSERT INTO Tasks (TaskID, ContractID, MilestoneID) " + "VALUES (@TID, @CID, @MID);"; AccessCmd.CommandText = command; AccessCmd.Parameters.Add("TID", OleDbType.Integer).Value = GlobalVars.AvailableTasksForMilestone[cb_TasksPicker.SelectedIndex].TaskID; AccessCmd.Parameters.Add("CID", OleDbType.Integer).Value = GlobalVars.SelectedContract; AccessCmd.Parameters.Add("MID", OleDbType.Integer).Value = GlobalVars.SelectedMilestone; AccessConn.Open(); try { if (AccessCmd.ExecuteNonQuery() > 0) { MessageBox.Show("Task successfully added.", "Added", MessageBoxButton.OK, MessageBoxImage.Information); } AccessCmd.Parameters.Clear(); } catch (Exception dbex) { MessageBox.Show("Error when adding task:\n" + dbex.Message + "\nPlease take a screenshot and\nreport this to Ashton.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } AccessConn.Close(); } } // Update the Global list of tasks for the selected milestone for that contract. ContractStatus cts = new ContractStatus(); cts.UpdateTasksForMilestoneList(GlobalVars.SelectedMilestone); // Head back to the contract status screen. NavigationService nav = NavigationService.GetNavigationService(this); nav.Navigate(new System.Uri("ContractStatus.xaml", UriKind.RelativeOrAbsolute)); } else { MessageBox.Show("No task selected. No tasks may be available to input\nfor this milestone.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { // Do nothing. Shouldn't be able to click save if false anyway. } }