コード例 #1
0
        //[NonPersistent()]
        //public bool PublishIntoDB { get; set; }
        //[NonPersistent()]
        //public bool PublishAsHtml { get; set; }

        protected DataGroup getGroupByNameOrNew(string name)
        {
            DataGroup returnValue = null;

            if (name != "")
            {
                //find group
                foreach (DataGroup group in Groups)
                {
                    if (group.Name == name)
                    {
                        returnValue = group;
                        break;
                    }
                }
                if (returnValue == null)
                {
                    //nieuwe groep aanmaken
                    DataGroup newgroup = new DataGroup();
                    newgroup.Name           = name;
                    newgroup.Site           = this.Site;
                    newgroup.DataCollection = this;
                    newgroup.Save();
                    returnValue = newgroup;
                }
            }
            return(returnValue);
        }
コード例 #2
0
ファイル: DataGroup.cs プロジェクト: hvanreenen/bitplate
        //        public void MoveItemsAndGroups(int fromOrderingNumber, int? tillOrderingNumber, MoveDirectionEnum direction)
        //        {
        //            //zowel groepen als items krijgen volgorde in de tree
        //            //union query waarbij groepen en item in 1 query staan.
        //            //resultaat van query wordt in BaseDataObject gezet.
        //            //veld title misbruiken om hier type (groep of item) in te bewaren
        //            //alleen de lagere nummers hoef je te updaten  (OrderingNumber <= orderingNumber)
        //            //krijgen allemaal 1 plekje lager, totaan tillOrderingNumber
        //            //ook subgroepen moeten worden geupdate, want hier wordt nieuwe hierarchie in nummering weergegeven
        //            string fromOrderingNumberString = this.OrderingNumber + "." + fromOrderingNumber.ToString("0000");
        //            string tillWhereClause = "";
        //            if (tillOrderingNumber.HasValue)
        //            {
        //                string tillOrderingNumberString = this.OrderingNumber + "." + tillOrderingNumber.Value.ToString("0000");
        //                tillWhereClause = String.Format(" AND OrderingNumber <= '{0}'", tillOrderingNumberString);
        //            }

        //            string sql = String.Format(@"SELECT ID, Name, 'Item' AS Title, OrderingNumber From DataItem WHERE FK_Parent_Group='{0}' AND OrderingNumber >= '{1}' {2}
        //UNION SELECT ID, Name, 'Group' AS Title, OrderingNumber From DataGroup WHERE FK_Parent_Group='{0}' AND OrderingNumber >= '{1}' {2}
        //ORDER BY OrderingNumber, Name", this.ID, fromOrderingNumberString, tillWhereClause);
        //            BaseCollection<BaseDataObject> dataObjects = BaseCollection<BaseDataObject>.LoadFromSql(sql);
        //            int currentOrderingNumber = fromOrderingNumber;
        //            foreach (BaseDataObject dataObject in dataObjects)
        //            {
        //                string newOrderingNumberString = "";
        //                if (direction == MoveDirectionEnum.Down)
        //                {
        //                    newOrderingNumberString = this.OrderingNumber + "." + (currentOrderingNumber - 1).ToString("0000");
        //                }
        //                else
        //                {
        //                    newOrderingNumberString = this.OrderingNumber + "." + (currentOrderingNumber + 1).ToString("0000");
        //                }

        //                string updateSql = String.Format("UPDATE Data{0} SET OrderingNumber='{1}' WHERE ID='{2}'", dataObject.Title, newOrderingNumberString, dataObject.ID);
        //                DataBase.Get().Execute(updateSql);
        //                if (dataObject.Title == "Group")
        //                {
        //                    dataObject.UpdateSubOrderingNumbers(newOrderingNumberString);
        //                }
        //                currentOrderingNumber++;
        //            }
        //        }

        //        public void MoveItemsAndGroupsDown(int fromOrderingNumber, int? tillOrderingNumber)
        //        {

        //            MoveItemsAndGroups(fromOrderingNumber, tillOrderingNumber, MoveDirectionEnum.Down);

        //        }

        //        public void MoveItemsAndGroupsUp(int fromOrderingNumber, int? tillOrderingNumber)

        //        {
        //            MoveItemsAndGroups(fromOrderingNumber, tillOrderingNumber, MoveDirectionEnum.Up);

        //        }

        //        internal string CalculateNewOrderingNumber()
        //        {
        //            string sql = String.Format(@"SELECT ID, Name, 'Item' AS Title, OrderingNumber From DataItem WHERE FK_Parent_Group='{0}'
        //UNION SELECT ID, Name, 'Group' AS Title, OrderingNumber From DataGroup WHERE FK_Parent_Group='{0}'", this.ID);
        //            BaseCollection<BaseDataObject> dataObjects = BaseCollection<BaseDataObject>.LoadFromSql(sql);
        //            int newOrderNumber = dataObjects.Count + 1;
        //            string newOrderingNumberString = this.OrderingNumber + "." + newOrderNumber.ToString("0000");
        //            return newOrderingNumberString;
        //        }

        public void Copy(string newName, Guid?dataCollectionID, Guid?parentGroupID, bool updateOrderNumber = false)
        {
            DataGroup newGroup = this.CreateCopy <DataGroup>(false);

            if (newName != "")
            {
                newGroup.Name = newName;
            }
            newGroup.LastPublishedDate = null;

            if (dataCollectionID.HasValue)
            {
                newGroup.DataCollection    = new DataCollection();
                newGroup.DataCollection.ID = dataCollectionID.Value;
            }
            if (parentGroupID.HasValue)
            {
                newGroup.ParentGroup    = new DataGroup();
                newGroup.ParentGroup.ID = parentGroupID.Value;
            }
            if (updateOrderNumber)
            {
                //gekopieerde item krijgt 1 plek hoger volgnummer
                newGroup.OrderNumber++;
            }
            newGroup.Save();

            if (updateOrderNumber)
            {
                //de rest van de items moeten 1 plek opschuiven om plaats te maken
                int newOrderNumber = newGroup.OrderNumber;
                if (newGroup.ParentGroup != null)
                {
                    string sql = String.Format("UPDATE DataGroup SET OrderNumber = OrderNumber + 1 WHERE OrderNumber >= {0} AND ID != '{1} ' AND FK_Parent_Group = '{2}'", newOrderNumber, newGroup.ID, this.ParentGroup.ID);
                    DataBase.Get().Execute(sql);
                }
                else
                {
                    string sql = String.Format("UPDATE DataGroup SET OrderNumber = OrderNumber + 1 WHERE OrderNumber >= {0} AND ID != '{1} ' AND FK_DataCollection = '{2}' AND FK_Parent_Group IS NULL", newOrderNumber, newGroup.ID, this.DataCollection.ID);
                    DataBase.Get().Execute(sql);
                }
            }


            foreach (DataItem item in this.GetItems())
            {
                item.Copy(item.Name, newGroup.DataCollection.ID, newGroup.ID);
            }

            foreach (DataGroup subGroup in this.GetSubGroups())
            {
                subGroup.Copy(subGroup.Name, newGroup.DataCollection.ID, newGroup.ID);
            }
        }
