void InitTables() { myDS = new DataSet(); myDS.EnforceConstraints = false; string columnlist = QueryCreator.SortedColumnNameList(SourceTable); Added = Conn.CreateTableByName(tablename, columnlist); Added.TableName = "added"; Added.Namespace = SourceTable.Namespace; myDS.Tables.Add(Added); DataAccess.SetTableForReading(Added, tablename); CopyKeyWhenBlank(SourceTable, Added); ToAdd = Conn.CreateTableByName(tablename, columnlist); ToAdd.TableName = "toadd"; myDS.Tables.Add(ToAdd); DataAccess.SetTableForReading(ToAdd, tablename); CopyKeyWhenBlank(SourceTable, ToAdd); //Riempie la Table delle righe "ToAdd" prendendole dal DB. Questa tabella // contiene anche righe già "added" in memoria, che vanno quindi escluse. //Inoltre va integrata con righe che erano "added" e sono state rimosse // in memoria DataAccess.RUN_SELECT_INTO_TABLE(Conn, ToAdd, sorting, filterSQL, null, true); //Riempie la Table delle righe "Added". Questa contiene anche righe che sono // state rimosse in memoria, e quindi vanno rimosse (e integrate a "ToAdd") QueryCreator.MergeDataTable(Added, SourceTable); //Per tutte le righe rimosse in memoria (che rispettano il filtro): le toglie da // Added e le mette in ToAdd. string tomovefilter = GetData.MergeFilters(notentitychildfilter, filter); DataRow[] RowsToMove = Added.Select(tomovefilter); foreach (DataRow ToMove in RowsToMove) { string verifyexistentfilter = QueryCreator.WHERE_KEY_CLAUSE(ToMove, DataRowVersion.Default, false); //Just for sure I remove from ToAdd those rows I'm going to add to it! DataRow[] ToRemoveFromToAdd = ToAdd.Select(verifyexistentfilter); foreach (DataRow ToRemFromToAdd in ToRemoveFromToAdd) { ToRemFromToAdd.Delete(); ToRemFromToAdd.AcceptChanges(); } //Adds the row to ToAdd AddRowToTable(ToAdd, ToMove); //Remove the row from Added ToMove.Delete(); if (ToMove.RowState != DataRowState.Detached) { ToMove.AcceptChanges(); } } //Per tutte le righe rimosse in memoria rimanenti (ossia che NON rispettano // il filtro) : le rimuovo da Added DataRow[] ToRemoveFromAdded = Added.Select(notentitychildfilter); foreach (DataRow ToRemFromAdded in ToRemoveFromAdded) { ToRemFromAdded.Delete(); if (ToRemFromAdded.RowState != DataRowState.Detached) { ToRemFromAdded.AcceptChanges(); } } //Per tutte le righe rimaste in Added: le rimuove da ToAdd DataRow[] ToRemoveFromToAdd2 = Added.Select(); foreach (DataRow ToRemFromToAdd in ToRemoveFromToAdd2) { string ToRemKeyFilter = QueryCreator.WHERE_KEY_CLAUSE(ToRemFromToAdd, DataRowVersion.Default, false); DataRow[] ToRemove = ToAdd.Select(ToRemKeyFilter); foreach (DataRow ToRem in ToRemove) { ToRem.Delete(); if (ToRem.RowState != DataRowState.Detached) { ToRem.AcceptChanges(); } } } MetaData M = linked.Dispatcher.Get(tablename); M.DescribeColumns(ToAdd, listingtype); M.DescribeColumns(Added, listingtype); HT["Added"] = Added; HT["ToAdd"] = ToAdd; SetDataTable(ToAdd, GridToAdd); SetDataTable(Added, GridAdded); }
// Сформувати послідовність дій і записати в текстовий документ private List<string> MakeSolvePath(Stack<State> path) { List<string> AllMoves = new List<string>(); StringBuilder temp = new StringBuilder(4); State FirstState = path.Pop(); int SpaceIndexFirst = 0, SpaceIndexSecond = 0, ToMove; int[] firstArr, secondArr; while (path.Count > 0) { firstArr = FirstState.GetStateCodeArr(); FirstState = path.Pop(); secondArr = FirstState.GetStateCodeArr(); for (int j = 0; j < 16; j++) { if (firstArr[j] == -1) SpaceIndexFirst = j; if (secondArr[j] == -1) SpaceIndexSecond = j; } ToMove = secondArr[SpaceIndexFirst]; temp.Append(ToMove.ToString() + ","); ToMove = SpaceIndexFirst - SpaceIndexSecond; switch (ToMove) { case -1: { temp.Append(DirectionSymbol.Left); break; } case 1: { temp.Append(DirectionSymbol.Right); break; } case 4: { temp.Append(DirectionSymbol.Down); break; } case -4: { temp.Append(DirectionSymbol.Up); break; } } AllMoves.Add(temp.ToString()); temp.Clear(); } StreamWriter str = new StreamWriter("Solver.txt"); for (int i = 0; i < AllMoves.Count; i++) { str.WriteLine(AllMoves[i]); } str.Close(); return AllMoves; }