예제 #1
0
        private static void UpdateEventStart(HPatternInstance instance, HPatternSettings settings, Transaction transaction, BasicParser parser)
        {
            StringBuilder eventCodeStart = new StringBuilder(100);

            eventCodeStart.AppendLine(Messages.VersionHPattern());

            Generator.GeneratorParameters parameters = new Generator.GeneratorParameters();
            DefaultProvider.PrepareTemplateParameters(parameters);
            parameters.Properties["Settings"] = settings;
            parameters.Properties["tipo"] = 0;

            AppendTemplateOutput(eventCodeStart, "SubLoadContext", parameters);

            //if (settings.Security.Enabled)
            //{

            eventCodeStart.AppendLine("[web]");
            eventCodeStart.AppendLine("{");

            parameters.Properties["Instance"] = instance;
            parameters.Properties["IsTransaction"] = true;

            AppendTemplateOutput(eventCodeStart, "SubCheckSecurity", parameters);

            //}

            if (settings.Security.EventStart != String.Empty)
            {
                eventCodeStart.AppendLine("");
                eventCodeStart.AppendLine(settings.Security.EventStart);
            }

            eventCodeStart.AppendLine();
            eventCodeStart.Append("}");

            if (settings.Template.UseTransactionContext)
            {
                if (eventCodeStart.Length > 0)
                    eventCodeStart.AppendLine();

                eventCodeStart.AppendLine("&TrnContext.FromXml(&WebSession.Get(!\"TrnContext\"))");

                if (HasContextAttributes(transaction))
                {
                    eventCodeStart.AppendLine("If (&TrnContext.TransactionName = &Pgmname and &Mode = TrnMode.Insert)");
                    eventCodeStart.AppendLine("\tFor &TrnContextAtt in &TrnContext.Attributes");

                    bool first = true;
                    foreach (TransactionAttribute icAtt in ContextAttributes(transaction))
                    {
                        if (first)
                        {
                            eventCodeStart.AppendLine("\t\tDo Case");
                            first = false;
                        }
                        eventCodeStart.AppendFormat("\t\t\t// When inserting with instantiated {0}\r\n", icAtt.Name);
                        eventCodeStart.AppendFormat("\t\t\tCase &TrnContextAtt.AttributeName = !\"{0}\"\r\n", icAtt.Name);
                        eventCodeStart.AppendFormat("\t\t\t\t&Insert_{0}.FromString(&TrnContextAtt.AttributeValue)\r\n", icAtt.Name);
                    }
                    if (!first)
                        eventCodeStart.AppendLine("\t\tEndcase");

                    eventCodeStart.AppendLine("\tEndfor");
                    eventCodeStart.Append("Endif");
                }
            }

            if (settings.Template.EventStart != String.Empty) {
                eventCodeStart.AppendLine("");
                eventCodeStart.AppendLine(settings.Template.EventStart);
            }

            eventCodeStart.AppendLine("");
            eventCodeStart.AppendLine("[web]");
            eventCodeStart.AppendLine("{");

                IBaseCollection<RowElement> lista = instance.Transaction.GetRows("",true,true);

                foreach (RowElement row in lista)
                {

                    foreach (ColumnElement col in row.Columns)
                    {
                        foreach (VariableElement var in col.Variables)
                        {
                            if (var.Domain != null || var.Attribute != null)
                            {
                                if (!var.Visible || !row.Visible)
                                {
                                    eventCodeStart.AppendLine("");
                                    eventCodeStart.AppendFormat("&{0}.Visible = false", var.Name);
                                }
                                if (!String.IsNullOrEmpty(var.LoadCode))
                                {
                                    eventCodeStart.AppendLine("");
                                    eventCodeStart.AppendLine(var.LoadCode);
                                }
                                if (!String.IsNullOrEmpty(var.LinksEventStart))
                                {
                                    eventCodeStart.AppendLine("");
                                    eventCodeStart.AppendLine(var.LinksEventStart);
                                }

                            }
                        }

                        foreach (AttributeElement att in col.Attributes)
                        {
                            if (att.Attribute != null)
                            {
                                if (!att.Visible || !row.Visible)
                                {
                                    eventCodeStart.AppendLine("");
                                    eventCodeStart.AppendFormat("{0}.Visible = false", att.AttributeName);

                                }
                                if (!String.IsNullOrEmpty(att.LinksEventStart))
                                {
                                    eventCodeStart.AppendLine("");
                                    eventCodeStart.AppendLine(att.LinksEventStart);
                                }
                                if (!String.IsNullOrEmpty(att.EventStart))
                                {
                                    eventCodeStart.AppendLine("");
                                    eventCodeStart.AppendLine(String.Format(att.EventStart, att.AttributeName, att.AttributeName));
                                }
                            }
                        }

                        foreach (TextElement text in col.Texts)
                        {

                            if (!text.Visible || !row.Visible)
                            {
                                eventCodeStart.AppendLine("");
                                eventCodeStart.AppendFormat("{0}.Visible = false", text.Name);
                            }
                        }
                    }
                }
            //}

            bool setFocus = instance.Transaction.GetSetFocus;
            /*
                settings.Template.TransactionSetFocus;
            if (instance.Transaction.SetFocus.ToLower() == "true")
                setFocus = true;
            if (instance.Transaction.SetFocus.ToLower() == "true")
                setFocus = false;
            */

            Artech.Genexus.Common.Objects.Attribute setFocusAtt = instance.Transaction.SetFocusAttribute;
            if (setFocusAtt == null && transaction.Structure.Root.DescriptionAttribute != null)
            {
                setFocusAtt = transaction.Structure.Root.DescriptionAttribute.Attribute;
            }

            if (setFocus && setFocusAtt != null)
            {
                eventCodeStart.AppendLine();
                eventCodeStart.AppendLine(setFocusAtt.Name + ".SetFocus()");
            }

            eventCodeStart.AppendLine("");

            // Se não vou gerar BC e tenho abas
            if (!instance.Transaction.WebBC && instance.Transaction.Form.Tabs.Count > 0)
            {
                Tab tabs = Tab.getTab(instance.Transaction.Form, transaction);
                eventCodeStart.Append(tabs.Events());
                //eventCodeStart.Append( TemplateAbas.Start(instance.Transaction.Form));
            }

            eventCodeStart.AppendLine(Helpers.Template.HMaskEventStart(instance.Transaction, "", false));

            eventCodeStart.AppendLine("}");

            if (!String.IsNullOrEmpty(instance.Transaction.EventStart))
            {
                eventCodeStart.AppendLine(Indentation.Indent(instance.Transaction.EventStart, 1));
            }

            if (eventCodeStart.Length > 0)
                UpdateEventCode(parser, new string[] { "Start" }, eventCodeStart.ToString());
        }
