当前位置: 首页>>代码示例>>C#>>正文


C# CsvReader.ReadRecord方法代码示例

本文整理汇总了C#中CsvReader.ReadRecord方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.ReadRecord方法的具体用法?C# CsvReader.ReadRecord怎么用?C# CsvReader.ReadRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsvReader的用法示例。


在下文中一共展示了CsvReader.ReadRecord方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImportSpareCodesFromCSV2

        private void ImportSpareCodesFromCSV2()
        {
            ConsoleManager.Show();
            Console.WriteLine(DateTime.Now.ToShortTimeString() + " - started...");
            string FilePath = "";
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = ".csv"; // Default file extension

            //    dlg.Filter = "*.csv"; // Filter files by extension
            Nullable<bool> result = dlg.ShowDialog();
            if (result == true)
            {
                DataAccess da = new DataAccess();

                // Open document
                FilePath = dlg.FileName;
                using (CsvReader csvData = new CsvReader(FilePath))
                {
                    csvData.Settings.Delimiter = ';';
                    while (csvData.ReadRecord())
                    {
                        da.SpareEdit(csvData.ReadToEnd());
                    }
                } // dispose of parser
            }
            Console.WriteLine(DateTime.Now.ToShortTimeString() + " - finished...");
            MessageBox.Show("Import finished!");
            Console.ReadLine();
            ConsoleManager.Hide();
            Application.Current.Shutdown();
        }
开发者ID:bashlykevich,项目名称:Bycar,代码行数:31,代码来源:MainWindow.xaml.cs

示例2: ImportSparesFromCSV

        private void ImportSparesFromCSV()
        {
            ConsoleManager.Show();
            Console.WriteLine(DateTime.Now.ToShortTimeString() + " - started...");
            string FilePath = "";
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = ".csv"; // Default file extension

            //    dlg.Filter = "*.csv"; // Filter files by extension
            Nullable<bool> result = dlg.ShowDialog();
            if (result == true)
            {
                DataAccess da = new DataAccess();

                // Open document
                FilePath = dlg.FileName;
                int counter = 0;
                int GlobalCnt = 0;
                using (CsvReader csvData = new CsvReader(FilePath))
                {
                    csvData.Settings.Delimiter = ';';
                    while (csvData.ReadRecord())
                    {
                        try
                        {
                            counter++;
                            GlobalCnt++;
                            string[] RawRecord = csvData.RawRecord.Split(';');
                            string GrandParentGroupName = RawRecord[0];
                            string ParentGroupName = RawRecord[1];
                            string BrandName = RawRecord[2];
                            string SpareCode = RawRecord[3];
                            string SpareName = RawRecord[4];
                            string CarModels = RawRecord[5];

                            if (!da.SpareExist(SpareCode, SpareName))
                            {
                                Console.WriteLine(GlobalCnt.ToString() + ": " + SpareName + " - " + SpareCode + " - creating");
                                da.SpareCreate(GrandParentGroupName, ParentGroupName, BrandName, SpareCode, SpareName, CarModels);
                            }
                            else
                            {
                                Console.WriteLine(GlobalCnt.ToString() + ": " + SpareName + " - " + SpareCode + " already exist");
                            }
                            if (counter > 1000)
                            {
                                counter = 0;
                                da = new DataAccess();
                                Console.WriteLine("Data access object refresh");
                            }
                        }
                        catch (Exception e1)
                        {
                            Console.WriteLine(GlobalCnt.ToString() + ": Exception failed: " + e1.Message);
                        }
                    }
                } // dispose of parser
            }
            Console.WriteLine(DateTime.Now.ToShortTimeString() + " - finished...");
            MessageBox.Show("Import finished!");
            Console.ReadLine();
            ConsoleManager.Hide();
            Application.Current.Shutdown();
        }
开发者ID:bashlykevich,项目名称:Bycar,代码行数:64,代码来源:MainWindow.xaml.cs

示例3: ImportSpareCodesFromCSV

        private void ImportSpareCodesFromCSV()
        {
            ConsoleManager.Show();
            Console.WriteLine(DateTime.Now.ToShortTimeString() + " - started...");
            string FilePath = "";
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = ".csv"; // Default file extension

            //    dlg.Filter = "*.csv"; // Filter files by extension
            Nullable<bool> result = dlg.ShowDialog();
            if (result == true)
            {
                DataAccess da = new DataAccess();

                // Open document
                FilePath = dlg.FileName;
                int counter = 0;
                int GlobalCnt = 0;
                using (CsvReader csvData = new CsvReader(FilePath))
                {
                    csvData.Settings.Delimiter = ';';
                    while (csvData.ReadRecord())
                    {
                        try
                        {
                            counter++;
                            GlobalCnt++;
                            string[] RawRecord = csvData.RawRecord.Split(';');
                            string CodeShatem = RawRecord[0];
                            string Code = RawRecord[1];

                            // delete chars after _
                            CodeShatem = CodeShatem.Split('_')[0];

                            if (da.SpareEdit(CodeShatem, Code))
                                Console.WriteLine(GlobalCnt.ToString() + ": " + CodeShatem + " ok!");
                            else
                                Console.WriteLine(GlobalCnt.ToString() + ": " + CodeShatem + " not found.");

                            if (counter > 1000)
                            {
                                counter = 0;
                                da = new DataAccess();
                                Console.WriteLine("Data access object refresh");
                            }
                        }
                        catch (Exception e1)
                        {
                            Console.WriteLine(GlobalCnt.ToString() + ": Exception failed: " + e1.Message);
                        }
                    }
                } // dispose of parser
            }
            Console.WriteLine(DateTime.Now.ToShortTimeString() + " - finished...");
            MessageBox.Show("Import finished!");
            Console.ReadLine();
            ConsoleManager.Hide();
            Application.Current.Shutdown();
        }
开发者ID:bashlykevich,项目名称:Bycar,代码行数:59,代码来源:MainWindow.xaml.cs


注:本文中的CsvReader.ReadRecord方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。