Esempio n. 1
0
        /// based on the code model, create the code;
        /// using the code generators that have been loaded
        public override void CreateCode(TCodeStorage ACodeStorage, string ATemplateFile)
        {
            FCodeStorage = ACodeStorage;
            TControlGenerator.FCodeStorage = ACodeStorage;
            FTemplate = new ProcessTemplate(ATemplateFile);
            FFormName = Path.GetFileNameWithoutExtension(YamlFilename).Replace("-", "_");

            // drop language specific part of the name
            if (FFormName.Contains("."))
            {
                FFormName = FFormName.Substring(0, FFormName.IndexOf("."));
            }

            FFormName  = FFormName.ToUpper()[0] + FFormName.Substring(1);
            FFormName += "Form";

            // load default header with license and copyright
            string templateDir = TAppSettingsManager.GetValue("TemplateDir", true);

            FTemplate.AddToCodelet("GPLFILEHEADER",
                                   ProcessTemplate.LoadEmptyFileComment(templateDir + Path.DirectorySeparatorChar + ".." +
                                                                        Path.DirectorySeparatorChar));

            FTemplate.SetCodelet("UPLOADFORM", "");
            FTemplate.SetCodelet("CHECKFORVALIDUPLOAD", "");

            FLanguageFileTemplate = FTemplate.GetSnippet("LANGUAGEFILE");

            // find the first control that is a panel or groupbox or tab control
            if (FCodeStorage.HasRootControl("content"))
            {
                AddRootControl("content");
            }

            InsertCodeIntoTemplate(YamlFilename);

            string languagefilepath = Path.GetDirectoryName(YamlFilename) + Path.DirectorySeparatorChar +
                                      Path.GetFileNameWithoutExtension(YamlFilename) + "-lang-template.js";

            File.WriteAllText(languagefilepath, FLanguageFileTemplate.FinishWriting(true));
        }
Esempio n. 2
0
        private static void CreateLocalisedYamlFile(string ALanguageCode, string AYamlfile)
        {
            TLogging.Log(AYamlfile);

            string localisedYamlFile = AYamlfile.Replace(".yaml", "." + ALanguageCode + ".yaml");

            TYml2Xml parser;
            XmlDocument localisedYamlFileDoc = new XmlDocument();

            if (File.Exists(localisedYamlFile))
            {
                // TODO parse the localised yaml file and add translations to the po file
                parser = new TYml2Xml(localisedYamlFile);
                localisedYamlFileDoc = parser.ParseYML2XML();
            }

            // parse the yaml file
            parser = new TYml2Xml(AYamlfile);
            XmlDocument yamlFile = parser.ParseYML2XML();

            SortedList xmlNodes = new SortedList();
            TCodeStorage CodeStorage = new TCodeStorage(yamlFile, xmlNodes);

            XmlNode RootNode = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "RootNode");
            RootNode.Attributes.RemoveAll();
            TXMLParser.SetAttribute(RootNode, "BaseYaml", Path.GetFileName(AYamlfile));

            // get controls node
            XmlNode Controls = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "Controls");

            if (Controls != null)
            {
                foreach (XmlNode control in Controls)
                {
                    AdjustLabel(control, CodeStorage, localisedYamlFileDoc);
                }
            }

            // get actions node
            XmlNode Actions = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "Actions");

            if (Actions != null)
            {
                foreach (XmlNode action in Actions)
                {
                    AdjustLabel(action, CodeStorage, localisedYamlFileDoc);
                }
            }

            // menu items
            XmlNode menuitems = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "Menu");

            if (menuitems != null)
            {
                foreach (XmlNode menu in menuitems)
                {
                    if (menu.Name.Contains("Separator"))
                    {
                        continue;
                    }

                    AdjustLabel(menu, CodeStorage, localisedYamlFileDoc);
                }
            }

            // toolbar buttons
            XmlNode tbbuttons = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "Toolbar");

            if (tbbuttons != null)
            {
                foreach (XmlNode tbb in tbbuttons)
                {
                    if (tbb.Name.Contains("Separator"))
                    {
                        continue;
                    }

                    AdjustLabel(tbb, CodeStorage, localisedYamlFileDoc);
                }
            }

            // TODO parse the cs file for string constants
            // TODO warn about Catalog.GetString calls in manualcode file
            // TODO add constants to localised yaml file

            TYml2Xml.Xml2Yml(yamlFile, localisedYamlFile);
        }
Esempio n. 3
0
        /// based on the code model, create the code;
        /// using the code generators that have been loaded
        public override void CreateCode(TCodeStorage ACodeStorage, string AXAMLFilename, string ATemplateFile)
        {
            FCodeStorage = ACodeStorage;
            TControlGenerator.FCodeStorage = ACodeStorage;
            FTemplate = new ProcessTemplate(ATemplateFile);
            FFormName = Path.GetFileNameWithoutExtension(AXAMLFilename).Replace("-", "_");

            // drop language specific part of the name
            if (FFormName.Contains("."))
            {
                FFormName = FFormName.Substring(0, FFormName.IndexOf("."));
            }

            FFormName = FFormName.ToUpper()[0] + FFormName.Substring(1);
            FFormName += "Form";

            // load default header with license and copyright
            string templateDir = TAppSettingsManager.GetValue("TemplateDir", true);
            FTemplate.AddToCodelet("GPLFILEHEADER",
                ProcessTemplate.LoadEmptyFileComment(templateDir + Path.DirectorySeparatorChar + ".." +
                    Path.DirectorySeparatorChar));

            FTemplate.SetCodelet("UPLOADFORM", "");
            FTemplate.SetCodelet("CHECKFORVALIDUPLOAD", "");

            FLanguageFileTemplate = FTemplate.GetSnippet("LANGUAGEFILE");

            // find the first control that is a panel or groupbox or tab control
            if (FCodeStorage.HasRootControl("content"))
            {
                AddRootControl("content");
            }

            InsertCodeIntoTemplate(AXAMLFilename);

            string languagefilepath = Path.GetDirectoryName(AXAMLFilename) + Path.DirectorySeparatorChar +
                                      Path.GetFileNameWithoutExtension(AXAMLFilename) + "-lang-template.js";
            File.WriteAllText(languagefilepath, FLanguageFileTemplate.FinishWriting(true));
        }
Esempio n. 4
0
        private static void AdjustLabel(XmlNode node, TCodeStorage CodeStorage, XmlDocument AOrigLocalisedYaml)
        {
            XmlNode TranslatedNode = TXMLParser.FindNodeRecursive(AOrigLocalisedYaml, node.Name);
            string TranslatedLabel = string.Empty;

            if (TranslatedNode != null)
            {
                TranslatedLabel = TXMLParser.GetAttribute(TranslatedNode, "Label");
            }

            TControlDef ctrlDef = new TControlDef(node, CodeStorage);
            string Label = ctrlDef.Label;

            if ((ctrlDef.GetAttribute("NoLabel") == "true") || (ctrlDef.controlTypePrefix == "pnl")
                || (TXMLParser.FindNodeRecursive(node.OwnerDocument, "act" + ctrlDef.controlName.Substring(ctrlDef.controlTypePrefix.Length)) != null)
                || ctrlDef.GetAttribute("Action").StartsWith("act"))
            {
                Label = string.Empty;
            }

            if ((ctrlDef.controlTypePrefix == "rgr") && (TXMLParser.GetChild(node, "OptionalValues") != null))
            {
                ProcessRadioGroupLabels(node);
            }
            else if (ctrlDef.controlTypePrefix == "mni")
            {
                // drop all attributes
                node.Attributes.RemoveAll();

                foreach (XmlNode menu in node.ChildNodes)
                {
                    if (menu.Name.Contains("Separator"))
                    {
                        continue;
                    }

                    AdjustLabel(menu, CodeStorage, AOrigLocalisedYaml);
                }
            }
            else
            {
                // drop all attributes and children nodes
                node.RemoveAll();
            }

            if (Label.Length > 0)
            {
                if ((TranslatedLabel != Label) && (TranslatedLabel != Catalog.GetString(Label)) && (TranslatedLabel.Length > 0))
                {
                    // add to po file
                    if (!NewTranslations.ContainsKey(Label))
                    {
                        NewTranslations.Add(Label, TranslatedLabel);
                    }

                    TXMLParser.SetAttribute(node, "Label", TranslatedLabel);
                }
                else
                {
                    TXMLParser.SetAttribute(node, "Label", Catalog.GetString(Label));
                }
            }
        }