예제 #2
0
 private static void UpdateEventPrompts(HPatternInstance instance,HPatternSettings settings, BasicParser parser)
 {
     string tmp = Helpers.Template.PromptEvents(instance.Transaction.Form, settings);
     if (!String.IsNullOrEmpty(tmp))
     {
         StringBuilder eventCode = new StringBuilder();
         //eventCode.AppendLine(Indentation.Indent(k_GeneratedMarkerStart, 1));
         eventCode.Append(tmp);
         eventCode.Append(Environment.NewLine);
         //eventCode.AppendLine(Indentation.Indent(k_GeneratedMarkerEnd, 1));
         parser.InsertBefore(0, eventCode.ToString());
     }
 }
예제 #3
0
        private static string UpdateEvents(HPatternInstance instance, HPatternSettings settings, Transaction transaction)
        {
            BasicParser parser = new BasicParser("");

            DeleteGeneratedBlocks(parser);

            UpdateEventCodes(instance.Settings, parser);

            parser.InsertBefore(0, MenuContext.get(instance.WebObject.Actions).Events());

            // Se não vou gerar BC e tenho abas
            if (!instance.Transaction.WebBC && instance.Transaction.Form.Tabs.Count > 0)
            {
                Tab tabs = Tab.getTab(instance.Transaction.Form, transaction);
                parser.InsertBefore(0, tabs.Subs());
                //parser.InsertBefore(0, TemplateAbas.EventsExtra(instance.Transaction.Form));
            }
            UpdateEventActions(instance, settings, parser);
            UpdateEventPrompts(instance, settings,parser);
            UpdateEventAfterTrn(instance, transaction, parser);
            UpdateEventStart(instance, settings, transaction, parser);

            return parser.Text;
        }
예제 #4
0
        private static void UpdateEventCodes( HPatternSettings settings, BasicParser parser)
        {
            string codes = TemplateInternal.EventCodes(TemplateInternal.CodeType.Transaction, settings);
            if (!String.IsNullOrEmpty(codes))
            {

                StringBuilder eventBuilder = new StringBuilder();
                //eventBuilder.AppendLine(k_GeneratedMarkerStart);
                eventBuilder.AppendLine(codes);
                //eventBuilder.AppendLine(k_GeneratedMarkerEnd);
                eventBuilder.Append(Environment.NewLine);
                parser.InsertBefore(0, eventBuilder.ToString());

            }
        }
