Ejemplo n.º 1
0
        private bool Changed = false; //represent if table was changed

        public Table(TextConnection connection, string tableName)
        {
            TableName  = tableName;
            Connection = connection;
            Rows       = new List <string[]>();

            using (TextDataReader reader = new TextDataReader(connection, tableName))
            {
                Columns = reader.Columns;

                string[] row;
                int      i = 0;

                while (reader.Read())
                {
                    row = new string[Columns.Length];

                    foreach (string column in Columns)
                    {
                        row[i] = reader[column];
                        i++;
                    }

                    Rows.Add(row);
                    i = 0;
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            /*connection.DeleteTable("table2");
             * //string tableName1 = "table1";
             * //string[] columns1 = new string[] {"column1", "column2", "column3" };
             * //connection.CreateTable(tableName,columns);
             *
             * //string tableName2 = "table2";
             * //string[] columns2 = new string[] { "column1", "column2", "column3" };
             * //connection.CreateTable(tableName2, columns2);
             *
             * //string tableName3 = "table3";
             * string[] columns3 = new string[] { "column1", "column2", "column3", "column4" };
             * //connection.CreateTable(tableName3, columns3);
             *
             * Table table1 = connection.GetTable("table1");
             * //Table table2 = connection.GetTable("table2");
             * //Table table3 = connection.GetTable("table3");
             *
             * ////Console.WriteLine(table1.GetContent());
             * //Console.WriteLine(table1);
             * //Console.WriteLine();
             * //Console.WriteLine(table2);
             * //Console.WriteLine();
             * //Console.WriteLine(table3);
             * //Console.WriteLine();
             */

            //////////////////////////////////////////////////////////////////////////////////

            //simple example//

            TextConnection connection = new TextConnection(
                @"D:\USERS\Buhrii_B\C#\Програмне забезпечення\TextMS\TextMS\TextBase.txt");//path to file


            string[] newcolumns = new string[] { "newcolumn1", "newcolumn2", "newcolumn3" };
            connection.CreateTable("newtable", newcolumns);

            Table table = connection.GetTable("newtable");

            table.Create("inew1", "inew2", "inew3");
            table.Create("inew4", "inew5", "inew6");
            table.Create("inew7", "inew8", "inew9");

            table.Delete("newcolumn2", "inew5");
            Console.WriteLine(string.Join(" ", table.Read("newcolumn1", "inew7")[0]));

            table.ExecuteChanges();//used to save changes to textbase

            Console.WriteLine("done");
            Console.Read();
        }
Ejemplo n.º 3
0
        public TextDataReader(TextConnection connection, string tableName)
        {
            this.Connection = connection;
            streamReader    = new StreamReader(connection.ConnectionString);

            string line = "";

            while (line != string.Format("<{0}>", tableName))
            {
                line = streamReader.ReadLine();
            }
            if (streamReader.EndOfStream)
            {
                throw new Exception(string.Format("Table \"{0}\" not found",
                                                  tableName));
            }
            else
            {
                Columns = streamReader.ReadLine().Split(connection.separator[0]);
            }
        }