//public Action SelectAction; public void load(TemplateInfo templateInfo, bool isEditable = false) { _isEditable = isEditable; mainGrid.DataContext = templateInfo; _argInfoList = Tools.GetArgInfoList(templateInfo, out _tmpReulst); intialArgList(); if (argTabControl.Items.Count != 0) { argTabControl.SelectedIndex = 0; } }
public static List<ArgInfo> GetArgInfoList(TemplateInfo templateInfo, out string result) { if (templateInfo == null) { result = "未发现模板对象"; return null; } var origArgInfoList = WindowsTools.XmlDeseerializer(typeof (List<ArgInfo>), ArgConfigPath, out result) as List<ArgInfo>; if (origArgInfoList == null) { return null; } return origArgInfoList.Where(p => p.templateName == templateInfo.templateName).OrderBy(p => p.argNo).ToList(); }
private void analyzeFile() { var task = new Thread(() => { _templateInfo = new TemplateInfo { templatePath = string.Format(@"{0}\templateFiles\{1}", Environment.CurrentDirectory,_file.Name), templateID = Guid.NewGuid(), templateSize = _file.Length.ToString(CultureInfo.InvariantCulture), templateName = _file.Name, updatetime = DateTime.Now, rowid = Guid.NewGuid() }; var argListTmpe = ReportOfficeTools.GetArgInfoListFromWord(_templateInfo, out _tmpResult); if (_tmpResult != "") { WorkWindow.ShowError(_tmpResult); } else { _tmpResult = Tools.UpdateArgConfig(argListTmpe); if (_tmpResult == "") { _templateInfo.templatePath = string.Format(@".\templateFiles\{0}",_file.Name); _tmpResult = Tools.UpdateTemplateConfig(_templateInfo); } } Dispatcher.Invoke(_analyzeFinished, _tmpResult); }); task.Start(); }
public static void ShowArgInfoControl(ArgInfo argInfo, TemplateInfoControl templateInfoControl, TemplateInfo templateInfo) { var w = new MetroWindow {Height = 430, Width = 600, EnableDWMDropShadow = true, ResizeMode = ResizeMode.NoResize}; w.LostFocus += (ss, ee) => w.Focus(); w.Title = "参数信息"; w.WindowStartupLocation = WindowStartupLocation.CenterScreen; var control = new ArgInfoControl(); control.Load(argInfo); control.OnCancelClose += (sender, args) => w.Close(); control.OnOkClose += (ss, ee) => { if (Tools.UpdateArgConfig(argInfo) != "") { return; } templateInfoControl.Load(templateInfo, true); w.Close(); }; w.Content = control; w.ShowDialog(); }
public static string UpdateTemplateConfig(TemplateInfo templateInfo) { var origTemplateInfoList = WindowsTools.XmlDeseerializer(typeof (List<TemplateInfo>), TemplateConfigPath, out _tmpResult) as List<TemplateInfo>; if (origTemplateInfoList == null || _tmpResult != "") { return _tmpResult; } origTemplateInfoList = origTemplateInfoList.Where(p => p.templateName != templateInfo.templateName).ToList(); origTemplateInfoList.Add(templateInfo); WindowsTools.XmlSerialize(origTemplateInfoList, TemplateConfigPath, out _tmpResult); return _tmpResult; }
/// <summary> /// /// </summary> /// <param name="templateInfo"></param> /// <param name="result"></param> /// <returns></returns> public static List<ArgInfo> GetArgInfoListFromWord(TemplateInfo templateInfo, out string result) { result = ""; var resultDocArgList = new List<ArgInfo>(); var wordApp = (Application) Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("000209FF-0000-0000-C000-000000000046"))); try { var wordDoc = wordApp.Documents.Open(templateInfo.templatePath, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis); var enumerator = wordDoc.Paragraphs.GetEnumerator(); try { while (enumerator.MoveNext()) { var item = (Paragraph) enumerator.Current; var m = Regex.Matches(item.Range.Text, string.Format(TagFormat, TagDocStart, TagDocEnd)); if (m.Count != 0) { resultDocArgList.AddRange(from Match mItem in m select new ArgInfo { templateID = templateInfo.templateID, templateName = templateInfo.templateName, argType = ArgType.文字.ToString(), argName = mItem.Groups["tag"].Value }); } m = Regex.Matches(item.Range.Text, string.Format(TagFormat, TagTableStart, TagTableEnd)); if (m.Count != 0) { resultDocArgList.AddRange(from Match mItem in m select new ArgInfo { templateID = templateInfo.templateID, templateName = templateInfo.templateName, argType = ArgType.表格.ToString(), argName = mItem.Groups["tag"].Value }); } m = Regex.Matches(item.Range.Text, string.Format(TagFormat, TagGraphStart, TagGraphEnd)); if (m.Count == 0) continue; resultDocArgList.AddRange(from Match mItem in m select new ArgInfo { templateID = templateInfo.templateID, templateName = templateInfo.templateName, argType = ArgType.图形.ToString(), argName = mItem.Groups["tag"].Value }); } } finally { var disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } wordApp.Quit(WdSaveOptions.wdDoNotSaveChanges, ref _mis, ref _mis); } catch (Exception ex) { result = ex.Message; wordApp.Quit(WdSaveOptions.wdDoNotSaveChanges, WdOriginalFormat.wdWordDocument, false); } return resultDocArgList; }