private bool ImportTextContent() { try { fLog.Clear(); GDMLines buffer = new GDMLines(); try { int prev_id = 0; int num = fRawContents.Count; for (int i = 0; i < num; i++) { string line = PrepareLine(fRawContents[i]); RawLine rawLine = (RawLine)fRawContents.GetObject(i); switch (rawLine.Type) { case RawLineType.rltComment: buffer.Add(line); break; case RawLineType.rltPerson: case RawLineType.rltRomeGeneration: case RawLineType.rltEOF: { prev_id = ParseBuffer(buffer); buffer.Clear(); switch (rawLine.Type) { case RawLineType.rltPerson: buffer.Add(line); break; case RawLineType.rltRomeGeneration: fLog.Add("> " + fLangMan.LS(ILS.LSID_Generation) + " \"" + line + "\""); break; case RawLineType.rltEOF: fLog.Add("> EOF."); break; } } break; } } return(true); } finally { } } catch (Exception ex) { Logger.WriteError("Importer.ImportTextContent()", ex); throw; } }
private bool ImportTableContent() { try { fLog.Clear(); MSOExcel.Application excel; try { excel = new MSOExcel.Application(); } catch (Exception) { return(false); } excel.Visible = DEBUG_EXCEL; excel.DisplayAlerts = false; excel.WindowState = MSOExcel.XlWindowState.xlMaximized; excel.Workbooks.Open(fFileName); MSOExcel.Worksheet sheet = excel.Worksheets[1] as MSOExcel.Worksheet; //sheet.Activate(); IProgressController progress = AppHost.Progress; GDMLines buffer = new GDMLines(); try { int rowsCount = sheet.UsedRange.Rows.Count; //int colsCount = sheet.UsedRange.Columns.Count; progress.ProgressInit(fLangMan.LS(ILS.LSID_Loading), rowsCount); MSOExcel.Range excelRange = sheet.UsedRange; object[,] valueArray = (object[, ])excelRange.get_Value(MSOExcel.XlRangeValueDataType.xlRangeValueDefault); int prevId = 0; for (int row = 1; row <= rowsCount; row++) { string c1 = GetCell(valueArray, row, 1).Trim(); // position number string c2 = GetCell(valueArray, row, 2).Trim(); // ancestor number string c3 = GetCell(valueArray, row, 3).Trim(); // name, maybe start with the number of marriage string c4 = GetCell(valueArray, row, 4).Trim(); // birth date string c5 = GetCell(valueArray, row, 5).Trim(); // death date string c6 = GetCell(valueArray, row, 6).Trim(); // birth or residence place string s123 = c1 + c2; if (s123 != "" && !string.IsNullOrEmpty(c3) && c3[0] != '/') { s123 += ". " + c3; } else { s123 += c3; } if (s123 == "") { continue; } string line, p_id = ""; RawLineType lineType = RawLineType.rltComment; if (IsGenerationLine(s123)) { line = s123; lineType = RawLineType.rltRomeGeneration; } else { line = s123 + " " + c4 + " " + c5; if (c6 != "") { line = line + ". " + c6 + "."; } line = line.Trim(); p_id = IsPersonLine(line); if (!string.IsNullOrEmpty(p_id)) { lineType = RawLineType.rltPerson; } } switch (lineType) { case RawLineType.rltComment: buffer.Add(line); break; case RawLineType.rltPerson: case RawLineType.rltRomeGeneration: case RawLineType.rltEOF: { prevId = ParseBuffer(buffer); buffer.Clear(); switch (lineType) { case RawLineType.rltPerson: buffer.Add(line); break; case RawLineType.rltRomeGeneration: fLog.Add("> " + fLangMan.LS(ILS.LSID_Generation) + " \"" + line + "\""); break; case RawLineType.rltEOF: fLog.Add("> EOF."); break; } } break; } progress.ProgressStep(row); } // hack: processing last items before end prevId = ParseBuffer(buffer); return(true); } finally { progress.ProgressDone(); buffer.Clear(); buffer = null; excel.Quit(); excel = null; } } catch (Exception ex) { fLog.Add(">>>> " + fLangMan.LS(ILS.LSID_DataLoadError)); Logger.WriteError("Importer.ImportTableContent()", ex); return(false); } }