/// <summary> /// getDoc(name) - get Document name - when nor read yet - from the file. If necessary - Create new Sheet /// </summary> /// <param name="name">Document name</param> /// <param name="fatal">FATAL if this flag = true; else - return null if Document doesnt exists</param> /// <returns>Document or null</returns> /// <returns>Document</returns> /// <history> 25.12.2013 отлажено /// 25.12.2013 - чтение из файла, формирование Range Body /// 28.12.13 - теперь doc.Sheet и doc.Wb храним в структуре Документа /// 5.4.14 - инициализируем docDic, то есть подготавливаем набор данных для Fetch /// 22.12.15 - getDoc для нового документа - в Штампе он помечен N /// 6.1.16 - NOP если FiliDirectory содержит # - каталог Документа еще будет разворачиваться позже /// 5.3.16 - null if Document not found or exist /// 30.3.16 - get #template Path from Bootstrap.Template; try-catch rewritten /// 5.4.16 - bug fix - SheetReset for "N" Document /// 19.4.16 - use Templ.getPath in getDoc() /// 27.4.16 - optional flag load - if false -> don't load contents from the file /// </history> public static Document getDoc(string name = Decl.DOC_TOC, bool fatal = true, bool load = true) { Log.set("getDoc(" + name + ")"); Document doc = null; string err = "Err getDoc: ", ex= ""; try { doc = Documents[name]; } catch (Exception e) { err += "doc not in TOC"; ex = e.Message; doc = null; } if (doc != null && !doc.isOpen) { if (load) { if (doc.FileDirectory.Contains("#")) // #Template substitute with Path in Dictionary doc.FileDirectory = Templates[doc.FileDirectory]; //-------- Load Document from the file or create it ------------ bool create = !string.IsNullOrEmpty(doc.type) && doc.type[0] == 'N' ? true : false; doc.Wb = FileOp.fileOpen(doc.FileDirectory, doc.FileName, create); try { if (doc.type == Decl.DOC_TYPE_N) FileOp.SheetReset(doc.Wb, doc.SheetN); doc.Sheet = doc.Wb.Worksheets[doc.SheetN]; } catch (Exception e) { err += "no SheetN"; ex = doc.SheetN; doc = null; } if (create && doc != null) doc.Reset(); else if (doc != null) doc.Body = FileOp.getSheetValue(doc.Sheet); } } // end if(!doc.isOpen) if(doc == null && fatal) Msg.F(err, ex, name); if(doc != null && doc.Body != null) doc.isOpen = true; Log.exit(); return doc; }
} // end Start /// <summary> /// tocStart(TOCdir) - open file TSmatch.xlsx in TOCdir directory /// </summary> /// <param name="TOCdir"></param> /// <returns>return TOC document</returns> /// <history>18.4.2016 /// 19.4.2016 - set Windows Environment Path paramenters /// 2.5.2016 - when TOCdir differ from Registry Environment value -- start DirRelocation Recovery /// 4.5.2016 - remove works with Registry to module Bootstrap /// </history> public static Document tocStart(string TOCdir) { Log.set("tocStart"); toc = new Document(Decl.DOC_TOC); toc.Wb = FileOp.fileOpen(TOCdir, Decl.F_MATCH); toc.Sheet = toc.Wb.Worksheets[Decl.DOC_TOC]; toc.Body = FileOp.getSheetValue(toc.Sheet); toc.type = Decl.TSMATCH_TYPE; toc.EOL(Decl.TOC_I0); Form.setWb(toc.Wb, toc.Body); toc.isOpen = true; Log.exit(); return toc; }
/// <summary> /// getDoc(name) - get Document name - when nor read yet - from the file. If necessary - Create new Sheet /// </summary> /// <param name="name">Document name</param> /// <param name="fatal">FATAL if this flag = true; else - return null if Document doesnt exists</param> /// <returns>Document or null</returns> /// <returns>Document</returns> /// <history> 25.12.2013 отлажено /// 25.12.2013 - чтение из файла, формирование Range Body /// 28.12.13 - теперь doc.Sheet и doc.Wb храним в структуре Документа /// 5.4.14 - инициализируем docDic, то есть подготавливаем набор данных для Fetch /// 22.12.15 - getDoc для нового документа - в Штампе он помечен N /// 6.1.16 - NOP если FiliDirectory содержит # - каталог Документа еще будет разворачиваться позже /// 5.3.16 - null if Document not found or exist /// 30.3.16 - get #template Path from Bootstrap.Template; try-catch rewritten /// 5.4.16 - bug fix - SheetReset for "N" Document /// 19.4.16 - use Templ.getPath in getDoc() /// 27.4.16 - optional flag load - if false -> don't load contents from the file /// 9.4.17 - optional create_if_not_exist argument /// 17.4.17 - doc.il = doc.Body.iEOL(); /// 27.4.17 - move Reset() later in code, error logic changed /// 31.7.17 - read XML file in doc.Body -- does't works yet!! /// 2.8.18 - bug fix doc.il set re-written /// </history> public static Document getDoc(string name = Decl.DOC_TOC , bool fatal = true, bool load = true, bool create_if_notexist = false, bool reset = false) { Log.set("getDoc(" + name + ")"); Document doc = null; string err = "Err getDoc: ", ex = ""; try { doc = Documents[name]; } catch (Exception e) { err += "doc not in TOC"; ex = e.Message; doc = null; } if (doc != null && !doc.isOpen) { if (load) { if (doc.FileDirectory.Contains("#")) // #Template substitute with Path in Dictionary doc.FileDirectory = Templates[doc.FileDirectory]; //-------- Load Document from the file or create it ------------ if (doc.type == "XML") { string file = Path.Combine(doc.FileDirectory, doc.FileName); throw new NotImplementedException(); doc.Body = rwXML.XML.ReadFromXmlFile<Mtr>(file); } else { doc.Wb = FileOp.fileOpen(doc.FileDirectory, doc.FileName, create_if_notexist, fatal); if (reset) doc.Reset(); try { doc.Sheet = doc.Wb.Worksheets[doc.SheetN]; } catch (Exception e) { err += "no SheetN"; ex = doc.SheetN; doc = null; } if (doc != null) doc.Body = FileOp.getSheetValue(doc.Sheet); } } } // end if(!doc.isOpen) if (doc != null) { doc.isOpen = true; if (doc.type != Decl.TSMATCH) doc.il = doc.Body.iEOL(); } else if (fatal) { Message.Message Msg = new Message.Message(); Msg.F(err, ex, name); } Log.exit(); return doc; }