/// <summary>
        /// read the Csv File and fill the DataTable in the DataSet
        /// </summary>
        /// <param name="dataSet"></param>
        /// <param name="dataTableName"></param>
        /// <returns></returns>
        public int Fill(DataSet dataSet, string dataTableName = "Table")
        {
            DataTable dt = new DataTable(dataTableName);

            dataSet.Tables.Add(dt);

            int fieldCount = reader.FieldCount;

            string[] headers = reader.GetFieldHeaders();

            foreach (string s in headers)
            {
                dt.Columns.Add(s);
            }

            int nbRows = 0;

            while (reader.ReadNextRecord())
            {
                DataRow row = dt.NewRow();

                for (int i = 0; i < fieldCount; i++)
                {
                    row.SetField(headers[i], reader[i]);
                }
                dt.Rows.Add(row);
                nbRows++;
            }
            return(nbRows);
        }
Example #2
0
        public bool Read()
        {
            if (_canceled)
            {
                return(false);
            }

            if (_reader.ReadNextRecord())
            {
                _reader.CopyCurrentRecordTo(_array);
                for (int i = 0; i < _array.Length; i++)
                {
                    if (_dataFormat.IsNullString(_array[i]))
                    {
                        _values[i] = null;
                    }
                    else
                    {
                        _values[i] = _array[i];
                    }
                }
                return(true);
            }
            return(false);
        }
