Exemplo n.º 1
0
 /// <summary>
 /// declare the control
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="ctrl"></param>
 public override void GenerateDeclaration(TFormWriter writer, TControlDef ctrl)
 {
     if (!IsMniFilterFindClickAndIgnore(writer, ctrl, false))
     {
         base.GenerateDeclaration(writer, ctrl);
     }
 }
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            // don't call base, because it should not have size, location, or name
            writer.Template.AddToCodelet("CONTROLINITIALISATION",
                "//" + Environment.NewLine + "// " + ctrl.controlName + Environment.NewLine + "//" + Environment.NewLine);

            return writer.FTemplate;
        }
Exemplo n.º 3
0
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            // TODO this does not work yet. see EventRole Maintain screen
            if ((!ctrl.HasAttribute("Align"))
                && (!ctrl.HasAttribute("Width")))
            {
                ctrl.SetAttribute("Stretch", "horizontally");
            }

            base.SetControlProperties(writer, ctrl);

            // stretch at design time, but do not align to the right
            writer.SetControlProperty(ctrl, "Anchor",
                "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)))");

            string labelText = "";

            if (TYml2Xml.HasAttribute(ctrl.xmlNode, "Text"))
            {
                labelText = TYml2Xml.GetAttribute(ctrl.xmlNode, "Text");
            }
            else
            {
                labelText = ctrl.Label + ":";
            }

            if (ctrl.HasAttribute("Width"))
            {
                ctrl.SetAttribute("Width", ctrl.GetAttribute("Width"));
            }
            else
            {
                ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(labelText) + 5).ToString());
            }

            if (ctrl.HasAttribute("Height"))
            {
                ctrl.SetAttribute("Height", ctrl.GetAttribute("Height"));
            }

            writer.SetControlProperty(ctrl, "Text", "\"" + labelText + "\"");
            writer.SetControlProperty(ctrl, "Padding", "new System.Windows.Forms.Padding(0, 5, 0, 0)");

            if (FRightAlign)
            {
                writer.SetControlProperty(ctrl, "TextAlign", "System.Drawing.ContentAlignment.TopRight");
            }

            return writer.FTemplate;
        }
Exemplo n.º 4
0
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            ProcessTemplate snippetRowDefinition = writer.FTemplate.GetSnippet(FControlDefinitionSnippetName);

            ((TExtJsFormsWriter)writer).AddResourceString(snippetRowDefinition, "LABEL", ctrl, ctrl.Label);

            StringCollection Controls = FindContainedControls(writer, ctrl.xmlNode);

            snippetRowDefinition.AddToCodelet("ITEMS", "");

            if (Controls.Count > 0)
            {
                // used for radiogroupbox
                foreach (string ChildControlName in Controls)
                {
                    TControlDef childCtrl = FCodeStorage.FindOrCreateControl(ChildControlName, ctrl.controlName);
                    IControlGenerator ctrlGen = writer.FindControlGenerator(childCtrl);
                    ProcessTemplate ctrlSnippet = ctrlGen.SetControlProperties(writer, childCtrl);

                    ctrlSnippet.SetCodelet("COLUMNWIDTH", "");

                    ctrlSnippet.SetCodelet("ITEMNAME", ctrl.controlName);
                    ctrlSnippet.SetCodelet("ITEMID", childCtrl.controlName);

                    if (ctrl.GetAttribute("hideLabel") == "true")
                    {
                        ctrlSnippet.SetCodelet("HIDELABEL", "true");
                    }
                    else if (ChildControlName == Controls[0])
                    {
                        ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "LABEL", ctrl, ctrl.Label);
                    }

                    snippetRowDefinition.InsertSnippet("ITEMS", ctrlSnippet, ",");
                }
            }
            else
            {
                // used for GroupBox, and Composite
                TExtJsFormsWriter.InsertControl(ctrl, snippetRowDefinition, "ITEMS", "HiddenValues", writer);
                TExtJsFormsWriter.InsertControl(ctrl, snippetRowDefinition, "ITEMS", "Controls", writer);
            }

            return snippetRowDefinition;
        }
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            base.SetControlProperties(writer, ctrl);

            if (ctrl.GetAttribute("AutoComplete").EndsWith("History"))
            {
                writer.SetControlProperty(ctrl, "AcceptNewValues", "true");
                writer.SetEventHandlerToControl(ctrl.controlName,
                    "AcceptNewEntries",
                    "TAcceptNewEntryEventHandler",
                    "FPetraUtilsObject.AddComboBoxHistory");
                writer.CallControlFunction(ctrl.controlName, "SetDataSourceStringList(\"\")");
                writer.Template.AddToCodelet("INITUSERCONTROLS",
                    "FPetraUtilsObject.LoadComboBoxHistory(" + ctrl.controlName + ");" + Environment.NewLine);
            }

            return writer.FTemplate;
        }
Exemplo n.º 6
0
        /// <summary>
        /// write the code for reading and writing the controls with the parameters
        /// </summary>
        public static void GenerateReadSetControls(TFormWriter writer, XmlNode curNode, ProcessTemplate ATargetTemplate, string ATemplateControlType)
        {
            string controlName = curNode.Name;

            // check if this control is already part of an optional group of controls depending on a radiobutton
            TControlDef ctrl = writer.CodeStorage.GetControl(controlName);

            if (ctrl.GetAttribute("DependsOnRadioButton") == "true")
            {
                return;
            }

            if (ctrl.GetAttribute("NoParameter") == "true")
            {
                return;
            }

            string paramName = ReportControls.GetParameterName(curNode);

            if (paramName == null)
            {
                return;
            }

            bool clearIfSettingEmpty = ReportControls.GetClearIfSettingEmpty(curNode);

            ProcessTemplate snippetReadControls = writer.Template.GetSnippet(ATemplateControlType + "READCONTROLS");
            snippetReadControls.SetCodelet("CONTROLNAME", controlName);
            snippetReadControls.SetCodelet("PARAMNAME", paramName);
            ATargetTemplate.InsertSnippet("READCONTROLS", snippetReadControls);

            ProcessTemplate snippetWriteControls = writer.Template.GetSnippet(ATemplateControlType + "SETCONTROLS");
            snippetWriteControls.SetCodelet("CONTROLNAME", controlName);
            snippetWriteControls.SetCodelet("PARAMNAME", paramName);

            if (clearIfSettingEmpty)
            {
                snippetWriteControls.SetCodelet("CLEARIFSETTINGEMPTY", clearIfSettingEmpty.ToString().ToLower());
            }

            ATargetTemplate.InsertSnippet("SETCONTROLS", snippetWriteControls);
        }
Exemplo n.º 7
0
        /// <summary>
        /// process the children
        /// </summary>
        public override void ProcessChildren(TFormWriter writer, TControlDef container)
        {
            // usually, the toolbar buttons are direct children of the toolbar control
            List <XmlNode>childrenlist = TYml2Xml.GetChildren(container.xmlNode, true);

            foreach (XmlNode childNode in childrenlist)
            {
                /* Get unique name if we need it
                 * at the moment we need it only for menu separators
                 */
                String UniqueChildName = childNode.Name;
                TControlDef childCtrl = container.FCodeStorage.GetControl(childNode.Name);

                if (childCtrl == null)
                {
                    UniqueChildName = TYml2Xml.GetAttribute(childNode, "UniqueName");
                    childCtrl = container.FCodeStorage.GetControl(UniqueChildName);
                }

                container.Children.Add(childCtrl);
                IControlGenerator ctrlGenerator = writer.FindControlGenerator(childCtrl);
                ctrlGenerator.GenerateControl(writer, childCtrl);
            }
        }
Exemplo n.º 8
0
 private static void AddChildUserControlExtraCalls(TFormWriter writer, TControlDef ctrl)
 {
     Console.WriteLine("adding to codelet: UserControl-specific extensions");
     writer.Template.AddToCodelet("USERCONTROLSRUNONCEONACTIVATION", ctrl.controlName + ".RunOnceOnParentActivation();" + Environment.NewLine);
     writer.Template.AddToCodelet("SAVEDATA", ctrl.controlName + ".GetDataFromControls();" + Environment.NewLine);
     writer.Template.AddToCodelet("PRIMARYKEYCONTROLSREADONLY", ctrl.controlName + ".SetPrimaryKeyReadOnly(AReadOnly);" + Environment.NewLine);
     writer.Template.AddToCodelet("USERCONTROLVALIDATION",
         ctrl.controlName + ".ValidateAllData(false, TErrorProcessingMode.Epm_None);" + Environment.NewLine);
     writer.Template.SetCodelet("PERFORMUSERCONTROLVALIDATION", "true");
 }
