private void ImportListAndAddClick(object sender, RoutedEventArgs e) { var dialog = new OpenFileDialog { Filter = "All file|*.*|JPEG file (.jpg)|*.jpg|PNG file (.png)|*.png|Bitmap file (.bmp)|*.bmp", Multiselect = true }; if (dialog.ShowDialog() != true) { return; } bool addQuestionMark = NewGameItem.GameName == Constant.GameConstant.TalkInMinute; foreach (var fileName in dialog.FileNames) { //NewGameItem GameItems.Add(new GameItem { GameName = NewGameItem.GameName, Topic = NewGameItem.Topic, Title = Path.GetFileNameWithoutExtension(fileName) + (addQuestionMark ? "?" : string.Empty), Image = ConvertHelper.ImageToByte(fileName) }); } FileManagement.SaveListGameData(GameItems); RaiseInformMessage("Data has been imported successfully"); //Re-load data NewGameItem.Title = Path.GetFileNameWithoutExtension(dialog.FileNames[0]) + (addQuestionMark ? "?" : string.Empty); LoadData(); }
private void SaveGaveItemClick(object sender, RoutedEventArgs e) { //Validate data string message; if (!IsValidate(out message)) { RaiseInformMessage(message); return; } // Add new or update switch (_currentAction) { case ActionState.Add: GameItems.Add(NewGameItem); FileManagement.SaveListGameData(GameItems); RaiseInformMessage("Data has been added successfully"); break; case ActionState.Update: UpdateProperty(SelectedGameItem, UpdateGameItem); FileManagement.SaveListGameData(GameItems); RaiseInformMessage("Data has been saved successfully"); break; } //Re-load data LoadData(); }
private void DeleteGameItemClick(object sender, RoutedEventArgs e) { if (GameItems == null || GameItems.Count < 1 || SelectedGameItem == null) { MessageBox.Show("No selected item to delete", "Delete", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (MessageBox.Show("Are you sure to delete selected item?", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { GameItems.Remove(SelectedGameItem); FileManagement.SaveListGameData(GameItems); //Re-load data LoadData(); } }
private void LoadData() { //Backup update item var backup = new GameItem(); if (_currentAction == ActionState.Update) { backup = EnglishGameHelper.CloneItem(UpdateGameItem); } //Get new list items GameItems = FileManagement.GetListGameData(); IntializeGroupData(); DataGridGameItem.UpdateLayout(); //Show data if (GameItems.Count > 0) { switch (_currentAction) { case ActionState.Add: SelectedGameItem = GameItems.First(x => x.Title == NewGameItem.Title && x.GameName == NewGameItem.GameName); break; case ActionState.Update: SelectedGameItem = GameItems.First(x => x.Title == backup.Title && x.GameName == backup.GameName); break; default: SelectedGameItem = GameItems[0]; break; } _currentAction = ActionState.Update; EditorTitle.Text = "Selected item detail"; ViewDetailItem.DataContext = UpdateGameItem; } else { AddNewGameItemClick(null, null); } CanCloneAndDeleteVisibility = GetCloneAndDeleteVisibility(); }
private void BackupGameItemClick(object sender, RoutedEventArgs e) { RaiseInformMessage("Data has been backup successfully in " + FileManagement.SaveBackupData(GameItems)); }
public static T CloneItem <T>(T obj) { return(FileManagement.FromXmlString <T>(FileManagement.ToXmlString(obj))); }