Exemplo n.º 1
0
        private void ReadFile(string filename)
        {
            try
            {
                using (var excelDoc = new ExcelDoc(filename))
                {
                    try
                    {
                        excelDoc.SetList("Расходы по а-м");

                        var grz = (excelDoc.getValue("B4") != null) ? excelDoc.getValue("B4").ToString() : string.Empty;

                        var car = GetCar(grz);

                        if (car == null)
                        {
                            var driverFio = (excelDoc.getValue("B5") != null) ? excelDoc.getValue("B5").ToString() : string.Empty;

                            var driverList = DriverList.getInstance();
                            var driver     = driverList.getItemByFIO(driverFio);

                            if (driver != null)
                            {
                                var driverCarList = DriverCarList.getInstance();
                                car = driverCarList.GetCar(driver);
                            }

                            if (car == null)
                            {
                                _mileageReportList.Add(new MileageReport(null,
                                                                         string.Concat("Не найден автомобиль: ", grz, " сотрудник: ", driverFio, ". Файл: ", filename)));
                            }
                        }

                        if (car != null)
                        {
                            string value = excelDoc.getValue("C8") != null?excelDoc.getValue("C8").ToString() : string.Empty;

                            SetMileage(car, value);
                        }
                    }

                    catch (IndexOutOfRangeException)
                    {
                        _mileageReportList.Add(new MileageReport(null, string.Concat("Ошибка при чтении файла: ", filename)));
                    }
                    catch (OverflowException)
                    {
                        _mileageReportList.Add(new MileageReport(null,
                                                                 string.Concat("Указан слишком большой пробег в файле: ", filename)));
                    }
                }
            }
            catch
            {
                _mileageReportList.Add(new MileageReport(null, string.Concat("Ошибка при чтении файла: ", filename)));
            }
        }
Exemplo n.º 2
0
        private string GetWaBillFullNumber(int currentNumber)
        {
            string[] wayBillFullNumber = _excelDoc.getValue("AM4").ToString().Split('/');

            wayBillFullNumber[1]  = currentNumber < 10 ? "0" : string.Empty;
            wayBillFullNumber[1] += currentNumber;

            StringBuilder sb = new StringBuilder();

            foreach (string item in wayBillFullNumber)
            {
                if (sb.Length > 0)
                {
                    sb.Append("/");
                }

                sb.Append(item);
            }

            return(sb.ToString());
        }