예제 #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
 //public void wrDoc(string form_name, params object[] objs)
 //{
 //    wrDoc(form_name, objs);
 //}
 ////////public void wrDoc(int iForm, object[] lst) // List<T> lst)
 ////////{
 ////////    Form frm = forms.Find(x => x.name == forms[iForm].name);
 ////////    string format_name = frm.name + "_F";
 ////////    if (!FileOp.isNamedRangeExist(Wb, format_name)) Msg.F("ERR __!!__.NOFORM_F", frm.name);
 ////////    object[] obj = new object[lst.Count];
 ////////    //!!-- fill obj[]
 ////////    wrDoc(frm.name, obj);
 ////////}
 ////public void wrDoc(string str)
 ////{
 ////    object[] t = { Lib.timeStr() };
 ////    wrDoc(str, t);
 ////    Body[1, 1] = t[0];
 ////}
 public void wrDoc(List<int> rows, List<int> cols, List<int> rFr, List<int> cFr)
 {
     Log.set("wrDoc(List rows, List cols, List rFr, List cFr)");
     Mtr tmpBody = FileOp.getSheetValue(this.Sheet);
     throw new NotImplementedException();
     Log.exit();
 }
예제 #3
0
        } // 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;
        }
예제 #4
0
 /// <summary>
 /// EOL(int tocRow) - setup this Document int numbers EndEOLinTOC, i0, and il - main table borders
 /// <para>when TSmatch.xlsx document handled, 'EOL' could be in il TOC column</para>
 /// </summary>
 /// <param name="tocRow">line number of this Document in TOC</param>
 /// <history>19.3.2016
 /// 2017.8.2 - bug fix; EOL works for TSmatch Document type only
 /// </history>
 void EOL(int tocRow)
 {
     i0 = Lib.ToInt(toc.Body.Strng(tocRow, Decl.DOC_I0));
     string str = toc.Body.Strng(tocRow, Decl.DOC_IL);
     if (str == "EOL")
     {
         if (type != Decl.TSMATCH) Msg.F("Shouldn't be 'EOL' here in TSmatch/TOC", tocRow);
         string shN = toc.Body.Strng(tocRow, Decl.DOC_SHEET);
         Mtr m;
         if (shN == Decl.DOC_TOC) m = toc.Body;
         else m = FileOp.getSheetValue(toc.Wb.Worksheets[shN]);
         il = m.iEOL();
     }
     else il = Lib.ToInt(str);
 }
예제 #5
0
        //internal void wrDoсForm(string dir, string v, DateTime date, string mD5, int count, string strListRules)
        //{
        //    throw new NotImplementedException();
        //}

        /// <summary>
        /// wrDoc(str, obect[] obj) -- write data from array of objects to the Document in Excel
        /// </summary>
        /// <param name="str">form name; "str_F" format is also accounted</param>
        /// <param name="obg">data array to be written</param>
        /// <history>16.3.2016
        /// 26.3.2016 - output HDR_ form with time.Now in [1,1]
        ///  3.4.2016 - multiple line output support with last_name
        /// 13.4.2016 - Internal error message, when form not found
        /// 22.8.2016 - auditted: if(obj is Array); i0+1
        /// </history>
        public void wrDoc(string formName, params object[] obj)
        {
            Log.set("wrDoc(" + formName + ", obj[])");

            if (obj is Array)
            {
                int objLng = obj.Length;
                object[] _obj = obj;
                //--------------- not implemented yet
                if (obj[0] is Array)
                {

                }
            }
            //           Type ob = typeof(obj);  //.IsAssignableFrom(type); 

            Form frm = forms.Find(x => x.name == formName);
            if (frm == null) Msg.F("Document.wrDoc no form", formName, this.name);
            if (frm.col.Count != frm.row.Count) Msg.F("wrDoc Form corrupted"
                , formName, frm.row.Count, frm.col.Count);
            if (frm.col.Count != obj.Length) Msg.F("wrDoc wrong agroments", obj);
            if (frm.name == Form.last_name)
            {
                Body.AddRow(obj);
            }
            else
            {
                saveDoc();
                int lineInBodyToWrite = Form.nStr < 1 ? Body.iEOL() : Form.nStr;
                Excel.Range rng = FileOp.setRange(Sheet, lineInBodyToWrite);
                Document toc = getDoc();
                FileOp.CopyRng(toc.Wb, formName, rng);
                Body = FileOp.getSheetValue(Sheet);
                FileOp.saveRngValue(Body);
                int i = 0;
                foreach (var v in obj)
                {
                    int r = frm.row[i] + lineInBodyToWrite - 1;
                    int c = frm.col[i++];
                    Body[r, c] = v;
                }
                FileOp.saveRngValue(Body, 1, AutoFit: frm.AutoFit);
                Form.last_name = frm.name;
            }
            Log.exit();
        }