Example #3
0
        static void Main(string[] args)
        {
            //const string filePath = @"C:\Users\gchan\Documents\DBIO2\Performance\dumpfile.csv";

            if (args == null || args.Length == 0)
            {
                Console.WriteLine("The filename and client must be supplied");
            }
            else if (args.Length == 1)
            {
                Console.WriteLine("The client must be supplied");
            }
            else if (!IsCsvFile(args[0]))
            {
                Console.WriteLine($"The file supplied '{args[0]}' is not a valid CSV");
            }
            else
            {
                var csvFilename = args[0];
                var datasetName = Path.GetFileNameWithoutExtension(csvFilename);
                var mineSite    = args[1];

                if (DatasetExists(datasetName))
                {
                    Console.WriteLine($"The dataset '{datasetName}' has already been imported!");
                }
                else
                {
                    Console.WriteLine($"Starting reading file '{csvFilename}' for Mine Site '{mineSite}'...");

                    using (var csv = new LumenWorks.Framework.IO.Csv.CsvReader(new StreamReader(csvFilename), true))
                    {
                        //string[] headers = csv.GetFieldHeaders();
                        string[] headers = { "EventName", "Type", "EventId", "Version", "Channel", "Level" };

                        using (var table = new DataTable())
                        {
                            table.Columns.Add(headers[0], typeof(string));
                            table.Columns.Add(headers[1], typeof(string));
                            table.Columns.Add(headers[2], typeof(int));

                            // todo: add remaining here...

                            table.Columns.Add("MineSite", typeof(string));
                            table.Columns.Add("DatasetName", typeof(string));

                            while (csv.ReadNextRecord())
                            {
                                table.Rows.Add(csv[0], csv[1], csv[2], mineSite, datasetName);
                            }

                            BulkInsertDataTable("etw.DispatchEvent", table);

                            Console.WriteLine($"Finished importing {table.Rows.Count} rows for file '{csvFilename}'.");
                        }
                    }
                }
            }
        }
        // Declaration of ReadRecords Method
        /// <summary>
        /// Catches all type of exceptions generated.
        /// </summary>
        /// <param name="passHeader"></param>
        /// <param name="in_delimeter"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public object ReadRecords(string[] passHeader = null, char in_delimeter = ',', string filePath = null)
        {
            try
            {
                if (!filePath.Contains(".csv"))
                {
                    throw new CensusAnalyserException(CensusAnalyserException.ExceptionType.INVALID_EXTENSION_OF_FILE, "Invalid Extension of file");
                }
                else if (!filePath.Contains(actualPath))
                {
                    throw new CensusAnalyserException(CensusAnalyserException.ExceptionType.FILE_NOT_FOUND, "Invalid file");
                }

                // streams are used to read/write data from csv files
                //CsvReader is open source C# library to read CSV data from strings/textFiles

                CsvReader csvRecords = new CsvReader(new StreamReader(filePath), true);
                int       fieldCount = csvRecords.FieldCount;
                string[]  headers    = csvRecords.GetFieldHeaders();
                delimeter = csvRecords.Delimiter;

                // string ArrayList
                List <string[]> record = new List <string[]>();
                while (csvRecords.ReadNextRecord())
                {
                    string[] tempRecord = new string[fieldCount];
                    csvRecords.CopyCurrentRecordTo(tempRecord);
                    record.Add(tempRecord);
                    numberOfRecord++;
                }

                if (numberOfRecord == 0)
                {
                    throw new CSVException(CSVException.ExceptionType.FILE_IS_EMPTY, "This file does not contains any data");
                }
                if (!in_delimeter.Equals(delimeter))
                {
                    throw new CensusAnalyserException(CensusAnalyserException.ExceptionType.INCORRECT_DELIMETER, "Incorrect Delimeter");
                }
                else if (!IsHeaderSame(passHeader, headers))
                {
                    throw new CensusAnalyserException(CensusAnalyserException.ExceptionType.INVALID_HEADER_ERROR, "Invalid Header");
                }
                return(numberOfRecord);
            }
            catch (CensusAnalyserException file_not_found)
            {
                return(file_not_found.Message);
            }
            catch (CSVException emptyFileException)
            {
                return(emptyFileException.Message);
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
        //private void OnConfiguration(object sender, RoutedEventArgs e)
        //{

        //}

        private void OnImportInventory(object sender, RoutedEventArgs e)
        {
            OpenFileDialog diag = new OpenFileDialog();

            diag.Title           = "Select File for Import";
            diag.Filter          = "Comma Delimited|*.csv|All Files|*.*";
            diag.CheckFileExists = true;
            diag.CheckPathExists = true;
            diag.DefaultExt      = "csv";
            diag.Multiselect     = false;



            if (diag.ShowDialog() == true)
            {
                using (StreamReader sr = new StreamReader(diag.FileName))
                {
                    LumenWorks.Framework.IO.Csv.CsvReader csv = new LumenWorks.Framework.IO.Csv.CsvReader(sr, true);

                    int      fieldCount = csv.FieldCount;
                    string[] headers    = csv.GetFieldHeaders();

                    while (csv.ReadNextRecord())
                    {
                        ActiveInventoryObject Inv = new ActiveInventoryObject();

                        int i = 0;

                        Inv.UPC = csv[0];

                        Inv.Distributor = csv[1];
                        Inv.SKU         = csv[2];
                        Inv.Description = csv[3];
                        Inv.Category    = csv[4];
                        if (int.TryParse(csv[5], out i))
                        {
                            Inv.Quantity = i;
                        }


                        Inv.WholeSalePrice = Configuration.CurrencyToDecimal(csv[6]);


                        Inv.MSRP = Configuration.CurrencyToDecimal(csv[7]);


                        Inv.AdditionalOverhead = Configuration.CurrencyToDecimal(csv[8]);

                        Inv.DescriptionShort = Inv.Description;
                        Inv.Manufacturer     = csv[14];

                        Cache.Current.Inventory.Add(Inv);
                    }
                }
                MessageBox.Show("Process Complete.");
            }
        }
Example #6
0
        public string[] Next()
        {
            if (_reader.ReadNextRecord())
            {
                int fieldCount = _reader.FieldCount;
                var row        = new string[fieldCount];

                for (int i = 0; i < fieldCount; i++)
                {
                    row[i] = _reader[i];
                }

                return(row);
            }
            return(null);
        }
        public List <T> GetRecords <T>(MemoryStream stream) where T : ICsvReadable, new()
        {
            var activate   = ActivatorFactory.Create <T>(_activationMethod);
            var allRecords = new List <T>();

            using (var reader = new StreamReader(stream))
                using (var csvReader = new LumenWorks.Framework.IO.Csv.CsvReader(reader, hasHeaders: false))
                {
                    while (csvReader.ReadNextRecord())
                    {
                        var record = activate();
                        record.Read(i => csvReader[i]);
                        allRecords.Add(record);
                    }
                }

            return(allRecords);
        }
        private List<List<string>> ParseCsv(byte[] input, char delimiter = ',')
        {
            using (var ms = new MemoryStream(input))
            using (var csv = new LumenWorks.Framework.IO.Csv.CsvReader(new StreamReader(ms), false, delimiter))
            {
                var output = new List<List<string>>();
                while (csv.ReadNextRecord())
                {
                    var row = new List<string>();
                    for (int i = 0; i < csv.FieldCount; i++)
                    {
                        row.Add(csv[i]);
                    }

                    output.Add(row);
                }

                return output;
            }
        }
Example #9
0
        public static IEnumerable <TestCaseData> GetTestData()
        {
            var testCases = new List <TestCaseData>();

            using (var csv = new LumenWorks.Framework.IO.Csv.CsvReader(new StreamReader("C:\\Users\\base2\\Downloads\\csharpseleniumextentreportnetcoretemplate-master\\CSharpSeleniumLarissaBicalho\\input.csv", true)))
            {
                while (csv.ReadNextRecord())
                {
                    string categoria  = string.Format(csv[0]);
                    string frequencia = string.Format(csv[1]);
                    string gravidade  = string.Format(csv[2]);
                    string prioridade = string.Format(csv[3]);
                    string perfil     = string.Format(csv[4]);
                    string resumo     = string.Format(csv[5]);
                    string descricao  = string.Format(csv[6]);
                    var    testCase   = new TestCaseData(categoria, frequencia, gravidade, prioridade, perfil, resumo, descricao);

                    testCases.Add(testCase);
                }
            }

            return(testCases);
        }
Example #10
0
        static public void EnsemblSynteny()
        {
            Dictionary <int, String> species = App.LoadSpecies();
            String sSpecies = String.Join(", ", species.Values);

            App.Log("Converting Synteny Data for species <i>" + sSpecies + "</i>...");

            App.DB.OpenFast();
            App.DB.Exec("DELETE FROM speciesChromosomeEns");

            LumenWorks.Framework.IO.Csv.CsvReader csv = App.DB.OpenCsv(@"data\synteny\dnafrag.txt");

            while (csv.ReadNextRecord())
            {
                int genomeDbId = Convert.ToInt32(csv[3]);
                if (species.ContainsKey(genomeDbId))
                {
                    String type  = csv[4];
                    String isRef = csv[5];
                    if ((type == "chromosome") && (isRef == "1"))
                    {
                        String name      = csv[2];
                        long   dnafragId = Convert.ToInt64(csv[0]);

                        String sql = "INSERT INTO speciesChromosomeEns (genomeDbId, dnafragId, name) VALUES (" +
                                     genomeDbId.ToString() + "," + dnafragId.ToString() + ",'" + name + "')";
                        App.DB.Exec(sql);
                        App.Log("Inserted " + species[genomeDbId] + " chromosome " + name + "");
                    }
                }
            }

            App.Log("Done reading chromosomes");
            App.Log("");


            App.Log("Converting Synteny Regions...");

            App.DB.Exec("DELETE FROM syntenyEns");

            Dictionary <string, int> fields = new Dictionary <string, int>();

            fields.Add("syntenyRegionId", 0);
            fields.Add("dnafragId", 1);
            fields.Add("start", 2);
            fields.Add("end", 3);
            fields.Add("strand", 4);

            App.DB.ImportCsv(@"data\synteny\dnafrag_region.txt", "syntenyEns", fields);

            App.Log("");


            App.Log("Connecting Tables...");

            System.Data.Common.DbDataReader res =
                App.DB.Query("SELECT * FROM speciesChromosomeEns");
            while (res.Read())
            {
                long   dnafragId  = Convert.ToInt64(res["dnafragId"].ToString());
                int    genomeDbId = Convert.ToInt32(res["genomeDbId"].ToString());
                String chromosome = res["name"].ToString();

                String sql = "UPDATE syntenyEns SET genomeDbId=" + genomeDbId.ToString() + ", chromosome='" +
                             chromosome + "' WHERE dnafragId=" + dnafragId.ToString();
                App.DB.Exec(sql);
                // App.Log(sql);
            }

            App.Log("Cleaning up table...");
            App.DB.Exec("DELETE FROM syntenyEns WHERE genomeDbId IS NULL");

            App.Log("Done.");

            App.DB.Close();
        }
        //private void OnConfiguration(object sender, RoutedEventArgs e)
        //{

        //}

        private void OnImportInventory(object sender, RoutedEventArgs e)
        {
            OpenFileDialog diag = new OpenFileDialog();
            diag.Title = "Select File for Import";
            diag.Filter = "Comma Delimited|*.csv|All Files|*.*";
            diag.CheckFileExists = true;
            diag.CheckPathExists = true;
            diag.DefaultExt = "csv";
            diag.Multiselect = false;





            if (diag.ShowDialog() == true)
            {
                using (StreamReader sr = new StreamReader(diag.FileName))
                {
                    LumenWorks.Framework.IO.Csv.CsvReader csv = new LumenWorks.Framework.IO.Csv.CsvReader(sr, true);

                    int fieldCount = csv.FieldCount;
                    string[] headers = csv.GetFieldHeaders();

                    while (csv.ReadNextRecord())
                    {
                        ActiveInventoryObject Inv = new ActiveInventoryObject();

                        int i = 0;

                        Inv.UPC = csv[0];

                        Inv.Distributor = csv[1];
                        Inv.SKU = csv[2];
                        Inv.Description = csv[3];
                        Inv.Category = csv[4];
                        if (int.TryParse(csv[5], out i))
                        {
                            Inv.Quantity = i;
                        }


                        Inv.WholeSalePrice = Configuration.CurrencyToDecimal(csv[6]);


                        Inv.MSRP = Configuration.CurrencyToDecimal(csv[7]);


                        Inv.AdditionalOverhead = Configuration.CurrencyToDecimal(csv[8]);

                        Inv.DescriptionShort = Inv.Description;
                        Inv.Manufacturer = csv[14];

                        Cache.Current.Inventory.Add(Inv);
                        
                    }

                }
                MessageBox.Show("Process Complete.");
            }

        }
Example #12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["testing"] == "true")
               return;
          //fdata.DataSource = csv;
          //fdata.DataBind();

          List<PayPalRecord> PayPalRecords = new List<PayPalRecord>();

          decimal totalfees  = Decimal.Parse("0.0");
          decimal totalgross = Decimal.Parse("0.0");
          decimal totalnet   = Decimal.Parse("0.0");
          string  text       = "";
          foreach (string directory in Directory.GetDirectories(@"W:\Projects\Weavver\Accounting\Paypal"))
          {
               foreach (string file in Directory.GetFiles(directory))
               {
                    Response.Write(file);
                    if (!file.EndsWith(".txt"))
                         continue;

                    LumenWorks.Framework.IO.Csv.CsvReader csv = new LumenWorks.Framework.IO.Csv.CsvReader(new StreamReader(file), true, '\t');

                    int fieldCount = csv.FieldCount;
                    string[] headers = csv.GetFieldHeaders();
                    decimal fees  = Decimal.Parse("0.0");
                    decimal gross = Decimal.Parse("0.0");
                    decimal net   = Decimal.Parse("0.0");

                    while (csv.ReadNextRecord())
                    {
                         string itemtitle = null;
                         try
                         {
                              itemtitle = csv["Item Title"];
                         }
                         catch (Exception ex)
                         {
                              ShowError(ex, "Import error");
                              continue;
                         }
                         if (itemtitle == "Snap Pro")
                         {
                              PayPalRecord item = new PayPalRecord();
                              item.Date                = csv["Date"];
                              item.Time                = csv["Time"];
                              item.TimeZone            = csv["Time Zone"];
                              item.Name                = csv["Name"];
                              item.Type                = csv["Type"];
                              item.Status              = csv["Status"];
                              item.Currency            = csv["Currency"];
                              item.Gross               = csv["Gross"];
                              item.Net                 = csv["Net"];
                              item.FromEmailAddress    = csv["From Email Address"];
                              item.ToEmailAddress      = csv["To Email Address"];
                              item.TransactionID       = csv["Transaction ID"];
                              item.CounterpartyStatus  = csv["Counterparty Status"];
                              item.ShippingAddress     = csv["Shipping Address"];
                              item.AddressStatus       = csv["Address Status"];
                              item.ItemTitle           = csv["Item Title"];
                              item.ItemID              = csv["Item ID"];
                              item.ShippingandHandlingAmount = Decimal.Parse(csv["Shipping and Handling Amount"]);
                              item.InsuranceAmount     = csv["Insurance Amount"];
                              item.SalesTax            = Decimal.Parse(csv["Sales Tax"]);
                              item.Option1Name         = csv["Option 1 Name"];
                              item.Option1Value        = csv["Option 1 Value"];
                              item.Option2Name         = csv["Option 2 Name"];
                              item.Option2Value        = csv["Option 2 Value"];
                              item.AuctionSite         = csv["Auction Site"];
                              item.BuyerID             = csv["Buyer ID"];
                              item.ReferenceTxnID      = csv["Reference Txn ID"];
                              item.InvoiceNumber       = csv["Invoice Number"];
                              item.CustomNumber        = csv["Custom Number"];
                              item.ReceiptID           = csv["Receipt ID"];
                              item.Balance             = csv["Balance"];
                              item.ContactPhoneNumber  = csv["Contact Phone Number"];
                              item.BalanceImpact       = csv["Balance Impact"];

                              PayPalRecords.Add(item);

                              fees                     += Decimal.Parse(csv["Fee"]);
                              gross                    += Decimal.Parse(csv["Gross"]);
                              net                      += Decimal.Parse(csv["Net"]);
                              continue;
                         }
                    }
                    text       += "<hr />";
                    totalfees  += fees;
                    totalgross += gross;
                    totalnet   += net;
               }
          }

          fdata.DataSource = PayPalRecords;

          //for (int i = 0; i < PayPalRecords.Count; i++)
          //{
          //     PayPalRecords[i].Commit();
          //}
          //fdata.DataBind();

          //FileData.Text  = text;
          //totalfees      = -1 * totalfees;
          //Fees.Text      = "Fees: $" + totalfees.ToString();
          //Totals.Text    = "Gross: $" + totalgross.ToString();
          //Net.Text       = "Net: $" + totalnet.ToString();

          //Net.Text        += "<br>Total Records: " + PayPalRecords.Count;
          //Console.ReadLine();
    }
Example #13
0
        public static ActiveInventoryCollection ImportFromWebsiteOpenCart(string file)
        {
            ActiveInventoryCollection retVal = new ActiveInventoryCollection();

            try
            {
                StringBuilder sb = new StringBuilder();
                using (StreamReader sr = new StreamReader(file))
                {
                    string sLine = null;
                    do
                    {
                        sLine = sr.ReadLine();
                        if (!string.IsNullOrEmpty(sLine))
                        {
                            sb.AppendLine(HttpUtility.UrlDecode(sLine));
                        }
                    } while (sLine != null);
                }
                using (LumenWorks.Framework.IO.Csv.CsvReader reader
                           = new LumenWorks.Framework.IO.Csv.CsvReader(new StringReader(sb.ToString()), true))
                {
                    while (reader.ReadNextRecord())
                    {
                        ActiveInventoryObject aio = new ActiveInventoryObject();
                        int     i = 0;
                        decimal d = 0M;
                        if (int.TryParse(reader["product_id"], out i))
                        {
                            aio.ProductID = i;
                        }
                        try
                        {
                            if (decimal.TryParse(reader["price"], out d))
                            {
                                aio.SellingPrice = d;
                            }
                        }
                        catch { }

                        aio.UPC          = reader["upc"];
                        aio.SKU          = reader["sku"];
                        aio.Name         = reader["prodname"];
                        aio.Manufacturer = reader["mname"];
                        aio.Distributor  = reader["dname"];
                        aio.Category     = reader["catname"];
                        if (reader["modelkit"] == "1")
                        {
                            //aio.DiscountRateLevel = 0.05M;
                            aio.IsModelKit = true;
                        }
                        else
                        {
                            aio.IsModelKit = false;
                        }

                        if (!int.TryParse(reader["stock"], out i))
                        {
                            aio.Quantity = 0;
                        }
                        else
                        {
                            aio.Quantity = i;
                        }

                        d = 0;
                        //if (decimal.TryParse(reader["pricesell"], out d))
                        //{
                        //    aio.WholeSalePrice = d;
                        //}

                        if (retVal.GetByProductID(aio.ProductID) == null)
                        {
                            retVal.Add(aio);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error on Import:\r\n\r\n" + ex.Message);
                retVal = null;
                if (_log.IsWarnEnabled)
                {
                    _log.Warn("Error importing: ", ex);
                }
            }
            return(retVal);
        }
Example #14
0
        public static ActiveInventoryCollection ImportFromSpreadsheet(string file)
        {
            ActiveInventoryCollection retVal = new ActiveInventoryCollection();

            try
            {
                using (LumenWorks.Framework.IO.Csv.CsvReader reader = new LumenWorks.Framework.IO.Csv.CsvReader(new System.IO.StreamReader(file, Encoding.GetEncoding(1252)), true))
                {
                    reader.SupportsMultiline = false;
                    //reader.ReadNextRecord();  //Header Record?
                    //string x = reader["UPC"];
                    while (reader.ReadNextRecord())
                    {
                        if (!string.IsNullOrEmpty(reader["SKU"]) && !reader["UPC"].Contains("~~"))
                        {
                            ActiveInventoryObject aio = new ActiveInventoryObject();
                            string data = reader.GetCurrentRawData();

                            aio.UPC = reader["UPC"];
                            int i = 0;
                            if (int.TryParse(reader["Product ID"], out i))
                            {
                                aio.ProductID = i;
                            }
                            aio.Distributor = reader["Distributor"];
                            aio.SKU         = reader["SKU"];
                            aio.Name        = reader["Description"];

                            //aio.Category = reader["Category"];
                            try
                            {
                                if (reader["Is Model Kit"].ToUpperInvariant() == "YES")
                                {
                                    //aio.DiscountRateLevel = 0.05M;
                                    aio.IsModelKit = true;
                                }
                                else
                                {
                                    aio.IsModelKit = false;
                                }
                            }
                            catch (Exception ex)
                            {
                                if (_log.IsWarnEnabled)
                                {
                                    _log.Warn("Error importing: ", ex);
                                }
                            }

                            try
                            {
                                //Quantity of zero might be valid--this could change that.
                                if (!int.TryParse(reader["Quantity"], out i))
                                {
                                    aio.Quantity = 0;
                                }
                                else
                                {
                                    aio.Quantity = i;
                                }
                            }
                            catch (Exception ex)
                            {
                                if (_log.IsWarnEnabled)
                                {
                                    _log.Warn("Error importing: ", ex);
                                }
                            }
                            decimal d = 0;
                            try
                            {
                                if (decimal.TryParse(reader["Wholesale"].Replace("$", string.Empty), out d))
                                {
                                    aio.WholeSalePrice = d;
                                }
                                else
                                {
                                    aio.WholeSalePrice = 0;
                                }
                            }
                            catch (Exception ex)
                            {
                                if (_log.IsWarnEnabled)
                                {
                                    _log.Warn("Error importing: ", ex);
                                }
                            }
                            try
                            {
                                if (decimal.TryParse(reader["MSRP"].Replace("$", string.Empty), out d))
                                {
                                    aio.MSRP = d;
                                }
                                else
                                {
                                    aio.MSRP = 0;
                                }
                            }
                            catch (Exception ex)
                            {
                                if (_log.IsWarnEnabled)
                                {
                                    _log.Warn("Error importing: ", ex);
                                }
                            }
                            //try
                            //{
                            //    if (decimal.TryParse(reader["Add'l Overhead"].Replace("$", string.Empty), out d))
                            //    {
                            //        aio.AdditionalOverhead = d;
                            //    }
                            //    else
                            //    {
                            //        aio.AdditionalOverhead = 0;
                            //    }
                            //}
                            //catch (Exception ex)
                            //{
                            //    if (_log.IsWarnEnabled)
                            //    {
                            //        _log.Warn("Error importing: ", ex);
                            //    }
                            //}
                            try
                            {
                                if (decimal.TryParse(reader["Price"].Replace("$", string.Empty), out d))
                                {
                                    aio.SellingPrice = d;
                                }
                            }
                            catch (Exception ex)
                            {
                                if (_log.IsWarnEnabled)
                                {
                                    _log.Warn("Error importing: ", ex);
                                }
                            }
                            retVal.Add(aio);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error on Import:\r\n\r\n" + ex.Message);
                retVal = null;
                if (_log.IsWarnEnabled)
                {
                    _log.Warn("Error importing: ", ex);
                }
            }
            return(retVal);
        }
Example #15
0
        public static ActiveInventoryCollection ImportFromWebsiteBase(string file)
        {
            ActiveInventoryCollection retVal = new ActiveInventoryCollection();
            decimal d = 0;

            try
            {
                using (LumenWorks.Framework.IO.Csv.CsvReader reader
                           = new LumenWorks.Framework.IO.Csv.CsvReader(new System.IO.StreamReader(file, Encoding.GetEncoding(1252)), true))
                {
                    reader.SupportsMultiline = true;
                    //reader.ReadNextRecord();  //Header Record?

                    while (reader.ReadNextRecord())
                    {
                        ActiveInventoryObject aio = new ActiveInventoryObject();
                        string data = reader.GetCurrentRawData();

                        aio.UPC = reader["upc"];


                        int i = 0;
                        if (int.TryParse(reader["product_id"], out i))
                        {
                            aio.ProductID = i;
                        }

                        aio.Name = reader["name"];


                        aio.SKU = reader["sku"];
                        //aio.Model = reader["model"];

                        aio.PictureURL = reader["image_name"];

                        aio.Description = reader["description"];

                        //aio.Category = reader["Category"];


                        if (!int.TryParse(reader["quantity"], out i))
                        {
                            aio.Quantity = 0;
                        }
                        else
                        {
                            aio.Quantity = i;
                        }
                        try
                        {
                            if (decimal.TryParse(reader["price"], out d))
                            {
                                aio.SellingPrice = d;
                            }
                        }
                        catch { }

                        aio.Metadata = reader["meta_description"];
                        aio.Keywords = reader["meta_keywords"];


                        retVal.Add(aio);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error on Import:\r\n\r\n" + ex.Message);
                retVal = null;
                if (_log.IsWarnEnabled)
                {
                    _log.Warn("Error importing: ", ex);
                }
            }
            return(retVal);
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["testing"] == "true")
        {
            return;
        }
        //fdata.DataSource = csv;
        //fdata.DataBind();

        List <PayPalRecord> PayPalRecords = new List <PayPalRecord>();

        decimal totalfees  = Decimal.Parse("0.0");
        decimal totalgross = Decimal.Parse("0.0");
        decimal totalnet   = Decimal.Parse("0.0");
        string  text       = "";

        foreach (string directory in Directory.GetDirectories(@"W:\Projects\Weavver\Accounting\Paypal"))
        {
            foreach (string file in Directory.GetFiles(directory))
            {
                Response.Write(file);
                if (!file.EndsWith(".txt"))
                {
                    continue;
                }

                LumenWorks.Framework.IO.Csv.CsvReader csv = new LumenWorks.Framework.IO.Csv.CsvReader(new StreamReader(file), true, '\t');

                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();
                decimal  fees       = Decimal.Parse("0.0");
                decimal  gross      = Decimal.Parse("0.0");
                decimal  net        = Decimal.Parse("0.0");

                while (csv.ReadNextRecord())
                {
                    string itemtitle = null;
                    try
                    {
                        itemtitle = csv["Item Title"];
                    }
                    catch (Exception ex)
                    {
                        ShowError(ex, "Import error");
                        continue;
                    }
                    if (itemtitle == "Snap Pro")
                    {
                        PayPalRecord item = new PayPalRecord();
                        item.Date                      = csv["Date"];
                        item.Time                      = csv["Time"];
                        item.TimeZone                  = csv["Time Zone"];
                        item.Name                      = csv["Name"];
                        item.Type                      = csv["Type"];
                        item.Status                    = csv["Status"];
                        item.Currency                  = csv["Currency"];
                        item.Gross                     = csv["Gross"];
                        item.Net                       = csv["Net"];
                        item.FromEmailAddress          = csv["From Email Address"];
                        item.ToEmailAddress            = csv["To Email Address"];
                        item.TransactionID             = csv["Transaction ID"];
                        item.CounterpartyStatus        = csv["Counterparty Status"];
                        item.ShippingAddress           = csv["Shipping Address"];
                        item.AddressStatus             = csv["Address Status"];
                        item.ItemTitle                 = csv["Item Title"];
                        item.ItemID                    = csv["Item ID"];
                        item.ShippingandHandlingAmount = Decimal.Parse(csv["Shipping and Handling Amount"]);
                        item.InsuranceAmount           = csv["Insurance Amount"];
                        item.SalesTax                  = Decimal.Parse(csv["Sales Tax"]);
                        item.Option1Name               = csv["Option 1 Name"];
                        item.Option1Value              = csv["Option 1 Value"];
                        item.Option2Name               = csv["Option 2 Name"];
                        item.Option2Value              = csv["Option 2 Value"];
                        item.AuctionSite               = csv["Auction Site"];
                        item.BuyerID                   = csv["Buyer ID"];
                        item.ReferenceTxnID            = csv["Reference Txn ID"];
                        item.InvoiceNumber             = csv["Invoice Number"];
                        item.CustomNumber              = csv["Custom Number"];
                        item.ReceiptID                 = csv["Receipt ID"];
                        item.Balance                   = csv["Balance"];
                        item.ContactPhoneNumber        = csv["Contact Phone Number"];
                        item.BalanceImpact             = csv["Balance Impact"];

                        PayPalRecords.Add(item);

                        fees  += Decimal.Parse(csv["Fee"]);
                        gross += Decimal.Parse(csv["Gross"]);
                        net   += Decimal.Parse(csv["Net"]);
                        continue;
                    }
                }
                text       += "<hr />";
                totalfees  += fees;
                totalgross += gross;
                totalnet   += net;
            }
        }

        fdata.DataSource = PayPalRecords;

        //for (int i = 0; i < PayPalRecords.Count; i++)
        //{
        //     PayPalRecords[i].Commit();
        //}
        //fdata.DataBind();

        //FileData.Text  = text;
        //totalfees      = -1 * totalfees;
        //Fees.Text      = "Fees: $" + totalfees.ToString();
        //Totals.Text    = "Gross: $" + totalgross.ToString();
        //Net.Text       = "Net: $" + totalnet.ToString();

        //Net.Text        += "<br>Total Records: " + PayPalRecords.Count;
        //Console.ReadLine();
    }