Esempio n. 5
0
        private static void AdjustLabel(XmlNode node, TCodeStorage CodeStorage, XmlDocument AOrigLocalisedYaml)
        {
            XmlNode TranslatedNode  = TXMLParser.FindNodeRecursive(AOrigLocalisedYaml, node.Name);
            string  TranslatedLabel = string.Empty;

            if (TranslatedNode != null)
            {
                TranslatedLabel = TXMLParser.GetAttribute(TranslatedNode, "Label");
            }

            TControlDef ctrlDef = new TControlDef(node, CodeStorage);
            string      Label   = ctrlDef.Label;

            if ((ctrlDef.GetAttribute("NoLabel") == "true") || (ctrlDef.controlTypePrefix == "pnl") ||
                (TXMLParser.FindNodeRecursive(node.OwnerDocument, "act" + ctrlDef.controlName.Substring(ctrlDef.controlTypePrefix.Length)) != null) ||
                ctrlDef.GetAttribute("Action").StartsWith("act"))
            {
                Label = string.Empty;
            }

            if ((ctrlDef.controlTypePrefix == "rgr") && (TXMLParser.GetChild(node, "OptionalValues") != null))
            {
                ProcessRadioGroupLabels(node);
            }
            else if (ctrlDef.controlTypePrefix == "mni")
            {
                // drop all attributes
                node.Attributes.RemoveAll();

                foreach (XmlNode menu in node.ChildNodes)
                {
                    if (menu.Name.Contains("Separator"))
                    {
                        continue;
                    }

                    AdjustLabel(menu, CodeStorage, AOrigLocalisedYaml);
                }
            }
            else
            {
                // drop all attributes and children nodes
                node.RemoveAll();
            }

            if (Label.Length > 0)
            {
                if ((TranslatedLabel != Label) && (TranslatedLabel != Catalog.GetString(Label)) && (TranslatedLabel.Length > 0))
                {
                    // add to po file
                    if (!NewTranslations.ContainsKey(Label))
                    {
                        NewTranslations.Add(Label, TranslatedLabel);
                    }

                    TXMLParser.SetAttribute(node, "Label", TranslatedLabel);
                }
                else
                {
                    TXMLParser.SetAttribute(node, "Label", Catalog.GetString(Label));
                }
            }
        }
Esempio n. 6
0
        private static void CreateLocalisedYamlFile(string ALanguageCode, string AYamlfile)
        {
            TLogging.Log(AYamlfile);

            string localisedYamlFile = AYamlfile.Replace(".yaml", "." + ALanguageCode + ".yaml");

            TYml2Xml    parser;
            XmlDocument localisedYamlFileDoc = new XmlDocument();

            if (File.Exists(localisedYamlFile))
            {
                // TODO parse the localised yaml file and add translations to the po file
                parser = new TYml2Xml(localisedYamlFile);
                localisedYamlFileDoc = parser.ParseYML2XML();
            }

            // parse the yaml file
            parser = new TYml2Xml(AYamlfile);
            XmlDocument yamlFile = parser.ParseYML2XML();

            SortedList   xmlNodes    = new SortedList();
            TCodeStorage CodeStorage = new TCodeStorage(yamlFile, xmlNodes);

            XmlNode RootNode = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "RootNode");

            RootNode.Attributes.RemoveAll();
            TXMLParser.SetAttribute(RootNode, "BaseYaml", Path.GetFileName(AYamlfile));

            // get controls node
            XmlNode Controls = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "Controls");

            if (Controls != null)
            {
                foreach (XmlNode control in Controls)
                {
                    AdjustLabel(control, CodeStorage, localisedYamlFileDoc);
                }
            }

            // get actions node
            XmlNode Actions = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "Actions");

            if (Actions != null)
            {
                foreach (XmlNode action in Actions)
                {
                    AdjustLabel(action, CodeStorage, localisedYamlFileDoc);
                }
            }

            // menu items
            XmlNode menuitems = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "Menu");

            if (menuitems != null)
            {
                foreach (XmlNode menu in menuitems)
                {
                    if (menu.Name.Contains("Separator"))
                    {
                        continue;
                    }

                    AdjustLabel(menu, CodeStorage, localisedYamlFileDoc);
                }
            }

            // toolbar buttons
            XmlNode tbbuttons = TXMLParser.FindNodeRecursive(yamlFile.DocumentElement, "Toolbar");

            if (tbbuttons != null)
            {
                foreach (XmlNode tbb in tbbuttons)
                {
                    if (tbb.Name.Contains("Separator"))
                    {
                        continue;
                    }

                    AdjustLabel(tbb, CodeStorage, localisedYamlFileDoc);
                }
            }

            // TODO parse the cs file for string constants
            // TODO warn about Catalog.GetString calls in manualcode file
            // TODO add constants to localised yaml file

            TYml2Xml.Xml2Yml(yamlFile, localisedYamlFile);
        }
Esempio n. 7
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;
                }

                writer.YamlFilename = FYamlFilename;

                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();
                string manualCodeFile = writer.CalculateManualCodeFilename();

                // 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, template);

                writer.CreateResourceFile(templateDir);

                writer.CreateDesignerFile(rootNode, templateDir);

                return writer.WriteFile(destinationFile);
            }

            return false;
        }
