コード例 #1
0
ファイル: MappingMetaClass.cs プロジェクト: alex765022/IBN
        public virtual FillResult FillData(FillDataMode mode, DataTable rawData, Rule rule, int modifierId, DateTime modified)
        {
            if (rawData == null)
            {
                throw new ArgumentNullException("rawData");
            }

            FillResult retVal = new FillResult(rawData.Rows.Count);

            Validate(rule, rawData);

            int RowIndex = 0;

            foreach (DataRow Row in rawData.Rows)
            {
                try
                {
                    int ObjectId = CreateSystemRow(mode, FillItemList(SystemColumnInfos, Row, RowIndex, rule, retVal.warningList));

                    if (UserColumnInfos.Length != 0)
                    {
                        MetaObject Object = MetaObject.Load(ObjectId, _innerMetaClassName, modifierId, modified);
                        if (Object == null)
                        {
                            Object = MetaObject.NewObject(ObjectId, _innerMetaClassName, modifierId, modified);
                        }
                        CreateUserRow(Object, rule, FillItemList(UserColumnInfos, Row, RowIndex, rule, retVal.warningList));

                        Object.AcceptChanges();
                    }
                    else if (ObjectId == -1)
                    {
                        throw new IdleOperationException();
                    }

                    retVal.SuccessfulRow();
                }
                catch (AlreadyExistException)
                {
                }
                catch (MdpImportException ex)
                {
                    retVal.ErrorRow();
                    ex.setRowInfo(Row, RowIndex);
                    retVal.ErrorException(ex);
                }
                catch (Exception ex)
                {
                    retVal.ErrorRow();
                    retVal.ErrorException(ex);
                }
                RowIndex++;
            }
            return(retVal);
        }
コード例 #2
0
    /// <summary>
    /// Updates meta field
    /// </summary>
    /// <param name="item">The data item.</param>
    /// <returns></returns>
    private void UpdateMetaField(CatalogEntryDto.CatalogEntryRow item)
    {
        int             MetaClassId = item.MetaClassId;
        int             ObjectId    = item.CatalogEntryId;
        MetaDataContext MDContext   = CatalogContext.MetaDataContext;

        if (ObjectId != 0)
        {
            // set username here, because calling FrameworkContext.Current.Profile causes MeteDataContext.Current to change (it's bug in ProfileContext class).
            string userName = FrameworkContext.Current.Profile.UserName;

            MDContext.UseCurrentUICulture = false;

            MDContext.Language = LanguageCode;

            MetaObject metaObj     = null;
            bool       saveChanges = true;

            metaObj = MetaObject.Load(MDContext, ObjectId, MetaClassId);

            if (metaObj == null)
            {
                metaObj = MetaObject.NewObject(MDContext, ObjectId, MetaClassId, userName);
                //DataBind(); return;
            }
            else
            {
                metaObj.ModifierId = userName;
                metaObj.Modified   = DateTime.UtcNow;
            }

            foreach (Control ctrl in MetaControls.Controls)
            {
                // Only update controls that belong to current language
                if (String.Compare(((IMetaControl)ctrl).LanguageCode, LanguageCode, true) == 0)
                {
                    ((IMetaControl)ctrl).MetaObject = metaObj;
                    //((IMetaControl)ctrl).MetaField = metaObj;
                    ((IMetaControl)ctrl).Update();
                }
            }

            // Only save changes when new object has been created
            if (saveChanges)
            {
                metaObj.AcceptChanges(MDContext);
            }

            MDContext.UseCurrentUICulture = true;
        }
    }
コード例 #3
0
        /// <summary>
        /// Clones the catalog node.
        /// </summary>
        /// <param name="parentCatalogId">The parent catalog id.</param>
        /// <param name="parentCatalogNodeId">The parent catalog node id.</param>
        /// <param name="catalogNodeId">The catalog node id.</param>
        private void CloneCatalogNode(int parentCatalogId, int parentCatalogNodeId, int catalogNodeId)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                CatalogNodeDto catalogNodeDto = CatalogContext.Current.GetCatalogNodeDto(catalogNodeId);
                if (catalogNodeDto.CatalogNode.Count > 0)
                {
                    CatalogNodeDto newCatalogNodeDto = new CatalogNodeDto();
                    newCatalogNodeDto.CatalogNode.ImportRow(catalogNodeDto.CatalogNode[0]);
                    newCatalogNodeDto.CatalogNode[0].SetAdded();
                    newCatalogNodeDto.CatalogNode[0].ParentNodeId = parentCatalogNodeId;
                    newCatalogNodeDto.CatalogNode[0].Code         = Guid.NewGuid().ToString();

                    if (catalogNodeDto.CatalogItemSeo.Count > 0)
                    {
                        foreach (CatalogNodeDto.CatalogItemSeoRow row in catalogNodeDto.CatalogItemSeo.Rows)
                        {
                            newCatalogNodeDto.CatalogItemSeo.ImportRow(row);
                            newCatalogNodeDto.CatalogItemSeo[newCatalogNodeDto.CatalogItemSeo.Count - 1].SetAdded();
                            newCatalogNodeDto.CatalogItemSeo[newCatalogNodeDto.CatalogItemSeo.Count - 1].Uri = Guid.NewGuid().ToString() + ".aspx";
                        }
                    }

                    if (newCatalogNodeDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogNode(newCatalogNodeDto);
                    }

                    if (newCatalogNodeDto.CatalogNode.Count > 0)
                    {
                        CatalogNodeDto.CatalogNodeRow node = newCatalogNodeDto.CatalogNode[0];
                        int newCatalogNodeId = node.CatalogNodeId;
                        int metaClassId      = node.MetaClassId;

                        // load list of MetaFields for MetaClass
                        MetaClass           metaClass  = MetaClass.Load(CatalogContext.MetaDataContext, metaClassId);
                        MetaFieldCollection metaFields = metaClass.MetaFields;

                        // cycle through each language and get meta objects
                        CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                        string[] languages = GetCatalogLanguages(parentCatalogId);
                        if (languages != null)
                        {
                            foreach (string language in languages)
                            {
                                CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                                CatalogContext.MetaDataContext.Language            = language;

                                MetaObject metaObject = MetaObject.Load(CatalogContext.MetaDataContext, catalogNodeDto.CatalogNode[0].CatalogNodeId, metaClassId);

                                MetaObject newMetaObject = MetaObject.NewObject(CatalogContext.MetaDataContext, newCatalogNodeId, metaClassId, FrameworkContext.Current.Profile.UserName);

                                foreach (MetaField metaField in metaFields)
                                {
                                    // skip system MetaFields
                                    if (!metaField.IsUser)
                                    {
                                        continue;
                                    }

                                    switch (metaField.DataType)
                                    {
                                    case MetaDataType.File:
                                    case MetaDataType.Image:
                                    case MetaDataType.ImageFile:
                                        MetaFile metaFile = (MetaFile)metaObject[metaField];
                                        if (metaFile != null)
                                        {
                                            newMetaObject[metaField] = new MetaFile(metaFile.Name, metaFile.ContentType, metaFile.Buffer);
                                        }
                                        break;

                                    default:
                                        if (metaObject[metaField] != null)
                                        {
                                            newMetaObject[metaField] = metaObject[metaField];
                                        }
                                        break;
                                    }
                                }
                                newMetaObject.AcceptChanges(CatalogContext.MetaDataContext);
                            }
                        }
                        CatalogContext.MetaDataContext.UseCurrentUICulture = false;

                        CatalogNodeDto childCatalogNodesDto = CatalogContext.Current.GetCatalogNodesDto(parentCatalogId, catalogNodeId);
                        if (childCatalogNodesDto.CatalogNode.Count > 0)
                        {
                            for (int i = 0; i < childCatalogNodesDto.CatalogNode.Count; i++)
                            {
                                CloneCatalogNode(parentCatalogId, newCatalogNodeDto.CatalogNode[0].CatalogNodeId, childCatalogNodesDto.CatalogNode[i].CatalogNodeId);
                            }
                        }

                        CatalogEntryDto catalogEntriesDto = CatalogContext.Current.GetCatalogEntriesDto(parentCatalogId, catalogNodeDto.CatalogNode[0].CatalogNodeId);
                        if (catalogEntriesDto.CatalogEntry.Count > 0)
                        {
                            for (int i = 0; i < catalogEntriesDto.CatalogEntry.Count; i++)
                            {
                                CloneNodeEntry(parentCatalogId, catalogNodeId, catalogEntriesDto.CatalogEntry[i].CatalogEntryId, parentCatalogId, newCatalogNodeDto.CatalogNode[0].CatalogNodeId);
                            }
                        }
                    }
                }

                scope.Complete();
            }
        }