예제 #5
0
        private static void UpdateEventCode(BasicParser parser, string[] eventName, string eventCode)
        {
            StringBuilder eventBuilder = new StringBuilder();
            eventBuilder.AppendLine("Event " + String.Join(" ", eventName));
            bool isNewEvent = true;

            // Keep the current event code, if any.
            List<string> beginEvent = new List<string>();

            beginEvent.Add("Event");
            beginEvent.AddRange(eventName);
            string currentEvent = parser.GetBlock(beginEvent.ToArray(), new string[] { "EndEvent" }, 0, true);
            if (currentEvent != null)
            {
                isNewEvent = false;
                string eventNameLastToken = eventName[eventName.Length - 1];
                int eventBodyStart = currentEvent.ToLower().IndexOf(eventNameLastToken.ToLower()) + eventNameLastToken.Length;
                int eventBodyEnd = currentEvent.ToLower().IndexOf("endevent");

                if (eventBodyStart != -1 && eventBodyEnd != -1)
                {
                    string currentEventCode = currentEvent.Substring(eventBodyStart, eventBodyEnd - eventBodyStart);
                    if (currentEventCode.Trim() != String.Empty)
                    {
                        currentEventCode = currentEventCode.TrimStart(Environment.NewLine.ToCharArray());
                        currentEventCode = currentEventCode.TrimEnd(Environment.NewLine.ToCharArray());
                        eventBuilder.AppendLine(currentEventCode);
                    }
                }
            }

            // Add the desired code.
            //eventBuilder.AppendLine(Indentation.Indent(k_GeneratedMarkerStart, 1));
            eventBuilder.AppendLine(Indentation.Indent(eventCode, 1));
            //eventBuilder.AppendLine(Indentation.Indent(k_GeneratedMarkerEnd, 1));
            eventBuilder.Append("EndEvent");

            if (isNewEvent)
            {
                eventBuilder.Append(Environment.NewLine);
                parser.InsertBefore(0, eventBuilder.ToString());
            }
            else
            {
                parser.ReplaceBlock(beginEvent.ToArray(), new string[] { "EndEvent" }, eventBuilder.ToString());
            }
        }
예제 #6
0
        private static void UpdateEventAfterTrn(HPatternInstance instance, Transaction transaction, BasicParser parser)
        {
            StringBuilder eventCodeAfterTrn = new StringBuilder();
            //if (transaction.IsBusinessComponent)
            //{
                eventCodeAfterTrn.AppendLine("[web]");
                eventCodeAfterTrn.AppendLine("{");
            //}

                if (instance.Settings.Template.GenerateCallBackLink)
                {
                    eventCodeAfterTrn.AppendLine(Indentation.Indent(String.Format("If &{0}.IsEmpty()", HPatternInstance.PARMCALLBACK), 1));
                    eventCodeAfterTrn.AppendLine(Indentation.Indent("Return", 2));
                    eventCodeAfterTrn.AppendLine(Indentation.Indent("Else", 1));
                    eventCodeAfterTrn.AppendLine(Indentation.Indent(String.Format("PrLinkCallBack(&{0})", HPatternInstance.PARMCALLBACK), 2));
                    eventCodeAfterTrn.AppendLine(Indentation.Indent("EndIf", 1));
                    eventCodeAfterTrn.AppendLine("");
                }
                else
                {

                    bool appendBlankLine = false;
                    AppendRedirection(instance, eventCodeAfterTrn, "Insert", instance.AfterInsert, ref appendBlankLine);
                    AppendRedirection(instance, eventCodeAfterTrn, "Update", instance.AfterUpdate, ref appendBlankLine);

                    // Delete is special because we cannot return to caller when deleting from a view.
                    if (!AppendRedirection(instance, eventCodeAfterTrn, "Delete", instance.AfterDelete, ref appendBlankLine))
                    {
                        SelectionElement emergencyRedirection;
                        if (instance.Settings.Template.UseTransactionContext && CanRedirectToSelection(instance, out emergencyRedirection))
                        {
                            if (appendBlankLine)
                                eventCodeAfterTrn.AppendLine(String.Empty);

                            eventCodeAfterTrn.AppendLine("If (&Mode = TrnMode.Delete and not &TrnContext.CallerOnDelete)");
                            eventCodeAfterTrn.AppendLine(String.Format("\t{0}.Call({1})", emergencyRedirection.ObjectName, emergencyRedirection.Parameters.List()));
                            eventCodeAfterTrn.Append("Endif");
                        }
                    }

                }

                //if (transaction.IsBusinessComponent)
                //{
                eventCodeAfterTrn.AppendLine("");
                eventCodeAfterTrn.Append("}");
                //}

            // Add the event (or modify the existing one).
            UpdateEventCode(parser, new string[] { "After", "Trn" }, eventCodeAfterTrn.ToString());
        }
예제 #7
0
 private static void DeleteGeneratedBlocks(BasicParser parser)
 {
     bool keepDeleting = true;
     while (keepDeleting)
         keepDeleting = parser.DeleteBlock(new string[] { k_GeneratedMarkerStart }, new string[] { k_GeneratedMarkerEnd });
 }
예제 #8
0
 private static void ClearRules(Transaction transaction)
 {
     BasicParser parser = new BasicParser(transaction.Rules.Source);
     DeleteGeneratedBlocks(parser);
     transaction.Rules.Source = parser.Text;
 }