/// <summary> /// Menu option "File->Load From File" to load an exisitng sudoku. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MnuLoadFromFile_Click(object sender, RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Data Files|*.dat"; ofd.Title = "Open Sudoku Board"; ofd.InitialDirectory = saveDir.FullName; bool?result = ofd.ShowDialog(); if (result == true) { string openPath = ofd.FileName; if (File.Exists(openPath)) { using (FileStream board = new FileStream(openPath, FileMode.Open, FileAccess.Read)) { try { var serializer = new XmlSerializer(typeof(Board)); sudoku = new Board(((Board)serializer.Deserialize(board))); ResetInterface(null); sudoku.CheckIfSolved(); } catch (Exception exc) { MessageBox.Show($"Error while loading file: {exc.Message}"); } } } } }
/// <summary> /// Menu option "File->Load" to load selected progress from the list. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MnuLoad_Click(object sender, RoutedEventArgs e) { if (listCurrentSaves.SelectedItem != null && currentSessionSudokuList[listCurrentSaves.SelectedIndex].Item1.ID != sudoku.ID) { var item = currentSessionSudokuList[listCurrentSaves.SelectedIndex]; sudoku = item.Item1; ResetInterface(item.Item2); sudoku.CheckIfSolved(); } }