public async void showAsEdit(Entry newEntry) { this.clearAll(); this.Show(); synchroniseCategory(); Category tempCat; tempCat = await categoryRepository.FindbyId(newEntry.CategoryId); editFlag = true; editEntry = newEntry; textBoxName.Text = newEntry.Name; textBoxCategory.Text = tempCat.Name; textBoxLocation.Text = newEntry.Location; }
private async void buttonCopy_Click(object sender, EventArgs e) { Entry toCopy = listBox1.SelectedItem as Entry; Entry newEntry = new Entry(); if (toCopy == null) { return; } newEntry.Name = toCopy.Name; newEntry.CategoryId = toCopy.CategoryId; newEntry.Location = toCopy.Location; entryRepository.Add(newEntry); await UpdateEntryDataSource(); }
private async void buttonSave_Click(object sender, EventArgs e) { Category tempCat; if (editFlag == true) { if (textBoxName.Text.Trim() == "") { labelError.Show(); return; } if (textBoxLocation.Text.Trim() == "") { labelError.Show(); return; } if (textBoxCategory.SelectedItem == null) { if (textBoxCategory.Text.Trim() == "") { labelError.Show(); return; } tempCat = new Category(Name = textBoxCategory.Text); categoryRepository.Add(tempCat); } else { tempCat = (textBoxCategory.SelectedItem as Category); } editEntry.Name = textBoxName.Text; editEntry.CategoryId = tempCat.Id; editEntry.Location = textBoxLocation.Text; editFlag = false; entryRepository.Update(editEntry); await myTextboxMain.UpdateEntryDataSource(); this.Hide(); this.clearAll(); } else { if (textBoxName.Text.Trim() == "") { labelError.Show(); return; } if (textBoxCategory.Text == "") { labelError.Show(); return; } if(textBoxCategory.SelectedItem == null) { if(textBoxCategory.Text.Trim() == "") { labelError.Show(); return; } tempCat = new Category(Name = textBoxCategory.Text); categoryRepository.Add(tempCat); } else { tempCat = (textBoxCategory.SelectedItem as Category); } Entry newEntry = new Entry { Name = textBoxName.Text, CategoryId = tempCat.Id, Location = textBoxLocation.Text }; entryRepository.Add(newEntry); await myTextboxMain.UpdateEntryDataSource(); this.Hide(); this.clearAll(); } }