private void LoadSudoku_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Sudoku File(*.sudoku) | *.sudoku"; if (open.ShowDialog() == DialogResult.OK) { ClearSudoku(); history.ClearHistoryAfter(1); HistoryJson historyJson = JsonConvert.DeserializeObject <HistoryJson>(File.ReadAllText(open.FileName)); List <CageJson> BackCell = historyJson.LastMoveHistory; foreach (CageJson c in BackCell) { if (c.Number != 0 || c.TempNumbers.Count > 0 || c.BackColor != Color.LavenderBlush) { Cage cg = Cell.OfType <Cage>().Where(a => a.NumName == c.NumName).First(); cg.Number = c.Number; c.TempNumbers.ForEach(a => cg.AddTempNumber(a)); cg.BackColor = c.BackColor; cg.ForeColor = c.ForeColor; cg.NumName = c.NumName; cg.IsTempColor = c.IsTempColor; } } Move = historyJson.Move; lbMove.Text = $"{Move}"; if (historyJson.LastActiveCage_NumName != 0) { history.LastActiveCage.Add(Cell.OfType <Cage>().Where(a => a.NumName == historyJson.LastActiveCage_NumName).FirstOrDefault()); ActiveButton = history.GetLastActiveCage(false); ActiveButton.BackColor = Color.HotPink; } IsSimilarActive = historyJson.IsSimilarActive; Similar_Click(null, null); IsCageGridActive = historyJson.IsCageGridActive; CageGrid_Click(null, null); IsErrorActive = historyJson.IsErrorActive; Error_Click(null, null); } }
//SETTINGS private void SaveSudoku_Click(object sender, EventArgs e) { SaveFileDialog save = new SaveFileDialog(); save.Filter = "Sudoku File(*.sudoku) | *.sudoku"; if (save.ShowDialog() == DialogResult.OK) { HistoryJson historyJson = new HistoryJson(); foreach (Cage c in Cell) { if (c.Number != 0 || c.TempNumbers.Count > 0 || c.BackColor != Color.LavenderBlush) { historyJson.LastMoveHistory.Add(new CageJson() { Number = c.Number, TempNumbers = c.TempNumbers.Select(a => a.Number).ToList(), IsTempColor = c.IsTempColor, BackColor = c.BackColor, ForeColor = c.ForeColor, NumName = c.NumName, }); } } if (ActiveButton != null) { historyJson.LastActiveCage_NumName = ActiveButton.NumName; } else { historyJson.LastActiveCage_NumName = 0; } historyJson.IsCageGridActive = IsCageGridActive; historyJson.IsErrorActive = IsErrorActive; historyJson.IsSimilarActive = IsSimilarActive; historyJson.Move = Move; String obj = JsonConvert.SerializeObject(historyJson); File.WriteAllText(save.FileName, obj); } }