B2022-107: Added code to update the Loading Screen / Progress Display

This commit is contained in:
Jake 2022-09-08 19:49:28 +00:00
parent aaffa70671
commit ef3bd24392

View File

@ -6,10 +6,10 @@ using System.Text.RegularExpressions;
using System.Data; using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Linq; using System.Linq;
using System.Threading;
using Csla.Data; using Csla.Data;
using System.Threading;
using System.Threading.Tasks;
namespace VEPROMS.CSLA.Library namespace VEPROMS.CSLA.Library
{ {
@ -106,10 +106,10 @@ namespace VEPROMS.CSLA.Library
public int ID; public int ID;
public int ParentID; public int ParentID;
public int type; public int type;
public string title; // gets used for treeview public string title; // gets used for treeview
public string roid; // roid unique identifier public string roid; // roid unique identifier
public string appid; // accessory page id - user specified unique id public string appid; // accessory page id - user specified unique id
public string value; // return value, can be multiple values public string value; // return value, can be multiple values
public rochild[] children; public rochild[] children;
}; };
@ -143,9 +143,18 @@ namespace VEPROMS.CSLA.Library
private List<string> _lstRoValues; private List<string> _lstRoValues;
private List<string> _multiRoValues; private List<string> _multiRoValues;
private Dictionary<string, string> _dicRoVars; private Dictionary<string, string> _dicRoVars;
private ItemInfo _itemInfo; private ItemInfo _itemInfo;
// B2022-107: Display Progress Bar Messages/Statuses when a new ROFST binary file is loaded into the database
private frmRofstLoadStatus _frmRofstLoadStatus = null;
private Dictionary<int, int> _dicRoCounts = null;
private bool _showLoadingStatus = true;
private int _curRoCnt = 0;
private int _dbRoCnt = 0;
private int _totalRoCnt = 0;
private double _pctComplete = 0;
#endregion #endregion
#region Properties #region Properties
@ -187,14 +196,14 @@ namespace VEPROMS.CSLA.Library
public List<RoExtension> Extensions public List<RoExtension> Extensions
{ {
get get
{ {
if (_extensions == null) if (_extensions == null)
{ {
_extensions = RofstDataGetExtensions(); _extensions = RofstDataGetExtensions();
} }
return _extensions; return _extensions;
} }
} }
@ -217,26 +226,35 @@ namespace VEPROMS.CSLA.Library
set { _autoCombineSingleRetValues = value; } set { _autoCombineSingleRetValues = value; }
} }
public bool ShowLoadingStatus
{
get { return _showLoadingStatus; }
}
#endregion #endregion
#region Constructors #region Constructors
public ROFSTLookup(int rofstID, DocVersionInfo dvi, string otherChild) public ROFSTLookup(int rofstID, DocVersionInfo dvi, string otherChild, bool showLoadingStatus = true)
{ {
// Set Fields/Properties
_rofstID = rofstID; _rofstID = rofstID;
MyDocVersionInfo = dvi; MyDocVersionInfo = dvi;
_otherChild = otherChild; _otherChild = otherChild;
_showLoadingStatus = showLoadingStatus;
// Check if ROFST file is already loaded, if not then parse/load Ro Values
if (!RofstDataExists(rofstID)) if (!RofstDataExists(rofstID))
{ {
Load(rofstID); Load(rofstID);
} }
} }
public ROFSTLookup(int rofstID, DocVersionInfo dvi) public ROFSTLookup(int rofstID, DocVersionInfo dvi, bool showLoadingStatus = true)
{ {
_rofstID = rofstID; _rofstID = rofstID;
MyDocVersionInfo = dvi; MyDocVersionInfo = dvi;
_showLoadingStatus = showLoadingStatus;
if (!RofstDataExists(rofstID)) if (!RofstDataExists(rofstID))
{ {
@ -244,10 +262,11 @@ namespace VEPROMS.CSLA.Library
} }
} }
public ROFSTLookup(int rofstID) public ROFSTLookup(int rofstID, bool showLoadingStatus = true)
{ {
_rofstID = rofstID; _rofstID = rofstID;
MyDocVersionInfo = null; MyDocVersionInfo = null;
_showLoadingStatus = showLoadingStatus;
if (!RofstDataExists(rofstID)) if (!RofstDataExists(rofstID))
{ {
@ -609,6 +628,23 @@ namespace VEPROMS.CSLA.Library
return new ROFSTLookup.rochild() { ID = -1, type = 0 }; return new ROFSTLookup.rochild() { ID = -1, type = 0 };
} }
public static string CalculateDuration(DateTime dtStart)
{
string duration = string.Empty;
double totalSecs = TimeSpan.FromTicks(DateTime.Now.Ticks - dtStart.Ticks).TotalSeconds;
int minutes = (totalSecs > 60) ? Convert.ToInt32(totalSecs) / 60 : 0;
double secs = (minutes <= 0) ? totalSecs : (totalSecs - Convert.ToDouble(minutes * 60));
if (minutes > 0) duration = string.Format("{0} min(s) ", minutes.ToString("n0"));
if (secs < 0) secs = 0.00;
duration = duration + string.Format("{0,10:#####0.00} sec(s)", secs).Trim();
return duration;
//return string.Format("{0,10:#####0.00}", TimeSpan.FromTicks(DateTime.Now.Ticks - dtStart.Ticks).TotalSeconds);
}
#endregion #endregion
#endregion #endregion
@ -769,7 +805,7 @@ namespace VEPROMS.CSLA.Library
cmd.CommandText = "vesp_RofstHeaderFinalizeLoad"; cmd.CommandText = "vesp_RofstHeaderFinalizeLoad";
cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID;
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
} }
@ -830,7 +866,7 @@ namespace VEPROMS.CSLA.Library
cmd.Parameters.Add(new SqlParameter("@type", SqlDbType.Int)).Value = type; cmd.Parameters.Add(new SqlParameter("@type", SqlDbType.Int)).Value = type;
cmd.Parameters.Add(new SqlParameter("@title", SqlDbType.VarChar)).Value = title; cmd.Parameters.Add(new SqlParameter("@title", SqlDbType.VarChar)).Value = title;
cmd.Parameters.Add(new SqlParameter("@roid", SqlDbType.VarChar)).Value = roid; cmd.Parameters.Add(new SqlParameter("@roid", SqlDbType.VarChar)).Value = roid;
if (!string.IsNullOrEmpty(appid)) if (!string.IsNullOrEmpty(appid))
cmd.Parameters.Add(new SqlParameter("@appid", SqlDbType.VarChar)).Value = appid; cmd.Parameters.Add(new SqlParameter("@appid", SqlDbType.VarChar)).Value = appid;
if (!string.IsNullOrEmpty(value)) if (!string.IsNullOrEmpty(value))
@ -1133,7 +1169,7 @@ namespace VEPROMS.CSLA.Library
cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID;
cmd.Parameters.Add(new SqlParameter("@ValueTypes", SqlDbType.VarChar)).Value = valueTypes.ToCommaDelimString(); cmd.Parameters.Add(new SqlParameter("@ValueTypes", SqlDbType.VarChar)).Value = valueTypes.ToCommaDelimString();
using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader())) using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader()))
{ {
while (dr.Read()) while (dr.Read())
@ -1379,6 +1415,8 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < dbs; i++) for (int i = 0; i < dbs; i++)
{ {
_dbRoCnt = 0;
int offset = hdrOffset + 6 + (i * 30); int offset = hdrOffset + 6 + (i * 30);
roh.myDbs[i].dbiID = BitConverter.ToInt16(ab, offset + 0); roh.myDbs[i].dbiID = BitConverter.ToInt16(ab, offset + 0);
@ -1397,6 +1435,8 @@ namespace VEPROMS.CSLA.Library
roh.myDbs[i].ID = tmp.ID; roh.myDbs[i].ID = tmp.ID;
roh.myDbs[i].children = tmp.children; roh.myDbs[i].children = tmp.children;
_dicRoCounts.Add(tableID, _dbRoCnt);
} }
return roh; return roh;
@ -1431,8 +1471,6 @@ namespace VEPROMS.CSLA.Library
ROFSTLookup.rogrp tmpg = LoadGroup(ab, childOffset, tableID); ROFSTLookup.rogrp tmpg = LoadGroup(ab, childOffset, tableID);
//MultipleReturnValuesInheritType(ref tmpg, tmp.type);
tmp.ID = tmpg.ID; tmp.ID = tmpg.ID;
tmp.ParentID = tmpg.ParentID; tmp.ParentID = tmpg.ParentID;
tmp.value = tmpg.value; tmp.value = tmpg.value;
@ -1455,10 +1493,10 @@ namespace VEPROMS.CSLA.Library
int slen = StringLength(ab, offset + 12); int slen = StringLength(ab, offset + 12);
myGrp.value = Encoding.Default.GetString(ab, offset + 12, slen); myGrp.value = Encoding.Default.GetString(ab, offset + 12, slen);
//ProcessROReturnValue(ref myGrp, Encoding.Default.GetString(ab, offset + 12, slen), tableID, dvi);
int slen2 = StringLength(ab, offset + 13 + slen); int slen2 = StringLength(ab, offset + 13 + slen);
myGrp.appid = Encoding.Default.GetString(ab, offset + 13 + slen, slen2); myGrp.appid = Encoding.Default.GetString(ab, offset + 13 + slen, slen2);
_dbRoCnt++;
} }
return myGrp; return myGrp;
@ -1466,40 +1504,101 @@ namespace VEPROMS.CSLA.Library
private void Load(int rofstID) private void Load(int rofstID)
{ {
//Get Original ROLookup Bytes _dicRoCounts = new Dictionary<int, int>();
byte[] bytes = RofstDataGetRofstLookupBytes(rofstID);
//Convert Bytes to Objects DateTime dtStart = DateTime.Now;
ROFSTLookup.roHdr roh = ConvertFst2Objects(bytes); string title = string.Empty;
string displayText = string.Empty;
//Save FstObjects to Database try
string userID = "System";
//Insert Rofst Header
RofstHeaderInsert(rofstID, roh.hSize, roh.hMonth, roh.hDay, roh.hcYear, roh.hcMonth,
roh.hcDay, roh.hcHour, roh.hcMin, roh.hcSec, roh.hcHund, userID);
for (int i = 0; i < roh.myDbs.Length; i++)
{ {
ROFSTLookup.rodbi rodbi = roh.myDbs[i]; if (ShowLoadingStatus)
//Insert Rofst Database
RofstDatabaseInsert(rofstID, rodbi.dbiID, rodbi.dbiType, rodbi.dbiAW,
rodbi.dbiTitle, rodbi.dbiAP, rodbi.ID, rodbi.ParentID);
if (rodbi.children != null && rodbi.children.Length > 0)
{ {
for (int j = 0; j < rodbi.children.Length; j++) _frmRofstLoadStatus = new frmRofstLoadStatus();
_frmRofstLoadStatus.Show();
_frmRofstLoadStatus.Focus();
}
//Get Original ROLookup Bytes
OnProgressChanged("Importing ROFST File...", null, 1, 100);
byte[] bytes = RofstDataGetRofstLookupBytes(rofstID);
//Convert Bytes to Objects
OnProgressChanged("Converting RO Values to Objects...", null, 5, 100);
ROFSTLookup.roHdr roh = ConvertFst2Objects(bytes);
//Save FstObjects to Database
string userID = "System";
//Insert Rofst Header
OnProgressChanged("Creating Rofst Header...", null, 10, 100);
RofstHeaderInsert(rofstID, roh.hSize, roh.hMonth, roh.hDay, roh.hcYear, roh.hcMonth,
roh.hcDay, roh.hcHour, roh.hcMin, roh.hcSec, roh.hcHund, userID);
_pctComplete = 10.0;
_totalRoCnt = Convert.ToInt32(_dicRoCounts.Sum(x => x.Value));
for (int i = 0; i < roh.myDbs.Length; i++)
{
ROFSTLookup.rodbi rodbi = roh.myDbs[i];
_dbRoCnt = (_dicRoCounts.Where(x => x.Key == rodbi.dbiID).Any()) ? Convert.ToInt32(_dicRoCounts.Where(x => x.Key == rodbi.dbiID).FirstOrDefault().Value) : 0;
_curRoCnt = 0;
title = string.Format("Loading '{0}' Database... ({1} of {2})", rodbi.dbiTitle, i + 1, roh.myDbs.Length);
displayText = string.Format("Processing RO Value... ({0} of {1})", 1, _dbRoCnt.ToString("n0"));
//Insert Rofst Database
OnProgressChanged(title, displayText, Convert.ToInt32(_pctComplete), 100);
RofstDatabaseInsert(rofstID, rodbi.dbiID, rodbi.dbiType, rodbi.dbiAW, rodbi.dbiTitle, rodbi.dbiAP, rodbi.ID, rodbi.ParentID);
if (rodbi.children != null && rodbi.children.Length > 0)
{ {
//Insert Rofst Child for (int j = 0; j < rodbi.children.Length; j++)
LoadChild(rofstID, rodbi.dbiID, rodbi.children[j]); {
//Insert Rofst Child
LoadChild(rofstID, rodbi.dbiID, rodbi.children[j]);
displayText = string.Format("Processing RO Values... ({0} of {1})", _curRoCnt.ToString("n0"), _dbRoCnt.ToString("n0"));
OnProgressChanged(displayText, Convert.ToInt32(_pctComplete), 100);
}
}
// Update Progress Bar Accordingly
if (_totalRoCnt > 0) _pctComplete = _pctComplete + ((Convert.ToDouble(_dbRoCnt) / Convert.ToDouble(_totalRoCnt)) * 80.0);
OnProgressChanged(displayText, Convert.ToInt32(_pctComplete), 100);
}
//Finalized Load for Rofst Header / Rebuild Indexes
OnProgressChanged("Finalizing Rofst Header and Rebuilding Indexes...", null, 90, 100);
RofstHeaderFinalizeLoad(rofstID);
title = string.Format("Successfully Loaded ({0}) RO Values... Total Duration {1}", _totalRoCnt.ToString("n0"), CalculateDuration(dtStart));
OnProgressChanged(title, null, 100, 100);
}
catch (Exception ex)
{
OnProgressChanged("Error Imported RO Values...", ex.Message, 100, 100);
}
finally
{
try
{
if (_frmRofstLoadStatus != null)
{
_frmRofstLoadStatus.Close();
_frmRofstLoadStatus.Dispose();
_frmRofstLoadStatus = null;
}
if (_dicRoCounts != null || _dicRoCounts.Count > 0)
{
_dicRoCounts = null;
} }
} }
catch { }
} }
//Finalized Load for Rofst Header / Rebuild Indexes
RofstHeaderFinalizeLoad(rofstID);
} }
private void LoadChild(int rofstID, int dbiID, ROFSTLookup.rochild child) private void LoadChild(int rofstID, int dbiID, ROFSTLookup.rochild child)
@ -1507,6 +1606,9 @@ namespace VEPROMS.CSLA.Library
//Insert Rofst Child //Insert Rofst Child
RofstChildInsert(rofstID, child.ID, child.ParentID, dbiID, child.type, child.title, child.roid, child.appid, child.value); RofstChildInsert(rofstID, child.ID, child.ParentID, dbiID, child.type, child.title, child.roid, child.appid, child.value);
//Increment RO Count if RoChild has a return value
if (!string.IsNullOrEmpty(child.value)) _curRoCnt++;
if (child.children != null && child.children.Length > 0) if (child.children != null && child.children.Length > 0)
{ {
for (int i = 0; i < child.children.Length; i++) for (int i = 0; i < child.children.Length; i++)
@ -1517,6 +1619,24 @@ namespace VEPROMS.CSLA.Library
} }
} }
#region (Parse/Load - Events/Handlers)
protected virtual void OnProgressChanged(string title, string displayText, int curVal = 0, int maxVal = 100)
{
// If frmRofstLoadStatus is not null then call Update Progress Method
if (_frmRofstLoadStatus != null)
_frmRofstLoadStatus.UpdateProgress(title, displayText, curVal, maxVal);
}
protected virtual void OnProgressChanged(string displayText, int curVal = 0, int maxVal = 100)
{
// If frmRofstLoadStatus is not null then call Update Progress Method
if (_frmRofstLoadStatus != null)
_frmRofstLoadStatus.UpdateProgress(_frmRofstLoadStatus.Title, displayText, curVal, maxVal);
}
#endregion
#endregion #endregion
#region (Convert To Objects) #region (Convert To Objects)
@ -1600,7 +1720,7 @@ namespace VEPROMS.CSLA.Library
re.Offset = (int)dr.GetValue("Offset"); re.Offset = (int)dr.GetValue("Offset");
re.RoidExt = (string)dr.GetValue("RoidExt"); re.RoidExt = (string)dr.GetValue("RoidExt");
re.AccPageExt = (string)dr.GetValue("AccPageExt"); re.AccPageExt = (string)dr.GetValue("AccPageExt");
return re; return re;
} }
@ -1665,7 +1785,7 @@ namespace VEPROMS.CSLA.Library
child.value = null; child.value = null;
} }
} }
_lstRoValues.Clear(); _lstRoValues.Clear();
_multiRoValues.Clear(); _multiRoValues.Clear();
@ -1678,7 +1798,7 @@ namespace VEPROMS.CSLA.Library
// C2022-001 new logic to handle new format of Parent/Child RO.FST // C2022-001 new logic to handle new format of Parent/Child RO.FST
// The RO.FST will not have a specific child value if that child value is the same as the default value // The RO.FST will not have a specific child value if that child value is the same as the default value
// B2021-093 Don't look for child RO values if "roval" is null // B2021-093 Don't look for child RO values if "roval" is null
if (string.IsNullOrEmpty(roval)) if (string.IsNullOrEmpty(roval))
return null; return null;
// Clean Up RoValue // Clean Up RoValue
@ -1740,7 +1860,7 @@ namespace VEPROMS.CSLA.Library
_dicRoVars = new Dictionary<string, string>(); _dicRoVars = new Dictionary<string, string>();
string tmp = ProcessRO(_myDocVersionInfo == null ? roval : _myDocVersionInfo.ProcessDocVersionSpecificInfo(roval), false); string tmp = ProcessRO(_myDocVersionInfo == null ? roval : _myDocVersionInfo.ProcessDocVersionSpecificInfo(roval), false);
if (!string.IsNullOrEmpty(tmp) && _lstRoValues.Count == 0) // was not a multiple return value if (!string.IsNullOrEmpty(tmp) && _lstRoValues.Count == 0) // was not a multiple return value
{ {
_lstRoValues.Add(tmp); _lstRoValues.Add(tmp);
@ -1782,7 +1902,7 @@ namespace VEPROMS.CSLA.Library
bool nfnd = false; bool nfnd = false;
string pbstr = ProcessBrace(str.Substring(1, cnt - 2), cnt - 2, ref nfnd, multiRtnVal); string pbstr = ProcessBrace(str.Substring(1, cnt - 2), cnt - 2, ref nfnd, multiRtnVal);
if (pbstr == null) if (pbstr == null)
return null; return null;
if (nfnd) if (nfnd)
@ -1916,7 +2036,7 @@ namespace VEPROMS.CSLA.Library
return str; return str;
string rtnstr = str; string rtnstr = str;
int indx; int indx;
while ((indx = rtnstr.ToUpper().IndexOf("@HSP(")) > -1) while ((indx = rtnstr.ToUpper().IndexOf("@HSP(")) > -1)
{ {
@ -2045,7 +2165,7 @@ namespace VEPROMS.CSLA.Library
DocVersionConfig dvc = (_myDocVersionInfo != null) ? _myDocVersionInfo.DocVersionConfig : null; DocVersionConfig dvc = (_myDocVersionInfo != null) ? _myDocVersionInfo.DocVersionConfig : null;
if (dvc != null) dvc.SelectedSlave = this.SelectedSlave; if (dvc != null) dvc.SelectedSlave = this.SelectedSlave;
switch (rc.roid) switch (rc.roid)
{ {
case "FFFF00000001": case "FFFF00000001":