Esempio n. 8
0
        /// based on the code model, create the code;
        /// using the code generators that have been loaded
        public override void CreateCode(TCodeStorage ACodeStorage, string AXAMLFilename, string ATemplateFile)
        {
            ResetAllValues();
            FCodeStorage = ACodeStorage;
            TControlGenerator.FCodeStorage = ACodeStorage;
            FTemplate = new ProcessTemplate(ATemplateFile);

            // load default header with license and copyright
            string templateDir = TAppSettingsManager.GetValue("TemplateDir", true);
            FTemplate.AddToCodelet("GPLFILEHEADER",
                ProcessTemplate.LoadEmptyFileComment(templateDir + Path.DirectorySeparatorChar + ".." +
                    Path.DirectorySeparatorChar));

            // init some template variables that can be empty
            FTemplate.AddToCodelet("INITUSERCONTROLS", "");
            FTemplate.AddToCodelet("INITMANUALCODE", "");
            FTemplate.AddToCodelet("GRIDMULTISELECTION", "");
            FTemplate.AddToCodelet("GRIDHEADERTOOLTIP", "");
            FTemplate.AddToCodelet("RUNONCEONACTIVATIONMANUAL", "");
            FTemplate.AddToCodelet("RUNONCEONPARENTACTIVATIONMANUAL", "");
            FTemplate.AddToCodelet("USERCONTROLSRUNONCEONACTIVATION", "");
            FTemplate.AddToCodelet("SETINITIALFOCUS", "");
            FTemplate.AddToCodelet("EXITMANUALCODE", "");
            FTemplate.AddToCodelet("CANCLOSEMANUAL", "");
            FTemplate.AddToCodelet("INITNEWROWMANUAL", "");
            FTemplate.AddToCodelet("DELETERECORD", "");
            FTemplate.AddToCodelet("DELETEREFERENCECOUNT", "");
            FTemplate.AddToCodelet("MULTIDELETEREFERENCECOUNT", "");
            FTemplate.AddToCodelet("ENABLEDELETEBUTTON", "");
            FTemplate.AddToCodelet("CANDELETESELECTION", "");
            FTemplate.AddToCodelet("CANDELETEROW", "");
            FTemplate.AddToCodelet("SELECTTABMANUAL", "");
            FTemplate.AddToCodelet("STOREMANUALCODE", "");
            FTemplate.AddToCodelet("FINDANDFILTERHOOKUPEVENTS", "");
            FTemplate.AddToCodelet("ACTIONENABLINGDISABLEMISSINGFUNCS", "");
            FTemplate.AddToCodelet("PRIMARYKEYCONTROLSREADONLY", "");
            FTemplate.AddToCodelet("SHOWDETAILSMANUAL", "");
            FTemplate.AddToCodelet("PREPROCESSCMDKEY", "");
            FTemplate.AddToCodelet("PROCESSCMDKEY", "");
            FTemplate.AddToCodelet("PROCESSCMDKEYCTRLF", "");
            FTemplate.AddToCodelet("PROCESSCMDKEYCTRLR", "");
            FTemplate.AddToCodelet("PROCESSCMDKEYMANUAL", "");
            FTemplate.AddToCodelet("FOCUSFIRSTEDITABLEDETAILSPANELCONTROL", "");
            FTemplate.AddToCodelet("CLEARDETAILS", "");
            FTemplate.AddToCodelet("CATALOGI18N", "");
            FTemplate.AddToCodelet("DYNAMICTABPAGEUSERCONTROLENUM", "");
            FTemplate.AddToCodelet("DYNAMICTABPAGEUSERCONTROLINITIALISATION", "");
            FTemplate.AddToCodelet("DYNAMICTABPAGEUSERCONTROLLOADING", "");
            FTemplate.AddToCodelet("ASSIGNFONTATTRIBUTES", "");
            FTemplate.AddToCodelet("CUSTOMDISPOSING", "");
            FTemplate.AddToCodelet("DYNAMICTABPAGEUSERCONTROLDECLARATION", "");
            FTemplate.AddToCodelet("DYNAMICTABPAGEBASICS", "");
            FTemplate.AddToCodelet("IGNOREFIRSTTABPAGESELECTIONCHANGEDEVENT", "");
            FTemplate.AddToCodelet("DYNAMICTABPAGEUSERCONTROLSETUPMETHODS", "");
            FTemplate.AddToCodelet("ELSESTATEMENT", "");
//          FTemplate.AddToCodelet("VALIDATEDETAILS", "");


            FTemplate.AddToCodelet("INITACTIONSTATE", "FPetraUtilsObject.InitActionState();" + Environment.NewLine);

            CallHandlerIfProvided("void BeforeShowDetailsManual", "SHOWDETAILS", "BeforeShowDetailsManual(ARow);");
            CallHandlerIfProvided("InitializeManualCode", "INITMANUALCODE", "InitializeManualCode();");
            CallHandlerIfProvided("RunOnceOnActivationManual", "RUNONCEONACTIVATIONMANUAL", "RunOnceOnActivationManual();");
            CallHandlerIfProvided("RunOnceOnParentActivationManual", "RUNONCEONPARENTACTIVATIONMANUAL", "RunOnceOnParentActivationManual();");
            CallHandlerIfProvided("ExitManualCode", "EXITMANUALCODE", "ExitManualCode();");
            CallHandlerIfProvided("CanCloseManual", "CANCLOSEMANUAL", " && CanCloseManual()");
            CallHandlerIfProvided("NewRowManual", "INITNEWROWMANUAL", "NewRowManual(ref NewRow);");
            CallHandlerIfProvided("StoreManualCode", "STOREMANUALCODE", "SubmissionResult = StoreManualCode(ref SubmitDS, out VerificationResult);");
            CallHandlerIfProvided("FindAndFilterHookUpEvents", "FINDANDFILTERHOOKUPEVENTS", "FindAndFilterHookUpEvents();");
            CallHandlerIfProvided("PreProcessCommandKey", "PREPROCESSCMDKEY", "PreProcessCommandKey();");

            if (FCodeStorage.ManualFileExistsAndContains("SelectTabManual"))
            {
                FTemplate.AddToCodelet("SELECTTABMANUAL",
                    "//Call code to execute on selection of new tab" + Environment.NewLine);
            }

            if (FCodeStorage.ManualFileExistsAndContains("PreDeleteManual"))
            {
                FTemplate.AddToCodelet("HASPREDELETEMANUAL", "true");
            }

            if (FCodeStorage.ManualFileExistsAndContains("DeleteRowManual"))
            {
                FTemplate.AddToCodelet("HASDELETEROWMANUAL", "true");
            }

            if (FCodeStorage.ManualFileExistsAndContains("PostDeleteManual"))
            {
                FTemplate.AddToCodelet("HASPOSTDELETEMANUAL", "true");
            }

            if (FCodeStorage.ManualFileExistsAndContains("GetChangedRecordCountManual"))
            {
                FTemplate.AddToCodelet("GETCHANGEDRECORDCOUNT", "return GetChangedRecordCountManual(out AMessage);");
            }
            else
            {
                FTemplate.AddToCodelet("GETCHANGEDRECORDCOUNT", "return FPetraUtilsObject.GetChangedRecordCount(FMainDS, out AMessage);");
            }

            if (FTemplate.FSnippets.ContainsKey("PROCESSCMDKEYCTRLL"))
            {
                if (FCodeStorage.FControlList.ContainsKey("grdDetails") && !FCodeStorage.FControlList["grdDetails"].HasAttribute("IgnoreEditMove]"))
                {
                    ProcessTemplate snipCtrlL = FTemplate.GetSnippet("PROCESSCMDKEYCTRLL");
                    FTemplate.InsertSnippet("PROCESSCMDKEY", snipCtrlL);

                    if (FCodeStorage.FControlList.ContainsKey("pnlDetails"))
                    {
                        ProcessTemplate snipCtrlE = FTemplate.GetSnippet("PROCESSCMDKEYCTRLE");
                        FTemplate.InsertSnippet("PROCESSCMDKEY", snipCtrlE);

                        ProcessTemplate snipSelectRow = FTemplate.GetSnippet("PROCESSCMDKEYSELECTROW");
                        FTemplate.InsertSnippet("PROCESSCMDKEY", snipSelectRow);

                        if (FCodeStorage.ManualFileExistsAndContains("void FocusFirstEditableControlManual()"))
                        {
                            FTemplate.SetCodelet("FOCUSFIRSTEDITABLEDETAILSPANELCONTROL", "FocusFirstEditableControlManual();" + Environment.NewLine);
                        }
                        else
                        {
                            ProcessTemplate snipFocusFirstControl = FTemplate.GetSnippet("FOCUSFIRSTDETAILSPANELCONTROL");
                            FTemplate.InsertSnippet("FOCUSFIRSTEDITABLEDETAILSPANELCONTROL", snipFocusFirstControl);
                        }
                    }
                }

                if (FCodeStorage.ManualFileExistsAndContains("ProcessCmdKeyManual(ref"))
                {
                    ProcessTemplate snipCmdKeyManual = FTemplate.GetSnippet("PROCESSCMDKEYMANUAL");
                    FTemplate.InsertSnippet("PROCESSCMDKEYMANUAL", snipCmdKeyManual);
                }
            }

            if ((FTemplate.FSnippets.ContainsKey("PROCESSCMDKEYCTRLF")) && (FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind")))
            {
                ProcessTemplate snipCtrlF = FTemplate.GetSnippet("PROCESSCMDKEYCTRLF");

                if (FCodeStorage.FActionList.ContainsKey("actEditFind"))
                {
                    snipCtrlF.SetCodelet("ACTIONCLICK", FCodeStorage.FActionList["actEditFind"].actionClick);
                }
                else
                {
                    snipCtrlF.SetCodelet("ACTIONCLICK", "MniFilterFind_Click");
                }

                FTemplate.InsertSnippet("PROCESSCMDKEY", snipCtrlF);
            }

            if ((FTemplate.FSnippets.ContainsKey("PROCESSCMDKEYCTRLR")) && (FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind")))
            {
                ProcessTemplate snipCtrlR = FTemplate.GetSnippet("PROCESSCMDKEYCTRLR");

                if (FCodeStorage.FActionList.ContainsKey("actEditFilter"))
                {
                    snipCtrlR.SetCodelet("ACTIONCLICK", FCodeStorage.FActionList["actEditFilter"].actionClick);
                }
                else
                {
                    snipCtrlR.SetCodelet("ACTIONCLICK", "MniFilterFind_Click");
                }

                FTemplate.InsertSnippet("PROCESSCMDKEY", snipCtrlR);
            }

            if (FCodeStorage.HasAttribute("DatasetType"))
            {
                FTemplate.SetCodelet("DATASETTYPE", FCodeStorage.GetAttribute("DatasetType"));
                FTemplate.SetCodelet("SHORTDATASETTYPE",
                    FCodeStorage.GetAttribute("DatasetType").Substring(FCodeStorage.GetAttribute("DatasetType").LastIndexOf(".") + 1));
                FTemplate.SetCodelet("MANAGEDDATASETORTYPE", "true");
            }
            else
            {
                FTemplate.SetCodelet("DATASETTYPE", String.Empty);
            }

//    FTemplate.SetCodelet("MANAGEDDATASETORTYPE", "true");

            XmlNode UsingNamespacesNode = TYml2Xml.GetChild(FCodeStorage.FRootNode, "UsingNamespaces");

            if (UsingNamespacesNode != null)
            {
                foreach (string s in TYml2Xml.GetElements(FCodeStorage.FRootNode, "UsingNamespaces"))
                {
                    FTemplate.AddToCodelet("USINGNAMESPACES", "using " + s + ";" + Environment.NewLine);
                }
            }
            else
            {
                FTemplate.AddToCodelet("USINGNAMESPACES", "");
            }

            SortedList <string, TTable>DataSetTables = null;

            // load the dataset if there is a dataset defined for this screen. this allows us to reference customtables and custom fields
            if (FCodeStorage.HasAttribute("DatasetType"))
            {
                DataSetTables = TDataBinding.LoadDatasetTables(CSParser.ICTPath, FCodeStorage.GetAttribute("DatasetType"), FCodeStorage);
            }
            else
            {
                TDataBinding.FCodeStorage = FCodeStorage;
                TDataBinding.ResetCurrentDataset();
            }

            if (FCodeStorage.HasAttribute("MasterTable"))
            {
                if ((DataSetTables != null) && DataSetTables.ContainsKey(FCodeStorage.GetAttribute("MasterTable")))
                {
                    TTable table = DataSetTables[FCodeStorage.GetAttribute("MasterTable")];
                    FTemplate.AddToCodelet("MASTERTABLE", table.strVariableNameInDataset);
                    FTemplate.AddToCodelet("MASTERTABLETYPE", table.strDotNetName);
                    FTemplate.SetCodelet("SHAREDVALIDATIONNAMESPACEMODULE",
                        String.Format("Ict.Petra.Shared.{0}.Validation",
                            TTable.GetNamespace(table.strGroup)));
                }
                else
                {
                    FTemplate.AddToCodelet("MASTERTABLE", FCodeStorage.GetAttribute("MasterTable"));

                    TTable table = TDataBinding.FPetraXMLStore.GetTable(FCodeStorage.GetAttribute("MasterTable"));
                    FTemplate.SetCodelet("SHAREDVALIDATIONNAMESPACEMODULE",
                        String.Format("Ict.Petra.Shared.{0}.Validation",
                            TTable.GetNamespace(table.strGroup)));

                    if (FCodeStorage.HasAttribute("MasterTableType"))
                    {
                        FTemplate.AddToCodelet("MASTERTABLETYPE", FCodeStorage.GetAttribute("MasterTableType"));
                    }
                    else
                    {
                        FTemplate.AddToCodelet("MASTERTABLETYPE", FCodeStorage.GetAttribute("MasterTable"));
                    }
                }
            }
            else
            {
                FTemplate.AddToCodelet("MASTERTABLE", "");
                FTemplate.AddToCodelet("MASTERTABLETYPE", "");
            }

            if (FCodeStorage.HasAttribute("DetailTable"))
            {
                string detailTable;

                if ((DataSetTables != null) && DataSetTables.ContainsKey(FCodeStorage.GetAttribute("DetailTable")))
                {
                    TTable table = DataSetTables[FCodeStorage.GetAttribute("DetailTable")];

                    if (table == null)
                    {
                        throw new Exception("invalid DetailTable, does not exist: " + FCodeStorage.GetAttribute("DetailTable"));
                    }

                    FTemplate.SetCodelet("SHAREDVALIDATIONNAMESPACEMODULE",
                        String.Format("Ict.Petra.Shared.{0}.Validation",
                            TTable.GetNamespace(table.strGroup)));

                    detailTable = table.strVariableNameInDataset;
                    FTemplate.AddToCodelet("DETAILTABLE", detailTable);
                    FTemplate.AddToCodelet("DETAILTABLETYPE", table.strDotNetName);
                }
                else
                {
                    detailTable = FCodeStorage.GetAttribute("DetailTable");
                    FTemplate.AddToCodelet("DETAILTABLE", detailTable);
                    FTemplate.AddToCodelet("DETAILTABLETYPE", detailTable);

                    TTable table = TDataBinding.FPetraXMLStore.GetTable(detailTable);
                    FTemplate.SetCodelet("SHAREDVALIDATIONNAMESPACEMODULE",
                        String.Format("Ict.Petra.Shared.{0}.Validation",
                            TTable.GetNamespace(table.strGroup)));
                }

                if ((FTemplate.FSnippets.Keys.Contains("INLINETYPEDDATASET"))
                    && (!FCodeStorage.HasAttribute("DatasetType")))
                {
                    ProcessTemplate inlineTypedDataSetSnippet = FTemplate.GetSnippet("INLINETYPEDDATASET");
                    inlineTypedDataSetSnippet.SetCodelet("DETAILTABLE", detailTable);

                    FTemplate.InsertSnippet("INLINETYPEDDATASET", inlineTypedDataSetSnippet);
                }
            }
            else
            {
                FTemplate.AddToCodelet("DETAILTABLE", "");
                FTemplate.AddToCodelet("DETAILTABLETYPE", "");
            }

            if (FCodeStorage.HasAttribute("TempTableName"))
            {
                FTemplate.AddToCodelet("TEMPTABLENAME", FCodeStorage.GetAttribute("TempTableName"));
            }

            if (FCodeStorage.HasAttribute("CacheableTable"))
            {
                FTemplate.AddToCodelet("CACHEABLETABLE", "\"" + FCodeStorage.GetAttribute("CacheableTable") + "\"");

                if (FCodeStorage.HasAttribute("CacheableTableSpecificFilter"))
                {
                    FTemplate.AddToCodelet("FILTERVAR", "object FFilter;");

                    string CacheableTableSpecificFilter = FCodeStorage.GetAttribute("CacheableTableSpecificFilter");

                    if (CacheableTableSpecificFilter.StartsWith("\""))
                    {
                        FTemplate.AddToCodelet("LOADDATAONCONSTRUCTORRUN", "LoadDataAndFinishScreenSetup();");
                        FTemplate.AddToCodelet("CACHEABLETABLERETRIEVEMETHOD", "GetCacheableDataTableFromCache");
                        FTemplate.AddToCodelet("DISPLAYFILTERINFORMTITLE", "this.Text = this.Text + \"   [Filtered]\";");
                        FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERLOAD", "" + CacheableTableSpecificFilter + ", FFilter");
                        FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERSAVE", ", " + CacheableTableSpecificFilter + ", FFilter");
                    }
                    else
                    {
                        FTemplate.AddToCodelet("LOADDATAONCONSTRUCTORRUN",
                            "// LoadDataAndFinishScreenSetup() needs to be called manually after setting FFilter!");
                        FTemplate.AddToCodelet("CACHEABLETABLERETRIEVEMETHOD", "GetSpecificallyFilteredCacheableDataTableFromCache");
                        FTemplate.AddToCodelet("DISPLAYFILTERINFORMTITLE",
                            "this.Text = this.Text + \"   [" + CacheableTableSpecificFilter + " = \" + FFilter.ToString() + \"]\";");
                        FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERLOAD", "\"" + CacheableTableSpecificFilter + "\", FFilter");
                        FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERSAVE", ", FFilter");
                    }

                    FTemplate.AddToCodelet("CACHEABLETABLESAVEMETHOD", "SaveSpecificallyFilteredCacheableDataTableToPetraServer");
                    //FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERSAVE", "FFilter, out VerificationResult");
                }
                else
                {
                    FTemplate.AddToCodelet("FILTERVAR", "");
                    FTemplate.AddToCodelet("DISPLAYFILTERINFORMTITLE", "");
                    FTemplate.AddToCodelet("LOADDATAONCONSTRUCTORRUN", "LoadDataAndFinishScreenSetup();");
                    FTemplate.AddToCodelet("CACHEABLETABLERETRIEVEMETHOD", "GetCacheableDataTableFromCache");
                    FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERLOAD", "String.Empty, null");
                    FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERSAVE", "");
                    FTemplate.AddToCodelet("CACHEABLETABLESAVEMETHOD", "SaveChangedCacheableDataTableToPetraServer");
                    //FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERSAVE", "out VerificationResult");
                }
            }

            if (FCodeStorage.HasAttribute("GenerateGetSelectedDetailRow")
                && (FCodeStorage.GetAttribute("GenerateGetSelectedDetailRow") == "true"))
            {
                FTemplate.AddToCodelet("GENERATEGETSELECTEDDETAILROW", "true");
            }

            if (FCodeStorage.HasAttribute("MultipleMasterRows")
                && (FCodeStorage.GetAttribute("MultipleMasterRows") == "true"))
            {
                FTemplate.AddToCodelet("MULTIPLEMASTERROWS", "true");
            }

            // Note - this IF clause needs to be the same as the one in generateReferenceCountConnectors.cs which is generating the server side code
            // Do Ctrl+F to find: this IF clause needs to be the same
            // in that file
            if ((FCodeStorage.GetAttribute("DetailTable") != String.Empty)
                && (FCodeStorage.FControlList.ContainsKey("btnDelete")
                    || FCodeStorage.FControlList.ContainsKey("btnDeleteType")
                    || FCodeStorage.FControlList.ContainsKey("btnDeleteExtract")
                    || FCodeStorage.FControlList.ContainsKey("btnDeleteDetail")
                    || (FCodeStorage.FControlList.ContainsKey("btnRemoveDetail") && (FCodeStorage.GetAttribute("FormType") != "report"))))
            {
                // We always auto-generate code to calculate the record reference count when a delete button exists unless specified in YAML
                if (TYml2Xml.GetAttribute((XmlNode)FCodeStorage.FXmlNodes["actDelete"], "SkipReferenceCheck").ToLower() != "true")
                {
                    AddDeleteReferenceCountImplementation();
                }

                // The generated code only writes the delete button event handler if there is a delete button and there is no manual code to handle the event
                if ((FCodeStorage.FActionList.ContainsKey("actDelete") && (FCodeStorage.FActionList["actDelete"].actionClick != "DeleteRecord"))
                    || FCodeStorage.ManualFileExistsAndContains("btnDelete.Click +=")
                    || FCodeStorage.ManualFileExistsAndContains("void DeleteRecord(")
                    || FCodeStorage.ManualFileExistsAndContains("void DeleteDetail(")
                    || FCodeStorage.ManualFileExistsAndContains("void DeleteRow(")
                    || FCodeStorage.ManualFileExistsAndContains("void RemoveDetail("))
                {
                    // Handled by manual code
                    Console.WriteLine("Skipping DeleteRecord() handler because it is handled by " +
                        Path.GetFileNameWithoutExtension(FCodeStorage.FManualCodeFilename));
                }
                else
                {
                    // Write the event handler to call the DeleteTableName() method
                    string deleteRecord = String.Format(
                        "{1}{0}private void DeleteRecord(Object sender, EventArgs e){1}{0}{{{1}{0}{0}Delete{2}();{1}{0}}}{1}{1}",
                        "    ",
                        Environment.NewLine,
                        FCodeStorage.GetAttribute("DetailTable"));
                    FTemplate.AddToCodelet("DELETERECORD", deleteRecord);

                    ProcessTemplate snippetCanDelete = FTemplate.GetSnippet("SNIPCANDELETESELECTION");
                    ProcessTemplate snippetCanDeleteRow = FTemplate.GetSnippet("SNIPCANDELETEROW");
                    bool bRequiresCanDeleteSelection = false;

                    // Write the one-line codelet that handles enable/disable of the delete button
                    string enableDelete = "btnDelete.Enabled = pnlDetails.Enabled";
                    string enableDeleteExtra = " && CanDeleteSelection()";

                    if (FCodeStorage.FControlList.ContainsKey("chkDetailDeletable")
                        || FCodeStorage.FControlList.ContainsKey("chkDeletable"))
                    {
                        enableDelete += enableDeleteExtra;
                        snippetCanDelete.SetCodelet("DELETEABLEFLAG", "Deletable");
                        snippetCanDeleteRow.SetCodelet("DELETEABLEFLAG", "Deletable");
                        bRequiresCanDeleteSelection = true;
                    }
                    else if (FCodeStorage.FControlList.ContainsKey("chkDetailDeletableFlag")
                             || FCodeStorage.FControlList.ContainsKey("chkDeletableFlag"))
                    {
                        enableDelete += enableDeleteExtra;
                        snippetCanDelete.SetCodelet("DELETEABLEFLAG", "DeletableFlag");
                        snippetCanDeleteRow.SetCodelet("DELETEABLEFLAG", "DeletableFlag");
                        bRequiresCanDeleteSelection = true;
                    }
                    else if (FCodeStorage.FControlList.ContainsKey("chkDetailTypeDeletable"))
                    {
                        enableDelete += enableDeleteExtra;
                        snippetCanDelete.SetCodelet("DELETEABLEFLAG", "TypeDeletable");
                        snippetCanDeleteRow.SetCodelet("DELETEABLEFLAG", "TypeDeletable");
                        bRequiresCanDeleteSelection = true;
                    }

                    enableDelete += ";" + Environment.NewLine;
                    FTemplate.AddToCodelet("ENABLEDELETEBUTTON", enableDelete);

                    if (bRequiresCanDeleteSelection)
                    {
                        snippetCanDelete.SetCodelet("DETAILTABLE", FCodeStorage.GetAttribute("DetailTable"));
                        FTemplate.InsertSnippet("CANDELETESELECTION", snippetCanDelete);
                        snippetCanDeleteRow.SetCodelet("DETAILTABLE", FCodeStorage.GetAttribute("DetailTable"));
                        FTemplate.InsertSnippet("CANDELETEROW", snippetCanDeleteRow);
                    }
                }
            }

            if (FTemplate.FCodelets["CANDELETEROW"].ToString() == String.Empty)
            {
                FTemplate.SetCodelet("CANDELETEROW", "return true;");
            }

            // find the first control that is a panel or groupbox or tab control
            if (FCodeStorage.HasRootControl("content"))
            {
                AddRootControl("content");
            }

            // Toolbar
            if (FCodeStorage.HasRootControl("tbr"))
            {
                AddRootControl("tbr");
            }

            // Main Menu
            if (FCodeStorage.HasRootControl("mnu"))
            {
                AddRootControl("mnu");
            }

            // Statusbar
            if (FCodeStorage.HasRootControl("stb"))
            {
                AddRootControl("stb");
            }

            // check for controls that have no parent
            List <TControlDef>orphans = FCodeStorage.GetOrphanedControls();

            if (orphans.Count > 0)
            {
                string msg = String.Empty;

                foreach (TControlDef o in orphans)
                {
                    msg += o.controlName + " ";
                }

                TLogging.Log("Warning !!! There are some controls that will not be part of the screen (missing parent control?): " + msg);
            }

            // add form events
            foreach (TEventHandler handler in FCodeStorage.FEventList.Values)
            {
                SetEventHandlerForForm(handler);
            }

            foreach (TReportParameter ReportPara in FCodeStorage.FReportParameterList.Values)
            {
                AddReportParameterImplementaion(ReportPara);
            }

            XmlNode rootNode = (XmlNode)FCodeStorage.FXmlNodes[TParseYAMLFormsDefinition.ROOTNODEYML];

            if (TYml2Xml.HasAttribute(rootNode, "UIConnectorType") && TYml2Xml.HasAttribute(rootNode, "UIConnectorCreate"))
            {
                FTemplate.AddToCodelet("UICONNECTORTYPE", TYml2Xml.GetAttribute(rootNode, "UIConnectorType"));
                FTemplate.AddToCodelet("UICONNECTORCREATE", TYml2Xml.GetAttribute(rootNode, "UIConnectorCreate"));
            }

            HandleWebConnectors(TYml2Xml.GetAttribute(rootNode, "Namespace"));

            if (TYml2Xml.HasAttribute(rootNode, "Icon"))
            {
                string iconFileName = TYml2Xml.GetAttribute(rootNode, "Icon");
                FTemplate.AddToCodelet("ADDMAINCONTROLS",
                    "this.Icon = (System.Drawing.Icon)resources.GetObject(\"$this.Icon\");" + Environment.NewLine);
                AddImageToResource("$this.Icon", iconFileName, "Icon");
            }

            if (FCodeStorage.FEventHandler.Contains("KeyEventHandler(this.Form_KeyDown)"))
            {
                // forms that have a KeyDown handler will need KeyPreview
                FTemplate.AddToCodelet("ADDMAINCONTROLS", "this.KeyPreview = true;" + Environment.NewLine);
            }

            string initialFocusControl = String.Empty;

            if (FCodeStorage.FControlList.ContainsKey("grdDetails"))
            {
                initialFocusControl = "grdDetails";
            }

            if (TYml2Xml.HasAttribute(rootNode, "InitialFocus"))
            {
                string tryFocus = TYml2Xml.GetAttribute(rootNode, "InitialFocus");

                if (FCodeStorage.FControlList.ContainsKey(tryFocus))
                {
                    initialFocusControl = tryFocus;
                }
                else
                {
                    TLogging.Log("Warning !!! Cannot set initial focus.  The specified control was not found: " + tryFocus);
                }
            }

            if (initialFocusControl != String.Empty)
            {
                FTemplate.SetCodelet("SETINITIALFOCUS", initialFocusControl + ".Focus();");
            }

            // add title
            if (ProperI18NCatalogGetString(FCodeStorage.FFormTitle))
            {
                FTemplate.AddToCodelet("CATALOGI18N",
                    "this.Text = Catalog.GetString(\"" + FCodeStorage.FFormTitle + "\");" + Environment.NewLine);
            }

            // add actions
            foreach (TActionHandler handler in FCodeStorage.FActionList.Values)
            {
                if (!handler.actionName.StartsWith("cnd"))
                {
                    AddActionHandlerImplementation(handler);
                }

                if (TYml2Xml.HasAttribute(handler.actionNode, "InitialValue"))
                {
                    string actionEnabling =
                        "if (e.ActionName == \"" + handler.actionName + "\")" + Environment.NewLine +
                        "{" + Environment.NewLine +
                        "    {#ENABLEDEPENDINGACTIONS_" + handler.actionName + "}" + Environment.NewLine +
                        "}" + Environment.NewLine + Environment.NewLine;
                    Template.AddToCodelet("ACTIONENABLING", actionEnabling);
                    Template.AddToCodelet(
                        "INITACTIONSTATE",
                        "ActionEnabledEvent(null, new ActionEventArgs(" +
                        "\"" + handler.actionName + "\", " + TYml2Xml.GetAttribute(handler.actionNode,
                            "InitialValue") + "));" + Environment.NewLine);
                }

                if (TYml2Xml.HasAttribute(handler.actionNode, "Enabled"))
                {
                    Template.AddToCodelet(
                        "ENABLEDEPENDINGACTIONS_" + TYml2Xml.GetAttribute(handler.actionNode, "Enabled"),
                        "FPetraUtilsObject.EnableAction(\"" + handler.actionName + "\", e.Enabled);" + Environment.NewLine);
                }
            }

            WriteAllControls();

            FinishUpInitialisingControls();

            if (FCodeStorage.ManualFileExistsAndContains("void ShowDataManual()"))
            {
                FTemplate.AddToCodelet("SHOWDATA", "ShowDataManual();" + Environment.NewLine);
            }
            else if (FCodeStorage.ManualFileExistsAndContains("void ShowDataManual("))
            {
                FTemplate.AddToCodelet("SHOWDATA", "ShowDataManual(ARow);" + Environment.NewLine);
            }

            if (FCodeStorage.FControlList.ContainsKey("pnlDetails"))
            {
                FTemplate.AddToCodelet("CLEARDETAILS", "FPetraUtilsObject.ClearControls(pnlDetails);" + Environment.NewLine);
            }

            if (FCodeStorage.ManualFileExistsAndContains("void ShowDetailsManual"))
            {
                FTemplate.AddToCodelet("SHOWDETAILS", "ShowDetailsManual(ARow);" + Environment.NewLine);
                FTemplate.AddToCodelet("CLEARDETAILS", "ShowDetailsManual(ARow);" + Environment.NewLine);
            }

            if (FCodeStorage.ManualFileExistsAndContains("GetDataFromControlsManual()"))
            {
                FTemplate.AddToCodelet("SAVEDATA", "GetDataFromControlsManual();" + Environment.NewLine);
            }
            else if (FCodeStorage.ManualFileExistsAndContains("GetDataFromControlsManual("))
            {
                FTemplate.AddToCodelet("SAVEDATA", "GetDataFromControlsManual(ARow);" + Environment.NewLine);
            }

            if (FCodeStorage.ManualFileExistsAndContains("GetDataFromControlsExtra()"))
            {
                FTemplate.AddToCodelet("SAVEDATAEXTRA", "GetDataFromControlsExtra();" + Environment.NewLine);
            }
            else if (FCodeStorage.ManualFileExistsAndContains("GetDataFromControlsExtra("))
            {
                FTemplate.AddToCodelet("SAVEDATAEXTRA", "GetDataFromControlsExtra(ARow);" + Environment.NewLine);
            }
            else
            {
                FTemplate.AddToCodelet("SAVEDATAEXTRA", "");
            }

//            if (FCodeStorage.ManualFileExistsAndContains("ValidateDetailsManual"))
//            {
//                ProcessTemplate validateSnippet = FTemplate.GetSnippet("VALIDATEDETAILS");
//                FTemplate.InsertSnippet("VALIDATEDETAILS", validateSnippet);
//            }
//
            if (FCodeStorage.ManualFileExistsAndContains("GetDetailDataFromControlsManual"))
            {
                FTemplate.AddToCodelet("SAVEDETAILS", "GetDetailDataFromControlsManual(ARow);" + Environment.NewLine);
            }

            if (FCodeStorage.ManualFileExistsAndContains("GetDetailDataFromControlsExtra"))
            {
                FTemplate.AddToCodelet("SAVEDETAILSEXTRA", "GetDetailDataFromControlsExtra(ARow);" + Environment.NewLine);
            }
            else
            {
                FTemplate.AddToCodelet("SAVEDETAILSEXTRA", "");
            }

            if (FCodeStorage.ManualFileExistsAndContains("void ReadControlsManual"))
            {
                FTemplate.AddToCodelet("READCONTROLS", "ReadControlsManual(ACalc, AReportAction);" + Environment.NewLine);
            }

            if (FCodeStorage.ManualFileExistsAndContains("void SetControlsManual"))
            {
                FTemplate.AddToCodelet("SETCONTROLS", "SetControlsManual(AParameters);" + Environment.NewLine);
            }

            if (FCodeStorage.ManualFileExistsAndContains("ValidateDataManual"))
            {
                FTemplate.SetCodelet("VALIDATEDATAMANUAL", "true");
            }

            if (FCodeStorage.ManualFileExistsAndContains("GetDetailsFromControlsManual"))
            {
                FTemplate.SetCodelet("GETDETAILSMANUAL", "true");
            }

            if (FCodeStorage.ManualFileExistsAndContains("ValidateDataDetailsManual"))
            {
                FTemplate.SetCodelet("VALIDATEDATADETAILSMANUAL", "true");
            }

            if (FCodeStorage.ManualFileExistsAndContains("GetSelectedDetailRowManual"))
            {
                FTemplate.AddToCodelet("GETSELECTEDDETAILROW", "return GetSelectedDetailRowManual();" + Environment.NewLine);
            }
            else
            {
                string getSelectedDetailRow =
                    "DataRowView[] SelectedGridRow = grdDetails.SelectedDataRowsAsDataRowView;" + Environment.NewLine + Environment.NewLine +
                    "if (SelectedGridRow.Length >= 1)" + Environment.NewLine +
                    "{" + Environment.NewLine +
                    "    return ({#DETAILTABLETYPE}Row)SelectedGridRow[0].Row;" + Environment.NewLine +
                    "}" + Environment.NewLine + Environment.NewLine +
                    "return null;" + Environment.NewLine + Environment.NewLine;

                FTemplate.SetCodelet("GETSELECTEDDETAILROW", getSelectedDetailRow);
            }

            InsertCodeIntoTemplate(AXAMLFilename);
        }
        private Boolean CreateConnectors(String AOutputPath, String AModulePath, String ATemplateDir)
        {
            // Work out the module name from the module path
            string[] items = AModulePath.Split(new char[] { Path.DirectorySeparatorChar });

            if (items.Length == 0)
            {
                // the -inputclient command line parameter must be wrong
                return false;
            }

            // Module name is e.g. MCommon, MPartner etc
            string moduleName = items[items.Length - 1];

            // Work out the actual folder/file for the output file
            String OutputFolder = AOutputPath + Path.DirectorySeparatorChar + "lib" +
                                  Path.DirectorySeparatorChar + moduleName +
                                  Path.DirectorySeparatorChar + "web";

            String OutputFile = OutputFolder + Path.DirectorySeparatorChar + "ReferenceCount-generated.cs";
            Console.WriteLine("working on " + OutputFile);

            // Where is the template?
            String templateFilename = ATemplateDir +
                                      Path.DirectorySeparatorChar + "ORM" +
                                      Path.DirectorySeparatorChar + "ReferenceCountWebConnector.cs";

            if (!File.Exists(templateFilename))
            {
                // The -templatedir command line parameter must have been wrong
                return false;
            }

            // Open the template
            ProcessTemplate Template = new ProcessTemplate(templateFilename);

            // now we need to remove the leading 'M' from the module name
            moduleName = moduleName.Substring(1);
            string className = "T" + moduleName + "ReferenceCountWebConnector";

            Console.WriteLine("Starting connector for " + className + Environment.NewLine);

            int cacheableCount = 0;
            int nonCacheableCount = 0;

            // load default header with license and copyright
            Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(ATemplateDir));
            Template.SetCodelet("TOPLEVELMODULE", moduleName);

            Template.SetCodelet("CLASSNAME", className);
            Template.SetCodelet("CACHEABLETABLECASES", string.Empty);
            Template.SetCodelet("CACHEABLETABLENAME", string.Empty);
            Template.SetCodelet("CACHEABLETABLECASE", string.Empty);
            Template.SetCodelet("CACHEABLETABLELISTNAME", string.Empty);
            Template.SetCodelet("CACHEABLETRANSACTION", string.Empty);
            Template.SetCodelet("CACHEABLEFINALLY", string.Empty);
            Template.SetCodelet("TABLESIF", string.Empty);
            Template.SetCodelet("TABLESELSEIF", string.Empty);
            Template.SetCodelet("TABLESELSE", string.Empty);
            Template.SetCodelet("TABLENAME", string.Empty);
            Template.SetCodelet("NONCACHEABLETRANSACTION", string.Empty);
            Template.SetCodelet("NONCACHEABLEFINALLY", string.Empty);

            // Find all the YAML files in the client module folder
            string[] clientFiles = Directory.GetFiles(AModulePath, "*.yaml", SearchOption.AllDirectories);

            foreach (String fn in clientFiles)
            {
                // only look for main files, not language specific files (*.xy-XY.yaml or *.xy.yaml)
                if (TProcessYAMLForms.IgnoreLanguageSpecificYamlFile(fn))
                {
                    continue;
                }

                XmlDocument doc = TYml2Xml.CreateXmlDocument();
                SortedList sortedNodes = null;
                TCodeStorage codeStorage = new TCodeStorage(doc, sortedNodes);
                TParseYAMLFormsDefinition yamlParser = new TParseYAMLFormsDefinition(ref codeStorage);
                yamlParser.LoadRecursively(fn, null);

                string attDetailTableName = codeStorage.GetAttribute("DetailTable");
                string attCacheableListName = codeStorage.GetAttribute("CacheableTable");

                // Note - this IF clause needs to be the same as the one in FormWriter.cs which is generating the client side code
                // Do Ctrl+F to find: this IF clause needs to be the same
                // in that file
                if ((attDetailTableName != String.Empty)
                    && (codeStorage.FControlList.ContainsKey("btnDelete")
                        || codeStorage.FControlList.ContainsKey("btnDeleteType")
                        || codeStorage.FControlList.ContainsKey("btnDeleteExtract")
                        || codeStorage.FControlList.ContainsKey("btnDeleteDetail")
                        || (codeStorage.FControlList.ContainsKey("btnRemoveDetail") && (codeStorage.GetAttribute("FormType") != "report"))))
                {
                    if (attCacheableListName != String.Empty)
                    {
                        ProcessTemplate snippet = Template.GetSnippet("CACHEABLETABLECASE");
                        snippet.SetCodelet("CACHEABLETABLENAME", attDetailTableName);
                        snippet.SetCodelet("CACHEABLETABLELISTNAME", attCacheableListName);
                        Template.InsertSnippet("CACHEABLETABLECASES", snippet);

                        if (cacheableCount == 0)
                        {
                            // Add these on the first time through
                            snippet = Template.GetSnippet("CACHEABLETRANSACTIONSNIP");
                            Template.InsertSnippet("CACHEABLETRANSACTION", snippet);
                            snippet = Template.GetSnippet("CACHEABLEFINALLYSNIP");
                            Template.InsertSnippet("CACHEABLEFINALLY", snippet);
                        }

                        Console.WriteLine("Creating cacheable reference count connector for " + attCacheableListName);
                        cacheableCount++;
                    }
                    else
                    {
                        ProcessTemplate snippet = null;

                        if (nonCacheableCount == 0)
                        {
                            snippet = Template.GetSnippet("TABLEIF");
                            snippet.SetCodelet("TABLENAME", attDetailTableName);
                            Template.InsertSnippet("TABLESIF", snippet);

                            snippet = Template.GetSnippet("NONCACHEABLETRANSACTIONSNIP");
                            Template.InsertSnippet("NONCACHEABLETRANSACTION", snippet);
                            snippet = Template.GetSnippet("NONCACHEABLEFINALLYSNIP");
                            Template.InsertSnippet("NONCACHEABLEFINALLY", snippet);
                        }
                        else
                        {
                            snippet = Template.GetSnippet("TABLEELSEIF");
                            snippet.SetCodelet("TABLENAME", attDetailTableName);
                            Template.InsertSnippet("TABLESELSEIF", snippet);
                        }

                        Console.WriteLine("Creating non-cacheable reference count connector for " + attDetailTableName);
                        nonCacheableCount++;
                    }
                }
            }

            // Now we finish off the template content depending on how many entries we made
            if ((nonCacheableCount == 0) && (cacheableCount > 0))
            {
                ProcessTemplate snippet = Template.GetSnippet("TABLENONE");
                Template.InsertSnippet("TABLESELSE", snippet);
            }

            if (nonCacheableCount > 0)
            {
                ProcessTemplate snippet = Template.GetSnippet("TABLEELSE");
                Template.InsertSnippet("TABLESELSE", snippet);
            }

            if ((cacheableCount > 0) || (nonCacheableCount > 0))
            {
                if (!Directory.Exists(OutputFolder))
                {
                    // The -outputserver command line parameter must be wrong, or the directory does not exist yet
                    // Directories must be manually created and added to source code control
                    Console.WriteLine("Error: directory does not exist: " + OutputFolder);
                    return false;
                }

                Console.WriteLine("Finishing connector for " + className + Environment.NewLine + Environment.NewLine);
                Template.FinishWriting(OutputFile, ".cs", true);

                FTotalCacheable += cacheableCount;
                FTotalNonCacheable += nonCacheableCount;
                FTotalConnectors++;
            }

            return true;
        }
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="ACodeStorage"></param>
 public TParseYAMLFormsDefinition(ref TCodeStorage ACodeStorage)
 {
     this.FCodeStorage = ACodeStorage;
 }
Esempio n. 11
0
 /// <summary>main function for generating the code</summary>
 public abstract void CreateCode(TCodeStorage AStorage, string AXamlFilename, string ATemplate);
        private Boolean CreateConnectors(String AOutputPath, String AModulePath, String ATemplateDir)
        {
            // Work out the module name from the module path
            string[] items = AModulePath.Split(new char[] { Path.DirectorySeparatorChar });

            if (items.Length == 0)
            {
                // the -inputclient command line parameter must be wrong
                return(false);
            }

            // Module name is e.g. MCommon, MPartner etc
            string moduleName = items[items.Length - 1];

            // Work out the actual folder/file for the output file
            String OutputFolder = AOutputPath + Path.DirectorySeparatorChar + "lib" +
                                  Path.DirectorySeparatorChar + moduleName +
                                  Path.DirectorySeparatorChar + "web";

            String OutputFile = OutputFolder + Path.DirectorySeparatorChar + "ReferenceCount-generated.cs";

            Console.WriteLine("working on " + OutputFile);

            // Where is the template?
            String templateFilename = ATemplateDir +
                                      Path.DirectorySeparatorChar + "ORM" +
                                      Path.DirectorySeparatorChar + "ReferenceCountWebConnector.cs";

            if (!File.Exists(templateFilename))
            {
                // The -templatedir command line parameter must have been wrong
                return(false);
            }

            // Open the template
            ProcessTemplate Template = new ProcessTemplate(templateFilename);

            // now we need to remove the leading 'M' from the module name
            moduleName = moduleName.Substring(1);
            string className = "T" + moduleName + "ReferenceCountWebConnector";

            Console.WriteLine("Starting connector for " + className + Environment.NewLine);

            int cacheableCount    = 0;
            int nonCacheableCount = 0;

            // load default header with license and copyright
            Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(ATemplateDir));
            Template.SetCodelet("TOPLEVELMODULE", moduleName);

            Template.SetCodelet("CLASSNAME", className);
            Template.SetCodelet("CACHEABLETABLECASES", string.Empty);
            Template.SetCodelet("CACHEABLETABLENAME", string.Empty);
            Template.SetCodelet("CACHEABLETABLECASE", string.Empty);
            Template.SetCodelet("CACHEABLETABLELISTNAME", string.Empty);
            Template.SetCodelet("CACHEABLETRANSACTION", string.Empty);
            Template.SetCodelet("CACHEABLEFINALLY", string.Empty);
            Template.SetCodelet("TABLESIF", string.Empty);
            Template.SetCodelet("TABLESELSEIF", string.Empty);
            Template.SetCodelet("TABLESELSE", string.Empty);
            Template.SetCodelet("TABLENAME", string.Empty);
            Template.SetCodelet("NONCACHEABLETRANSACTION", string.Empty);
            Template.SetCodelet("NONCACHEABLEFINALLY", string.Empty);

            // Find all the YAML files in the client module folder
            string[] clientFiles = Directory.GetFiles(AModulePath, "*.yaml", SearchOption.AllDirectories);

            foreach (String fn in clientFiles)
            {
                // only look for main files, not language specific files (*.xy-XY.yaml or *.xy.yaml)
                if (TProcessYAMLForms.IgnoreLanguageSpecificYamlFile(fn))
                {
                    continue;
                }

                XmlDocument  doc                     = TYml2Xml.CreateXmlDocument();
                SortedList   sortedNodes             = null;
                TCodeStorage codeStorage             = new TCodeStorage(doc, sortedNodes);
                TParseYAMLFormsDefinition yamlParser = new TParseYAMLFormsDefinition(ref codeStorage);
                yamlParser.LoadRecursively(fn, null);

                string attDetailTableName   = codeStorage.GetAttribute("DetailTable");
                string attCacheableListName = codeStorage.GetAttribute("CacheableTable");

                // Note - this IF clause needs to be the same as the one in FormWriter.cs which is generating the client side code
                // Do Ctrl+F to find: this IF clause needs to be the same
                // in that file
                if ((attDetailTableName != String.Empty) &&
                    (codeStorage.FControlList.ContainsKey("btnDelete") ||
                     codeStorage.FControlList.ContainsKey("btnDeleteType") ||
                     codeStorage.FControlList.ContainsKey("btnDeleteExtract") ||
                     codeStorage.FControlList.ContainsKey("btnDeleteDetail") ||
                     (codeStorage.FControlList.ContainsKey("btnRemoveDetail") && (codeStorage.GetAttribute("FormType") != "report"))))
                {
                    if (attCacheableListName != String.Empty)
                    {
                        ProcessTemplate snippet = Template.GetSnippet("CACHEABLETABLECASE");
                        snippet.SetCodelet("CACHEABLETABLENAME", attDetailTableName);
                        snippet.SetCodelet("CACHEABLETABLELISTNAME", attCacheableListName);
                        Template.InsertSnippet("CACHEABLETABLECASES", snippet);

                        if (cacheableCount == 0)
                        {
                            // Add these on the first time through
                            snippet = Template.GetSnippet("CACHEABLETRANSACTIONSNIP");
                            Template.InsertSnippet("CACHEABLETRANSACTION", snippet);
                            snippet = Template.GetSnippet("CACHEABLEFINALLYSNIP");
                            Template.InsertSnippet("CACHEABLEFINALLY", snippet);
                        }

                        Console.WriteLine("Creating cacheable reference count connector for " + attCacheableListName);
                        cacheableCount++;
                    }
                    else
                    {
                        ProcessTemplate snippet = null;

                        if (nonCacheableCount == 0)
                        {
                            snippet = Template.GetSnippet("TABLEIF");
                            snippet.SetCodelet("TABLENAME", attDetailTableName);
                            Template.InsertSnippet("TABLESIF", snippet);

                            snippet = Template.GetSnippet("NONCACHEABLETRANSACTIONSNIP");
                            Template.InsertSnippet("NONCACHEABLETRANSACTION", snippet);
                            snippet = Template.GetSnippet("NONCACHEABLEFINALLYSNIP");
                            Template.InsertSnippet("NONCACHEABLEFINALLY", snippet);
                        }
                        else
                        {
                            snippet = Template.GetSnippet("TABLEELSEIF");
                            snippet.SetCodelet("TABLENAME", attDetailTableName);
                            Template.InsertSnippet("TABLESELSEIF", snippet);
                        }

                        Console.WriteLine("Creating non-cacheable reference count connector for " + attDetailTableName);
                        nonCacheableCount++;
                    }
                }
            }

            // Now we finish off the template content depending on how many entries we made
            if ((nonCacheableCount == 0) && (cacheableCount > 0))
            {
                ProcessTemplate snippet = Template.GetSnippet("TABLENONE");
                Template.InsertSnippet("TABLESELSE", snippet);
            }

            if (nonCacheableCount > 0)
            {
                ProcessTemplate snippet = Template.GetSnippet("TABLEELSE");
                Template.InsertSnippet("TABLESELSE", snippet);
            }

            if ((cacheableCount > 0) || (nonCacheableCount > 0))
            {
                if (!Directory.Exists(OutputFolder))
                {
                    // The -outputserver command line parameter must be wrong, or the directory does not exist yet
                    // Directories must be manually created and added to source code control
                    Console.WriteLine("Error: directory does not exist: " + OutputFolder);
                    return(false);
                }

                Console.WriteLine("Finishing connector for " + className + Environment.NewLine + Environment.NewLine);
                Template.FinishWriting(OutputFile, ".cs", true);

                FTotalCacheable    += cacheableCount;
                FTotalNonCacheable += nonCacheableCount;
                FTotalConnectors++;
            }

            return(true);
        }
Esempio n. 13
0
        /// <summary>
        /// load the dataset tables
        /// </summary>
        public static SortedList <string, TTable>LoadDatasetTables(string AICTPath, string ADataSetTypeWithNamespace, TCodeStorage ACodeStorage,
            string APluginPath)
        {
            if (FDatasetTables == null)
            {
                FDatasetTables = new SortedList <string, SortedList <string, TTable>>();
            }

            FCodeStorage = ACodeStorage;

            if (!ADataSetTypeWithNamespace.StartsWith("Ict.Petra.Shared") && !ADataSetTypeWithNamespace.StartsWith("Ict.Petra.Plugins"))
            {
                throw new Exception("the DatasetType must contain the full namespace, starting with Ict.Petra.Shared or Ict.Petra.Plugins");
            }

            if (FDatasetTables.ContainsKey(ADataSetTypeWithNamespace))
            {
                FCurrentDataset = FDatasetTables[ADataSetTypeWithNamespace];

                return FCurrentDataset;
            }

            string[] datasetTypeSplit = ADataSetTypeWithNamespace.Split(new char[] { '.' });
            string module = datasetTypeSplit[3];
            string datasetName = datasetTypeSplit[datasetTypeSplit.Length - 1];

            // find the correct xml file for the dataset.
            // look in Ict/Petra/Shared/lib/MODULE/data
            string dataPath = AICTPath + "/Petra/Shared/lib/" + module + "/data/";

            if (ADataSetTypeWithNamespace.StartsWith("Ict.Petra.Plugins"))
            {
                int start = "Ict.Petra.Plugins.".Length;
                int end = ADataSetTypeWithNamespace.IndexOf(".", start);
                string PluginName = ADataSetTypeWithNamespace.Substring(start, end - start);
                dataPath = AICTPath + "/Petra/Plugins/" + PluginName + "/data/";
            }

            DirectoryInfo directory = new DirectoryInfo(dataPath);
            FileInfo[] xmlFiles = directory.GetFiles("*.xml");
            XmlNode datasetNode = null;

            foreach (FileInfo fileinfo in xmlFiles)
            {
                if (datasetNode == null)
                {
                    TXMLParser parser = new TXMLParser(dataPath + "/" + fileinfo.Name, false);
                    datasetNode = parser.GetDocument().SelectSingleNode(String.Format("//DataSet[@name='{0}']", datasetName));
                }
            }

            if ((datasetNode == null) && File.Exists(APluginPath))
            {
                // also check the plugin directory of the yaml file, for plugins can have a file TypedDataSets.xml
                TXMLParser parser = new TXMLParser(APluginPath, false);
                datasetNode = parser.GetDocument().SelectSingleNode(String.Format("//DataSet[@name='{0}']", datasetName));
            }

            if (datasetNode == null)
            {
                throw new Exception("cannot find the xml file for dataset " + ADataSetTypeWithNamespace);
            }

            SortedList <string, TTable>result = new SortedList <string, TTable>();
            XmlNodeList tables = datasetNode.SelectNodes("Table|CustomTable");

            foreach (XmlNode tableNode in tables)
            {
                TTable table = new TTable();
                string tablename;

                if ((tableNode.Name == "Table") && TXMLParser.HasAttribute(tableNode, "sqltable"))
                {
                    tablename = TTable.NiceTableName(tableNode.Attributes["sqltable"].Value);
                    table.Assign(FPetraXMLStore.GetTable(tablename));

                    table.strVariableNameInDataset = TXMLParser.HasAttribute(tableNode, "name") ? tableNode.Attributes["name"].Value : tablename;

                    if ((tableNode.SelectNodes("CustomField").Count > 0) || (tableNode.SelectNodes("Field").Count > 0))
                    {
                        table.strDotNetName = datasetName + tablename;
                    }
                }
                else if ((tableNode.Name == "Table") && TXMLParser.HasAttribute(tableNode, "customtable"))
                {
                    table = new TTable();
                    tablename = tableNode.Attributes["customtable"].Value;
                    table.strName = tablename;
                    table.strDotNetName = tablename;
                    table.strVariableNameInDataset = TXMLParser.HasAttribute(tableNode, "name") ? tableNode.Attributes["name"].Value : tablename;
                }
                else
                {
                    table = new TTable();
                    tablename = tableNode.Attributes["name"].Value;
                    table.strName = tablename;
                    table.strDotNetName = datasetName + tablename;
                    table.strVariableNameInDataset = tablename;
                }

                // add the custom fields if there are any
                XmlNodeList customFields = tableNode.SelectNodes("CustomField");

                foreach (XmlNode customField in customFields)
                {
                    TTableField newField = new TTableField();
                    newField.strName = customField.Attributes["name"].Value;
                    newField.strNameDotNet = newField.strName;
                    newField.strType = customField.Attributes["type"].Value;
                    newField.strTypeDotNet = customField.Attributes["type"].Value;
                    newField.strTableName = tablename;
                    newField.strDescription = "";
                    newField.bNotNull =
                        TXMLParser.HasAttribute(customField, "notnull") && TXMLParser.GetAttribute(customField, "notnull").ToLower() == "true";
                    table.grpTableField.Add(newField);
                }

                // add other fields from other tables that are defined in petra.xml
                XmlNodeList otherFields = tableNode.SelectNodes("Field");

                foreach (XmlNode otherField in otherFields)
                {
                    TTable otherTable = FPetraXMLStore.GetTable(otherField.Attributes["sqltable"].Value);
                    TTableField newField = new TTableField(otherTable.GetField(otherField.Attributes["sqlfield"].Value));

                    if (TXMLParser.HasAttribute(otherField, "name"))
                    {
                        newField.strNameDotNet = otherField.Attributes["name"].Value;
                    }

                    newField.strTableName = tablename;
                    table.grpTableField.Add(newField);
                }

                result.Add(table.strVariableNameInDataset, table);
            }

            FDatasetTables.Add(ADataSetTypeWithNamespace, result);
            FCurrentDataset = result;
            return result;
        }