Esempio n. 1
0
 public override IEnumerable<IPatternEditorCommand> GetCommands(PatternInstanceElement onElement)
 {
     if (onElement.Type == InstanceElements.FilterAttributes)
         yield return new CommandAddFilterVariable(onElement);
     if (onElement.Type == InstanceElements.Tabs)
         yield return new CommandAddTab(onElement);
 }
Esempio n. 2
0
 internal String GeraNomeUnico(PatternInstanceElement element)
 {
     String ret = "";
     List<String> nomes = new List<string>();
     foreach (PatternInstanceElement el in element.InstancePart.SelectElements("//" + element.Name))
     {
         nomes.Add((String)el.Attributes[InstanceAttributes.Text.Name]);
     }
     ret = element.Name;
     int max = 0;
     int at = 0;
     foreach (String el in nomes)
     {
         try
         {
             at = int.Parse(el.Replace(element.Name, ""));
         }
         catch (Exception e)
         {
             at = 0;
         }
         if (at > max)
             max = at;
     }
     max++;
     ret += max.ToString().Trim();
     return ret;
 }
Esempio n. 3
0
        public override void InitializeElement(PatternInstanceElement element)
        {
            if (element.Type == InstanceElements.WebPanelRoot || element.Type == InstanceElements.Transaction)
            {
                throw new HPatternException("Operação não permitida");
            }
            else
            {
                if (element.Type == InstanceElements.Text || element.Type == InstanceElements.TabForm || element.Type == InstanceElements.UserTable )
                {
                    element.Attributes[InstanceAttributes.Text.Name] = GeraNomeUnico(element);
                }

                base.InitializeElement(element);
            }
        }
Esempio n. 4
0
        public override bool CustomShowElement(PatternInstanceElement element, ref string caption, ref System.Drawing.Icon icon)
        {
            if (element.Type == InstanceElements.Modes)
            {
                List<string> modes = new List<string>();
                SettingsStandardActionsElement ssa = HPatternSettings.Get(element.Instance.Model).StandardActions;
                foreach (string mode in ALL_MODES)
                {
                    if (element.Attributes.GetPropertyValue<string>(mode) == ModesElement.InsertValue.True ||
                        (element.Attributes.GetPropertyValue<string>(mode) == ModesElement.InsertValue.Default &&
                        ((ssa.FindAction(mode).DefaultMode && element.Parent.Type != InstanceElements.Prompt) ||
                        (ssa.FindAction(mode).PromptMode && element.Parent.Type == InstanceElements.Prompt))))
                    {
                        modes.Add(mode);
                    }
                }

                caption = String.Format("modes ({0})", String.Join(", ", modes.ToArray()));
                return true;
            }

            return base.CustomShowElement(element, ref caption, ref icon);
        }
