Exemple #1
0
        void AddExcelTransactionToTransactionModelList(List <Transaction> list, ExcelTransaction transaction, Dictionary <string, List <string> > tagGroupDict)
        {
            var model = this.ConvertToModel(transaction);

            model.Tags = this.GetTagModelList(transaction.TagGroupId, transaction.TagNames, tagGroupDict);
            list.Add(model);
        }
Exemple #2
0
 public Transaction ConvertToModel(ExcelTransaction tr)
 {
     return(new Transaction()
     {
         //Id = default(int),
         Account = tr.Account,
         AccountName = tr.AccountName,
         AccountingDate = tr.AccountingDate,
         Type = tr.Type,
         TransactionId = tr.TransactionId,
         PartnerAccount = tr.PartnerAccount,
         PartnerName = tr.PartnerName,
         Sum = (decimal?)tr.Sum,
         Message = tr.Message,
         Tags = null,
         Currency = new Currency()
         {
             //Id = this.newTransactionId--,
             Name = tr.Currency,
             CreateDate = DateTime.Now,
             State = "T"
         },
         CreateDate = DateTime.Now,
         State = "T"
     });
 }
Exemple #3
0
        void ReadExcel(string fullFilePath, ExcelSheet excelSheet)
        {
            ISheet sheet;

            using (var stream = new FileStream(fullFilePath, FileMode.Open))
            {
                stream.Position = 0;
                if (Path.GetExtension(fullFilePath) == ".xls")
                {
                    HSSFWorkbook hssfwb = new HSSFWorkbook(stream); //This will read the Excel 97-2000 formats
                    sheet = hssfwb.GetSheetAt(0);                   //get first sheet from workbook
                }
                else
                {
                    XSSFWorkbook hssfwb = new XSSFWorkbook(stream); //This will read 2007 Excel format
                    sheet = hssfwb.GetSheetAt(0);                   //get first sheet from workbook
                }

                if (excelSheet.IsHeaderEmpty)
                {
                    IRow headerRow = sheet.GetRow(0);
                    this.AddHeaderColumns(excelSheet, headerRow);
                }

                int i = this.GetStartingIndexValue(sheet);

                while ((IsReadFromTheBeginning && i <= sheet.LastRowNum) || // from the beginning
                       (!IsReadFromTheBeginning && i >= (sheet.FirstRowNum + 1))) // from end
                {
                    IRow row = sheet.GetRow(i);
                    if (row != null &&
                        row.Cells.Any(d => d.CellType != CellType.Blank))
                    {
                        var tr = new ExcelTransaction();

                        if (row.GetCell(0) != null)
                        {
                            tr.AccountingDate = row.GetCell(0).DateCellValue;
                        }
                        if (row.GetCell(1) != null)
                        {
                            tr.TransactionId = row.GetCell(1).ToString().Trim();
                        }
                        if (row.GetCell(2) != null)
                        {
                            tr.Type = row.GetCell(2).ToString().Trim();
                        }
                        if (row.GetCell(3) != null)
                        {
                            tr.Account = row.GetCell(3).ToString().Trim();
                        }
                        if (row.GetCell(4) != null)
                        {
                            tr.AccountName = row.GetCell(4).ToString().Trim();
                        }
                        if (row.GetCell(5) != null)
                        {
                            tr.PartnerAccount = row.GetCell(5).ToString().Trim();
                        }
                        if (row.GetCell(6) != null)
                        {
                            tr.PartnerName = row.GetCell(6).ToString().Trim();
                        }
                        if (row.GetCell(7) != null)
                        {
                            tr.Sum = double.Parse(row.GetCell(7).ToString());
                        }
                        if (row.GetCell(8) != null)
                        {
                            tr.Currency = row.GetCell(8).ToString().Trim();
                        }
                        if (row.GetCell(9) != null)
                        {
                            tr.Message = row.GetCell(9).ToString().Trim();
                        }

                        if (row.GetCell(10) != null)
                        {
                            tr.IsOmitted = row.GetCell(10).ToString().Trim() == "1";
                        }
                        if (row.GetCell(11) != null)
                        {
                            tr.GroupId = row.GetCell(11).ToString().Trim();
                        }
                        if (row.GetCell(12) != null)
                        {
                            tr.TagNames = this.GetIntList(row.GetCell(12).ToString().Trim());
                        }
                        if (row.GetCell(13) != null)
                        {
                            tr.TagGroupId = row.GetCell(13).ToString().Trim();
                        }

                        excelSheet.AddNewRow(tr);
                    }
                    i = this.GetNextIteration(i);
                }
            }
        }