コード例 #4
0
        /// <summary>
        /// Clones the node entry.
        /// </summary>
        /// <param name="catalogId">The catalog id.</param>
        /// <param name="catalogNodeId">The catalog node id.</param>
        /// <param name="catalogEntryId">The catalog entry id.</param>
        /// <param name="targetCatalogId">The target catalog id.</param>
        /// <param name="targetCatalogNodeId">The target catalog node id.</param>
        private void CloneNodeEntry(int catalogId, int catalogNodeId, int catalogEntryId, int targetCatalogId, int targetCatalogNodeId)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(catalogEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    if (catalogId <= 0)
                    {
                        catalogId = catalogEntryDto.CatalogEntry[0].CatalogId;
                    }

                    if (targetCatalogId <= 0)
                    {
                        targetCatalogId = catalogId;
                    }

                    CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(catalogId, catalogNodeId, catalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogEntry));

                    CatalogAssociationDto catalogAssociationDto = CatalogContext.Current.GetCatalogAssociationDtoByEntryId(catalogEntryId);

                    CatalogEntryDto newCatalogEntryDto = new CatalogEntryDto();
                    newCatalogEntryDto.CatalogEntry.ImportRow(catalogEntryDto.CatalogEntry[0]);
                    newCatalogEntryDto.CatalogEntry[0].SetAdded();
                    newCatalogEntryDto.CatalogEntry[0].Code = Guid.NewGuid().ToString();

                    if (catalogEntryDto.CatalogItemSeo.Count > 0)
                    {
                        foreach (CatalogEntryDto.CatalogItemSeoRow row in catalogEntryDto.CatalogItemSeo.Rows)
                        {
                            newCatalogEntryDto.CatalogItemSeo.ImportRow(row);
                            newCatalogEntryDto.CatalogItemSeo[newCatalogEntryDto.CatalogItemSeo.Count - 1].SetAdded();
                            newCatalogEntryDto.CatalogItemSeo[newCatalogEntryDto.CatalogItemSeo.Count - 1].Uri = Guid.NewGuid().ToString() + ".aspx";
                        }
                    }

                    if (catalogEntryDto.Variation.Count > 0)
                    {
                        foreach (CatalogEntryDto.VariationRow row in catalogEntryDto.Variation.Rows)
                        {
                            newCatalogEntryDto.Variation.ImportRow(row);
                            newCatalogEntryDto.Variation[newCatalogEntryDto.Variation.Count - 1].SetAdded();
                        }
                    }

                    if (catalogEntryDto.SalePrice.Count > 0)
                    {
                        foreach (CatalogEntryDto.SalePriceRow row in catalogEntryDto.SalePrice.Rows)
                        {
                            CatalogEntryDto.SalePriceRow newRow = newCatalogEntryDto.SalePrice.NewSalePriceRow();
                            newRow.ItemArray = row.ItemArray;
                            newRow.ItemCode  = newCatalogEntryDto.CatalogEntry[0].Code;
                            newCatalogEntryDto.SalePrice.Rows.Add(newRow);
                            //newCatalogEntryDto.SalePrice.ImportRow(row);
                            //newCatalogEntryDto.SalePrice[newCatalogEntryDto.SalePrice.Count - 1].ItemCode = newCatalogEntryDto.CatalogEntry[0].Code;
                            //newCatalogEntryDto.SalePrice[newCatalogEntryDto.SalePrice.Count - 1].SetAdded();
                        }
                    }

                    if (catalogEntryDto.Inventory.Count > 0)
                    {
                        foreach (CatalogEntryDto.InventoryRow row in catalogEntryDto.Inventory.Rows)
                        {
                            newCatalogEntryDto.Inventory.ImportRow(row);
                            newCatalogEntryDto.Inventory[newCatalogEntryDto.Inventory.Count - 1].SetAdded();
                            newCatalogEntryDto.Inventory[newCatalogEntryDto.Inventory.Count - 1].SkuId = newCatalogEntryDto.CatalogEntry[0].Code;
                        }
                    }

                    if (newCatalogEntryDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogEntry(newCatalogEntryDto);
                    }

                    if (newCatalogEntryDto.CatalogEntry.Count > 0)
                    {
                        CatalogEntryDto.CatalogEntryRow entry = newCatalogEntryDto.CatalogEntry[0];
                        int newCatalogEntryId = entry.CatalogEntryId;
                        int metaClassId       = entry.MetaClassId;

                        // load list of MetaFields for MetaClass
                        MetaClass           metaClass  = MetaClass.Load(CatalogContext.MetaDataContext, metaClassId);
                        MetaFieldCollection metaFields = metaClass.MetaFields;

                        // cycle through each language and get meta objects
                        CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                        string[] languages = GetCatalogLanguages(catalogId);
                        if (languages != null)
                        {
                            foreach (string language in languages)
                            {
                                CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                                CatalogContext.MetaDataContext.Language            = language;

                                MetaObject metaObject = MetaObject.Load(CatalogContext.MetaDataContext, catalogEntryDto.CatalogEntry[0].CatalogEntryId, metaClassId);

                                MetaObject newMetaObject = MetaObject.NewObject(CatalogContext.MetaDataContext, newCatalogEntryId, metaClassId, FrameworkContext.Current.Profile.UserName);

                                foreach (MetaField metaField in metaFields)
                                {
                                    // skip system MetaFields
                                    if (!metaField.IsUser)
                                    {
                                        continue;
                                    }

                                    switch (metaField.DataType)
                                    {
                                    case MetaDataType.File:
                                    case MetaDataType.Image:
                                    case MetaDataType.ImageFile:
                                        MetaFile metaFile = (MetaFile)metaObject[metaField];
                                        if (metaFile != null)
                                        {
                                            newMetaObject[metaField] = new MetaFile(metaFile.Name, metaFile.ContentType, metaFile.Buffer);
                                        }
                                        break;

                                    default:
                                        if (metaObject[metaField] != null)
                                        {
                                            newMetaObject[metaField] = metaObject[metaField];
                                        }
                                        break;
                                    }
                                }
                                newMetaObject.AcceptChanges(CatalogContext.MetaDataContext);
                            }
                        }
                        CatalogContext.MetaDataContext.UseCurrentUICulture = false;

                        CatalogRelationDto newCatalogRelationDto = new CatalogRelationDto();

                        foreach (CatalogRelationDto.CatalogEntryRelationRow row in catalogRelationDto.CatalogEntryRelation.Rows)
                        {
                            if (row.ParentEntryId == catalogEntryId)
                            {
                                newCatalogRelationDto.CatalogEntryRelation.ImportRow(row);
                                newCatalogRelationDto.CatalogEntryRelation[newCatalogRelationDto.CatalogEntryRelation.Count - 1].SetAdded();
                                newCatalogRelationDto.CatalogEntryRelation[newCatalogRelationDto.CatalogEntryRelation.Count - 1].ParentEntryId = newCatalogEntryId;
                            }
                        }

                        if (targetCatalogNodeId > 0)
                        {
                            foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows)
                            {
                                if (row.CatalogEntryId == catalogEntryId)
                                {
                                    newCatalogRelationDto.NodeEntryRelation.ImportRow(row);
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].SetAdded();
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogId      = targetCatalogId;
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogNodeId  = targetCatalogNodeId;
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogEntryId = newCatalogEntryId;
                                }
                            }
                        }

                        if (newCatalogRelationDto.HasChanges())
                        {
                            CatalogContext.Current.SaveCatalogRelationDto(newCatalogRelationDto);
                        }

                        CatalogAssociationDto newCatalogAssociationDto = new CatalogAssociationDto();

                        foreach (CatalogAssociationDto.CatalogAssociationRow row in catalogAssociationDto.CatalogAssociation.Rows)
                        {
                            newCatalogAssociationDto.CatalogAssociation.ImportRow(row);
                            newCatalogAssociationDto.CatalogAssociation[newCatalogAssociationDto.CatalogAssociation.Count - 1].SetAdded();
                            newCatalogAssociationDto.CatalogAssociation[newCatalogAssociationDto.CatalogAssociation.Count - 1].CatalogEntryId = newCatalogEntryId;
                        }

                        foreach (CatalogAssociationDto.CatalogEntryAssociationRow row in catalogAssociationDto.CatalogEntryAssociation.Rows)
                        {
                            newCatalogAssociationDto.CatalogEntryAssociation.ImportRow(row);
                            newCatalogAssociationDto.CatalogEntryAssociation[newCatalogAssociationDto.CatalogEntryAssociation.Count - 1].SetAdded();
                            //newCatalogAssociationDto.CatalogEntryAssociation[newCatalogAssociationDto.CatalogEntryAssociation.Count - 1].CatalogEntryId = newCatalogEntryId;
                        }

                        if (newCatalogAssociationDto.HasChanges())
                        {
                            CatalogContext.Current.SaveCatalogAssociation(newCatalogAssociationDto);
                        }
                    }
                }

                scope.Complete();
            }
        }
