Exemple #1
0
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            DayEvent dayEvent = new DayEvent(this.descriptionTextBox.Text,
                                             new DateTime(chosenDate.Year, chosenDate.Month, chosenDate.Day, this.startHourComboBox.SelectedIndex, this.startMinuteComboBox.SelectedIndex, 1),
                                             new DateTime(chosenDate.Year, chosenDate.Month, chosenDate.Day, this.endHourComboBox.SelectedIndex, this.endMinuteComboBox.SelectedIndex, 1));

            if (Model.Calendar.getInstance().dayEventsList.BinarySearch(dayEvent, new DayEventsComparer()) >= 0)
            {
                MessageBox.Show("To zdarzenie istnieje już w kalendarzu");
                return;
            }

            Model.Calendar.getInstance().dayEventsList.Add(dayEvent);
            Model.Calendar.getInstance().dayEventsList.Sort(new DayEventsComparer());
            ViewModel.MainWindowViewModel.getInstance().DisplayEvents();
            //DiskInputOutput.DiskManager.getInstance().WriteEventsToFile();

            DayEvents dayEventInDataBase = new DayEvents()
            {
                username         = ViewModel.MainWindowViewModel.getInstance().username,
                eventDescription = dayEvent.GetDescription(),
                startTime        = dayEvent.GetStartTime(),
                endTime          = dayEvent.GetEndTime()
            };

            ViewModel.MainWindowViewModel.getInstance().databaseContext.DayEvents.AddObject(dayEventInDataBase);
            ViewModel.MainWindowViewModel.getInstance().databaseContext.SaveChanges();

            this.Close();
        }
        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;
        }
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            int index = Calendar.Model.Calendar.getInstance().dayEventsList.BinarySearch(chosenDayEvent, new DayEventsComparer());

            ((DayEvent)Calendar.Model.Calendar.getInstance().dayEventsList[index]).SetDescription(this.descriptionTextBox.Text);
            ((DayEvent)Calendar.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)Calendar.Model.Calendar.getInstance().dayEventsList[index]).SetEndTime(new DateTime(chosenDayEvent.GetEndTime().Year, chosenDayEvent.GetEndTime().Month, chosenDayEvent.GetEndTime().Day, this.endHourComboBox.SelectedIndex, this.endMinuteComboBox.SelectedIndex, 1));
            Calendar.ViewModel.MainWindowViewModel.getInstance().DisplayEvents();
            DiskInputOutput.DiskManager.getInstance().WriteEventsToFile();
            this.Close();
        }