diff --git a/PROMS/VEPROMS User Interface/frmVEPROMS.cs b/PROMS/VEPROMS User Interface/frmVEPROMS.cs index a9fb5e1f..b29834b0 100644 --- a/PROMS/VEPROMS User Interface/frmVEPROMS.cs +++ b/PROMS/VEPROMS User Interface/frmVEPROMS.cs @@ -9,6 +9,7 @@ using System.Text; using System.Windows.Forms; using System.IO; using System.Configuration; +using System.Reflection; using VEPROMS.CSLA.Library; //using Csla; using DevComponents; @@ -397,6 +398,27 @@ namespace VEPROMS _MyLog.InfoFormat("\r\nSession Beginning\r\n<===={0}[SQL:{1:yyMM.ddHH}]====== User: {2}/{3} Started {4} ===============>{5}" , Application.ProductVersion, Database.RevDate, Environment.UserDomainName, Environment.UserName, DateTime.Now.ToString("dddd MMMM d, yyyy h:mm:ss tt"), FormatInfo.Failed ?? ""); + // C2022-030 Notify the user if the stored procedure in the database are not update to date + // with those in the PROMSFixes.sql delivered with the PROMS executable + string pfVersion = ExeInfo.GetAssocicatedPROMSFixesVersion(); + string dbpfVersion = string.Format("{0:yyMM.ddHH}", Database.RevDate); + // if pfVersion is null, that means there was a problem finding or reading the PROMSFixes.SQL file in the executable folder + if (pfVersion != null && !pfVersion.Equals(dbpfVersion)) + { + _MyLog.WarnFormat("PROMSFixes Version - in Data Version is {0} PROMS is Expecting Version {1}", dbpfVersion, pfVersion); + StringBuilder sbMsg = new StringBuilder(); + //sbMsg.Append("The SQL Stored Procedures in the Database are a different version than what PROMS is expecting."); + sbMsg.Append("The SQL Stored Procedures version in the database is different than what PROMS is expecting."); + sbMsg.Append("\nPROMS may not run properly until the lastest SQL Stored Procedures are installed."); + sbMsg.AppendFormat("\n\n The database has SQL Stored Procedures version: {0}", dbpfVersion); + sbMsg.AppendFormat("\n PROMS is expecting SQL Stored Procedures version: {0}", pfVersion); + sbMsg.Append("\n\nPlease have your DBA update the database with the PROMSFixes.sql script file that was\ndelivered with this PROMS executable."); + sbMsg.Append("\n\nThe PROMSFixes.sql file is included with the PROMS installation download."); + sbMsg.Append("\n\nIt can also be found in your PROMS executable folder:"); + sbMsg.AppendFormat("\n\t{0}",ExeInfo.PROMSExecutableFolderPath()); + FlexibleMessageBox.Show(sbMsg.ToString(),"SQL Stored Procedures Version Difference"); + } + foreach (string parameter in parameters) { if (parameter.ToUpper().StartsWith("/UF=")) diff --git a/PROMS/Volian.Base.Library/ExeInfo.cs b/PROMS/Volian.Base.Library/ExeInfo.cs index f9170282..5d0e6eeb 100644 --- a/PROMS/Volian.Base.Library/ExeInfo.cs +++ b/PROMS/Volian.Base.Library/ExeInfo.cs @@ -1,23 +1,66 @@ using System; using System.Collections.Generic; using System.Text; +using System.IO; +using System.Linq; namespace Volian.Base.Library { public static class ExeInfo { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion public static string GetROEditorPath() { - //string roapp = Environment.GetEnvironmentVariable("roapp"); - // Get the current location of the PROMS executable and build a path to the RO Editor executable. - // the system call below return a path string with "file:\\" preceeding it. - string roapp = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); - if (roapp[7] == ':') // either a local drive or a mapped network drive - roapp = roapp.Substring(6); - else - roapp = @"\" + roapp.Substring(5); // non-mapped network drive - need to add extra back slash in front - roapp = roapp + @"\ROEDITOR.EXE"; + string roapp = PROMSExecutableFolderPath() + @"\ROEDITOR.EXE"; return roapp; } + + // returns the path to the executable folder + public static string PROMSExecutableFolderPath() + { + string pathPROMSexe = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); + if (pathPROMSexe[7] == ':') // either a local drive or a mapped network drive + pathPROMSexe = pathPROMSexe.Substring(6); + else + pathPROMSexe = @"\" + pathPROMSexe.Substring(5); // non-mapped network drive - need to add extra back slash in front + return pathPROMSexe; + } + + // C2022-030 get the version of PROMSFixes associated with this execuable + public static string GetAssocicatedPROMSFixesVersion() + { + try + { + // Build the path to the PROMSFixes.sql file located in the PROMS exe folder + string pathPROMSFixes = PROMSExecutableFolderPath() + @"\PROMSFixes.sql"; + + // open the PROMSFixes.sql file and grab the line of text containing the PROMSFixes RevDate + // using Linq to open and read the PROMSFixes file + // it returns a list of lines. we look at only the first one (should only be one of these in PROMSFixes) + var lines = from text in File.ReadLines(pathPROMSFixes) + where text.Contains("set @RevDate =") + select new + { + Text = text + }; + var txt = lines.First(); // get the first line of text where "set @RevDate =" was found + string dtstring = txt.Text; // this is the actual text line + // Parse out the date/time text that follows "set @RevDate =" + int idx = dtstring.IndexOf('=') + 3; + dtstring = dtstring.Substring(idx); + dtstring = dtstring.Substring(0, dtstring.IndexOf("'")); + // convert the parsed date/time text string to a DateTime and string format it to yyMM.ddHH like used in Help About + string rtnStr = string.Format("{0:yyMM.ddHH}", DateTime.Parse(dtstring)); + return rtnStr; // return the PROMSFixes version date stored in the PROMSFixes.sql file that's in the PROMS exe folder + } + catch (Exception ex) + { + _MyLog.ErrorFormat("GetAssociatedPROMSFixesVersion - {0}", ex.Message); + return null; // return null to signal that we could not find or parse the PROMSFixes version date + } + } + } }