Exemplo n.º 1
0
        public override IQueryResult ExecuteQuery(QQuery query)
        {
            Transaction trans = query.Transaction();

            query.CaptureQueryResultConfig();
            query.Marshall();
            MsgD msg = Msg.QueryExecute.GetWriter(Serializer.Marshall(trans, query));

            Write(msg);
            return(ReadQueryResult(trans));
        }
Exemplo n.º 2
0
        //private void toolExpression_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
        //{
        //    QQuery exp = e.ClickedItem.Tag as QQuery;
        //    Query = exp;
        //}

        private void ToolParseClick(object sender, EventArgs e)
        {
            if (Query == null)
            {
                Query = new QQuery();
            }

            var test = textQuery.PlainText;

            Query.Parse(test);
        }
Exemplo n.º 3
0
        public static IEnumerable <UserReg> GetOld(User User)
        {
            var filter = new QQuery(string.Empty, UserReg.DBTable);

            filter.BuildPropertyParam(nameof(UserReg.UserId), CompareType.Equal, User.PrimaryId);
            filter.BuildPropertyParam(nameof(UserReg.RegType), CompareType.Equal, UserRegType.Password);
            filter.Orders.Add(new QOrder {
                Column = UserReg.DBTable.ParseProperty(nameof(UserReg.Id)), Direction = ListSortDirection.Descending
            });
            return(UserReg.DBTable.Load(filter, DBLoadParam.Load | DBLoadParam.Synchronize));
        }
Exemplo n.º 4
0
        public Balance GetBalance(object typeid)
        {
            var filter = new QQuery("", Balance.DBTable);

            filter.BuildPropertyParam(nameof(Balance.AccountId), CompareType.Equal, PrimaryId);
            filter.BuildPropertyParam(nameof(Balance.TypeId), CompareType.Equal, typeid);
            var balances = Balance.DBTable.Load(filter, DBLoadParam.Load | DBLoadParam.Synchronize).ToList();

            balances.Sort(new DBComparer <Balance, DateTime?>(Balance.BalanceDateKey, ListSortDirection.Descending));
            return(balances.FirstOrDefault());
        }
Exemplo n.º 5
0
        public static void SynchMessage()
        {
            if (MessageAddress.DBTable == null)
            {
                return;
            }
            var query = new QQuery(string.Empty, MessageAddress.DBTable);

            query.BuildPropertyParam(nameof(MessageAddress.UserId), CompareType.Equal, GuiEnvironment.User?.Id);
            query.BuildPropertyParam(nameof(MessageAddress.DateRead), CompareType.Is, DBNull.Value);
            MessageAddress.DBTable.Load(query, DBLoadParam.Synchronize, null).LastOrDefault();
        }
Exemplo n.º 6
0
 private void ToolReportClick(object sender, EventArgs e)
 {
     if (dataTree.SelectedDBItem is DBTable)
     {
         var query = new QQuery {
             Table = (DBTable)dataTree.SelectedDBItem
         };
         var projecth = new ProjectHandler {
             Project = query
         };
         GuiService.Main.CurrentProject = projecth;
     }
 }
Exemplo n.º 7
0
        public IEnumerable <T> LoadByStamp(QQuery query, DBTransaction transaction = null)
        {
            if (items.Count == 0)
            {
                return(Load(query));
            }

            query.Columns.Clear();
            query.Columns.Add(new QColumn(PrimaryKey));
            query.Columns.Add(new QColumn(StampKey));

            return(Load(query.ToCommand(), DBLoadParam.Synchronize, transaction));
        }
Exemplo n.º 8
0
 public Task <IEnumerable <T> > LoadAsync(QQuery query, DBLoadParam param = DBLoadParam.None, DBTransaction transaction = null)
 {
     return(Task.Run <IEnumerable <T> >(() =>
     {
         try
         {
             return Load(query, param, transaction);
         }
         catch (Exception e)
         {
             Helper.OnException(e);
             return null;
         }
     }));
 }
