From e492f126024828a212bb82062f68e0b72c9e9d1b Mon Sep 17 00:00:00 2001 From: mschill Date: Thu, 30 Jul 2026 08:15:47 -0400 Subject: [PATCH] AdjustBuildRevision, FlexMsgBx, Formats, LBWordLib, VlnStatus, RoAccessToSql, TablePicker, VG --- PROMS/AdjustBuildRevision/Program.cs | 48 +- .../FlexableMessageBox/FlexibleMessageBox.cs | 103 +- PROMS/Formats/Formats.csproj | 1 + PROMS/Formats/GlobalSuppressions.cs | 8 + PROMS/Formats/Program.cs | 1 - PROMS/Formats/frmFormatCopy.cs | 37 +- PROMS/LBWordLibrary/GlobalSuppressions.cs | 8 + PROMS/LBWordLibrary/LBComObject.cs | 1196 +++++------------ PROMS/LBWordLibrary/LBObjectExtension.cs | 1151 +++++++--------- PROMS/LBWordLibrary/LBWordLibrary.csproj | 1 + PROMS/LBWordLibrary/OutlookLBComObject.cs | 199 +-- PROMS/LBWordLibrary/OutlookLBComObjectExt.cs | 16 +- PROMS/LBWordLibrary/RegHive.cs | 34 +- .../LibSource/VlnStatus/StatusBarFrm.cs | 36 - .../LibSource/VlnStatus/StatusMessageFrm.cs | 25 - .../LibSource/VlnStatus/VlnStatusBar.cs | 5 +- .../LibSource/VlnStatus/VlnStatusMessage.cs | 4 +- PROMS/RoAccessToSql/GlobalSuppressions.cs | 8 + PROMS/RoAccessToSql/Program.cs | 3 - PROMS/RoAccessToSql/RoAccessToSql.cs | 227 ++-- PROMS/RoAccessToSql/RoAccessToSql.csproj | 1 + PROMS/TablePicker/TablePicker.cs | 163 +-- PROMS/VG/IVGOutput.cs | 149 +- PROMS/VG/VG.cs | 207 +-- .../Volian.Controls.Library/DisplaySearch.cs | 12 +- 25 files changed, 1159 insertions(+), 2484 deletions(-) create mode 100644 PROMS/Formats/GlobalSuppressions.cs create mode 100644 PROMS/LBWordLibrary/GlobalSuppressions.cs create mode 100644 PROMS/RoAccessToSql/GlobalSuppressions.cs diff --git a/PROMS/AdjustBuildRevision/Program.cs b/PROMS/AdjustBuildRevision/Program.cs index 773f3aaf..b2a41b3c 100644 --- a/PROMS/AdjustBuildRevision/Program.cs +++ b/PROMS/AdjustBuildRevision/Program.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using System.IO; using System.Text.RegularExpressions; using System.Windows.Forms; @@ -35,31 +33,7 @@ namespace AdjustBuildRevision outline = Regex.Replace(line, @"([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)""\)", DateTime.Now.ToString("2.4.yyMM.dHH") + "\")"); else outline = Regex.Replace(line, @"([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)""\)", DateTime.Now.ToString("2.3.yyMM.dHH") + "\")"); - // if (outline != line) - // { - // Console.WriteLine("Before: '{0}'", line); - // Console.WriteLine("After: '{0}'", outline); - // lines[i] = outline; - // changed = true; - // } - // else - // { - // Console.WriteLine("No change: '{0}'", line); - // } - // } - //} - //if (changed) - //{ - // if (!fi.IsReadOnly) fi.IsReadOnly = false; - // StreamWriter sw = fi.CreateText(); - // foreach (string line in lines) - // sw.WriteLine(line); - // sw.Close(); - // string line = lines[i]; - // string outline = line; - // if (line.Contains("AssemblyVersion") || line.Contains("AssemblyFileVersion")) - // { - //outline = Regex.Replace(line, @"([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)""\)", DateTime.Now.ToString("1.1.yyMM.dHH") + "\")"); + if (outline != line) { Console.WriteLine("Before: '{0}'", line); @@ -84,7 +58,7 @@ namespace AdjustBuildRevision } else { - MessageBox.Show("File " + fi.FullName + " does not exist"); + MessageBox.Show($"File {fi.FullName} does not exist"); } } catch (Exception ex) @@ -93,10 +67,6 @@ namespace AdjustBuildRevision } } - //private static DateTime GetLatestDateTime(string path) - //{ - // return GetLatestDateTime(new DirectoryInfo(path)); - //} private static DateTime GetLatestDateTime(DirectoryInfo di, DateTime dtCheck) { DateTime dtMax = dtCheck; @@ -104,24 +74,14 @@ namespace AdjustBuildRevision foreach(FileInfo myFile in myFiles) { DateTime dt = myFile.LastWriteTime; - //if (dt > dtCheck) - //{ - //Console.WriteLine("\"File\"\t\"{0}\"\t\"{1}\"\t{2}\t{3}",myFile.FullName,dt.ToString("1.1.yyMM.dHH"),dt,dtCheck); - if(dtMax < dt) dtMax = dt; - //} + if(dtMax < dt) dtMax = dt; } DirectoryInfo[] myFolders = di.GetDirectories(); foreach (DirectoryInfo diChild in myFolders) { DateTime dtChild = GetLatestDateTime(diChild,dtCheck); - //if (dtChild > dtCheck) - //{ - //Console.WriteLine("\"SubFolder\"\t\"{0}\"\t\"{1}\"\t{2}\t{3}", diChild.FullName, dtChild.ToString("1.1.yyMM.dHH"),dtChild,dtCheck); - if(dtChild > dtMax) dtMax = dtChild; - //} + if(dtChild > dtMax) dtMax = dtChild; } - //if(dtMax > dtCheck) - // Console.WriteLine("\"Folder\"\t\"{0}\"\t\"{1}\"", di.FullName, dtMax.ToString("1.1.yyMM.dHH")); return dtMax; } } diff --git a/PROMS/FlexableMessageBox/FlexibleMessageBox.cs b/PROMS/FlexableMessageBox/FlexibleMessageBox.cs index 535b983a..1eb8b401 100644 --- a/PROMS/FlexableMessageBox/FlexibleMessageBox.cs +++ b/PROMS/FlexableMessageBox/FlexibleMessageBox.cs @@ -1,8 +1,6 @@ using System; using System.Diagnostics; using System.Drawing; -using System.Globalization; -//using System.Linq; using System.Windows.Forms; @@ -121,10 +119,7 @@ namespace JR.Utils.GUI.Forms /// /// The text. /// The dialog result. - public static DialogResult Show(string text) - { - return FlexibleMessageBoxForm.Show(null, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); - } + public static DialogResult Show(string text) => FlexibleMessageBoxForm.Show(null, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); /// /// Shows the specified message box. @@ -132,10 +127,7 @@ namespace JR.Utils.GUI.Forms /// The owner. /// The text. /// The dialog result. - public static DialogResult Show(IWin32Window owner, string text) - { - return FlexibleMessageBoxForm.Show(owner, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); - } + public static DialogResult Show(IWin32Window owner, string text) => FlexibleMessageBoxForm.Show(owner, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); /// /// Shows the specified message box. @@ -143,10 +135,7 @@ namespace JR.Utils.GUI.Forms /// The text. /// The caption. /// The dialog result. - public static DialogResult Show(string text, string caption) - { - return FlexibleMessageBoxForm.Show(null, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); - } + public static DialogResult Show(string text, string caption) => FlexibleMessageBoxForm.Show(null, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); /// /// Shows the specified message box. @@ -155,10 +144,7 @@ namespace JR.Utils.GUI.Forms /// The text. /// The caption. /// The dialog result. - public static DialogResult Show(IWin32Window owner, string text, string caption) - { - return FlexibleMessageBoxForm.Show(owner, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); - } + public static DialogResult Show(IWin32Window owner, string text, string caption) => FlexibleMessageBoxForm.Show(owner, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); /// /// Shows the specified message box. @@ -167,10 +153,7 @@ namespace JR.Utils.GUI.Forms /// The caption. /// The buttons. /// The dialog result. - public static DialogResult Show(string text, string caption, MessageBoxButtons buttons) - { - return FlexibleMessageBoxForm.Show(null, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); - } + public static DialogResult Show(string text, string caption, MessageBoxButtons buttons) => FlexibleMessageBoxForm.Show(null, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); /// /// Shows the specified message box. @@ -180,10 +163,7 @@ namespace JR.Utils.GUI.Forms /// The caption. /// The buttons. /// The dialog result. - public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons) - { - return FlexibleMessageBoxForm.Show(owner, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); - } + public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons) => FlexibleMessageBoxForm.Show(owner, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); /// /// Shows the specified message box. @@ -193,10 +173,7 @@ namespace JR.Utils.GUI.Forms /// The buttons. /// The icon. /// - public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) - { - return FlexibleMessageBoxForm.Show(null, text, caption, buttons, icon, MessageBoxDefaultButton.Button1); - } + public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) => FlexibleMessageBoxForm.Show(null, text, caption, buttons, icon, MessageBoxDefaultButton.Button1); /// /// Shows the specified message box. @@ -207,10 +184,7 @@ namespace JR.Utils.GUI.Forms /// The buttons. /// The icon. /// The dialog result. - public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) - { - return FlexibleMessageBoxForm.Show(owner, text, caption, buttons, icon, MessageBoxDefaultButton.Button1); - } + public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) => FlexibleMessageBoxForm.Show(owner, text, caption, buttons, icon, MessageBoxDefaultButton.Button1); /// /// Shows the specified message box. @@ -221,10 +195,7 @@ namespace JR.Utils.GUI.Forms /// The icon. /// The default button. /// The dialog result. - public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton) - { - return FlexibleMessageBoxForm.Show(null, text, caption, buttons, icon, defaultButton); - } + public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton) => FlexibleMessageBoxForm.Show(null, text, caption, buttons, icon, defaultButton); /// /// Shows the specified message box. @@ -236,10 +207,7 @@ namespace JR.Utils.GUI.Forms /// The icon. /// The default button. /// The dialog result. - public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton) - { - return FlexibleMessageBoxForm.Show(owner, text, caption, buttons, icon, defaultButton); - } + public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton) => FlexibleMessageBoxForm.Show(owner, text, caption, buttons, icon, defaultButton); /// /// Shows the specified message box. @@ -251,10 +219,8 @@ namespace JR.Utils.GUI.Forms /// The icon. /// The default button. /// The dialog result. - public static DialogResult ShowCustom(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) - { - return FlexibleMessageBoxForm.ShowCustom(null, text, caption, buttons, icon); - } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping owner for legacy reasons")] + public static DialogResult ShowCustom(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) => FlexibleMessageBoxForm.ShowCustom(null, text, caption, buttons, icon); #endregion @@ -341,7 +307,7 @@ namespace JR.Utils.GUI.Forms this.richTextBoxMessage.TabIndex = 0; this.richTextBoxMessage.TabStop = false; this.richTextBoxMessage.Text = ""; - this.richTextBoxMessage.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.richTextBoxMessage_LinkClicked); + this.richTextBoxMessage.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.RichTextBoxMessage_LinkClicked); // // panel1 // @@ -431,8 +397,8 @@ namespace JR.Utils.GUI.Forms #region Private constants //These separators are used for the "copy to clipboard" standard operation, triggered by Ctrl + C (behavior and clipboard format is like in a standard MessageBox) - private static readonly String STANDARD_MESSAGEBOX_SEPARATOR_LINES = "---------------------------\n"; - private static readonly String STANDARD_MESSAGEBOX_SEPARATOR_SPACES = " "; + private static readonly string STANDARD_MESSAGEBOX_SEPARATOR_LINES = "---------------------------\n"; + private static readonly string STANDARD_MESSAGEBOX_SEPARATOR_SPACES = " "; //These are the possible buttons (in a standard MessageBox) private enum ButtonID { OK = 0, CANCEL, YES, NO, ABORT, RETRY, IGNORE, OVERWRITE, RENAME }; @@ -440,10 +406,10 @@ namespace JR.Utils.GUI.Forms //These are the buttons texts for different languages. //If you want to add a new language, add it here and in the GetButtonText-Function private enum TwoLetterISOLanguageID { en, de, es, it }; - private static readonly String[] BUTTON_TEXTS_ENGLISH_EN = { "OK", "Cancel", "&Yes", "&No", "&Abort", "&Retry", "&Ignore", "&Overwrite", "&Rename" }; //Note: This is also the fallback language - private static readonly String[] BUTTON_TEXTS_GERMAN_DE = { "OK", "Abbrechen", "&Ja", "&Nein", "&Abbrechen", "&Wiederholen", "&Ignorieren", "&Overwrite", "&Rename" }; - private static readonly String[] BUTTON_TEXTS_SPANISH_ES = { "Aceptar", "Cancelar", "&Sí", "&No", "&Abortar", "&Reintentar", "&Ignorar", "&Overwrite", "&Rename" }; - private static readonly String[] BUTTON_TEXTS_ITALIAN_IT = { "OK", "Annulla", "&Sì", "&No", "&Interrompi", "&Riprova", "&Ignora", "&Overwrite", "&Rename" }; + private static readonly string[] BUTTON_TEXTS_ENGLISH_EN = { "OK", "Cancel", "&Yes", "&No", "&Abort", "&Retry", "&Ignore", "&Overwrite", "&Rename" }; //Note: This is also the fallback language + private static readonly string[] BUTTON_TEXTS_GERMAN_DE = { "OK", "Abbrechen", "&Ja", "&Nein", "&Abbrechen", "&Wiederholen", "&Ignorieren", "&Overwrite", "&Rename" }; + private static readonly string[] BUTTON_TEXTS_SPANISH_ES = { "Aceptar", "Cancelar", "&Sí", "&No", "&Abortar", "&Reintentar", "&Ignorar", "&Overwrite", "&Rename" }; + private static readonly string[] BUTTON_TEXTS_ITALIAN_IT = { "OK", "Annulla", "&Sì", "&No", "&Interrompi", "&Riprova", "&Ignora", "&Overwrite", "&Rename" }; #endregion @@ -451,7 +417,7 @@ namespace JR.Utils.GUI.Forms private MessageBoxDefaultButton defaultButton; private int visibleButtonsCount; - private TwoLetterISOLanguageID languageID = TwoLetterISOLanguageID.en; + private readonly TwoLetterISOLanguageID languageID = TwoLetterISOLanguageID.en; #endregion @@ -758,9 +724,9 @@ namespace JR.Utils.GUI.Forms /// The instance containing the event data. private void FlexibleMessageBoxForm_Shown(object sender, EventArgs e) { - int buttonIndexToFocus = 1; Button buttonToFocus; + int buttonIndexToFocus; //Set the default button... switch (this.defaultButton) { @@ -799,7 +765,7 @@ namespace JR.Utils.GUI.Forms /// /// The source of the event. /// The instance containing the event data. - private void richTextBoxMessage_LinkClicked(object sender, LinkClickedEventArgs e) + private void RichTextBoxMessage_LinkClicked(object sender, LinkClickedEventArgs e) { try { @@ -877,12 +843,14 @@ namespace JR.Utils.GUI.Forms public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton) { //Create a new instance of the FlexibleMessageBox form - var flexibleMessageBoxForm = new FlexibleMessageBoxForm(); - flexibleMessageBoxForm.ShowInTaskbar = false; + var flexibleMessageBoxForm = new FlexibleMessageBoxForm + { + ShowInTaskbar = false, - //Bind the caption and the message text - flexibleMessageBoxForm.CaptionText = caption; - flexibleMessageBoxForm.MessageText = text; + //Bind the caption and the message text + CaptionText = caption, + MessageText = text + }; flexibleMessageBoxForm.FlexibleMessageBoxFormBindingSource.DataSource = flexibleMessageBoxForm; //Set the buttons visibilities and texts. Also set a default button. @@ -914,15 +882,18 @@ namespace JR.Utils.GUI.Forms /// The icon. /// The default button. /// The dialog result. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping buttons for legacy reasons")] public static DialogResult ShowCustom(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) { //Create a new instance of the FlexibleMessageBox form - var flexibleMessageBoxForm = new FlexibleMessageBoxForm(); - flexibleMessageBoxForm.ShowInTaskbar = false; + var flexibleMessageBoxForm = new FlexibleMessageBoxForm + { + ShowInTaskbar = false, - //Bind the caption and the message text - flexibleMessageBoxForm.CaptionText = caption; - flexibleMessageBoxForm.MessageText = text; + //Bind the caption and the message text + CaptionText = caption, + MessageText = text + }; flexibleMessageBoxForm.FlexibleMessageBoxFormBindingSource.DataSource = flexibleMessageBoxForm; //Set the buttons visibilities and texts. Also set a default button. diff --git a/PROMS/Formats/Formats.csproj b/PROMS/Formats/Formats.csproj index c73a80c5..63e75909 100644 --- a/PROMS/Formats/Formats.csproj +++ b/PROMS/Formats/Formats.csproj @@ -66,6 +66,7 @@ frmFormatCopy.cs + diff --git a/PROMS/Formats/GlobalSuppressions.cs b/PROMS/Formats/GlobalSuppressions.cs new file mode 100644 index 00000000..046248af --- /dev/null +++ b/PROMS/Formats/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Not modifying Naming Styles")] diff --git a/PROMS/Formats/Program.cs b/PROMS/Formats/Program.cs index ecbbfc91..59ba4f28 100644 --- a/PROMS/Formats/Program.cs +++ b/PROMS/Formats/Program.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Windows.Forms; namespace Formats diff --git a/PROMS/Formats/frmFormatCopy.cs b/PROMS/Formats/frmFormatCopy.cs index be941c3e..e5f3d7fe 100644 --- a/PROMS/Formats/frmFormatCopy.cs +++ b/PROMS/Formats/frmFormatCopy.cs @@ -1,9 +1,4 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; using System.IO; using System.Windows.Forms; @@ -28,7 +23,7 @@ namespace Formats txbxPROMSFormatsPath.Text = savedFormatPath; else { - string curFolder = Environment.CurrentDirectory; // C:\development/PROMS/Formats/bin/debug + string curFolder = Environment.CurrentDirectory; // .../PROMS/Formats/bin/debug int idx = curFolder.ToUpper().IndexOf(@"\PROMS\"); txbxPROMSFormatsPath.Text = curFolder.Substring(0, idx); } @@ -40,9 +35,8 @@ namespace Formats DirectoryInfo di = new DirectoryInfo(path); if (di.Exists == false) //return; { - DialogResult dlgrslt = DialogResult.No; - dlgrslt = MessageBox.Show(string.Format("{0} does not exist. Create it?", path), "Create Folder?", MessageBoxButtons.YesNo); - if (dlgrslt == DialogResult.Yes) + DialogResult dlgrslt = MessageBox.Show(string.Format("{0} does not exist. Create it?", path), "Create Folder?", MessageBoxButtons.YesNo); + if (dlgrslt == DialogResult.Yes) { di.Create(); di.CreateSubdirectory("fmtall"); @@ -86,10 +80,11 @@ namespace Formats private void btnBrowse_Click(object sender, EventArgs e) { - FolderBrowserDialog fbd = new FolderBrowserDialog(); - - fbd.SelectedPath = txbxPROMSFormatsPath.Text; - if (fbd.ShowDialog() == DialogResult.OK) + FolderBrowserDialog fbd = new FolderBrowserDialog + { + SelectedPath = txbxPROMSFormatsPath.Text + }; + if (fbd.ShowDialog() == DialogResult.OK) { if (Directory.Exists(fbd.SelectedPath)) txbxPROMSFormatsPath.Text = fbd.SelectedPath + @"\"; } @@ -116,9 +111,9 @@ namespace Formats if (!txbxPROMSFormatsPath.Text.EndsWith(@"\")) txbxPROMSFormatsPath.Text += @"\"; // There should be a "fmtall" and "genmacall" folder in the delelopment project folder - // ex: C:\development\PROMS\Formats\fmtall and C:\development\PROMS\Formats\genmacall - string destFmtallPath = txbxPROMSFormatsPath.Text + @"fmtall\"; - string destGenmacallPath = txbxPROMSFormatsPath.Text + @"genmacall\"; + // ex: ...\PROMS\Formats\fmtall and ...\PROMS\Formats\genmacall + string destFmtallPath = $@"{txbxPROMSFormatsPath.Text}fmtall\"; + string destGenmacallPath = $@"{txbxPROMSFormatsPath.Text}genmacall\"; string srcFmtallPath = @"..\..\"; // up to levels from startup path // clear the destination fmtall and genmacall folders @@ -156,14 +151,10 @@ namespace Formats } Properties.Settings.Default.FormatPath = txbxPROMSFormatsPath.Text.Substring(0,txbxPROMSFormatsPath.Text.Length-1); // save the copy format path minus the ending backslash Properties.Settings.Default.Save(); - //if(MessageBox.Show("Do you want to end the Format Copier?","Formats Copied.", MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes) - Application.Exit(); - } - - private void buttonX2_Click(object sender, EventArgs e) - { Application.Exit(); } - } + private void buttonX2_Click(object sender, EventArgs e) => Application.Exit(); + + } } \ No newline at end of file diff --git a/PROMS/LBWordLibrary/GlobalSuppressions.cs b/PROMS/LBWordLibrary/GlobalSuppressions.cs new file mode 100644 index 00000000..046248af --- /dev/null +++ b/PROMS/LBWordLibrary/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Not modifying Naming Styles")] diff --git a/PROMS/LBWordLibrary/LBComObject.cs b/PROMS/LBWordLibrary/LBComObject.cs index 8bc36189..e73e8dd0 100644 --- a/PROMS/LBWordLibrary/LBComObject.cs +++ b/PROMS/LBWordLibrary/LBComObject.cs @@ -1,64 +1,46 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Reflection; +using System.Windows.Forms.VisualStyles; namespace LBWordLibrary { public abstract partial class LBComObject { - private Object _Item; - internal Object Item + private object _Item; + internal object Item { get { return _Item; } set { _Item = value; - if (value != null) _MyType = _Item.GetType(); + if (value != null) MyType = _Item.GetType(); } } - private Type _MyType; - public Type MyType - { - get { return _MyType; } - set { _MyType = value; } - } - protected LBComObject() { } + + public Type MyType { get; set; } + protected LBComObject() { } protected LBComObject(string ProgID) { Type objClassType; objClassType = Type.GetTypeFromProgID(ProgID); Item = Activator.CreateInstance(objClassType); } - protected LBComObject(Object item) - { - Item = item; - } - private Object DoInvokeMember(string name, Object[] parameters, BindingFlags bf, Binder b) + protected LBComObject(object item) => Item = item; + private object DoInvokeMember(string name, object[] parameters, BindingFlags bf, Binder b) { try { - return _MyType.InvokeMember(name, bf, b, _Item, parameters); + return MyType.InvokeMember(name, bf, b, _Item, parameters); } catch (Exception ex) { - throw new Exception(string.Format("LBComObject.DoInvokeMember {0}.{1}", _MyType.Name, name), ex); + throw new Exception(string.Format("LBComObject.DoInvokeMember {0}.{1}", MyType.Name, name), ex); } - return null; } - protected void SetProperty(string propertyName, params Object[] parameters) - { - DoInvokeMember(propertyName, parameters, BindingFlags.SetProperty, null); - } - protected Object GetProperty(string propertyName) - { - return DoInvokeMember(propertyName, null, BindingFlags.GetProperty, null); - } - protected Object GetProperty(string propertyName, params Object[] parameters) - { - return DoInvokeMember(propertyName, parameters, BindingFlags.GetProperty, null); - } - protected Object InvokeMethod(string methodName, params Object[] parameters) + protected void SetProperty(string propertyName, params object[] parameters) => DoInvokeMember(propertyName, parameters, BindingFlags.SetProperty, null); + protected object GetProperty(string propertyName) => DoInvokeMember(propertyName, null, BindingFlags.GetProperty, null); + protected object GetProperty(string propertyName, params object[] parameters) => DoInvokeMember(propertyName, parameters, BindingFlags.GetProperty, null); + protected object InvokeMethod(string methodName, params object[] parameters) { if (parameters != null) FixParameters(parameters); @@ -71,150 +53,79 @@ namespace LBWordLibrary if (parameters[i] is LBComObject) parameters[i] = (parameters[i] as LBComObject).Item; } - protected Object InvokeMethod(string methodName) - { - return InvokeMethod(methodName, null); - } - } + protected object InvokeMethod(string methodName) => InvokeMethod(methodName, null); + } public class LBComObjectList : LBComObject where TList : LBComObjectList where TItem : LBComObject, new() { - //public new(Object item):base(item){} public TItem Add() { - TItem tmp = new TItem(); - tmp.Item = InvokeMethod("Add"); - return tmp; + TItem tmp = new TItem + { + Item = InvokeMethod("Add") + }; + return tmp; } - // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content - // Get each item in a collection - public Object this[int item] - { - get - { - return InvokeMethod("Item", item);// Use Item Method to get an entry from an object list - } - } - } + // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content + // Get each item in a collection + public object this[int item] => InvokeMethod("Item", item);// Use Item Method to get an entry from an object list + } public partial class LBApplicationClass : LBComObject { public LBApplicationClass() : base("Word.Application") { } - public LBApplicationClass(Object item) : base(item) { } - public Boolean Visible + public LBApplicationClass(object item) : base(item) { } + public bool Visible { - get { return (GetProperty("Visible") as Boolean? ?? false); } + get { return (GetProperty("Visible") as bool? ?? false); } set { SetProperty("Visible", value); } } - public LBDocuments Documents - { - get { return new LBDocuments(GetProperty("Documents")); } - } - public LBSelection Selection - { - get { return new LBSelection(GetProperty("Selection")); } - } - public LBDocumentClass ActiveDocument - { - get { return new LBDocumentClass(GetProperty("ActiveDocument")); } - } - public LBWindow ActiveWindow - { - get { return new LBWindow(GetProperty("ActiveWindow")); } - } - public String Version - { - get { return (GetProperty("Version").ToString()); } - } - public String ActivePrinter + public LBDocuments Documents => new LBDocuments(GetProperty("Documents")); + public LBSelection Selection => new LBSelection(GetProperty("Selection")); + public LBDocumentClass ActiveDocument => new LBDocumentClass(GetProperty("ActiveDocument")); + public LBWindow ActiveWindow => new LBWindow(GetProperty("ActiveWindow")); + public string Version => (GetProperty("Version").ToString()); + public string ActivePrinter { get { return (GetProperty("ActivePrinter").ToString()); } set { SetProperty("ActivePrinter", value); } } - public int BackgroundPrintingStatus - { - get { return (GetProperty("BackgroundPrintingStatus") as int? ?? 0); } - } - public LBWdWindowState WindowState + public int BackgroundPrintingStatus => (GetProperty("BackgroundPrintingStatus") as int? ?? 0); + public LBWdWindowState WindowState { get { return (LBWdWindowState)GetProperty("WindowState"); } set { SetProperty("WindowState", value); } } - public int BackgroundSavingStatus - { - get { return (GetProperty("BackgroundSavingStatus") as int? ?? 0); } - } - public void Quit() - { - InvokeMethod("Quit", Missing.Value, Missing.Value, Missing.Value); - } - public void Quit(object SaveChanges, object OriginalFormat, object RouteDocument) - { - InvokeMethod("Quit", SaveChanges, OriginalFormat, RouteDocument); - } - public void PrintOut() - { - InvokeMethod("PrintOut", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); - } - public void PrintOut(object Background, object Append, object Range, object OutputFileName, object From, object To, object Item, object Copies, object Pages, object PageType, object PrintToFile, object Collate, object FileName, object ActivePrinterMacGX, object ManualDuplexPrint, object PrintZoomColumn, object PrintZoomRow, object PrintZoomPaperWidth, object PrintZoomPaperHeight) - { - InvokeMethod("PrintOut", Background, Append, Range, OutputFileName, From, To, Item, Copies, Pages, PageType, PrintToFile, Collate, FileName, ActivePrinterMacGX, ManualDuplexPrint, PrintZoomColumn, PrintZoomRow, PrintZoomPaperWidth, PrintZoomPaperHeight); - } - public void Activate() - { - InvokeMethod("Activate"); - } - } + public int BackgroundSavingStatus => (GetProperty("BackgroundSavingStatus") as int? ?? 0); + public void Quit() => InvokeMethod("Quit", Missing.Value, Missing.Value, Missing.Value); + public void Quit(object SaveChanges, object OriginalFormat, object RouteDocument) => InvokeMethod("Quit", SaveChanges, OriginalFormat, RouteDocument); + public void PrintOut() => InvokeMethod("PrintOut", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); + public void PrintOut(object Background, object Append, object Range, object OutputFileName, object From, object To, object Item, object Copies, object Pages, object PageType, object PrintToFile, object Collate, object FileName, object ActivePrinterMacGX, object ManualDuplexPrint, object PrintZoomColumn, object PrintZoomRow, object PrintZoomPaperWidth, object PrintZoomPaperHeight) => InvokeMethod("PrintOut", Background, Append, Range, OutputFileName, From, To, Item, Copies, Pages, PageType, PrintToFile, Collate, FileName, ActivePrinterMacGX, ManualDuplexPrint, PrintZoomColumn, PrintZoomRow, PrintZoomPaperWidth, PrintZoomPaperHeight); + public void Activate() => InvokeMethod("Activate"); + } public partial class LBDocuments : LBComObjectList /* Collection */ { - public LBDocuments(Object item) - { - Item = item; - } - public LBDocumentClass Open(object FileName) - { - return new LBDocumentClass(InvokeMethod("Open", FileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); - } - public LBDocumentClass Open(object FileName, object ConfirmConversions, object ReadOnly, object AddToRecentFiles, object PasswordDocument, object PasswordTemplate, object Revert, object WritePasswordDocument, object WritePasswordTemplate, object Format, object Encoding, object Visible, object OpenAndRepair, object DocumentDirection, object NoEncodingDialog, object XMLTransform) - { - return new LBDocumentClass(InvokeMethod("Open", FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible, OpenAndRepair, DocumentDirection, NoEncodingDialog, XMLTransform)); - } - } + public LBDocuments(object item) => Item = item; + public LBDocumentClass Open(object FileName) => new LBDocumentClass(InvokeMethod("Open", FileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); + public LBDocumentClass Open(object FileName, object ConfirmConversions, object ReadOnly, object AddToRecentFiles, object PasswordDocument, object PasswordTemplate, object Revert, object WritePasswordDocument, object WritePasswordTemplate, object Format, object Encoding, object Visible, object OpenAndRepair, object DocumentDirection, object NoEncodingDialog, object XMLTransform) => new LBDocumentClass(InvokeMethod("Open", FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible, OpenAndRepair, DocumentDirection, NoEncodingDialog, XMLTransform)); + } public partial class LBSelection : LBComObject { public LBSelection() { } - public LBSelection(Object item) : base(item) { } - public LBRange Range - { - get { return new LBRange(GetProperty("Range")); } - } - public LBStyle Style - { - get { return new LBStyle(GetProperty("Style")); } - } - public LBParagraphFormatClass ParagraphFormat - { - get { return new LBParagraphFormatClass(GetProperty("ParagraphFormat")); } - } - public String Text + public LBSelection(object item) : base(item) { } + public LBRange Range => new LBRange(GetProperty("Range")); + public LBStyle Style => new LBStyle(GetProperty("Style")); + public LBParagraphFormatClass ParagraphFormat => new LBParagraphFormatClass(GetProperty("ParagraphFormat")); + public string Text { //B2022-083: Support Conditional RO Values get { return Convert.ToString(GetProperty("Text")); } set { SetProperty("Text", value); } } - public LBWdSelectionType Type - { - get { return (LBWdSelectionType)GetProperty("Type"); } - } - public LBFind Find - { - get { return new LBFind(GetProperty("Find")); } - } - public LBFontClass Font - { - get { return new LBFontClass(GetProperty("Font")); } - } - public int End + public LBWdSelectionType Type => (LBWdSelectionType)GetProperty("Type"); + public LBFind Find => new LBFind(GetProperty("Find")); + public LBFontClass Font => new LBFontClass(GetProperty("Font")); + public int End { get { return (GetProperty("End") as int? ?? 0); } set { SetProperty("End", value); } @@ -224,15 +135,9 @@ namespace LBWordLibrary get { return (GetProperty("Start") as int? ?? 0); } set { SetProperty("Start", value); } } - public LBInlineShapes InlineShapes - { - get { return new LBInlineShapes(GetProperty("InlineShapes")); } - } - public LBParagraphs Paragraphs - { - get { return new LBParagraphs(GetProperty("Paragraphs")); } - } - public LBTables Tables + public LBInlineShapes InlineShapes => new LBInlineShapes(GetProperty("InlineShapes")); + public LBParagraphs Paragraphs => new LBParagraphs(GetProperty("Paragraphs")); + public LBTables Tables { // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content get @@ -262,227 +167,77 @@ namespace LBWordLibrary } } } - public LBRows Rows - { - get { return new LBRows(GetProperty("Rows")); } - } - public void WholeStory() - { - InvokeMethod("WholeStory"); - } - public int MoveStart() - { - return InvokeMethod("MoveStart", Missing.Value, Missing.Value) as int? ?? 0; - } - public int MoveStart(object Unit, object Count) - { - return InvokeMethod("MoveStart", Unit, Count) as int? ?? 0; - } - public int MoveEnd() - { - return InvokeMethod("MoveEnd", Missing.Value, Missing.Value) as int? ?? 0; - } - public int MoveEnd(object Unit, object Count) - { - return InvokeMethod("MoveEnd", Unit, Count) as int? ?? 0; - } - public void Copy() - { - InvokeMethod("Copy"); - } - public int EndKey() - { - return InvokeMethod("EndKey", Missing.Value, Missing.Value) as int? ?? 0; - } - public int EndKey(object Unit, object Extend) - { - return InvokeMethod("EndKey", Unit, Extend) as int? ?? 0; - } - public void TypeText(string Text) - { - InvokeMethod("TypeText", Text); - } - public int EndOf() - { - return InvokeMethod("EndOf", Missing.Value, Missing.Value) as int? ?? 0; - } - public int EndOf(object Unit, object Extend) - { - return InvokeMethod("EndOf", Unit, Extend) as int? ?? 0; - } - public LBRange GoTo() - { - return new LBRange(InvokeMethod("GoTo", Missing.Value, Missing.Value, Missing.Value, Missing.Value)); - } - public LBRange GoTo(object What, object Which, object Count, object Name) - { - return new LBRange(InvokeMethod("GoTo", What, Which, Count, Name)); - } - public void InsertSymbol(int CharacterNumber) - { - InvokeMethod("InsertSymbol", CharacterNumber, Missing.Value, Missing.Value, Missing.Value); - } - public void InsertSymbol(int CharacterNumber, object Font, object Unicode, object Bias) - { - InvokeMethod("InsertSymbol", CharacterNumber, Font, Unicode, Bias); - } - public int MoveRight() - { - return InvokeMethod("MoveRight", Missing.Value, Missing.Value, Missing.Value) as int? ?? 0; - } - public int MoveRight(object Unit, object Count, object Extend) - { - return InvokeMethod("MoveRight", Unit, Count, Extend) as int? ?? 0; - } - public int MoveLeft() - { - return InvokeMethod("MoveLeft", Missing.Value, Missing.Value, Missing.Value) as int? ?? 0; - } - public int MoveLeft(object Unit, object Count, object Extend) - { - return InvokeMethod("MoveLeft", Unit, Count, Extend) as int? ?? 0; - } - public void SelectCell() - { - InvokeMethod("SelectCell"); - } - public void SelectRow() - { - InvokeMethod("SelectRow"); - } - public void SelectColumn() - { - InvokeMethod("SelectColumn"); - } - public void TypeParagraph() - { - InvokeMethod("TypeParagraph"); - } - public void TypeBackspace() - { - InvokeMethod("TypeBackspace"); - } - public int MoveDown() - { - return InvokeMethod("MoveDown", Missing.Value, Missing.Value, Missing.Value) as int? ?? 0; - } - public int MoveDown(object Unit, object Count, object Extend) - { - return InvokeMethod("MoveDown", Unit, Count, Extend) as int? ?? 0; - } - public int MoveUp() - { - return InvokeMethod("MoveUp", Missing.Value, Missing.Value, Missing.Value) as int? ?? 0; - } - public int MoveUp(object Unit, object Count, object Extend) - { - return InvokeMethod("MoveUp", Unit, Count, Extend) as int? ?? 0; - } - } + public LBRows Rows => new LBRows(GetProperty("Rows")); + public void WholeStory() => InvokeMethod("WholeStory"); + public int MoveStart() => InvokeMethod("MoveStart", Missing.Value, Missing.Value) as int? ?? 0; + public int MoveStart(object Unit, object Count) => InvokeMethod("MoveStart", Unit, Count) as int? ?? 0; + public int MoveEnd() => InvokeMethod("MoveEnd", Missing.Value, Missing.Value) as int? ?? 0; + public int MoveEnd(object Unit, object Count) => InvokeMethod("MoveEnd", Unit, Count) as int? ?? 0; + public void Copy() => InvokeMethod("Copy"); + public int EndKey() => InvokeMethod("EndKey", Missing.Value, Missing.Value) as int? ?? 0; + public int EndKey(object Unit, object Extend) => InvokeMethod("EndKey", Unit, Extend) as int? ?? 0; + public void TypeText(string Text) => InvokeMethod("TypeText", Text); + public int EndOf() => InvokeMethod("EndOf", Missing.Value, Missing.Value) as int? ?? 0; + public int EndOf(object Unit, object Extend) => InvokeMethod("EndOf", Unit, Extend) as int? ?? 0; + public LBRange GoTo() => new LBRange(InvokeMethod("GoTo", Missing.Value, Missing.Value, Missing.Value, Missing.Value)); + public LBRange GoTo(object What, object Which, object Count, object Name) => new LBRange(InvokeMethod("GoTo", What, Which, Count, Name)); + public void InsertSymbol(int CharacterNumber) => InvokeMethod("InsertSymbol", CharacterNumber, Missing.Value, Missing.Value, Missing.Value); + public void InsertSymbol(int CharacterNumber, object Font, object Unicode, object Bias) => InvokeMethod("InsertSymbol", CharacterNumber, Font, Unicode, Bias); + public int MoveRight() => InvokeMethod("MoveRight", Missing.Value, Missing.Value, Missing.Value) as int? ?? 0; + public int MoveRight(object Unit, object Count, object Extend) => InvokeMethod("MoveRight", Unit, Count, Extend) as int? ?? 0; + public int MoveLeft() => InvokeMethod("MoveLeft", Missing.Value, Missing.Value, Missing.Value) as int? ?? 0; + public int MoveLeft(object Unit, object Count, object Extend) => InvokeMethod("MoveLeft", Unit, Count, Extend) as int? ?? 0; + public void SelectCell() => InvokeMethod("SelectCell"); + public void SelectRow() => InvokeMethod("SelectRow"); + public void SelectColumn() => InvokeMethod("SelectColumn"); + public void TypeParagraph() => InvokeMethod("TypeParagraph"); + public void TypeBackspace() => InvokeMethod("TypeBackspace"); + public int MoveDown() => InvokeMethod("MoveDown", Missing.Value, Missing.Value, Missing.Value) as int? ?? 0; + public int MoveDown(object Unit, object Count, object Extend) => InvokeMethod("MoveDown", Unit, Count, Extend) as int? ?? 0; + public int MoveUp() => InvokeMethod("MoveUp", Missing.Value, Missing.Value, Missing.Value) as int? ?? 0; + public int MoveUp(object Unit, object Count, object Extend) => InvokeMethod("MoveUp", Unit, Count, Extend) as int? ?? 0; + } public partial class LBDocumentClass : LBComObject { public LBDocumentClass() { } - public LBDocumentClass(Object item) : base(item) { } - public LBApplicationClass Application + public LBDocumentClass(object item) : base(item) { } + public LBApplicationClass Application => new LBApplicationClass(GetProperty("Application")); + public int SaveFormat => (GetProperty("SaveFormat") as int? ?? 0); + public string FullName => (GetProperty("FullName").ToString()); + public LBShapes Shapes => new LBShapes(GetProperty("Shapes")); + public LBWindow ActiveWindow => new LBWindow(GetProperty("ActiveWindow")); + public LBPageSetup PageSetup => new LBPageSetup(GetProperty("PageSetup")); + public bool Saved { - get { return new LBApplicationClass(GetProperty("Application")); } - } - public int SaveFormat - { - get { return (GetProperty("SaveFormat") as int? ?? 0); } - } - public String FullName - { - get { return (GetProperty("FullName").ToString()); } - } - public LBShapes Shapes - { - get { return new LBShapes(GetProperty("Shapes")); } - } - public LBWindow ActiveWindow - { - get { return new LBWindow(GetProperty("ActiveWindow")); } - } - public LBPageSetup PageSetup - { - get { return new LBPageSetup(GetProperty("PageSetup")); } - } - public Boolean Saved - { - get { return (GetProperty("Saved") as Boolean? ?? false); } + get { return (GetProperty("Saved") as bool? ?? false); } set { SetProperty("Saved", value); } } - public LBTables Tables - { - get { return new LBTables(GetProperty("Tables")); } - } - public float DefaultTabStop + public LBTables Tables => new LBTables(GetProperty("Tables")); + public float DefaultTabStop { get { return (GetProperty("DefaultTabStop") as float? ?? 0); } set { SetProperty("DefaultTabStop", value); } } - public void SaveAs2000() - { - InvokeMethod("SaveAs2000", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); - } - public void SaveAs2000(object FileName, object FileFormat, object LockComments, object Password, object AddToRecentFiles, object WritePassword, object ReadOnlyRecommended, object EmbedTrueTypeFonts, object SaveNativePictureFormat, object SaveFormsData, object SaveAsAOCELetter) - { - InvokeMethod("SaveAs2000", FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter); - } - public void SaveAs() - { - InvokeMethod("SaveAs", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); - } - public void SaveAs(object FileName, object FileFormat, object LockComments, object Password, object AddToRecentFiles, object WritePassword, object ReadOnlyRecommended, object EmbedTrueTypeFonts, object SaveNativePictureFormat, object SaveFormsData, object SaveAsAOCELetter, object Encoding, object InsertLineBreaks, object AllowSubstitutions, object LineEnding, object AddBiDiMarks) - { - InvokeMethod("SaveAs", FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter, Encoding, InsertLineBreaks, AllowSubstitutions, LineEnding, AddBiDiMarks); - } - public void Close() - { - InvokeMethod("Close", Missing.Value, Missing.Value, Missing.Value); - } - public void Close(object SaveChanges, object OriginalFormat, object RouteDocument) - { - InvokeMethod("Close", SaveChanges, OriginalFormat, RouteDocument); - } - public void ExportAsFixedFormat(string OutputFileName, LBWdExportFormat ExportFormat) - { - InvokeMethod("ExportAsFixedFormat", OutputFileName, ExportFormat, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); - } - public void ExportAsFixedFormat(string OutputFileName, LBWdExportFormat ExportFormat, Boolean OpenAfterExport, LBWdExportOptimizeFor OptimizeFor, LBWdExportRange Range, int From, int To, LBWdExportItem Item, Boolean IncludeDocProps, Boolean KeepIRM, LBWdExportCreateBookmarks CreateBookmarks, Boolean DocStructureTags, Boolean BitmapMissingFonts, Boolean UseISO19005_1, object FixedFormatExtClassPtr) - { - InvokeMethod("ExportAsFixedFormat", OutputFileName, ExportFormat, OpenAfterExport, OptimizeFor, Range, From, To, Item, IncludeDocProps, KeepIRM, CreateBookmarks, DocStructureTags, BitmapMissingFonts, UseISO19005_1, FixedFormatExtClassPtr); - } - public LBRange Range() - { - return new LBRange(InvokeMethod("Range", Missing.Value, Missing.Value)); - } - public LBRange Range(object Start, object End) - { - return new LBRange(InvokeMethod("Range", Start, End)); - } - public Boolean Undo() - { - return InvokeMethod("Undo", Missing.Value) as Boolean? ?? false; - } - public Boolean Undo(object Times) - { - return InvokeMethod("Undo", Times) as Boolean? ?? false; - } - } + public void SaveAs2000() => InvokeMethod("SaveAs2000", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); + public void SaveAs2000(object FileName, object FileFormat, object LockComments, object Password, object AddToRecentFiles, object WritePassword, object ReadOnlyRecommended, object EmbedTrueTypeFonts, object SaveNativePictureFormat, object SaveFormsData, object SaveAsAOCELetter) => InvokeMethod("SaveAs2000", FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter); + public void SaveAs() => InvokeMethod("SaveAs", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); + public void SaveAs(object FileName, object FileFormat, object LockComments, object Password, object AddToRecentFiles, object WritePassword, object ReadOnlyRecommended, object EmbedTrueTypeFonts, object SaveNativePictureFormat, object SaveFormsData, object SaveAsAOCELetter, object Encoding, object InsertLineBreaks, object AllowSubstitutions, object LineEnding, object AddBiDiMarks) => InvokeMethod("SaveAs", FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter, Encoding, InsertLineBreaks, AllowSubstitutions, LineEnding, AddBiDiMarks); + public void Close() => InvokeMethod("Close", Missing.Value, Missing.Value, Missing.Value); + public void Close(object SaveChanges, object OriginalFormat, object RouteDocument) => InvokeMethod("Close", SaveChanges, OriginalFormat, RouteDocument); + public void ExportAsFixedFormat(string OutputFileName, LBWdExportFormat ExportFormat) => InvokeMethod("ExportAsFixedFormat", OutputFileName, ExportFormat, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); + public void ExportAsFixedFormat(string OutputFileName, LBWdExportFormat ExportFormat, bool OpenAfterExport, LBWdExportOptimizeFor OptimizeFor, LBWdExportRange Range, int From, int To, LBWdExportItem Item, bool IncludeDocProps, bool KeepIRM, LBWdExportCreateBookmarks CreateBookmarks, bool DocStructureTags, bool BitmapMissingFonts, bool UseISO19005_1, object FixedFormatExtClassPtr) => InvokeMethod("ExportAsFixedFormat", OutputFileName, ExportFormat, OpenAfterExport, OptimizeFor, Range, From, To, Item, IncludeDocProps, KeepIRM, CreateBookmarks, DocStructureTags, BitmapMissingFonts, UseISO19005_1, FixedFormatExtClassPtr); + public LBRange Range() => new LBRange(InvokeMethod("Range", Missing.Value, Missing.Value)); + public LBRange Range(object Start, object End) => new LBRange(InvokeMethod("Range", Start, End)); + public bool Undo() => InvokeMethod("Undo", Missing.Value) as bool? ?? false; + public bool Undo(object Times) => InvokeMethod("Undo", Times) as bool? ?? false; + } public partial class LBWindow : LBComObject { public LBWindow() { } - public LBWindow(Object item) : base(item) { } - public LBPane ActivePane - { - get { return new LBPane(GetProperty("ActivePane")); } - } - public LBView View - { - get { return new LBView(GetProperty("View")); } - } - } + public LBWindow(object item) : base(item) { } + public LBPane ActivePane => new LBPane(GetProperty("ActivePane")); + public LBView View => new LBView(GetProperty("View")); + } public enum LBWdWindowState { wdWindowStateNormal = 0, @@ -493,78 +248,39 @@ namespace LBWordLibrary { public LBRange() { } - // B2022-088: Find Doc Ro button not working in Word Sections - public LBFind Find - { - get { return new LBFind(GetProperty("Find")); } - } + // B2022-088: Find Doc Ro button not working in Word Sections + public LBFind Find => new LBFind(GetProperty("Find")); - public int MoveStart() - { - return InvokeMethod("MoveStart", Missing.Value, Missing.Value) as int? ?? 0; - } + public int MoveStart() => InvokeMethod("MoveStart", Missing.Value, Missing.Value) as int? ?? 0; - public int MoveStart(object Unit, object Count) - { - return InvokeMethod("MoveStart", Unit, Count) as int? ?? 0; - } + public int MoveStart(object Unit, object Count) => InvokeMethod("MoveStart", Unit, Count) as int? ?? 0; - public int MoveEnd() - { - return InvokeMethod("MoveEnd", Missing.Value, Missing.Value) as int? ?? 0; - } + public int MoveEnd() => InvokeMethod("MoveEnd", Missing.Value, Missing.Value) as int? ?? 0; - public int MoveEnd(object Unit, object Count) - { - return InvokeMethod("MoveEnd", Unit, Count) as int? ?? 0; - } + public int MoveEnd(object Unit, object Count) => InvokeMethod("MoveEnd", Unit, Count) as int? ?? 0; - public void InsertSymbol(int CharacterNumber) - { - InvokeMethod("InsertSymbol", CharacterNumber, Missing.Value, Missing.Value, Missing.Value); - } + public void InsertSymbol(int CharacterNumber) => InvokeMethod("InsertSymbol", CharacterNumber, Missing.Value, Missing.Value, Missing.Value); - public void InsertSymbol(int CharacterNumber, object Font, object Unicode, object Bias) - { - InvokeMethod("InsertSymbol", CharacterNumber, Font, Unicode, Bias); - } + public void InsertSymbol(int CharacterNumber, object Font, object Unicode, object Bias) => InvokeMethod("InsertSymbol", CharacterNumber, Font, Unicode, Bias); - public void TypeText(string Text) - { - InvokeMethod("TypeText", Text); - } + public void TypeText(string Text) => InvokeMethod("TypeText", Text); - public LBRange(Object item) : base(item) { } - // B2018-028 Word 2016 has a different value for the Vertical Position Relative to the Text Boundary than older version of Word. - // We now need to calculated the last row of text in the PROMS attachment differently. - // We now subtract the TopMargin the Page Setup from the Vertical Position Relative to the Page (Lenght in LBObjectExtension.cs) - public LBPageSetup PageSetup - { - get { return new LBPageSetup(GetProperty("PageSetup")); } - } - // C2019-021 Added LateBinding for ListFormat - public LBListFormat ListFormat - { - get { return new LBListFormat(GetProperty("ListFormat")); } - } - public LBFontClass Font - { - get { return new LBFontClass(GetProperty("Font")); } - } - public LBWdColorIndex HighlightColorIndex + public LBRange(object item) : base(item) { } + // B2018-028 Word 2016 has a different value for the Vertical Position Relative to the Text Boundary than older version of Word. + // We now need to calculated the last row of text in the PROMS attachment differently. + // We now subtract the TopMargin the Page Setup from the Vertical Position Relative to the Page (Lenght in LBObjectExtension.cs) + public LBPageSetup PageSetup => new LBPageSetup(GetProperty("PageSetup")); + // C2019-021 Added LateBinding for ListFormat + public LBListFormat ListFormat => new LBListFormat(GetProperty("ListFormat")); + public LBFontClass Font => new LBFontClass(GetProperty("Font")); + public LBWdColorIndex HighlightColorIndex { get { return (LBWdColorIndex)GetProperty("HighlightColorIndex"); } set { SetProperty("HighlightColorIndex", value); } } - public LBParagraphFormatClass ParagraphFormat - { - get { return new LBParagraphFormatClass(GetProperty("ParagraphFormat")); } - } - public LBParagraphs Paragraphs - { - get { return new LBParagraphs(GetProperty("Paragraphs")); } - } - public int End + public LBParagraphFormatClass ParagraphFormat => new LBParagraphFormatClass(GetProperty("ParagraphFormat")); + public LBParagraphs Paragraphs => new LBParagraphs(GetProperty("Paragraphs")); + public int End { get { return (GetProperty("End") as int? ?? 0); } set { SetProperty("End", value); } @@ -574,25 +290,16 @@ namespace LBWordLibrary get { return (GetProperty("Start") as int? ?? 0); } set { SetProperty("Start", value); } } - public String Text + public string Text { get { return (GetProperty("Text").ToString()); } set { SetProperty("Text", value); } } - public LBTables Tables - { - get { return new LBTables(GetProperty("Tables")); } - } - public LBRows Rows - { - get { return new LBRows(GetProperty("Rows")); } - } - public LBColumns Columns - { - get { return new LBColumns(GetProperty("Columns")); } - } - // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content - public LBCells Cells + public LBTables Tables => new LBTables(GetProperty("Tables")); + public LBRows Rows => new LBRows(GetProperty("Rows")); + public LBColumns Columns => new LBColumns(GetProperty("Columns")); + // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content + public LBCells Cells { get { @@ -600,29 +307,20 @@ namespace LBWordLibrary { return new LBCells(GetProperty("Cells")); } - catch(Exception ex) - { + catch (Exception) + { return null; } } } - public LBRange GoTo() - { - return new LBRange(InvokeMethod("GoTo", Missing.Value, Missing.Value, Missing.Value, Missing.Value)); - } - public LBRange GoTo(object What, object Which, object Count, object Name) - { - return new LBRange(InvokeMethod("GoTo", What, Which, Count, Name)); - } - public LBRange Select() - { - return new LBRange(InvokeMethod("Select")); - } - } + public LBRange GoTo() => new LBRange(InvokeMethod("GoTo", Missing.Value, Missing.Value, Missing.Value, Missing.Value)); + public LBRange GoTo(object What, object Which, object Count, object Name) => new LBRange(InvokeMethod("GoTo", What, Which, Count, Name)); + public LBRange Select() => new LBRange(InvokeMethod("Select")); + } public partial class LBParagraphFormatClass : LBComObject { public LBParagraphFormatClass() { } - public LBParagraphFormatClass(Object item) : base(item) { } + public LBParagraphFormatClass(object item) : base(item) { } public LBWdLineSpacing LineSpacingRule { get { return (LBWdLineSpacing)GetProperty("LineSpacingRule"); } @@ -689,14 +387,11 @@ namespace LBWordLibrary public partial class LBFind : LBComObject { public LBFind() { } - public LBFind(Object item) : base(item) { } - public LBReplacement Replacement + public LBFind(object item) : base(item) { } + public LBReplacement Replacement => new LBReplacement(GetProperty("Replacement")); + public bool Forward { - get { return new LBReplacement(GetProperty("Replacement")); } - } - public Boolean Forward - { - get { return (GetProperty("Forward") as Boolean? ?? false); } + get { return (GetProperty("Forward") as bool? ?? false); } set { SetProperty("Forward", value); } } public LBWdFindWrap Wrap @@ -704,58 +399,49 @@ namespace LBWordLibrary get { return (LBWdFindWrap)GetProperty("Wrap"); } set { SetProperty("Wrap", value); } } - public Boolean Format + public bool Format { - get { return (GetProperty("Format") as Boolean? ?? false); } + get { return (GetProperty("Format") as bool? ?? false); } set { SetProperty("Format", value); } } - public Boolean MatchWholeWord + public bool MatchWholeWord { - get { return (GetProperty("MatchWholeWord") as Boolean? ?? false); } + get { return (GetProperty("MatchWholeWord") as bool? ?? false); } set { SetProperty("MatchWholeWord", value); } } - public Boolean MatchWildcards + public bool MatchWildcards { - get { return (GetProperty("MatchWildcards") as Boolean? ?? false); } + get { return (GetProperty("MatchWildcards") as bool? ?? false); } set { SetProperty("MatchWildcards", value); } } - public Boolean MatchSoundsLike + public bool MatchSoundsLike { - get { return (GetProperty("MatchSoundsLike") as Boolean? ?? false); } + get { return (GetProperty("MatchSoundsLike") as bool? ?? false); } set { SetProperty("MatchSoundsLike", value); } } - public Boolean MatchAllWordForms + public bool MatchAllWordForms { - get { return (GetProperty("MatchAllWordForms") as Boolean? ?? false); } + get { return (GetProperty("MatchAllWordForms") as bool? ?? false); } set { SetProperty("MatchAllWordForms", value); } } - public String Text + public string Text { get { return (GetProperty("Text").ToString()); } set { SetProperty("Text", value); } } - public Boolean MatchCase + public bool MatchCase { - get { return (GetProperty("MatchCase") as Boolean? ?? false); } + get { return (GetProperty("MatchCase") as bool? ?? false); } set { SetProperty("MatchCase", value); } } - public Boolean Execute() - { - return InvokeMethod("Execute", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value) as Boolean? ?? false; - } - public Boolean Execute(object FindText, object MatchCase, object MatchWholeWord, object MatchWildcards, object MatchSoundsLike, object MatchAllWordForms, object Forward, object Wrap, object Format, object ReplaceWith, object Replace, object MatchKashida, object MatchDiacritics, object MatchAlefHamza, object MatchControl) - { - return InvokeMethod("Execute", FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace, MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl) as Boolean? ?? false; - } - public void ClearFormatting() - { - InvokeMethod("ClearFormatting"); - } - } + public bool Execute() => InvokeMethod("Execute", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value) as bool? ?? false; + public bool Execute(object FindText, object MatchCase, object MatchWholeWord, object MatchWildcards, object MatchSoundsLike, object MatchAllWordForms, object Forward, object Wrap, object Format, object ReplaceWith, object Replace, object MatchKashida, object MatchDiacritics, object MatchAlefHamza, object MatchControl) => InvokeMethod("Execute", FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace, MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl) as bool? ?? false; + public void ClearFormatting() => InvokeMethod("ClearFormatting"); + } public partial class LBFontClass : LBComObject { public LBFontClass() { } - public LBFontClass(Object item) : base(item) { } + public LBFontClass(object item) : base(item) { } public LBWdColor Color { get { return (LBWdColor)GetProperty("Color"); } @@ -781,7 +467,7 @@ namespace LBWordLibrary get { return (GetProperty("Size") as float? ?? 0); } set { SetProperty("Size", value); } } - public String Name + public string Name { get { return (GetProperty("Name").ToString()); } set { SetProperty("Name", value); } @@ -837,85 +523,35 @@ namespace LBWordLibrary } public partial class LBInlineShapes : LBComObjectList /* Collection */ { - public LBInlineShapes(Object item) - { - Item = item; - } - public LBInlineShape AddPicture(string FileName) - { - return new LBInlineShape(InvokeMethod("AddPicture", FileName, Missing.Value, Missing.Value, Missing.Value)); - } - public LBInlineShape AddPicture(string FileName, object LinkToFile, object SaveWithDocument, object Range) - { - return new LBInlineShape(InvokeMethod("AddPicture", FileName, LinkToFile, SaveWithDocument, Range)); - } - } + public LBInlineShapes(object item) => Item = item; + public LBInlineShape AddPicture(string FileName) => new LBInlineShape(InvokeMethod("AddPicture", FileName, Missing.Value, Missing.Value, Missing.Value)); + public LBInlineShape AddPicture(string FileName, object LinkToFile, object SaveWithDocument, object Range) => new LBInlineShape(InvokeMethod("AddPicture", FileName, LinkToFile, SaveWithDocument, Range)); + } public partial class LBParagraphs : LBComObjectList /* Collection */ { - // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content - public LBParagraph this[int item] - { - get // Get a Cell from a List - { - return new LBParagraph(base[item]); - } - } - public LBParagraphs(Object item) - { - Item = item; - } - public int Count - { - get { return (GetProperty("Count") as int? ?? 0); } - } - public LBParagraph First - { - get { return new LBParagraph(GetProperty("First")); } - } - public LBParagraph Last - { - get { return new LBParagraph(GetProperty("Last")); } - } - public System.Object GetEnumerator() - { - return InvokeMethod("GetEnumerator"); - } - } + // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content + public new LBParagraph this[int item] => new LBParagraph(base[item]); + public LBParagraphs(object item) => Item = item; + public int Count => (GetProperty("Count") as int? ?? 0); + public LBParagraph First => new LBParagraph(GetProperty("First")); + public LBParagraph Last => new LBParagraph(GetProperty("Last")); + public object GetEnumerator() => InvokeMethod("GetEnumerator"); + } public partial class LBTables : LBComObjectList /* Collection */ { - public LBTables(Object item) - { - Item = item; - } - public LBTable Add(LBRange Range, int NumRows, int NumColumns) - { - return new LBTable(InvokeMethod("Add", Range, NumRows, NumColumns, Missing.Value, Missing.Value)); - } - public LBTable Add(LBRange Range, int NumRows, int NumColumns, object DefaultTableBehavior, object AutoFitBehavior) - { - return new LBTable(InvokeMethod("Add", Range, NumRows, NumColumns, DefaultTableBehavior, AutoFitBehavior)); - } - // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content - public int Count - { - get { return (GetProperty("Count") as int? ?? 0); } - } - public LBTable this[int item] - { - get - { // Get a Table from a list - return new LBTable(base[item]); - } - } + public LBTables(object item) => Item = item; + public LBTable Add(LBRange Range, int NumRows, int NumColumns) => new LBTable(InvokeMethod("Add", Range, NumRows, NumColumns, Missing.Value, Missing.Value)); + public LBTable Add(LBRange Range, int NumRows, int NumColumns, object DefaultTableBehavior, object AutoFitBehavior) => new LBTable(InvokeMethod("Add", Range, NumRows, NumColumns, DefaultTableBehavior, AutoFitBehavior)); + // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content + public int Count => (GetProperty("Count") as int? ?? 0); + // Get a Table from a list + public new LBTable this[int item] => new LBTable(base[item]); - } + } public partial class LBCells : LBComObjectList /* Collection */ { - public LBCells(Object item) - { - Item = item; - } - public LBWdCellVerticalAlignment VerticalAlignment + public LBCells(object item) => Item = item; + public LBWdCellVerticalAlignment VerticalAlignment { get { return (LBWdCellVerticalAlignment)GetProperty("VerticalAlignment"); } set { SetProperty("VerticalAlignment", value); } @@ -925,54 +561,27 @@ namespace LBWordLibrary get { return (GetProperty("Height") as float? ?? 0); } set { SetProperty("Height", value); } } - // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content - public int Count - { - get { return (GetProperty("Count") as int? ?? 0); } - } - public LBBorders Borders - { - get { return new LBBorders(GetProperty("Borders")); } - } - public System.Object GetEnumerator() - { - return InvokeMethod("GetEnumerator"); - } - public void Merge() - { - InvokeMethod("Merge"); - } - // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content - public LBCell this[int item] - { - get // Get a Cell from a List - { - return new LBCell(base[item]); - } - } + // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content + public int Count => (GetProperty("Count") as int? ?? 0); + public LBBorders Borders => new LBBorders(GetProperty("Borders")); + public object GetEnumerator() => InvokeMethod("GetEnumerator"); + public void Merge() => InvokeMethod("Merge"); + // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content + public new LBCell this[int item] => new LBCell(base[item]); - } + } public partial class LBRows : LBComObjectList /* Collection */ { - public LBRows(Object item) - { - Item = item; - } - public int HeadingFormat + public LBRows(object item) => Item = item; + public int HeadingFormat { get { return (GetProperty("HeadingFormat") as int? ?? 0); } set { SetProperty("HeadingFormat", value); } } - // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content - public int Count - { - get { return (GetProperty("Count") as int? ?? 0); } - } - public LBRow First - { - get { return new LBRow(GetProperty("First")); } - } - public int AllowBreakAcrossPages + // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content + public int Count => (GetProperty("Count") as int? ?? 0); + public LBRow First => new LBRow(GetProperty("First")); + public int AllowBreakAcrossPages { get { return (GetProperty("AllowBreakAcrossPages") as int? ?? 0); } set { SetProperty("AllowBreakAcrossPages", value); } @@ -980,23 +589,14 @@ namespace LBWordLibrary } public partial class LBShapes : LBComObjectList /* Collection */ { - public LBShapes(Object item) - { - Item = item; - } - public LBShape AddPicture(string FileName) - { - return new LBShape(InvokeMethod("AddPicture", FileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); - } - public LBShape AddPicture(string FileName, object LinkToFile, object SaveWithDocument, object Left, object Top, object Width, object Height, object Anchor) - { - return new LBShape(InvokeMethod("AddPicture", FileName, LinkToFile, SaveWithDocument, Left, Top, Width, Height, Anchor)); - } - } + public LBShapes(object item) => Item = item; + public LBShape AddPicture(string FileName) => new LBShape(InvokeMethod("AddPicture", FileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); + public LBShape AddPicture(string FileName, object LinkToFile, object SaveWithDocument, object Left, object Top, object Width, object Height, object Anchor) => new LBShape(InvokeMethod("AddPicture", FileName, LinkToFile, SaveWithDocument, Left, Top, Width, Height, Anchor)); + } public partial class LBPageSetup : LBComObject { public LBPageSetup() { } - public LBPageSetup(Object item) : base(item) { } + public LBPageSetup(object item) : base(item) { } public float BottomMargin { get { return (GetProperty("BottomMargin") as float? ?? 0); } @@ -1079,28 +679,22 @@ namespace LBWordLibrary public partial class LBPane : LBComObject { public LBPane() { } - public LBPane(Object item) : base(item) { } - public LBPages Pages - { - get { return new LBPages(GetProperty("Pages")); } - } - public LBView View - { - get { return new LBView(GetProperty("View")); } - } - } + public LBPane(object item) : base(item) { } + public LBPages Pages => new LBPages(GetProperty("Pages")); + public LBView View => new LBView(GetProperty("View")); + } public partial class LBView : LBComObject { public LBView() { } - public LBView(Object item) : base(item) { } + public LBView(object item) : base(item) { } public LBWdViewType Type { get { return (LBWdViewType)GetProperty("Type"); } set { SetProperty("Type", value); } } - public Boolean ShowRevisionsAndComments + public bool ShowRevisionsAndComments { - get { return (GetProperty("ShowRevisionsAndComments") as Boolean? ?? false); } + get { return (GetProperty("ShowRevisionsAndComments") as bool? ?? false); } set { SetProperty("ShowRevisionsAndComments", value); } } public LBWdRevisionsView RevisionsView @@ -1108,11 +702,8 @@ namespace LBWordLibrary get { return (LBWdRevisionsView)GetProperty("RevisionsView"); } set { SetProperty("RevisionsView", value); } } - public LBZoom Zoom - { - get { return new LBZoom(GetProperty("Zoom")); } - } - } + public LBZoom Zoom => new LBZoom(GetProperty("Zoom")); + } public enum LBWdColorIndex { wdNoHighlight = 0, @@ -1136,35 +727,14 @@ namespace LBWordLibrary } public partial class LBColumns : LBComObjectList /* Collection */ { - public LBColumns(Object item) - { - Item = item; - } - public LBColumn First - { - get { return new LBColumn(GetProperty("First")); } - } - public LBColumn Last - { - get { return new LBColumn(GetProperty("Last")); } - } - public int Count - { - get { return (GetProperty("Count") as int? ?? 0); } - } - public System.Object GetEnumerator() - { - return InvokeMethod("GetEnumerator"); - } - public LBColumn this[int item] - { - get // Get a Column from a List - { - return new LBColumn(base[item]); - } - } + public LBColumns(object item) => Item = item; + public LBColumn First => new LBColumn(GetProperty("First")); + public LBColumn Last => new LBColumn(GetProperty("Last")); + public int Count => (GetProperty("Count") as int? ?? 0); + public object GetEnumerator() => InvokeMethod("GetEnumerator"); + public new LBColumn this[int item] => new LBColumn(base[item]); - } + } public enum LBWdLineSpacing { wdLineSpaceSingle = 0, @@ -1189,17 +759,14 @@ namespace LBWordLibrary public partial class LBReplacement : LBComObject { public LBReplacement() { } - public LBReplacement(Object item) : base(item) { } - public String Text + public LBReplacement(object item) : base(item) { } + public string Text { get { return (GetProperty("Text").ToString()); } set { SetProperty("Text", value); } } - public void ClearFormatting() - { - InvokeMethod("ClearFormatting"); - } - } + public void ClearFormatting() => InvokeMethod("ClearFormatting"); + } public enum LBWdFindWrap { wdFindStop = 0, @@ -1293,7 +860,7 @@ namespace LBWordLibrary public partial class LBInlineShape : LBComObject { public LBInlineShape() { } - public LBInlineShape(Object item) : base(item) { } + public LBInlineShape(object item) : base(item) { } public float Height { get { return (GetProperty("Height") as float? ?? 0); } @@ -1308,30 +875,18 @@ namespace LBWordLibrary public partial class LBParagraph : LBComObject { public LBParagraph() { } - public LBParagraph(Object item) : base(item) { } - public LBRange Range - { - get { return new LBRange(GetProperty("Range")); } - } - } + public LBParagraph(object item) : base(item) { } + public LBRange Range => new LBRange(GetProperty("Range")); + } public partial class LBTable : LBComObject { public LBTable() { } - public LBTable(Object item) : base(item) { } - // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content - public LBRange Range - { - get { return new LBRange(GetProperty("Range")); } - } - public LBColumns Columns - { - get { return new LBColumns(GetProperty("Columns")); } - } - public LBRows Rows - { - get { return new LBRows(GetProperty("Rows")); } - } - public float TopPadding + public LBTable(object item) : base(item) { } + // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content + public LBRange Range => new LBRange(GetProperty("Range")); + public LBColumns Columns => new LBColumns(GetProperty("Columns")); + public LBRows Rows => new LBRows(GetProperty("Rows")); + public float TopPadding { get { return (GetProperty("TopPadding") as float? ?? 0); } set { SetProperty("TopPadding", value); } @@ -1360,38 +915,26 @@ namespace LBWordLibrary } public partial class LBBorders : LBComObjectList /* Collection */ { - public LBBorders(Object item) - { - Item = item; - } - public int Count - { - get { return (GetProperty("Count") as int? ?? 0); } - } - } + public LBBorders(object item) => Item = item; + public int Count => (GetProperty("Count") as int? ?? 0); + } public partial class LBRow : LBComObject { public LBRow() { } - public LBRow(Object item) : base(item) { } + public LBRow(object item) : base(item) { } public float Height { get { return (GetProperty("Height") as float? ?? 0); } set { SetProperty("Height", value); } } - public void Select() - { - InvokeMethod("Select"); - } - } + public void Select() => InvokeMethod("Select"); + } public partial class LBShape : LBComObject { public LBShape() { } - public LBShape(Object item) : base(item) { } - public void ConvertToInlineShape() - { - InvokeMethod("ConvertToInlineShape"); - } - public float Height + public LBShape(object item) : base(item) { } + public void ConvertToInlineShape() => InvokeMethod("ConvertToInlineShape"); + public float Height { get { return (GetProperty("Height") as float? ?? 0); } set { SetProperty("Height", value); } @@ -1401,21 +944,8 @@ namespace LBWordLibrary get { return (GetProperty("Width") as float? ?? 0); } set { SetProperty("Width", value); } } - //public float ScaleHeight - //{ - // get { return (GetProperty("ScaleHeight") as float? ?? 0); } - // set { SetProperty("ScaleHeight", value); } - //} - //public float ScaleWidth - //{ - // get { return (GetProperty("ScaleWidth") as float? ?? 0); } - // set { SetProperty("ScaleWidth", value); } - //} - public LBRange Anchor - { - get { return new LBRange(GetProperty("Anchor")); } - } - public LBMsoTriState LockAspectRatio + public LBRange Anchor => new LBRange(GetProperty("Anchor")); + public LBMsoTriState LockAspectRatio { get { return (LBMsoTriState)GetProperty("LockAspectRatio"); } set { SetProperty("LockAspectRatio", value); } @@ -1455,9 +985,9 @@ namespace LBWordLibrary get { return (GetProperty("LockAnchor") as int? ?? 0); } set { SetProperty("LockAnchor", value); } } - public Boolean LayoutInCell + public bool LayoutInCell { - get { return (GetProperty("LayoutInCell") as Boolean? ?? false); } + get { return (GetProperty("LayoutInCell") as bool? ?? false); } set { SetProperty("LayoutInCell", value); } } } @@ -1513,15 +1043,9 @@ namespace LBWordLibrary } public partial class LBPages : LBComObjectList /* Collection */ { - public LBPages(Object item) - { - Item = item; - } - public int Count - { - get { return (GetProperty("Count") as int? ?? 0); } - } - } + public LBPages(object item) => Item = item; + public int Count => (GetProperty("Count") as int? ?? 0); + } public enum LBWdViewType { wdNormalView = 1, @@ -1540,7 +1064,7 @@ namespace LBWordLibrary public partial class LBZoom : LBComObject { public LBZoom() { } - public LBZoom(Object item) : base(item) { } + public LBZoom(object item) : base(item) { } public LBWdPageFit PageFit { get { return (LBWdPageFit)GetProperty("PageFit"); } @@ -1555,29 +1079,17 @@ namespace LBWordLibrary public partial class LBColumn : LBComObject { public LBColumn() { } - public LBColumn(Object item) : base(item) { } + public LBColumn(object item) : base(item) { } public float Width { get { return (GetProperty("Width") as float? ?? 0); } set { SetProperty("Width", value); } } - public int Index - { - get { return (GetProperty("Index") as int? ?? 0); } - } - public LBColumn Next - { - get { return new LBColumn(GetProperty("Next")); } - } - public LBColumn Previous - { - get { return new LBColumn(GetProperty("Previous")); } - } - public void SetWidth(float ColumnWidth, LBWdRulerStyle RulerStyle) - { - InvokeMethod("SetWidth", ColumnWidth, RulerStyle); - } - } + public int Index => (GetProperty("Index") as int? ?? 0); + public LBColumn Next => new LBColumn(GetProperty("Next")); + public LBColumn Previous => new LBColumn(GetProperty("Previous")); + public void SetWidth(float ColumnWidth, LBWdRulerStyle RulerStyle) => InvokeMethod("SetWidth", ColumnWidth, RulerStyle); + } public enum LBWdRelativeHorizontalPosition { wdRelativeHorizontalPositionMargin = 0, @@ -1617,15 +1129,15 @@ namespace LBWordLibrary public partial class LBBorder : LBComObject { public LBBorder() { } - public LBBorder(Object item) : base(item) { } + public LBBorder(object item) : base(item) { } public LBWdLineStyle LineStyle { get { return (LBWdLineStyle)GetProperty("LineStyle"); } set { SetProperty("LineStyle", value); } } - public Boolean Visible + public bool Visible { - get { return (GetProperty("Visible") as Boolean? ?? false); } + get { return (GetProperty("Visible") as bool? ?? false); } set { SetProperty("Visible", value); } } } @@ -1671,29 +1183,14 @@ namespace LBWordLibrary public partial class LBCell : LBComObject { public LBCell() { } - public LBCell(Object item) : base(item) { } - // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content - public LBRange Range - { - get { return new LBRange(GetProperty("Range")); } - } - public LBColumn Column - { - get { return new LBColumn(GetProperty("Column")); } - } - public LBCell Next - { - get { return new LBCell(GetProperty("Next")); } - } - public LBCell Previous - { - get { return new LBCell(GetProperty("Previous")); } - } - public LBRow Row - { - get { return new LBRow(GetProperty("Row")); } - } - public LBWdCellVerticalAlignment VerticalAlignment + public LBCell(object item) : base(item) { } + // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content + public LBRange Range => new LBRange(GetProperty("Range")); + public LBColumn Column => new LBColumn(GetProperty("Column")); + public LBCell Next => new LBCell(GetProperty("Next")); + public LBCell Previous => new LBCell(GetProperty("Previous")); + public LBRow Row => new LBRow(GetProperty("Row")); + public LBWdCellVerticalAlignment VerticalAlignment { get { return (LBWdCellVerticalAlignment)GetProperty("VerticalAlignment"); } set { SetProperty("VerticalAlignment", value); } @@ -1708,24 +1205,12 @@ namespace LBWordLibrary get { return (GetProperty("Height") as float? ?? 0); } set { SetProperty("Height", value); } } - // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content - public int RowIndex - { - get { return (GetProperty("RowIndex") as int? ?? 0); } - } - public int ColumnIndex - { - get { return (GetProperty("ColumnIndex") as int? ?? 0); } - } - public LBTables Tables - { - get { return new LBTables(GetProperty("Tables")); } - } - public void SetWidth(float ColumnWidth, LBWdRulerStyle RulerStyle) - { - InvokeMethod("SetWidth", ColumnWidth, RulerStyle); - } - } + // C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content + public int RowIndex => (GetProperty("RowIndex") as int? ?? 0); + public int ColumnIndex => (GetProperty("ColumnIndex") as int? ?? 0); + public LBTables Tables => new LBTables(GetProperty("Tables")); + public void SetWidth(float ColumnWidth, LBWdRulerStyle RulerStyle) => InvokeMethod("SetWidth", ColumnWidth, RulerStyle); + } public enum LBWdSaveFormat { wdFormatDocument = 0, @@ -1785,31 +1270,16 @@ namespace LBWordLibrary public partial class LBPage : LBComObject { public LBPage() { } - public LBPage(Object item) : base(item) { } - public int Height - { - get { return (GetProperty("Height") as int? ?? 0); } - } - public int Left - { - get { return (GetProperty("Left") as int? ?? 0); } - } - public LBRectangles Rectangles - { - get { return new LBRectangles(GetProperty("Rectangles")); } - } - public int Top - { - get { return (GetProperty("Top") as int? ?? 0); } - } - public int Width - { - get { return (GetProperty("Width") as int? ?? 0); } - } - } + public LBPage(object item) : base(item) { } + public int Height => (GetProperty("Height") as int? ?? 0); + public int Left => (GetProperty("Left") as int? ?? 0); + public LBRectangles Rectangles => new LBRectangles(GetProperty("Rectangles")); + public int Top => (GetProperty("Top") as int? ?? 0); + public int Width => (GetProperty("Width") as int? ?? 0); + } public partial class LBRectangles : LBComObjectList /* Collection */ { - public LBRectangles(Object item) + public LBRectangles(object item) { Item = item; } @@ -1821,36 +1291,21 @@ namespace LBWordLibrary public partial class LBRectangle : LBComObject { public LBRectangle() { } - public LBRectangle(Object item) : base(item) { } - public LBLines Lines - { - get { return new LBLines(GetProperty("Lines")); } - } - } + public LBRectangle(object item) : base(item) { } + public LBLines Lines => new LBLines(GetProperty("Lines")); + } public partial class LBLines : LBComObjectList /* Collection */ { - public LBLines(Object item) - { - Item = item; - } - public int Count - { - get { return (GetProperty("Count") as int? ?? 0); } - } - } + public LBLines(object item) => Item = item; + public int Count => (GetProperty("Count") as int? ?? 0); + } public partial class LBLine : LBComObject { public LBLine() { } - public LBLine(Object item) : base(item) { } - public int Top - { - get { return (GetProperty("Top") as int? ?? 0); } - } - public int Height - { - get { return (GetProperty("Height") as int? ?? 0); } - } - } + public LBLine(object item) : base(item) { } + public int Top => (GetProperty("Top") as int? ?? 0); + public int Height => (GetProperty("Height") as int? ?? 0); + } public enum LBWdMovementType { wdMove = 0, @@ -1905,54 +1360,29 @@ namespace LBWordLibrary public partial class LBPictureFormat : LBComObject { public LBPictureFormat() { } - public LBPictureFormat(Object item) : base(item) { } + public LBPictureFormat(object item) : base(item) { } } public partial class LBStyle : LBComObject { public LBStyle() { } - public LBStyle(Object item) : base(item) { } - public String NameLocal + public LBStyle(object item) : base(item) { } + public string NameLocal { get { return (GetProperty("NameLocal").ToString()); } set { SetProperty("NameLocal", value); } } - public int ListLevelNumber - { - get { return (GetProperty("ListLevelNumber") as int? ?? 0); } - } - } + public int ListLevelNumber => (GetProperty("ListLevelNumber") as int? ?? 0); + } // C2019-021 Added new object type LBListFormat public partial class LBListFormat : LBComObject { public LBListFormat() { } - public LBListFormat(Object item) : base(item) { } - public String NameLocal + public LBListFormat(object item) : base(item) { } + public string NameLocal { get { return (GetProperty("NameLocal").ToString()); } set { SetProperty("NameLocal", value); } } - public string ListString - { - get { return (GetProperty("ListString").ToString()); } - } - } - // public partial class LBStyles : LBComObjectList /* Collection */ -// { -// public LBStyles(Object item) -// { -// Item = item; -// } -// public int Count -// { -// get { return (GetProperty("Count") as int? ?? 0); } -// } -// public LBStyle Item -// { -// get { return new LBStyle(GetProperty("Item")); } -// } -// public System.Object GetEnumerator() -// { -// return InvokeMethod("GetEnumerator"); -// } -// } + public string ListString => (GetProperty("ListString").ToString()); + } } diff --git a/PROMS/LBWordLibrary/LBObjectExtension.cs b/PROMS/LBWordLibrary/LBObjectExtension.cs index 8af4c527..93d44e07 100644 --- a/PROMS/LBWordLibrary/LBObjectExtension.cs +++ b/PROMS/LBWordLibrary/LBObjectExtension.cs @@ -1,654 +1,519 @@ +using Microsoft.Win32; +using Read64bitRegistryFrom32bitApp; using System; using System.Collections.Generic; -using System.Text; using System.Reflection; -using Microsoft.Win32; -using System.Windows.Forms; +using System.Text; using System.Text.RegularExpressions; -using Read64bitRegistryFrom32bitApp; +using System.Windows.Forms; namespace LBWordLibrary { - public partial class LBApplicationClass : LBComObject - { - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - /// - /// This gives the option of specifying Background = false to print in the foreground. - /// - /// boolean BackGround - /// If true - document will be printed in the background - /// If false - document will be printed in the foreground - public void PrintOut(Boolean Background) - { - InvokeMethod("PrintOut", Background, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); - } - public void Quit(bool save) - { - InvokeMethod("Quit", save, Missing.Value, Missing.Value); - } - public bool VolianPDFInstalled - { - get - { - foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters) - if (printer == "VolianPDF Writer") return true; - return false; - } - } - private static bool? _WordPDFExporterInstalled = null; - public static bool WordPDFExporterInstalled - { - get - { - if (_WordPDFExporterInstalled == null) - { - // this is to determine if ExportAsFixedFormat was installed in MSOffice - // This key only worked for Vista - //RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"Installer\Components\12B306B24E250DD428FC7016B6FB4BD8"); - // This key works for Windows Vista and Windows 7 - try - { - string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\0E5C161912A2A6C4C93C76678926C56C"; - bool validKey = RegistryWOW6432.CheckRegKey64Valid(RegHive.HKEY_LOCAL_MACHINE, keyPath); - _WordPDFExporterInstalled = validKey; - if(!validKey) - _MyLog.WarnFormat("MSWord2007 PDF Export Registry Key Missing"); - //RegistryKey key = Registry.LocalMachine.OpenSubKey(keyPath, RegistryKeyPermissionCheck.ReadSubTree); - //if (key == null) - //{ - // RegistryKey localMachine64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); - // key = localMachine64.OpenSubKey(keystring, RegistryKeyPermissionCheck.ReadSubTree); - //} - //if (key != null) - //{ - // key.Close(); - // _WordPDFExporterInstalled = true; - // return (bool) _WordPDFExporterInstalled; - //} - //_WordPDFExporterInstalled = FindEXP_PDF(); - return (bool) _WordPDFExporterInstalled; - } - catch (Exception ex) - { - _MyLog.WarnFormat("MSWord2007 PDF Export Registry Key Failure {0} - {1}", ex.GetType().Name, ex.Message); - _WordPDFExporterInstalled = false; - return (bool) _WordPDFExporterInstalled; - } + public partial class LBApplicationClass : LBComObject + { + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + /// + /// This gives the option of specifying Background = false to print in the foreground. + /// + /// boolean BackGround + /// If true - document will be printed in the background + /// If false - document will be printed in the foreground + public void PrintOut(bool Background) => InvokeMethod("PrintOut", Background, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); + public void Quit(bool save) => InvokeMethod("Quit", save, Missing.Value, Missing.Value); + public bool VolianPDFInstalled + { + get + { + foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters) + if (printer == "VolianPDF Writer") return true; + return false; + } + } + private static bool? _WordPDFExporterInstalled = null; + public static bool WordPDFExporterInstalled + { + get + { + if (_WordPDFExporterInstalled == null) + { + // this is to determine if ExportAsFixedFormat was installed in MSOffice + // This key only worked for Vista + //RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"Installer\Components\12B306B24E250DD428FC7016B6FB4BD8"); + // This key works for Windows Vista and Windows 7 + try + { + string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\0E5C161912A2A6C4C93C76678926C56C"; + bool validKey = RegistryWOW6432.CheckRegKey64Valid(RegHive.HKEY_LOCAL_MACHINE, keyPath); + _WordPDFExporterInstalled = validKey; + if (!validKey) + _MyLog.WarnFormat("MSWord2007 PDF Export Registry Key Missing"); + + return (bool)_WordPDFExporterInstalled; + } + catch (Exception ex) + { + _MyLog.WarnFormat("MSWord2007 PDF Export Registry Key Failure {0} - {1}", ex.GetType().Name, ex.Message); + _WordPDFExporterInstalled = false; + return (bool)_WordPDFExporterInstalled; + } - } - return (bool) _WordPDFExporterInstalled; - } - } - private static bool FindEXP_PDF() - { - bool retval = false; - DateTime dtStart = DateTime.Now; - try - { - //string keystr = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\0E5C161912A2A6C4C93C76678926C56C"; - RegistryKey key = null; - string keystr = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components"; - while (key == null && keystr != "") - { - key = Registry.LocalMachine.OpenSubKey(keystr, RegistryKeyPermissionCheck.ReadSubTree); - keystr = keystr.Substring(0, keystr.LastIndexOf("\\")); - } - if (FindKeys(key, "EXP_PDF.DLL")) - retval = true; - } - catch (Exception ex) - { - AddKeyFound(string.Format("{0} - {1}", ex.GetType().Name, ex.Message)); - } - finally - { - DateTime dtEnd = DateTime.Now; - TimeSpan ts = TimeSpan.FromTicks(dtEnd.Ticks - dtStart.Ticks); - AddKeyFound(string.Format("{0} Seconds", ts.TotalSeconds)); - } - return retval; - } - private static bool FindKeys(RegistryKey key, string find) - { - string[] keyNames = key.GetSubKeyNames(); - foreach (string keyName in keyNames) - { - using (RegistryKey subKey = key.OpenSubKey(keyName, RegistryKeyPermissionCheck.ReadSubTree)) - { - if (FindKeys(subKey, find)) return true; - } - } - if (FindNames(key, find)) return true; - return false; - } - private static bool FindNames(RegistryKey key, string find) - { - string[] names = key.GetValueNames(); - foreach (string name in names) - { - if (FindNames(key, name, find)) return true; - } - return false; - } - private static bool FindNames(RegistryKey key, string name, string find) - { - RegistryValueKind kind = key.GetValueKind(name); - if (kind == RegistryValueKind.String) - { - string val = (string)key.GetValue(name); - if (val.Contains(find)) - { - AddKeyFound(string.Format("'{0}'\r\n Value {1} = '{2}'", key.ToString(), name, val)); - return true; - } - } - return false; - } - private static void AddKeyFound(string str) - { - _MyLog.WarnFormat("RegistryKeySearch: {0}",str); - } - private bool CanCreatePDFFile(string pdfFileName) - { - System.IO.FileInfo file = new System.IO.FileInfo(pdfFileName); - if (!file.Exists) return true; - try - { - file.Delete(); - return true; - } - catch (System.IO.IOException exio) - { - if (exio.Message.StartsWith("The process cannot access the file")) return false; - throw new Exception(string.Format("Cannot Delete PDF file {0}", pdfFileName), exio); - } - catch (Exception ex) - { - throw new Exception(string.Format("Cannot Delete PDF file {0}", pdfFileName), ex); - } - } - private string AvailableFileName(string pdfFileName) - { - if (CanCreatePDFFile(pdfFileName)) return pdfFileName; - string prefix = pdfFileName.Replace(".pdf", ""); - for (int i = 1; i < 1000; i++) - { - string newname = string.Format("{0}_{1:000}.PDF", prefix, i); - if (CanCreatePDFFile(newname)) return newname; - } - throw new Exception("Cannot find a name to use"); - } - public string CreatePDF(string pdfFileName, bool openPDF,int DebugStatus) - { - pdfFileName = CreatePDF(pdfFileName, DebugStatus); - if (openPDF) OpenPDF(pdfFileName); - return pdfFileName; - } - static List _AcrobatProcesses=new List(); - private static void OpenPDF(string pdfFileName) - { - _AcrobatProcesses.Add(System.Diagnostics.Process.Start(pdfFileName)); - } - public static void ClosePDFs() - { - foreach(System.Diagnostics.Process proc in _AcrobatProcesses) - if (!proc.HasExited) - KillAndWait(proc); - } - private static void KillAndWait(System.Diagnostics.Process proc) - { - Console.WriteLine("{0:s.ffff} Killing Adobe", DateTime.Now); - DateTime tStart = DateTime.Now; - proc.Kill(); - DateTime tEnd = DateTime.Now.AddMilliseconds(100); - while (DateTime.Now < tEnd) - { - Application.DoEvents(); - } - Console.WriteLine("{0:yyyy-MM-dd HH:mm:ss.ffff} {1:yyyy-MM-dd HH:mm:ss.ffff} {2}", DateTime.Now, proc.ExitTime - ,TimeSpan.FromTicks(proc.ExitTime.Ticks - tStart.Ticks).TotalMilliseconds); - } - public string CreatePDF(string pdfFileName, int DebugStatus) - { - pdfFileName = AvailableFileName(pdfFileName); - if (((int)Convert.ToSingle(Version)) > 12) - return CreatePDF2007(pdfFileName, DebugStatus); - if (((int)Convert.ToSingle(Version)) == 12 && WordPDFExporterInstalled) - { - //_MyLog.WarnFormat("Word PDF Exporter Installed - MSWord Version = '{0}'" , Version); - return CreatePDF2007(pdfFileName, DebugStatus); - } - if (VolianPDFInstalled) - { - _MyLog.WarnFormat("Using VolianPDFWriter - MSWord Version = '{0}'", Version); - return CreatePDF2003BG(pdfFileName); - } - //else // Force PDF Export - //{ - // _MyLog.WarnFormat("Force PDF Export for Michelle - MSWord Version = '{0}'", Version); - // return CreatePDF2007(pdfFileName, DebugStatus); - throw new Exception("No PDF Writer support installed for MS Word sections"); - //} - } - public string CreatePDF2003FG(string pdfFileName, bool openPDF) - { - pdfFileName = CreatePDF2003FG(pdfFileName); - if (openPDF) OpenPDF(pdfFileName); - return pdfFileName; - } - public string CreatePDF2003FG(string pdfFileName) - { - pdfFileName = AvailableFileName(pdfFileName); - if (!VolianPDFInstalled) - throw new Exception("VolianPDF Writer is not installed properly"); - try - { - string printer = ActivePrinter; - RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\VolianPDF Writer"); - key.SetValue("OutputFile", pdfFileName, RegistryValueKind.String); - key.SetValue("BypassSaveAs", "1", RegistryValueKind.String); - key.Close(); - ActivePrinter = "VolianPDF Writer"; - PrintOut(false); - ActivePrinter = printer; - Registry.CurrentUser.DeleteSubKeyTree(@"Software\VolianPDF Writer"); - return pdfFileName; - } - catch (Exception ex) - { - throw new Exception("Error creating PDF - LBApplicationClass.CreatePDF2003FG", ex); - } - } - public string CreatePDF2003BG(string pdfFileName, bool openPDF) - { - pdfFileName = CreatePDF2003BG(pdfFileName); - if (openPDF) OpenPDF(pdfFileName); - return pdfFileName; - } - public string CreatePDF2003BG(string pdfFileName) - { - pdfFileName = AvailableFileName(pdfFileName); - if (!VolianPDFInstalled) - throw new Exception("VolianPDF Writer is not installed properly"); - try - { - string printer = ActivePrinter; - RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\VolianPDF Writer"); - key.SetValue("OutputFile", pdfFileName, RegistryValueKind.String); - key.SetValue("BypassSaveAs", "1", RegistryValueKind.String); - key.Close(); - ActivePrinter = "VolianPDF Writer"; - PrintOut(true); - do - { - // Console.WriteLine("Background Printing Status = {0}", _MyApp.BackgroundPrintingStatus); - Application.DoEvents(); - } while (BackgroundPrintingStatus == 1); - ActivePrinter = printer; - Registry.CurrentUser.DeleteSubKeyTree(@"Software\VolianPDF Writer"); - return pdfFileName; - } - catch (Exception ex) - { - throw new Exception("Error creating PDF - LBApplicationClass.CreatePDF2003BG", ex); - } - } - public string CreatePDF2007(string pdfFileName, bool openPDF, int DebugStatus) - { - pdfFileName = CreatePDF2007(pdfFileName, DebugStatus); - if (openPDF) OpenPDF(pdfFileName); - return pdfFileName; - } - public string CreatePDF2007(string pdfFileName,int DebugStatus) - { - pdfFileName = AvailableFileName(pdfFileName); - // Removed to support MSWord 2010 and beyond. - //if (!WordPDFExporterInstalled) - // throw new Exception("MS Word PDF Exporter is not installed"); - try - { - ActiveDocument.ExportAsFixedFormat(pdfFileName, LBWdExportFormat.wdExportFormatPDF, DebugStatus); - return pdfFileName; - } - catch (Exception ex) - { - throw new Exception("Error creating PDF - LBApplicationClass.CreatePDF2007", ex); - } - } - } - public partial class LBDocuments - { - public LBDocumentClass Open(string fileName, Boolean addToRecentFiles) - { - return Open(fileName, Missing.Value, Missing.Value, addToRecentFiles); - } - private LBDocumentClass Open(params object[] myParams) - { - return new LBDocumentClass(InvokeMethod("Open", myParams)); - } - } - public partial class LBDocumentClass : LBComObject - { - public void ExportAsFixedFormat(string OutputFileName, LBWdExportFormat ExportFormat, int DebugStatus) - { - // iso 19005-1 compliant (PDF/A) [UseISO19005_1] should be set to false. for compare print - // iso 19005-1 compliant (PDF/A) [UseISO19005_1] should be set to true for production print - InvokeMethod("ExportAsFixedFormat", OutputFileName, ExportFormat, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, DebugStatus == 0, Missing.Value); - } - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public void SaveAs2000(string fileName) - { - if (fileName.ToUpper().EndsWith("DOC")) - SaveAs2000(fileName, LBWdSaveFormat.wdFormatDocument); - else if (fileName.ToUpper().EndsWith("RTF")) - SaveAs2000(fileName, LBWdSaveFormat.wdFormatRTF); - else - SaveAs2000(fileName); - } - public void SaveAs2000(params object[] myParams) - { - InvokeMethod("SaveAs2000", myParams); - } - public void SaveAs(string fileName) - { - if (fileName.ToUpper().EndsWith("DOC")) - SaveAs2(fileName, LBWdSaveFormat.wdFormatDocument, Missing.Value, Missing.Value, false); - else if (fileName.ToUpper().EndsWith("RTF")) - SaveAs2(fileName, LBWdSaveFormat.wdFormatRTF, Missing.Value, Missing.Value, false); - else if (fileName.ToUpper().EndsWith("TXT")) - SaveAs2(fileName, LBWdSaveFormat.wdFormatDOSText, Missing.Value, Missing.Value, false); - else if (fileName.ToUpper().EndsWith("DOCX")) - SaveAs2(fileName, LBWdSaveFormat.wdFormatXMLDocument, Missing.Value, Missing.Value, false); - else - SaveAs2(fileName, Missing.Value, Missing.Value, Missing.Value, false); - } - public void SaveAs2(params object[] myParams) - { - InvokeMethod("SaveAs", myParams); - } - public void SaveAs(string fileName, LBWdSaveFormat format) - { - SaveAs2(fileName, format, Missing.Value, Missing.Value, false); - } - public LBRange Range(int Start, int End) - { - return new LBRange(InvokeMethod("Range", Start, End)); - } - /// - /// Length is Pages and Partial Pages - /// The integral part is the number of full pages - /// The decimal part is the size of the last page divided by 7200 - /// (the first two digits should be the number of inches) - /// - public float Length - { - get - { - ActiveWindow.ActivePane.View.Type = LBWdViewType.wdPrintView; - ActiveWindow.View.Type = LBWdViewType.wdPrintView; - LBPages myPages = ActiveWindow.ActivePane.Pages;// Start with pages - float retval = (float)myPages.Count - 1; - LBRange myRange = Range(); - - myRange = myRange.GoTo(LBWdGoToItem.wdGoToPercent, LBWdGoToDirection.wdGoToAbsolute, 0); - float mytop = myRange.PageSetup.TopMargin; + } + return (bool)_WordPDFExporterInstalled; + } + } + + private static bool FindKeys(RegistryKey key, string find) + { + string[] keyNames = key.GetSubKeyNames(); + foreach (string keyName in keyNames) + { + using (RegistryKey subKey = key.OpenSubKey(keyName, RegistryKeyPermissionCheck.ReadSubTree)) + { + if (FindKeys(subKey, find)) return true; + } + } + if (FindNames(key, find)) return true; + return false; + } + private static bool FindNames(RegistryKey key, string find) + { + string[] names = key.GetValueNames(); + foreach (string name in names) + { + if (FindNames(key, name, find)) return true; + } + return false; + } + private static bool FindNames(RegistryKey key, string name, string find) + { + RegistryValueKind kind = key.GetValueKind(name); + if (kind == RegistryValueKind.String) + { + string val = (string)key.GetValue(name); + if (val.Contains(find)) + { + AddKeyFound(string.Format("'{0}'\r\n Value {1} = '{2}'", key.ToString(), name, val)); + return true; + } + } + return false; + } + private static void AddKeyFound(string str) => _MyLog.WarnFormat("RegistryKeySearch: {0}", str); + private bool CanCreatePDFFile(string pdfFileName) + { + System.IO.FileInfo file = new System.IO.FileInfo(pdfFileName); + if (!file.Exists) return true; + try + { + file.Delete(); + return true; + } + catch (System.IO.IOException exio) + { + if (exio.Message.StartsWith("The process cannot access the file")) return false; + throw new Exception(string.Format("Cannot Delete PDF file {0}", pdfFileName), exio); + } + catch (Exception ex) + { + throw new Exception(string.Format("Cannot Delete PDF file {0}", pdfFileName), ex); + } + } + private string AvailableFileName(string pdfFileName) + { + if (CanCreatePDFFile(pdfFileName)) return pdfFileName; + string prefix = pdfFileName.Replace(".pdf", ""); + for (int i = 1; i < 1000; i++) + { + string newname = string.Format("{0}_{1:000}.PDF", prefix, i); + if (CanCreatePDFFile(newname)) return newname; + } + throw new Exception("Cannot find a name to use"); + } + public string CreatePDF(string pdfFileName, bool openPDF, int DebugStatus) + { + pdfFileName = CreatePDF(pdfFileName, DebugStatus); + if (openPDF) OpenPDF(pdfFileName); + return pdfFileName; + } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] + static List _AcrobatProcesses = new List(); + private static void OpenPDF(string pdfFileName) => _AcrobatProcesses.Add(System.Diagnostics.Process.Start(pdfFileName)); + public static void ClosePDFs() + { + foreach (System.Diagnostics.Process proc in _AcrobatProcesses) + if (!proc.HasExited) + KillAndWait(proc); + } + private static void KillAndWait(System.Diagnostics.Process proc) + { + Console.WriteLine("{0:s.ffff} Killing Adobe", DateTime.Now); + DateTime tStart = DateTime.Now; + proc.Kill(); + DateTime tEnd = DateTime.Now.AddMilliseconds(100); + while (DateTime.Now < tEnd) + { + Application.DoEvents(); + } + Console.WriteLine("{0:yyyy-MM-dd HH:mm:ss.ffff} {1:yyyy-MM-dd HH:mm:ss.ffff} {2}", DateTime.Now, proc.ExitTime + , TimeSpan.FromTicks(proc.ExitTime.Ticks - tStart.Ticks).TotalMilliseconds); + } + public string CreatePDF(string pdfFileName, int DebugStatus) + { + pdfFileName = AvailableFileName(pdfFileName); + if (((int)Convert.ToSingle(Version)) > 12) + return CreatePDF2007(pdfFileName, DebugStatus); + if (((int)Convert.ToSingle(Version)) == 12 && WordPDFExporterInstalled) + { + //_MyLog.WarnFormat("Word PDF Exporter Installed - MSWord Version = '{0}'" , Version); + return CreatePDF2007(pdfFileName, DebugStatus); + } + if (VolianPDFInstalled) + { + _MyLog.WarnFormat("Using VolianPDFWriter - MSWord Version = '{0}'", Version); + return CreatePDF2003BG(pdfFileName); + } + throw new Exception("No PDF Writer support installed for MS Word sections"); + } + public string CreatePDF2003FG(string pdfFileName, bool openPDF) + { + pdfFileName = CreatePDF2003FG(pdfFileName); + if (openPDF) OpenPDF(pdfFileName); + return pdfFileName; + } + public string CreatePDF2003FG(string pdfFileName) + { + pdfFileName = AvailableFileName(pdfFileName); + if (!VolianPDFInstalled) + throw new Exception("VolianPDF Writer is not installed properly"); + try + { + string printer = ActivePrinter; + RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\VolianPDF Writer"); + key.SetValue("OutputFile", pdfFileName, RegistryValueKind.String); + key.SetValue("BypassSaveAs", "1", RegistryValueKind.String); + key.Close(); + ActivePrinter = "VolianPDF Writer"; + PrintOut(false); + ActivePrinter = printer; + Registry.CurrentUser.DeleteSubKeyTree(@"Software\VolianPDF Writer"); + return pdfFileName; + } + catch (Exception ex) + { + throw new Exception("Error creating PDF - LBApplicationClass.CreatePDF2003FG", ex); + } + } + public string CreatePDF2003BG(string pdfFileName, bool openPDF) + { + pdfFileName = CreatePDF2003BG(pdfFileName); + if (openPDF) OpenPDF(pdfFileName); + return pdfFileName; + } + public string CreatePDF2003BG(string pdfFileName) + { + pdfFileName = AvailableFileName(pdfFileName); + if (!VolianPDFInstalled) + throw new Exception("VolianPDF Writer is not installed properly"); + try + { + string printer = ActivePrinter; + RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\VolianPDF Writer"); + key.SetValue("OutputFile", pdfFileName, RegistryValueKind.String); + key.SetValue("BypassSaveAs", "1", RegistryValueKind.String); + key.Close(); + ActivePrinter = "VolianPDF Writer"; + PrintOut(true); + do + { + // Console.WriteLine("Background Printing Status = {0}", _MyApp.BackgroundPrintingStatus); + Application.DoEvents(); + } while (BackgroundPrintingStatus == 1); + ActivePrinter = printer; + Registry.CurrentUser.DeleteSubKeyTree(@"Software\VolianPDF Writer"); + return pdfFileName; + } + catch (Exception ex) + { + throw new Exception("Error creating PDF - LBApplicationClass.CreatePDF2003BG", ex); + } + } + public string CreatePDF2007(string pdfFileName, bool openPDF, int DebugStatus) + { + pdfFileName = CreatePDF2007(pdfFileName, DebugStatus); + if (openPDF) OpenPDF(pdfFileName); + return pdfFileName; + } + public string CreatePDF2007(string pdfFileName, int DebugStatus) + { + pdfFileName = AvailableFileName(pdfFileName); + try + { + ActiveDocument.ExportAsFixedFormat(pdfFileName, LBWdExportFormat.wdExportFormatPDF, DebugStatus); + return pdfFileName; + } + catch (Exception ex) + { + throw new Exception("Error creating PDF - LBApplicationClass.CreatePDF2007", ex); + } + } + } + public partial class LBDocuments + { + public LBDocumentClass Open(string fileName, bool addToRecentFiles) => Open(fileName, Missing.Value, Missing.Value, addToRecentFiles); + private LBDocumentClass Open(params object[] myParams) => new LBDocumentClass(InvokeMethod("Open", myParams)); + } + public partial class LBDocumentClass : LBComObject + { + public void ExportAsFixedFormat(string OutputFileName, LBWdExportFormat ExportFormat, int DebugStatus) + { + // iso 19005-1 compliant (PDF/A) [UseISO19005_1] should be set to false. for compare print + // iso 19005-1 compliant (PDF/A) [UseISO19005_1] should be set to true for production print + InvokeMethod("ExportAsFixedFormat", OutputFileName, ExportFormat, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, DebugStatus == 0, Missing.Value); + } + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + public void SaveAs2000(string fileName) + { + if (fileName.ToUpper().EndsWith("DOC")) + SaveAs2000(fileName, LBWdSaveFormat.wdFormatDocument); + else if (fileName.ToUpper().EndsWith("RTF")) + SaveAs2000(fileName, LBWdSaveFormat.wdFormatRTF); + else + SaveAs2000(fileName); + } + public void SaveAs2000(params object[] myParams) => InvokeMethod("SaveAs2000", myParams); + public void SaveAs(string fileName) + { + if (fileName.ToUpper().EndsWith("DOC")) + SaveAs2(fileName, LBWdSaveFormat.wdFormatDocument, Missing.Value, Missing.Value, false); + else if (fileName.ToUpper().EndsWith("RTF")) + SaveAs2(fileName, LBWdSaveFormat.wdFormatRTF, Missing.Value, Missing.Value, false); + else if (fileName.ToUpper().EndsWith("TXT")) + SaveAs2(fileName, LBWdSaveFormat.wdFormatDOSText, Missing.Value, Missing.Value, false); + else if (fileName.ToUpper().EndsWith("DOCX")) + SaveAs2(fileName, LBWdSaveFormat.wdFormatXMLDocument, Missing.Value, Missing.Value, false); + else + SaveAs2(fileName, Missing.Value, Missing.Value, Missing.Value, false); + } + public void SaveAs2(params object[] myParams) => InvokeMethod("SaveAs", myParams); + public void SaveAs(string fileName, LBWdSaveFormat format) => SaveAs2(fileName, format, Missing.Value, Missing.Value, false); + public LBRange Range(int Start, int End) => new LBRange(InvokeMethod("Range", Start, End)); + /// + /// Length is Pages and Partial Pages + /// The integral part is the number of full pages + /// The decimal part is the size of the last page divided by 7200 + /// (the first two digits should be the number of inches) + /// + public float Length + { + get + { + ActiveWindow.ActivePane.View.Type = LBWdViewType.wdPrintView; + ActiveWindow.View.Type = LBWdViewType.wdPrintView; + LBPages myPages = ActiveWindow.ActivePane.Pages;// Start with pages + float retval = (float)myPages.Count - 1; + LBRange myRange = Range(); + + myRange = myRange.GoTo(LBWdGoToItem.wdGoToPercent, LBWdGoToDirection.wdGoToAbsolute, 0); + float mytop = myRange.PageSetup.TopMargin; myRange = myRange.GoTo(LBWdGoToItem.wdGoToPercent, LBWdGoToDirection.wdGoToLast, 100); - //float partial = (float) myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary); - // B2018-028 Word 2016 has a different value for the Vertical Position Relative to the Text Boundary than older version of Word. - // We now need to calculated the last row of text in the PROMS attachment differently. - // We now subtract the TopMargin the Page Setup from the Vertical Position Relative to the Page - // this works with older versions of MS Word as well. - float partial = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage) - mytop; - partial += myRange.Font.Size; - retval += partial / 7200; - return retval; - } - } - public string Ascii - { - get - { - LBRange myRange = Range(); - myRange = myRange.GoTo(LBWdGoToItem.wdGoToPercent, LBWdGoToDirection.wdGoToLast, 100); - myRange.Start = 0; - return ReplaceSymbolCharacters(GetRangeText(myRange)); - } - } - private static string[] SymbolFontName = { "VolianDraw", "WingDings", "VESymb", "VESymbFix", "Symbol" }; - private static bool IsSymbolFont(string fontName) - { - foreach (string symbolFont in SymbolFontName) - if (fontName.ToUpper().StartsWith(symbolFont.ToUpper())) - return true; - return false; - } - - /// - /// Checks to see if the document contains symbol characters - /// - /// - public bool HasSymbolCharacters - { - get - { - LBRange myRange = Range(); - myRange = myRange.GoTo(LBWdGoToItem.wdGoToPercent, LBWdGoToDirection.wdGoToLast, 100); - myRange.Start = 0; - int end = myRange.End; - string myText = GetRangeText(myRange); - //return _RegFindSymbol.IsMatch(myText); - MatchCollection problems = _RegFindSymbol.Matches(myText); - int offset = 0; - foreach (Match problem in problems) - { - myRange.Start = problem.Index + offset; - myRange.End = problem.Index + problem.Length + offset; - int newOffset = FindRangeOffset(myRange, problem, offset, end); - if (IsSymbolFont(myRange.Font.Name)) - { - Console.WriteLine("Font '{0}' has Symbols", myRange.Font.Name); - //return true; - } - else - return true; - offset = newOffset; - } - return false; - } - } - Regex _RegFindSymbol = new Regex("[\\uF020-\\uF07F]+"); + float partial = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage) - mytop; + partial += myRange.Font.Size; + retval += partial / 7200; + return retval; + } + } + public string Ascii + { + get + { + LBRange myRange = Range(); + myRange = myRange.GoTo(LBWdGoToItem.wdGoToPercent, LBWdGoToDirection.wdGoToLast, 100); + myRange.Start = 0; + return ReplaceSymbolCharacters(GetRangeText(myRange)); + } + } + private static readonly string[] SymbolFontName = { "VolianDraw", "WingDings", "VESymb", "VESymbFix", "Symbol" }; + private static bool IsSymbolFont(string fontName) + { + foreach (string symbolFont in SymbolFontName) + if (fontName.ToUpper().StartsWith(symbolFont.ToUpper())) + return true; + return false; + } - /// - /// Get the Range Text with error handling. myRange.Text sometimes will get a null reference exception. - /// - /// - /// - internal static string GetRangeText(LBRange myRange) - { - string text=""; - try - { - if (myRange.Start == myRange.End)// If Start and End equal return an empty string. - text = ""; - else - text = myRange.Text; - } - catch (Exception ex) - { - Console.WriteLine("GetRangeText {0} - {1}", ex.GetType().Name, ex.Message); - } - return text; - } - /// - /// Looks for the problem string and adjusts the range as necessary - /// - /// - /// - /// - /// - /// - private int FindRangeOffset(LBRange myRange, Match problem, int offset, int end) - { - // try to find the string - string text = GetRangeText(myRange); - if (text != problem.Value) - { - // Get the entire text starting at the offset of the first match - myRange.Start = problem.Index + offset; - myRange.End = end; - text = GetRangeText(myRange); - while (!text.StartsWith(problem.Value)) - { - int newStart = text.IndexOf(problem.Value);// Find the string if it is not at the beginning - myRange.Start += myRange.Start == newStart ? newStart + 1 : newStart; // adjust the starting location - text = GetRangeText(myRange);// get the text to check - } - myRange.End = myRange.Start + problem.Length; // assume that the end should be the start plus the length - text = GetRangeText(myRange); - while (text.Length < problem.Length) // If the result is too short increase the length - { - myRange.End += (problem.Length - text.Length); - text = GetRangeText(myRange); - } - } - return myRange.Start - problem.Index; - } - /// - /// ReplaceSymbolCharacters processes the string returned and changes any symbols (0xF0??) to normal characters - /// - /// - /// - private static string ReplaceSymbolCharacters(string str) - { - StringBuilder results = new StringBuilder(); - foreach (char c in str) - { - if ((c & 0xFF00) == 0xF000) - results.Append((char)(c & 0xFF)); - else - results.Append((char)(c)); - } - return results.ToString(); - } - /// - /// Close the document - /// - /// Save Changes - public void Close(bool SaveChanges) - { - InvokeMethod("Close", SaveChanges, Missing.Value, Missing.Value); - } - } - public partial class LBFind - { - public void ReplaceAll() - { - this.Execute(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, - Missing.Value, Missing.Value, Missing.Value, Missing.Value, LBWdReplace.wdReplaceAll, Missing.Value, - Missing.Value, Missing.Value, Missing.Value); - } - } - public partial class LBFontClass : LBComObject - { - public int TextColor - { - get { return (int)GetProperty("Color"); } - set { SetProperty("Color", value); } - } - } - public partial class LBRange : LBComObject - { - public Object get_Information(LBWdInformation info) - { - return GetProperty("Information", info); - } - public LBRange GoTo(LBWdGoToItem What, LBWdGoToDirection Which, int Count) - { - return new LBRange(InvokeMethod("GoTo", What, Which, Count, Missing.Value)); - } - } - public partial class LBSelection : LBComObject - { - public Object get_Information(LBWdInformation info) - { - return GetProperty("Information", info); - } - public int MoveStart(LBWdUnits Unit, int Count) - { - return InvokeMethod("MoveStart", Unit, Count) as int? ?? 0; - } - public int MoveEnd(LBWdUnits Unit, int Count) - { - return InvokeMethod("MoveEnd", Unit, Count) as int? ?? 0; - } - public int EndKey(LBWdUnits Unit, bool Extend) - { - return InvokeMethod("EndKey", Unit, Extend) as int? ?? 0; - } - public bool LastWasUpper - { - get - { - LBRange myRange = Range; - int start = myRange.Start - 1; - while (start >= 0) - { - myRange.Start = start; - myRange.End = start + 1; - string previous = LBDocumentClass.GetRangeText(myRange); - if (Regex.IsMatch(previous, "[A-Z]")) return true; - if (Regex.IsMatch(previous, "[a-z]")) return false; - start = start - 1; - } - return false; - } - } - } - public partial class LBInlineShapes : LBComObjectList /* Collection */ - { - public LBInlineShape AddPicture(string FileName, LBRange Range) - { - return new LBInlineShape(InvokeMethod("AddPicture", FileName, false, true, Range)); - } - } - public partial class LBShapes : LBComObjectList /* Collection */ - { - public LBShape AddPicture(string FileName, float Left, float Top, LBRange Anchor) - { - return new LBShape(InvokeMethod("AddPicture", FileName, false, true, Left, Top, Missing.Value, Missing.Value, Anchor)); - } - public LBShape AddPicture(string FileName, float Left, float Top) - { - return new LBShape(InvokeMethod("AddPicture", FileName, false, true, Left, Top, Missing.Value, Missing.Value, Missing.Value)); - } - } - public enum LBMsoTriState - { - msoCTrue = 1, - msoFalse = 0, - msoTriStateMixed = -2, - msoTriStateToggle = -3, - msoTrue = -1 - } - //public partial class ProcessKiller - //{ - // System.Diagnostics.Process _MyProcess; - // private bool _Exited = false; - // public ProcessKiller(System.Diagnostics.Process myProcess) - // { - // _MyProcess = myProcess; - // _MyProcess.Exited += new EventHandler(_MyProcess_Exited); - // _MyProcess.Kill(); - // DateTime next = DateTime.Now.AddMilliseconds(200); - // while (DateTime.Now < next) - // Application.DoEvents(); - // while (!_Exited) - // Application.DoEvents(); - // } - // void _MyProcess_Exited(object sender, EventArgs e) - // { - // Console.WriteLine("Exited"); - // _Exited = true; - // } - //} + /// + /// Checks to see if the document contains symbol characters + /// + /// + public bool HasSymbolCharacters + { + get + { + LBRange myRange = Range(); + myRange = myRange.GoTo(LBWdGoToItem.wdGoToPercent, LBWdGoToDirection.wdGoToLast, 100); + myRange.Start = 0; + int end = myRange.End; + string myText = GetRangeText(myRange); + MatchCollection problems = _RegFindSymbol.Matches(myText); + int offset = 0; + foreach (Match problem in problems) + { + myRange.Start = problem.Index + offset; + myRange.End = problem.Index + problem.Length + offset; + int newOffset = FindRangeOffset(myRange, problem, offset, end); + if (IsSymbolFont(myRange.Font.Name)) + { + Console.WriteLine("Font '{0}' has Symbols", myRange.Font.Name); + } + else + return true; + offset = newOffset; + } + return false; + } + } + readonly Regex _RegFindSymbol = new Regex("[\\uF020-\\uF07F]+"); + + /// + /// Get the Range Text with error handling. myRange.Text sometimes will get a null reference exception. + /// + /// + /// + internal static string GetRangeText(LBRange myRange) + { + string text = ""; + try + { + if (myRange.Start == myRange.End)// If Start and End equal return an empty string. + text = ""; + else + text = myRange.Text; + } + catch (Exception ex) + { + Console.WriteLine("GetRangeText {0} - {1}", ex.GetType().Name, ex.Message); + } + return text; + } + /// + /// Looks for the problem string and adjusts the range as necessary + /// + /// + /// + /// + /// + /// + private int FindRangeOffset(LBRange myRange, Match problem, int offset, int end) + { + // try to find the string + string text = GetRangeText(myRange); + if (text != problem.Value) + { + // Get the entire text starting at the offset of the first match + myRange.Start = problem.Index + offset; + myRange.End = end; + text = GetRangeText(myRange); + while (!text.StartsWith(problem.Value)) + { + int newStart = text.IndexOf(problem.Value);// Find the string if it is not at the beginning + myRange.Start += myRange.Start == newStart ? newStart + 1 : newStart; // adjust the starting location + text = GetRangeText(myRange);// get the text to check + } + myRange.End = myRange.Start + problem.Length; // assume that the end should be the start plus the length + text = GetRangeText(myRange); + while (text.Length < problem.Length) // If the result is too short increase the length + { + myRange.End += (problem.Length - text.Length); + text = GetRangeText(myRange); + } + } + return myRange.Start - problem.Index; + } + /// + /// ReplaceSymbolCharacters processes the string returned and changes any symbols (0xF0??) to normal characters + /// + /// + /// + private static string ReplaceSymbolCharacters(string str) + { + StringBuilder results = new StringBuilder(); + foreach (char c in str) + { + if ((c & 0xFF00) == 0xF000) + results.Append((char)(c & 0xFF)); + else + results.Append((char)(c)); + } + return results.ToString(); + } + /// + /// Close the document + /// + /// Save Changes + public void Close(bool SaveChanges) => InvokeMethod("Close", SaveChanges, Missing.Value, Missing.Value); + } + public partial class LBFind + { + public void ReplaceAll() + { + this.Execute(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, + Missing.Value, Missing.Value, Missing.Value, Missing.Value, LBWdReplace.wdReplaceAll, Missing.Value, + Missing.Value, Missing.Value, Missing.Value); + } + } + public partial class LBFontClass : LBComObject + { + public int TextColor + { + get { return (int)GetProperty("Color"); } + set { SetProperty("Color", value); } + } + } + public partial class LBRange : LBComObject + { + public object get_Information(LBWdInformation info) => GetProperty("Information", info); + public LBRange GoTo(LBWdGoToItem What, LBWdGoToDirection Which, int Count) => new LBRange(InvokeMethod("GoTo", What, Which, Count, Missing.Value)); + } + public partial class LBSelection : LBComObject + { + public object get_Information(LBWdInformation info) => GetProperty("Information", info); + public int MoveStart(LBWdUnits Unit, int Count) => InvokeMethod("MoveStart", Unit, Count) as int? ?? 0; + public int MoveEnd(LBWdUnits Unit, int Count) => InvokeMethod("MoveEnd", Unit, Count) as int? ?? 0; + public int EndKey(LBWdUnits Unit, bool Extend) => InvokeMethod("EndKey", Unit, Extend) as int? ?? 0; + public bool LastWasUpper + { + get + { + LBRange myRange = Range; + int start = myRange.Start - 1; + while (start >= 0) + { + myRange.Start = start; + myRange.End = start + 1; + string previous = LBDocumentClass.GetRangeText(myRange); + if (Regex.IsMatch(previous, "[A-Z]")) return true; + if (Regex.IsMatch(previous, "[a-z]")) return false; + start--; + } + return false; + } + } + } + public partial class LBInlineShapes : LBComObjectList /* Collection */ + { + public LBInlineShape AddPicture(string FileName, LBRange Range) => new LBInlineShape(InvokeMethod("AddPicture", FileName, false, true, Range)); + } + public partial class LBShapes : LBComObjectList /* Collection */ + { + public LBShape AddPicture(string FileName, float Left, float Top, LBRange Anchor) => new LBShape(InvokeMethod("AddPicture", FileName, false, true, Left, Top, Missing.Value, Missing.Value, Anchor)); + public LBShape AddPicture(string FileName, float Left, float Top) => new LBShape(InvokeMethod("AddPicture", FileName, false, true, Left, Top, Missing.Value, Missing.Value, Missing.Value)); + } + public enum LBMsoTriState + { + msoCTrue = 1, + msoFalse = 0, + msoTriStateMixed = -2, + msoTriStateToggle = -3, + msoTrue = -1 + } } diff --git a/PROMS/LBWordLibrary/LBWordLibrary.csproj b/PROMS/LBWordLibrary/LBWordLibrary.csproj index 8164fb19..577c35e5 100644 --- a/PROMS/LBWordLibrary/LBWordLibrary.csproj +++ b/PROMS/LBWordLibrary/LBWordLibrary.csproj @@ -79,6 +79,7 @@ + diff --git a/PROMS/LBWordLibrary/OutlookLBComObject.cs b/PROMS/LBWordLibrary/OutlookLBComObject.cs index c459dcdc..ac2bdacc 100644 --- a/PROMS/LBWordLibrary/OutlookLBComObject.cs +++ b/PROMS/LBWordLibrary/OutlookLBComObject.cs @@ -1,64 +1,45 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Reflection; namespace LBOutlookLibrary { public abstract partial class LBComObject { - private Object _Item; - internal Object Item + private object _Item; + internal object Item { get { return _Item; } set { _Item = value; - if (value != null) _MyType = _Item.GetType(); + if (value != null) MyType = _Item.GetType(); } } - private Type _MyType; - public Type MyType - { - get { return _MyType; } - set { _MyType = value; } - } - protected LBComObject() { } + + public Type MyType { get; set; } + protected LBComObject() { } protected LBComObject(string ProgID) { Type objClassType; objClassType = Type.GetTypeFromProgID(ProgID); Item = Activator.CreateInstance(objClassType); } - protected LBComObject(Object item) - { - Item = item; - } - private Object DoInvokeMember(string name, Object[] parameters, BindingFlags bf, Binder b) + protected LBComObject(object item) => Item = item; + private object DoInvokeMember(string name, object[] parameters, BindingFlags bf, Binder b) { try { - return _MyType.InvokeMember(name, bf, b, _Item, parameters); + return MyType.InvokeMember(name, bf, b, _Item, parameters); } catch (Exception ex) { - throw new Exception(string.Format("LBComObject.DoInvokeMember {0}.{1}", _MyType.Name, name), ex); + throw new Exception(string.Format("LBComObject.DoInvokeMember {0}.{1}", MyType.Name, name), ex); } - return null; } - protected void SetProperty(string propertyName, params Object[] parameters) - { - DoInvokeMember(propertyName, parameters, BindingFlags.SetProperty, null); - } - protected Object GetProperty(string propertyName) - { - return DoInvokeMember(propertyName, null, BindingFlags.GetProperty, null); - } - protected Object GetProperty(string propertyName, params Object[] parameters) - { - return DoInvokeMember(propertyName, parameters, BindingFlags.GetProperty, null); - } - protected Object InvokeMethod(string methodName, params Object[] parameters) + protected void SetProperty(string propertyName, params object[] parameters) => DoInvokeMember(propertyName, parameters, BindingFlags.SetProperty, null); + protected object GetProperty(string propertyName) => DoInvokeMember(propertyName, null, BindingFlags.GetProperty, null); + protected object GetProperty(string propertyName, params object[] parameters) => DoInvokeMember(propertyName, parameters, BindingFlags.GetProperty, null); + protected object InvokeMethod(string methodName, params object[] parameters) { if (parameters != null) FixParameters(parameters); @@ -71,45 +52,15 @@ namespace LBOutlookLibrary if (parameters[i] is LBComObject) parameters[i] = (parameters[i] as LBComObject).Item; } - protected Object InvokeMethod(string methodName) - { - return InvokeMethod(methodName, null); - } - } - public class LBComObjectList : LBComObject - where TList : LBComObjectList - where TItem : LBComObject, new() - { - //public new(Object item):base(item){} - public TItem Add() - { - TItem tmp = new TItem(); - tmp.Item = InvokeMethod("Add"); - return tmp; - } - //public TItem this[int item] - //{ - // get - // { - // TItem tmp = new TItem(); - // tmp.Item = GetProperty("Item", item); - // return tmp; - // } - //} - } + protected object InvokeMethod(string methodName) => InvokeMethod(methodName, null); + } public partial class LBApplicationClass : LBComObject { public LBApplicationClass() : base("Outlook.Application") { } - public LBApplicationClass(Object item) : base(item) { } - public System.Object CreateItem(LBOlItemType ItemType) - { - return InvokeMethod("CreateItem", ItemType); - } - public void Quit() - { - InvokeMethod("Quit"); - } - } + public LBApplicationClass(object item) : base(item) { } + public object CreateItem(LBOlItemType ItemType) => InvokeMethod("CreateItem", ItemType); + public void Quit() => InvokeMethod("Quit"); + } public enum LBOlItemType { olMailItem = 0, @@ -124,13 +75,13 @@ namespace LBOutlookLibrary public partial class LBMailItem : LBComObject { public LBMailItem() { } - public LBMailItem(Object item) : base(item) { } + public LBMailItem(object item) : base(item) { } } public partial class LBMailItemClass : LBComObject { public LBMailItemClass() { } - public LBMailItemClass(Object item) : base(item) { } - public String Body + public LBMailItemClass(object item) : base(item) { } + public string Body { get { return (GetProperty("Body").ToString()); } set { SetProperty("Body", value); } @@ -140,29 +91,20 @@ namespace LBOutlookLibrary get { return (LBOlBodyFormat)GetProperty("BodyFormat"); } set { SetProperty("BodyFormat", value); } } - public LBAttachments Attachments - { - get { return new LBAttachments(GetProperty("Attachments")); } - } - public String Subject + public LBAttachments Attachments => new LBAttachments(GetProperty("Attachments")); + public string Subject { get { return (GetProperty("Subject").ToString()); } set { SetProperty("Subject", value); } } - public LBRecipients Recipients - { - get { return new LBRecipients(GetProperty("Recipients")); } - } - public String To + public LBRecipients Recipients => new LBRecipients(GetProperty("Recipients")); + public string To { get { return (GetProperty("To").ToString()); } set { SetProperty("To", value); } } - public void Send() - { - InvokeMethod("Send"); - } - } + public void Send() => InvokeMethod("Send"); + } public enum LBOlBodyFormat { olFormatUnspecified = 0, @@ -173,79 +115,40 @@ namespace LBOutlookLibrary public partial class LBAttachments : LBComObject { public LBAttachments() { } - public LBAttachments(Object item) : base(item) { } - public int Count - { - get { return (GetProperty("Count") as int? ?? 0); } - } - public LBAttachment Item - { - get { return new LBAttachment(GetProperty("Item")); } - } - public LBAttachment Add(object Source) - { - return new LBAttachment(InvokeMethod("Add", Source, Missing.Value, Missing.Value, Missing.Value)); - } - public LBAttachment Add(object Source, object Type, object Position, object DisplayName) + public LBAttachments(object item) : base(item) { } + public int Count => (GetProperty("Count") as int? ?? 0); + public new LBAttachment Item => new LBAttachment(GetProperty("Item")); + public LBAttachment Add(object Source) => new LBAttachment(InvokeMethod("Add", Source, Missing.Value, Missing.Value, Missing.Value)); + public LBAttachment Add(object Source, object Type, object Position, object DisplayName) { return new LBAttachment(InvokeMethod("Add", Source, Type, Position, DisplayName)); } - public void Remove(int Index) - { - InvokeMethod("Remove", Index); - } - } + public void Remove(int Index) => InvokeMethod("Remove", Index); + } public partial class LBRecipients : LBComObject { public LBRecipients() { } - public LBRecipients(Object item) : base(item) { } - public int Count - { - get { return (GetProperty("Count") as int? ?? 0); } - } - public LBRecipient Item - { - get { return new LBRecipient(GetProperty("Item")); } - } - public LBRecipient Add(string Name) - { - return new LBRecipient(InvokeMethod("Add", Name)); - } - public void Remove(int Index) - { - InvokeMethod("Remove", Index); - } - public Boolean ResolveAll() - { - return InvokeMethod("ResolveAll") as Boolean? ?? false; - } - } + public LBRecipients(object item) : base(item) { } + public int Count => (GetProperty("Count") as int? ?? 0); + public new LBRecipient Item => new LBRecipient(GetProperty("Item")); + public LBRecipient Add(string Name) => new LBRecipient(InvokeMethod("Add", Name)); + public void Remove(int Index) => InvokeMethod("Remove", Index); + public bool ResolveAll() => InvokeMethod("ResolveAll") as bool? ?? false; + } public partial class LBAttachment : LBComObject { public LBAttachment() { } - public LBAttachment(Object item) : base(item) { } - public LBOlAttachmentType Type - { - get { return (LBOlAttachmentType)GetProperty("Type"); } - } - } + public LBAttachment(object item) : base(item) { } + public LBOlAttachmentType Type => (LBOlAttachmentType)GetProperty("Type"); + } public partial class LBRecipient : LBComObject { public LBRecipient() { } - public LBRecipient(Object item) : base(item) { } - public String Address - { - get { return (GetProperty("Address").ToString()); } - } - public String Name - { - get { return (GetProperty("Name").ToString()); } - } - public Boolean Resolve() - { - return InvokeMethod("Resolve") as Boolean? ?? false; - } - } + public LBRecipient(object item) : base(item) { } + public string Address => (GetProperty("Address").ToString()); + public string Name => (GetProperty("Name").ToString()); + public bool Resolve() => InvokeMethod("Resolve") as bool? ?? false; + } public enum LBOlAttachmentType { olByValue = 1, diff --git a/PROMS/LBWordLibrary/OutlookLBComObjectExt.cs b/PROMS/LBWordLibrary/OutlookLBComObjectExt.cs index 20bd38c1..4cfda7fe 100644 --- a/PROMS/LBWordLibrary/OutlookLBComObjectExt.cs +++ b/PROMS/LBWordLibrary/OutlookLBComObjectExt.cs @@ -1,21 +1,13 @@ using System; -using System.Collections.Generic; -using System.Text; namespace LBOutlookLibrary { public partial class LBApplicationClass { - public LBMailItemClass CreateMailItem() - { - return new LBMailItemClass(CreateItem(LBOlItemType.olMailItem)); - } - } + public LBMailItemClass CreateMailItem() => new LBMailItemClass(CreateItem(LBOlItemType.olMailItem)); + } public partial class LBMailItemClass { - public void AddAttachment(string filename) - { - Attachments.Add(filename, LBOlAttachmentType.olByValue, Type.Missing, Type.Missing); - } - } + public void AddAttachment(string filename) => Attachments.Add(filename, LBOlAttachmentType.olByValue, Type.Missing, Type.Missing); + } } diff --git a/PROMS/LBWordLibrary/RegHive.cs b/PROMS/LBWordLibrary/RegHive.cs index f4bb27b0..cd0a5991 100644 --- a/PROMS/LBWordLibrary/RegHive.cs +++ b/PROMS/LBWordLibrary/RegHive.cs @@ -49,19 +49,13 @@ namespace Read64bitRegistryFrom32bitApp ref uint lpType, System.Text.StringBuilder lpData, ref uint lpcbData); - #endregion - #endregion + #endregion + #endregion - #region Functions - static public string GetRegKey64Value(UIntPtr inHive, String inKeyName, String inPropertyName) - { - return GetRegKey64Value(inHive, inKeyName, RegSAM.WOW64_64Key, inPropertyName); - } - static public string GetRegKey32Value(UIntPtr inHive, String inKeyName, String inPropertyName) - { - return GetRegKey64Value(inHive, inKeyName, RegSAM.WOW64_32Key, inPropertyName); - } - static public string GetRegKey64Value(UIntPtr inHive, String inKeyName, RegSAM in32or64key, String inPropertyName) + #region Functions + static public string GetRegKey64Value(UIntPtr inHive, string inKeyName, string inPropertyName) => GetRegKey64Value(inHive, inKeyName, RegSAM.WOW64_64Key, inPropertyName); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "inHive kept to match dll signature")] + static public string GetRegKey64Value(UIntPtr inHive, string inKeyName, RegSAM in32or64key, string inPropertyName) { int hkey = 0; try @@ -80,15 +74,10 @@ namespace Read64bitRegistryFrom32bitApp if (0 != hkey) RegCloseKey(hkey); } } - static public bool CheckRegKey64Valid(UIntPtr inHive, String inKeyName) - { - return CheckRegKey64Valid(inHive, inKeyName, RegSAM.WOW64_64Key); - } - static public bool GetRegKey32Valid(UIntPtr inHive, String inKeyName) - { - return CheckRegKey64Valid(inHive, inKeyName, RegSAM.WOW64_32Key); - } - static public bool CheckRegKey64Valid(UIntPtr inHive, String inKeyName, RegSAM in32or64key) + static public bool CheckRegKey64Valid(UIntPtr inHive, string inKeyName) => CheckRegKey64Valid(inHive, inKeyName, RegSAM.WOW64_64Key); + static public bool GetRegKey32Valid(UIntPtr inHive, string inKeyName) => CheckRegKey64Valid(inHive, inKeyName, RegSAM.WOW64_32Key); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "inHive kept to match dll signature")] + static public bool CheckRegKey64Valid(UIntPtr inHive, string inKeyName, RegSAM in32or64key) { int hkey = 0; try @@ -103,8 +92,5 @@ namespace Read64bitRegistryFrom32bitApp } } #endregion - - #region Enums - #endregion } } \ No newline at end of file diff --git a/PROMS/ReferencedObjects/LibSource/VlnStatus/StatusBarFrm.cs b/PROMS/ReferencedObjects/LibSource/VlnStatus/StatusBarFrm.cs index 6828458b..580fc949 100644 --- a/PROMS/ReferencedObjects/LibSource/VlnStatus/StatusBarFrm.cs +++ b/PROMS/ReferencedObjects/LibSource/VlnStatus/StatusBarFrm.cs @@ -19,11 +19,6 @@ *********************************************************************************************/ using System; -using System.Drawing; -using System.Collections; -using System.ComponentModel; -using System.Windows.Forms; -//using ROProfiler; //don't forget to add VlnProfiler to the reference list namespace VlnStatus { @@ -35,11 +30,6 @@ namespace VlnStatus private System.Windows.Forms.ProgressBar progressBar1; private System.Windows.Forms.Label lblBar; private System.Windows.Forms.Label StatMsg; -// private string strLblLast=""; - /// - /// Required designer variable. - /// - private System.ComponentModel.Container components = null; public StatusBarFrm() { @@ -61,21 +51,6 @@ namespace VlnStatus Text = StatusBoxTitle; } - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if(components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify @@ -190,14 +165,6 @@ namespace VlnStatus { lblBar.Text = (Math.Round((decimal)(progressBar1.Value * 100) / progressBar1.Maximum)).ToString(); lblBar.Text += "% Complete"; -// if( lblBar.Text != strLblLast) -// { -// Profiler.Start("UpdateLabel"); - lblBar.Refresh(); -// lblBar.Update(); -// Profiler.End("UpdateLabel"); -// } -// strLblLast = lblBar.Text; } public string StatusMessage @@ -209,10 +176,7 @@ namespace VlnStatus set { StatMsg.Text = value; -// Profiler.Start("StatusMessage"); StatMsg.Refresh(); -// StatMsg.Update(); -// Profiler.End("StatusMessage"); } } diff --git a/PROMS/ReferencedObjects/LibSource/VlnStatus/StatusMessageFrm.cs b/PROMS/ReferencedObjects/LibSource/VlnStatus/StatusMessageFrm.cs index 386d145c..c983a868 100644 --- a/PROMS/ReferencedObjects/LibSource/VlnStatus/StatusMessageFrm.cs +++ b/PROMS/ReferencedObjects/LibSource/VlnStatus/StatusMessageFrm.cs @@ -17,12 +17,6 @@ * Added overbounds check *********************************************************************************************/ -using System; -using System.Drawing; -using System.Collections; -using System.ComponentModel; -using System.Windows.Forms; - namespace VlnStatus { /// @@ -31,10 +25,6 @@ namespace VlnStatus public class StatusMessageFrm : System.Windows.Forms.Form { private System.Windows.Forms.Label lblStatMsg; - /// - /// Required designer variable. - /// - private System.ComponentModel.Container components = null; public StatusMessageFrm() { @@ -54,21 +44,6 @@ namespace VlnStatus Text = StatTitle; } - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if(components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify diff --git a/PROMS/ReferencedObjects/LibSource/VlnStatus/VlnStatusBar.cs b/PROMS/ReferencedObjects/LibSource/VlnStatus/VlnStatusBar.cs index a7a4e2cd..ac47b954 100644 --- a/PROMS/ReferencedObjects/LibSource/VlnStatus/VlnStatusBar.cs +++ b/PROMS/ReferencedObjects/LibSource/VlnStatus/VlnStatusBar.cs @@ -33,7 +33,7 @@ namespace VlnStatus /// public class VlnStatusBar { - StatusBarFrm StatBar; + readonly StatusBarFrm StatBar; private int Cnt; // Create a status window with the default title of "Status" @@ -53,8 +53,6 @@ namespace VlnStatus // Increament the the status bar by the passed in value. public void PerformStep(int val) { -// StatBar.Value = val; -// Cnt = val; BarValue = val; StatBar.PerformStep(); } @@ -62,7 +60,6 @@ namespace VlnStatus // Increament the the status bar by one public void PerformStep() { -// StatBar.Value = StatBar.Value + 1; Cnt++; BarValue = Cnt; StatBar.PerformStep(); diff --git a/PROMS/ReferencedObjects/LibSource/VlnStatus/VlnStatusMessage.cs b/PROMS/ReferencedObjects/LibSource/VlnStatus/VlnStatusMessage.cs index e0221ee8..ff26ca8c 100644 --- a/PROMS/ReferencedObjects/LibSource/VlnStatus/VlnStatusMessage.cs +++ b/PROMS/ReferencedObjects/LibSource/VlnStatus/VlnStatusMessage.cs @@ -13,8 +13,6 @@ * Added overbounds check *********************************************************************************************/ -using System; - namespace VlnStatus { /// @@ -28,7 +26,7 @@ namespace VlnStatus /// public class VlnStatusMessage { - StatusMessageFrm StatusMessageBox; + readonly StatusMessageFrm StatusMessageBox; // Create a status window with the default title of "Status" public VlnStatusMessage() diff --git a/PROMS/RoAccessToSql/GlobalSuppressions.cs b/PROMS/RoAccessToSql/GlobalSuppressions.cs new file mode 100644 index 00000000..6c4a515e --- /dev/null +++ b/PROMS/RoAccessToSql/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Not modifying Naming Styles")] \ No newline at end of file diff --git a/PROMS/RoAccessToSql/Program.cs b/PROMS/RoAccessToSql/Program.cs index 20a37fc6..e73cb61f 100644 --- a/PROMS/RoAccessToSql/Program.cs +++ b/PROMS/RoAccessToSql/Program.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using System.Windows.Forms; namespace RoAccessToSql diff --git a/PROMS/RoAccessToSql/RoAccessToSql.cs b/PROMS/RoAccessToSql/RoAccessToSql.cs index afe5a3ae..a44589c1 100644 --- a/PROMS/RoAccessToSql/RoAccessToSql.cs +++ b/PROMS/RoAccessToSql/RoAccessToSql.cs @@ -1,16 +1,10 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Data; using System.IO; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; using System.Data.OleDb; -using Volian.Base.Library; [assembly: log4net.Config.XmlConfigurator(Watch = true)] @@ -33,25 +27,11 @@ namespace RoAccessToSql public partial class RoAccessToSql : Form { private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - private string _MSAccessPath = null; - public string MSAccessPath - { - get { return _MSAccessPath; } - set { _MSAccessPath = value; } - } - private string _SqlServerName = null; - public string SqlServerName - { - get { return _SqlServerName; } - set { _SqlServerName = value; } - } - private string _SqlDatabaseName = null; - public string SqlDatabaseName - { - get { return _SqlDatabaseName; } - set { _SqlDatabaseName = value; } - } - bool _Initializing = false; + + public string MSAccessPath { get; set; } = null; + public string SqlServerName { get; set; } = null; + public string SqlDatabaseName { get; set; } = null; + readonly bool _Initializing = false; public RoAccessToSql(string[] args) { @@ -66,7 +46,7 @@ namespace RoAccessToSql } else if (parm.StartsWith("/sqldb=")) { - SqlDatabaseName = parm.Substring(7) + "_RO"; + SqlDatabaseName = $"{parm.Substring(7)}_RO"; } else if (parm.StartsWith("/server=")) { @@ -92,7 +72,7 @@ namespace RoAccessToSql if (UserInRoEditor()) this.Close(); tbSqlDbName.Text = SqlDatabaseName; _TmpFileForConnectStr = Path.GetTempPath(); - _TmpFileForConnectStr = _TmpFileForConnectStr + @"\PromsConnect.txt"; + _TmpFileForConnectStr += @"\PromsConnect.txt"; File.Delete(_TmpFileForConnectStr); _Initializing = false; } @@ -100,10 +80,10 @@ namespace RoAccessToSql private bool UserInRoEditor() { FileInfo fiown = null; - FileStream fsown = null; - // The following code was taken from the roeditor. It uses the 'RoEditor.own' file to assure that - // no one is in the roeditor. This file is located in the microsoft access database directory. - try + FileStream fsown; + // The following code was taken from the roeditor. It uses the 'RoEditor.own' file to assure that + // no one is in the roeditor. This file is located in the microsoft access database directory. + try { string filename = MSAccessPath + @"\RoEditor.own"; fiown = new FileInfo(filename); @@ -119,7 +99,7 @@ namespace RoAccessToSql fsown = fiown.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); TextReader tr1 = new StreamReader(fsown); string who1 = tr1.ReadToEnd(); - MessageBox.Show(ex.Message + "\r\n\r\n" + who1, "RO Editor In Use", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + MessageBox.Show($"{ex.Message}\r\n\r\n{who1}", "RO Editor In Use", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } fsown = fiown.Open(FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite); TextReader tr = new StreamReader(fsown); @@ -142,8 +122,8 @@ namespace RoAccessToSql tw.WriteLine("Current User: {0}, Date and Time Started: {1}", Environment.UserName.ToUpper(), DateTime.Now.ToString("MM/dd/yyyy @ hh:mm")); tw.Flush(); } - catch (IOException ex) - { + catch (IOException) + { fsown = fiown.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); TextReader tr = new StreamReader(fsown); string who = tr.ReadToEnd(); @@ -154,25 +134,20 @@ namespace RoAccessToSql } return false; } - static string _ErrorLogFileName; - public static string ErrorLogFileName - { - get { return _ErrorLogFileName; } - set { _ErrorLogFileName = value; } - } - // make error log file name (uses same logic as proms error log) - static bool ChangeLogFileName(string AppenderName, string NewFilename) + + public static string ErrorLogFileName { get; set; } + // make error log file name (uses same logic as proms error log) + static bool ChangeLogFileName(string AppenderName, string NewFilename) { log4net.Repository.ILoggerRepository RootRep; RootRep = log4net.LogManager.GetRepository(); foreach (log4net.Appender.IAppender iApp in RootRep.GetAppenders()) { if (iApp.Name.CompareTo(AppenderName) == 0 - && iApp is log4net.Appender.FileAppender) - { - log4net.Appender.FileAppender fApp = (log4net.Appender.FileAppender)iApp; + && iApp is log4net.Appender.FileAppender fApp) + { string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); - fApp.File = folderPath + @"\VEPROMS\" + (Volian.Base.Library.VlnSettings.GetCommand("prefix", "") + "_").TrimStart("_".ToCharArray()) + NewFilename; + fApp.File = $@"{folderPath}\VEPROMS\{($"{Volian.Base.Library.VlnSettings.GetCommand("prefix", "")}_").TrimStart("_".ToCharArray())}{NewFilename}"; ErrorLogFileName = fApp.File; fApp.ActivateOptions(); return true; @@ -189,7 +164,7 @@ namespace RoAccessToSql if (Directory.Exists(fbd.SelectedPath)) tbAccessPath.Text = fbd.SelectedPath; else - MessageBox.Show("Path doesn't exist " + tbAccessPath.Text); + MessageBox.Show($"Path doesn't exist {tbAccessPath.Text}"); } } // Convert the data @@ -212,7 +187,7 @@ namespace RoAccessToSql { DateTime dtSunday = DateTime.Now.AddDays(-((int)DateTime.Now.DayOfWeek)); - ChangeLogFileName("LogFileAppender", SqlDatabaseName + " " + dtSunday.ToString("yyyyMMdd") + " ErrorLog.txt"); + ChangeLogFileName("LogFileAppender", $"{SqlDatabaseName} {dtSunday:yyyyMMdd} ErrorLog.txt"); _MyLog.InfoFormat("\r\nSession Beginning\r\n<===={0}[SQL:{1:yyMM.ddHH}]====== User: {2}/{3} Started {4} ===============>{5}" , Application.ProductVersion, RevDate, DateTime.Now, Environment.UserDomainName, Environment.UserName, DateTime.Now.ToString("dddd MMMM d, yyyy h:mm:ss tt"), ""); } @@ -229,7 +204,7 @@ namespace RoAccessToSql if (sqlConnection.State == ConnectionState.Open) { // now try to open access db: - string strDatabaseConnectionCommand = "Provider=Microsoft.ACE.OLEDB.12.0;Password=\"\";User ID=Admin;Data Source=" + MSAccessPath + "\\ROMaster.mdb;Mode=Share Deny None;Extended Properties=\"\";Jet OLEDB:System database=\"\";Jet OLEDB:Registry Path=\"\";Jet OLEDB:Database Password=\"\";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=\"\";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False"; + string strDatabaseConnectionCommand = $"Provider=Microsoft.ACE.OLEDB.12.0;Password=\"\";User ID=Admin;Data Source={MSAccessPath}\\ROMaster.mdb;Mode=Share Deny None;Extended Properties=\"\";Jet OLEDB:System database=\"\";Jet OLEDB:Registry Path=\"\";Jet OLEDB:Database Password=\"\";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=\"\";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False"; using (OleDbConnection accessConnection = new OleDbConnection(strDatabaseConnectionCommand)) { try @@ -251,13 +226,13 @@ namespace RoAccessToSql } else { - _MyLog.Error("SQL Connection is not open. Check connection string: " + tbSqlDbName.Text); - MessageBox.Show("Check connection string: " + tbSqlDbName.Text, "SQL Connection is not open."); + _MyLog.Error($"SQL Connection is not open. Check connection string: {tbSqlDbName.Text}"); + MessageBox.Show($"Check connection string: {tbSqlDbName.Text}", "SQL Connection is not open."); } } catch (SqlException ex) { - _MyLog.Error("SQL Connection is not open. Check connection string: " + tbSqlDbName.Text); + _MyLog.Error($"SQL Connection is not open. Check connection string: {tbSqlDbName.Text}"); MessageBox.Show(ex.Message, "Unknown error when migrating RO data from MS Access to SQL"); } } @@ -274,11 +249,10 @@ namespace RoAccessToSql lastTimeDbs = ProgressBarUpdate(pBarDbs, null, 0, 1, 0, 0, lastTimeDbs, false); lastTimeRos = ProgressBarUpdate(pBarROs, null, 0, maxCntRo, 0, 0, lastTimeRos, false); lastTimeDbs = ProgressBarUpdate(pBarDbs, "ROMaster Table", 0, 5, 0, 1, lastTimeDbs, false); - OleDbDataReader reader = null; - OleDbCommand command = new OleDbCommand("select * from ROMaster", accessConnection); - reader = command.ExecuteReader(); - // Do access's romaster table first so that the list of other tables to process is found. While doing this, migrate this table's data. - int cntRo = 0; + OleDbCommand command = new OleDbCommand("select * from ROMaster", accessConnection); + OleDbDataReader reader = command.ExecuteReader(); + // Do access's romaster table first so that the list of other tables to process is found. While doing this, migrate this table's data. + int cntRo = 0; int cntDb = 0; int maxCntDb = 0; while (reader.Read()) // reading from Access Database @@ -303,13 +277,12 @@ namespace RoAccessToSql maxCntDb++; } } - lastTimeRos = ProgressBarUpdate(pBarROs, "ROMaster", 0, maxCntRo, maxCntRo, 1, lastTimeRos, true); + ProgressBarUpdate(pBarROs, "ROMaster", 0, maxCntRo, maxCntRo, 1, lastTimeRos, true); lastTimeDbs = ProgressBarUpdate(pBarDbs, null, 0, maxCntDb, 0, 0, lastTimeDbs, false); reader.Close(); - reader = null; - - // now migrate all the tables that were found - foreach (string tableName in allTables) + + // now migrate all the tables that were found + foreach (string tableName in allTables) { lastTimeRos = DateTime.Now; cntRo = 0; @@ -318,7 +291,7 @@ namespace RoAccessToSql lastTimeRos = ProgressBarUpdate(pBarROs, null, 0, maxCntRo, 0, 0, lastTimeRos, true); lastTimeDbs = ProgressBarUpdate(pBarDbs, allTablesText[cntDb], 0, maxCntDb, cntDb, 1, lastTimeDbs, false); command = null; - command = new OleDbCommand("select * from " + tableName, accessConnection); + command = new OleDbCommand($"select * from {tableName}", accessConnection); reader = command.ExecuteReader(); while (reader.Read()) // read all of the records from the current access table { @@ -338,7 +311,7 @@ namespace RoAccessToSql reader = null; lastTimeRos = ProgressBarUpdate(pBarROs, tableName, 0, maxCntRo, maxCntRo, 1, lastTimeRos, false); } - lastTimeDbs = ProgressBarUpdate(pBarDbs, allTablesText[maxCntDb - 1], 0, maxCntDb, maxCntDb, 1, lastTimeDbs, false); + ProgressBarUpdate(pBarDbs, allTablesText[maxCntDb - 1], 0, maxCntDb, maxCntDb, 1, lastTimeDbs, false); pBarDbs.Text = "Referenced Object Tables Migration Completed"; pBarROs.Text = "Referenced Objects Migration Completed"; btnConvert.Enabled = false; @@ -357,7 +330,7 @@ namespace RoAccessToSql string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now); string strInsert = "INSERT INTO ROMaster (RecID, RecType, ModDateTime, Info) "; // note that '8' for rectype flags database converted: - strInsert = strInsert + " VALUES ('09999999', 8, '" + dt + "', '" + _SqlConnectStr + "');"; + strInsert = $"{strInsert} VALUES ('09999999', 8, '{dt}', '{_SqlConnectStr}');"; OleDbCommand command = new OleDbCommand(strInsert, accessConnection); reader = command.ExecuteReader(); if (reader.Read()) return; @@ -367,7 +340,7 @@ namespace RoAccessToSql MessageBox.Show(e.Message, "Error on insert to flag migration completed"); } } - private string _TmpFileForConnectStr = null; + private readonly string _TmpFileForConnectStr = null; private void WriteSqlPathToTempFile() { System.IO.File.WriteAllText(_TmpFileForConnectStr, _SqlConnectStr); @@ -375,13 +348,12 @@ namespace RoAccessToSql // the following is used to update the progress bars, it finds how many records are in a table. private int GetRecordCountForTable(string tableName, OleDbConnection accessConnection) { - OleDbDataReader reader = null; - int retcnt = 100; + int retcnt = 100; try { - OleDbCommand command = new OleDbCommand("SELECT COUNT (RecID) as cnt FROM " + tableName, accessConnection); - reader = command.ExecuteReader(); - if (reader.Read()) + OleDbCommand command = new OleDbCommand($"SELECT COUNT (RecID) as cnt FROM {tableName}", accessConnection); + OleDbDataReader reader = command.ExecuteReader(); + if (reader.Read()) { retcnt = reader.GetInt32(0); } @@ -393,7 +365,8 @@ namespace RoAccessToSql } return retcnt; } - DateTime ProgressBarUpdate(DevComponents.DotNetBar.Controls.ProgressBarX pbi, string msg, int min, int max, int progress, int flag, DateTime lastUpdateDisplay, bool doTimeCheck) + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping min for Debugging")] + DateTime ProgressBarUpdate(DevComponents.DotNetBar.Controls.ProgressBarX pbi, string msg, int min, int max, int progress, int flag, DateTime lastUpdateDisplay, bool doTimeCheck) { if (flag == 0) // setup pbi.Maximum = max; @@ -412,11 +385,13 @@ namespace RoAccessToSql { try { - SqlCommand command = new SqlCommand(); - command.Connection = sqlConnection; - command.CommandType = CommandType.StoredProcedure; - command.CommandText = "insertAllRectypes"; - command.Parameters.AddWithValue("@RecType", RecType); + SqlCommand command = new SqlCommand + { + Connection = sqlConnection, + CommandType = CommandType.StoredProcedure, + CommandText = "insertAllRectypes" + }; + command.Parameters.AddWithValue("@RecType", RecType); if (AccPageID == null || AccPageID == "") command.Parameters.AddWithValue("@AccPageID", string.Empty); else @@ -428,9 +403,8 @@ namespace RoAccessToSql command.Parameters.AddWithValue("@ModDateTime", ModDateTime); using (SqlDataReader reader = command.ExecuteReader()) { - bool success = true; - } - command = null; + } + command = null; } catch (Exception ex) { @@ -438,32 +412,15 @@ namespace RoAccessToSql _MyLog.Error(msg, ex); } } - private void btnExit_Click(object sender, EventArgs e) - { - this.Close(); - } - // the user selected the button to test the sql connection string - private void btnTestConnect_Click(object sender, EventArgs e) - { - TestConnection(true); - } - // the RevDate & RevDescription are found in a stored procedure, vesp_GetSQLCodeRevision, in the sql database. These get updated each - // time a revision is made to the sql database using ROFixes.sql script. - private static DateTime _RevDate = DateTime.MinValue; - public static DateTime RevDate - { - get { return _RevDate; } - set { _RevDate = value; } - } - private static string _RevDescription = "Unknown"; - public static string RevDescription - { - get { return _RevDescription; } - set { _RevDescription = value; } - } - // This is called to test the sql connection, either from the button when pressed by user, or from the convert button, before - // the conversion is done. See below for what is checked - private bool TestConnection(bool notifyUser) + private void btnExit_Click(object sender, EventArgs e) => this.Close(); + // the user selected the button to test the sql connection string + private void btnTestConnect_Click(object sender, EventArgs e) => TestConnection(true); + + public static DateTime RevDate { get; set; } = DateTime.MinValue; + public static string RevDescription { get; set; } = "Unknown"; + // This is called to test the sql connection, either from the button when pressed by user, or from the convert button, before + // the conversion is done. See below for what is checked + private bool TestConnection(bool notifyUser) { // The following conditions must be true in order to migrate the ro data to sql. Only the first condition can be // tested in this executable since the roall database is interfaced to by the roeditor & the program that migrates the data. @@ -485,12 +442,14 @@ namespace RoAccessToSql connection.Open(); if (connection.State == ConnectionState.Open) { - // now see if there is an roall table - SqlCommand command = new SqlCommand(); - command.Connection = connection; - command.CommandType = CommandType.Text; - command.CommandText = "(SELECT count(*) FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ROALL]') AND type in (N'U'))"; - using (SqlDataReader reader = command.ExecuteReader()) + // now see if there is an roall table + SqlCommand command = new SqlCommand + { + Connection = connection, + CommandType = CommandType.Text, + CommandText = "(SELECT count(*) FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ROALL]') AND type in (N'U'))" + }; + using (SqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { @@ -509,11 +468,13 @@ namespace RoAccessToSql { // now see if there are stored procedures: command = null; // reset command - command = new SqlCommand(); - command.Connection = connection; - command.CommandType = CommandType.Text; - command.CommandText = "(SELECT count(*) FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[deleteByROTable]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)"; - using (SqlDataReader reader = command.ExecuteReader()) + command = new SqlCommand + { + Connection = connection, + CommandType = CommandType.Text, + CommandText = "(SELECT count(*) FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[deleteByROTable]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)" + }; + using (SqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { @@ -533,11 +494,13 @@ namespace RoAccessToSql { // now test that the roall table is empty: command = null; // reset command - command = new SqlCommand(); - command.Connection = connection; - command.CommandType = CommandType.Text; - command.CommandText = "SELECT count(*) FROM roall"; - using (SqlDataReader reader = command.ExecuteReader()) + command = new SqlCommand + { + Connection = connection, + CommandType = CommandType.Text, + CommandText = "SELECT count(*) FROM roall" + }; + using (SqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { @@ -557,16 +520,18 @@ namespace RoAccessToSql { // now test that the database version is ok command = null; // reset command - command = new SqlCommand(); - command.Connection = connection; - command.CommandType = CommandType.StoredProcedure; - command.CommandText = "vesp_GetSQLCodeRevision"; - using (SqlDataReader reader = command.ExecuteReader()) + command = new SqlCommand + { + Connection = connection, + CommandType = CommandType.StoredProcedure, + CommandText = "vesp_GetSQLCodeRevision" + }; + using (SqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { - _RevDate = reader.GetDateTime(0); - _RevDescription = reader.GetString(1); + RevDate = reader.GetDateTime(0); + RevDescription = reader.GetString(1); dbsuc = true; } else @@ -582,13 +547,13 @@ namespace RoAccessToSql } catch (SqlException ex) { - if (notifyUser) MessageBox.Show("Connection failed: " + ex, "Connection Failed"); + if (notifyUser) MessageBox.Show($"Connection failed: {ex}", "Connection Failed"); } } } catch (Exception ex) { - if (notifyUser) MessageBox.Show("Connection failed: " + ex, "Connection Failed"); + if (notifyUser) MessageBox.Show($"Connection failed: {ex}", "Connection Failed"); } if (notifyUser && success) MessageBox.Show("You have been successfully connected to the database!", "Connection Succeeded"); diff --git a/PROMS/RoAccessToSql/RoAccessToSql.csproj b/PROMS/RoAccessToSql/RoAccessToSql.csproj index d956be8a..99b22330 100644 --- a/PROMS/RoAccessToSql/RoAccessToSql.csproj +++ b/PROMS/RoAccessToSql/RoAccessToSql.csproj @@ -66,6 +66,7 @@ + Form diff --git a/PROMS/TablePicker/TablePicker.cs b/PROMS/TablePicker/TablePicker.cs index 92369edb..551cb53d 100644 --- a/PROMS/TablePicker/TablePicker.cs +++ b/PROMS/TablePicker/TablePicker.cs @@ -1,7 +1,4 @@ -using System; using System.Drawing; -using System.Collections; -using System.ComponentModel; using System.Windows.Forms; namespace Accentra.Controls @@ -11,11 +8,6 @@ namespace Accentra.Controls /// public class TablePicker : System.Windows.Forms.Form { - /// - /// Required designer variable. - /// - private System.ComponentModel.Container components = null; - public TablePicker() { // Activates double buffering @@ -29,21 +21,6 @@ namespace Accentra.Controls InitializeComponent(); } - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if(components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify @@ -75,82 +52,41 @@ namespace Accentra.Controls } #endregion - private Pen BeigePen = new Pen(Color.Beige, 1); - private Brush BeigeBrush = System.Drawing.Brushes.Beige; - private Brush GrayBrush = System.Drawing.Brushes.Gray; - private Brush BlackBrush = System.Drawing.Brushes.Black; - private Brush WhiteBrush = System.Drawing.Brushes.White; + private readonly Brush BlackBrush = System.Drawing.Brushes.Black; + private readonly Brush WhiteBrush = System.Drawing.Brushes.White; - private Brush Jbrush = System.Drawing.Brushes.LightBlue; - //private Brush Jbrush = System.Drawing.Brushes.LightSteelBlue; - //private Brush Jbrush = System.Drawing.Brushes.SteelBlue; - //private Brush Jbrush = System.Drawing.Brushes.PowderBlue; + private readonly Brush Jbrush = System.Drawing.Brushes.LightBlue; - private Pen BorderPen = new Pen(SystemColors.ControlDark); - private Pen BluePen = new Pen(Color.SlateGray, 1); + private readonly Pen BorderPen = new Pen(SystemColors.ControlDark); + private readonly Pen BluePen = new Pen(Color.SlateGray, 1); private string DispText = "Esc to Cancel"; // Display text - private int DispHeight = 40;//20; // Display ("Table 1x1", "Cancel") - private Font DispFont = new Font("Tahoma", 8.25F); - private int SquareX = 20; // Width of squares - private int SquareY = 20; // Height of squares + private readonly int DispHeight = 40; // Display ("Table 1x1", "Cancel") + private readonly Font DispFont = new Font("Tahoma", 8.25F); + private readonly int SquareX = 20; // Width of squares + private readonly int SquareY = 20; // Height of squares private int SquareQX = 3; // Number of visible squares (X) private int SquareQY = 3; // Number of visible squares (Y) private int SelQX = 1; // Number of selected squares (x) private int SelQY = 1; // Number of selected squares (y) - private bool bHiding = false; - private bool bCancel = true; // Determines whether to Cancel + public int MaxRows { get; set; } = -1; - // Added my Volian 4/27/11 - private int _MaxRows = -1; + public int MaxCols { get; set; } = -1; - public int MaxRows - { - get { return _MaxRows; } - set { _MaxRows = value; } - } - private int _MaxCols = -1; + /// + /// Returns the number of columns, or the horizontal / X count, + /// of the selection. + /// + public int SelectedColumns => SelQX; - public int MaxCols - { - get { return _MaxCols; } - set { _MaxCols = value; } - } + /// + /// Returns the number of rows, or the vertical / Y count, + /// of the selection. + /// + public int SelectedRows => SelQY; - /// - /// Similar to - /// == , - /// but is used as a state value before the form - /// is hidden and cancellation is finalized. - /// - public bool Cancel { - get { - return bCancel; - } - } - - /// - /// Returns the number of columns, or the horizontal / X count, - /// of the selection. - /// - public int SelectedColumns { - get { - return SelQX; - } - } - - /// - /// Returns the number of rows, or the vertical / Y count, - /// of the selection. - /// - public int SelectedRows { - get { - return SelQY; - } - } - - private void TablePicker_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { + private void TablePicker_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; // First, increment the number of visible squares if the @@ -162,8 +98,8 @@ namespace Accentra.Controls if (SquareQX < 7) SquareQX = 7; if (SquareQY < 5) SquareQY = 5; - if (_MaxRows > 0 && SquareQY > _MaxRows) SquareQY = _MaxRows; - if (_MaxCols > 0 && SquareQX > _MaxCols) SquareQX = _MaxCols; + if (MaxRows > 0 && SquareQY > MaxRows) SquareQY = MaxRows; + if (MaxCols > 0 && SquareQX > MaxCols) SquareQX = MaxCols; // Second, expand the dimensions of this form according to the // number of visible squares. @@ -177,14 +113,7 @@ namespace Accentra.Controls // the text is left-justified, only the Y (vertical) position // is calculated. int dispY = ((SquareY - 1) * SquareQY) + SquareQY + 4; - //if (this.Cancel) { - // DispText = "Esc Key to Cancel"; - //} else { - // DispText = SelQX.ToString() + " by " + SelQY.ToString() + " Table"; - //} - //DispText = SelQX.ToString() + " by " + SelQY.ToString() + " Table\nEsc Key to Cancel"; - //DispText = SelQY.ToString() + " Row"+((SelQY>1)?"s by ":" by ") + SelQX.ToString() + " Column"+((SelQX>1)?"s\nEsc Key to Cancel":"\nEsc Key to Cancel"); - DispText = SelQY.ToString() + " Row" + ((SelQY > 1) ? "s" : "") + " " + SelQX.ToString() + " Column" + ((SelQX > 1) ? "s" : "")+ "\nEsc to Cancel"; + DispText = $"{SelQY} Row{((SelQY > 1) ? "s" : "")} {SelQX} Column{((SelQX > 1) ? "s" : "")}\nEsc to Cancel"; g.DrawString(DispText, DispFont, BlackBrush, 3, dispY + 2); // Draw each of the squares and fill with the default color. @@ -198,7 +127,6 @@ namespace Accentra.Controls // Go back and paint the squares with selection colors. for (int x=0; x private void TablePicker_Deactivate(object sender, System.EventArgs e) { - // bCancel = true - // and DialogResult = DialogResult.Cancel - // were previously already set in MouseLeave. - - //this.Hide(); } /// @@ -242,42 +165,24 @@ namespace Accentra.Controls /// escaped (canceling) state. /// private void TablePicker_MouseLeave(object sender, System.EventArgs e) { - //if (!bHiding) bCancel = true; - //this.DialogResult = DialogResult.Cancel; - //this.Invalidate(); if (this.DialogResult == DialogResult.None) this.DialogResult = DialogResult.Cancel; } - /// - /// Cancels the prior cancellation caused by MouseLeave. - /// - private void TablePicker_MouseEnter(object sender, System.EventArgs e) { - //bHiding = false; - //bCancel = false; - //this.DialogResult = DialogResult.OK; - this.Invalidate(); - } + /// + /// Cancels the prior cancellation caused by MouseLeave. + /// + private void TablePicker_MouseEnter(object sender, System.EventArgs e) => this.Invalidate(); - /// - /// Detects that the user made a selection by clicking. - /// - private void TablePicker_Click(object sender, System.EventArgs e) { - //bHiding = true; // Not the same as Visible == false - // // because bHiding suggests that the control - // // is still "active" (not canceled). - //this.Hide(); - this.DialogResult = DialogResult.OK; - } + /// + /// Detects that the user made a selection by clicking. + /// + private void TablePicker_Click(object sender, System.EventArgs e) => this.DialogResult = DialogResult.OK; - private void TablePicker_KeyPress(object sender, KeyPressEventArgs e) + private void TablePicker_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Escape) { - //bHiding = true; // Not the same as Visible == false - //// because bHiding suggests that the control - //// is still "active" (not canceled). - //this.Hide(); this.DialogResult = DialogResult.Cancel; } } diff --git a/PROMS/VG/IVGOutput.cs b/PROMS/VG/IVGOutput.cs index 2e5ec04a..1035e0f9 100644 --- a/PROMS/VG/IVGOutput.cs +++ b/PROMS/VG/IVGOutput.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Text; using System.Drawing; using iTextSharp.text.pdf; -using iTextSharp.text.factories; -using Microsoft.Win32; using Volian.Base.Library; namespace VG @@ -25,141 +20,25 @@ namespace VG } public partial class VGOut_Graphics: IVGOutput { - private int _DebugStatus = 0; - public int DebugStatus - { - get { return _DebugStatus; } - set { _DebugStatus = value; } - } - private Graphics _VGOutput; - //public Graphics VGOutput - //{ get { return _VGOutput; } } - public VGOut_Graphics(Graphics vgOutput) - { _VGOutput = vgOutput; } - public float Scale - { get { return 1; } } - //{ get { return _VGOutput.Transform.Elements[0]; } } - public void DrawLine(Pen pn, float startx, float starty, float endx, float endy) - { _VGOutput.DrawLine(pn, startx, starty, endx, endy); } - public void DrawRectangle(Pen pn, RectangleF rectf) + public int DebugStatus { get; set; } = 0; + private readonly Graphics _VGOutput; + public VGOut_Graphics(Graphics vgOutput) => _VGOutput = vgOutput; + public float Scale => 1; + public void DrawLine(Pen pn, float startx, float starty, float endx, float endy) => _VGOutput.DrawLine(pn, startx, starty, endx, endy); + public void DrawRectangle(Pen pn, RectangleF rectf) { _VGOutput.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; _VGOutput.FillRectangle(DebugStatus == 1 ? Brushes.Transparent : Brushes.White, rectf.X, rectf.Y, rectf.Width, rectf.Height); _VGOutput.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; _VGOutput.DrawRectangle(pn, rectf.X, rectf.Y, rectf.Width, rectf.Height); } - public void DrawEllipse(Pen pn, float cx, float cy, float dx, float dy) - { _VGOutput.DrawEllipse(pn, cx, cy, dx, dy); } - public void DrawImage(Bitmap bm, RectangleF rectf) - { _VGOutput.DrawImage(bm, rectf); } - public void DrawString(string text, Font myFont, Brush brush, RectangleF rectf) - { _VGOutput.DrawString(text, myFont, brush, rectf, StringFormat.GenericTypographic); } - public void DrawArc(Pen pn, RectangleF rectf, float startAngle, float sweepAngle) - { _VGOutput.DrawArc(pn, rectf, startAngle, sweepAngle); } - public SizeF MeasureString(string text, Font myFont) - { return _VGOutput.MeasureString(text, myFont, new PointF(0, 0), StringFormat.GenericTypographic); } - public void Save(string fileName) + public void DrawEllipse(Pen pn, float cx, float cy, float dx, float dy) => _VGOutput.DrawEllipse(pn, cx, cy, dx, dy); + public void DrawImage(Bitmap bm, RectangleF rectf) => _VGOutput.DrawImage(bm, rectf); + public void DrawString(string text, Font myFont, Brush brush, RectangleF rectf) => _VGOutput.DrawString(text, myFont, brush, rectf, StringFormat.GenericTypographic); + public void DrawArc(Pen pn, RectangleF rectf, float startAngle, float sweepAngle) => _VGOutput.DrawArc(pn, rectf, startAngle, sweepAngle); + public SizeF MeasureString(string text, Font myFont) => _VGOutput.MeasureString(text, myFont, new PointF(0, 0), StringFormat.GenericTypographic); + public void Save(string fileName) { ;/* Don't do anything*/ } - public float FontSizeAdjust - { get { return .71f * 96f / _VGOutput.DpiX; } } // Changed to adjust for Screen DPI Setting - } - public partial class VGOut_ITextSharp : IVGOutput - { - private int _DebugStatus = 0; - public int DebugStatus - { - get { return _DebugStatus; } - set { _DebugStatus = value; } - } - private PdfContentByte _VGOutput; - //public Graphics VGOutput - //{ get { return _VGOutput; } } - public VGOut_ITextSharp(PdfContentByte vgOutput) - { _VGOutput = vgOutput; } - public float Scale - { get { return 1; } } - public void DrawLine(Pen pn, float startx, float starty, float endx, float endy) - { - _VGOutput.SaveState(); - SetStrokeData(pn); - _VGOutput.MoveTo(startx, ScaleY(starty)); - _VGOutput.LineTo(endx, ScaleY(endy)); - _VGOutput.Stroke(); - _VGOutput.RestoreState(); - } - private void SetStrokeData(Pen pn) - { - _VGOutput.SetLineWidth(pn.Width); - _VGOutput.SetColorStroke(new iTextSharp.text.Color(pn.Color.R, pn.Color.G, pn.Color.B, pn.Color.A)); - } - public void DrawRectangle(Pen pn, RectangleF rectf) - { - _VGOutput.SaveState(); - SetStrokeData(pn); - _VGOutput.Rectangle(rectf.X, ScaleY(rectf.Y), rectf.Width, -rectf.Height); - _VGOutput.Stroke(); - _VGOutput.RestoreState(); - } - public void DrawEllipse(Pen pn, float cx, float cy, float dx, float dy) - { - _VGOutput.SaveState(); - SetStrokeData(pn); - _VGOutput.Ellipse(cx, ScaleY(cy), dx, -dy); - _VGOutput.Stroke(); - _VGOutput.RestoreState(); - } - public void DrawImage(Bitmap bm, RectangleF rectf) - { - _VGOutput.SaveState(); - // TODO: Determine how I can create an iTextSharp.text.Image - //_VGOutput.AddImage(new iTextSharp.text.Image( - _VGOutput.RestoreState(); - } - public void DrawString(string text, Font myFont, Brush brush, RectangleF rectf) - { - _VGOutput.SaveState(); - _VGOutput.BeginText(); - iTextSharp.text.Font itFont = GetFont(myFont.Name); - iTextSharp.text.pdf.BaseFont baseFont = itFont.BaseFont; - // _VGOutput.DrawString(text, myFont, brush, rectf, StringFormat.GenericTypographic); - _VGOutput.MoveText(rectf.X, ScaleY(rectf.Y) - myFont.SizeInPoints); - _VGOutput.SetFontAndSize(baseFont, myFont.SizeInPoints); - _VGOutput.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL); - _VGOutput.ShowTextKerned(text); - _VGOutput.EndText(); - _VGOutput.RestoreState(); - } - public void DrawArc(Pen pn, RectangleF rectf, float startAngle, float sweepAngle) - { - _VGOutput.SaveState(); - SetStrokeData(pn); - _VGOutput.Arc(rectf.X, ScaleY(rectf.Y), rectf.X + rectf.Width, ScaleY(rectf.Y + rectf.Height), -startAngle, -sweepAngle); - _VGOutput.Stroke(); - _VGOutput.RestoreState(); - } - public SizeF MeasureString(string text, Font myFont) - { - iTextSharp.text.Font itFont = GetFont(myFont.Name); - iTextSharp.text.pdf.BaseFont baseFont = itFont.BaseFont; - return new SizeF(baseFont.GetWidthPoint(text,myFont.SizeInPoints) - , baseFont.GetAscentPoint(text, myFont.SizeInPoints) + baseFont.GetDescentPoint(text, myFont.SizeInPoints)); - } - public void Save(string fileName) - { ;/* Don't do anything*/ } - public float FontSizeAdjust - { get { return 1; } } // Changed to adjust for Screen DPI Setting - public static iTextSharp.text.Font GetFont(string fontName) - { - /// - /// B2019-116 Volian.Base.Library This is a generic class for dealing with iTextSharp Fonts - /// Code moved and consolidated from Volian.Print.Library Volian PDF.Library and VG - /// - VlnItextFont.RegisterFont(fontName); - return iTextSharp.text.FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); - } - private float ScaleY(float y) - { - return _VGOutput.PdfWriter.PageSize.Height - y; - } - } + public float FontSizeAdjust => .71f * 96f / _VGOutput.DpiX; // Changed to adjust for Screen DPI Setting + } } diff --git a/PROMS/VG/VG.cs b/PROMS/VG/VG.cs index 856efbd1..7e047535 100644 --- a/PROMS/VG/VG.cs +++ b/PROMS/VG/VG.cs @@ -20,64 +20,34 @@ namespace VG // Temporary page class to store portrait/landscape, Left Margin, Vertical offset, etc public class Page { - private bool _Portrait = true; - public bool Portrait + public bool Portrait { get; set; } = true; + public float LeftMargin { get; set; } = 0; + public float TopMargin { get; set; } = 0; + public float RightMargin { get; set; } = 0; + public float BottomMargin { get; set; } = 0; + public Page(bool portrait, float leftMargin, float topMargin, float rightMargin, float bottomMargin) { - get { return _Portrait; } - set { _Portrait = value; } - } - private float _LeftMargin = 0; - public float LeftMargin - { - get { return _LeftMargin; } - set { _LeftMargin = value; } - } - private float _TopMargin = 0; - public float TopMargin - { - get { return _TopMargin; } - set { _TopMargin = value; } - } - private float _RightMargin = 0; - public float RightMargin - { - get { return _RightMargin; } - set { _RightMargin = value; } - } - private float _BottomMargin = 0; - public float BottomMargin - { - get { return _BottomMargin; } - set { _BottomMargin = value; } - } - public Page(bool portrait, float leftMargin, float topMargin, float rightMargin, float bottomMargin) - { - _Portrait = portrait; - _LeftMargin = leftMargin; - _TopMargin = topMargin; - _RightMargin = rightMargin; - _BottomMargin = bottomMargin; + Portrait = portrait; + LeftMargin = leftMargin; + TopMargin = topMargin; + RightMargin = rightMargin; + BottomMargin = bottomMargin; } public Page(bool portrait, float leftMargin, float topMargin) { - _Portrait = portrait; - _LeftMargin = leftMargin; - _TopMargin = topMargin; + Portrait = portrait; + LeftMargin = leftMargin; + TopMargin = topMargin; } } public class VG { - private static Brush _BlackBrush = Brushes.Black; - public static Brush BlackBrush - { - get { return _BlackBrush; } - set { _BlackBrush = value; } - } - private static Color _BlackColor = Color.Black; + public static Brush BlackBrush { get; set; } = Brushes.Black; + private static Color _BlackColor = Color.Black; public static Color BlackColor { get { return _BlackColor; } - set { _BlackColor = value; _BlackBrush = new SolidBrush(value); } + set { _BlackColor = value; BlackBrush = new SolidBrush(value); } } // Values of vector graphics items are stored as twips (1440 twips in an inch) public int cx; @@ -105,16 +75,12 @@ namespace VG MoveAbsolute = ima; pg = ipg; } - public float ToPoints(float twip) - { - float r = ((float)twip) * 0.05f; - return r; - } - public void UpdatePageInfo(Page pa) + public float ToPoints(float twip) => (float)(((float)twip) * 0.05f); + public void UpdatePageInfo(Page pa) { pg.LeftMargin = pa.LeftMargin; - pg.Portrait = pa.Portrait; // RHM 20081003 - This had been pg.portrait=pg.portrait - pg.TopMargin = pa.TopMargin; // RHM 20081003 - This had been pg.VertOffset=pg.VertOffset + pg.Portrait = pa.Portrait; + pg.TopMargin = pa.TopMargin; } public string AddRTFBUI(string origStr, string bold, string underline, string italics) { @@ -145,7 +111,6 @@ namespace VG int B1 = (int)(colorFraction * color.B); int B2 = (int)((1 - colorFraction) * Color.White.B); pn = new Pen(Color.FromArgb(R1 + R2, G1 + G2, B1 + B2), scaleWid); - //pn = new Pen(color, wid*wid); } else pn = new Pen(color, scaleWid); @@ -217,74 +182,14 @@ namespace VG vgOutput.DrawRectangle(pn, rc); } } - public class VG_Image : VG - { - private int Scale; - private string FileName; - // Image is defined as starting point, scale factor (defaults to 1) & image file name - public VG_Image(int sx, int sy, int iscale, string fname) - { - cx = sx; - cy = sy; - Scale = 1; - FileName = fname; - } - public VG_Image(XmlElement svg, Page ipg) - { - cx = System.Convert.ToInt32(svg.GetAttribute("x")); - cy = System.Convert.ToInt32(svg.GetAttribute("y")); - Scale = 1; - if (svg.HasAttribute("scale")) Scale = System.Convert.ToInt32(svg.GetAttribute("scale")); - FileName = svg.GetAttribute("bname"); - pg = ipg; - } - public void Draw(IVGOutput vgOutput) - { - Pen pn = new Pen(VG.BlackBrush, lnwid); - Bitmap bm = new Bitmap(FileName); - RectangleF rc = new RectangleF(); - rc.Height = ToPoints((bm.Height * Scale) * 4.8f); - rc.Width = ToPoints((bm.Width * Scale) * 4.8f); - rc.X = ToPoints(pg.LeftMargin + cx); - rc.Y = ToPoints(pg.TopMargin + cy); - // TODO: grfx.DrawImage(bm, rc, ContentAlignment.MiddleCenter, ImageSizeModeEnum.Scale); - } - } - public class VG_Ellipse : VG - { - // Ellipse (circle) is defined by a bounding rectangle specified by a coordinate pair, a width, and a height - public VG_Ellipse(int sx, int sy, int ex, int ey, int w, Page ipg) - { - cx = sx; - cy = sy; - dx = ex; - dy = ey; - lnwid = w; - pg = ipg; - } - public VG_Ellipse(XmlElement svg, Page ipg) - { - cx = System.Convert.ToInt32(svg.GetAttribute("cx")); - cy = System.Convert.ToInt32(svg.GetAttribute("cy")); - dx = System.Convert.ToInt32(svg.GetAttribute("rx")); - dy = System.Convert.ToInt32(svg.GetAttribute("ry")); - lnwid = System.Convert.ToInt32(svg.GetAttribute("stroke-width")); - pg = ipg; - } - public void Draw(IVGOutput vgOutput) - { - Pen pn = new Pen(VG.BlackBrush, ToPoints(lnwid)); - vgOutput.DrawEllipse(pn, ToPoints(pg.LeftMargin + cx), ToPoints(pg.TopMargin + cy), ToPoints(dx), ToPoints(dy)); - } - } public class VG_Text : VG { - private string FontName; - private int FontSize; - private string Bold; - private string Underline; - private string Italics; - private string Text; + private readonly string FontName; + private readonly int FontSize; + private readonly string Bold; + private readonly string Underline; + private readonly string Italics; + private readonly string Text; // Text is defined by a starting location, attributes & the string public VG_Text(int sx, int sy, int fs, string txt, string fn, string ibold, string iunder, string iitalics, Page ipg) { @@ -297,48 +202,28 @@ namespace VG Underline = iunder; Italics = iitalics; pg = ipg; - // TODO: The following were in the 16-bit code - we may need to use these, wait and see - // strokeWidth = stroke; - // strokeWidthBold = strokebold; - // ULOffset = UnderlineOffset; - // ULWidth = UnderlineWidth; - } - public VG_Text(XmlElement svg, Page ipg) - { - cx = System.Convert.ToInt32(svg.GetAttribute("x")); - cy = System.Convert.ToInt32(svg.GetAttribute("y")); - FontSize = System.Convert.ToInt32(svg.GetAttribute("font-size")); - Bold = svg.GetAttribute("font-weight"); - Underline = svg.GetAttribute("text-decoration"); - Italics = svg.GetAttribute("font-style"); - FontName = svg.GetAttribute("font-family"); - Text = svg.InnerText; - pg = ipg; } public void Draw(IVGOutput vgOutput) { // TODO: Font myfont = new Font(FontName, (FontSize*9)/10); Font myfont = new Font(FontName, FontSize * vgOutput.FontSizeAdjust); // TODO: Trying 80% - RectangleF rc = new RectangleF(); - // the returned value from c1 grfx code is already in points, - // so need to convert the size. - rc.Size = vgOutput.MeasureString(Text, myfont); // TODO: 500 or pagewidth, or what - //rc.Size = grfx.MeasureString(Text, myfont, 500); // TODO: 500 or pagewidth, or what - rc.X = ToPoints(pg.LeftMargin + cx); - rc.Y = ToPoints(pg.TopMargin + cy) - FontSize; - rc.Height *= 1.0000001F; // Small factor to make text visible. - // add bold, underline & italics for entire object. - // TODO: string rtfout = AddRTFBUI(Text, Bold, Underline, Italics); - //using(Pen pn = new Pen(Color.DarkBlue, .1F)) - // grfx.DrawRectangle(pn, rc.X,rc.Y,rc.Width,rc.Height); + RectangleF rc = new RectangleF + { + // the returned value from c1 grfx code is already in points, + // so need to convert the size. + Size = vgOutput.MeasureString(Text, myfont), // TODO: 500 or pagewidth, or what + //rc.Size = grfx.MeasureString(Text, myfont, 500); // TODO: 500 or pagewidth, or what + X = ToPoints(pg.LeftMargin + cx), + Y = ToPoints(pg.TopMargin + cy) - FontSize + }; + rc.Height *= 1.0000001F; // Small factor to make text visible. vgOutput.DrawString(Text, myfont, VG.BlackBrush, rc); - //grfx.DrawString(Text, myfont, VG.BlackBrush, rc); } } public class VG_Arc : VG { - public Single sweepAngle; - public Single startAngle; + public float sweepAngle; + public float startAngle; public float stX, stY; public float rWid, rHgt; // Arc is defined by a bounding rectangle specified by a coordinate pair, a width, and a height @@ -365,9 +250,7 @@ namespace VG rHgt = -hight; } startAngle = stAngle; - // startAngle = 90; sweepAngle = swpAngle; - // sweepAngle = -45; lnwid = w; pg = ipg; } @@ -391,18 +274,6 @@ namespace VG float starty = pg.Portrait ? (stY + pg.TopMargin) : (pg.LeftMargin - stX); RectangleF rc = new RectangleF(ToPoints(startx), ToPoints(starty), ToPoints(rWid), ToPoints(rHgt)); //Console.WriteLine("{0},'{1}',{2},{3},{4},{5},{6},{7}", iColor, pn.Color, rc.X, rc.Y, rc.Width, rc.Height, startAngle, sweepAngle); - //if (iColor == 7 || iColor == 8) return; - //if (iColor == 6) return; - //if (iColor == 4 || iColor == 6) - //{ - // using (Pen lightPen = new Pen(myColors[iColor % myColors.Length], .01F)) - //{ - // vgOutput.DrawEllipse(lightPen, rc.X, rc.Y, rc.Width, rc.Height); - // float xc = rc.X + (rc.Width / 2); - // float yc = rc.Y + (rc.Height / 2); - // vgOutput.DrawEllipse(lightPen, xc - .5F, yc - .5F, 1F, 1F); - //} - //} if (sweepAngle > 0) vgOutput.DrawArc(pn, rc, startAngle, sweepAngle); else diff --git a/PROMS/Volian.Controls.Library/DisplaySearch.cs b/PROMS/Volian.Controls.Library/DisplaySearch.cs index f30c8bb2..3694f618 100644 --- a/PROMS/Volian.Controls.Library/DisplaySearch.cs +++ b/PROMS/Volian.Controls.Library/DisplaySearch.cs @@ -15,7 +15,6 @@ using System.Linq; namespace Volian.Controls.Library { -#pragma warning disable IDE1006 // Naming Styles #pragma warning disable IDE0044 // Add readonly modifier public partial class DisplaySearch : UserControl { @@ -339,14 +338,14 @@ namespace Volian.Controls.Library { if (cmboTreeROs.SelectedNode.Tag is ROFSTLookup.rodbi db) { - return $"{_MyRODbID.ToString()}:{string.Format("{0}", db.dbiID.ToString("X4"))}"; + return $"{_MyRODbID}:{string.Format("{0}", db.dbiID.ToString("X4"))}"; } else if (cmboTreeROs.SelectedNode.Tag is ROFSTLookup.rochild roch) { ROFSTLookup.rochild[] chld = roch.children; // build a list of ROs to search // B2022-118: remove the ending comma otherwise query will fail - string strRtnStr = $"{_MyRODbID.ToString()}:{GetROsToSearch(chld)}"; + string strRtnStr = $"{_MyRODbID}:{GetROsToSearch(chld)}"; if (strRtnStr.EndsWith(",")) strRtnStr = strRtnStr.Substring(0, strRtnStr.Length - 1); return strRtnStr; @@ -1008,7 +1007,7 @@ namespace Volian.Controls.Library { Text = string.Format("{0}", (char)sym.Unicode), // to name button use unicode rather than desc, desc may have spaces or odd chars - Name = $"btnCM{sym.Unicode.ToString()}", + Name = $"btnCM{sym.Unicode}", Tooltip = sym.Desc, Tag = string.Format(@"{0}", sym.Unicode), FontBold = true @@ -2379,6 +2378,7 @@ namespace Volian.Controls.Library } // if the selected folder has a docversion, handle it: +#pragma warning disable CS0252 // Possible unintended reference comparison; left hand side needs cast -- this is by design if (n.Tag != SelectAllProcedureSetsText) { FolderInfo fi = (FolderInfo)n.Tag; @@ -2391,8 +2391,9 @@ namespace Volian.Controls.Library StartAdvTreeStepTypesFillIn();// B2016-258 Hang after selecting a procedure if the Step Type panel is open on the search panel } } +#pragma warning restore CS0252 // Possible unintended reference comparison; left hand side needs cast - SetupContextMenu(); + SetupContextMenu(); buildSetToSearchPanelTitle(); //C2025-005 Find Step Elements @@ -3627,7 +3628,6 @@ namespace Volian.Controls.Library } } } -#pragma warning restore IDE1006 // Naming Styles #pragma warning restore IDE0044 // Add readonly modifier #endregion