public void Copy(string newName, Guid?dataCollectionID, Guid?parentGroupID, bool updateOrderNumber = false) { DataItem newItem = this.CreateCopy <DataItem>(false); if (newName != "") { newItem.Name = newName; } newItem.LastPublishedDate = null; if (dataCollectionID.HasValue) { newItem.DataCollection = new DataCollection(); newItem.DataCollection.ID = dataCollectionID.Value; } if (parentGroupID.HasValue) { newItem.ParentGroup = new DataGroup(); newItem.ParentGroup.ID = parentGroupID.Value; } if (updateOrderNumber) { //gekopieerde item krijgt 1 plek hoger volgnummer newItem.OrderNumber++; } newItem.Save(); if (updateOrderNumber) { //de rest van de items moeten 1 plek opschuiven om plaats te maken int newOrderNumber = newItem.OrderNumber; if (newItem.ParentGroup != null) { string sql = String.Format("UPDATE DataItem SET OrderNumber = OrderNumber + 1 WHERE OrderNumber >= {0} AND ID != '{1} ' AND FK_Parent_Group = '{2}'", newOrderNumber, newItem.ID, this.ParentGroup.ID); DataBase.Get().Execute(sql); } else { string sql = String.Format("UPDATE DataItem SET OrderNumber = OrderNumber + 1 WHERE OrderNumber >= {0} AND ID != '{1} ' AND FK_DataCollection = '{2}' AND FK_Parent_Group IS NULL", newOrderNumber, newItem.ID, this.DataCollection.ID); DataBase.Get().Execute(sql); } } if (DataItemLanguages != null) { foreach (DataItemLanguage languageItem in DataItemLanguages) { DataItemLanguage newLanguageItem = languageItem.CreateCopy <DataItemLanguage>(false); newLanguageItem.DataItem = newItem; newLanguageItem.Save(); } } }
public void MoveItems(string itemid, int newOrderingnumber) { DataItem item = BaseObject.GetById <DataItem>(new Guid(itemid)); int oldOrderingNumber = item.OrderNumber; if (oldOrderingNumber < newOrderingnumber) { //nummer wordt hoger: alles tussen oude nummer en nieuwe nummer 1 plek lager zetten string sql = String.Format("UPDATE DataItem 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 DataItem 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); } item.OrderNumber = newOrderingnumber; item.Save(); }