예제 #6
0
        /// <summary>
        /// saveDoc(doc [,BodySave, string MD5]) - сохраняет Документ в Excel файл, если он изменялся
        /// </summary>
        /// <param name="name">имя документа</param>
        /// <param name="BodySave>true - doc.Body нужно сохранить, false - уже в Excel</param>
        /// <param name="MD5">MD5 документа. Если BodySave = false - обязательно</param>
        /// <history>10.1.2016
        /// 18.1.16 - аккуратная обработка BodySave=false и MD5
        /// 20.1.16 - fix bug: not write EOLinTOC for TSmatch type Documents
        /// 1.04.16 - overlay saveDoc(..)
        /// </history>
        public static void saveDoc(Document doc, bool BodySave = true, string MD5 = "", int EOL = 0)
        {
            Log.set("saveDoc(\"" + doc.name + "\")");
            try
            {
                Document toc = Documents[Decl.DOC_TOC];
                if (doc.type == Decl.DOC_TYPE_N) doc.isChanged = true;
                if (doc.isChanged)
                {
                    int EOLinTOC = EOL;
                    if (BodySave)
                    {
                        FileOp.setRange(doc.Sheet);
                        FileOp.saveRngValue(doc.Body);
//24/4/17                        doc.chkSum = doc.Body.ComputeMD5();
//2/8/17 removed EOLinTOC                       doc.EOLinTOC = doc.Body.iEOL();
                        doc.il = doc.Body.iEOL();
                        FileOp.fileSave(doc.Wb);
                        doc.isChanged = false;
                    }
                    else
                    {
                        if (MD5.Length < 20 || EOL == 0) { Message.Message Msg = new Message.Message(); Msg.F("ERR_05.8_saveDoc_NOMD5"); }
                        //2/8/17 removed EOLinTOC                        else { doc.chkSum = MD5; doc.EOLinTOC = EOLinTOC; }
                        else { doc.chkSum = MD5; doc.il = EOLinTOC; }
                    }
                    Mtr tmp = FileOp.getSheetValue(toc.Sheet);
                    for (int n = toc.i0; n <= toc.il; n++)
                    {   // находим и меняем строку документа doc TOC
                        if ((string)toc.Body[n, Decl.DOC_NAME] != doc.name) continue;
                        tmp[1, 1] = Lib.timeStr();
                        tmp[n, Decl.DOC_TIME] = Lib.timeStr();
                        tmp[n, Decl.DOC_MD5] = doc.chkSum;
                        if (doc.type == "N") tmp[n, Decl.DOC_CREATED] = Lib.timeStr();
//2/8/17 removed EOLinTOC                        if (doc.type != Decl.TSMATCH_TYPE) tmp[n, Decl.DOC_EOL] = doc.EOLinTOC;
                        if (doc.type != Decl.TSMATCH_TYPE) tmp[n, Decl.DOC_EOL] = doc.il;
                        FileOp.setRange(toc.Sheet);
                        FileOp.saveRngValue(tmp, AutoFit: false);  //======= save TОC in TSmatch.xlsx
                        break;
                    }
                }
            }
            catch (Exception e) { Log.FATAL("Ошибка \"" + e.Message + "\" сохранения файла \"" + doc.name + "\""); }
            Log.exit();
        }
예제 #7
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();
 }
예제 #8
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
 ///  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;
 }