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 Izv { #region Constructor public Izv(DMS document, XLAB7Repository repository, int copies = 1) { _document = document; _repository = repository; _copies = copies; _docs = _repository.GetDMS().Where(w => w.NND == _document.NND).ToList(); _fi = new FileInfo(@"Resources\DOCX\Izv.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 List _docs; 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 = new List(); foreach (var doc in _docs) { try { ekzmk.Add(_repository.GetEKZMK().Result.FirstOrDefault(f => f.IDEKZMK == doc.IDOD)); } catch { continue; } } Replace("number", _document.NND); Replace("name", ekzmk.FirstOrDefault().IDEKZNavigation.IDTPRZNavigation.IDTIPSNavigation.IDSPNMTPNavigation.NMTP); if (ekzmk.Count() > 3) { Replace("serial", ekzmk.Count().ToString()+" шт."); } else { string serials=string.Empty; foreach (var d in ekzmk) { serials += d.IDEKZNavigation.NNZV+", "; } Replace("serial", serials); } Replace("type", ekzmk.FirstOrDefault().IDEKZNavigation.IDTPRZNavigation.IDTIPSNavigation.TP); Replace("gr", ekzmk.FirstOrDefault().IDEKZNavigation.IDTPRZNavigation.IDTIPSNavigation.NNTPGR); Replace("reason", ekzmk.FirstOrDefault().PRCHNPGDN); Replace("method", ""); Replace("dev", ekzmk.FirstOrDefault().IDEKZNavigation.IDFRPDVNavigation.NMFRPD); Replace("person", ekzmk.FirstOrDefault().IDPRSNNavigation.PRFIO); Replace("date", ((DateTime)ekzmk.FirstOrDefault().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 } }