示例#1
0
 public Condition ScratchPadCondition()
 {
     Condition c;
     var q = (from cc in Queries
              where cc.Owner == Util.UserName
              where !cc.Ispublic
              where cc.Name == Util.ScratchPad2
              orderby cc.LastRun // get the oldest one
              select cc).ToList();
     Query query = null;
     if (q.Count < 5)
     {
         c = Condition.CreateNewGroupClause();
         query = new Query
         {
             QueryId = c.Id,
             Owner = Util.UserName,
             Created = DateTime.Now,
             LastRun = DateTime.Now,
             Name = Util.ScratchPad2,
             Text = c.ToXml()
         };
         Queries.InsertOnSubmit(query);
         SubmitChanges();
     }
     else
     {
         query = q.First();
         c = query.ToClause();
     }
     c.Id = query.QueryId; // force these to match
     c.JustLoadedQuery = query;
     return c;
 }
示例#2
0
 public void UpdateModel()
 {
     if (query == null)
         query = DbUtil.Db.LoadQueryById2(QueryId);
     this.CopyPropertiesTo(query);
     DbUtil.Db.SubmitChanges();
 }
示例#3
0
 public Condition FetchLastQuery()
 {
     var q = (from cc in Queries
              where cc.Owner == Util.UserName
              //where !cc.Ispublic
              orderby cc.LastRun descending
              select cc).FirstOrDefault();
     Condition c;
     if (q == null)
     {
         c = Condition.CreateNewGroupClause();
         c.AddNewClause();
         q = new Query
         {
             QueryId = c.Id,
             Owner = Util.UserName,
             Created = DateTime.Now,
             LastRun = DateTime.Now,
             Name = Util.ScratchPad2,
             Text = c.ToXml()
         };
         Queries.InsertOnSubmit(q);
     }
     else
         c = q.ToClause();
     c.Id = q.QueryId; // force these to match
     c.justloadedquery = q;
     c.Description = q.Name;
     return c;
 }
示例#4
0
 public List<Query> FetchLastFiveQueries()
 {
     var q = from cc in Queries
             where cc.Owner == Util.UserName
             where !cc.Ispublic
             where cc.Name != Util.ScratchPad2
             orderby cc.LastRun descending
             select cc;
     var list = q.Take(5).ToList();
     if (!list.Any())
     {
         var c = Condition.CreateNewGroupClause();
         c.AddNewClause();
         var query = new Query
         {
             QueryId = c.Id,
             Owner = Util.UserName,
             Created = DateTime.Now,
             LastRun = DateTime.Now,
             Text = c.ToXml()
         };
         Queries.InsertOnSubmit(query);
         SubmitChanges();
         list.Add(query);
     }
     return list;
 }
示例#5
0
        public void Save(CMSDataContext Db, bool increment = false, string owner = null)
        {
            var q = (from e in Db.Queries
                     where e.QueryId == Id
                     select e).FirstOrDefault();

            if (q == null)
            {
                q = new Query
                {
                    QueryId = Id,
                    Owner = Util.UserName,
                    Created = DateTime.Now,
                    Ispublic = IsPublic,
                    Name = Description
                };
                Db.Queries.InsertOnSubmit(q);
            }
            if(increment)
                q.LastRun = DateTime.Now;

            if (Description != q.Name)
            {
                var same = (from v in Db.Queries
                            where !v.Ispublic
                            where v.Owner == Util.UserName
                            where v.Name == Description
                            orderby v.LastRun descending
                            select v).FirstOrDefault();
                if (same != null)
                    same.Text = ToXml();
                else
                {
                    var c = Clone();
                    var cq = new Query
                    {
                        QueryId = c.Id,
                        Owner = Util.UserName,
                        Created = q.Created,
                        Ispublic = q.Ispublic,
                        Name = q.Name,
                        Text = c.ToXml(),
                        RunCount = q.RunCount,
                        CopiedFrom = q.CopiedFrom,
                        LastRun = q.LastRun
                    };
                    Db.Queries.InsertOnSubmit(cq);
                }
            }
            q.Name = Description;
            q.LastRun = DateTime.Now;
            if(owner.HasValue())
                q.Owner = owner;
            q.Ispublic = IsPublic;
            if (increment)
                q.RunCount = q.RunCount + 1;
            q.Text = ToXml();
            Db.SubmitChanges();
        }
示例#6
0
 public Query StandardQuery(string name, QueryType typ)
 {
     var qb = Queries.FirstOrDefault(c => c.Owner == STR_System && c.Name == name);
     if (qb == null)
     {
         var c = Condition.CreateNewGroupClause();
         c.AddNewClause(typ, CompareType.Equal, "1,True");
         qb = new Query
         {
             QueryId = c.Id,
             Owner = STR_System,
             Created = DateTime.Now,
             LastRun = DateTime.Now,
             Name = name,
             Text = c.ToXml()
         };
         Queries.InsertOnSubmit(qb);
         SubmitChanges();
     }
     return qb;
 }
示例#7
0
 public SavedQueryInfo(Guid id)
 {
     query = DbUtil.Db.LoadQueryById2(id);
     this.CopyPropertiesFrom(query);
 }