using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; namespace XLIMS.CORE.Helpers { public class Svid { #region Constructor public Svid(DMS document, XLAB7Repository repository, int copies = 1) { _copies = copies; _document = document; _repository = repository; _fi = new FileInfo(@"Resources\DOCX\Svid.docx"); _wordApp = new Application(); _wordDocument = _wordApp.Documents.Open(_fi.FullName); } #endregion //Constructor #region Fields private Application _wordApp; private Microsoft.Office.Interop.Word.Document _wordDocument; private object _wFalse = false; private object _wTrue = true; private object _missing = null; private FileInfo _fi; private DMS _document; private Table _table; private int _copies; private XLAB7Repository _repository; #endregion //Fields #region Properties #endregion //Properties #region Mehtods private void Replace(string text, string replacementText) { Find find = _wordApp.Selection.Find; find.Text = text; find.Replacement.Text = replacementText; find.Execute(FindText: Type.Missing, MatchCase: false, MatchWholeWord: false, MatchWildcards: false, MatchSoundsLike: Type.Missing, MatchAllWordForms: false, Forward: true, Wrap: Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue, Format: false, ReplaceWith: Type.Missing, Replace: Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll); } public void Print() { var ekzmk = _repository.GetEKZMK().Result.FirstOrDefault(f => f.IDEKZMK == _document.IDOD); Replace("number", _document.NND); Replace("nextpovdate", ((DateTime)ekzmk.IDEKZNavigation.EKZMCP.FirstOrDefault().DTMKPLO).ToLongDateString()); Replace("name", ekzmk.IDEKZNavigation.IDTPRZNavigation.IDTIPSNavigation.IDSPNMTPNavigation.NMTP); Replace("serial", ekzmk.IDEKZNavigation.NNZV); Replace("type", ekzmk.IDEKZNavigation.IDTPRZNavigation.IDTIPSNavigation.TP); Replace("gr", ekzmk.IDEKZNavigation.IDTPRZNavigation.IDTIPSNavigation.NNTPGR); Replace("method", ""); Replace("temp", ekzmk.EKZMKFCTVL.FirstOrDefault(f=>f.IDSPIV==1000).ZNFCTVLMIN.ToString()); Replace("hum", ekzmk.EKZMKFCTVL.FirstOrDefault(f => f.IDSPIV == 1002).ZNFCTVLMIN.ToString()); Replace("press", ekzmk.EKZMKFCTVL.FirstOrDefault(f => f.IDSPIV == 1001).ZNFCTVLMIN.ToString()); Replace("count", ""); Replace("person", ekzmk.IDPRSNNavigation.PRFIO); Replace("date", ((DateTime)ekzmk.DTMKFK).ToLongDateString()); _wordDocument.PrintOut(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, _copies); _wordDocument.Close(_wFalse); _wordApp.Quit(); } #endregion //Mehtods } }