Ejemplo n.º 1
0
        private void BtnCsvImport_Click(object sender, RoutedEventArgs e)
        {
            pbStatus.Visibility = Visibility.Visible;

            var remainingRecords = new List <DynamicCsv>();

            remainingRecords.AddRange(RecordsToInsert);
            var insertedRecordsNumber = 0;
            var updatedRecordsNumber  = 0;

            while (remainingRecords.Count > 0)
            {
                var result = CsvWriterCustom.WriteToDatabase(remainingRecords, 10);
                insertedRecordsNumber        += result.NewlyInsertedRecordsCount;
                insertedRecordsCount.Content  = "Inserted:" + insertedRecordsNumber;
                updatedRecordsNumber         += result.UpdatedRecordsCount;
                updatedDbRecordsCount.Content = "Updated:" + updatedRecordsNumber;
                remainingRecords = result.RemainingRecords;

                pbStatus.Value = (insertedRecordsNumber / RecordsToInsert.Count()) * 100;
            }
        }
Ejemplo n.º 2
0
        /*
         * static void Main(string[] args)
         * {
         * PromptUser();
         *
         * }
         */

        private static void PromptUser()
        {
            Console.WriteLine("Paste/Type File Path:");
            var filePath = Console.ReadLine();

            Console.WriteLine("Number of columns in CSV file :");
            var numberOfColumns = int.Parse(Console.ReadLine());

            Console.WriteLine("Does CSV file have header (column names) ?  Y/N :");
            var hasHeader = Console.ReadLine() == "Y" ? true : false;

            Console.WriteLine("Test if it works or copy to database ?  TEST/COPY :");
            var testOnly = Console.ReadLine() == "TEST" ? true : false;

            Console.WriteLine("Max records at once (max 1000) ?  TEST/COPY :");
            var inputedRecords   = int.Parse(Console.ReadLine());
            var maxRecordsAtOnce = inputedRecords > 1000 ? inputedRecords : 1000;

            var csvParams = new CsvSetupParams()
            {
                FilePath        = filePath,
                NumberOfColumns = numberOfColumns,
                HasHeader       = hasHeader,
                TestOnly        = testOnly
            };

            var csvTouple = CsvReaderCustom.ReadByType(csvParams);

            if (testOnly)
            {
                CsvWriterCustom.WriteToConsole(csvTouple.csvList);
            }
            else
            {
                CsvWriterCustom.WriteToDatabase(csvTouple.csvList, maxRecordsAtOnce);
            }
        }