コード例 #1
0
        public void StartImport()
        {
            try
            {
                using (ExcelDoc excel = new ExcelDoc(FilePath))
                {
                    int i = 7;

                    string curCell = "H" + i;
                    while (excel.getValue(curCell) != null)
                    {
                        curCell = "A" + i;
                        if ((excel.getValue(curCell) == null) ||
                            ((excel.getValue(curCell).ToString().ToUpper() != "AM") && (excel.getValue(curCell).ToString().ToUpper() != "АМ")))
                        {
                            curCell = "H" + i;
                            i++;
                            continue;
                        }

                        curCell = "H" + i;
                        string number = excel.getValue(curCell).ToString();

                        curCell = "D" + i;
                        DateTime dateBegin;
                        DateTime.TryParse(excel.getValue1(curCell).ToString(), out dateBegin);

                        curCell = "E" + i;
                        DateTime dateEnd;
                        DateTime.TryParse(excel.getValue1(curCell).ToString(), out dateEnd);

                        for (DateTime date = dateBegin; date <= dateEnd; date = date.AddDays(1))
                        {
                            Tabel tabel = new Tabel(number, date) { Comment = "businessTrip" };
                            tabel.Save();
                        }

                        curCell = "H" + i;
                        i++;
                    }
                }
            }
            catch (NullReferenceException ex)
            {
                LogManager.Logger.Error(ex, "Error in file {file}", FilePath);
            }
            catch (COMException ex)
            {
                LogManager.Logger.Error(ex, "Error in file {file}", FilePath);
            }
        }
コード例 #2
0
ファイル: FuelLoader.cs プロジェクト: NextStalker/BBAuto
        private static void LoadPetrol(ExcelDoc excel)
        {
            int i = 4; //начальный индекс

            string currentCell = "B" + i;
            while (excel.getValue(currentCell) != null)
            {
                currentCell = "D" + i;
                string number = excel.getValue(currentCell).ToString();
                FuelCard fuelCard = fuelCardList.getItem(number);
                if (fuelCard == null)
                {
                    i++;
                    currentCell = "B" + i;
                    erorrs.Add("Не найдена карта №" + number); //throw new NullReferenceException("Не найдена карта №" + number);
                    continue;
                }

                currentCell = "B" + i;
                string dateString = excel.getValue1(currentCell).ToString();
                DateTime datetime;
                DateTime.TryParse(dateString, out datetime);//присутствует время, не забываем убирать

                currentCell = "G" + i;
                string engineTypeName = excel.getValue(currentCell).ToString();
                EngineType engineType = GetEngineType(engineTypeName);

                currentCell = "H" + i;
                double value;
                double.TryParse(excel.getValue(currentCell).ToString(), out value);

                Fuel fuel = new Fuel(fuelCard, datetime.Date, engineType);
                fuel.AddValue(value);
                fuel.Save();

                i++;
                currentCell = "B" + i;
            }
        }