Beispiel #1
0
        //THIS USES THE CURRENCY CONVERTER
        public bool SN760756ToExcel(string filePath)
        {
            //try {

            var engine = new FileHelperEngine <TruckCSV>();
            var result = engine.ReadFile(filePath);

            int currentRow = 5;

            // result is now an array of RekordCSV

            foreach (TruckCSV csvTruck in result)
            {
                csvTruck.registration = csvTruck.registration.Replace(" ", string.Empty);
                //checks if any truck was found
                bool truckWithThisRegistrationFound = false;


                //THIS IS KAROL'S CODE

                foreach (Truck element in TruckData)
                {
                    if (element.Registration == csvTruck.registration)//this is working, just lookin bad
                    {
                        truckWithThisRegistrationFound = true;


                        //this is so f*****g bad i don't even
                        String ProductName = csvTruck.product;

                        if (match(ProductName, new string[] { "Olej", "Diesel", " ON" }) && csvTruck.quantity >= 0 && csvTruck.netto_price >= 0)
                        {
                            element.DieselL    += (float)csvTruck.quantity;
                            element.DieselCost += (float)csvTruck.netto_price * currencyConverter.getRateOf(csvTruck.currency);
                        }
                        else if (match(ProductName, new string[] { "Autostrada", "Podatek", "Road tax", "Eurovignette", "Motorway", "Eurowinieta", "drogowe", "elektroniczna" }) && csvTruck.netto_price >= 0)
                        {
                            element.RoadTax += (float)csvTruck.netto_price * currencyConverter.getRateOf(csvTruck.currency);
                        }
                        else if (match(ProductName, new string[] { "AdBlue", "ad blue" }) && csvTruck.quantity >= 0 && csvTruck.netto_price >= 0)
                        {
                            element.AdblueL    += (float)csvTruck.quantity;
                            element.AdblueCost += (float)csvTruck.netto_price * currencyConverter.getRateOf(csvTruck.currency);
                        }
                        else if (csvTruck.netto_price >= 0)
                        {
                            element.OtherCost += (float)csvTruck.netto_price * currencyConverter.getRateOf(csvTruck.currency);
                        }
                    }
                }


                //END OF PIETRZAKOWY KOD

                //if there was no truck with this registration number
                if (!truckWithThisRegistrationFound)
                {
                    TruckNotFound truck = new TruckNotFound(filePath);
                    truck.line         = currentRow;
                    truck.Registration = csvTruck.registration;
                    truck.otherData   += "Produkt: " + csvTruck.product + ", cena: " + csvTruck.netto_price;

                    notFoundTrucks.Add(truck);
                }

                currentRow++;
            }

            //}
            //catch (Exception e) {
            //   System.Windows.Forms.MessageBox.Show("Nie udało się otworzyć " + filePath);
            //  return false;
            // }


            closeAllWorkbooksDontKillApp();

            return(true);
        }
Beispiel #2
0
        public bool _F61506817081ToExcel(string Path)
        {
            string RegistrationColumn = "X";
            string ProductColumn      = "E";
            string QuantityColumn     = "F";
            string NettoPriceColumn   = "T";
            string CurrencyColumn     = "O";

            Microsoft.Office.Interop.Excel.Worksheet MyWorksheet;
            Microsoft.Office.Interop.Excel.Range     MyCells;

            try {
                MyExcel.Workbooks.Open(Path);
                MyWorksheet = MyExcel.Worksheets.Item[1];
                MyCells     = MyWorksheet.Cells;
            } catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Nie udało się otworzyć " + Path);
                return(false);
            }

            int CurrentRow = 2;
            int iRowCount  = MyWorksheet.UsedRange.Rows.Count;

            while (CurrentRow <= iRowCount)
            {
                String Reg = MyCells.Item[CurrentRow, RegistrationColumn].Value;
                Reg = Reg.Replace(" ", string.Empty);

                //checks if any truck was found
                bool truckWithThisRegistrationFound = false;


                foreach (Truck element in TruckData)
                {
                    if (element.Registration == Reg)//this is working, just lookin bad
                    {
                        truckWithThisRegistrationFound = true;


                        String ProductName = MyCells.Item[CurrentRow, ProductColumn].Value;
                        if (match(ProductName, new string[] { "Olej", "Diesel" }) && MyCells.Item[CurrentRow, QuantityColumn].Value >= 0 && MyCells.Item[CurrentRow, NettoPriceColumn].Value >= 0)
                        {
                            element.DieselL    += MyCells.Item[CurrentRow, QuantityColumn].Value;
                            element.DieselCost += MyCells.Item[CurrentRow, NettoPriceColumn].Value;
                        }
                        else if (match(ProductName, new string[] { "Autostrada", "Podatek", "Road tax", "Eurovignette", "Motorway" }) && MyCells.Item[CurrentRow, NettoPriceColumn].Value >= 0)
                        {
                            element.RoadTax += MyCells.Item[CurrentRow, NettoPriceColumn].Value;
                        }
                        else if (match(ProductName, new string[] { "AdBlue", "Ad Blue" }) && MyCells.Item[CurrentRow, QuantityColumn].Value >= 0 && MyCells.Item[CurrentRow, NettoPriceColumn].Value >= 0)
                        {
                            element.AdblueL    += MyCells.Item[CurrentRow, QuantityColumn].Value;
                            element.AdblueCost += MyCells.Item[CurrentRow, NettoPriceColumn].Value;
                        }
                        else if (MyCells.Item[CurrentRow, NettoPriceColumn].Value >= 0)
                        {
                            element.OtherCost += MyCells.Item[CurrentRow, NettoPriceColumn].Value;
                        }
                    }
                }

                //if there was no truck with this registration number
                if (!truckWithThisRegistrationFound)
                {
                    TruckNotFound truck = new TruckNotFound(Path);
                    truck.line         = CurrentRow;
                    truck.Registration = Reg;
                    truck.otherData   += "Produkt: " + MyCells.Item[CurrentRow, ProductColumn].Value + ", ilość: " + MyCells.Item[CurrentRow, QuantityColumn].Value;

                    notFoundTrucks.Add(truck);
                }

                CurrentRow++;
            }


            closeAllWorkbooksDontKillApp();

            return(true);
        }