Beispiel #1
0
        public void ReadFile2DB(long iterations = 10, int progressLength = 20) //to do multiple versions
        {
            MyDataBase dtb  = new MyDataBase();
            var        db   = dtb.db;
            var        Cols = db.Tables[0].Columns.Cast <DataColumn>().Where(x => x.ColumnName != "id").Select(y => y.ColumnName).ToList();
            //var Cols = (from dc in db.DataTable1.Columns.Cast<DataColumn>()
            //            where dc.ColumnName != "id"
            //             select dc.ColumnName).ToList();

            //Cols.ForEach(Console.WriteLine);
            string line;

            MyWatch t = new MyWatch();

            using (StreamReader sr = new StreamReader(myFn))
            {
                int       i           = 1;
                MyProgBar progressBar = new MyProgBar(iterations, progressLength);
                progressBar.Init();

                while ((line = sr.ReadLine()) != null)
                {
                    progressBar.Step(i++);
                    List <string> newDataRow = line.Split(',').Take(6).ToList();
                    newDataRow = newDataRow.Select(s => s.Replace('.', ',')).ToList(); //Double

                    DataRow dr = db.Tables[0].NewRow();
                    Cols.ForEach(x => dr[x.ToString()] = newDataRow[Cols.IndexOf(x.ToString())]);
                    db.Tables[0].Rows.Add(dr);
                }
            }

            t.StopAndPrint();
        }
Beispiel #2
0
        public void Write2File(long iterations = 10, int progLength = 20)
        {
            MyWatch     t           = new MyWatch();
            GenerateCSV generateCSV = new GenerateCSV();

            t.Start();

            using (StreamWriter sw = new StreamWriter(myFn))
            {
                string    line;
                MyProgBar progressBar = new MyProgBar(iterations, progLength);
                progressBar.Init();

                for (int i = 1; i <= iterations; i++)
                {
                    progressBar.Step(i);
                    line = generateCSV.GenerateLine();
                    sw.WriteLine(line);
                }
            }
            t.StopAndPrint();
        }