Exemplo n.º 9
0
        /// <summary>
        /// assign event handler to control
        /// </summary>
        public void AssignEventHandlerToControl(TFormWriter writer, TControlDef ctrl, string AEvent, string AEventHandlerType, string ActionToPerform)
        {
            if ((AEvent == null) || (AEvent.Length == 0))
            {
                return;
            }

            if (ActionToPerform.StartsWith("act"))
            {
                TActionHandler ActionHandler = writer.CodeStorage.FActionList[ActionToPerform];

                if (ActionHandler.actionId.Length > 0)
                {
                    // actionId is managed by FPetraUtilsObject
                    // need a special function that wraps calls to FPetraUtilsObject, otherwise problems in designer
                    ActionToPerform = ActionHandler.actionName;
                }
                else if (ActionHandler.actionClick.Length > 0)
                {
                    if (ActionHandler.actionClick.StartsWith("FPetraUtilsObject"))
                    {
                        // need a special function that wraps calls to FPetraUtilsObject, otherwise problems in designer
                        ActionToPerform = ActionHandler.actionName;
                    }
                    else
                    {
                        // direct call
                        ActionToPerform = ActionHandler.actionClick;
                    }
                }
                else
                {
                    ActionToPerform = "";
                }
            }
            else
            {
                // direct call: use ActionToPerform
            }

            if (ActionToPerform.Length > 0)
            {
                writer.SetEventHandlerToControl(ctrl.controlName, AEvent, AEventHandlerType, ActionToPerform);
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// generate the children, and write the size of this control
 /// </summary>
 public virtual void ProcessChildren(TFormWriter writer, TControlDef ctrl)
 {
 }
Exemplo n.º 11
0
        /// <summary>
        /// declaration and code creation in the designer file
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="ctrl"></param>
        public virtual void GenerateDeclaration(TFormWriter writer, TControlDef ctrl)
        {
            string localControlType = ControlType;

            if (ctrl.controlType.Length > 0)
            {
                localControlType = ctrl.controlType;
            }

            writer.Template.AddToCodelet("CONTROLDECLARATION", "private " + localControlType + " " + ctrl.controlName + ";" + Environment.NewLine);
            writer.Template.AddToCodelet("CONTROLCREATION", "this." + ctrl.controlName + " = new " + localControlType + "();" + Environment.NewLine);

            // TODO generate a property that can be accessed from outside
        }
Exemplo n.º 12
0
        /// add and install event handler for change of selection
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            base.SetControlProperties(writer, ctrl);

            writer.Template.AddToCodelet("CHECKEDCHANGED_" + ctrl.controlName, string.Empty);

            foreach (TControlDef ChildCtrl in ctrl.Children)
            {
                // make sure the control is enabled/disabled depending on the selection of the radiobutton
                writer.Template.AddToCodelet("CHECKEDCHANGED_" + ctrl.controlName,
                    ChildCtrl.controlName + ".Enabled = " + ctrl.controlName + ".Checked;" + Environment.NewLine);
            }

            writer.CodeStorage.FEventHandlersImplementation += "void " + ctrl.controlName + "CheckedChanged(object sender, System.EventArgs e)" +
                                                               Environment.NewLine + "{" + Environment.NewLine + "  {#CHECKEDCHANGED_" +
                                                               ctrl.controlName + "}" + Environment.NewLine +
                                                               "}" + Environment.NewLine + Environment.NewLine;
            writer.Template.AddToCodelet("INITIALISESCREEN", ctrl.controlName + "CheckedChanged(null, null);" + Environment.NewLine);
            writer.Template.AddToCodelet("CONTROLINITIALISATION",
                "this." + ctrl.controlName +
                ".CheckedChanged += new System.EventHandler(this." +
                ctrl.controlName +
                "CheckedChanged);" + Environment.NewLine);
            writer.Template.AddToCodelet("INITACTIONSTATE", ctrl.controlName + "CheckedChanged(null, null);" + Environment.NewLine);

            return writer.Template;
        }
Exemplo n.º 13
0
 /// e.g. used for controls on Reports (readparameter, etc)
 public virtual void ApplyDerivedFunctionality(TFormWriter writer, TControlDef control)
 {
 }
Exemplo n.º 14
0
 /// <summary>
 /// write code for on change event
 /// </summary>
 public virtual void OnChangeDataType(TFormWriter writer, XmlNode curNode)
 {
     OnChangeDataType(writer, curNode, curNode.Name);
 }
Exemplo n.º 15
0
        /// <summary>
        /// process the yaml document
        /// </summary>
        /// <returns></returns>
        public Boolean ProcessDocument()
        {
            string baseyaml;

            if (!TYml2Xml.ReadHeader(FYamlFilename, out baseyaml))
            {
                Console.WriteLine("ProcessYAML: cannot recognise type of form");
            }
            else
            {
                new TAppSettingsManager(false);

                //******************
                //* parsing *******
                //******************
                XmlDocument  myDoc                   = TYml2Xml.CreateXmlDocument();
                TCodeStorage codeStorage             = new TCodeStorage(myDoc, FXmlNodes);
                TParseYAMLFormsDefinition yamlParser = new TParseYAMLFormsDefinition(ref codeStorage);

                // should not need to be specific to special forms
                yamlParser.LoadRecursively(FYamlFilename, FSelectedLocalisation);

                // for debugging purposes, we can write the xml file that has been parsed from the yaml file
                // codeStorage.FXmlDocument.Save(FYamlFilename + ".xml");

                //****************
                //* output *******
                //****************
                TFormWriter writer = null;

                // get the appropriate derived class from IFormWriter (e.g. TFrmReportWriter)
                XmlNode rootNode = (XmlNode)yamlParser.FCodeStorage.FXmlNodes[TParseYAMLFormsDefinition.ROOTNODEYML];
                string  formType = TYml2Xml.GetAttribute(rootNode, "FormType");

                if (formType == "abstract")
                {
                    Console.WriteLine("Ignore yaml file because it has the formtype abstract: " + FYamlFilename);
                    return(true);
                }

                // the Template attribute is also quite important, because it determines which code is written
                // FormType is mainly important for the difference of the controls of reports and normal screens
                writer = GetWriter(formType);

                if (writer == null)
                {
                    Console.WriteLine("cannot find writer for {0}", formType);
                    return(false);
                }

                string templateDir = TAppSettingsManager.GetValue("TemplateDir", true);
                string template    = TYml2Xml.GetAttribute(rootNode, "Template");

                if (template.Length > 0)
                {
                    template = templateDir + Path.DirectorySeparatorChar + template + writer.CodeFileExtension;
                }

                string destinationFile = writer.CalculateDestinationFilename(FYamlFilename);
                string manualCodeFile  = writer.CalculateManualCodeFilename(FYamlFilename);

                // need to know the path to the manual code file in order to call manual functions which would not be called if they do not exist
                codeStorage.ManualCodeFilename = manualCodeFile;

                writer.CreateCode(codeStorage, FYamlFilename, template);

                writer.CreateResourceFile(FYamlFilename, templateDir);

                writer.CreateDesignerFile(FYamlFilename, rootNode, templateDir);

                return(writer.WriteFile(destinationFile));
            }

            return(false);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Sets the properties of a control which are defined under "Actions:" in the .yaml file
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="ctrl"></param>
        /// <param name="AActionHandler"></param>
        public virtual void SetControlActionProperties(TFormWriter writer, TControlDef ctrl, TActionHandler AActionHandler)
        {
            if (AActionHandler.actionImage.Length > 0)
            {
                /* Get the name of the image for the toolbar button
                 * and put it into the resources.
                 * The images must be in the directory specified by the ResourceDir command line parameter
                 */
                writer.SetControlProperty(ctrl, "Image",
                    "((System.Drawing.Bitmap)resources" + ctrl.controlType + ".GetObject(\"" + ctrl.controlName + ".Glyph\"))");
                writer.AddImageToResource(ctrl.controlName, AActionHandler.actionImage, "Bitmap");
            }

            if ((AActionHandler.actionTooltip.Length > 0) && (ctrl.controlTypePrefix != "btn"))
            {
                writer.SetControlProperty(ctrl, "ToolTipText", "\"" + AActionHandler.actionTooltip + "\"");
            }
        }
Exemplo n.º 17
0
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            base.SetControlProperties(writer, ctrl);

            if (TYml2Xml.HasAttribute(ctrl.xmlNode, "SelectedRowActivates"))
            {
                // TODO: this function needs to be called by the manual code at the moment when eg a search finishes
                // TODO: call "Activate" + TYml2Xml.GetAttribute(ctrl.xmlNode, "SelectedRowActivates")
            }

            StringCollection Columns = TYml2Xml.GetElements(ctrl.xmlNode, "Columns");

            if (Columns.Count > 0)
            {
                writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".Columns.Clear();" + Environment.NewLine);

                foreach (string ColumnFieldName in Columns)
                {
                    bool IsDetailNotMaster;
                    TTableField field = null;

                    // customfield, eg. UC_GLTransactions, ATransaction.DateEntered and ATransaction.AnalysisAttributes
                    // there needs to be a list of CustomColumns
                    XmlNode CustomColumnsNode = TYml2Xml.GetChild(ctrl.xmlNode, "CustomColumns");
                    XmlNode CustomColumnNode = null;

                    if (CustomColumnsNode != null)
                    {
                        CustomColumnNode = TYml2Xml.GetChild(CustomColumnsNode, ColumnFieldName);
                    }

                    if (CustomColumnNode != null)
                    {
                        //string ColumnType = "System.String";

                        /* TODO DateTime (tracker: #58)
                         * if (TYml2Xml.GetAttribute(CustomColumnNode, "Type") == "System.DateTime")
                         * {
                         *  ColumnType = "DateTime";
                         * }
                         */

                        // TODO: different behaviour for double???
                        if (TYml2Xml.GetAttribute(CustomColumnNode, "Type") == "Boolean")
                        {
                            //ColumnType = "CheckBox";
                        }

                        writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".Columns.Add(" +
                            "FMainDS." + ctrl.GetAttribute("TableName") + ".Get" + ColumnFieldName + "DBName(), \"" +
                            TYml2Xml.GetAttribute(CustomColumnNode, "Label") + "\");" + Environment.NewLine);
                    }
                    else if (ctrl.HasAttribute("TableName"))
                    {
                        field =
                            TDataBinding.GetTableField(null, ctrl.GetAttribute("TableName") + "." + ColumnFieldName,
                                out IsDetailNotMaster,
                                true);
                    }
                    else
                    {
                        field = TDataBinding.GetTableField(null, ColumnFieldName, out IsDetailNotMaster, true);
                    }

                    if (field != null)
                    {
                        //string ColumnType = "System.String";

                        /* TODO DateTime (tracker: #58)
                         * if (field.GetDotNetType() == "System.DateTime")
                         * {
                         *  ColumnType = "DateTime";
                         * }
                         */

                        // TODO: different behaviour for double???
                        if (field.GetDotNetType() == "Boolean")
                        {
                            //ColumnType = "CheckBox";
                        }

                        writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".Columns.Add(" +
                            TTable.NiceTableName(field.strTableName) + "Table.Get" +
                            TTable.NiceFieldName(field.strName) + "DBName(), \"" +
                            field.strLabel + "\");" + Environment.NewLine);
                    }
                }
            }

            if (ctrl.HasAttribute("ActionLeavingRow"))
            {
                AssignEventHandlerToControl(writer, ctrl, "Selection.FocusRowLeaving", "SourceGrid.RowCancelEventHandler",
                    ctrl.GetAttribute("ActionLeavingRow"));
            }

            if (ctrl.HasAttribute("ActionFocusRow"))
            {
// TODO                AssignEventHandlerToControl(writer, ctrl, "Selection.FocusRowEntered", "SourceGrid.RowEventHandler",
//                    ctrl.GetAttribute("ActionFocusRow"));
            }

            if ((ctrl.controlName == "grdDetails") && FCodeStorage.HasAttribute("DetailTable"))
            {
                writer.Template.AddToCodelet("SHOWDATA", "");

                if (ctrl.HasAttribute("SortOrder"))
                {
                    // SortOrder is comma separated and has DESC or ASC after the column name
                    string SortOrder = ctrl.GetAttribute("SortOrder");

                    foreach (string SortOrderPart in SortOrder.Split(','))
                    {
                        bool temp;
                        TTableField field = null;

                        if ((SortOrderPart.Split(' ')[0].IndexOf(".") == -1) && ctrl.HasAttribute("TableName"))
                        {
                            field =
                                TDataBinding.GetTableField(null, ctrl.GetAttribute("TableName") + "." + SortOrderPart.Split(
                                        ' ')[0], out temp, true);
                        }
                        else
                        {
                            field =
                                TDataBinding.GetTableField(
                                    null,
                                    SortOrderPart.Split(' ')[0],
                                    out temp, true);
                        }

                        if (field != null)
                        {
                            SortOrder = SortOrder.Replace(SortOrderPart.Split(' ')[0], field.strName);
                        }
                    }

                    writer.Template.AddToCodelet("GRIDSORT", SortOrder);
                }

                if (ctrl.HasAttribute("RowFilter"))
                {
                    // this references a field in the table, and assumes there exists a local variable with the same name
                    // eg. FBatchNumber in GL Journals
                    string RowFilter = ctrl.GetAttribute("RowFilter");

                    String FilterString = "\"";

                    foreach (string RowFilterPart in RowFilter.Split(','))
                    {
                        bool temp;
                        string columnName =
                            TDataBinding.GetTableField(
                                null,
                                RowFilterPart,
                                out temp, true).strName;

                        if (FilterString.Length > 1)
                        {
                            FilterString += " + \" and ";
                        }

                        FilterString += columnName + " = \" + F" + TTable.NiceFieldName(columnName) + ".ToString()";
                    }

                    writer.Template.AddToCodelet("GRIDFILTER", FilterString);
                }
            }

            return writer.FTemplate;
        }
