//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(); }
/// <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(); }
/// <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(); }