private void Delete_Click(object sender, RoutedEventArgs e) { var et = new RememberUtility.Model.Entertainment(); // txtEtName if (txtEtName.Text != "") { et.EnterName = txtEtName.Text; } else { AddEtResult.Foreground = Brushes.Red; AddEtResult.Content = "Et name cannot be null. Please choose a type"; } if (txtEtName.Text == "") { AddEtResult.Foreground = Brushes.Red; AddEtResult.Content = "You must input Et name"; } else // has input { var findEt = entertainmentUtil.FindEntertainmentBy(txtEtName.Text); if (findEt != null) { if (et.EnterName.ToLower() == findEt.EnterName.ToLower()) { if (MessageBox.Show($"Found '{txtEtName.Text}'." + $" Do you wanna delete '{txtEtName.Text}'", "Confirm delete", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { entertainmentUtil.DeleteEntertainment(et.EnterName); AddEtResult.Foreground = Brushes.Green; AddEtResult.Content = $"Delete '{txtEtName.Text}' Successful"; txtEtName.Text = string.Empty; txtLink.Text = string.Empty; txtAuthorEnter.Text = string.Empty; lstListEtCategory.Text = string.Empty; } else { AddEtResult.Foreground = Brushes.YellowGreen; AddEtResult.Content = $"Delete operate was canceled."; } } } // input and not found else { AddEtResult.Foreground = Brushes.Red; AddEtResult.Content = $" Cannot find '{txtEtName.Text}'. Delete failed."; } } }
private void btnFind_Click(object sender, RoutedEventArgs e) { entertainment = EntertainmentUtil.FindEntertainmentBy(txtUpdateEtName.Text); if (entertainment != null) { lblResult.Foreground = Brushes.Green; lblResult.Content = $"Found '{entertainment.EnterName}'."; txtUpdateEtName.Text = entertainment.EnterName; txtLink.Text = entertainment.Links; txtAuthorEnter.Text = entertainment.AuthorEnter; cbbListEtUpdateCategory.Text = entertainment.Category; btnUpadte.IsEnabled = true; } else { lblResult.Foreground = Brushes.Red; lblResult.Content = $"Nothing found."; } }
public UpdateEt() { LoggerUtil.HandleLogPath(); InitializeComponent(); EntertainmentUtil = new EntertainmentUtil(); entertainment = new RememberUtility.Model.Entertainment(); WindowStartupLocation = WindowStartupLocation.CenterScreen; Application.Current.ShutdownMode = ShutdownMode.OnLastWindowClose; // Disable resize ResizeMode = ResizeMode.CanMinimize; var listConstantValue = typeof(CategoriesEntertainmentConstant).GetAllPublicConstantValues <string>(); listConstantValue.Sort(); cbbListEtUpdateCategory.ItemsSource = listConstantValue; txtUpdateEtName.IsEnabled = true; txtLink.IsEnabled = true; btnUpadte.IsEnabled = false; }
private void Add_Click(object sender, RoutedEventArgs e) { var et = new RememberUtility.Model.Entertainment(); // txtEtName if (txtEtName.Text != "") { et.EnterName = txtEtName.Text.Trim(); } else { AddEtResult.Foreground = Brushes.Red; AddEtResult.Content = "et name cannot be null. Please choose a type"; } // txtLink if (txtLink.Text != "") { et.Links = txtLink.Text.Trim(); } else { AddEtResult.Foreground = Brushes.Red; AddEtResult.Content = "Links cannot be null. Please choose a type"; } // txtAuthorEnter if (txtAuthorEnter.Text != "") { et.AuthorEnter = txtAuthorEnter.Text.Trim(); } else { AddEtResult.Foreground = Brushes.Red; AddEtResult.Content = "Author Enter cannot be null. Please choose a type"; } if (lstListEtCategory.SelectedIndex == -1) { AddEtResult.Foreground = Brushes.Red; AddEtResult.Content = "Category aren't choose. Please choose a type"; } if (txtLink.Text != "" && txtEtName.Text != "" && txtAuthorEnter.Text != "" && lstListEtCategory.SelectedIndex >= 0) { dynamic categoryInList = (lstListEtCategory.SelectedItem); string catchCustom = categoryInList as string; if (catchCustom.ToString() == CategoriesEntertainmentConstant.Custom) { if (txtBtnCustomTextBox.Text == "") { AddEtResult.Foreground = Brushes.Red; AddEtResult.Content = "Category custom is emtpy. Please pick one."; return; } else { et.Category = txtBtnCustomTextBox.Text; } } else { // use dynamic as type to cast your anonymous object to categoryInList = (lstListEtCategory.SelectedItem); // add category here et.Category = categoryInList as string; } var findet = entertainmentUtil.FindEntertainmentBy(txtEtName.Text); if (findet != null) { if (et.EnterName.ToLower() != findet.EnterName.ToLower()) { entertainmentUtil.AddEntertainment(et); AddEtResult.Foreground = Brushes.Green; if (et.EnterName.Length <= 10) { AddEtResult.Content = $"Add '{et.EnterName}' Successful"; } else { AddEtResult.Content = $"Add et Successful"; } txtEtName.Text = string.Empty; txtLink.Text = string.Empty; txtAuthorEnter.Text = string.Empty; lstListEtCategory.Text = string.Empty; } else { AddEtResult.Foreground = Brushes.Red; AddEtResult.Content = $"'{txtEtName.Text}' duplicate. Add failed."; } } else { entertainmentUtil.AddEntertainment(et); AddEtResult.Foreground = Brushes.Green; AddEtResult.Content = "Add et Successful"; txtEtName.Text = string.Empty; txtLink.Text = string.Empty; txtAuthorEnter.Text = string.Empty; lstListEtCategory.Text = string.Empty; } } }