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.SqlClient;
using System.Linq;
using System.Threading;
using Csla.Data;
using System.Threading;
using System.Threading.Tasks;
namespace VEPROMS.CSLA.Library
{
@ -106,10 +106,10 @@ namespace VEPROMS.CSLA.Library
public int ID;
public int ParentID;
public int type;
public string title; // gets used for treeview
public string roid; // roid unique identifier
public string appid; // accessory page id - user specified unique id
public string value; // return value, can be multiple values
public string title; // gets used for treeview
public string roid; // roid unique identifier
public string appid; // accessory page id - user specified unique id
public string value; // return value, can be multiple values
public rochild[] children;
};
@ -143,9 +143,18 @@ namespace VEPROMS.CSLA.Library
private List<string> _lstRoValues;
private List<string> _multiRoValues;
private Dictionary<string, string> _dicRoVars;
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
#region Properties
@ -217,26 +226,35 @@ namespace VEPROMS.CSLA.Library
set { _autoCombineSingleRetValues = value; }
}
public bool ShowLoadingStatus
{
get { return _showLoadingStatus; }
}
#endregion
#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;
MyDocVersionInfo = dvi;
_otherChild = otherChild;
_showLoadingStatus = showLoadingStatus;
// Check if ROFST file is already loaded, if not then parse/load Ro Values
if (!RofstDataExists(rofstID))
{
Load(rofstID);
}
}
public ROFSTLookup(int rofstID, DocVersionInfo dvi)
public ROFSTLookup(int rofstID, DocVersionInfo dvi, bool showLoadingStatus = true)
{
_rofstID = rofstID;
MyDocVersionInfo = dvi;
_showLoadingStatus = showLoadingStatus;
if (!RofstDataExists(rofstID))
{
@ -244,10 +262,11 @@ namespace VEPROMS.CSLA.Library
}
}
public ROFSTLookup(int rofstID)
public ROFSTLookup(int rofstID, bool showLoadingStatus = true)
{
_rofstID = rofstID;
MyDocVersionInfo = null;
_showLoadingStatus = showLoadingStatus;
if (!RofstDataExists(rofstID))
{
@ -609,6 +628,23 @@ namespace VEPROMS.CSLA.Library
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
@ -1379,6 +1415,8 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < dbs; i++)
{
_dbRoCnt = 0;
int offset = hdrOffset + 6 + (i * 30);
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].children = tmp.children;
_dicRoCounts.Add(tableID, _dbRoCnt);
}
return roh;
@ -1431,8 +1471,6 @@ namespace VEPROMS.CSLA.Library
ROFSTLookup.rogrp tmpg = LoadGroup(ab, childOffset, tableID);
//MultipleReturnValuesInheritType(ref tmpg, tmp.type);
tmp.ID = tmpg.ID;
tmp.ParentID = tmpg.ParentID;
tmp.value = tmpg.value;
@ -1455,10 +1493,10 @@ namespace VEPROMS.CSLA.Library
int slen = StringLength(ab, offset + 12);
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);
myGrp.appid = Encoding.Default.GetString(ab, offset + 13 + slen, slen2);
_dbRoCnt++;
}
return myGrp;
@ -1466,40 +1504,101 @@ namespace VEPROMS.CSLA.Library
private void Load(int rofstID)
{
//Get Original ROLookup Bytes
byte[] bytes = RofstDataGetRofstLookupBytes(rofstID);
_dicRoCounts = new Dictionary<int, int>();
//Convert Bytes to Objects
ROFSTLookup.roHdr roh = ConvertFst2Objects(bytes);
DateTime dtStart = DateTime.Now;
string title = string.Empty;
string displayText = string.Empty;
//Save FstObjects to Database
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++)
try
{
ROFSTLookup.rodbi rodbi = roh.myDbs[i];
//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)
if (ShowLoadingStatus)
{
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
LoadChild(rofstID, rodbi.dbiID, rodbi.children[j]);
for (int j = 0; j < rodbi.children.Length; 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)
@ -1507,6 +1606,9 @@ namespace VEPROMS.CSLA.Library
//Insert Rofst Child
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)
{
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
#region (Convert To Objects)