コード例 #5
0
    /// <summary>
    /// Binds the batch control.
    /// </summary>
    private void BindData()
    {
        CatalogEntryDto.VariationRow[] variationRows = null;

        CatalogEntryDto.CatalogEntryRow item = (CatalogEntryDto.CatalogEntryRow)DataItem;

        if (IsMetaField)
        {
            int             MetaClassId = item.MetaClassId;
            int             ObjectId    = item.CatalogEntryId;
            MetaDataContext MDContext   = CatalogContext.MetaDataContext;

            MetaControls.EnableViewState = false;
            if (MetaControls.Controls.Count > 0)
            {
                return;
            }

            MetaControls.Controls.Clear();

            MetaClass mc = MetaClass.Load(MDContext, MetaClassId);

            if (mc == null)
            {
                return;
            }

            MDContext.UseCurrentUICulture = false;
            MDContext.Language            = LanguageCode;

            MetaObject metaObj = null;
            if (ObjectId > 0)
            {
                metaObj = MetaObject.Load(MDContext, ObjectId, mc);
                if (metaObj == null)
                {
                    metaObj = MetaObject.NewObject(MDContext, ObjectId, MetaClassId, FrameworkContext.Current.Profile.UserName);
                    metaObj.AcceptChanges(MDContext);
                }
            }
            MDContext.UseCurrentUICulture = true;


            MetaField mf = MetaField.Load(MDContext, FieldName);
            if (mf.IsUser)
            {
                string  controlName = ResolveMetaControl(mc, mf);
                Control ctrl        = MetaControls.FindControl(mf.Name);

                if (ctrl == null)
                {
                    ctrl = Page.LoadControl(controlName);
                    MetaControls.Controls.Add(ctrl);
                }


                CoreBaseUserControl coreCtrl = ctrl as CoreBaseUserControl;
                if (coreCtrl != null)
                {
                    coreCtrl.MDContext = MDContext;
                }

                //ctrl.ID = String.Format("{0}-{1}", mf.Name, index.ToString());

                ((IMetaControl)ctrl).MetaField = mf;
                if (metaObj != null && metaObj[mf.Name] != null)
                {
                    ((IMetaControl)ctrl).MetaObject = metaObj;
                }

                ((IMetaControl)ctrl).LanguageCode    = LanguageCode;
                ((IMetaControl)ctrl).ValidationGroup = String.Empty;

                ctrl.DataBind();
            }
        }
        else
        {
            switch (FieldName)
            {
            case "Name":
            case "Code":
                tbItem.Visible = true;
                tbItem.Text    = (string)item[FieldName];
                break;

            case "StartDate":
            case "EndDate":
                cdpItem.Visible = true;
                cdpItem.Value   = (DateTime)item[FieldName];
                break;

            case "TemplateName":
                ddlItem.Visible = true;
                TemplateDto templates = DictionaryManager.GetTemplateDto();
                if (templates.main_Templates.Count > 0)
                {
                    DataView view = templates.main_Templates.DefaultView;
                    view.RowFilter         = "TemplateType = 'entry'";
                    ddlItem.DataTextField  = "FriendlyName";
                    ddlItem.DataValueField = "Name";
                    ddlItem.DataSource     = view;
                    ddlItem.DataBind();
                }
                ManagementHelper.SelectListItem2(ddlItem, item.TemplateName);
                break;

            case "SortOrder":
                tbItem.Visible = true;
                CatalogRelationDto relationDto = CatalogContext.Current.GetCatalogRelationDto(item.CatalogId, CatalogNodeId, item.CatalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));
                if (relationDto.NodeEntryRelation.Count > 0)
                {
                    tbItem.Text = relationDto.NodeEntryRelation[0].SortOrder.ToString();
                }
                break;

            case "IsActive":
                becItem.Visible    = true;
                becItem.IsSelected = item.IsActive;
                break;

            case "ListPrice":
                tbItem.Visible = true;
                variationRows  = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    tbItem.Text = variationRows[0].ListPrice.ToString("#0.00");
                }
                break;

            case "TaxCategoryId":
                ddlItem.Visible = true;
                ddlItem.Items.Add(new ListItem(Resources.CatalogStrings.Entry_Select_Tax_Category, "0"));
                CatalogTaxDto taxes = CatalogTaxManager.GetTaxCategories();
                if (taxes.TaxCategory != null)
                {
                    foreach (CatalogTaxDto.TaxCategoryRow row in taxes.TaxCategory.Rows)
                    {
                        ddlItem.Items.Add(new ListItem(row.Name, row.TaxCategoryId.ToString()));
                    }
                }
                ddlItem.DataBind();
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    ManagementHelper.SelectListItem2(ddlItem, variationRows[0].TaxCategoryId);
                }
                break;

            case "TrackInventory":
                becItem.Visible = true;
                variationRows   = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    becItem.IsSelected = variationRows[0].TrackInventory;
                }
                break;

            case "MerchantId":
                ddlItem.Visible = true;
                ddlItem.Items.Insert(0, new ListItem(Resources.CatalogStrings.Entry_Select_Merchant, ""));
                CatalogEntryDto merchants = CatalogContext.Current.GetMerchantsDto();
                if (merchants.Merchant != null)
                {
                    foreach (CatalogEntryDto.MerchantRow row in merchants.Merchant.Rows)
                    {
                        ddlItem.Items.Add(new ListItem(row.Name, row.MerchantId.ToString()));
                    }
                }
                ddlItem.DataBind();
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0 && !variationRows[0].IsMerchantIdNull())
                {
                    ManagementHelper.SelectListItem2(ddlItem, variationRows[0].MerchantId);
                }
                break;

            case "WarehouseId":
                ddlItem.Visible = true;
                ddlItem.Items.Insert(0, new ListItem(Resources.CatalogStrings.Entry_Select_Warehouse, "0"));
                WarehouseDto warehouses = WarehouseManager.GetWarehouseDto();
                if (warehouses.Warehouse != null)
                {
                    foreach (WarehouseDto.WarehouseRow row in warehouses.Warehouse.Rows)
                    {
                        ddlItem.Items.Add(new ListItem(row.Name, row.WarehouseId.ToString()));
                    }
                }
                ddlItem.DataBind();
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    ManagementHelper.SelectListItem2(ddlItem, variationRows[0].WarehouseId);
                }
                break;

            case "PackageId":
                ddlItem.Visible = true;
                ddlItem.Items.Insert(0, new ListItem(Resources.CatalogStrings.Entry_Select_Package, "0"));
                ShippingMethodDto shippingDto = ShippingManager.GetShippingPackages();
                if (shippingDto.Package != null)
                {
                    foreach (ShippingMethodDto.PackageRow row in shippingDto.Package.Rows)
                    {
                        ddlItem.Items.Add(new ListItem(row.Name, row.PackageId.ToString()));
                    }
                }
                ddlItem.DataBind();
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    ManagementHelper.SelectListItem2(ddlItem, variationRows[0].PackageId);
                }
                break;

            case "Weight":
            case "MinQuantity":
            case "MaxQuantity":
                tbItem.Visible = true;
                variationRows  = item.GetVariationRows();
                if (variationRows.Length > 0 && variationRows[0][FieldName] != DBNull.Value)
                {
                    tbItem.Text = variationRows[0][FieldName].ToString();
                }
                break;

            case "InStockQuantity":
            case "ReservedQuantity":
            case "ReorderMinQuantity":
            case "PreorderQuantity":
            case "BackorderQuantity":
                tbItem.Visible = true;
                if (item.InventoryRow != null && item.InventoryRow[FieldName] != DBNull.Value)
                {
                    tbItem.Text = item.InventoryRow[FieldName].ToString();
                }
                break;

            case "AllowBackorder":
            case "AllowPreorder":
                becItem.Visible = true;
                if (item.InventoryRow != null)
                {
                    becItem.IsSelected = (bool)item.InventoryRow[FieldName];
                }
                break;

            case "InventoryStatus":
                ddlItem.Visible = true;
                ddlItem.Items.Insert(0, new ListItem(Resources.SharedStrings.Disabled, "0"));
                ddlItem.Items.Insert(0, new ListItem(Resources.SharedStrings.Enabled, "1"));
                ddlItem.Items.Insert(0, new ListItem(Resources.SharedStrings.Ignored, "2"));
                ddlItem.DataBind();
                if (item.InventoryRow != null)
                {
                    ManagementHelper.SelectListItem2(ddlItem, item.InventoryRow.InventoryStatus);
                }
                break;

            case "PreorderAvailabilityDate":
            case "BackorderAvailabilityDate":
                cdpItem.Visible = true;
                if (item.InventoryRow != null)
                {
                    cdpItem.Value = (DateTime)item.InventoryRow[FieldName];
                }
                break;
            }
        }
    }
