/// <summary> /// Adds the plan to the DataBase and plans listbox after filling /// the plan description in PlanDescription Window /// </summary> private void addButton_Click(object sender, RoutedEventArgs e) { try { plan = new PlanDescription(); plan.DeadLine_datepicker.SelectedDate = DateTime.Today; bool? result = plan.ShowDialog(); if (result.Value == true) { if (String.IsNullOrEmpty(plan.descriptionTextBox.Text) == false && plan.DeadLine_datepicker.SelectedDate != null && InputLanguageManager.Current.CurrentInputLanguage.Name == "en-US") { MainWindow.Connection.Open(); cmd = new SqlCommand("Insert into [Plan] (User_login, Description, IsCompleted, DeadLine, Date) values (@User_login, @Description, 'N', @DeadLine, @Date)", MainWindow.Connection); cmd.Parameters.AddWithValue("@User_login", MainWindow.CurrentUser); cmd.Parameters.AddWithValue("@Description", plan.descriptionTextBox.Text); cmd.Parameters.AddWithValue("@DeadLine", plan.DeadLine_datepicker.SelectedDate); cmd.Parameters.AddWithValue("@Date", DateTime.Now); cmd.ExecuteNonQuery(); MainWindow.Connection.Close(); plansListBox.Items.Add(plan.descriptionTextBox.Text + ": (Till " + plan.DeadLine_datepicker.SelectedDate.Value.ToShortDateString() + ")"); } else MessageBox.Show("Description can't be empty or written in Russian (Write in English)", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (SqlException ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error); MainWindow.Connection.Close(); } catch (Exception except) { MessageBox.Show(except.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); MainWindow.Connection.Close(); } }
/// <summary> /// Allows the user to edit the selected plan after pressing /// the "Edit" button /// </summary> private void editButton_Click(object sender, RoutedEventArgs e) { try { if (plansListBox.SelectedItem != null) { plan = new PlanDescription(); plan.descriptionTextBox.Text = plansListBox.SelectedItem.ToString().Split(':')[0]; plan.DeadLine_datepicker.SelectedDate = GetDeadLineDate(MainWindow.Connection, CurrentPlanId); bool? result = plan.ShowDialog(); if (result.Value == true) { if (string.IsNullOrEmpty(plan.descriptionTextBox.Text) == false && InputLanguageManager.Current.CurrentInputLanguage.Name == "en-US") { MainWindow.Connection.Open(); cmd = new SqlCommand(@"update [Plan] set Description='" + plan.descriptionTextBox.Text + "', " + "DeadLine='" + plan.DeadLine_datepicker.SelectedDate + "' where Id like " + CurrentPlanId, MainWindow.Connection); cmd.ExecuteNonQuery(); MainWindow.Connection.Close(); MainWindow.GetTasks(MainWindow.Connection, plansListBox, "N"); } else MessageBox.Show("The description field can't be empty or written in Russian!", "Description", MessageBoxButton.OK, MessageBoxImage.Information); } } else MessageBox.Show("Select the plan you want to edit!", "Select the plan", MessageBoxButton.OK, MessageBoxImage.Information); } catch (SqlException ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error); MainWindow.Connection.Close(); } catch (Exception except) { MessageBox.Show(except.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); MainWindow.Connection.Close(); } }