public override IEnumerable<IEditorScript> GetScripts(ICSharpCode.AvalonEdit.Document.ITextSource text, int offset)
 {
   var item = GetCurrentItem(text, offset);
   if (item != null)
   {
     var generator = new ScriptMenuGenerator()
     {
       Conn = _conn,
       ConnData = _connData,
       Items = new[] { item }
     };
     return generator.GetScripts().Concat(Enumerable.Repeat(new EditorScriptExecute() {
       Name = "Transform: Criteria to Where Clause",
       Execute = () =>
       {
         var doc = text as IDocument;
         if (doc != null)
         {
           var segment = GetCurrentQuerySegment(text, offset);
           var elem = XElement.Load(text.CreateReader(segment.Offset, segment.Length));
           AmlTransforms.CriteriaToWhereClause(elem);
           doc.Replace(segment.Offset, segment.Length, elem.ToString());
         }
         return Task.FromResult(true);
       }
     }, 1));
   }
   return Enumerable.Empty<IEditorScript>();
 }
Esempio n. 2
0
        public override IEnumerable <IEditorScript> GetScripts(ICSharpCode.AvalonEdit.Document.ITextSource text, int offset)
        {
            var item = GetCurrentItem(text, offset);

            if (item != null)
            {
                var generator = new ScriptMenuGenerator()
                {
                    Conn     = _conn,
                    ConnData = _connData,
                    Items    = new[] { item }
                };
                return(generator.GetScripts().Concat(Enumerable.Repeat(new EditorScriptExecute()
                {
                    Name = "Transform: Criteria to Where Clause",
                    Execute = () =>
                    {
                        var doc = text as IDocument;
                        if (doc != null)
                        {
                            var segment = GetCurrentQuerySegment(text, offset);
                            var elem = XElement.Load(text.CreateReader(segment.Offset, segment.Length));
                            AmlTransforms.CriteriaToWhereClause(elem);
                            doc.Replace(segment.Offset, segment.Length, elem.ToString());
                        }
                        return Task.FromResult(true);
                    }
                }, 1)));
            }
            return(Enumerable.Empty <IEditorScript>());
        }
 public override IEnumerable<IEditorScript> GetScripts(IEnumerable<DataRow> rows, string column)
 {
   var generator = new ScriptMenuGenerator()
   {
     Column = column,
     Conn = _conn,
     ConnData = _connData,
     Items = rows.Select(r => new DataRowItemData(r))
   };
   return generator.GetScripts();
 }
Esempio n. 4
0
        public override IEnumerable <IEditorScript> GetScripts(IEnumerable <DataRow> rows, string column)
        {
            var generator = new ScriptMenuGenerator()
            {
                Column   = column,
                Conn     = _conn,
                ConnData = _connData,
                Items    = rows.Select(r => new DataRowItemData(r))
            };

            return(generator.GetScripts());
        }
Esempio n. 5
0
        public override IEnumerable <IEditorScript> GetScripts(ITextSource text, int offset, bool readOnly)
        {
            var item = GetCurrentItem(text, offset);

            if (item != null)
            {
                var generator = new ScriptMenuGenerator()
                {
                    Conn     = _conn,
                    ConnData = _connData,
                    Items    = new[] { item }
                };

                var extras = new List <IEditorScript>();
                if (!readOnly)
                {
                    extras.Add(new EditorScriptExecute()
                    {
                        Name    = "Transform: Criteria to Where Clause",
                        Execute = () =>
                        {
                            var doc = text as IDocument;
                            if (doc != null)
                            {
                                try
                                {
                                    var segment   = GetCurrentQuerySegment(text, offset);
                                    var queryItem = _conn.AmlContext.FromXml(text.CreateReader(segment.Offset, segment.Length)).AssertItem();
                                    queryItem.QueryType().Set("ignore");
                                    queryItem.Where().Remove();
                                    var settings = new SqlSettings(_conn)
                                    {
                                        RenderOption = SqlRenderOption.WhereClause
                                    };

                                    var elem        = XElement.Load(text.CreateReader(segment.Offset, segment.Length));
                                    var whereClause = elem.Attribute("where")?.Value ?? "";
                                    if (whereClause != "")
                                    {
                                        whereClause += " and ";
                                    }
                                    whereClause += queryItem.ToQueryItem().ToArasSql(settings);
                                    elem.SetAttributeValue("where", whereClause);

                                    foreach (var child in elem.Elements().ToArray())
                                    {
                                        child.Remove();
                                    }

                                    doc.Replace(segment.Offset, segment.Length, elem.ToString());
                                }
                                catch (Exception ex)
                                {
                                    // Do nothing
                                }
                            }
                            return(Task.FromResult(true));
                        }
                    });
                }

                return(generator.GetScripts().Concat(extras));
            }
            return(Enumerable.Empty <IEditorScript>());
        }