C2021-026 Parent/Child applicability in RO Editor

This commit is contained in:
2021-07-29 18:28:12 +00:00
parent 697490d5bf
commit ce9e9e182e
16 changed files with 1103 additions and 263 deletions

View File

@@ -1,5 +1,5 @@
/*********************************************************************************************
* Copyright 2002 - Volian Enterprises, Inc. All rights reserved.
* Copyright 2021 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: RODBInterface.cs $ $Revision: 48 $
@@ -264,6 +264,7 @@ using Org.Mentalis.Files;
using System.Data.SqlClient;
using System.Collections.Generic;
namespace RODBInterface
{
/// <summary>
@@ -273,7 +274,6 @@ namespace RODBInterface
{
Master = 0, SubDatabase = 1, Schema = 2, Group = 3, GroupSchema = 4, RRO = 5, SchemaStart = 6, SchemaEnd = 7, ConvertedToSql = 8
}
/// <summary>
/// The following class handles generation of sql strings to get/put requested parts of
/// XML RO Tree. And performs the database access using the VLN_DB class.
@@ -314,6 +314,13 @@ namespace RODBInterface
get { return _OnlyConnectOnce; }
set { _OnlyConnectOnce = value; }
}
// C2021-026 used to access in the list of P/C Children
private static string[] _PCChildList = null;
public static string[] PCChildList
{
get { return _PCChildList; }
set { _PCChildList = value; }
}
#endregion
#region abstracts // need these for each method that must be defined for each database type
public abstract string RODB_GetNextGroupTable();
@@ -354,7 +361,6 @@ namespace RODBInterface
}
#region GeneralDB
public void GetDbServerInfo(string ROdir)
{
@@ -504,6 +510,84 @@ namespace RODBInterface
}
return inuse;
}
//C2021-026 adding ability to have field values based on Parent/Child applicability
// This reads the database and returns a list of the field where applicability was enabled
public ArrayList RODB_GetApplicabilityEnabledFields(VlnXmlElement elem, ArrayList fieldsInUse, ref string origApplcFields, bool pcApplicabilityEnabled)
{
ArrayList newApplicList = new ArrayList();
if (!pcApplicabilityEnabled)
{
origApplcFields = null;
return newApplicList;
}
VlnXmlElement startelem = elem;
string atribApplicFields = "ApplicabilityEnabled"; //xml attribute containing list of field recids
// if this element doesn't have any fields in use, walk up the tree until
// we find them.
string applicFields = "";
if (startelem.HasAttribute(atribApplicFields) == false)
{
VlnXmlElement parent;
parent = (VlnXmlElement)startelem.ParentNode;
while (parent != null && applicFields == "")
{
applicFields = parent.GetAttribute(atribApplicFields);
if (parent.Name != "RO_Root")
parent = (VlnXmlElement)parent.ParentNode;
else
parent = null;
}
}
else
applicFields = startelem.GetAttribute(atribApplicFields);
origApplcFields = applicFields; // make a copy to compare to later.
// if there are no fields with applicability (may be inserting a top group)
// return an empty list.
if (applicFields == "") return newApplicList;
// Go through the FieldsInUse list and copy elements to newApplicList
int strpos = 0;
string recid;
recid = applicFields.Substring(strpos, 8);
MyRecID = recid;
while (recid != null)
{
// find it in avail list and add to newApplicList
for (int i = 0; i < fieldsInUse.Count; i++)
{
ROField rof = (ROField)fieldsInUse[i];
string lrecid = rof.GetRecID;
if (lrecid == recid)
{
// add to newApplilcList if it is not already there list
ROField inuserof = new ROField(rof.GetFieldname, rof.GetRecID, rof.GetMasterRecID, rof.GetFieldType);
bool addit = true;
foreach (ROField arof in newApplicList)
{
if (arof.GetRecID == inuserof.GetRecID)
{
addit = false; //this field is already in the list
break;
}
}
if (addit)
newApplicList.Add((object)inuserof);
break;
}
}
strpos = strpos + 9;
if (strpos > applicFields.Length)
recid = null;
else
{
recid = applicFields.Substring(strpos, 8);
}
}
return newApplicList;
}
public string CvtUserFldToFld(string fldname)
{
if (fldname.Length < 2)
@@ -649,6 +733,12 @@ namespace RODBInterface
xmlTextWriter.WriteString(enode.GetAttribute("FieldsInUse"));
xmlTextWriter.WriteEndAttribute();
}
if (enode.HasAttribute("ApplicabilityEnabled")) //C2021-026 save field applicability
{
xmlTextWriter.WriteStartAttribute("ApplicabilityEnabled", null);
xmlTextWriter.WriteString(enode.GetAttribute("ApplicabilityEnabled"));
xmlTextWriter.WriteEndAttribute();
}
if (enode.HasAttribute("GroupMenuItem"))
{
xmlTextWriter.WriteStartAttribute("GroupMenuItem", null);
@@ -755,12 +845,31 @@ namespace RODBInterface
success = RODB_NewSchemaPiece(lrecid, parent.GetAttribute("RecID"), myelem.GetAttribute("Table"), strbld.ToString(), editlevel);
return success;
}
// C2021-026 rename any P/C Child fields
public string DoReplaceParentChildField(string infstr, string oldName, string newName)
{
string rtnInfoStr = infstr;
if (PCChildList == null) return rtnInfoStr;
int pcChildIdx = 0; // children indexing starts at one so initialize with zero
foreach (string chld in PCChildList)
{
pcChildIdx++;
string csufx = string.Format("_PCCHILD{0}", pcChildIdx); // Create child field name
string oldFldNameChild = oldName.Insert(oldName.Length - 1, CvtUserFldToFld(csufx));
string newFldNameChild = newName.Insert(newName.Length - 1, CvtUserFldToFld(csufx));
rtnInfoStr = rtnInfoStr.Replace(oldFldNameChild, newFldNameChild);
}
return rtnInfoStr;
}
public string DoCmbFieldReplace(string repstring, string oname, string nname, string letter)
{
string cmboname, cmbnname;
cmboname = oname.Insert(oname.Length - 1, letter);
cmbnname = nname.Insert(nname.Length - 1, letter);
return (repstring.Replace(cmboname, cmbnname));
string rtnstr = repstring.Replace(cmboname, cmbnname);
rtnstr = DoReplaceParentChildField(rtnstr, cmboname, cmbnname); // C2021-026 create child fields in combo group
return rtnstr;
}
// RODB_UpdateNamesInROs: goes through subtree (top node is 'fld') and if this
@@ -2333,11 +2442,9 @@ namespace RODBInterface
DBE.CommandDispose();
return success;
}
public override bool RODB_ProcessRROFieldChange(VlnXmlElement child, string oldname, string newname, uint editlevel,
VlnStatusMessage StatMsgWindow, bool combofield)
{
bool success;
string str;
string info;
@@ -2464,7 +2571,9 @@ namespace RODBInterface
if (combofield == false)
{
tinfo1 = info.Replace(onameOpen, nnameOpen);
tinfo1 = DoReplaceParentChildField(tinfo1, onameOpen, nnameOpen); //C2021-0226 also update Parent/Child fields
tinfo2 = tinfo1.Replace(onameClose, nnameClose);
tinfo2 = DoReplaceParentChildField(tinfo2, onameClose, nnameClose); //C2021-0226 also update Parent/Child fields
XmlNodeList nodeList;
nodeList = echild.SelectNodes(oldname);
foreach (XmlNode nod in nodeList)
@@ -2499,7 +2608,6 @@ namespace RODBInterface
}
}
}
StatMsgWindow.StatusMessage = echild.GetAttribute("MenuTitle");
str = "UPDATE " + echild.GetAttribute("Table") + " SET Info = '" + tinfo2 + "'";
str = str + ", ModDateTime = '" + dt + "' WHERE RecID = '" + echild.GetAttribute("RecID") + "';";

View File

@@ -2133,7 +2133,9 @@ namespace RODBInterface
if (combofield == false)
{
tinfo1 = info.Replace(onameOpen, nnameOpen);
tinfo1 = DoReplaceParentChildField(tinfo1, onameOpen, nnameOpen); //C2021-0226 also update Parent/Child fields
tinfo2 = tinfo1.Replace(onameClose, nnameClose);
tinfo2 = DoReplaceParentChildField(tinfo2, onameClose, nnameClose); //C2021-0226 also update Parent/Child fields
XmlNodeList nodeList;
nodeList = echild.SelectNodes(oldname);
foreach (XmlNode nod in nodeList)
@@ -2565,6 +2567,7 @@ namespace RODBInterface
return null;
}
}
// C2021-026 read in schema for the "ApplicabilityEnabled" attribute
entireschema = schemastart + entireschema + schemaend;
}
XmlTextReader schemareader = new XmlTextReader(entireschema, XmlNodeType.Element, null);

View File

@@ -1,5 +1,5 @@
/*********************************************************************************************
* Copyright 2002 - Volian Enterprises, Inc. All rights reserved.
* Copyright 2021 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: VlnXml.cs $ $Revision: 23 $
@@ -689,13 +689,78 @@ namespace RODBInterface
return rtnval;
}
private ArrayList GetApplcFieldListForElement(RODB roDatabase, VlnXmlElement elem, bool pcApplicability)
{
ArrayList rtnval = null;
ArrayList InUseApplcList = null;
ArrayList AvailList = null;
ArrayList InUseList = null;
string origFieldsInUse = "";
string origApplicFields = "";
ArrayList tmp = roDatabase.RODB_GetFields((VlnXmlElement)elem.ParentNode, (uint)RecordType.Schema);
// put the items in the AvailList box.
if (AvailList == null) AvailList = new ArrayList();
for (int i = 0; i < tmp.Count; i++) AvailList.Add(tmp[i]); // don't modify the list returned from RODB_GetFields since it is part of dictionary
InUseList = roDatabase.RODB_GetFieldsInUse((VlnXmlElement)elem.ParentNode, AvailList, "FieldsInUse", ref origFieldsInUse, false);
InUseApplcList = roDatabase.RODB_GetApplicabilityEnabledFields((VlnXmlElement)elem.ParentNode, InUseList, ref origApplicFields, pcApplicability);
rtnval = new ArrayList();
foreach (ROField rof in InUseApplcList)
rtnval.Add(rof.GetFieldname);
return rtnval;
}
private string GetPCReturnValues(RODB theDb, string[] pcChildern, VlnXmlElement elm, bool PCApplicability, string inusename, string defValue)
{
string applicValues = defValue;
ArrayList FieldsWithApplic = GetApplcFieldListForElement(theDb, elm, PCApplicability);
if (FieldsWithApplic.Contains(CvtFldToUserFld(inusename))) // C2021-026 returns True if field should show Parent/Child Applicability fields
{
XmlNode elmnode = (XmlNode)elm;
XmlNode nd = elmnode.SelectSingleNode(inusename);
string parentName = inusename;
string parentValue = "";
public string GetReturnValue(RODB theDb, string TableName,string RtnValTemplate, ArrayList InUseList, ref ushort ValueType)
if (nd == null)
{
XmlNode radNode = elmnode.FirstChild;
string radNodeName = radNode.Name;
while (radNode != null && !radNodeName.StartsWith(inusename))
{
radNode = radNode.NextSibling;
radNodeName = radNode.Name;
}
parentValue = radNode.InnerText;
parentName = radNodeName;
}
else
parentValue = nd.InnerText;
//applicValues = "";
applicValues = string.Format("<APL DefaultVal={0}", parentValue);
int pcChildIdx = 0;
foreach (string c in pcChildern)
{
//string csufx = CvtUserFldToFld(c);
pcChildIdx++;
string csufx = string.Format("_PCCHILD{0}", pcChildIdx);
applicValues += ",";
XmlNode cn = elmnode.SelectSingleNode(parentName + csufx);
if (cn == null)
applicValues += string.Format("UnitIdx={0} Value={1}", pcChildIdx, parentValue); // use parent value as default
else
applicValues += string.Format("UnitIdx={0} Value={1}", pcChildIdx, cn.InnerText);
}
applicValues += " /APL>";
}
return applicValues;
}
public string GetReturnValue(RODB theDb, string TableName, string RtnValTemplate, ArrayList InUseList, ref ushort ValueType, string[] pcChildern)
{
string RtnValStr = "";
VlnXmlElement elm = this;
StringBuilder strbld = new StringBuilder();
bool PCApplicability = (pcChildern != null && pcChildern.Length > 0);
// Parse the template for the fields and generate a return string
int left = RtnValTemplate.IndexOf("<"); // look for begining of field
int right = -1;
@@ -762,6 +827,8 @@ namespace RODBInterface
}
ValueType |= FldType;
if (PCApplicability)
text = GetPCReturnValues(theDb, pcChildern, elm, PCApplicability, inusename, text); // C2021-026 Get P/C Children return values
strbld.Append(text);
}
else
@@ -789,6 +856,7 @@ namespace RODBInterface
return RtnValStr;
}
public string GetComboFieldValueAndType(XmlNode CurNode, string Fld, ref ushort FldTyp, bool ForMenu)
{
string RtnVal = "";
@@ -929,52 +997,52 @@ namespace RODBInterface
///
// ShowGroupDetail sends to print.tmp the data for a Group level.
private bool ShowGroupDetail(RODB myrodb)
{
ROField rof;
XmlNode nd;
VlnXmlDocument xmldoc = (VlnXmlDocument) this.OwnerDocument;
string nm;
//private bool ShowGroupDetail(RODB myrodb)
//{
// ROField rof;
// XmlNode nd;
// VlnXmlDocument xmldoc = (VlnXmlDocument) this.OwnerDocument;
// string nm;
// First get the fields used for this Group.
string tmp=null; // needed for inuse call
ArrayList AvailList = myrodb.RODB_GetFields(this, 0);
ArrayList InUseList = myrodb.RODB_GetFieldsInUse(this, AvailList, "GroupFieldsInUse", ref tmp, false);
// // First get the fields used for this Group.
// string tmp=null; // needed for inuse call
// ArrayList AvailList = myrodb.RODB_GetFields(this, 0);
// ArrayList InUseList = myrodb.RODB_GetFieldsInUse(this, AvailList, "GroupFieldsInUse", ref tmp, false);
// For each field, print the header (field name) & then print data if it exists.
if (InUseList != null)
{
xmldoc.writeRROBegin();
xmldoc.writeInt(7);
xmldoc.writeText(" ");
// // For each field, print the header (field name) & then print data if it exists.
// if (InUseList != null)
// {
// xmldoc.writeRROBegin();
// xmldoc.writeInt(7);
// xmldoc.writeText(" ");
for (int i=0; i< InUseList.Count; i++)
{
rof = (ROField) InUseList[i];
if (rof.GetFieldname != null)
{
string nm0 = rof.GetFieldname;
nm = rof.MakeFieldName(nm0);
xmldoc.pushHeader(nm0);
// see if it has data in the ro.
nd = this.SelectSingleNode(nm);
// if not found with just the string, search the tree.
if (nd==null)nd = this.SelectSingleNode("*/"+nm);
if (nd == null) // not found, write out a '0'.
xmldoc.writeInt(0);
else
{
VlnXmlElement end;
end = (VlnXmlElement) nd;
xmldoc.writeTextValue(end.InnerText);
}
xmldoc.popHeader();
}
}
xmldoc.writeRROEnd();
}
return true;
}
// for (int i=0; i< InUseList.Count; i++)
// {
// rof = (ROField) InUseList[i];
// if (rof.GetFieldname != null)
// {
// string nm0 = rof.GetFieldname;
// nm = rof.MakeFieldName(nm0);
// xmldoc.pushHeader(nm0);
// // see if it has data in the ro.
// nd = this.SelectSingleNode(nm);
// // if not found with just the string, search the tree.
// if (nd==null)nd = this.SelectSingleNode("*/"+nm);
// if (nd == null) // not found, write out a '0'.
// xmldoc.writeInt(0);
// else
// {
// VlnXmlElement end;
// end = (VlnXmlElement) nd;
// xmldoc.writeTextValue(end.InnerText);
// }
// xmldoc.popHeader();
// }
// }
// xmldoc.writeRROEnd();
// }
// return true;
//}
public XmlNode GetCurrentOfMultiFields(VlnXmlElement CurElement, string FldName)
{
@@ -997,6 +1065,19 @@ namespace RODBInterface
return nd;
}
private bool ContainedInArrayList(ROField rof, ArrayList aryList)
{
bool isInList = false;
foreach (ROField arof in aryList)
{
if (arof.GetRecID == rof.GetRecID)
{
isInList = true;
break;
}
}
return isInList;
}
// ShowRRO writes data for the input RO.
private bool ShowRRO(RODB myrodb, ArrayList headers)
{
@@ -1010,7 +1091,8 @@ namespace RODBInterface
string tmp=null; // needed for inuse call
ArrayList AvailList = myrodb.RODB_GetFields(this, 0);
ArrayList InUseList = myrodb.RODB_GetFieldsInUse(this, AvailList, "FieldsInUse", ref tmp, false);
ArrayList InUseApplcList = myrodb.RODB_GetApplicabilityEnabledFields(this, InUseList, ref tmp, HasApplicabilityEnabled); // C2021-026 get fields that have P/C Children
string defPCROval = "";
// put out the stored headers, i.e. the group titles up the tree.
xmldoc.doHeader(headers);
@@ -1094,13 +1176,33 @@ namespace RODBInterface
if (doingplot)
xmldoc.writePlot(end.InnerText);
else
{
xmldoc.writeTextValue(end.InnerText);
defPCROval = end.InnerText;
}
}
}
// C2021_026 put out PC children values
if (ContainedInArrayList(rof,InUseApplcList))
{
XmlNode pcn;
int pcChildIdx = 0;
foreach (string s in PCChildren)
{
pcChildIdx++;
string pcName = nd.Name + string.Format("_PCCHILD{0}", pcChildIdx); // create child field name
string pcField = rof.MakeFieldName(pcName);
xmldoc.pushHeader(" "+s); // put out the PC Child name (indented 5 spaces) for complete RO Report
// see if it has data in the ro.
pcn = this.SelectSingleNode(pcField);
if (pcn != null)
xmldoc.writeTextValue(pcn.InnerText); // use PC Child value
else
xmldoc.writeTextValue(defPCROval); // use default value
}
}
xmldoc.popHeader();
}
}
xmldoc.writeRROEnd();
}
@@ -1184,12 +1286,21 @@ namespace RODBInterface
headers.RemoveAt(headers.Count-1);
return true;
}
private static string[] PCChildren = null; //C2021-026 holds list of P/C children names
public bool HasApplicabilityEnabled
{
get
{
return (PCChildren != null && PCChildren.Length > 0);
}
}
// put this element, and if a group all it's subelements out to the 'print.tmp'
// file for complete reports.
public bool Show(RODB myrodb, ArrayList headers, VlnStatusMessage showStat)
public bool Show(RODB myrodb, ArrayList headers, VlnStatusMessage showStat, string [] pcChildren)
{
bool success;
PCChildren = pcChildren; // C2021-026 list of P/C children
VlnXmlDocument xmldoc = (VlnXmlDocument) this.OwnerDocument;
success = xmldoc.OpenTemp();
if (success==false) return false;

View File

@@ -1,5 +1,5 @@
/*********************************************************************************************
* Copyright 2002 - Volian Enterprises, Inc. All rights reserved.
* Copyright 2021 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: ROField.cs $ $Revision: 11 $
@@ -63,12 +63,22 @@ using System.Text;
namespace ROFields
{
// Field Types:
// SingleTxt - Single Line Text
// VariableTxt - Variable Length Text (multiple lines)
// FrmtSingleTxt - Single Line Formatted text - used for Accessory ID fields
// XYPlot - used to enter the plot language commands
// Table - Used to enter a table (16-bit VE-PROMS text based style using dashes and pipe characters to define cells)
// Image - Used for images (ex. TIF,JPG,BMP file references)
// MultiTxt - ??
// Combination - used for Setpoint return values - user can select type of return value (Single/Multi line text, Table, X/Y Plot)
// when entering the RO data
// MultiField - ??
public enum FieldTypes: uint
{
Nil=0, SingleTxt=1, VariableTxt=2, FrmtSingleTxt=4, XYPlot=8, Table=10, Image=32,
MultiTxt=40, Combination=128, MultiFld=100
}
/// <summary>
/// Summary description for ROField: This class contains RO Field information. Each ROField
/// contains:
@@ -92,7 +102,7 @@ namespace ROFields
recID = rID;
masterrecID = mrID;
fldtype = fieldtype;
}
}
public string GetFieldname { get {return fieldname;}}
public string GetRecID { get {return recID;}}
public string GetMasterRecID { get {return masterrecID;}}
@@ -101,7 +111,23 @@ namespace ROFields
public void SetRecID(string recid) {recID = recid;}
public void SetMasterRecID(string mrecid) {masterrecID = mrecid;}
public void SetFieldType(uint ftype) {fldtype = ftype;}
// C2021-026 return true if we allow child values for the current field type
public bool FieldTypeCanDoApplicability()
{
bool rtnval = false;
switch (fldtype)
{
case (uint)FieldTypes.SingleTxt:
case (uint)FieldTypes.VariableTxt:
case (uint)FieldTypes.Combination:
rtnval = true;
break;
}
return rtnval;
}
// Given a schema string, determine which RO Field type it is.
public uint ParseFieldType(string info)
{
@@ -191,7 +217,7 @@ namespace ROFields
StringBuilder strbld = new StringBuilder();
strbld.Append("<xsd:element name=\"");
strbld.Append(MakeFieldName(fieldname));
strbld.Append("\" minOccurs=\"0\">\n");
strbld.Append("\" minOccurs=\"0\">\n");
if (ftype == (uint)FieldTypes.VariableTxt || ftype == (uint)FieldTypes.Table || ftype == (uint)FieldTypes.XYPlot)
{
strbld.Append("<xsd:annotation>\n<xsd:documentation xml:lang=\"en\">");

View File

@@ -1,5 +1,5 @@
/*********************************************************************************************
* Copyright 2002 - Volian Enterprises, Inc. All rights reserved.
* Copyright 2021 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: ctlXMLEdit.cs $ $Revision: 36 $
@@ -258,12 +258,17 @@ namespace ctlXMLEditLib
int DPPL = (720/6);
int DPPC = (720/12);
int height, width;
/** C2021-026 the following are use for Parent Child RO fields **/
public ArrayList FieldsWithApplic = null;
public string[] PCChildren;
private GroupBox pcGrpBox = null;
/** end C2021-026 **/
// use this struct to define attributes for the text box fields, storing
// the pattern, radio button association, required field flag, etc.
struct TextBoxAttrTag
{
bool required; //whether the field is required
string req_msg; //message to print if required, but not set
string pattern; //pattern for validation
@@ -295,10 +300,12 @@ namespace ctlXMLEditLib
public void SetImageDate(string imgdate) {this.imagedate = imgdate;}
}
public ctlXMLEdit(VlnXmlElement myelem, XmlSchema myschema, ArrayList reqfields)
public ctlXMLEdit(VlnXmlElement myelem, XmlSchema myschema, ArrayList reqfields, ArrayList fldsWithApplic, string [] pckids)
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
FieldsWithApplic = fldsWithApplic;
PCChildren = pckids; //C2021-026 list of Parent/Child children
zmtooltip = new ToolTip();
myHT = new Hashtable();
tabindx=0;
@@ -409,6 +416,38 @@ namespace ctlXMLEditLib
}
}
}
// C2021-026 If this is a Parent/Child field that has no value saved in the database
// then use the parent's value and display it as grey colored text.
private void GetDefaultParentValue(TextBox tb, XmlNode node, string chldName)
{
XmlNode parentNode = null;
// PCChildren contains a list strings reprenting the Children setup in the current Working Draft Parent/Child property
if (PCChildren == null) return; // C2021-026 no children to process
int pcChildIdx = 0; // C2021-026 corresponds with DocVersionConfig.SelectedSlave value: 0 = no child selected 1 = first child ...
foreach (string c in PCChildren)
{
pcChildIdx++;
string csufx = string.Format("_PCCHILD{0}", pcChildIdx); // C2021-026 create a child field name
if (chldName.EndsWith(csufx))
{
int idx = chldName.LastIndexOf(csufx);
if (idx > 0)
{
string parent = chldName.Remove(idx);
parentNode = node.SelectSingleNode(parent);
// if not found with just the string, search the tree.
if (parentNode == null) parentNode = node.SelectSingleNode("*/" + parent);
if (parentNode != null)
{
tb.Text = parentNode.InnerText; // set the P/C Child text box to the parent's value
tb.ForeColor = SystemColors.GrayText;
break;
}
}
}
}
}
// Given a parent XmlNode, walk through the child nodes & add the text for the
// node to the associated text box.
@@ -425,7 +464,9 @@ namespace ctlXMLEditLib
nd = node.SelectSingleNode(str);
// if not found with just the string, search the tree.
if (nd==null)nd = node.SelectSingleNode("*/"+str);
if (nd != null)
if (nd == null)
GetDefaultParentValue(hwnd, node, str); // C2021-026 Parent/Child Field has no value so use parent's value
else
{
hwnd.Text = nd.InnerText; // set the field's text from XML
@@ -504,8 +545,8 @@ namespace ctlXMLEditLib
{
// if MaxWidth is small, a scroll bar appears below the fields
// so make this a bit larger, so a scroll bar doesn't appear
if (MaxWidth<30) return MaxWidth+60;
return MaxWidth+30;
if (MaxWidth < 30) return MaxWidth + 100;
return MaxWidth + 70;
}
public int GetMaxLength()
{
@@ -569,11 +610,46 @@ namespace ctlXMLEditLib
editelem.InnerXml = savedInnerXml;
}
//C2021-026 when saving the RO record, if a PC Child's textbox contains a value identical
// to the parent's value, then clear the child's textbox so that nothing is saved
// to the database. This allow us to know that a specific value was not set
// for this Parent/Child child
private void RemovePCChildTextIfSameAsParent(XmlNode node, TextBox tb, string chldName)
{
XmlNode parentNode = null;
// if this is a child node get the parent's value
// PCChildren contains a list strings reprenting the Children setup in the current Working Draft Parent/Child property
if (PCChildren == null) return;
int pcChildIdx = 0;
foreach (string c in PCChildren)
{
//string csufx = CvtUserFldToFld(c);
pcChildIdx++;
string csufx = string.Format("_PCCHILD{0}", pcChildIdx);
if (chldName.EndsWith(csufx))
{
int idx = chldName.LastIndexOf(csufx);
if (idx > 0)
{
string parent = chldName.Remove(idx);
parentNode = node.SelectSingleNode(parent);
// if not found with just the string, search the tree.
if (parentNode == null) parentNode = node.SelectSingleNode("*/" + parent);
if (parentNode != null && parentNode.InnerText == tb.Text)
{
tb.Text = "";
break;
}
}
}
}
}
// SaveData saves the data in the element which had been sent to the control. Return
// true if success, false if fail.
// Note that the Parent and Child XML node variables below are not coding for Parent/Child Applicabily Fields
public bool SaveData()
{
if (mysavexml)
{
TextBox hwnd;
@@ -586,7 +662,6 @@ namespace ctlXMLEditLib
object o = myHT[str];
hwnd = (TextBox) o;
imgdate = null;
// if this is a required field and there is no text, put out an error
// message and get out of here.
if (hwnd.Tag != null)
@@ -602,7 +677,6 @@ namespace ctlXMLEditLib
return (false);
}
imgdate = tag.GetImageDate;
}
// find the element in the current element node.
@@ -612,7 +686,7 @@ namespace ctlXMLEditLib
XmlNode elmnode = (XmlNode) editelem;
XmlNode nd = elmnode.SelectSingleNode(str);
if (nd == null) nd = elmnode.SelectSingleNode("*/"+str);
RemovePCChildTextIfSameAsParent(elmnode, hwnd, str); // C2021-026 will clear hwnd.Text if child value is same as parent value
// handle, element exists - but text removed first (delete element)
if ((hwnd.Text == null || hwnd.Text == "") && nd != null)
{
@@ -694,6 +768,7 @@ namespace ctlXMLEditLib
}
}
mysavexml=false; // data has been saved, don't allow it again.
DisplayFieldContents((XmlNode) editelem); // to refresh display after saving Parent/Child fields to show default values
return(true);
}
return (false);
@@ -783,7 +858,8 @@ namespace ctlXMLEditLib
{
XmlSchemaDocumentation doc = (XmlSchemaDocumentation) item;
XmlNode[] node = (XmlNode[]) doc.Markup;
// Note: this has nothing to do with PROMS Annotations. This is more of a field type description
// used for Graphics (figures) RO fields to setup event handlers and buttons to display a Find File Dialog
getannot = node[0].InnerText;
if (getannot == "VLN_FINDFILE")
{
@@ -894,7 +970,6 @@ namespace ctlXMLEditLib
else
tmp = element.SchemaTypeName.Name;
radio.Text = CvtFldToUserFld(tmp);
//radio.Width = (int) radio.Font.SizeInPoints * radio.Text.Length + 20; // add 20 for button
radio.TabIndex = 0;
ysize = (int) radio.Height;
@@ -916,8 +991,20 @@ namespace ctlXMLEditLib
tb.KeyDown += new KeyEventHandler(MyOnKeyDown);
gbox.Contains(tb);
// the following will set attributes on the text boxes such as maxlength, multiline, etc.
DisplayXmlSchemaSimpleType((XmlSchemaSimpleType)element.SchemaType, tb, radio,false,null);
rety = (ysize + 25 + tb.Height);
DisplayXmlSchemaSimpleType((XmlSchemaSimpleType)element.SchemaType, tb, radio,false,null);
int chldGrpHeight = 0;
if (FieldsWithApplic != null && FieldsWithApplic.Contains(gbox.Text) && radio.Text == "Fixed") // C2021-026 user turned appicability on for this field
{
int saveScreeny = screeny;
int saveScreenx = screenx;
screeny += tb.Height + 50;
screenx += 20;
pcGrpBox = null; // C2021-026 used to hide/show Parent/Child group when radio buttons are selected
DisplayAppicChildrenGroup(element, PCChildren, ref chldGrpHeight, gbox.Text); // C2021-026 make sub-group for Parent/Child child fields (if needed)
screeny = saveScreeny;
screenx = saveScreenx;
}
rety = (ysize + 25 + chldGrpHeight + tb.Height);
retx = tb.Width;
}
@@ -956,25 +1043,84 @@ namespace ctlXMLEditLib
// get the widths of all children of this group box & use this to set the size
// of the groupbox.
int gritms = groupbox.Controls.Count;
screeny=screeny+maxyfortext+10;
screeny = screeny + maxyfortext + 20;
MaxWidth = (maxxfortext+40>MaxWidth)?maxxfortext+40:MaxWidth;
groupbox.Size = new System.Drawing.Size(maxxfortext+40, maxyfortext+10);
Controls.Add(groupbox);
}
private void DisplayXmlSchemaElement(XmlSchemaElement element)
{
string userfldName = CvtFldToUserFld(element.Name);
string childLabel = "";
bool pcApplic = FieldsWithApplic != null && FieldsWithApplic.Contains(userfldName); // C2021-026 returns True if field should show Parent/Child Applicability fields
if (pcApplic) childLabel = CvtFldToUserFld(element.Name);
int dmy = 0;
DoDisplayXmlSchemaElement(element, childLabel, 0, ref dmy, Color.Transparent, 0);
if (pcApplic)
{
// C2021-026 this will create a grouping containing Parent/Child Applicability fields
DisplayAppicChildrenGroup(element, PCChildren, ref dmy, null);
screeny += 10;
}
}
// C2021-026 Creates a group box containing Parent/Child Applicability fields
// the group box is indented and shaded a blue color
private void DisplayAppicChildrenGroup(XmlSchemaElement element, string [] PCChildren, ref int chldgrphgt, string altGrpName)
{
int screenposx, screenposy;
int savescreenX = screenx;
screenx += 20;
GroupBox groupbox = new GroupBox();
groupbox.BackColor = Color.AliceBlue;
groupbox.SuspendLayout();
groupbox.Location = new System.Drawing.Point(screenx, screeny);
groupbox.Name = "PCgb_" + element.Name;
groupbox.TabStop = false;
// remove the last character of the name for the title of the group box.
string tstr = (altGrpName == null)?CvtFldToUserFld(element.Name):altGrpName;//(elem.Name);
groupbox.Text = "Child Values";
screenposx = screenx + 20;
screenposy = screeny + 20;
int screenySave = screeny;
screeny += 20;
int maxChldWidth = 0;
int pcChildIdx = 0;
foreach (string s in PCChildren)
{
string childLabel = s;
pcChildIdx++;
DoDisplayXmlSchemaElement(element, childLabel, 20, ref maxChldWidth,Color.AliceBlue, pcChildIdx);
}
// get the widths and number of all children of this group box & use this to set the size
// of the groupbox.
groupbox.Size = new System.Drawing.Size(Math.Max(55,maxChldWidth + 40), screeny - screenySave + 5);//maxxfortext + 40, maxyfortext + 10);
chldgrphgt = screeny - screenySave + 5;
Controls.Add(groupbox);
if (pcGrpBox == null)
pcGrpBox = groupbox; // only save if is in a Choice (radio button) group - used to hide/unhide the P/C Group box when radio buttons are selected
screenx = savescreenX;
}
private void DoDisplayXmlSchemaElement(XmlSchemaElement element, string applicLabel, int indent, ref int maxwidth, Color chlbckcolor, int pcChildIdx)
{
// always add a label.
Label mylabel;
int sscreeny;
mylabel = new System.Windows.Forms.Label();
mylabel.Location = new Point(screenx, screeny);
mylabel.Name = element.Name;
mylabel.Text = CvtFldToUserFld(element.Name);
string userfldName = CvtFldToUserFld(element.Name);
string pcChildFldName = element.Name; // C2021-026 PC Child field name
// C2021-026 the first PC Child has pcChildIdx of one
if (pcChildIdx > 0)
pcChildFldName += string.Format("_PCCHILD{0}", pcChildIdx);
Label mylabel;
mylabel = new System.Windows.Forms.Label();
mylabel.BackColor = chlbckcolor; // PC Applic fields are shaded blue otherwise backcolor is transparent
mylabel.Location = new Point(screenx+indent, screeny);
mylabel.Name = (pcChildIdx == 0) ? CvtUserFldToFld(element.Name) : CvtUserFldToFld(pcChildFldName);
mylabel.Text = (applicLabel.Length > 0) ? applicLabel : CvtFldToUserFld(element.Name); // C2021-026 applicLabel is the P/C Child name
mylabel.AutoSize = true;
Controls.Add(mylabel);
// add 3 onto screeny so that textbox is slightly below label.
screeny = screeny+mylabel.Height+3;
screeny = screeny + mylabel.Height + 3;
sscreeny = screeny; // save 'y' location in case of annotation.
if (element.SchemaType != null && element.SchemaType is XmlSchemaComplexType)
{
@@ -986,23 +1132,34 @@ namespace ctlXMLEditLib
{
TextBox mytextbox;
mytextbox = new TextBox();
mytextbox.Location = new Point(screenx, screeny);
myHT.Add(element.Name,mytextbox);
mytextbox.Location = new Point(screenx+indent, screeny);
string tFieldName = (pcChildIdx == 0) ? CvtUserFldToFld(element.Name) : CvtUserFldToFld(pcChildFldName);
myHT.Add(tFieldName, mytextbox);
tabindx++;
Controls.Add(mytextbox);
screeny+=mytextbox.Height;
screeny = screeny + 10;
mytextbox.TextChanged += new System.EventHandler(this.textbox_change);
mytextbox.Validating += new System.ComponentModel.CancelEventHandler(this.textbox_Validating);
mytextbox.GotFocus += new System.EventHandler(this.textbox_zoombtn);
mytextbox.KeyDown += new KeyEventHandler(MyOnKeyDown);
if (pcChildIdx > 0)
{
mytextbox.Enter += new System.EventHandler(this.txtBox_Enter);
mytextbox.Leave += new System.EventHandler(this.txtBox_Leave);
}
string labelAnnot;
bool imgchld = false;
if (element.Name == "Image_Filename" || element.Name == "Image_Height" || element.Name == "Image_Width") imgchld = true;
// Pass the textbox in to set attributes such as maxlength, multiline and pattern
// DisplayXmlSchemaSimpleType will set up
// - the textbox length which is needed to determin the Parent/Child group box width
// - add special buttons and events for Graphic (figure) RO type fields
labelAnnot = DisplayXmlSchemaSimpleType((XmlSchemaSimpleType)element.SchemaType,mytextbox, null,imgchld,GraphicsText);
if (labelAnnot != null)
{
// this is part of a Graphics (figure) RO - either the height or width adjustment text box
// so put a lable next to the respective height/width text box
Label annot;
annot = new System.Windows.Forms.Label();
annot.Location = new Point(screenx+mytextbox.Width+10, sscreeny);
@@ -1011,7 +1168,9 @@ namespace ctlXMLEditLib
annot.AutoSize = true;
Controls.Add(annot);
}
screeny+=mytextbox.Height;
screeny += mytextbox.Height;
maxwidth = Math.Max(maxwidth, mylabel.Width); // is the label wider?
maxwidth = Math.Max(mytextbox.Width, maxwidth); // is the text box wider?
}
}
@@ -1028,6 +1187,37 @@ namespace ctlXMLEditLib
{
if(dosaveflag)mysavexml = true;
}
// C2021-026 Event handler for Parent/Child child textbox
// if the textbox text is same as parent, then or nothing is entered in the textbox
// then use the parent value and set the text color to gray
private void txtBox_Leave(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
string dfTxt = "";
string parName = pcGrpBox.Name.Substring(5);
object o = myHT[parName];
if (o != null)
dfTxt = (o as TextBox).Text; // set to use the parent's value (default)
if (dosaveflag) mysavexml = true;
if (tb.Text.Length == 0 || tb.Text == dfTxt)
{
tb.Text = dfTxt;
tb.ForeColor = SystemColors.GrayText;
}
}
// C2021-026 Event handler for Parent/Child child textbox
// If the textbox is set to gray, then we are using the parent value
// so clear the textbox so that user can enter the value for that child
private void txtBox_Enter(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
if (tb.ForeColor == SystemColors.GrayText) // currently no value set - using parent's value
{
tb.Text = "";
tb.ForeColor = SystemColors.WindowText;
}
}
// radiocheckchg - called when a radio button is selected. This will set
// visibility for associated text box.
@@ -1050,6 +1240,30 @@ namespace ctlXMLEditLib
assocbox = (TextBox) o;
// make the text box visible if checked, otherwise, invisible
assocbox.Visible = btnsel.Checked;
// C2021-026 show or hide the Parent/Child appicability group box
if (pcGrpBox != null) // note that we save only one applicability group box and only for the schema choice field type (radio buttons)
{
bool vsblState = (btnsel.Text == "Fixed"); // only show parent/child group if the Fixed radio button is selected
{
pcGrpBox.Visible = vsblState; // show or hide the P/C Children group box (the box shaded in blue)
// C2021-026 PCChildren contains a list strings reprenting the Children setup in the current Working Draft Parent/Child property
int pcChildIdx = 0;
foreach (string s in PCChildren)
{
pcChildIdx++;
string fldx = string.Format("_PCCHILD{0}", pcChildIdx); // create a field name for P/C Child fields
string tstr = pcGrpBox.Name.Substring(5) + fldx; // get the base part of the label and text box control name
foreach (Control c in Controls)
if (c.Name == tstr)
{
c.Visible = vsblState; // show or hide the lable inside the group box
object oo = myHT[c.Name];
if (oo != null)
(oo as TextBox).Visible = vsblState; // show or hide the associated text box
}
}
}
}
}
// these two methods convert user input field names from/to xml tags. (xml tags