コード例 #6
0
        protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item)
        {
            int    i = 0;
            object objSysRowAction = Item[i++];
            //CatalogNode
            object objCode         = Item[i++];
            object objParentCode   = Item[i++];
            object objName         = Item[i++];
            object objStartDate    = Item[i++];
            object objEndDate      = Item[i++];
            object objTemplateName = Item[i++];
            object objIsActive     = Item[i++];
            object objSortOrder    = Item[i++];
            //SEO
            object objSeoTitle       = Item[i++];
            object objSeoUrl         = Item[i++];
            object objSeoDescription = Item[i++];
            object objSeoKeywords    = Item[i++];

            CatalogNodeDto.CatalogNodeRow nodeRow = null;

            try
            {
                RowAction sysRowAction = RowAction.Default;

                if (objSysRowAction != null)
                {
                    sysRowAction = GetRowActionEnum((string)objSysRowAction);
                }

                string Code;
                if (!String.IsNullOrEmpty((string)objCode))
                {
                    Code = (string)objCode;
                }
                else
                {
                    throw new AbsentValue("Code");
                }

                int parentNodeId = 0;
                if (objParentCode != null)
                {
                    if (!objParentCode.Equals(String.Empty))
                    {
                        CatalogNodeDto parentNodeDto = CatalogNodeManager.GetCatalogNodeDto((string)objParentCode, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeInfo));
                        if (parentNodeDto.CatalogNode.Count > 0)
                        {
                            parentNodeId = parentNodeDto.CatalogNode[0].CatalogNodeId;
                        }
                    }
                }

                bool           bIsNew         = false;
                CatalogNodeDto catalogNodeDto = CatalogNodeManager.GetCatalogNodeDto(Code, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeFull));
                if (catalogNodeDto.CatalogNode.Count > 0)
                {
                    if (sysRowAction == RowAction.Insert)
                    {
                        throw new MDPImportException(String.Format("The Catalog Node with Code '{0}' already exists.", Code));
                    }

                    nodeRow = catalogNodeDto.CatalogNode[0];

                    if (sysRowAction == RowAction.Delete)
                    {
                        CatalogContext.Current.DeleteCatalogNode(nodeRow.CatalogNodeId, nodeRow.CatalogId);
                        return(0);
                    }

                    if (objParentCode != null && parentNodeId > -1)
                    {
                        nodeRow.ParentNodeId = parentNodeId;
                    }
                }
                else
                {
                    if (sysRowAction == RowAction.Update)
                    {
                        throw new MDPImportException(String.Format("The Catalog Node with code '{0}' does not exists.", Code));
                    }

                    if (sysRowAction == RowAction.Delete)
                    {
                        throw new MDPImportException(String.Format("The Catalog Node with code '{0}' does not exists.", Code));
                    }

                    nodeRow = catalogNodeDto.CatalogNode.NewCatalogNodeRow();
                    nodeRow.ApplicationId = CatalogConfiguration.Instance.ApplicationId;
                    nodeRow.CatalogId     = _CatalogId;
                    nodeRow.Code          = Code;
                    nodeRow.ParentNodeId  = parentNodeId;
                    nodeRow.Name          = String.Empty;
                    nodeRow.StartDate     = DateTime.UtcNow;
                    nodeRow.EndDate       = DateTime.UtcNow.AddYears(3);
                    nodeRow.TemplateName  = String.Empty;
                    nodeRow.IsActive      = false;
                    nodeRow.SortOrder     = 0;
                    bIsNew = true;
                }

                if (objName != null)
                {
                    nodeRow.Name = (string)objName;
                }

                if (objStartDate != null)
                {
                    nodeRow.StartDate = ((DateTime)objStartDate).ToUniversalTime();
                }

                if (objEndDate != null)
                {
                    nodeRow.EndDate = ((DateTime)objEndDate).ToUniversalTime();
                }

                if (objTemplateName != null)
                {
                    nodeRow.TemplateName = (string)objTemplateName;
                }

                if (objIsActive != null)
                {
                    nodeRow.IsActive = (bool)objIsActive;
                }

                if (objSortOrder != null)
                {
                    nodeRow.SortOrder = (int)objSortOrder;
                }

                int oldMetaClassId = 0;
                if (!_isSystemClass && _metaClassId > 0)
                {
                    if (!bIsNew)
                    {
                        oldMetaClassId = nodeRow.MetaClassId;
                    }

                    nodeRow.MetaClassId = _metaClassId;
                }
                else if (bIsNew)
                {
                    throw new MDPImportException("The new category cannot be created without metaclass definition.");
                }

                if (bIsNew)
                {
                    catalogNodeDto.CatalogNode.AddCatalogNodeRow(nodeRow);
                }

                //SEO
                CatalogNodeDto.CatalogItemSeoRow catalogItemSeoRow = null;
                bool bSeoIsNew = false;
                if (!String.IsNullOrEmpty(this.Context.Language))
                {
                    if (catalogNodeDto.CatalogItemSeo.Count > 0)
                    {
                        DataRow[] drs = catalogNodeDto.CatalogItemSeo.Select(String.Format("LanguageCode LIKE '{0}' AND CatalogNodeId = {1}", this.Context.Language, nodeRow.CatalogNodeId));
                        if (drs.Length > 0)
                        {
                            catalogItemSeoRow = (CatalogNodeDto.CatalogItemSeoRow)drs[0];
                        }
                    }

                    if (catalogItemSeoRow == null)
                    {
                        catalogItemSeoRow = catalogNodeDto.CatalogItemSeo.NewCatalogItemSeoRow();
                        catalogItemSeoRow.ApplicationId = CatalogConfiguration.Instance.ApplicationId;
                        catalogItemSeoRow.LanguageCode  = this.Context.Language.ToLower();
                        catalogItemSeoRow.CatalogNodeId = nodeRow.CatalogNodeId;
                        catalogItemSeoRow.Description   = String.Empty;
                        catalogItemSeoRow.Keywords      = String.Empty;
                        bSeoIsNew = true;
                    }

                    if (objSeoTitle != null)
                    {
                        catalogItemSeoRow.Title = (string)objSeoTitle;
                    }

                    if (objSeoUrl != null)
                    {
                        catalogItemSeoRow.Uri = (string)objSeoUrl;
                    }
                    else if (bSeoIsNew)
                    {
                        // Auto generate the URL if empty
                        string name = catalogNodeDto.CatalogNode[0].Name;
                        string url  = String.Format("{0}.aspx", CommerceHelper.CleanUrlField(name));

                        int index = 1;
                        while (CatalogContext.Current.GetCatalogEntryByUriDto(url, this.Context.Language).CatalogEntry.Count != 0 || CatalogContext.Current.GetCatalogNodeDto(url, this.Context.Language).CatalogNode.Count != 0)
                        {
                            url = String.Format("{0}-{1}.aspx", CommerceHelper.CleanUrlField(name), index.ToString());
                            index++;
                        }

                        catalogItemSeoRow.Uri = url;
                    }


                    if (objSeoDescription != null)
                    {
                        catalogItemSeoRow.Description = (string)objSeoDescription;
                    }

                    if (objSeoKeywords != null)
                    {
                        catalogItemSeoRow.Keywords = (string)objSeoKeywords;
                    }

                    if (bSeoIsNew)
                    {
                        catalogNodeDto.CatalogItemSeo.AddCatalogItemSeoRow(catalogItemSeoRow);
                    }
                }

                using (TransactionScope tx = new TransactionScope())
                {
                    // Save modifications
                    if (catalogNodeDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogNode(catalogNodeDto);
                    }

                    if (!bIsNew && !_isSystemClass && oldMetaClassId != nodeRow.MetaClassId)
                    {
                        MetaObject.Delete(this.Context, nodeRow.CatalogNodeId, oldMetaClassId);
                        MetaObject obj = MetaObject.NewObject(this.Context, nodeRow.CatalogNodeId, nodeRow.MetaClassId);
                        obj.AcceptChanges(this.Context);
                    }

                    tx.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item);
            }

            return(nodeRow.CatalogNodeId);
        }
