private void modifyElButton_Click(object sender, RoutedEventArgs e) { if (listBox.SelectedItem == null) { MessageBox.Show("Please select a subject from the list"); return; } ListEl listEl = listOfListEls[listBox.SelectedIndex]; CreateUpdateWindow window = new CreateUpdateWindow(); window.Title = "Modify"; window.subjectTextBlock.Text = listEl.SubjectName; window.deadlineDatePicker.SelectedDate = listEl.Deadline; window.amountOfTopicsTextBlock.Text = listEl.AmountOfTopics.ToString(); window.numberOfDoneTopicsTextBlock.Text = listEl.NumberOfDoneTopics.ToString(); window.ShowDialog(); window.Owner = this; if (window.DialogResult == true) { string oldData = JsonConvert.SerializeObject(listEl.Data); listEl.SubjectName = window.subjectTextBlock.Text; listEl.Deadline = window.deadlineDatePicker.SelectedDate ?? DateTime.Now; listEl.AmountOfTopics = Convert.ToInt32(window.amountOfTopicsTextBlock.Text); listEl.NumberOfDoneTopics = Convert.ToInt32(window.numberOfDoneTopicsTextBlock.Text); DBExecutor.ModifyDBEntry(oldData, JsonConvert.SerializeObject(listEl.Data)); } }
private void AddListElement(int amountOfTopics, DateTime deadline, string subjectName, int numberOfDoneTopics) { ListEl listEl = new ListEl(listBox.ActualWidth, amountOfTopics, deadline, subjectName, numberOfDoneTopics); listOfListEls.Add(listEl); listBox.Items.Add(listEl.BaseGrid); DBExecutor.WriteToDB(JsonConvert.SerializeObject(listEl.Data)); }
static public void FillTheListFromDB(ref ListBox listBox, ref List <ListEl> listOfListEls) { using (StreamReader streamReader = new StreamReader(path)) { string line = ""; while ((line = streamReader.ReadLine()) != null) { ListEl listEl = new ListEl(listBox.ActualWidth, JsonConvert.DeserializeObject <ListElData>(line)); listOfListEls.Add(listEl); listBox.Items.Add(listEl.BaseGrid); } } }