Exemplo n.º 1
0
        public static int GetMaxId()
        {
            //Session session = new Session();
            //session.ConnectionString = XpoDefault.ConnectionString;

            // Obtain the persistent object class info required by the GetObjects method
            XPClassInfo dstnClass = XpoDefault.Session.GetClassInfo(typeof(DataStore));

            // Create criteria to get objects
            CriteriaOperator criteria = null; // new BinaryOperator("Discontinued", true);

            // Create a sort list if objects must be processed in a specific order
            SortingCollection sortProps = null; // new SortingCollection(null);
                                                // sortProps.Add(new SortProperty("Price", DevExpress.Xpo.DB.SortingDirection.Ascending));

            // Create criteria patcher to filter out the objects marked as "deleted"
            // and to support loading of inherited objects of a given base persistent class
            CollectionCriteriaPatcher patcher = new DevExpress.Xpo.Generators.CollectionCriteriaPatcher(false, XpoDefault.Session.TypesManager);
            // Call GetObjects
            ICollection collection = XpoDefault.Session.GetObjects(dstnClass, criteria, sortProps, 0, patcher, true);

            int max = int.MinValue;

            // Do processing
            foreach (DataStore dstn in collection)
            {
                max = Math.Max(max, dstn.Id);
            }
            return(max);
        }
        private void wizardControl1_FinishClick(object sender, CancelEventArgs e)
        {
            FinishClicked = true;
            {
                ParentName = this.parentTreeListLookUpEdit.Text;
                {
                    //Session session = new Session();
                    //session.ConnectionString = XpoDefault.ConnectionString;

                    // Obtain the persistent object class info required by the GetObjects method
                    XPClassInfo dstnClass = XpoDefault.Session.GetClassInfo(typeof(DataStoreTreeNode));

                    // Create criteria to get objects
                    CriteriaOperator criteria;
                    criteria = null; // new BinaryOperator("Discontinued", true);

                    // Create a sort list if objects must be processed in a specific order
                    SortingCollection sortProps = null; // new SortingCollection(null);
                    // sortProps.Add(new SortProperty("Price", DevExpress.Xpo.DB.SortingDirection.Ascending));

                    // Create criteria patcher to filter out the objects marked as "deleted"
                    // and to support loading of inherited objects of a given base persistent class
                    CollectionCriteriaPatcher patcher = new DevExpress.Xpo.Generators.CollectionCriteriaPatcher(false, XpoDefault.Session.TypesManager);
                    // Call GetObjects
                    ICollection collection = XpoDefault.Session.GetObjects(dstnClass, criteria, sortProps, 0, patcher, true);

                    int max = int.MinValue;
                    // Do processing
                    foreach (DataStoreTreeNode dstn in collection)
                    {
                        max = Math.Max(max, dstn.Id);
                    }
                    NewDataStoreTreeNode = new DataStoreTreeNode();
                    {
                        NewDataStoreTreeNode.Id               = max + 1;
                        NewDataStoreTreeNode.ParentId         = (int)this.parentTreeListLookUpEdit.EditValue;
                        NewDataStoreTreeNode.IsFolder         = isItFolderCheckEdit.Checked;
                        NewDataStoreTreeNode.Name             = this.nameTextEdit.Text;
                        NewDataStoreTreeNode.SyntaxProvider   = this.syntaxProviderComboBoxEdit.SelectedItem as string;
                        NewDataStoreTreeNode.ConnectionString = this.connectionStringMemoEdit.Text;
                        NewDataStoreTreeNode.Description      = this.descriptionNodeMemoEdit.Text;
                        NewDataStoreTreeNode.Save();
                    }
                }
            }
            this.Close();
        }