コード例 #7
0
        protected override int CreateSystemRow(FillDataMode mode, int RowIndex, params object[] item)
        {
            int    i = 0;
            object objSysRowAction = item[i++];
            //Entry
            object objCode          = item[i++];
            object objName          = item[i++];
            object objClassTypeId   = item[i++];
            object objStartDate     = item[i++];
            object objEndDate       = item[i++];
            object objTemplateName  = item[i++];
            object objIsActive      = item[i++];
            object objCategoryCodes = item[i++];
            object objSortOrder     = item[i++];
            //SEO
            object objSeoTitle       = item[i++];
            object objSeoUrl         = item[i++];
            object objSeoDescription = item[i++];
            object objSeoKeywords    = item[i++];

            CatalogEntryDto.CatalogEntryRow entryRow = null;

            try
            {
                RowAction sysRowAction = RowAction.Default;

                if (objSysRowAction != null)
                {
                    sysRowAction = GetRowActionEnum((string)objSysRowAction);
                }

                string code;
                if (objCode != null)
                {
                    code = (string)objCode;
                }
                else
                {
                    throw new AbsentValue("Code");
                }

                bool            bIsNew          = false;
                CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(code, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    if (sysRowAction == RowAction.Insert)
                    {
                        throw new MDPImportException(String.Format("The Entry with code '{0}' already exists.", code));
                    }

                    entryRow = catalogEntryDto.CatalogEntry[0];

                    if (sysRowAction == RowAction.Delete)
                    {
                        CatalogContext.Current.DeleteCatalogEntry(entryRow.CatalogEntryId, true);
                        return(0);
                    }
                }
                else
                {
                    if (sysRowAction == RowAction.Update)
                    {
                        throw new MDPImportException(String.Format("The Entry with code '{0}' does not exists.", code));
                    }

                    if (sysRowAction == RowAction.Delete)
                    {
                        throw new MDPImportException(String.Format("The Entry with code '{0}' does not exists.", code));
                    }

                    entryRow = catalogEntryDto.CatalogEntry.NewCatalogEntryRow();
                    entryRow.ApplicationId = CatalogConfiguration.Instance.ApplicationId;
                    entryRow.CatalogId     = _CatalogId;
                    entryRow.Code          = code;
                    bIsNew = true;
                }

                //Entry
                if (objName != null)
                {
                    string Name = (string)objName;
                    entryRow.Name = Name;
                }
                else if (bIsNew)
                {
                    throw new AbsentValue("Name");
                }

                if (objClassTypeId != null)
                {
                    string classTypeId = (string)objClassTypeId;
                    entryRow.ClassTypeId = classTypeId;
                }
                else if (bIsNew)
                {
                    entryRow.ClassTypeId = EntryType.Product;
                }

                if (objStartDate != null)
                {
                    DateTime startDate = (DateTime)objStartDate;
                    entryRow.StartDate = startDate.ToUniversalTime();
                }
                else if (bIsNew)
                {
                    entryRow.StartDate = DateTime.UtcNow;
                }

                if (objEndDate != null)
                {
                    DateTime endDate = (DateTime)objEndDate;
                    entryRow.EndDate = endDate.ToUniversalTime();
                }
                else if (bIsNew)
                {
                    entryRow.EndDate = DateTime.UtcNow.AddYears(1);
                }

                if (objTemplateName != null)
                {
                    string templateName = (string)objTemplateName;
                    entryRow.TemplateName = templateName;
                }
                else if (bIsNew)
                {
                    entryRow.TemplateName = String.Empty;
                }

                if (objIsActive != null)
                {
                    bool IsActive = (bool)objIsActive;
                    entryRow.IsActive = IsActive;
                }
                else if (bIsNew)
                {
                    entryRow.IsActive = false;
                }

                int oldMetaClassId = 0;
                if (!_isSystemClass && _metaClassId > 0)
                {
                    if (!bIsNew)
                    {
                        oldMetaClassId = entryRow.MetaClassId;
                    }

                    entryRow.MetaClassId = _metaClassId;
                }
                else if (bIsNew)
                {
                    throw new MDPImportException("The new entry cannot be created without metaclass definition.");
                }

                if (bIsNew)
                {
                    catalogEntryDto.CatalogEntry.AddCatalogEntryRow(entryRow);
                }
                else
                {
                    entryRow.SerializedData = null;
                }

                //SEO
                CatalogEntryDto.CatalogItemSeoRow catalogItemSeoRow = null;
                bool bSeoIsNew = false;
                if (!String.IsNullOrEmpty(this.Context.Language))
                {
                    if (catalogEntryDto.CatalogItemSeo.Count > 0)
                    {
                        DataRow[] drs = catalogEntryDto.CatalogItemSeo.Select(String.Format("LanguageCode LIKE '{0}' AND CatalogEntryId = {1}", this.Context.Language, entryRow.CatalogEntryId));
                        if (drs.Length > 0)
                        {
                            catalogItemSeoRow = (CatalogEntryDto.CatalogItemSeoRow)drs[0];
                        }
                    }

                    if (catalogItemSeoRow == null)
                    {
                        catalogItemSeoRow = catalogEntryDto.CatalogItemSeo.NewCatalogItemSeoRow();
                        catalogItemSeoRow.ApplicationId  = CatalogConfiguration.Instance.ApplicationId;
                        catalogItemSeoRow.LanguageCode   = this.Context.Language.ToLower();
                        catalogItemSeoRow.CatalogEntryId = entryRow.CatalogEntryId;
                        bSeoIsNew = true;
                    }

                    if (objSeoTitle != null)
                    {
                        catalogItemSeoRow.Title = (string)objSeoTitle;
                    }

                    if (objSeoUrl != null)
                    {
                        catalogItemSeoRow.Uri = (string)objSeoUrl;
                    }
                    else if (bSeoIsNew)
                    {
                        // Auto generate the URL if empty
                        string name = catalogEntryDto.CatalogEntry.Count > 0 ? catalogEntryDto.CatalogEntry[0].Name : "";
                        string url  = String.Format("{0}.aspx", CommerceHelper.CleanUrlField(name));

                        int index = 1;
                        while (CatalogContext.Current.GetCatalogEntryByUriDto(url, this.Context.Language).CatalogEntry.Count != 0 || CatalogContext.Current.GetCatalogNodeDto(url, this.Context.Language).CatalogNode.Count != 0)
                        {
                            url = String.Format("{0}-{1}.aspx", CommerceHelper.CleanUrlField(name), index.ToString());
                            index++;
                        }

                        catalogItemSeoRow.Uri = url;
                    }

                    if (objSeoDescription != null)
                    {
                        catalogItemSeoRow.Description = (string)objSeoDescription;
                    }

                    if (objSeoKeywords != null)
                    {
                        catalogItemSeoRow.Keywords = (string)objSeoKeywords;
                    }

                    if (bSeoIsNew)
                    {
                        catalogEntryDto.CatalogItemSeo.AddCatalogItemSeoRow(catalogItemSeoRow);
                    }
                }

                using (TransactionScope tx = new TransactionScope())
                {
                    // Save modifications
                    if (catalogEntryDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);
                    }

                    int sortOrder = -1;
                    if (objSortOrder != null)
                    {
                        sortOrder = (int)objSortOrder;
                    }

                    if (objCategoryCodes != null)
                    {
                        //NodeEntryRelation

                        string[] categoryCodes = ((string)objCategoryCodes).Split(',');

                        Catalog.Dto.CatalogRelationDto catalogRelationDto = FrameworkContext.Current.CatalogSystem.GetCatalogRelationDto(this._CatalogId, 0, entryRow.CatalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));

                        Catalog.Dto.CatalogNodeDto catalogNodeDto = FrameworkContext.Current.CatalogSystem.GetCatalogNodesDto(this._CatalogId);
                        if (catalogNodeDto.CatalogNode.Count > 0)
                        {
                            //remove product from category
                            if (catalogRelationDto.NodeEntryRelation.Count > 0)
                            {
                                foreach (CatalogRelationDto.NodeEntryRelationRow nodeEntryRelationRow in catalogRelationDto.NodeEntryRelation)
                                {
                                    DataRow[] catalogNodeDataRows = catalogNodeDto.CatalogNode.Select(String.Format("CatalogNodeId = {0}", nodeEntryRelationRow.CatalogNodeId));
                                    if (catalogNodeDataRows.Length > 0)
                                    {
                                        Catalog.Dto.CatalogNodeDto.CatalogNodeRow catalogNode = (Catalog.Dto.CatalogNodeDto.CatalogNodeRow)catalogNodeDataRows[0];

                                        bool bExist = false;
                                        foreach (string categoryCode in categoryCodes)
                                        {
                                            if (catalogNode.Code.Equals(categoryCode))
                                            {
                                                if (sortOrder >= 0)
                                                {
                                                    nodeEntryRelationRow.SortOrder = sortOrder;
                                                }

                                                bExist = true;
                                                break;
                                            }
                                        }
                                        if (!bExist)
                                        {
                                            nodeEntryRelationRow.Delete();
                                        }
                                    }
                                }
                            }

                            //add entry to category
                            foreach (string categoryCode in categoryCodes)
                            {
                                DataRow[] catalogNodeDataRows = catalogNodeDto.CatalogNode.Select(String.Format("Code = '{0}'", categoryCode.Replace("'", "''")));
                                if (catalogNodeDataRows.Length > 0)
                                {
                                    Catalog.Dto.CatalogNodeDto.CatalogNodeRow catalogNode = (Catalog.Dto.CatalogNodeDto.CatalogNodeRow)catalogNodeDataRows[0];

                                    DataRow[] nodeEntryRelationDataRows = catalogRelationDto.NodeEntryRelation.Select(String.Format("CatalogNodeId = {0}", catalogNode.CatalogNodeId));
                                    if (nodeEntryRelationDataRows.Length == 0)
                                    {
                                        Catalog.Dto.CatalogRelationDto.NodeEntryRelationRow row = catalogRelationDto.NodeEntryRelation.NewNodeEntryRelationRow();
                                        row.CatalogId      = this._CatalogId;
                                        row.CatalogEntryId = entryRow.CatalogEntryId;
                                        row.CatalogNodeId  = catalogNode.CatalogNodeId;

                                        if (sortOrder >= 0)
                                        {
                                            row.SortOrder = sortOrder;
                                        }
                                        else
                                        {
                                            row.SortOrder = 0;
                                        }

                                        catalogRelationDto.NodeEntryRelation.AddNodeEntryRelationRow(row);
                                    }
                                }
                            }
                        }

                        if (catalogRelationDto.HasChanges())
                        {
                            CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto);
                        }
                    }

                    if (!bIsNew && !_isSystemClass && oldMetaClassId != entryRow.MetaClassId)
                    {
                        MetaObject.Delete(this.Context, entryRow.CatalogEntryId, oldMetaClassId);
                        MetaObject obj = MetaObject.NewObject(this.Context, entryRow.CatalogEntryId, entryRow.MetaClassId);
                        obj.AcceptChanges(this.Context);
                    }

                    tx.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new MDPImportException(ex.Message, null, RowIndex, null, null, item);
            }

            return(entryRow.CatalogEntryId);
        }