Exemplo n.º 9
0
        public static void LoadDocuments(User user)
        {
            var qWork = new QQuery(string.Empty, DocumentWork.DBTable);

            qWork.Columns.Add(new QColumn(nameof(DocumentWork.Document)));
            qWork.BuildPropertyParam(nameof(DocumentWork.IsComplete), CompareType.Equal, false);
            qWork.BuildPropertyParam(nameof(DocumentWork.UserId), CompareType.Equal, user);

            var qDocs = new QQuery(string.Empty, Document.DBTable);

            qDocs.BuildPropertyParam(nameof(Document.Id), CompareType.In, qWork);

            Document.DBTable.Load(qDocs, DBLoadParam.Synchronize);
            DocumentWork.DBTable.Load(qWork, DBLoadParam.Synchronize);
        }
Exemplo n.º 10
0
        public static async Task <User> GetUser(string login, string passoword)
        {
            var query = new QQuery(string.Empty, User.DBTable);

            query.BuildPropertyParam(nameof(Login), CompareType.Equal, login);
            query.BuildPropertyParam(nameof(Password), CompareType.Equal, passoword);
            var user = User.DBTable.Select(query).FirstOrDefault();

            if (user != null)
            {
                await UserReg.LogUser(user, UserRegType.Authorization, "GetUser");
            }

            return(user);
        }
 public IList <ElementType> Query <ElementType>(Transaction trans, Type extent, IComparer <ElementType> comparer)
 {
     lock (Lock())
     {
         trans = CheckTransaction(trans);
         QQuery query = (QQuery)Query(trans);
         query.Constrain(extent);
         if (null != comparer)
         {
             query.SortBy(new GenericComparerAdaptor <ElementType>(comparer));
         }
         IQueryResult queryResult = query.GetQueryResult();
         return(new GenericObjectSetFacade <ElementType>(queryResult));
     }
 }
Exemplo n.º 12
0
 public DBTableView(DBTable <T> table, QParam defaultFilter, DBViewKeys mode = DBViewKeys.None, DBStatus statusFilter = DBStatus.Empty)
 {
     propertyHandler = null;
     this.table      = table;
     FilterQuery     = new Query <T>();
     Query           = new QQuery();
     TypeFilter      = typeof(T);
     DefaultParam    = defaultFilter;
     StatusFilter    = statusFilter;
     keys            = mode;
     table.AddView(this);
     if ((keys & DBViewKeys.Empty) != DBViewKeys.Empty)
     {
         UpdateFilter();
     }
 }
Exemplo n.º 13
0
        public PersoneIdentify FindByCustomer(object customer)
        {
            if (customer == null)
            {
                return(null);
            }
            var filter = new QQuery("", PersoneIdentify.DBTable);

            filter.BuildPropertyParam(nameof(PersoneIdentify.PersoneId), CompareType.Equal, customer);
            var list = ((IEnumerable <PersoneIdentify>)table.LoadItems(filter, DBLoadParam.Load)).ToList();

            if (list.Count > 1)
            {
                list.Sort(new DBComparer <PersoneIdentify, int?>(Table.PrimaryKey, ListSortDirection.Descending));
            }
            return(list.Count == 0 ? null : list[0] as PersoneIdentify);
        }
Exemplo n.º 14
0
        private void ToolCreateClick(object sender, EventArgs e)
        {
            if (Table == null)
            {
                return;
            }

            //if (DataEnvir.Items.Queries.Contains (toolExpName.Text)) {
            //	MessageBox.Show ("Запрос с данным кодом уже имеется!");
            //	return;
            //}

            Table = Table;
            Query = new QQuery {
                Table = Table
            };
            //DataEnvir.Items.Queries.Add (expression);
        }
Exemplo n.º 15
0
        public async Task <object> Execute(ExecuteArgs parameters)
        {
            var filter = new QQuery(string.Empty, DocumentWork.DBTable);

            filter.BuildPropertyParam(nameof(DocumentWork.IsComplete), CompareType.Equal, false);
            filter.BuildPropertyParam(nameof(DocumentWork.IsSystem), CompareType.Equal, true);
            //string filter = string.Format("{0}!='{1}' and {2} in (select {3} from {4} where {5} = '{6}')",
            foreach (DocumentWork work in DocumentWork.DBTable.Load(filter, DBLoadParam.Load | DBLoadParam.Synchronize, parameters.Transaction))
            {
                if (work.Stage == null || work.Document == null)
                {
                    continue;
                }
                work.Document.ExecuteProceduresByWork(work, StageParamProcudureType.Manual, parameters.Transaction);
                await work.Document.Save(parameters.Transaction);
            }
            return(null);
        }