Exemplo n.º 18
0
 /// <summary>
 /// write code for on change event
 /// </summary>
 public virtual void OnChangeDataType(TFormWriter writer, XmlNode curNode, string controlName)
 {
     // the selection of this control triggers the available options in other controls
     if (TYml2Xml.HasAttribute(curNode, "OnChangeDataType"))
     {
         writer.Template.AddToCodelet("CONTROLINITIALISATION",
             "this." + controlName + ".Leave += new EventHandler(this." + StringHelper.UpperCamelCase(controlName,
                 ',',
                 false,
                 false) + "_SelectionChangeCommitted);" + Environment.NewLine +
             "this." + controlName + ".SelectionChangeCommitted += new EventHandler(this." +
             StringHelper.UpperCamelCase(controlName, ',', false, false) + "_SelectionChangeCommitted);" + Environment.NewLine);
         writer.CodeStorage.FEventHandlersImplementation +=
             "private void " +
             StringHelper.UpperCamelCase(controlName, ',', false,
                 false) + "_SelectionChangeCommitted(System.Object sender, System.EventArgs e)" + Environment.NewLine +
             "{" + Environment.NewLine +
             "  " +
             StringHelper.UpperCamelCase(controlName, ',', false,
                 false) + "_Initialise(" + controlName + ".GetSelected" + TYml2Xml.GetAttribute(
                 curNode,
                 "OnChangeDataType") + "());" + Environment.NewLine +
             "}" + Environment.NewLine + Environment.NewLine;
         writer.CodeStorage.FEventHandlersImplementation +=
             "private void " + StringHelper.UpperCamelCase(controlName, ',', false, false) + "_Initialise(" + TYml2Xml.GetAttribute(curNode,
                 "OnChangeDataType") + " AParam)" + Environment.NewLine +
             "{" + Environment.NewLine +
             "  Int32 Index;" + Environment.NewLine +
             "  Index = this." + controlName + ".Find" +
             TYml2Xml.GetAttribute(curNode, "OnChangeDataType") + "InComboBox(AParam);" + Environment.NewLine +
             "  if ((Index >= 0) && (Index < this." + controlName + ".Items.Count) && (Index != this." + controlName + ".SelectedIndex)) " +
             Environment.NewLine +
             "  {" + Environment.NewLine +
             "    this." + controlName + ".SelectedIndex = Index;" + Environment.NewLine +
             "  }" + Environment.NewLine +
             "  {#INITIALISE_" + controlName + "}" + Environment.NewLine +
             "}" + Environment.NewLine + Environment.NewLine;
     }
 }