コード例 #8
0
ファイル: MetaDataWrapper.cs プロジェクト: alex765022/IBN
 public static MetaObject NewMetaObject(int ObjectId, string MetaClassName)
 {
     return(MetaObject.NewObject(ObjectId, MetaClassName, Security.CurrentUser.UserID, DateTime.UtcNow));
 }
コード例 #9
0
        /// <summary>
        /// Saves the changes.
        /// </summary>
        /// <param name="context">The context.</param>
        public void SaveChanges(IDictionary context)
        {
            if (ObjectId != 0)
            {
                // set username here, because calling FrameworkContext.Current.Profile causes MeteDataContext.Current to change (it's bug in ProfileContext class).
                string userName = FrameworkContext.Current.Profile.UserName;

                MDContext.UseCurrentUICulture = false;

                // make sure all the values are saved using transaction
                //using (TransactionScope scope = new TransactionScope())
                {
                    MetaObjectSerialized serialized = new MetaObjectSerialized();
                    //bool saveSerialized = false;
                    //string
                    foreach (string language in Languages)
                    {
                        MDContext.Language = language;

                        MetaObject metaObj     = null;
                        bool       saveChanges = true;

                        // Check if meta object contect exists
                        if (context != null && context.Contains(_MetaObjectContextKey + language))
                        {
                            saveChanges = false;
                            metaObj     = (MetaObject)context[_MetaObjectContextKey + language];
                        }
                        //if (context != null)
                        //{
                        //    if (context.Contains(_MetaObjectContextKey + language))
                        //    {
                        //        saveChanges = false;
                        //        saveSerialized = true;
                        //        metaObj = (MetaObject)context[_MetaObjectContextKey + language];
                        //    }
                        //    else if (context.Contains(_OrderMetaObjectContextKey + language))
                        //    {
                        //        metaObj = (MetaObject)context[_OrderMetaObjectContextKey + language];
                        //    }
                        //}

                        if (metaObj == null)
                        {
                            metaObj = MetaObject.Load(MDContext, ObjectId, MetaClassId);
                        }

                        if (metaObj == null)
                        {
                            metaObj = MetaObject.NewObject(MDContext, ObjectId, MetaClassId, userName);
                            //DataBind(); return;
                        }
                        else
                        {
                            metaObj.ModifierId = userName;
                            metaObj.Modified   = DateTime.UtcNow;
                        }

                        foreach (Control ctrl in MetaControls.Controls)
                        {
                            // Only update controls that belong to current language
                            if (String.Compare(((IMetaControl)ctrl).LanguageCode, language, true) == 0)
                            {
                                ((IMetaControl)ctrl).MetaObject = metaObj;
                                //((IMetaControl)ctrl).MetaField = metaObj;
                                ((IMetaControl)ctrl).Update();
                            }
                        }

                        // Only save changes when new object has been created
                        if (saveChanges)
                        {
                            metaObj.AcceptChanges(MDContext);
                        }
                        //else
                        if (context != null)
                        {
                            serialized.AddMetaObject(language, metaObj);
                        }
                    }

                    if (context != null)                     //&& saveSerialized)
                    {
                        context.Add("MetaObjectSerialized", serialized);
                    }
                    //scope.Complete();
                }

                MDContext.UseCurrentUICulture = true;
            }

            //DataBind();
        }
