From f2c8ac8740ff52c467960b87d63fd8d7db804528 Mon Sep 17 00:00:00 2001 From: Rich Date: Thu, 28 Feb 2013 23:36:45 +0000 Subject: [PATCH] Update the Progress Bar as the RO values are refreshed in Word --- PROMS/VEPROMS User Interface/frmVEPROMS.cs | 22 +++++++++++ .../Extension/DocumentExt.cs | 28 +++++++++---- PROMS/Volian.Controls.Library/DSOTabPanel.cs | 7 +++- .../DisplayTabControl.cs | 39 +++++++++++++++++++ 4 files changed, 88 insertions(+), 8 deletions(-) diff --git a/PROMS/VEPROMS User Interface/frmVEPROMS.cs b/PROMS/VEPROMS User Interface/frmVEPROMS.cs index b755369c..2f485e58 100644 --- a/PROMS/VEPROMS User Interface/frmVEPROMS.cs +++ b/PROMS/VEPROMS User Interface/frmVEPROMS.cs @@ -572,6 +572,7 @@ namespace VEPROMS //displayRO.EnabledChanged += new EventHandler(displayRO_EnabledChanged); tc.Enter += new EventHandler(tc_Enter); tc.Leave += new EventHandler(tc_Leave); + tc.StatusChanged += new DisplayTabControlStatusEvent(tc_StatusChanged); tc.ToggleRibbonExpanded += new DisplayTabControlEvent(tc_ToggleRibbonExpanded); this.Deactivate += new EventHandler(frmVEPROMS_Deactivate); if (VlnSettings.DemoMode) StepRTB.MyFontFamily = GetFamily("Bookman Old Style"); @@ -594,6 +595,27 @@ namespace VEPROMS StepTabRibbon.PasteNoReturnsSetting = Properties.Settings.Default.PasteNoReturns; StepTabRibbon.PastePlainTextSetting = Properties.Settings.Default.PastePlainText; } + void tc_StatusChanged(object sender, DisplayTabControlStatusEventArgs args) + { + switch (args.Type) + { + case VolianStatusType.Initialize: + ProgBarMax = args.Count; + ProgBarText = args.Text; + ProgBarValue = 0; + break; + case VolianStatusType.Update: + ProgBarText = args.Text; + ProgBarValue = args.Count; + break; + case VolianStatusType.Complete: + ProgBarText = args.Text; + ProgBarValue = 0; + break; + default: + break; + } + } void tmrShutDown_Tick(object sender, EventArgs e) { (sender as Timer).Enabled = false; diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs index 329b5bdd..a6889d2c 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs @@ -17,6 +17,13 @@ using System.Diagnostics; namespace VEPROMS.CSLA.Library { + public enum VolianStatusType + { + Initialize, + Update, + Complete + } + public delegate void VolianStatusChange(VolianStatusType type, int count, string text); public partial class Document { public string DocumentTitle @@ -363,7 +370,7 @@ namespace VEPROMS.CSLA.Library _MyFile = new FileInfo(value); } } - public void SaveFile(float length, string ascii, ItemInfo myItemInfo, bool cvtLibDoc) + public void SaveFile(float length, string ascii, ItemInfo myItemInfo, bool cvtLibDoc, VolianStatusChange statusChange) { // TODO: Add Try & Catch logic if (_MyDocument == null) return; @@ -405,7 +412,7 @@ namespace VEPROMS.CSLA.Library doc.DTS = _MyFile.LastWriteTimeUtc; doc = doc.Save(); List roids = new List(); - string pdfTmp = MSWordToPDF.ToPDFReplaceROs(_MyDocument, roids, myItemInfo); + string pdfTmp = MSWordToPDF.ToPDFReplaceROs(_MyDocument, roids, myItemInfo,statusChange); FileInfo pdfFile = new FileInfo(pdfTmp); fs = pdfFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); buf = new byte[pdfFile.Length]; @@ -516,7 +523,7 @@ namespace VEPROMS.CSLA.Library List roids = new List(); try { - pdfTmp = MSWordToPDF.ToPDFReplaceROs(docInfo,roids,sect); + pdfTmp = MSWordToPDF.ToPDFReplaceROs(docInfo,roids,sect,null); } catch (Exception ex) { @@ -548,13 +555,13 @@ namespace VEPROMS.CSLA.Library docInfo.RefreshConfig(); return true; } - public static string ToPDFReplaceROs(DocumentInfo doc,List roids, ItemInfo sect) + public static string ToPDFReplaceROs(DocumentInfo doc, List roids, ItemInfo sect, VolianStatusChange statusChange) { //ItemInfo sect = doc.DocumentEntries[0].MyContent.ContentItems[0]; - return ToPDFReplaceROs(sect, false, roids); + return ToPDFReplaceROs(sect, false, roids, statusChange); } private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public static string ToPDFReplaceROs(ItemInfo sect, bool openPdf, List roids) //, System.Drawing.Color overrideColor, System.Windows.Forms.Form myForm) + public static string ToPDFReplaceROs(ItemInfo sect, bool openPdf, List roids, VolianStatusChange statusChange) //, System.Drawing.Color overrideColor, System.Windows.Forms.Form myForm) { string fileName = GetFileName(sect); // TODO: do we want to cache the word pdfs @@ -653,9 +660,14 @@ namespace VEPROMS.CSLA.Library selxy.WholeStory(); selxy = FindXyPlot(); } - LBSelection sel = hasRos ? FindRO() : null; + LBSelection sel = MyApp.Selection; + sel.WholeStory(); + if(statusChange != null) statusChange(VolianStatusType.Initialize, sel.End, "Refreshing ROs"); + sel = hasRos ? FindRO() : null; + int roCount = 0; while (sel != null) { + if (statusChange != null) statusChange(VolianStatusType.Update, sel.Start, string.Format("{0} ROs Refreshed", ++roCount)); string val = lookup.GetROValueByAccPagID(sel.Text, spPrefix, igPrefix); int? type = lookup.GetROTypeByAccPagID(sel.Text, spPrefix, igPrefix); // if type is null, then set type to zero so that InsertROValue will put in "RO Not Found" for the value @@ -753,6 +765,7 @@ namespace VEPROMS.CSLA.Library } sel = FindRO(); } + if (statusChange != null) statusChange(VolianStatusType.Update, 0, "Creating PDF"); sel = MyApp.Selection; sel.WholeStory(); //sel.Range.Font.Color = (LBWdColor)WordColor(PrintOverride.OverrideTextColor(System.Drawing.Color.Black)); @@ -764,6 +777,7 @@ namespace VEPROMS.CSLA.Library { CloseAppAfterWait(); } + if (statusChange != null) statusChange(VolianStatusType.Complete, 0, ""); return fileName; } } diff --git a/PROMS/Volian.Controls.Library/DSOTabPanel.cs b/PROMS/Volian.Controls.Library/DSOTabPanel.cs index 0f269e5b..52242ee9 100644 --- a/PROMS/Volian.Controls.Library/DSOTabPanel.cs +++ b/PROMS/Volian.Controls.Library/DSOTabPanel.cs @@ -347,7 +347,7 @@ namespace Volian.Controls.Library DialogResult ans = MessageBox.Show("Save as Library Document for all usages?", "Document Save", MessageBoxButtons.YesNo); if (ans == DialogResult.No) cvtLibDoc = true; } - MyDSOFile.SaveFile(doc.Length,doc.Ascii,MyDisplayTabItem.MyItemInfo, cvtLibDoc); + MyDSOFile.SaveFile(doc.Length, doc.Ascii, MyDisplayTabItem.MyItemInfo, cvtLibDoc, StatusChanged); if (cvtLibDoc) { MyDisplayTabItem.Text = MyDisplayTabItem.MyItemInfo.TabTitle; @@ -355,6 +355,11 @@ namespace Volian.Controls.Library MyDisplayTabItem.SetPrivateTooltip(MyDisplayTabItem.MyItemInfo.TabToolTip); } } + public void StatusChanged(VolianStatusType type, int count, string text) + { + DisplayTabControl tc = Parent.Parent.Parent as DisplayTabControl; + tc.ONStatusChanged(this, new DisplayTabControlStatusEventArgs(type, count, text)); + } /// /// Before a document closes check to see if it's contents should be saved. /// diff --git a/PROMS/Volian.Controls.Library/DisplayTabControl.cs b/PROMS/Volian.Controls.Library/DisplayTabControl.cs index 3ff6ae6d..84dd23d3 100644 --- a/PROMS/Volian.Controls.Library/DisplayTabControl.cs +++ b/PROMS/Volian.Controls.Library/DisplayTabControl.cs @@ -12,8 +12,47 @@ using DevComponents.DotNetBar; namespace Volian.Controls.Library { public delegate void DisplayTabControlEvent(object sender,EventArgs args); + public delegate void DisplayTabControlStatusEvent(object sender, DisplayTabControlStatusEventArgs args); + public partial class DisplayTabControlStatusEventArgs : EventArgs + { + private VolianStatusType _Type; + public VolianStatusType Type + { + get { return _Type; } + set { _Type = value; } + } + private int _Count; + public int Count + { + get { return _Count; } + set { _Count = value; } + } + private string _Text; + public string Text + { + get { return _Text; } + set { _Text = value; } + } + public DisplayTabControlStatusEventArgs() + { + _Type = VolianStatusType.Initialize; + _Count = 0; + _Text = "Default"; + } + public DisplayTabControlStatusEventArgs(VolianStatusType type, int count, string text) + { + _Type = type; + _Count = count; + _Text = text; + } + } public partial class DisplayTabControl : UserControl { + public event DisplayTabControlStatusEvent StatusChanged; + public void ONStatusChanged(object Sender, DisplayTabControlStatusEventArgs args) + { + if (StatusChanged != null) StatusChanged(Sender, args); + } public event DisplayTabControlEvent ToggleRibbonExpanded; public void OnToggleRibbonExpanded(object sender, EventArgs args) {