Esempio n. 5
0
        internal void XmlToVariable(VariablesPart obj,PatternInstanceElement c,XmlNode xn)
        {
            string nome = xn.Attributes["Name"].Value;
            bool IsNovo = false;
            if (Variable.IsValidName(nome))
            {
                try
                {
                    Variable var = getVariable(obj, nome, out IsNovo);
                    foreach (XmlNode xi in xn.SelectNodes("Properties/Property"))
                    {
                        string pnome = xi.SelectSingleNode("Name").InnerText;
                        string pvalue = xi.SelectSingleNode("Value").InnerText;
                        if (pnome == "ATTCUSTOMTYPE" && pvalue.ToUpper().Trim() == "BITMAP" && GXVersion.Version == GXVersion.Versions.Ev2)
                        {
                            pvalue = "IMAGE";
                        }

                        object vs = var.GetPropertyValueFromString(pnome, pvalue);
                        object v = var.GetPropertyValue(pnome);
                        bool atu = true;
                        if (v != null)
                        {
                            if (vs is AttCustomType)
                            {
                                AttCustomType act = (AttCustomType)vs;
                                AttCustomType act2 = (AttCustomType)v;
                                if (act.DataType == act2.DataType && (act.Guid == act2.Guid || (act.Guid == null && act2.Guid == "")))
                                {
                                    atu = false;
                                }
                            }
                            else if (vs is BasedOnReference)
                            {
                                BasedOnReference bof = (BasedOnReference)vs;
                                BasedOnReference bof2 = (BasedOnReference)v;
                                if (bof.ObjData == bof2.ObjData && bof.ObjKey.Equals(bof2.ObjKey))
                                {
                                    atu = false;
                                }
                            }
                            else if (vs is CT_GXTXVAL_type)
                            {
                                CT_GXTXVAL_type gxt = (CT_GXTXVAL_type)vs;
                                CT_GXTXVAL_type gxt2 = (CT_GXTXVAL_type)v;
                                if (gxt.Data.Count == gxt2.Data.Count)
                                {
                                    atu = false;
                                    foreach (KeyValuePair<string, string> current in gxt.Data)
                                    {
                                        if (!gxt2.Data.Contains(current))
                                        {
                                            atu = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        if (atu && vs != v)
                        {
                            var.SetPropertyValue(pnome, vs);
                        }

                    }
                }
                catch (Exception e)
                {
                    throw new HPatternException(String.Format("Erro ao criar variável: {0}", nome),e);
                }
            }
        }
Esempio n. 6
0
 internal bool MergeWebPanel(WebPanel obj, PatternInstanceElement c, UpdateObject uo, ObjectTemplate t)
 {
     int saveObject = 0;
     bool overwrite = (uo == UpdateObject.OverWrite ? true : false);
     saveObject += MergeVariables(obj.Variables, c, t.Variables, overwrite);
     saveObject += MergeConditions(obj.Conditions, c, t.Conditons, overwrite);
     if (uo != UpdateObject.OnlySource)
     {
         saveObject += MergeWebForm(obj.WebForm, c, t.WebForm, overwrite);
     }
     saveObject += MergeRules(obj.Rules, c, t.Rules, overwrite);
     saveObject += MergeEvents(obj.Events, c, t.Events, overwrite);
     saveObject += t.DeleteVariables(c, obj, overwrite);
     return saveObject > 0;
 }
Esempio n. 7
0
 internal int MergeWebForm(WebFormPart obj, PatternInstanceElement c, string template,bool overwrite)
 {
     if (!String.IsNullOrEmpty(template))
     {
         return MergeWebForm(obj, AppendTemplateOutput(obj.KBObject, obj, c, template));
     }
     return 0;
 }
Esempio n. 8
0
 internal int MergeVariables(VariablesPart obj, PatternInstanceElement c, string template, bool overwrite)
 {
     string oldValue = serializeVariables(obj);
     if (overwrite)
     {
         obj.Clear();
     }
     if (!String.IsNullOrEmpty(template))
     {
         XmlDocument x = AppendTemplateOutputInner(obj.KBObject, obj, c, template);
         List<string> tem = new List<string>();
         foreach (XmlNode xn in x.FirstChild.SelectNodes("Variable"))
         {
             string nome = xn.Attributes["Name"].Value.ToUpper();
             if (!tem.Contains(nome))
             {
                 tem.Add(nome);
                 XmlToVariable(obj, c, xn);
             }
         }
     }
     if (serializeVariables(obj) != oldValue)
     {
         return 1;
     }
     return 0;
 }
Esempio n. 9
0
        internal void AddTrn(PatternInstanceElement tabAttElement,Gx.Transaction gxt)
        {
            PatternInstanceElement tabElement = tabAttElement.Children.AddNewElement(InstanceChildren.Tab.Transaction);
            tabElement.Attributes[InstanceAttributes.Transaction._Transaction] = gxt;

            PatternInstanceElement parmsElement = tabElement.Children.AddNewElement(InstanceChildren.Transaction.Parameters);
            parmsElement.Children.AddNewElement(InstanceChildren.Parameters.Parameter).Attributes[InstanceAttributes.Parameter.Name] = "&Mode";
            foreach (TransactionAttribute ta in gxt.Structure.Root.PrimaryKey)
            {
                parmsElement.Children.AddNewElement(InstanceChildren.Parameters.Parameter).Attributes[InstanceAttributes.Parameter.Name] = ta.Name;
            }

            //TODO falta preencher o Form da Transaction, vamos fazer depois do item #20 - Novo elemento TransactionAtribute

            PatternInstanceElement tabAttsElement = tabAttElement.Children.AddNewElement(InstanceChildren.Tab.Attributes);
            foreach (TransactionAttribute ta in gxt.Structure.Root.Attributes)
            {
                PatternInstanceElement taElement = tabAttsElement.Children.AddNewElement(InstanceChildren.Attributes.Attribute);
                taElement.Attributes[InstanceAttributes.Attribute._Attribute] = ta.Attribute;
                taElement.Attributes[InstanceAttributes.Attribute.Description] = ta.Attribute.Description;
            }
        }
Esempio n. 10
0
 internal static UpdateObject getUpdate(PatternObject tipo, PatternInstanceElement element)
 {
     string gera = element.Attributes.GetPropertyValueString(getTemplate(tipo).AttributeUpdate);
     UpdateObject uo = UpdateObject.CreateDefault;
     if (gera == TransactionElement.UpdateObjectValue.DoNotUpdate)
     {
         uo = UpdateObject.DoNotUpdate;
     }
     else if (gera == TransactionElement.UpdateObjectValue.Overwrite)
     {
         uo = UpdateObject.OverWrite;
     }
     else if (gera == TransactionElement.UpdateObjectValue.OnlyRulesEventsAndConditions)
     {
         uo = UpdateObject.OnlySource;
     }
     return uo;
 }
Esempio n. 11
0
 internal bool MergeProcedure(Procedure obj, PatternInstanceElement c, UpdateObject uo, ObjectTemplate t)
 {
     int saveObject = 0;
     bool overwrite = (uo == UpdateObject.OverWrite ? true : false);
     saveObject += MergeVariables(obj.Variables, c, t.Variables, overwrite);
     saveObject += MergeConditions(obj.Conditions, c, t.Conditons, overwrite);
     saveObject += MergeRules(obj.Rules, c, t.Rules, overwrite);
     saveObject += MergeProcedureSource(obj.ProcedurePart, c, t.Source, overwrite);
     return saveObject > 0;
 }
Esempio n. 12
0
 internal int MergeDataProviderSource(DataProviderSourcePart obj, PatternInstanceElement c, string template, bool overwrite)
 {
     string oldValue = obj.Source;
     if (!String.IsNullOrEmpty(template))
     {
         obj.Source = MergeTextMarked(obj.Source, AppendTemplateOutput(obj.KBObject, obj, c, template),overwrite);
     }
     return (oldValue != obj.Source ? 1 : 0);
 }
Esempio n. 13
0
 internal bool MergeDataProvider(DataProvider obj, PatternInstanceElement c, UpdateObject uo, ObjectTemplate t)
 {
     int saveObject = 0;
     bool overwrite = (uo == UpdateObject.OverWrite ? true : false);
     saveObject += MergeVariables(obj.Variables, c, t.Variables, overwrite);
     saveObject += MergeRules(obj.Rules, c, t.Rules, overwrite);
     saveObject += MergeDataProviderSource(obj.DataProviderSource, c, t.Source, overwrite);
     return saveObject > 0;
 }
Esempio n. 14
0
 internal int MergeConditions(ConditionsPart obj, PatternInstanceElement c, string template, bool overwrite)
 {
     string oldValue = obj.Source;
     if (!String.IsNullOrEmpty(template))
     {
         obj.Source = MergeTextMarked(obj.Source, AppendTemplateOutput(obj.KBObject, obj, c, template),overwrite);
     }
     if (oldValue != obj.Source)
         return 1;
     return 0;
 }
Esempio n. 15
0
 internal String AppendTemplateOutputXml(KBObject obj, KBObjectPart part, PatternInstanceElement element, String template)
 {
     return AppendTemplateOutputInner(obj, part, element, template).InnerXml;
 }
Esempio n. 16
0
 internal XmlDocument AppendTemplateOutputInner(KBObject obj, KBObjectPart part, PatternInstanceElement element, String template)
 {
     Generator.GeneratorParameters parms = new Generator.GeneratorParameters();
     DefaultProvider.PrepareTemplateParameters(parms);
     parms.Properties["Object"] = obj;
     parms.Properties["Part"] = part;
     parms.Properties["Instance"] = Instance;
     parms.Properties["Element"] = element;
     StringBuilder sb = new StringBuilder();
     Heurys.Patterns.HPattern.HPatternTransactionUpdater.AppendTemplateOutput(sb, template, parms);
     XmlDocument xmlDocument = new XmlDocument();
     xmlDocument.LoadXml(sb.ToString());
     return xmlDocument;
 }
Esempio n. 17
0
            public int DeleteVariables(PatternInstanceElement element, KBObject obj, bool overwrite)
            {
                int ret = 0;
                if (obj is WebPanel
                    && (element.Type == InstanceElements.Selection || element.Type == InstanceElements.Tab)
                    && element.SelectElements("actions/action[@multiRowSelection=\"True\"]").Count == 0)
                {
                    bool canDelete = true;
                    WebPanel webp = (WebPanel)obj;

                    if (overwrite == false)
                    {
                        if (webp.Events.Source.IndexOf("&SelectedRows.") >= 0)
                        {
                            canDelete = false;
                        }
                        else if (webp.Events.Source.IndexOf("&SelectedRow.") >= 0)
                        {
                            canDelete = false;
                        }
                    }
                    if (canDelete)
                    {
                        Variable var = webp.Variables.GetVariable("SelectedRows");
                        if (var != null)
                        {
                            ret = 1;
                            webp.Variables.Remove(var);
                        }
                        var = null;
                        var = webp.Variables.GetVariable("SelectedRow");
                        if (var != null)
                        {
                            ret = 1;
                            webp.Variables.Remove(var);
                        }
                    }
                }

                return ret;
            }
Esempio n. 18
0
 internal int DeleteVariables(PatternInstanceElement element, KBObject obj, bool overwrite)
 {
     if (mDelVar != null) {
         return mDelVar.DeleteVariables(element, obj, overwrite);
     }
     return 0;
 }
Esempio n. 19
0
 public CommandAddFilterVariable(PatternInstanceElement onElement)
     : base(onElement)
 {
 }
Esempio n. 20
0
        internal int MergeProcedureSource(ProcedurePart obj, PatternInstanceElement c, string template, bool overwrite)
        {
            string oldValue = obj.Source;
            if (!String.IsNullOrEmpty(template))
            {
                try
                {
                    HParser pOld = new HParser(obj.Source);
                    HParser pNew = new HParser(AppendTemplateOutput(obj.KBObject, obj, c, template));
                    Dictionary<string, string> sNew = pNew.GetSubs();
                    Dictionary<string, string> sOld = pOld.GetSubs(true, sNew.Keys);
                    pOld.DeleteBlocks(new string[] { "Sub" }, new string[] { "EndSub" });
                    pNew.DeleteBlocks(new string[] { "Sub" }, new string[] { "EndSub" });

                    HParser p = (overwrite ? pNew : pOld);
                    p.ReplaceInsertBlockMarked(HParser.BuildBlockMarked(pNew.Text));
                    p.ClearCode();

                    MergeEventCode(sNew, sOld, "Sub", pNew, pOld, overwrite);

                    obj.Source = p.Text;
                }
                catch (Exception ex)
                {
                    throw new TemplateException(obj.KBObject.Name, ex);
                }

            }
            return (oldValue != obj.Source ? 1 : 0);
        }
Esempio n. 21
0
 public CommandAddTab(PatternInstanceElement onElement)
     : base(onElement)
 {
 }
Esempio n. 22
0
 internal bool MergeSDT(SDT obj, PatternInstanceElement c, UpdateObject uo, ObjectTemplate t)
 {
     int saveObject = 0;
     bool overwrite = (uo == UpdateObject.OverWrite ? true : false);
     saveObject += MergeSDTStructure(obj.SDTStructure, c, t.Source, overwrite);
     return saveObject > 0;
 }
Esempio n. 23
0
 internal int MergeSDTStructure(SDTStructurePart obj, PatternInstanceElement c, string template, bool overwrite)
 {
     string oldValue = getSDTStructure(obj);
     if (!String.IsNullOrEmpty(template))
     {
         string newValue = AppendTemplateOutputXml(obj.KBObject, obj, c, template);
         if (oldValue == newValue)
         {
             return 0;
         }
         try
         {
             XmlReader xr = new XmlTextReader(new StringReader(newValue));
             BLServices.KnowledgeManager.ImportInPart(xr, obj);
         }
         catch (Exception e)
         {
             throw new TemplateException("ImportInPart - "+template+": "+e.Message, (e.InnerException != null ? e.InnerException : e), obj.KBObject.Name);
         }
     }
     return (oldValue != getSDTStructure(obj) ? 1 : 0);
 }
Esempio n. 24
0
 private string CreateCondition(Gx.Attribute att,PatternInstanceElement element)
 {
     // TODO: Customize these options.
     return HPatternInstanceGenerator.CreateDefaultCondition(att,element);
 }
Esempio n. 25
0
 internal static string CreateDefaultCondition(Gx.Attribute att,PatternInstanceElement element)
 {
     HPatternSettings settings = HPatternSettings.Get(element.Instance.Model);
     return getCondition(att, settings);
 }