/// <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; } } }
/// <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++; } } } } }