Exemple #1
0
        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();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// zet alle waardes van een DataItemLanguage regel in de DataItem
        /// Hierdoor kunnen dezelfde velden worden gebruikt in de dataModule
        /// </summary>
        /// <param name="languageCode"></param>
        public void Translate(string languageCode)
        {
            if (DataCollection.HasStaticLanguage || languageCode == Site.DefaultLanguage)
            {
                return;
            }
            string where = "FK_DataItem='" + this.ID + "' AND LanguageCode ='" + languageCode + "'";
            DataItemLanguage itemLanguage = DataItemLanguage.GetFirst <DataItemLanguage>(where);

            if (itemLanguage == null)
            {
                return;
            }
            this.Title = itemLanguage.Title;
            foreach (DataField fld in this.DataCollection.DataItemFields)
            {
                if (fld.IsMultiLanguageField)
                {
                    if (fld.FieldType != FieldTypeEnum.ImageList &&
                        fld.FieldType != FieldTypeEnum.FileList &&
                        fld.FieldType != FieldTypeEnum.DropDown)
                    {
                        System.Reflection.PropertyInfo propItem = this.GetType().GetProperty(fld.MappingColumn);

                        System.Reflection.PropertyInfo propLanguage = itemLanguage.GetType().GetProperty(fld.MappingColumn);

                        Object valueLanguage = propLanguage.GetValue(itemLanguage, null);
                        propItem.SetValue(this, valueLanguage, null);
                    }
                    else if (fld.FieldType == FieldTypeEnum.ImageList)
                    {
                        _imageList1 = BaseCollection <DataFile> .Get("Type = '" + DataFile.TYPE_EXTRA_IMAGE + "' AND FK_Item='" + this.ID + "' AND Language='" + languageCode + "'", "Name");

                        _imageList1.IsLoaded = true;
                    }
                    else if (fld.FieldType == FieldTypeEnum.FileList)
                    {
                        _imageList1 = BaseCollection <DataFile> .Get("Type = '" + DataFile.TYPE_EXTRA_FILE + "' AND FK_Item='" + this.ID + "' AND Language='" + languageCode + "'", "Name");

                        _imageList1.IsLoaded = true;
                    }
                    else if (fld.FieldType == FieldTypeEnum.DropDown)
                    {
                        //todo
                    }
                }
            }
        }