B2022-107: Added code to update the Loading Screen / Progress Display
This commit is contained in:
parent
aaffa70671
commit
ef3bd24392
@ -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
|
||||||
{
|
{
|
||||||
@ -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
|
||||||
@ -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
|
||||||
@ -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,26 +1504,53 @@ namespace VEPROMS.CSLA.Library
|
|||||||
|
|
||||||
private void Load(int rofstID)
|
private void Load(int rofstID)
|
||||||
{
|
{
|
||||||
|
_dicRoCounts = new Dictionary<int, int>();
|
||||||
|
|
||||||
|
DateTime dtStart = DateTime.Now;
|
||||||
|
string title = string.Empty;
|
||||||
|
string displayText = string.Empty;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (ShowLoadingStatus)
|
||||||
|
{
|
||||||
|
_frmRofstLoadStatus = new frmRofstLoadStatus();
|
||||||
|
_frmRofstLoadStatus.Show();
|
||||||
|
_frmRofstLoadStatus.Focus();
|
||||||
|
}
|
||||||
|
|
||||||
//Get Original ROLookup Bytes
|
//Get Original ROLookup Bytes
|
||||||
|
OnProgressChanged("Importing ROFST File...", null, 1, 100);
|
||||||
byte[] bytes = RofstDataGetRofstLookupBytes(rofstID);
|
byte[] bytes = RofstDataGetRofstLookupBytes(rofstID);
|
||||||
|
|
||||||
//Convert Bytes to Objects
|
//Convert Bytes to Objects
|
||||||
|
OnProgressChanged("Converting RO Values to Objects...", null, 5, 100);
|
||||||
ROFSTLookup.roHdr roh = ConvertFst2Objects(bytes);
|
ROFSTLookup.roHdr roh = ConvertFst2Objects(bytes);
|
||||||
|
|
||||||
//Save FstObjects to Database
|
//Save FstObjects to Database
|
||||||
string userID = "System";
|
string userID = "System";
|
||||||
|
|
||||||
//Insert Rofst Header
|
//Insert Rofst Header
|
||||||
|
OnProgressChanged("Creating Rofst Header...", null, 10, 100);
|
||||||
RofstHeaderInsert(rofstID, roh.hSize, roh.hMonth, roh.hDay, roh.hcYear, roh.hcMonth,
|
RofstHeaderInsert(rofstID, roh.hSize, roh.hMonth, roh.hDay, roh.hcYear, roh.hcMonth,
|
||||||
roh.hcDay, roh.hcHour, roh.hcMin, roh.hcSec, roh.hcHund, userID);
|
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++)
|
for (int i = 0; i < roh.myDbs.Length; i++)
|
||||||
{
|
{
|
||||||
ROFSTLookup.rodbi rodbi = roh.myDbs[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
|
//Insert Rofst Database
|
||||||
RofstDatabaseInsert(rofstID, rodbi.dbiID, rodbi.dbiType, rodbi.dbiAW,
|
OnProgressChanged(title, displayText, Convert.ToInt32(_pctComplete), 100);
|
||||||
rodbi.dbiTitle, rodbi.dbiAP, rodbi.ID, rodbi.ParentID);
|
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 (rodbi.children != null && rodbi.children.Length > 0)
|
||||||
{
|
{
|
||||||
@ -1493,13 +1558,47 @@ namespace VEPROMS.CSLA.Library
|
|||||||
{
|
{
|
||||||
//Insert Rofst Child
|
//Insert Rofst Child
|
||||||
LoadChild(rofstID, rodbi.dbiID, rodbi.children[j]);
|
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
|
//Finalized Load for Rofst Header / Rebuild Indexes
|
||||||
|
OnProgressChanged("Finalizing Rofst Header and Rebuilding Indexes...", null, 90, 100);
|
||||||
RofstHeaderFinalizeLoad(rofstID);
|
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 { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user