예제 #1
0
 /// <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;
 }
예제 #2
0
 /// <summary>
 /// Reset() - "Reset" of the Document. All contents of hes Excel Sheet erased, write Header form
 /// Reset("Now") - write DataTime.Now string in Cell [1,1]
 /// </summary>
 /// <history>9.1.2014
 /// 17.1.16 - полностью переписано с записью Шапки
 /// 16.3.16 - header name get from doc.forms[0]
 /// 26.3.16 - Reset("Now")
 /// 27.3.16 - bug fixed. Issue was: Reset named as a doc.name instead SheetN
 /// </history>
 public void Reset(string str = "")
 {
     Log.set("Reset(" + this.name + ")");
     Document toc = getDoc();
     this.Sheet = FileOp.SheetReset(this.Wb, this.SheetN);
     Excel.Range rng = FileOp.setRange(this.Sheet);
     if (this.forms.Count == 0) Msg.F("Document.Reset no HDR form", this.name);
     string myHDR_name = this.forms[0].name;
     FileOp.CopyRng(toc.Wb, myHDR_name, rng);
     this.Body = FileOp.getSheetValue(this.Sheet);
     if (str == "Now")
     {
         Body[1, 1] = Lib.timeStr();
         FileOp.setRange(this.Sheet);
         FileOp.saveRngValue(Body);
     }
     Log.exit();
 }