private void saveButton_Click(object sender, RoutedEventArgs e) { int index = CalendarWithBase.Model.Calendar.getInstance().dayEventsList.BinarySearch(chosenDayEvent, new DayEventsComparer()); ((DayEvent)CalendarWithBase.Model.Calendar.getInstance().dayEventsList[index]).SetDescription(this.descriptionTextBox.Text); ((DayEvent)CalendarWithBase.Model.Calendar.getInstance().dayEventsList[index]).SetStartTime(new DateTime(chosenDayEvent.GetStartTime().Year, chosenDayEvent.GetStartTime().Month, chosenDayEvent.GetStartTime().Day, this.startHourComboBox.SelectedIndex, this.startMinuteComboBox.SelectedIndex, 1)); ((DayEvent)CalendarWithBase.Model.Calendar.getInstance().dayEventsList[index]).SetEndTime(new DateTime(chosenDayEvent.GetEndTime().Year, chosenDayEvent.GetEndTime().Month, chosenDayEvent.GetEndTime().Day, this.endHourComboBox.SelectedIndex, this.endMinuteComboBox.SelectedIndex, 1)); CalendarWithBase.ViewModel.MainWindowViewModel.getInstance().DisplayEvents(); //DiskInputOutput.DiskManager.getInstance().WriteEventsToFile(); DateTime newStartTime = new DateTime(chosenDayEvent.GetStartTime().Year, chosenDayEvent.GetStartTime().Month, chosenDayEvent.GetStartTime().Day, this.startHourComboBox.SelectedIndex, this.startMinuteComboBox.SelectedIndex, 1); DateTime newEndTime = new DateTime(chosenDayEvent.GetEndTime().Year, chosenDayEvent.GetEndTime().Month, chosenDayEvent.GetEndTime().Day, this.endHourComboBox.SelectedIndex, this.endMinuteComboBox.SelectedIndex, 1); SqlConnection connection = new SqlConnection(@"Data Source=X51RL-PC;Initial Catalog=NTR2017;Integrated Security=True;MultipleActiveResultSets=True;"); using (connection) { string sqlQuery = string.Format(@" UPDATE DayEvents SET username = '******', eventDescription = '{1}', startTime = CAST('{2}' AS DATETIME), endTime = CAST('{3}' AS DATETIME) WHERE username = '******' AND eventDescription = '{4}' AND startTime = CAST('{5}' AS DATETIME) AND endTime = CAST('{6}' AS DATETIME);", ViewModel.MainWindowViewModel.getInstance().username, descriptionTextBox.Text, newStartTime, newEndTime, chosenDayEvent.GetDescription(), chosenDayEvent.GetStartTime(), chosenDayEvent.GetEndTime() ); SqlCommand command = new SqlCommand(sqlQuery, connection); command.Connection.Open(); command.ExecuteNonQuery(); } //CalendarWithBase.ViewModel.MainWindowViewModel.getInstance().ClearDatabase(); //CalendarWithBase.ViewModel.MainWindowViewModel.getInstance().WriteAllEventsFromListToDatabase(); this.Close(); }
public EditEventWindow(DayEvent chosenDayEvent) { InitializeComponent(); this.chosenDayEvent = chosenDayEvent; for (int i = 0; i < 24; i++) { this.startHourComboBox.Items.Add(i.ToString()); this.endHourComboBox.Items.Add(i.ToString()); } for (int i = 0; i < 60; i++) { this.startMinuteComboBox.Items.Add(i.ToString()); this.endMinuteComboBox.Items.Add(i.ToString()); } this.descriptionTextBox.Text = chosenDayEvent.GetDescription(); this.startHourComboBox.SelectedIndex = chosenDayEvent.GetStartTime().Hour; this.startMinuteComboBox.SelectedIndex = chosenDayEvent.GetStartTime().Minute; this.endHourComboBox.SelectedIndex = chosenDayEvent.GetEndTime().Hour; this.endMinuteComboBox.SelectedIndex = chosenDayEvent.GetEndTime().Minute; }