Exemplo n.º 16
0
        public IEnumerable <T> Select(QQuery query, IEnumerable <T> list = null)
        {
            IEnumerable <T> buf = null;

            if (query.Parameters.Count == 0)
            {
                buf = list ?? this;
            }
            else if (query.Parameters.Count == 1)
            {
                buf = Select(query.Parameters[0], list);
            }
            else
            {
                buf = Select(query.Parameters, list);
            }
            return(buf);
        }
Exemplo n.º 17
0
        private void LoadTable(DBTable table)
        {
            rows.Clear();
            wait.Reset();
            string filter = table.GetStatusParam(DBStatus.New | DBStatus.Edit | DBStatus.Delete).Format();

            if (!wait.WaitOne(0))
            {
                foreach (DBItem row in table.LoadItems("where " + filter))
                {
                    if (wait.WaitOne(0))
                    {
                        break;
                    }

                    if (rows.Find("Row", CompareType.Equal, row) == null)
                    {
                        try
                        {
                            rows.Add(new LogMap(row));
                        }
                        catch
                        {
                        }
                    }
                }
            }
            using (QQuery qdelete = new QQuery("", (DBTable)table.LogTable))
            {
                qdelete.BuildParam(table.LogTable.ElementTypeKey, CompareType.Equal, DBLogType.Delete);
                qdelete.BuildParam(table.LogTable.StatusKey, CompareType.Equal, DBStatus.New);
                foreach (DBLogItem log in table.LogTable.LoadItems(qdelete, DBLoadParam.Synchronize))
                {
                    LogMap change = new LogMap {
                        Table = table
                    };
                    //change.Logs.Add(log);
                    change.RefreshChanges();
                    rows.Add(change);
                }
            }
            //wait.Set();
            rows.OnCollectionChanged(NotifyCollectionChangedAction.Reset);
        }
Exemplo n.º 18
0
 public IEnumerable <T> LoadCache(string filter, DBLoadParam loadParam = DBLoadParam.Referencing, DBTransaction transaction = null)
 {
     if (!queryChache.TryGetValue(filter, out var query))
     {
         query = new QQuery(filter, this);
         Load(query, loadParam, transaction);
         queryChache.TryAdd(filter, query);
     }
     if (TypeHelper.IsInterface(typeof(T), typeof(IGroup)))
     {
         var temp = Select(query).ToList();
         ListHelper.QuickSort(temp, TreeComparer <IGroup> .Default);
         return(temp);
     }
     else
     {
         return(Select(query));
     }
 }
Exemplo n.º 19
0
        public static QParam CreateRefsParam(object id)
        {
            var qrefing = new QQuery(string.Format("select {0} from {1} where {2} = {3}",
                                                   DocumentReference.DBTable.ParseProperty(nameof(DocumentReference.DocumentId)).Name,
                                                   DocumentReference.DBTable.Name,
                                                   DocumentReference.DBTable.ParseProperty(nameof(DocumentReference.ReferenceId)).Name,
                                                   id));
            var qrefed = new QQuery(string.Format("select {2} from {1} where {0} = {3}",
                                                  DocumentReference.DBTable.ParseProperty(nameof(DocumentReference.DocumentId)).Name,
                                                  DocumentReference.DBTable.Name,
                                                  DocumentReference.DBTable.ParseProperty(nameof(DocumentReference.ReferenceId)).Name,
                                                  id));

            var param = new QParam();

            param.Parameters.Add(new QParam(LogicType.And, DBTable.PrimaryKey, CompareType.In, qrefed));
            param.Parameters.Add(new QParam(LogicType.Or, DBTable.PrimaryKey, CompareType.In, qrefing));
            return(param);
        }
