Exemplo n.º 1
0
        /// <summary>
        /// process a tab page
        /// </summary>
        /// <param name="curNode"></param>
        /// <returns></returns>
        public Boolean AddTabPage(XmlNode curNode)
        {
            // name of tabpage
            TControlDef tabPage = FCodeStorage.AddControl(curNode);

            tabPage.parentName = FCodeStorage.GetRootControl("tab").controlName;
            curNode            = TXMLParser.NextNotBlank(curNode.FirstChild);

            if (curNode != null)
            {
                if (curNode.Name == "Controls")
                {
                    // one control per row, align labels
                    StringCollection controls = TYml2Xml.GetElements(curNode);

                    foreach (string ctrlName in controls)
                    {
                        TControlDef ctrl = FCodeStorage.GetControl(ctrlName);

                        if (ctrl != null)
                        {
                            ctrl.parentName = tabPage.controlName;
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 2
0
 /// <summary>
 /// check if the control has an attribute with the property name in the xml definition
 /// if such an attribute exists, then set it
 /// </summary>
 /// <param name="ACtrl"></param>
 /// <param name="APropertyName"></param>
 public virtual void SetControlProperty(TControlDef ACtrl, string APropertyName)
 {
     if (TYml2Xml.HasAttribute(ACtrl.xmlNode, APropertyName))
     {
         SetControlProperty(ACtrl, APropertyName, TYml2Xml.GetAttribute(ACtrl.xmlNode, APropertyName));
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// which node does this control belong to?
        /// </summary>
        /// <param name="AControlName"></param>
        /// <param name="AParentName"></param>
        /// <returns></returns>
        public XmlNode GetCorrectCollection(string AControlName, string AParentName)
        {
            string  prefix         = TControlDef.GetLowerCasePrefix(AControlName);
            XmlNode collectionNode = (XmlNode)FXmlNodes["Controls"];

            if (prefix == "mni")
            {
                collectionNode = (XmlNode)FXmlNodes["Menu"];

                // submenus
                if (AParentName.Length > 0)
                {
                    collectionNode = (XmlNode)FXmlNodes[AParentName];
                }
            }
            else if ((prefix == "tbb") || (prefix == "tbc") || (prefix == "tch"))
            {
                collectionNode = (XmlNode)FXmlNodes["Toolbar"];
            }
            else if (prefix == "tpg")
            {
                collectionNode = ((XmlNode)FXmlNodes["Layout"])["Tabs"];
            }

            return(collectionNode);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Determines whether automatic Data Validation code should be created for a certain Control in a YAML file.
        /// </summary>
        /// <param name="AControl">Control in YAML file.</param>
        /// <param name="AHasDataField"></param>
        /// <param name="AMasterOrDetailTable">Pass in 'true' if the YAML file has got a 'MasterTable' or 'DetailTable' Element. </param>
        /// <param name="AIncludeMasterOrDetailTableControl"></param>
        /// <param name="AScope">Scope of the Data Validation that should be checked for. Specify <see cref="TAutomDataValidationScope.advsAll"/>
        /// to find out if any of the scopes should be checked against, or use any other value of that enum to specifiy a specific scope.</param>
        /// <param name="AReasonForAutomValidation">Contains the reason why automatic data validation code needs to be generated.</param>
        /// <returns>True if automatic Data Validation code should be created for the Control in a YAML that was passed in in <paramref name="AControl" /> for
        /// the scope that was specified with <paramref name="AScope" />, otherwise false. This Method also returns false if the Control specified in
        /// <paramref name="AControl" /> isn't linked to a DB Table Field.</returns>
        public static bool GenerateAutoValidationCodeForControl(TControlDef AControl, bool AHasDataField, bool AMasterOrDetailTable,
                                                                bool AIncludeMasterOrDetailTableControl, TAutomDataValidationScope AScope, out string AReasonForAutomValidation)
        {
            TTableField DBField = null;
            bool        IsDetailNotMaster;

            AReasonForAutomValidation = String.Empty;

            if (AHasDataField)
            {
                DBField = TDataBinding.GetTableField(AControl, AControl.GetAttribute("DataField"), out IsDetailNotMaster, true);
            }
            else if (AMasterOrDetailTable && AIncludeMasterOrDetailTableControl)
            {
                DBField = TDataBinding.GetTableField(AControl, AControl.controlName.Substring(
                                                         AControl.controlTypePrefix.Length), out IsDetailNotMaster, false);
            }

            if (DBField != null)
            {
                return(GenerateAutoValidationCodeForDBTableField(DBField, AScope, null, out AReasonForAutomValidation));
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// get the definition of the control, if it has not been loaded yet from yaml then do it now
        /// </summary>
        /// <param name="AControlName"></param>
        /// <param name="AParentName"></param>
        /// <returns></returns>
        public TControlDef FindOrCreateControl(string AControlName, string AParentName)
        {
            TControlDef result = GetControl(AControlName);

            if (result != null)
            {
                // or should we throw an exception?
                return(result);
            }

            if (AControlName == "pnlEmpty")
            {
                int countEmpty = 1;

                foreach (string name in FControlList.Keys)
                {
                    if (name.StartsWith("pnlEmpty"))
                    {
                        countEmpty++;
                    }
                }

                AControlName += countEmpty.ToString();
            }

            XmlNode collectionNode = GetCorrectCollection(AControlName, AParentName);

            XmlElement newNode = FXmlDocument.CreateElement(AControlName);

            collectionNode.AppendChild(newNode);
            FXmlNodes.Add(AControlName, newNode);
            result            = new TControlDef(newNode, this);
            result.parentName = AParentName;
            FControlList.Add(AControlName, result);
            FSortedControlList.Add(FSortedControlList.Count, result);
            TControlDef parentCtrl = GetControl(AParentName);

            if ((parentCtrl != null) && !AControlName.StartsWith("pnlEmpty"))
            {
                XmlNode parentNode = parentCtrl.xmlNode;
                XmlNode controls   = TXMLParser.GetChild(parentNode, "Controls");

                if (controls == null)
                {
                    controls = FXmlDocument.CreateElement("Controls");
                    parentNode.AppendChild(controls);
                }

                XmlNode      element = FXmlDocument.CreateElement(TYml2Xml.XMLLIST);
                XmlAttribute attr    = FXmlDocument.CreateAttribute("name");
                attr.Value = AControlName;
                element.Attributes.Append(attr);
                controls.AppendChild(element);
            }

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// load the toolbar
        /// </summary>
        /// <param name="parentName"></param>
        /// <param name="curNode"></param>
        /// <returns></returns>
        public Boolean LoadToolbar(string parentName,
                                   XmlNode curNode)
        {
            List <XmlNode> children = TYml2Xml.GetChildren(curNode, true);

            XmlNode rootBarNode = FCodeStorage.GetRootControl("tbr").xmlNode;

            foreach (XmlNode childNode in children)
            {
                // the check for tbb works around problems with elements list, shortcutkeys
                if (childNode.Name.StartsWith("tbb") || childNode.Name.StartsWith("tbc"))
                {
                    string tbbName = childNode.Name;

                    if (tbbName == "tbbSeparator")
                    {
                        // UniqueName is not stored to yml again; just used temporary
                        TYml2Xml.SetAttribute(childNode, "UniqueName", tbbName + FToolbarSeparatorCount.ToString());
                        FToolbarSeparatorCount++;
                    }

                    TControlDef tbbItem = FCodeStorage.AddControl(childNode);
                    tbbItem.parentName = parentName;

                    rootBarNode.AppendChild(childNode);
                }
                else
                {
                    // use ToolStripControlHost to host any control
                    TControlDef tbbItem = FCodeStorage.AddControl(childNode);
                    string      prefix  = TControlDef.GetLowerCasePrefix(childNode.Name);
                    tbbItem.parentName = "tch" + childNode.Name.Substring(prefix.Length);

                    XmlNode controlHostNode = rootBarNode.OwnerDocument.CreateElement(tbbItem.parentName);
                    TYml2Xml.SetAttribute(controlHostNode, "depth", TYml2Xml.GetAttribute(childNode, "depth"));
                    TYml2Xml.SetAttribute(controlHostNode, "HostedControl", childNode.Name);
                    rootBarNode.AppendChild(controlHostNode);

                    XmlNode controlsNode = rootBarNode.OwnerDocument.CreateElement("Controls");
                    controlHostNode.AppendChild(controlsNode);
                    XmlNode elementNode = rootBarNode.OwnerDocument.CreateElement("Element");
                    controlsNode.AppendChild(elementNode);
                    TYml2Xml.SetAttribute(elementNode, "name", childNode.Name);

                    TControlDef hostItem = FCodeStorage.AddControl(controlHostNode);
                    hostItem.parentName = parentName;
                }
            }

            return(true);
        }
Exemplo n.º 7
0
        /// <summary>
        /// get all controls that have parentName set to the given parent control
        /// </summary>
        /// <param name="AParent"></param>
        /// <returns></returns>
        public List <TControlDef> GetChildren(TControlDef AParent)
        {
            List <TControlDef> result = new List <TControlDef>();

            foreach (TControlDef item in this.FSortedControlList.Values)
            {
                if (item.parentName == AParent.controlName)
                {
                    result.Add(item);
                }
            }

            return(result);
        }
Exemplo n.º 8
0
        /// <summary>
        /// get the main menustrip, tabpage, statusstrip etc;
        /// if prefix is content, the first available pnl, uco, tpg or grp control is returned;
        /// the first control can be overwritten with attribute RootControl=true; this is necessary for the reports, see tabReportSettings
        /// </summary>
        /// <param name="APrefix">can be mnu, tab, tbr, sbt, stb, content</param>
        /// <param name="AThrowException">if there is no root control, throw an exception</param>
        /// <returns></returns>
        public TControlDef GetRootControl(string APrefix, bool AThrowException)
        {
            TControlDef firstControl = null;

            foreach (TControlDef ctrl in FSortedControlList.Values)
            {
                if (ctrl.controlTypePrefix == APrefix)
                {
                    if (firstControl == null)
                    {
                        firstControl = ctrl;
                    }

                    if (ctrl.HasAttribute("RootControl") && (ctrl.GetAttribute("RootControl").ToLower() == "true"))
                    {
                        return(ctrl);
                    }
                }

                if ((APrefix == "content") &&
                    ((ctrl.controlTypePrefix == "tab") ||
                     (ctrl.controlTypePrefix == "grp") ||
                     (ctrl.controlTypePrefix == "uco") ||
                     (ctrl.controlTypePrefix == "pnl")))
                {
                    if (firstControl == null)
                    {
                        firstControl = ctrl;
                    }

                    if (ctrl.HasAttribute("RootControl") && (ctrl.GetAttribute("RootControl").ToLower() == "true"))
                    {
                        return(ctrl);
                    }
                }
            }

            if (firstControl != null)
            {
                return(firstControl);
            }

            if (AThrowException)
            {
                throw new Exception("cannot find a default control for prefix " + APrefix);
            }

            return(null);
        }
Exemplo n.º 9
0
        /// <summary>
        /// load the menu
        /// </summary>
        /// <param name="parentName"></param>
        /// <param name="curNode"></param>
        /// <returns></returns>
        public Boolean LoadMenu(string parentName,
                                XmlNode curNode)
        {
            string menuName = curNode.Name;

            if (menuName == "mniSeparator")
            {
                // UniqueName is not stored to yml again; just used temporary
                TYml2Xml.SetAttribute(curNode, "UniqueName", menuName + FMenuSeparatorCount.ToString());
                FMenuSeparatorCount++;
            }

            if (curNode.ParentNode.Name == TParseYAMLFormsDefinition.ROOTNODEYML)
            {
                // add each menu, but obviously not the "Menu" tag
                XmlNode        menuNode = curNode;
                List <XmlNode> children = TYml2Xml.GetChildren(menuNode, true);

                foreach (XmlNode childNode in children)
                {
                    LoadMenu(parentName, childNode);

                    // attach the menu to the appropriate root control
                    XmlNode rootMenu = FCodeStorage.GetRootControl("mnu").xmlNode;
                    rootMenu.AppendChild(childNode);
                }

                return(true);
            }

            TControlDef menuItem = FCodeStorage.AddControl(curNode);

            menuItem.parentName = parentName;
            List <XmlNode> children2 = TYml2Xml.GetChildren(curNode, true);

            foreach (XmlNode childNode in children2)
            {
                // the check for mni works around problems with elements list, shortcutkeys
                if (childNode.Name.StartsWith("mni"))
                {
                    LoadMenu(menuName, childNode);
                }
            }

            return(true);
        }
Exemplo n.º 10
0
        /// <summary>
        /// get the correct control generator for the control, depending on the prefix of the name, and other parameters
        /// </summary>
        /// <param name="ACtrlDef"></param>
        /// <returns></returns>
        public IControlGenerator FindControlGenerator(TControlDef ACtrlDef)
        {
            IControlGenerator fittingGenerator = null;

            if (ACtrlDef.controlGenerator != null)
            {
                return(ACtrlDef.controlGenerator);
            }

            foreach (IControlGenerator generator in AvailableControlGenerators)
            {
                if (generator.ControlFitsNode(ACtrlDef.xmlNode))
                {
                    if (fittingGenerator != null)
                    {
                        throw new Exception(
                                  "Error: control with name " + ACtrlDef.xmlNode.Name + " does fit both control generators " +
                                  fittingGenerator.ControlType +
                                  " and " +
                                  generator.ControlType);
                    }

                    fittingGenerator = generator;
                }
            }

            if ((fittingGenerator == null) &&
                (!ACtrlDef.controlName.StartsWith("Empty")))
            {
                if (TYml2Xml.HasAttribute(ACtrlDef.xmlNode, "Type") && (FBaseControlGeneratorType != null))
                {
                    return((IControlGenerator)Activator.CreateInstance(FBaseControlGeneratorType, new Object[] { ACtrlDef.xmlNode.Name.Substring(0,
                                                                                                                                                 3),
                                                                                                                 TYml2Xml.GetAttribute(ACtrlDef.
                                                                                                                                       xmlNode, "Type") }));
                }

                throw new Exception("Error: cannot find a generator for control with name " + ACtrlDef.xmlNode.Name);
            }

            ACtrlDef.controlGenerator = fittingGenerator;

            return(fittingGenerator);
        }
Exemplo n.º 11
0
        /// only to be called by TParseXAML when loading the controls from the file
        /// don't call this for creating new nodes; use FindOrCreateControl instead
        public TControlDef AddControl(XmlNode AParsedNode)
        {
            if (AParsedNode.Name == "base")
            {
                throw new Exception("should not parse the 'base' node this way");
            }

            string parsedNodeName = AParsedNode.Name;

            if (TYml2Xml.HasAttribute(AParsedNode, "UniqueName"))
            {
                parsedNodeName = TYml2Xml.GetAttribute(AParsedNode, "UniqueName");
            }

            TControlDef result = GetControl(parsedNodeName);

            if (result != null)
            {
                // this node already existed in a base yaml and is now being overwritten

                // this should never happen
                string  nameDetails = AParsedNode.Name;
                XmlNode parentNode  = AParsedNode.ParentNode;

                while ((parentNode != null) && (parentNode.Name != "AutoConvertedYML2XML"))
                {
                    nameDetails = parentNode.Name + "." + nameDetails;
                    parentNode  = parentNode.ParentNode;
                }

                throw new Exception("please use FindOrCreateControl(XmlNode) only when loading from the XAML file (" +
                                    nameDetails + ")");
            }

            result = new TControlDef(AParsedNode, this);
            FControlList.Add(parsedNodeName, result);
            FSortedControlList.Add(FSortedControlList.Count, result);
            return(result);
        }
Exemplo n.º 12
0
 /// <summary>
 /// for special functionality specific to a control
 /// </summary>
 public virtual void ApplyDerivedFunctionality(IControlGenerator generator, TControlDef control)
 {
     generator.ApplyDerivedFunctionality(this, control);
 }
Exemplo n.º 13
0
 /// <summary>set the property of a control</summary>
 public void SetControlProperty(TControlDef ACtrl, string APropertyName, string APropertyValue)
 {
     SetControlProperty(ACtrl.controlName, APropertyName, APropertyValue, !(ACtrl.GetAttribute("VariableLabelText") == "true"));
 }
Exemplo n.º 14
0
        /// <summary>
        /// resolve a reference to a field in the database;
        /// support master and detail tables
        /// </summary>
        /// <param name="ACtrl"></param>
        /// <param name="ADataField">string with potential reference to data field</param>
        /// <param name="AIsDetailNotMaster">returns if this is a field in the master or in the detail table</param>
        /// <param name="AShowWarningNonExistingField">fail on non existing field</param>
        /// <returns>reference to the table field, or null</returns>
        public static TTableField GetTableField(TControlDef ACtrl,
                                                string ADataField,
                                                out bool AIsDetailNotMaster,
                                                bool AShowWarningNonExistingField)
        {
            string tablename = "";
            string fieldname = "";

            // is there an explicit specification for which datafield to use
            if (ADataField.IndexOf(".") > 0)
            {
                tablename = ADataField.Split('.')[0];
                fieldname = ADataField.Split('.')[1];
            }
            else
            {
                if (ACtrl != null)
                {
                    if (ACtrl.HasAttribute("Unbound") && (ACtrl.GetAttribute("Unbound").ToLower() == "true"))
                    {
                        AIsDetailNotMaster = false;
                        return(null);
                    }

                    if (ADataField.Length == 0)
                    {
                        ADataField = ACtrl.controlName.Substring(ACtrl.controlTypePrefix.Length);
                    }

                    if (ADataField.StartsWith("Detail"))
                    {
                        fieldname = ADataField;

                        if (fieldname.StartsWith("Detail"))
                        {
                            fieldname = fieldname.Substring("Detail".Length);
                        }

                        tablename = FCodeStorage.GetAttribute("DetailTable");
                    }
                    else
                    {
                        // check for other tables in the typed Dataset
                        if (FCurrentDataset != null)
                        {
                            // ADataField can either contain just the field, or the table name and the field

                            // does ADataField start with a table name?
                            foreach (TTable table2 in FCurrentDataset.Values)
                            {
                                if (ADataField.StartsWith(table2.strDotNetName) || ADataField.StartsWith(TTable.NiceTableName(table2.strName)))
                                {
                                    if (ADataField.StartsWith(table2.strDotNetName))
                                    {
                                        tablename = table2.strDotNetName;
                                    }
                                    else
                                    {
                                        tablename = TTable.NiceTableName(table2.strName);
                                    }

                                    foreach (TTableField field in table2.grpTableField)
                                    {
                                        if (TTable.NiceFieldName(field.strName) == ADataField.Substring(tablename.Length))
                                        {
                                            fieldname = TTable.NiceFieldName(field.strName);
                                        }

                                        if (field.strNameDotNet == ADataField.Substring(tablename.Length))
                                        {
                                            fieldname = field.strNameDotNet;
                                        }
                                    }
                                }
                            }

                            // check if the master table has such a field
                            if ((fieldname.Length == 0) && FCodeStorage.HasAttribute("MasterTable"))
                            {
                                TTable table2 = FCurrentDataset[FCodeStorage.GetAttribute("MasterTable")];

                                foreach (TTableField field in table2.grpTableField)
                                {
                                    if ((TTable.NiceFieldName(field.strName) == ADataField) || (field.strNameDotNet == ADataField))
                                    {
                                        tablename = FCodeStorage.GetAttribute("MasterTable");
                                        fieldname = ADataField;
                                    }
                                }
                            }

                            // check if the detail table has such a field
                            if ((fieldname.Length == 0) && FCodeStorage.HasAttribute("DetailTable"))
                            {
                                if ((FCurrentDataset != null) && FCurrentDataset.ContainsKey(FCodeStorage.GetAttribute("DetailTable")))
                                {
                                    TTable table2 = FCurrentDataset[FCodeStorage.GetAttribute("DetailTable")];

                                    foreach (TTableField field in table2.grpTableField)
                                    {
                                        if ((TTable.NiceFieldName(field.strName) == ADataField) || (field.strNameDotNet == ADataField))
                                        {
                                            tablename = FCodeStorage.GetAttribute("DetailTable");
                                            fieldname = ADataField;
                                        }
                                    }
                                }
                            }

                            // check if there is a unique match for this control name in all the tables
                            if (fieldname.Length == 0)
                            {
                                foreach (TTable table2 in FCurrentDataset.Values)
                                {
                                    foreach (TTableField field in table2.grpTableField)
                                    {
                                        if ((TTable.NiceFieldName(field.strName) == ADataField) || (field.strNameDotNet == ADataField))
                                        {
                                            if (fieldname.Length > 0)
                                            {
                                                throw new Exception(
                                                          String.Format("there are a several tables with field {0}: {1} and {2}",
                                                                        fieldname, tablename, table2.strDotNetName));
                                            }

                                            if ((table2.strDotNetName != null) && (table2.strDotNetName.Length > 0))
                                            {
                                                tablename = table2.strDotNetName;
                                            }
                                            else
                                            {
                                                tablename = TTable.NiceTableName(table2.strName);
                                            }

                                            if ((field.strNameDotNet != null) && (field.strNameDotNet.Length > 0))
                                            {
                                                fieldname = field.strNameDotNet;
                                            }
                                            else
                                            {
                                                fieldname = TTable.NiceFieldName(field.strName);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            tablename = FCodeStorage.GetAttribute("MasterTable");
                            fieldname = ADataField;
                        }
                    }
                }
                else
                {
                    // eg used for columns in datagrid
                    if (ADataField.StartsWith("Detail"))
                    {
                        tablename = FCodeStorage.GetAttribute("DetailTable");
                        fieldname = ADataField.Substring("Detail".Length);
                    }
                    else
                    {
                        tablename = FCodeStorage.GetAttribute("MasterTable");
                        fieldname = ADataField;
                    }
                }
            }

            AIsDetailNotMaster = FCodeStorage.GetAttribute("DetailTable") == tablename;

            if (tablename.Length == 0)
            {
                // this is probably no data field at all
                if (AShowWarningNonExistingField)
                {
                    Console.WriteLine("Warning: Expected data field but cannot resolve " + ADataField);
                }

                return(null);
            }

            TTable table = null;

            if ((FCurrentDataset != null) && FCurrentDataset.ContainsKey(tablename))
            {
                table = FCurrentDataset[tablename];
            }
            else
            {
                table = FPetraXMLStore.GetTable(tablename);
            }

            if (table == null)
            {
                if (!AShowWarningNonExistingField)
                {
                    return(null);
                }

                throw new Exception("Cannot find table: " + tablename);
            }

            return(table.GetField(fieldname, AShowWarningNonExistingField));
        }