public void Save() { Console.WriteLine("Saving the base..."); for (int j = 0; j < CountOfTables; j++) { using (FileStream fstream = new FileStream($"{Name.GetString()} {tables[j].Name.GetString()}.txt", FileMode.OpenOrCreate)) { MyString str = new MyString(); MyList <Row> rows = GetRows(tables[j].Name); for (int i = 0; i < rows.Size; i++) { if (!rows[i].IsConnected) { str += rows[i].Data[0] + new MyString(' '); } else { str += rows[i].Data[0] + new MyString('[') + GetNameOfTable(rows[i].NumberTableToConnect) + new MyString(',') + new MyString(rows[i].NumberFieldToConnect) + new MyString(']') + new MyString(' '); } } str += new MyString('\n'); for (int k = 1; k < rows[0].Data.Size; k++) { for (int i = 0; i < rows.Size; i++) { str += rows[i].Data[k] + new MyString(' '); } str += new MyString('\n'); } str = str.Substring(0, str.Length - 2); byte[] array = System.Text.Encoding.Default.GetBytes(str.GetString()); fstream.Write(array, 0, array.Length); } } Console.WriteLine("Done."); }
public void Open(MyString name) { for (int i = 1; i <= CountOfTables; i++) { int countOfFields = 0; Console.Write($"Input name of {i} table: "); MyString nameTable = new MyString(Console.ReadLine().ToCharArray()); SetNameForTable(i - 1, nameTable); using (FileStream fstream = File.OpenRead($"{name.GetString()} {nameTable.GetString()}.txt")) { byte[] array = new byte[fstream.Length]; fstream.Read(array, 0, array.Length); char[] textFromFile = System.Text.Encoding.Default.GetChars(array); MyString text = new MyString(textFromFile); MyString[] parsingTable = text.Split(' '); for (int j = 0; j < parsingTable.Length; j++) { int index = parsingTable[j].IndexOf(new MyString('\n')); if (index >= 0) { if (countOfFields == 0) { countOfFields = j; for (int l = 0; l < countOfFields; l++) { AddField(nameTable, parsingTable[l]); } } parsingTable[j] = parsingTable[j].Replace(new MyString('\n'), new MyString('/')); } } ReadNotes(nameTable, countOfFields, parsingTable); } } ReadConnections(); }