Exemplo n.º 20
0
        private void CheckDelete(QQuery filter, IEnumerable <T> buf, DBLoadParam param, DBTransaction transaction)
        {
            var list    = Select(filter).ToList();
            var bufList = buf.ToList();

            if (list.Count > bufList.Count)
            {
                foreach (var item in list)
                {
                    if ((item.UpdateState & DBUpdateState.Insert) != DBUpdateState.Insert && !bufList.Contains(item))
                    {
                        if (transaction.View != null && transaction.View.IsStatic)
                        {
                            transaction.View.Remove(item);
                        }
                        Remove(item);
                    }
                }
            }
        }
Exemplo n.º 21
0
        public static async Task <Instance> GetByNetId(IPEndPoint endPoint, bool create, IUserIdentity user = null)
        {
            var query = new QQuery(DBTable);

            query.BuildPropertyParam(nameof(Host), CompareType.Equal, endPoint.Address.ToString());
            query.BuildPropertyParam(nameof(Port), CompareType.Equal, endPoint.Port);
            query.BuildPropertyParam(nameof(Action), CompareType.Equal, false);
            var instance = DBTable.Load(query).LastOrDefault();

            if (instance == null && create)
            {
                instance = new Instance
                {
                    EndPoint  = endPoint,
                    Active    = true,
                    IsCurrent = true
                };
                await instance.Save(user);
            }
            return(instance);
        }
Exemplo n.º 22
0
        public IEnumerable <T> Load(QQuery query, DBLoadParam param = DBLoadParam.None, DBTransaction transaction = null)
        {
            if (query.Table != this)
            {
                throw new ArgumentException(nameof(query));
            }
            if (Count == 0)
            {
                param &= ~DBLoadParam.CheckDeleted;
            }
            var buf = Load(query.ToCommand(true), param, transaction);

            if (buf != null && (param & DBLoadParam.CheckDeleted) == DBLoadParam.CheckDeleted)
            {
                CheckDelete(query, buf, param, transaction);
            }
            if (query.Parameters.Count == 0)
            {
                IsSynchronized = true;
            }
            return(buf);
        }
Exemplo n.º 23
0
        protected override IEnumerable ListFind(string filter)
        {
            IEnumerable list = null;

            if (Table.CodeKey != null)
            {
                DBItem item = Table.LoadItemByCode(filter.Trim(), Table.CodeKey, Table.IsSynchronized ? DBLoadParam.None : DBLoadParam.Load | DBLoadParam.Synchronize);
                if (item != null)
                {
                    list = new object[] { item }
                }
                ;
            }
            if (list == null)
            {
                var query = new QQuery("", Table);
                query.SimpleFilter(EntryText);
                TableEditor.Loader.LoadAsync(query);
                list = query.Select();
            }
            return(list);
        }
Exemplo n.º 24
0
 public string FormatValue(QItem Value, IDbCommand command = null)
 {
     if (Value == null)
     {
         return(string.Empty);
     }
     if (Value is QQuery && ((QQuery)Value).Table != null)
     {
         QQuery squery = (QQuery)Value;
         if (squery.Columns.Count == 0)
         {
             squery.Columns.Add(new QColumn(squery.Table.PrimaryKey));
         }
         return("(" + squery.Format(command) + ")");
     }
     else if (Value is QExpression)
     {
         return("(" + Value.Format(command) + ")");
     }
     else
     {
         return(Value.Format(command));
     }
 }
Exemplo n.º 25
0
 /// <param name="q"></param>
 public virtual void LoadFromQuery(QQuery q)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 26
0
 public _IEnumerable_28(QQuery query)
 {
     this.query = query;
 }
Exemplo n.º 27
0
 public override void LoadFromQuery(QQuery query)
 {
     _iterable = new _IEnumerable_28(query);
 }
Exemplo n.º 28
0
 public QLinRoot(IQuery query, Type clazz)
 {
     _query = (QQuery)query;
     query.Constrain(clazz);
     QLinSupport.Context(clazz);
 }
Exemplo n.º 29
0
 public _IClosure4_35(MQueryExecute _enclosing, QQuery query)
 {
     this._enclosing = _enclosing;
     this.query      = query;
 }
Exemplo n.º 30
0
 private AbstractQueryResult ExecuteFully(QQuery query)
 {
     return((AbstractQueryResult)query.TriggeringQueryEvents(new _IClosure4_35(this,
                                                                               query)));
 }