コード例 #10
0
        /// <summary>
        /// Creates the child controls internal.
        /// </summary>
        private void CreateChildControlsInternal()
        {
            //if (this.ObjectId > 0)
            {
                MetaControls.EnableViewState = false;
                if (MetaControls.Controls.Count > 0)
                {
                    return;
                }

                MetaControls.Controls.Clear();

                MetaClass mc = MetaClass.Load(this.MDContext, MetaClassId);

                if (mc == null)
                {
                    return;
                }

                Dictionary <string, MetaObject> metaObjects = new Dictionary <string, MetaObject>();

                if (_metaObjects != null)
                {
                    metaObjects = _metaObjects;
                }
                else
                {
                    // cycle through each language and get meta objects
                    MDContext.UseCurrentUICulture = false;
                    foreach (string language in Languages)
                    {
                        MDContext.UseCurrentUICulture = false;
                        MDContext.Language            = language;

                        MetaObject metaObj = null;
                        if (ObjectId > 0)
                        {
                            metaObj = MetaObject.Load(MDContext, ObjectId, mc);
                            if (metaObj == null)
                            {
                                metaObj = MetaObject.NewObject(MDContext, ObjectId, MetaClassId, FrameworkContext.Current.Profile.UserName);
                                metaObj.AcceptChanges(MDContext);
                            }
                        }

                        metaObjects[language] = metaObj;
                    }
                    MDContext.UseCurrentUICulture = true;
                }

                MetaFieldCollection metaFieldsColl = MetaField.GetList(MDContext, MetaClassId);
                foreach (MetaField mf in metaFieldsColl)
                {
                    if (mf.IsUser)
                    {
                        int index = 0;
                        foreach (string language in Languages)
                        {
                            string  controlName = ResolveMetaControl(mc, mf);
                            Control ctrl        = MetaControls.FindControl(mf.Name);

                            if (ctrl == null)
                            {
                                ctrl = Page.LoadControl(controlName);
                                MetaControls.Controls.Add(ctrl);
                            }


                            CoreBaseUserControl coreCtrl = ctrl as CoreBaseUserControl;
                            if (coreCtrl != null)
                            {
                                coreCtrl.MDContext = this.MDContext;
                            }

                            //ctrl.ID = String.Format("{0}-{1}", mf.Name, index.ToString());

                            ((IMetaControl)ctrl).MetaField = mf;
                            if (metaObjects[language] != null && metaObjects[language][mf] != null)
                            {
                                ((IMetaControl)ctrl).MetaObject = metaObjects[language];
                            }

                            ((IMetaControl)ctrl).LanguageCode    = language;
                            ((IMetaControl)ctrl).ValidationGroup = ValidationGroup;

                            ctrl.DataBind();

                            if (!mf.MultiLanguageValue)
                            {
                                break;
                            }

                            index++;
                        }
                    }
                }
            }
        }