コード例 #3
0
        public void MoveGroups(string groupid, int newOrderingnumber)
        {
            DataGroup group             = BaseObject.GetById <DataGroup>(new Guid(groupid));
            int       oldOrderingNumber = group.OrderNumber;

            if (oldOrderingNumber < newOrderingnumber)
            {
                //nummer wordt hoger: alles tussen oude nummer en nieuwe nummer 1 plek lager zetten
                string sql = String.Format("UPDATE DataGroup SET OrderNumber = OrderNumber - 1 WHERE OrderNumber > {0} And OrderNumber <= {1} AND FK_DataCollection = '{2}' AND FK_Parent_Group IS NULL", oldOrderingNumber, newOrderingnumber, this.ID);
                DataBase.Get().Execute(sql);
            }
            else if (oldOrderingNumber > newOrderingnumber)
            {
                //nummer wordt lager: alles tussen nieuwe nummer en oude nummer 1 plek verder zetten
                string sql = String.Format("UPDATE DataGroup SET OrderNumber = OrderNumber + 1 WHERE OrderNumber < {0} And OrderNumber >= {1} AND FK_DataCollection = '{2}' AND FK_Parent_Group IS NULL", oldOrderingNumber, newOrderingnumber, this.ID);
                DataBase.Get().Execute(sql);
            }
            group.OrderNumber = newOrderingnumber;
            group.Save();
        }