Added checkbox to sort Complete or Summary RO report on setpoint id and logic to sort by setpoint ID

Added status message for report generation.  Added logic to handle underline on/off (using the _ character).
This commit is contained in:
2015-04-17 16:54:21 +00:00
parent f9992cd299
commit f50e7d11b4
3 changed files with 464 additions and 115 deletions

View File

@@ -97,6 +97,95 @@ namespace Volian.Controls.Library
}
}
private Dictionary<string, string> AccIDROIDdic = new Dictionary<string, string>();
private void GenerateAccIDSortedROList()
{
//Dictionary<string, string> AccIDROIDdic = new Dictionary<string, string>();
List<string> AccPgIDsList = new List<string>();
AccIDROIDdic.Clear();
string rtnStr = "";
ROFSTLookup.rochild[] chld = null;
ROFSTLookup.rochild ch;
ROList.Clear();
foreach (object rolkup in lstCheckedROs)
{
if (rolkup == null) // All Referenced Objects selected, return list of RO databases
{
foreach (ROFSTLookup.rodbi rodbi in _MyROFSTLookup.GetRODatabaseList())
{
rtnStr = _MyRODbID.ToString() + ":" + string.Format("{0}", rodbi.dbiID.ToString("X4"));
//ROList.Add(rtnStr);
foreach (ROFSTLookup.rochild roc in rodbi.children)
PutROChildrenInDictionary(_MyRODbID.ToString() + ":", roc);
}
continue;
}
else if (rolkup is ROFSTLookup.rodbi)
{
//rtnStr = _MyRODbID.ToString() + ":" + string.Format("{0}", ((ROFSTLookup.rodbi)rolkup).dbiID.ToString("X4"));
ROFSTLookup.rodbi rodbi = (ROFSTLookup.rodbi)rolkup;
foreach (ROFSTLookup.rochild roc in rodbi.children)
PutROChildrenInDictionary(_MyRODbID.ToString() + ":", roc);
}
else if (rolkup is ROFSTLookup.rochild)
{
ch = (ROFSTLookup.rochild)rolkup;
chld = ch.children;
//rtnStr = _MyRODbID.ToString() + ":" + GetROChildren(rolkup).TrimEnd(',');
PutROChildrenInDictionary(_MyRODbID.ToString() + ":", rolkup);
}
//else if (rolkup is ROFSTLookup.rogrp)
// Console.WriteLine("RO Group");
//else if (rolkup is ROFSTLookup.roHdr)
// Console.WriteLine("RO Header");
//ROList.Add(rtnStr);
}
foreach (string k in AccIDROIDdic.Keys)
AccPgIDsList.Add(k);
string[] AccPgIdListArray = AccPgIDsList.ToArray();
Array.Sort(AccPgIdListArray, new AlphanumComparatorFast());
foreach (string accid in AccPgIdListArray)
ROList.Add(AccIDROIDdic[accid]);
}
static int blankKeyCnt = 0;
private string GetNextBlankKey()
{
return string.Format(" _{0}", blankKeyCnt++);
}
private void PutROChildrenInDictionary(string rodbidPrefix, object roObj)
{
ROFSTLookup.rochild chld = (ROFSTLookup.rochild)roObj;
string rtnstr = rodbidPrefix;// "";
string keystr = (chld.appid == "") ? GetNextBlankKey() : chld.appid;
if (chld.children == null) // get a single ROID
{
rtnstr = rodbidPrefix + string.Format("{0}", chld.roid);
if (rtnstr.Length == 12) rtnstr += "0000"; // last four digits are used for multiple return values
AccIDROIDdic.Add(keystr, rtnstr);
}
else if (!cbxROUsage.Checked && chld.children[0].ParentID == 0)
{
rtnstr = rodbidPrefix + string.Format("{0},", chld.roid); // doing a RO Summary or RO Complete report - don't want children that are multiple return values
AccIDROIDdic.Add(keystr, rtnstr);
}
else
{ // spin through the child list and get the ROIDs.
// if the child has children, then call this function recursivly
foreach (ROFSTLookup.rochild roc in chld.children)
{
// Don't get the children if we are doing a RO Summary or RO Complete report & children are the multiple return values
if (roc.children != null && (cbxROUsage.Checked || roc.children[0].ParentID != 0))
PutROChildrenInDictionary(rodbidPrefix, roc);
else if (roc.appid != null && roc.appid != "")
{
rtnstr = rodbidPrefix + string.Format("{0}", roc.roid);
keystr = (roc.appid == "") ? GetNextBlankKey() : roc.appid;
AccIDROIDdic.Add(keystr, rtnstr);
}
}
}
}
private void GenerateROList()
{
@@ -116,7 +205,7 @@ namespace Volian.Controls.Library
continue;
}
else if (rolkup is ROFSTLookup.rodbi)
rtnStr = _MyRODbID.ToString() + ":" + string.Format("{0}", ((ROFSTLookup.rodbi)rolkup).dbiID.ToString("X4"));
rtnStr = _MyRODbID.ToString() + ":" + string.Format("{0}", ((ROFSTLookup.rodbi)rolkup).dbiID.ToString("X4"));
else if (rolkup is ROFSTLookup.rochild)
{
ch = (ROFSTLookup.rochild)rolkup;
@@ -200,6 +289,8 @@ namespace Volian.Controls.Library
cbxIncldMissingROs.Text = "Include Empty RO Fields";
cbxIncldMissingROs.Checked = false;// !cbxSummary.Checked;
cbxIncldMissingROs.Visible = cbxROUsage.Checked || cbxComplete.Checked;
cbxSortBySetpointID.Checked = false;
cbxSortBySetpointID.Visible = cbxComplete.Checked || cbxSummary.Checked;
}
public void SelectReferencedObjectTab()
@@ -213,7 +304,7 @@ namespace Volian.Controls.Library
{
foreach (DevComponents.AdvTree.Node n in chldrn)
{
if (n.Checked)
if (n.Checked)
lstCheckedROs.Add(n.Tag);
else
AddSelectedROChildren(n.Nodes);
@@ -252,6 +343,8 @@ namespace Volian.Controls.Library
cbxIncldMissingROs.Text = "Include Empty RO Fields";
//cbxIncldMissingROs.Checked = cbxROUsage.Checked || cbxComplete.Checked;
cbxIncldMissingROs.Visible = cbxROUsage.Checked || cbxComplete.Checked;
cbxSortBySetpointID.Visible = cbxComplete.Checked || cbxSummary.Checked;
labelX1.Visible = cmbxROUsageSort.Visible = !cbxSortBySetpointID.Visible;
}
private void tabTransitionReports_Click(object sender, EventArgs e)
@@ -267,10 +360,12 @@ namespace Volian.Controls.Library
{
xpSetToReport.Enabled = cbxROUsage.Checked;
xpSetToReport.Expanded = cbxROUsage.Checked;
cmbxROUsageSort.Enabled = cbxROUsage.Checked;
labelX1.Visible = cmbxROUsageSort.Visible = cbxROUsage.Checked;
xpSelROs.Enabled = true;
xpSelROs.Expanded = true;
cbxIncldMissingROs.Checked = false;// !cbxSummary.Checked;
cbxSortBySetpointID.Checked = false;
cbxSortBySetpointID.Visible = !cbxROUsage.Checked;
EnableOrDisablePrintButton();
}
@@ -278,11 +373,13 @@ namespace Volian.Controls.Library
{
xpSetToReport.Enabled = cbxROUsage.Checked;
xpSetToReport.Expanded = cbxROUsage.Checked;
cmbxROUsageSort.Enabled = cbxROUsage.Checked;
labelX1.Visible = cmbxROUsageSort.Visible = cbxROUsage.Checked;
// reset the RO tree and clear anything that was selected
advTreeROFillIn(true);
lstCheckedROs.Clear();
cbxIncldMissingROs.Checked = false;// !cbxSummary.Checked;
cbxSortBySetpointID.Checked = false;
cbxSortBySetpointID.Visible = !cbxROUsage.Checked;
EnableOrDisablePrintButton();
}
#region Procedure List
@@ -522,7 +619,7 @@ namespace Volian.Controls.Library
DevComponents.AdvTree.Node topnode = null;
advTreeRO.Nodes.Clear();
if (_MyROFSTLookup == null) return;
advTreeRO.BeforeExpand +=new AdvTreeNodeCancelEventHandler(advTreeRO_BeforeExpand);
advTreeRO.BeforeExpand += new AdvTreeNodeCancelEventHandler(advTreeRO_BeforeExpand);
advTreeRO.AfterExpand += new AdvTreeNodeEventHandler(advTreeRO_AfterExpandorCollapse);
advTreeRO.AfterCollapse += new AdvTreeNodeEventHandler(advTreeRO_AfterExpandorCollapse);
topnode = new DevComponents.AdvTree.Node();
@@ -710,14 +807,14 @@ namespace Volian.Controls.Library
{
return DisplayRO.GreaterValue(value1, value2);
// Match match1 = _RegExGetNumber.Match(value1);
// Match match2 = _RegExGetNumber.Match(value2);
// if (match1.Success && match2.Success) // Compare the numeric value
// {
// double dbl1 = double.Parse(match1.ToString());
// double dbl2 = double.Parse(match2.ToString());
// return dbl1 > dbl2;
// }
// return String.Compare(value1, value2, true) > 0;
// Match match2 = _RegExGetNumber.Match(value2);
// if (match1.Success && match2.Success) // Compare the numeric value
// {
// double dbl1 = double.Parse(match1.ToString());
// double dbl2 = double.Parse(match2.ToString());
// return dbl1 > dbl2;
// }
// return String.Compare(value1, value2, true) > 0;
}
@@ -777,6 +874,7 @@ namespace Volian.Controls.Library
private void cbxComplete_CheckedChanged(object sender, EventArgs e)
{
cbxIncldMissingROs.Checked = false;// !cbxSummary.Checked;
cbxSortBySetpointID.Checked = false;
EnableOrDisablePrintButton();
}
@@ -803,7 +901,7 @@ namespace Volian.Controls.Library
}
if (MyDVI == null || MyDVI.DocVersionAssociationCount < 1)
{
MessageBox.Show("Could not find associated path for ro data.","No RO Data", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("Could not find associated path for ro data.", "No RO Data", MessageBoxButtons.OK, MessageBoxIcon.Information);
return "";
}
//string roloc = "\"" + MyDVI.DocVersionAssociations[0].MyROFst.MyRODb.FolderPath + "\" " + "\"" + ROList + "\"";
@@ -816,7 +914,6 @@ namespace Volian.Controls.Library
roDataFile = MyDVI.DocVersionAssociations[0].MyROFst.MyRODb.FolderPath + "\\" + roDataFile;
try
{
if (File.Exists(roDataFile)) File.Delete(roDataFile);
Application.DoEvents();
string fname = VlnSettings.TemporaryFolder + "\\ROCompleteRprt.txt";
@@ -847,12 +944,18 @@ namespace Volian.Controls.Library
Cursor = Cursors.WaitCursor;
if (cbxSummary.Checked) // RO Summary Report
{
GenerateROList();
if (cbxSortBySetpointID.Checked)
GenerateAccIDSortedROList();
else
GenerateROList();
OnPrintRequest(new DisplayReportsEventArgs("RO Summary Report", "RO Summary Report", MyROFSTLookup, ROList));
}
else if (cbxComplete.Checked) // Complete RO Report
{
GenerateROList();
if (cbxSortBySetpointID.Checked)
GenerateAccIDSortedROList();
else
GenerateROList();
string ROList = GetListOfROs(false);//don't include the RODbID in the RO list
string roDataFile = BuildRODataFile(ROList);
OnPrintRequest(new DisplayReportsEventArgs("Complete RO Report", "Complete RO Report", roDataFile, MyROFSTLookup, cbxComplete.Checked, this.Mydocversion.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta, cbxIncldMissingROs.Checked));
@@ -867,10 +970,10 @@ namespace Volian.Controls.Library
{
Csla.SortedBindingList<ItemInfo> sortedResults = new Csla.SortedBindingList<ItemInfo>(SearchResults);
sortedResults.ApplySort("FoundROID", ListSortDirection.Ascending);
OnPrintRequest(new DisplayReportsEventArgs("Referenced Objects Usage By RO", "RO Usage", sortedResults, usageSortedByProcedure,cbxIncldMissingROs.Checked));
OnPrintRequest(new DisplayReportsEventArgs("Referenced Objects Usage By RO", "RO Usage", sortedResults, usageSortedByProcedure, cbxIncldMissingROs.Checked));
}
else
OnPrintRequest(new DisplayReportsEventArgs("Referenced Objects Usage By Procedure", "RO Usage", SearchResults, usageSortedByProcedure,cbxIncldMissingROs.Checked));
OnPrintRequest(new DisplayReportsEventArgs("Referenced Objects Usage By Procedure", "RO Usage", SearchResults, usageSortedByProcedure, cbxIncldMissingROs.Checked));
}
else if (cbxTransFromProcs.Checked)
{
@@ -984,4 +1087,164 @@ namespace Volian.Controls.Library
}
}
public delegate void DisplayReportsEvent(object sender, DisplayReportsEventArgs args);
public class AlphanumComparatorFast : IComparer<string>
{
List<string> GetList(string s1)
{
List<string> SB1 = new List<string>();
string st1, st2, st3;
st1 = "";
bool flag = char.IsDigit(s1[0]);
foreach (char c in s1)
{
if (flag != char.IsDigit(c) || !(char.IsDigit(c) || char.IsLetter(c)))// || c == '\'')
{
if (st1 != "")
SB1.Add(st1);
st1 = "";
flag = char.IsDigit(c);
}
if (char.IsDigit(c))
{
st1 += c;
}
if (char.IsLetter(c))
{
st1 += c;
}
}
SB1.Add(st1);
return SB1;
}
public int Compare(string x, string y)
{
string s1 = x;// as string;
if (s1 == null)
{
return 0;
}
string s2 = y;// as string;
if (s2 == null)
{
return 0;
}
if (s1 == s2)
{
return 0;
}
int len1 = s1.Length;
int len2 = s2.Length;
int marker1 = 0;
int marker2 = 0;
// Walk through two the strings with two markers.
List<string> str1 = GetList(s1);
List<string> str2 = GetList(s2);
while (str1.Count != str2.Count)
{
if (str1.Count < str2.Count)
{
str1.Add("");
}
else
{
str2.Add("");
}
}
int x1 = 0; int res = 0; int x2 = 0; string y2 = "";
bool status = false;
string y1 = ""; bool s1Status = false; bool s2Status = false;
//s1status ==false then string ele int;
//s2status ==false then string ele int;
int result = 0;
for (int i = 0; i < str1.Count && i < str2.Count; i++)
{
status = int.TryParse(str1[i].ToString(), out res);
if (res == 0)
{
y1 = str1[i].ToString();
s1Status = false;
}
else
{
x1 = Convert.ToInt32(str1[i].ToString());
s1Status = true;
}
status = int.TryParse(str2[i].ToString(), out res);
if (res == 0)
{
y2 = str2[i].ToString();
s2Status = false;
}
else
{
x2 = Convert.ToInt32(str2[i].ToString());
s2Status = true;
}
//checking --the data comparision
if (!s2Status && !s1Status) //both are strings
{
result = str1[i].CompareTo(str2[i]);
}
else if (s2Status && s1Status) //both are intergers
{
if (x1 == x2)
{
if (str1[i].ToString().Length < str2[i].ToString().Length)
{
result = 1;
}
else if (str1[i].ToString().Length > str2[i].ToString().Length)
result = -1;
else
result = 0;
}
else
{
int st1ZeroCount = str1[i].ToString().Trim().Length - str1[i].ToString().TrimStart(new char[] { '0' }).Length;
int st2ZeroCount = str2[i].ToString().Trim().Length - str2[i].ToString().TrimStart(new char[] { '0' }).Length;
if (st1ZeroCount > st2ZeroCount)
result = -1;
else if (st1ZeroCount < st2ZeroCount)
result = 1;
else
result = x1.CompareTo(x2);
}
}
else
{
result = str1[i].CompareTo(str2[i]);
}
if (result == 0)
{
continue;
}
else
break;
}
return result;
}
// sample usage
// List<string> marks = new List<string>();
// marks.Add("M'00Z1");
// marks.Add("M'0A27");
// marks.Add("M'00Z0");
// marks.Add("0000A27");
// marks.Add("100Z0");
//string[] Markings = marks.ToArray();
// Array.Sort(Markings, new AlphanumComparatorFast());
}
}