/// <summary> /// Изменение ячейки в таблице /// </summary> /// <param name="e"></param> private EditCellSudoku DataGridSudoku_CellEditEnding(DataGridCellEditEndingEventArgs e) { TextBox cell = (TextBox)e.EditingElement; EditCellSudoku editCellSudoku = null; if (!(e.EditAction == DataGridEditAction.Cancel)) { if (cell.Text.Length > 1) { MessageBox.Show("Не символ"); return(editCellSudoku); } char k; if (cell.Text.Length == 0) { k = ' '; } else { k = cell.Text[0]; } //TODO: это объединить editCellSudoku = new EditCellSudoku(e.Row.GetIndex(), e.Column.DisplayIndex, k); } return(editCellSudoku); }
/// <summary> /// Изменение таблицы судоку по данным /// </summary> /// <param name="editCellSudoku"></param> public void ResetTableSudoku(EditCellSudoku editCellSudoku) { DataGridSudoku.BeginInit(); if (editCellSudoku != null) { ((ItemCellSudoku)dataTableSudoku.Rows[editCellSudoku.Row][editCellSudoku.Column]).ResetItem(editCellSudoku.Simbol); for (int row = 0; row < dataTableSudoku.Rows.Count; row++) { for (int column = 0; column < dataTableSudoku.Columns.Count; column++) { var item = ((ItemCellSudoku)dataTableSudoku.Rows[row][column]); } } List <char> AllSimbols = new List <char>(); for (char ch = '1'; ch < '1' + 9; ch++) { AllSimbols.Add(ch); } foreach (var listItemSudoku in ListItemSudokus) { foreach (var simbol in AllSimbols) { ListItemSudoku listItemSudokus = new ListItemSudoku(); List <ItemSudoku> itemSudokus = new List <ItemSudoku>(); foreach (var itemSudoku in listItemSudoku.ItemSudokus) { var item = itemSudoku; if (item.ItemCellSudoku.Can.Contains(simbol)) { itemSudokus.Add(item); } } listItemSudokus.ItemSudokus = itemSudokus; var k = ListItemSudokus.Where(x => x.Contains(listItemSudokus)).ToList(); if (itemSudokus != null && k.Count > 1 && itemSudokus.Count > 0) { //Которые надо изменить var kk = k.Select(x => x.ItemSudokus.Where(y => !itemSudokus.Contains(y)).ToList()).ToList(); foreach (var item1 in kk) { foreach (var item2 in item1) { item2.ItemCellSudoku.Can.Remove(simbol); } } } } } } DataGridSudoku.EndInit(); }
/// <summary> /// чтение из файла /// </summary> /// <param name="sourseFile">путь к файлу</param> private void FillFile(string sourseFile) { string line; StreamReader file = new StreamReader(sourseFile); int lineNumber = 0; while ((line = file.ReadLine()) != null) { var temp = line.Split(';'); DataRow dataRow = dataTableSudoku.NewRow(); for (int j = 0; j < dataTableSudoku.Columns.Count; j++) { if (temp[j].Length > 1) { throw new ArgumentException("Не символ"); } else { char k; if (temp[j].Length == 0) { k = ' '; } else { k = temp[j][0]; } //TODO: это объединить var editCellSudoku = new EditCellSudoku(lineNumber, j, k); ResetTableSudoku(editCellSudoku); //((ItemCellSudoku)dataTableSudoku.Rows[lineNumber][j]).ResetItem(k); } } lineNumber++; } }