Exemplo n.º 19
0
        private void AddColumnToGrid(TFormWriter writer, string AGridControlName, string AColumnType, string ALabel,
            string AHeaderTooltip, string ATableName, string AColumnName)
        {
            string ColumnType = "Text";
            string PotentialDecimalPrecision;
            string TrueString = string.Empty;
            string FalseString = string.Empty;
            string HeaderTooltip = (AHeaderTooltip == string.Empty) ? ALabel : AHeaderTooltip;

            if (AColumnType.Contains("DateTime"))
            {
                ColumnType = "Date";
            }
            else if (AColumnType.Contains("Currency"))
            {
                ColumnType = "Currency";

                if (AColumnType.Contains("Currency("))
                {
                    PotentialDecimalPrecision = AColumnType.Substring(AColumnType.IndexOf('(') + 1,
                        AColumnType.IndexOf(')') - AColumnType.IndexOf('(') - 1);

//Console.WriteLine("AddColumnToGrid: PotentialDecimalPrecision: " + PotentialDecimalPrecision);

                    if (PotentialDecimalPrecision != String.Empty)
                    {
                        try
                        {
                            FDecimalPrecision = Convert.ToInt16(PotentialDecimalPrecision);
                        }
                        catch (System.FormatException)
                        {
                            throw new ApplicationException(
                                "Grid Column with currency formatting: The specifier for the currency precision '" + PotentialDecimalPrecision +
                                "' is not a number!");
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                }
            }
            else if (AColumnType.Contains("Boolean"))
            {
                if (AColumnType.Contains("("))
                {
                    string BooleanNames = AColumnType.Substring(AColumnType.IndexOf('(') + 1,
                        AColumnType.IndexOf(')') - AColumnType.IndexOf('(') - 1);
                    TrueString = BooleanNames.Split(',')[0];
                    FalseString = BooleanNames.Split(',')[1];
                }

                if ((TrueString.Length > 0) || (FalseString.Length > 0))
                {
                    ColumnType = "Boolean";
                }
                else
                {
                    ColumnType = "CheckBox";
                }
            }
            else if (AColumnType.Contains("PartnerKey"))
            {
                ColumnType = "PartnerKey";
            }
            else if (AColumnType.Contains("Time"))
            {
                ColumnType = AColumnType;
            }

            if (ColumnType == "Boolean")
            {
                writer.Template.AddToCodelet("INITMANUALCODE",
                    AGridControlName + ".Add" + ColumnType + "Column(Catalog.GetString(\"" + ALabel + "\"), " +
                    "FMainDS." +
                    ATableName + ".Column" +
                    AColumnName + ", Catalog.GetString(\"" + TrueString + "\"), Catalog.GetString(\"" + FalseString + "\"));" + Environment.NewLine);
            }
            else if ((ColumnType != "Currency")
                     || ((ColumnType == "Currency") && (FDecimalPrecision == 2)))
            {
                writer.Template.AddToCodelet("INITMANUALCODE",
                    AGridControlName + ".Add" + ColumnType + "Column(Catalog.GetString(\"" + ALabel + "\"), " +
                    "FMainDS." +
                    ATableName + ".Column" +
                    AColumnName + ");" + Environment.NewLine);
            }
            else if (ColumnType == "PartnerKey")
            {
                writer.Template.AddToCodelet("INITMANUALCODE",
                    AGridControlName + ".Add" + ColumnType + "Column(Catalog.GetString(\"" + ALabel + "\"), " +
                    "FMainDS." +
                    ATableName + ".Column" +
                    AColumnName + ");" + Environment.NewLine);
            }
            else
            {
                writer.Template.AddToCodelet("INITMANUALCODE",
                    AGridControlName + ".Add" + ColumnType + "Column(Catalog.GetString(\"" + ALabel + "\"), " +
                    "FMainDS." +
                    ATableName + ".Column" +
                    AColumnName + ", " + FDecimalPrecision.ToString() + ");" + Environment.NewLine);
            }

            // Are we still working with the same grid?  If not reset our tracking variables back to the first column
            if (AGridControlName != FPrevControlName)
            {
                FColumnIndex = 0;
                FPrevControlName = AGridControlName;
            }

            writer.Template.AddToCodelet("GRIDHEADERTOOLTIP",
                AGridControlName + ".SetHeaderTooltip(" + FColumnIndex.ToString() + ", Catalog.GetString(\"" + HeaderTooltip + "\"));" +
                Environment.NewLine);
            FColumnIndex++;
        }
Exemplo n.º 20
0
        /// <summary>
        /// generate the children, and write the size of this control
        /// </summary>
        public override void ProcessChildren(TFormWriter writer, TControlDef ctrl)
        {
            XmlNode Controls = TXMLParser.GetChild(ctrl.xmlNode, "Controls");

            if (Controls != null)
            {
                StringCollection childControls = TYml2Xml.GetElements(Controls);

                // this is a checkbox that enables another control or a group of controls
                ctrl.SetAttribute("GenerateWithOtherControls", "yes");

                if (childControls.Count == 1)
                {
                    TControlDef ChildCtrl = ctrl.FCodeStorage.GetControl(childControls[0]);
                    ChildCtrl.parentName = ctrl.controlName;
                    ctrl.Children.Add(ChildCtrl);

                    ChildCtrl.SetAttribute("DependsOnRadioButton", "true");

                    // use the label of the child control
                    if (ChildCtrl.HasAttribute("Label"))
                    {
                        ctrl.Label = ChildCtrl.Label;
                    }
                }
                else
                {
                    foreach (string child in childControls)
                    {
                        TControlDef ChildCtrl = ctrl.FCodeStorage.GetControl(child);

                        if (ChildCtrl == null)
                        {
                            throw new Exception("cannot find control " + child + " which should belong to " + ctrl.controlName);
                        }

                        ChildCtrl.parentName = ctrl.controlName;
                        ctrl.Children.Add(ChildCtrl);

                        ChildCtrl.SetAttribute("DependsOnRadioButton", "true");

                        IControlGenerator ctrlGenerator = writer.FindControlGenerator(ChildCtrl);
                        ctrlGenerator.GenerateControl(writer, ChildCtrl);
                    }
                }
            }
        }
Exemplo n.º 21
0
        private bool GenerateDataValidationCode(TFormWriter writer, TControlDef ctrl, out bool AAutomDataValidation,
            out string AReasonForAutomValidation)
        {
            AAutomDataValidation = false;
            AReasonForAutomValidation = String.Empty;

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

            if (TDataValidation.GenerateAutoValidationCodeForControl(ctrl,
                    ctrl.HasAttribute("DataField"),
                    (writer.CodeStorage.HasAttribute("MasterTable")
                     || writer.CodeStorage.HasAttribute("DetailTable")),
                    !((this is LabelGenerator) || (this is LinkLabelGenerator)),
                    TDataValidation.TAutomDataValidationScope.advsAll, out AReasonForAutomValidation)
                )
            {
                AAutomDataValidation = true;

                return true;
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// generate all code for the control
 /// </summary>
 public void GenerateControl(TFormWriter writer, TControlDef ctrl)
 {
     GenerateDeclaration(writer, ctrl);
     ProcessChildren(writer, ctrl);
     SetControlProperties(writer, ctrl);
     OnChangeDataType(writer, ctrl.xmlNode, ctrl.controlName);
     writer.InitialiseDataSource(ctrl.xmlNode, ctrl.controlName);
     writer.ApplyDerivedFunctionality(this, ctrl);
     AddChildren(writer, ctrl);
 }
Exemplo n.º 23
0
        /// <summary>
        /// fetch the partner short name from the server;
        /// this control is readonly, therefore we don't need statusbar help
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="ctrl"></param>
        private void LinkControlPartnerShortNameLookup(TFormWriter writer, TControlDef ctrl)
        {
            string PartnerShortNameLookup = ctrl.GetAttribute("PartnerShortNameLookup");
            bool IsDetailNotMaster;

            TTableField field = TDataBinding.GetTableField(ctrl, PartnerShortNameLookup, out IsDetailNotMaster, true);

            string showData = "TPartnerClass partnerClass;" + Environment.NewLine;
            string RowName = "FMainDS." + TTable.NiceTableName(field.strTableName) + "[0]";

            if ((TTable.NiceTableName(field.strTableName) == writer.CodeStorage.GetAttribute("DetailTable"))
                || (TTable.NiceTableName(field.strTableName) == writer.CodeStorage.GetAttribute("MasterTable")))
            {
                RowName = "ARow";
            }

            showData += "string partnerShortName;" + Environment.NewLine;
            showData += "TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetPartnerShortName(" + Environment.NewLine;
            showData += "    " + RowName + "." + TTable.NiceFieldName(field.strName) + "," +
                        Environment.NewLine;
            showData += "    out partnerShortName," + Environment.NewLine;
            showData += "    out partnerClass);" + Environment.NewLine;
            showData += ctrl.controlName + ".Text = partnerShortName;" + Environment.NewLine;

            writer.Template.AddToCodelet("SHOWDATA", showData);
        }
Exemplo n.º 24
0
 /// <summary>
 /// add the children to this control
 /// </summary>
 public virtual void AddChildren(TFormWriter writer, TControlDef ctrl)
 {
 }
Exemplo n.º 25
0
        private void DataFieldUndoCapability(TFormWriter writer, TControlDef ctrl, TTableField AField, bool AIsDetailNotMaster)
        {
            if (AField == null)
            {
                return;
            }

            string tablename = TTable.NiceTableName(AField.strTableName);
            string fieldname = TTable.NiceFieldName(AField);
            string TestForNullTable = "FMainDS." + tablename;

            if ((tablename == writer.CodeStorage.GetAttribute("DetailTable")) || (tablename == writer.CodeStorage.GetAttribute("MasterTable")))
            {
                TestForNullTable = "";
            }

            string targetCodelet = "UNDODATA";

            ProcessTemplate snippetShowData = GenerateUndoDataSnippetCode(ref tablename, ref fieldname, ref TestForNullTable, writer, ctrl, AField);

            writer.Template.InsertSnippet(targetCodelet, snippetShowData);
        }
Exemplo n.º 26
0
 /// <summary>
 /// overload
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="ctrl"></param>
 /// <param name="AEvent">Click or DoubleClick or other</param>
 /// <param name="ActionToPerform"></param>
 public void AssignEventHandlerToControl(TFormWriter writer, TControlDef ctrl, string AEvent, string ActionToPerform)
 {
     AssignEventHandlerToControl(writer, ctrl, AEvent, "System.EventHandler", ActionToPerform);
 }
Exemplo n.º 27
0
        private void LinkControlDataField(TFormWriter writer, TControlDef ctrl, TTableField AField, bool AIsDetailNotMaster)
        {
            ProcessTemplate snippetValidationControlsDictAdd;
            bool AutomDataValidation;
            string ReasonForAutomValidation;
            string ColumnIDStr;
            bool OKToGenerateDVCode = true;

            if (AField == null)
            {
                return;
            }

            string tablename = TTable.NiceTableName(AField.strTableName);
            string fieldname = TTable.NiceFieldName(AField);
            string RowName = "FMainDS." + tablename + "[0]";
            string TestForNullTable = "FMainDS." + tablename;

            if ((tablename == writer.CodeStorage.GetAttribute("DetailTable")) || (tablename == writer.CodeStorage.GetAttribute("MasterTable")))
            {
                RowName = "ARow";
                TestForNullTable = "";
            }

            string targetCodelet = "SHOWDATA";

            if (tablename == writer.CodeStorage.GetAttribute("DetailTable"))
            {
                targetCodelet = "SHOWDETAILS";
            }

            ProcessTemplate snippetShowData = GenerateShowDataSnippetCode(ref fieldname, ref RowName, ref TestForNullTable, writer, ctrl, AField);

            writer.Template.InsertSnippet(targetCodelet, snippetShowData);

            if (AField.bPartOfPrimKey)
            {
                // check if the current row is new; then allow changing the primary key; otherwise make the control readonly
                writer.Template.AddToCodelet(targetCodelet, ctrl.controlName + "." + (FHasReadOnlyProperty ? "ReadOnly" : "Enabled") + " = " +
                    "(" + RowName + ".RowState " + (FHasReadOnlyProperty ? "!=" : "==") + " DataRowState.Added);" + Environment.NewLine);
                writer.Template.AddToCodelet("PRIMARYKEYCONTROLSREADONLY",
                    ctrl.controlName + "." + (FHasReadOnlyProperty ? "ReadOnly = " : "Enabled = !") + "AReadOnly;" + Environment.NewLine);
            }

            if (ctrl.GetAttribute("ReadOnly").ToLower() != "true")
            {
                targetCodelet = targetCodelet.Replace("SHOW", "SAVE");

                ProcessTemplate snippetGetData = writer.Template.GetSnippet("GETDATAFORCOLUMNTHATCANBENULL");

                if (AField.GetDotNetType().ToLower().Contains("string"))
                {
                    snippetGetData.SetCodelet("GETVALUEORNULL", "{#ROW}.{#COLUMNNAME} = {#CONTROLVALUE};");
                    snippetGetData.InsertSnippet("GETROWVALUEORNULL", writer.Template.GetSnippet("GETROWVALUEORNULLSTRING"));
                }
                else
                {
                    snippetGetData.InsertSnippet("GETVALUEORNULL", writer.Template.GetSnippet("GETVALUEORNULL"));
                    snippetGetData.InsertSnippet("GETROWVALUEORNULL", writer.Template.GetSnippet("GETROWVALUEORNULL"));
                }

                snippetGetData.SetCodelet("CANBENULL", !AField.bNotNull && (this.GetControlValue(ctrl, null) != null) ? "yes" : "");
                snippetGetData.SetCodelet("NOTDEFAULTTABLE", TestForNullTable);
                snippetGetData.SetCodelet("DETERMINECONTROLISNULL", this.GetControlValue(ctrl, null));
                snippetGetData.SetCodelet("ROW", RowName);
                snippetGetData.SetCodelet("COLUMNNAME", fieldname);
                snippetGetData.SetCodelet("CONTROLVALUE", this.GetControlValue(ctrl, AField.GetDotNetType()));
                snippetGetData.SetCodelet("CONTROLNAME", ctrl.controlName);

                writer.Template.InsertSnippet(targetCodelet, snippetGetData);
            }

            // setstatusbar tooltips for datafields, with getstring plus value from petra.xml
            string helpText = AField.strHelp;

            if (helpText.Length == 0)
            {
                helpText = AField.strDescription;
            }

            if ((helpText.Length > 0) && (ctrl.GetAttribute("Tooltip").Length == 0))
            {
                writer.Template.AddToCodelet("INITUSERCONTROLS", "FPetraUtilsObject.SetStatusBarText(" + ctrl.controlName +
                    ", Catalog.GetString(\"" +
                    helpText.Replace("\"", "\\\"") +                           // properly escape double quotation marks
                    "\"));" + Environment.NewLine);
            }

            // Data Validation
            if (GenerateDataValidationCode(writer, ctrl, out AutomDataValidation, out ReasonForAutomValidation))
            {
                string targetCodeletValidation = "ADDCONTROLTOVALIDATIONCONTROLSDICT";

                ColumnIDStr = "FMainDS." + tablename + ".Columns[(short)FMainDS." + tablename + ".GetType().GetField(\"Column" + fieldname +
                              "Id\", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy).GetValue(FMainDS." + tablename +
                              ".GetType())]";

                if (writer.Template.FCodelets.Keys.Contains(targetCodeletValidation))
                {
                    // Check if code for the addition of a certain DataColumn is is already contained in Template;
                    // if so, skip a further addition to prevent an Exception at runtime
                    if (writer.Template.FCodelets[targetCodeletValidation].ToString().Contains(ColumnIDStr))
                    {
                        OKToGenerateDVCode = false;
                    }
                }

                if (OKToGenerateDVCode)
                {
                    if (!ctrl.GetAttribute("Validation").ToLower().StartsWith("pair("))
                    {
                        snippetValidationControlsDictAdd = writer.Template.GetSnippet("VALIDATIONCONTROLSDICTADD");
                    }
                    else
                    {
                        snippetValidationControlsDictAdd = writer.Template.GetSnippet("VALIDATIONCONTROLSDICTADDMULTI");

                        string PairControlName = ctrl.GetAttribute("Validation").Substring(5, ctrl.GetAttribute("Validation").Length - 6);
                        TControlDef SecondValidationControl = writer.CodeStorage.GetControl(PairControlName);

                        if (SecondValidationControl != null)
                        {
                            snippetValidationControlsDictAdd.SetCodelet("VALIDATIONCONTROL2", SecondValidationControl.controlName);

                            if (TFormWriter.ProperI18NCatalogGetString(StringHelper.TrimQuotes(SecondValidationControl.Label)))
                            {
                                snippetValidationControlsDictAdd.SetCodelet("LABELTEXT2",
                                    "Catalog.GetString(" + "\"" + SecondValidationControl.Label + "\")");
                            }
                            else
                            {
                                snippetValidationControlsDictAdd.SetCodelet("LABELTEXT2", "\"" + SecondValidationControl.Label + "\"");
                            }
                        }
                        else
                        {
                            throw new ApplicationException(
                                "Pair Control for Validation '" + PairControlName + "' does not exist. Please specify a valid control!");
                        }
                    }

                    snippetValidationControlsDictAdd.SetCodelet("TABLENAME", tablename);
                    snippetValidationControlsDictAdd.SetCodelet("COLUMNID", ColumnIDStr);
                    snippetValidationControlsDictAdd.SetCodelet("VALIDATIONCONTROLSDICTVAR",
                        writer.Template.FTemplateCode.Contains(
                            "FValidationControlsDict") ? "FValidationControlsDict" : "FPetraUtilsObject.ValidationControlsDict");

                    if (AutomDataValidation)
                    {
                        snippetValidationControlsDictAdd.SetCodelet("AUTOMATICVALIDATIONCOMMENT",
                            " // Automatic Data Validation based on DB specification: " + ReasonForAutomValidation);
                    }
                    else
                    {
                        snippetValidationControlsDictAdd.SetCodelet("AUTOMATICVALIDATIONCOMMENT", "");
                    }

                    snippetValidationControlsDictAdd.SetCodelet("VALIDATIONCONTROL", ctrl.controlName);

                    if (TFormWriter.ProperI18NCatalogGetString(StringHelper.TrimQuotes(ctrl.Label)))
                    {
                        snippetValidationControlsDictAdd.SetCodelet("LABELTEXT", "Catalog.GetString(" + "\"" + ctrl.Label + "\")");
                    }
                    else
                    {
                        snippetValidationControlsDictAdd.SetCodelet("LABELTEXT", "\"" + ctrl.Label + "\"");
                    }

                    writer.Template.InsertSnippet(targetCodeletValidation, snippetValidationControlsDictAdd);
                }
            }
        }
Exemplo n.º 28
0
 /// <summary>
 /// action is enabled, enable the controls depending on the action
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="ActionCondition"></param>
 /// <param name="ControlName"></param>
 public void AddToActionEnabledEvent(TFormWriter writer, string ActionCondition, string ControlName)
 {
     writer.Template.AddToCodelet(
         "ENABLEDEPENDINGACTIONS_" + ActionCondition,
         ControlName + ".Enabled = e.Enabled;" + Environment.NewLine);
 }
Exemplo n.º 29
0
        /// <summary>
        /// Generates code for the SHOWDATA Snippet.
        /// </summary>
        /// <param name="fieldname">Name of field</param>
        /// <param name="RowName">Name of row</param>
        /// <param name="TestForNullTable"></param>
        /// <param name="writer">FormWriter instance.</param>
        /// <param name="ctrl">TControlDef instance.</param>
        /// <param name="AField">TTableField instance.</param>
        /// <returns>A <see cref="ProcessTemplate"></see>.</returns>
        ProcessTemplate GenerateShowDataSnippetCode(ref string fieldname,
            ref string RowName,
            ref string TestForNullTable,
            TFormWriter writer,
            TControlDef ctrl,
            TTableField AField)
        {
            ProcessTemplate snippetShowData = writer.Template.GetSnippet("SHOWDATAFORCOLUMN");

            if (AField.GetDotNetType().ToLower().Contains("string"))
            {
                snippetShowData.SetCodelet("SETVALUEORNULL", "{#SETCONTROLVALUE}");
                snippetShowData.SetCodelet("SETROWVALUEORNULL", "{#SETROWVALUE}");
            }
            else
            {
                snippetShowData.InsertSnippet("SETVALUEORNULL", writer.Template.GetSnippet("SETVALUEORNULL"));
                snippetShowData.InsertSnippet("SETROWVALUEORNULL", writer.Template.GetSnippet("SETROWVALUEORNULL"));
            }

            snippetShowData.SetCodelet("CANBENULL", !AField.bNotNull ? "yes" : "");
            snippetShowData.SetCodelet("DETERMINECONTROLISNULL", this.GetControlValue(ctrl, null));
            snippetShowData.SetCodelet("NOTDEFAULTTABLE", TestForNullTable);
            snippetShowData.SetCodelet("ROW", RowName);
            snippetShowData.SetCodelet("COLUMNNAME", fieldname);
            snippetShowData.SetCodelet("SETNULLVALUE", this.AssignValue(ctrl, null, null));
            snippetShowData.SetCodelet("SETCONTROLVALUE", this.AssignValue(ctrl, RowName + "." + fieldname, AField.GetDotNetType()));
            snippetShowData.InsertSnippet("SETROWVALUE", writer.Template.GetSnippet("SETROWVALUE"));

            return snippetShowData;
        }
Exemplo n.º 30
0
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public virtual ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            bool AutomDataValidation;
            string ReasonForAutomValidation;
            bool IsDetailNotMaster;

            writer.SetControlProperty(ctrl, "Name", "\"" + ctrl.controlName + "\"");

            if (FLocation && !ctrl.HasAttribute("Dock"))
            {
                writer.SetControlProperty(ctrl, "Location", "new System.Drawing.Point(2,2)");
            }

            #region Aligning and stretching

            if (ctrl.HasAttribute("Align")
                && !(ctrl.HasAttribute("Stretch")))
            {
                if ((ctrl.GetAttribute("Align").ToLower() == "right")
                    || (ctrl.GetAttribute("Align").ToLower() == "top-right"))
                {
                    writer.SetControlProperty(ctrl,
                        "Anchor",
                        "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)))");
                }
                else if (ctrl.GetAttribute("Align").ToLower() == "middle-right")
                {
                    writer.SetControlProperty(ctrl,
                        "Anchor",
                        "((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Right))");
                }
                else if (ctrl.GetAttribute("Align").ToLower() == "bottom-right")
                {
                    writer.SetControlProperty(ctrl,
                        "Anchor",
                        "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)))");
                }
                else if ((ctrl.GetAttribute("Align").ToLower() == "center")
                         || (ctrl.GetAttribute("Align").ToLower() == "top-center"))
                {
                    writer.SetControlProperty(ctrl,
                        "Anchor",
                        "((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Top))");
                }
                else if (ctrl.GetAttribute("Align").ToLower() == "middle-center")
                {
                    writer.SetControlProperty(ctrl,
                        "Anchor",
                        "((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.None))");
                }
                else if (ctrl.GetAttribute("Align").ToLower() == "bottom-center")
                {
                    writer.SetControlProperty(ctrl,
                        "Anchor",
                        "((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Bottom))");
                }
                else if ((ctrl.GetAttribute("Align").ToLower() == "bottom")
                         || (ctrl.GetAttribute("Align").ToLower() == "bottom-left"))
                {
                    writer.SetControlProperty(ctrl,
                        "Anchor",
                        "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Bottom)))");
                }
                else if ((ctrl.GetAttribute("Align").ToLower() == "middle")
                         || (ctrl.GetAttribute("Align").ToLower() == "middle-left"))
                {
                    writer.SetControlProperty(ctrl,
                        "Anchor",
                        "((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Left))");
                }
                else if ((ctrl.GetAttribute("Align").ToLower() == "left")
                         || (ctrl.GetAttribute("Align").ToLower() == "top")
                         || (ctrl.GetAttribute("Align").ToLower() == "top-left"))
                {
                    // do nothing (here just to avoid throwing the following Exception)
                    Console.WriteLine(
                        "HINT: Attribute 'Align' with value 'left', 'top' or 'top-left' does not affect the layout since these create the default alignment. Control: '"
                        +
                        ctrl.controlName + "'.");
                }
                else
                {
                    throw new Exception("Invalid value for Attribute 'Align' of Control '" + ctrl.controlName + "': '" + ctrl.GetAttribute(
                            "Align") +
                        "'. Supported values are: Simple: left, right, center; top, middle, bottom; Combined: top-left, middle-left, bottom-left, top-center, middle-center, bottom-center, top-right, middle-right, bottom-right.");
                }
            }

            if (ctrl.HasAttribute("Stretch"))
            {
                if (ctrl.GetAttribute("Stretch").ToLower() == "horizontally")
                {
                    if ((!ctrl.HasAttribute("Align"))
                        || (ctrl.HasAttribute("Align") && (ctrl.GetAttribute("Align").ToLower() == "top")))
                    {
                        // Horizontally stretched, top aligned (=default)
                        writer.SetControlProperty(
                            ctrl,
                            "Anchor",
                            "((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)))");
                    }
                    else
                    {
                        if (ctrl.GetAttribute("Align").ToLower() == "bottom")
                        {
                            // Horizontally stretched, bottom aligned
                            writer.SetControlProperty(
                                ctrl,
                                "Anchor",
                                "((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)))");
                        }
                        else if (ctrl.GetAttribute("Align").ToLower() == "middle")
                        {
                            // Horizontally stretched, vertically centered
                            writer.SetControlProperty(
                                ctrl,
                                "Anchor",
                                "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)))");
                        }
                        else
                        {
                            throw new Exception("Invalid value '" + ctrl.GetAttribute(
                                    "Align") + "' for Attribute 'Align' of Control '" + ctrl.controlName +
                                "' whose Attribute 'Stretch' is set to '" +
                                ctrl.GetAttribute("Stretch") +
                                "'. Supported values are: top, middle, bottom.");
                        }
                    }
                }
                else if (ctrl.GetAttribute("Stretch").ToLower() == "vertically")
                {
                    if ((!ctrl.HasAttribute("Align"))
                        || (ctrl.HasAttribute("Align") && (ctrl.GetAttribute("Align").ToLower() == "left")))
                    {
                        // Vertically stretched, left aligned (=default)
                        writer.SetControlProperty(
                            ctrl,
                            "Anchor",
                            "((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Bottom)))");
                    }
                    else
                    {
                        if (ctrl.GetAttribute("Align").ToLower() == "right")
                        {
                            // Vertically stretched, right aligned
                            writer.SetControlProperty(
                                ctrl,
                                "Anchor",
                                "((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right) | System.Windows.Forms.AnchorStyles.Bottom)))");
                        }
                        else if (ctrl.GetAttribute("Align").ToLower() == "center")
                        {
                            // Vertically stretched, horizontally centered
                            writer.SetControlProperty(
                                ctrl,
                                "Anchor",
                                "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)))");
                        }
                        else
                        {
                            throw new Exception("Invalid value '" + ctrl.GetAttribute(
                                    "Align") + "' for Attribute 'Align' of Control '" + ctrl.controlName +
                                "' whose Attribute 'Stretch' is set to  '" +
                                ctrl.GetAttribute("Stretch") +
                                "'. Supported values are: left, center, right.");
                        }
                    }
                }
                else if (ctrl.GetAttribute("Stretch").ToLower() == "fully")
                {
                    // Fully stretched
                    writer.SetControlProperty(
                        ctrl,
                        "Anchor",
                        "((System.Windows.Forms.AnchorStyles)(((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right) | System.Windows.Forms.AnchorStyles.Bottom))))");

                    if (ctrl.HasAttribute("Align"))
                    {
                        Console.WriteLine(
                            "WARNING for Control '" + ctrl.controlName +
                            "': Attribute 'Align' gets ignored when Attribute 'Stretch' with value 'fully' is used.");
                    }
                }
                else if (ctrl.GetAttribute("Stretch").ToLower() == "none")
                {
                    // do nothing (here just to avoid throwing the following Exception)
                    Console.WriteLine(
                        "HINT: Attribute 'Stretch' with value 'none' does not affect the layout since this is the default. Control: '" +
                        ctrl.controlName + "'.");
                }
                else
                {
                    throw new Exception("Invalid value for Attribute 'Stretch' of Control '" + ctrl.controlName + "': '" +
                        ctrl.GetAttribute("Stretch") + "'. Supported values are: horizontally, vertically, fully, none.");
                }
            }

            #endregion

            if (ctrl.HasAttribute("Dock"))
            {
                writer.SetControlProperty(ctrl, "Dock");
            }

            if (ctrl.HasAttribute("Visible")
                && (ctrl.GetAttribute("Visible").ToLower() == "false"))
            {
                writer.SetControlProperty(ctrl, "Visible", "false");
            }

            if (ctrl.HasAttribute("Enabled")
                && (ctrl.GetAttribute("Enabled").ToLower() == "false"))
            {
                writer.SetControlProperty(ctrl, "Enabled", "false");
            }
            else if ((ctrl.GetAction() != null) && (TYml2Xml.GetAttribute(ctrl.GetAction().actionNode, "InitiallyEnabled").ToLower() == "false"))
            {
                string ActionEnabling = ctrl.controlName + ".Enabled = false;" + Environment.NewLine;
                writer.Template.AddToCodelet("INITACTIONSTATE", ActionEnabling);
            }

            if (ctrl.HasAttribute("TabStop")
                && (ctrl.GetAttribute("TabStop").ToLower() == "false"))
            {
                writer.SetControlProperty(ctrl, "TabStop", "false");
            }

            if (ctrl.HasAttribute("TabIndex"))
            {
                writer.SetControlProperty(ctrl, "TabIndex", ctrl.GetAttribute("TabIndex"));
            }

            if (ctrl.HasAttribute("BorderStyle"))
            {
                writer.SetControlProperty(ctrl, "BorderStyle", "System.Windows.Forms.BorderStyle." + ctrl.GetAttribute("BorderStyle"));

                if (ctrl.GetAttribute("BorderStyle").ToLower() == "none")
                {
                    writer.SetControlProperty(ctrl, "Margin", "new System.Windows.Forms.Padding(0, 5, 0, 0)");
                }
            }

            if (ctrl.HasAttribute("Padding"))
            {
                writer.SetControlProperty(ctrl, "Padding", "new System.Windows.Forms.Padding(" + ctrl.GetAttribute("Padding") + ")");
            }

            if (ctrl.HasAttribute("Margin"))
            {
                string margin = ctrl.GetAttribute("Margin");

                if (margin != "0")
                {
                    writer.SetControlProperty(ctrl, "Margin", "new System.Windows.Forms.Padding(" + margin + ")");
                }
            }

            if (ctrl.HasAttribute("BackColor"))
            {
                writer.SetControlProperty(ctrl, "BackColor", ctrl.GetAttribute("BackColor"));
            }

            if (ctrl.HasAttribute("AutoScroll"))
            {
                writer.SetControlProperty(ctrl, "AutoScroll", ctrl.GetAttribute("AutoScroll"));
            }

            // needed so that ctrl.Height and ctrl.Width return correct values
            ctrl.SetAttribute("DefaultWidth", FDefaultWidth.ToString());
            ctrl.SetAttribute("DefaultHeight", FDefaultHeight.ToString());

            if (ctrl.HasAttribute("Width") || ctrl.HasAttribute("Height"))
            {
                if (!ctrl.HasAttribute("Width"))
                {
                    ctrl.SetAttribute("Width", FDefaultWidth.ToString());
                }

                if (!ctrl.HasAttribute("Height"))
                {
                    ctrl.SetAttribute("Height", FDefaultHeight.ToString());
                }

                if (ctrl.HasAttribute("Width") && ctrl.HasAttribute("Height"))
                {
                    writer.SetControlProperty(ctrl, "Size", "new System.Drawing.Size(" +
                        ctrl.GetAttribute("Width").ToString() + ", " + ctrl.GetAttribute("Height").ToString() + ")");
                }
            }
            else if (ctrl.GetAttribute("Dock").ToLower() == "fill")
            {
                // no size information for Dock Fill
            }
            else
            {
                writer.SetControlProperty(ctrl, "Size",
                    "new System.Drawing.Size(" + FDefaultWidth.ToString() + ", " + FDefaultHeight.ToString() + ")");
            }

            if (ctrl.HasAttribute("SuppressChangeDetection") && (ctrl.GetAttribute("SuppressChangeDetection").ToLower() == "true"))
            {
                writer.SetControlProperty(ctrl, "Tag", "\"SuppressChangeDetection\"");
            }

            if (ctrl.GetAction() != null)
            {
                string ActionToPerform = ctrl.GetAction().actionName;

                // deal with enabling and disabling of action, affecting the menu item
                if (!writer.Template.FCodelets.Keys.Contains("ENABLEDEPENDINGACTIONS_" + ActionToPerform))
                {
                    string ActionEnabling = "";
                    ActionEnabling += "if (e.ActionName == \"" + ActionToPerform + "\")" + Environment.NewLine;
                    ActionEnabling += "{" + Environment.NewLine;
                    ActionEnabling += "    {#ENABLEDEPENDINGACTIONS_" + ActionToPerform + "}" + Environment.NewLine;
                    ActionEnabling += "}" + Environment.NewLine;
                    writer.Template.AddToCodelet("ACTIONENABLING", ActionEnabling);
                }

                AddToActionEnabledEvent(writer, ActionToPerform, ctrl.controlName);

                // deal with action handler
                if (((ActionToPerform == "actEditFilter") || (ActionToPerform == "actEditFindNext") || (ActionToPerform == "actEditFindPrevious")
                     || (ActionToPerform == "actEditFind")) && !writer.FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind"))
                {
                    // Do nothing unless there is a manual code handler (on screens with user controls)
                    if (writer.FCodeStorage.ManualFileExistsAndContains("void MniFilterFind_Click("))
                    {
                        AssignEventHandlerToControl(writer, ctrl, "Click", "MniFilterFind_Click");
                    }
                    else if (ActionToPerform == "actEditFind")
                    {
                        TLogging.Log("No implementation of actEditFind on this screen");
                    }
                }
                else
                {
                    AssignEventHandlerToControl(writer, ctrl, "Click", ActionToPerform);
                }

                TActionHandler ActionHandler = writer.CodeStorage.FActionList[ActionToPerform];
                SetControlActionProperties(writer, ctrl, ActionHandler);

                string strMniFilterFindClick = "void MniFilterFind_Click(";

                if ((ActionToPerform == "actEditFind") && (ctrl.controlName == "mniEditFind")
                    && (writer.FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind")
                        || writer.FCodeStorage.ManualFileExistsAndContains(strMniFilterFindClick)))
                {
                    writer.SetControlProperty("mniEditFind", "ShortcutKeys", "Keys.F | Keys.Control", false);
                }

                if ((ActionToPerform == "actEditFindNext") && (ctrl.controlName == "mniEditFindNext")
                    && (writer.FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind")
                        || writer.FCodeStorage.ManualFileExistsAndContains(strMniFilterFindClick)))
                {
                    writer.SetControlProperty("mniEditFindNext", "ShortcutKeys", "Keys.F3", false);
                }

                if ((ActionToPerform == "actEditFindPrevious") && (ctrl.controlName == "mniEditFindPrevious")
                    && (writer.FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind")
                        || writer.FCodeStorage.ManualFileExistsAndContains(strMniFilterFindClick)))
                {
                    writer.SetControlProperty("mniEditFindPrevious", "ShortcutKeys", "Keys.F3 | Keys.Shift", false);
                }

                if ((ActionToPerform == "actEditTop") && (ctrl.controlName == "mniEditTop"))
                {
                    writer.SetControlProperty("mniEditTop", "ShortcutKeys", "Keys.Home | Keys.Control", false);
                }

                if ((ActionToPerform == "actEditPrevious") && (ctrl.controlName == "mniEditPrevious"))
                {
                    writer.SetControlProperty("mniEditPrevious", "ShortcutKeys", "Keys.Up | Keys.Control", false);
                }

                if ((ActionToPerform == "actEditNext") && (ctrl.controlName == "mniEditNext"))
                {
                    writer.SetControlProperty("mniEditNext", "ShortcutKeys", "Keys.Down | Keys.Control", false);
                }

                if ((ActionToPerform == "actEditBottom") && (ctrl.controlName == "mniEditBottom"))
                {
                    writer.SetControlProperty("mniEditBottom", "ShortcutKeys", "Keys.End | Keys.Control", false);
                }

                if ((ActionToPerform == "actEditFocusGrid") && (ctrl.controlName == "mniEditFocusGrid"))
                {
                    writer.SetControlProperty("mniEditFocusGrid", "ShortcutKeys", "Keys.G | Keys.Control", false);
                }

                if ((ActionToPerform == "actEditFilter") && (ctrl.controlName == "mniEditFilter")
                    && (writer.FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind")
                        || writer.FCodeStorage.ManualFileExistsAndContains(strMniFilterFindClick)))
                {
                    writer.SetControlProperty("mniEditFilter", "ShortcutKeys", "Keys.R | Keys.Control", false);
                }

                if ((ActionToPerform == "actSave") && (ctrl.controlName == "mniFileSave"))
                {
                    ProcessTemplate snipCtrlS = writer.FTemplate.GetSnippet("PROCESSCMDKEYCTRLS");
                    writer.FTemplate.InsertSnippet("PROCESSCMDKEY", snipCtrlS);
                    writer.SetControlProperty("mniFileSave", "ShortcutKeys", "Keys.S | Keys.Control", false);
                }

                if ((ActionToPerform == "actPrint") && (ctrl.controlName == "mniFilePrint"))
                {
                    writer.SetControlProperty("mniFilePrint", "ShortcutKeys", "Keys.P | Keys.Control", false);
                }

                if (FCodeStorage.ManualFileExistsAndContains(" " + ActionHandler.actionName.Substring(3) + "(Form AParentForm)"))
                {
                    writer.SetEventHandlerFunction(ActionHandler.actionName.Substring(3), "", ActionHandler.actionName.Substring(
                            3) + "(this);");
                }
            }
            else if (ctrl.HasAttribute("ActionClick"))
            {
                if (ctrl.GetAttribute("ActionClick").EndsWith("FilterFind_Click"))
                {
                    // MniFilterFind_Click is part of the base template for many forms.
                    // We only create an action handler if the screen has a pnlFilterAndFind
                    if (writer.FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind"))
                    {
                        AssignEventHandlerToControl(writer, ctrl, "Click", ctrl.GetAttribute("ActionClick"));
                    }
                }
                else
                {
                    // The control is not mniEditFilter or mniEditFind, so just write the resource file item
                    // The manual code file will have the event handler itself
                    AssignEventHandlerToControl(writer, ctrl, "Click", ctrl.GetAttribute("ActionClick"));
                }
            }
            else if (ctrl.HasAttribute("ActionDoubleClick"))
            {
                AssignEventHandlerToControl(writer, ctrl, "DoubleClick", ctrl.GetAttribute("ActionDoubleClick"));
            }
            else if (ctrl.HasAttribute("ActionOpenScreen"))
            {
                AssignEventHandlerToControl(writer, ctrl, "Click", "OpenScreen" + ctrl.controlName.Substring(ctrl.controlTypePrefix.Length));
                string ActionHandler =
                    "/// auto generated" + Environment.NewLine +
                    "protected void OpenScreen" + ctrl.controlName.Substring(ctrl.controlTypePrefix.Length) + "(object sender, EventArgs e)" +
                    Environment.NewLine +
                    "{" + Environment.NewLine;

                string ActionOpenScreen = ctrl.GetAttribute("ActionOpenScreen");
                ActionHandler += "    " + ActionOpenScreen + " frm = new " + ActionOpenScreen +
                                 "(this);" + Environment.NewLine;

                if (ActionOpenScreen.Contains("."))
                {
                    string namespaceOfScreen = ActionOpenScreen.Substring(0, ActionOpenScreen.LastIndexOf("."));
                    writer.Template.AddToCodelet("USINGNAMESPACES", "using " + namespaceOfScreen + ";" + Environment.NewLine, false);
                }

                // Does PropertyForSubScreens fit a property in the new screen? eg LedgerNumber
                if (FCodeStorage.HasAttribute("PropertyForSubScreens"))
                {
                    string propertyName = FCodeStorage.GetAttribute("PropertyForSubScreens");

                    if (FCodeStorage.ImplementationContains(ctrl.GetAttribute("ActionOpenScreen"), " " + propertyName + Environment.NewLine))
                    {
                        ActionHandler += "    frm." + propertyName + " = F" + propertyName + ";" + Environment.NewLine;
                    }
                }

                /*                for (string propertyName in FCodeStorage.GetFittingProperties(ctrl.GetAttribute("ActionOpenScreen")))
                 *              {
                 *                  ActionHandler += "    frm." + propertyName + " = F" + propertyName + ";" + Environment.NewLine;
                 *              }
                 */
                ActionHandler += "    frm.Show();" + Environment.NewLine;
                ActionHandler += "}" + Environment.NewLine + Environment.NewLine;

                FCodeStorage.FActionHandlers += ActionHandler;
            }

            if (ctrl.HasAttribute("Enabled"))
            {
                AddToActionEnabledEvent(writer, ctrl.GetAttribute("Enabled"), ctrl.controlName);
            }

            if (ctrl.HasAttribute("OnChange"))
            {
                AssignEventHandlerToControl(writer, ctrl,
                    GetEventNameForChangeEvent(),
                    GetEventHandlerTypeForChangeEvent(),
                    ctrl.GetAttribute("OnChange"));
            }

            if (ctrl.HasAttribute("OnEnter"))
            {
                AssignEventHandlerToControl(writer, ctrl,
                    "Enter",
                    "System.EventHandler",
                    ctrl.GetAttribute("OnEnter"));
            }

            if (ctrl.HasAttribute("OnLeave"))
            {
                AssignEventHandlerToControl(writer, ctrl,
                    "Leave",
                    "System.EventHandler",
                    ctrl.GetAttribute("OnLeave"));
            }

            if (ctrl.HasAttribute("Tooltip"))
            {
                writer.Template.AddToCodelet("INITUSERCONTROLS", "FPetraUtilsObject.SetStatusBarText(" + ctrl.controlName +
                    ", Catalog.GetString(\"" +
                    ctrl.GetAttribute("Tooltip") +
                    "\"));" + Environment.NewLine);
            }
            else if (ctrl.controlName == "grdDetails")
            {
                writer.Template.AddToCodelet("INITUSERCONTROLS", "FPetraUtilsObject.SetStatusBarText(" + ctrl.controlName +
                    ", Catalog.GetString(\"Use the mouse or navigation keys to select a data row to view or edit\"));" + Environment.NewLine);
            }
            else if (ctrl.controlName == "btnNew")
            {
                writer.Template.AddToCodelet("INITUSERCONTROLS", "FPetraUtilsObject.SetStatusBarText(" + ctrl.controlName +
                    ", Catalog.GetString(\"Click to create a new record\"));" + Environment.NewLine);
            }
            else if (ctrl.controlName == "btnDelete")
            {
                writer.Template.AddToCodelet("INITUSERCONTROLS", "FPetraUtilsObject.SetStatusBarText(" + ctrl.controlName +
                    ", Catalog.GetString(\"Click to delete the highlighted record(s)\"));" + Environment.NewLine);
            }
            else if (ctrl.controlName.StartsWith("spt"))
            {
                writer.Template.AddToCodelet(
                    "INITUSERCONTROLS",
                    "FPetraUtilsObject.SetStatusBarText(" + ctrl.controlName +
                    ", Catalog.GetString(\"Use the arrow keys to change the Splitter position and change the relative proportions of the panels\"));"
                    +
                    Environment.NewLine);
            }

            //TODO: CT
//            if (ctrl.HasAttribute("DefaultValue"))
//            {
//                writer.Template.AddToCodelet("DEFAULTOVERRIDE", UndoValue(ctrl, ;
//            }

//Console.WriteLine("ctrl.controlTypePrefix: " + ctrl.controlName + ": " + ctrl.controlTypePrefix);
            if (ctrl.HasAttribute("PartnerShortNameLookup"))
            {
                LinkControlPartnerShortNameLookup(writer, ctrl);
            }
            else if (ctrl.HasAttribute("DataField"))
            {
                string dataField = ctrl.GetAttribute("DataField");

                TTableField field = TDataBinding.GetTableField(ctrl, dataField, out IsDetailNotMaster, true);

                LinkControlDataField(writer, ctrl, field, IsDetailNotMaster);
                DataFieldUndoCapability(writer, ctrl, field, IsDetailNotMaster);
            }
            else if (writer.CodeStorage.HasAttribute("MasterTable") || writer.CodeStorage.HasAttribute("DetailTable"))
            {
                //if (ctrl.controlTypePrefix != "lbl" && ctrl.controlTypePrefix != "pnl" && ctrl.controlTypePrefix != "grp" &&
                if (!((this is LabelGenerator) || (this is LinkLabelGenerator)))
                {
                    TTableField field = TDataBinding.GetTableField(ctrl, ctrl.controlName.Substring(
                            ctrl.controlTypePrefix.Length), out IsDetailNotMaster, false);

                    if (field != null)
                    {
                        LinkControlDataField(writer, ctrl, field, IsDetailNotMaster);
                        DataFieldUndoCapability(writer, ctrl, field, IsDetailNotMaster);
                    }
                }
            }
            else if (ctrl.controlTypePrefix == "uco")
            {
                AddChildUserControlExtraCalls(writer, ctrl);
            }
            else if (ctrl.HasAttribute("DynamicControlType"))
            {
                writer.Template.AddToCodelet("SAVEDATA", "if(FUco" + ctrl.controlName.Substring(
                        3) + " != null)" + Environment.NewLine + "{" + Environment.NewLine +
                    "    FUco" + ctrl.controlName.Substring(3) + ".GetDataFromControls();" + Environment.NewLine + "}" + Environment.NewLine);
                writer.Template.AddToCodelet("PRIMARYKEYCONTROLSREADONLY", "if(FUco" + ctrl.controlName.Substring(
                        3) + " != null)" + Environment.NewLine + "{" + Environment.NewLine +
                    "    FUco" + ctrl.controlName.Substring(
                        3) + ".SetPrimaryKeyReadOnly(AReadOnly);" + Environment.NewLine + "}" + Environment.NewLine);
            }

            // Allow for adding of child-usercontrol extra calls *even* if the Template has got 'MasterTable' or 'DetailTable' attribute(s) [see above for those checks]
            if ((ctrl.controlTypePrefix == "uco")
                && (writer.CodeStorage.GetAttribute("DependentChildUserControl") == "true"))
            {
                AddChildUserControlExtraCalls(writer, ctrl);
            }

            // the readonly property eg of Textbox still allows tooltips and copy to clipboard, which enable=false would not allow
            if (TYml2Xml.HasAttribute(ctrl.xmlNode, "ReadOnly")
                && (TYml2Xml.GetAttribute(ctrl.xmlNode, "ReadOnly").ToLower() == "true"))
            {
                if (FHasReadOnlyProperty)
                {
                    writer.SetControlProperty(ctrl,
                        "ReadOnly",
                        "true");
                    writer.SetControlProperty(ctrl,
                        "TabStop",
                        "false");
                }
                else
                {
                    writer.SetControlProperty(ctrl,
                        "Enabled",
                        "false");
                }
            }

            if (GenerateDataValidationCode(writer, ctrl, out AutomDataValidation, out ReasonForAutomValidation))
            {
                AssignEventHandlerToControl(writer, ctrl, "Validated", "ControlValidatedHandler");
            }
            else
            {
                bool AssignControlUpdateDataHandler = false;

                if (ctrl.HasAttribute("DataField"))
                {
                    TDataBinding.GetTableField(ctrl, ctrl.GetAttribute("DataField"), out IsDetailNotMaster, true);

                    if (IsDetailNotMaster)
                    {
                        AssignControlUpdateDataHandler = true;
                    }
                }
                else
                {
                    if (writer.CodeStorage.HasAttribute("DetailTable"))
                    {
                        if (!((this is LabelGenerator) || (this is LinkLabelGenerator)))
                        {
                            if (TDataBinding.GetTableField(ctrl, ctrl.controlName.Substring(
                                        ctrl.controlTypePrefix.Length), out IsDetailNotMaster, false) != null)
                            {
                                if (IsDetailNotMaster)
                                {
                                    AssignControlUpdateDataHandler = true;
                                }
                            }
                        }
                    }
                }

                if (AssignControlUpdateDataHandler)
                {
                    if ((!ctrl.controlTypePrefix.StartsWith("mn"))
                        && (!ctrl.controlTypePrefix.StartsWith("tb"))
                        && (ctrl.controlTypePrefix != "pnl")
                        && (ctrl.controlTypePrefix != "grp")
                        && (ctrl.controlTypePrefix != "grd")
                        && (ctrl.controlTypePrefix != "btn")
                        && (ctrl.controlTypePrefix != "stb")
                        && (ctrl.controlTypePrefix != "lbl"))
                    {
                        AssignEventHandlerToControl(writer, ctrl, "Validated", "ControlUpdateDataHandler");
                        writer.Template.SetCodelet("GENERATECONTROLUPDATEDATAHANDLER", "true");
                    }
                }
            }

            return writer.Template;
        }
Exemplo n.º 31
0
        /// <summary>
        /// Generates code for the UNDODATA Snippet.
        /// </summary>
        /// <param name="tablename">Name of table</param>
        /// <param name="fieldname">Name of field</param>
        /// <param name="TestForNullTable"></param>
        /// <param name="writer">FormWriter instance.</param>
        /// <param name="ctrl">TControlDef instance.</param>
        /// <param name="AField">TTableField instance.</param>
        /// <returns>A <see cref="ProcessTemplate"></see>.</returns>
        ProcessTemplate GenerateUndoDataSnippetCode(ref string tablename,
            ref string fieldname,
            ref string TestForNullTable,
            TFormWriter writer,
            TControlDef ctrl,
            TTableField AField)
        {
            ProcessTemplate snippetShowData = writer.Template.GetSnippet("UNDODATAFORCOLUMN");

            snippetShowData.SetCodelet("NOTDEFAULTTABLE", TestForNullTable);

            snippetShowData.SetCodelet("UNDOCONTROLVALUE",
                this.UndoValue(ctrl, "ARow[FMainDS." + tablename + ".Columns[(short)FMainDS." + tablename + ".GetType().GetField(\"Column" +
                    fieldname +
                    "Id\", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy).GetValue(FMainDS." + tablename +
                    ".GetType())], DataRowVersion.Original]",
                    AField.GetDotNetType()));
            snippetShowData.InsertSnippet("UNDOROWVALUE", writer.Template.GetSnippet("UNDOROWVALUE"));

            snippetShowData.SetCodelet("CONTROLNAME", ctrl.controlName);

            return snippetShowData;
        }