302 lines
9.6 KiB
C#
302 lines
9.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using VEPROMS.CSLA.Library;
|
|
|
|
namespace TestFullLoad
|
|
{
|
|
public partial class frmLoadAtOnce : Form
|
|
{
|
|
public frmLoadAtOnce()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
private ItemInfoList _Procedures;
|
|
private bool _IsMultiUnit = false;
|
|
private void frmLoadAtOnce_Load(object sender, EventArgs e)
|
|
{
|
|
LoadSettings();
|
|
// Set these events after loading settings - otherwise the settings will be updated to the defaults
|
|
Move+=new EventHandler(frmLoadAtOnce_Move);
|
|
Resize+=new EventHandler(frmLoadAtOnce_Resize);
|
|
try
|
|
{
|
|
DocVersionInfo docVersion = GetDocVersionWithContent();
|
|
if (docVersion.MultiUnitCount > 1)
|
|
{
|
|
foreach (string s in docVersion.UnitNames)
|
|
cbUnits.Items.Add(s.Trim());
|
|
cbUnits.SelectedIndex = 0;
|
|
cbUnits.Enabled = true;
|
|
_IsMultiUnit = true;
|
|
}
|
|
_Procedures = docVersion.Procedures;
|
|
lbProcedures.DataSource = _Procedures;
|
|
lbProcedures.SelectedIndex = -1;
|
|
lbProcedures.SelectedValueChanged+=new EventHandler(lbProcedures_SelectedValueChanged);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("ex - {0}", ex);
|
|
}
|
|
}
|
|
private void LoadSettings()
|
|
{
|
|
if (GetPropertyString("Location") != "")
|
|
this.Location = Properties.Settings.Default.Location;
|
|
if ((Properties.Settings.Default["Size"] ?? "") != "")
|
|
this.Size = Properties.Settings.Default.Size;
|
|
this.WindowState = Properties.Settings.Default.WindowState;
|
|
Database.ConnectionName = "VEPROMS_BODINE_DEBUG";
|
|
if (Properties.Settings.Default.LastDatabase != string.Empty)
|
|
{
|
|
if (MessageBox.Show(string.Format("use database {0}?", Properties.Settings.Default.LastDatabase), "use database", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
Database.SelectedDatabase = Properties.Settings.Default.LastDatabase;
|
|
}
|
|
Properties.Settings.Default.LastDatabase = Database.SelectedDatabase;
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
private string GetPropertyString(string propertyName)
|
|
{
|
|
object prop = Properties.Settings.Default[propertyName];
|
|
return prop == null ? "" : prop.ToString();
|
|
}
|
|
private DocVersionInfo GetDocVersionWithContent()
|
|
{
|
|
DocVersionInfoList dvList = DocVersionInfoList.Get();
|
|
foreach (DocVersionInfo docVersion in dvList)
|
|
if (docVersion.Procedures != null)
|
|
if (docVersion.Procedures[0].ItemID != 0)
|
|
return docVersion;
|
|
return null;
|
|
}
|
|
private int WalkThroughChildren(ItemInfo itemInfo)
|
|
{
|
|
Console.WriteLine(itemInfo.ItemID);
|
|
if (itemInfo.ItemID == 284)
|
|
Console.WriteLine("stop or spot");
|
|
int retval = 0;
|
|
// Look at siblings and look at children
|
|
if (itemInfo != null)
|
|
{
|
|
if (itemInfo.MyContent.ContentPartCount > 0)
|
|
{
|
|
foreach (PartInfo pi in itemInfo.MyContent.ContentParts)
|
|
{
|
|
foreach (ItemInfo ii in pi.MyItems)
|
|
{
|
|
//retval += WalkThroughSiblings(ii);
|
|
retval++;
|
|
retval += WalkThroughChildren(ii);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return retval;
|
|
}
|
|
private string ChildList(ItemInfo itm, int level)
|
|
{
|
|
StringBuilder retval = new StringBuilder();
|
|
// Look at siblings and look at children
|
|
//if (itm.MyContent.ContentPartCount > 0 && itm.ItemID != 4078 && itm.ItemID != 4192 && itm.ItemID != 4194 &&
|
|
// itm.ItemID != 4330 && itm.ItemID != 4452)
|
|
if (itm.MyContent.ContentPartCount > 0 )
|
|
{
|
|
//retval.Append(string.Format("\r\n{0}(", "".PadLeft(level, '\t')));
|
|
retval.Append(ShowItem(itm));
|
|
foreach (PartInfo pi in itm.MyContent.ContentParts)
|
|
{
|
|
retval.Append(string.Format("\r\n{0}({1} ", "".PadLeft(level + 1, '\t'), Enum.GetName(typeof(E_FromTypes), pi.FromType)));
|
|
foreach (ItemInfo ii in pi.MyItems)
|
|
{
|
|
//retval += WalkThroughSiblings(ii);
|
|
if (retval.ToString().EndsWith(")"))
|
|
retval.Append(string.Format("\r\n{0}", "".PadLeft(level + 2, '\t')));
|
|
retval.Append(ChildList(ii, level + 1));
|
|
}
|
|
retval.Append(string.Format(")", "".PadLeft(level, '\t')));
|
|
}
|
|
//retval.Append(string.Format("\r\n{0})", "".PadLeft(level, '\t')));
|
|
}
|
|
else
|
|
{
|
|
retval.Append(ShowItem(itm));
|
|
}
|
|
return retval.ToString();
|
|
}
|
|
private string ShowItem(ItemInfo itm)
|
|
{
|
|
return string.Format("{0}{1} ", itm.ItemID, ActiveSection(itm));
|
|
//return string.Format("{0}{1} ", itm.ItemID, ActiveParent(itm));
|
|
}
|
|
private string ActiveParent(ItemInfo itm)
|
|
{
|
|
if (itm == null || itm.MyActiveParent == null) return string.Empty;
|
|
return string.Format("({0})", itm.MyActiveParent);
|
|
}
|
|
private string ActiveSection(ItemInfo itm)
|
|
{
|
|
if (itm == null || itm.MyActiveSection == null) return "";
|
|
return string.Format("({0})", itm.MyActiveSection);
|
|
}
|
|
//private int WalkThroughSiblings(ItemInfo itemInfo)
|
|
//{
|
|
// int retval = 0;
|
|
// if (itemInfo.NextItemCount > 0)
|
|
// {
|
|
// foreach (ItemInfo itm in itemInfo.NextItems)
|
|
// {
|
|
// retval++;
|
|
// retval += WalkThroughChildren(itm);
|
|
// }
|
|
// }
|
|
// return retval;
|
|
//}
|
|
private void lbProcedures_SelectedValueChanged(object sender, EventArgs e)
|
|
{
|
|
ItemInfo itemInfo = lbProcedures.SelectedValue as ItemInfo;
|
|
if (itemInfo != null)
|
|
{
|
|
LoadEntireProcedure(itemInfo.ItemID);
|
|
pg.SelectedObject = MyItemInfo;
|
|
}
|
|
}
|
|
private ItemInfo _MyItemInfo;
|
|
public ItemInfo MyItemInfo
|
|
{
|
|
get { return _MyItemInfo; }
|
|
set { _MyItemInfo = value; }
|
|
}
|
|
private int LoadEntireProcedure(int itemID)
|
|
{
|
|
DateTime dtStart = DateTime.Now;// Record the start time
|
|
MyItemInfo = GetItem(itemID);// Load an item
|
|
DateTime dtLoad = DateTime.Now;// Record the time to this point
|
|
int cnt = WalkThroughChildren(MyItemInfo);// Scan the item counting it's nodes
|
|
DateTime dtEnd = DateTime.Now; // Record the end time
|
|
RecordResults(dtStart,dtLoad,dtEnd,cnt);// Place results on Status Line
|
|
//pg.SelectedObject = itemInfo; // Set the propertygrid to point to the loaded object
|
|
return cnt;
|
|
}
|
|
private ItemInfo GetItem(int itemID)
|
|
{
|
|
switch (cbType.Text as string)
|
|
{
|
|
case("One at a time")://
|
|
return ItemInfo.Get(itemID);
|
|
case ("CSLA - All at Once - Spin Through Children")://
|
|
return ItemInfo.GetItemAndChildren2(itemID);
|
|
case ("SQL - All at Once - Query")://
|
|
if (_IsMultiUnit)
|
|
return ProcedureInfo.GetItemAndChildrenByUnit(itemID, 0, cbUnits.SelectedIndex + 1);
|
|
else
|
|
return ItemInfo.GetItemAndChildren(itemID, 0);
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
private TimeSpan _TsLoad;
|
|
private TimeSpan _TsWalk;
|
|
private TimeSpan _TsTotal;
|
|
private int _Count;
|
|
private void ResetResults()
|
|
{
|
|
_TsLoad = _TsWalk = _TsTotal = new TimeSpan(0);
|
|
_Count = 0;
|
|
}
|
|
private void RecordResults(DateTime dtStart, DateTime dtLoad, DateTime dtEnd, int count)
|
|
{
|
|
TimeSpan tsLoad = dtLoad - dtStart;
|
|
TimeSpan tsWalk = dtEnd - dtLoad;
|
|
TimeSpan tsTotal = dtEnd - dtStart;
|
|
_TsLoad += tsLoad;
|
|
_TsWalk += tsWalk;
|
|
_TsTotal += tsTotal;
|
|
_Count += count;
|
|
tsslStatus.Text = string.Format("Load {0}, Check {1}, Total {2}, Items {3}",
|
|
tsLoad.TotalSeconds, tsWalk.TotalSeconds, tsTotal.TotalSeconds, count);
|
|
//Application.DoEvents();
|
|
//Console.WriteLine("{0}\t{1}\t{2}\t{3}", tsLoad.TotalSeconds,tsWalk.TotalSeconds,tsTotal.TotalSeconds, cnt);
|
|
}
|
|
private void DisplaySummary()
|
|
{
|
|
tsslStatus.Text = string.Format("Load {0}, Check {1}, Total {2}, Items {3}",
|
|
_TsLoad.TotalSeconds, _TsWalk.TotalSeconds, _TsTotal.TotalSeconds, _Count);
|
|
Console.WriteLine("{0},{1},{2},{3}",
|
|
_TsLoad.TotalSeconds, _TsWalk.TotalSeconds, _TsTotal.TotalSeconds, _Count);
|
|
}
|
|
private string _MyTitle;
|
|
public string MyTitle
|
|
{
|
|
get { return _MyTitle; }
|
|
set
|
|
{
|
|
if (_MyTitle == value) return;
|
|
_MyTitle = value;
|
|
Console.WriteLine(MyTitle);
|
|
}
|
|
}
|
|
|
|
private void btnRunAll_Click(object sender, EventArgs e)
|
|
{
|
|
Cursor tmp = this.Cursor;
|
|
this.Cursor = Cursors.WaitCursor;
|
|
//DateTime dtStart = DateTime.Now;
|
|
MyTitle = cbType.Text;
|
|
ResetResults();
|
|
int cnt = 0;
|
|
foreach(ItemInfo itemInfo in _Procedures)
|
|
cnt += LoadEntireProcedure(itemInfo.ItemID);
|
|
//DateTime dtEnd = DateTime.Now;
|
|
//tsslStatus.Text = string.Format("Total {0} Count {1}",
|
|
// TimeSpan.FromTicks(dtEnd.Ticks - dtStart.Ticks).TotalSeconds,cnt);
|
|
DisplaySummary();
|
|
this.Cursor = tmp;
|
|
}
|
|
private void btnRunOne_Click(object sender, EventArgs e)
|
|
{
|
|
// Run the Gets for
|
|
int itemID = int.Parse(tbItemID.Text);
|
|
//for(int i=1;i<5;i++)
|
|
// ShowItem(ItemInfo.GetItemAndChildren(itemID, 0), string.Format("XX All at Once Query({0})",i));
|
|
//ShowItem(ItemInfo.Get(itemID),"One at a time");
|
|
//ShowItem(ItemInfo.GetItemAndChildren2(itemID),"All at Once");
|
|
ShowItem(ItemInfo.GetItemAndChildren(itemID, 0), "XX All at Once Query");
|
|
}
|
|
private void ShowItem(ItemInfo itemInfo, string title)
|
|
{
|
|
Console.WriteLine("{0}\r\n{1}", title, ChildList(itemInfo, 0));
|
|
}
|
|
private void frmLoadAtOnce_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
SaveSettings();
|
|
}
|
|
private void SaveSettings()
|
|
{
|
|
Properties.Settings.Default.LastDatabase = Database.SelectedDatabase;
|
|
Properties.Settings.Default.WindowState = this.WindowState;
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
private void frmLoadAtOnce_Move(object sender, EventArgs e)
|
|
{
|
|
if (this.WindowState == FormWindowState.Normal)
|
|
{
|
|
Properties.Settings.Default.Location = this.Location;
|
|
Properties.Settings.Default.Size = this.Size;
|
|
}
|
|
}
|
|
private void frmLoadAtOnce_Resize(object sender, EventArgs e)
|
|
{
|
|
if (this.WindowState == FormWindowState.Normal)
|
|
{
|
|
Properties.Settings.Default.Location = this.Location;
|
|
Properties.Settings.Default.Size = this.Size;
|
|
}
|
|
}
|
|
|
|
}
|
|
} |