Ejemplo n.º 1
0
        public void test_read_excel_should_report_missing_column_error()
        {
            ExcelDataReader <InvoiceData> processor = new ExcelDataReader <InvoiceData>();

            processor.Source = this.getFilePath("invoice_missing_column.xlsx");
            var process_result = processor.ReadData();

            Assert.IsFalse(process_result);
            Assert.AreEqual(0, processor.Data.Count());
            Assert.AreEqual(1, processor.Errors.Count);

            Assert.AreEqual("column Circuit Name is not found", processor.Errors[0].GetError("Circuit Name").Message);
        }
Ejemplo n.º 2
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            Thread t = new Thread(() =>
            {
                using (var openFileDialog = new OpenFileDialog())
                {
                    openFileDialog.CheckFileExists = true;
                    openFileDialog.Multiselect     = false;
                    openFileDialog.Filter          = @"Excel Files|*.xls;*.xlsx";
                    openFileDialog.Title           = "Select Excel File With Data";
                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        var fileName = openFileDialog.FileName;
                        //todo add Unity Container
                        using (IDataReader excelDataReader = new ExcelDataReader())
                        {
                            if (excelDataReader is INotifyChanges)
                            {
                                ((INotifyChanges)excelDataReader).SendNotification += SendNotification;
                            }
                            excelDataReader.ReaderDetails = fileName;
                            var response = excelDataReader.ReadData();

                            if (response.Success)
                            {
                                WritePlayers(response.ReturnValue as IEnumerable <PlayersGroup>);
                                SendNotification(null, "Work Completed.");
                            }
                            else
                            {
                                foreach (var exception in response.Errors)
                                {
                                    Logger.Error(exception);
                                }
                                SendNotification(null,
                                                 string.Format(Resources.SplashForm_Errors_Log, response.Errors.Count));
                            }
                        }
                    }
                    SystemSounds.Beep.Play();
                    Thread.Sleep(500);
                    MainForm.Finished = true;
                }
            });

            t.IsBackground = true;
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }
Ejemplo n.º 3
0
        public void test_read_excel_should_report_data_errors()
        {
            ExcelDataReader <InvoiceData> processor = new ExcelDataReader <InvoiceData>();

            processor.Source = this.getFilePath("invoice_invalid_data.xlsx");
            var process_result = processor.ReadData();

            Assert.IsFalse(process_result);
            Assert.AreEqual(4, processor.Data.Count());
            Assert.AreEqual(1, processor.Errors.Count);

            var error = processor.Errors[0];

            Assert.AreEqual(3, error.Count);
            Assert.AreEqual("unable to convert 'today' to datetime value", error.GetError("Invoice From").Message);
            Assert.AreEqual("unable to convert 'tomorrow' to datetime value", error.GetError("Invoice To").Message);
            Assert.AreEqual("unable to convert '300 Million' to number value", error.GetError("Termination Charge").Message);
        }
Ejemplo n.º 4
0
        public void test_read_excel_should_success()
        {
            ExcelDataReader <InvoiceData> processor = new ExcelDataReader <InvoiceData>();

            processor.Source = this.getFilePath("invoice.xlsx");
            var process_result = processor.ReadData();

            Assert.IsTrue(process_result);
            Assert.AreEqual(5, processor.Data.Count());
            Assert.AreEqual(5, processor.TotalRecords);

            var first_row = processor.Data.First();

            Assert.AreEqual("Circuit #1", first_row.CircuitName);
            Assert.AreEqual("CNY", first_row.CurrencyCode);
            Assert.AreEqual("2019-08-01 00:00:00", first_row.BillingPeriod.ToString("yyyy-MM-dd HH:mm:ss"));
            Assert.AreEqual(360.33, first_row.TerminationCharge);
            Assert.AreEqual(4000.56m, first_row.AccessInstallationCharge);
            Assert.AreEqual(872.18m, Math.Round(first_row.VAT, 2));
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            //var configLoader = new AttributeConfigurationLoader();
            var configLoader = new XmlConfigurationLoader("configs\\test.config.xml");
            var reader       = new ExcelDataReader("testdata.xlsx", configLoader);

            try
            {
                var users = reader.ReadData <User>();

                foreach (var u in users)
                {
                    Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", u.ID, u.Name, u.Age, u.Email, u.Birthday);
                }
            }
            catch (DataReaderException ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
Ejemplo n.º 6
0
 private void GenerateRang(object sender, DoWorkEventArgs e)
 {
     _range = ExcelDataReader.ReadData(_webGraphExcelFile);
 }