protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (EntityId == 0) this.entity = new BXRating(); else if ((this.entity = BXRating.GetById(EntityId, BXTextEncoder.EmptyTextEncoder)) == null) { this.editorError = RatingEditorError.IsNotFound; this.errorMessageText = GetMessageRaw("Message.RatingIsNotFound"); return; } EditorMode = this.entity.IsNew ? BXAdminPageEditorMode.Creation : BXAdminPageEditorMode.Modification; if (!IsPostBack) { if (!this.entity.IsNew) { Active.Checked = this.entity.Active; Name.Text = this.entity.Name; CurValCustomFieldName.Text = this.entity.CurValCustomFieldName; PrevValCustomFieldName.Text = this.entity.PrevValCustomFieldName; ListItem boundTypeItem = BoundEntityType.Items.FindByValue(this.entity.BoundEntityTypeId); if (boundTypeItem != null) boundTypeItem.Selected = true; ListItem calculationMethItem = CalculationMethod.Items.FindByValue(this.entity.CalculationMethod.ToString("G")); if (calculationMethItem != null) calculationMethItem.Selected = true; //ListItem refreshMethItem = RefreshMethod.Items.FindByValue(this.entity.RefreshMethod.ToString("G")); //if (refreshMethItem != null) // refreshMethItem.Selected = true; XmlId.Text = this.entity.XmlId; } else { Active.Checked = true; CurValCustomFieldName.Text = "Cur#RatingId#"; PrevValCustomFieldName.Text = "Prev#RatingId#"; ListItem boundTypeItem = BoundEntityType.Items.FindByValue("USER"); if (boundTypeItem != null) { boundTypeItem.Selected = true; Name.Text = GetMessageRaw("UserRating"); } } InitialComponentData.Value = GetComponentConfigEditorsJson(); } MasterTitle = Page.Title = EditorMode == BXAdminPageEditorMode.Creation ? GetMessage("PageTitle.Creation") : string.Concat(GetMessage("PageTitle.Modification"), " #", EntityId.ToString()); }
protected override void OnInit(EventArgs e) { if (!BXPrincipal.Current.IsCanOperate(BXRoleOperation.Operations.ProductSettingsManage)) BXAuthentication.AuthenticationRequired(); string id = Request.QueryString["id"]; if (string.IsNullOrEmpty(id)) this.entityId = 0; else { try { this.entityId = Convert.ToInt32(Request.QueryString["id"]); } catch { this.entityId = 0; } } if (this.entityId == 0) this.entity = new BXStorageConfiguration(); else if ((this.entity = BXStorageConfiguration.GetById(EntityId, BXTextEncoder.EmptyTextEncoder)) == null) { this.editorError = StorageConfigEditorError.IsNotFound; this.errorMessageText = GetMessageRaw("Message.EntityIsNotFound"); return; } this.editorMode = this.entity.IsNew ? BXAdminPageEditorMode.Creation : BXAdminPageEditorMode.Modification; List<BXTypeInfo> storageInfoLst = new List<BXTypeInfo>(); foreach (BXTypeInfo storageInfo in BXStorageManager.GetStorageInfos()) { //do not include BXFileSystemStorage - is not cloud storage if (!string.Equals(storageInfo.Name, typeof(BXFileSystemStorage).FullName, StringComparison.OrdinalIgnoreCase)) { storageInfoLst.Add(storageInfo); } } this.storageInfos = storageInfoLst.ToArray(); List<BXStorageSettingsEditor> storageSettingsEditorLst = new List<BXStorageSettingsEditor>(); foreach(BXTypeInfo storageInfo in this.storageInfos) { BXStorageSettingsEditor editor = BXStorageManager.CreateStorageSettingsEditor(storageInfo.Name); if (editor != null) { storageSettingsEditorLst.Add(editor); if (!this.entity.IsNew && string.Equals(this.entity.StorageTypeName, storageInfo.Name, StringComparison.OrdinalIgnoreCase)) { editor.Settings = this.entity.StorageSettings; } } } this.storageSettingsEditors = storageSettingsEditorLst.ToArray(); MasterTitle = Page.Title = this.editorMode == BXAdminPageEditorMode.Creation ? GetMessage("PageTitle.Creation") : string.Concat(GetMessage("PageTitle.Modification"), " #", EntityId.ToString()); base.OnInit(e); }
private void TryLoadAdvertisingBanner() { int id = ChargeId; if (id <= 0) { _editorMode = BXAdminPageEditorMode.Creation; _charge = new BXAdvertisingBanner(); if(ChargeSpaceCode.Length > 0) { BXAdvertisingSpaceCollection c = BXAdvertisingSpace.GetList( new BXFilter(new BXFilterItem(BXAdvertisingSpace.Fields.Code, BXSqlFilterOperators.Equal, ChargeSpaceCode)), null, new BXSelect(BXSelectFieldPreparationMode.Normal, BXAdvertisingSpace.Fields.Id), new BXQueryParams(BXPagingOptions.Top(1))); if(c.Count > 0) _charge.SpaceId = c[0].Id; } } else { _editorMode = BXAdminPageEditorMode.Modification; if ((_charge = BXAdvertisingBanner.GetById(id, BXTextEncoder.EmptyTextEncoder)) == null) { _errorMessage = string.Format(GetMessageRaw("Error.UnableToFindAdvertisingBanner"), id); _editorError = AdvertisingBannerEditorError.IsNotFound; return; } } if (!IsPostBack) { abCode.Text = _charge.Code; abActive.Checked = _charge.Active; DateTime? rotationStart = _charge.DateOfRotationStart; //if (rotationStart.HasValue) // AdvertisingBannerRotationPeriod.StartDate = rotationStart.Value; //else // AdvertisingBannerRotationPeriod.SetEmptyStartDate(); if (rotationStart.HasValue) abRotationPeriodStartTbx.Text = rotationStart.Value.ToString("d"); DateTime? rotationFinish = _charge.DateOfRotationFinish; //if (rotationFinish.HasValue) // AdvertisingBannerRotationPeriod.EndDate = rotationFinish.Value; //else // AdvertisingBannerRotationPeriod.SetEmptyStartDate(); if (rotationFinish.HasValue) abRotationPeriodFinishTbx.Text = rotationFinish.Value.ToString("d"); if (_charge.SpaceId <= 0) { if (abSpace.Items.Count > 0) abSpace.SelectedIndex = 0; } else { ListItem item = abSpace.Items.FindByValue(_charge.SpaceId.ToString()); if (item != null) item.Selected = true; } abWeight.Text = _charge.Weight.ToString(); ListItem contentTypeItem = abContentType.Items.FindByValue(_charge.ContentType.ToString("d")); if (contentTypeItem != null) contentTypeItem.Selected = true; abName.Text = _charge.Name; abDescription.Text = _charge.Description; abXmlId.Text = _charge.XmlId; if (_charge.ContentType == BXAdvertisingBannerContentType.Image) abImageContentFile.FileId = _charge.ContentFileId; else if (_charge.ContentType == BXAdvertisingBannerContentType.Flash) { abFlashVersion.Text = _charge.FlashVersion; abFlashContentFile.FileId = _charge.ContentFileId; abFlashAltImageFile.FileId = _charge.FlashAltImageFileId; } else if (_charge.ContentType == BXAdvertisingBannerContentType.Silverlight) { abSilverlightVersion.Text = _charge.FlashVersion; abSLContentFile.FileId = _charge.ContentFileId; abSLAltImageFile.FileId = _charge.FlashAltImageFileId; } //abFlashDynamicCreation.Checked = _charge.FlashDynamicCreation; //abFlashUseCustomUrl.Checked = _charge.FlashUseCustomUrl; abHtmlCode.StartMode = _charge.TextContentType == BXAdvertisingBannerTextContentType.Plain ? BXWebEditor.StartModeType.PlainText : BXWebEditor.StartModeType.HTMLVisual; abHtmlCode.Content = _charge.TextContent; abLinkUrl.Text = _charge.LinkUrl; LinkTargetFromCharge(BXAdvertisingBannerContentType.Image); abToolTip.Text = _charge.ToolTip; abFlashLinkUrl.Text = _charge.LinkUrl; LinkTargetFromCharge(BXAdvertisingBannerContentType.Flash); abFlashToolTip.Text = _charge.ToolTip; abRotationWeekSchedule.HourSpans.Clear(); BXAdvertisingBannerWeekScheduleHourSpanCollection bannerHourSpans = _charge.RotationHourSpans; if(bannerHourSpans.Count > 0) { BXWeekScheduleHourSpanControl[] hourSpanControls = new BXWeekScheduleHourSpanControl[bannerHourSpans.Count]; for (int i = 0; i < bannerHourSpans.Count; i++) abRotationWeekSchedule.HourSpans.Add(new BXWeekScheduleHourSpanControl(bannerHourSpans[i].Item)); } else if (_charge.IsNew) abRotationWeekSchedule.HourSpans.Add(new BXWeekScheduleHourSpanControl(new BXWeekScheduleHourSpan(0, 168))); ListItemCollection siteItems = abSites.Items; string[] siteIds = _charge.GetSiteIds(); foreach (string siteId in siteIds) { ListItem li = siteItems.FindByValue(siteId); if (li != null) li.Selected = true; } StringBuilder bannerUrlTemplatePermitted = new StringBuilder(), bannerUrlTemplateNotPermitted = new StringBuilder(); BXAdvertisingBannerUrlTemplateCollection bannerUrlTemplates = _charge.RotationUrlTemplates; foreach (BXAdvertisingBannerUrlTemplate bannerUrlTemplate in bannerUrlTemplates) { if(bannerUrlTemplate.IsPermitted) bannerUrlTemplatePermitted.AppendLine(bannerUrlTemplate.UrlTemplate); else bannerUrlTemplateNotPermitted.AppendLine(bannerUrlTemplate.UrlTemplate); } AdvertisingPermittedForRotationUrlTemplates.Text = bannerUrlTemplatePermitted.ToString(); AdvertisingNotPermittedForRotationUrlTemplates.Text = bannerUrlTemplateNotPermitted.ToString(); ListItemCollection userRolesItems = abUserRoles.Items; int[] userRoleIds = _charge.GetVisitorRoleIds(); foreach (int userRoleId in userRoleIds) { ListItem li = userRolesItems.FindByValue(userRoleId.ToString()); if (li != null) li.Selected = true; } EnableRotationForVisitorRoles.Items.FindByValue(_charge.EnableRotationForVisitorRoles ? "Y" : "N").Selected = true; abEnableFixedRotation.Checked = _charge.IsNew ? true : _charge.EnableFixedRotation; //abEnableUniformRotationVelocity.Checked = _charge.EnableUniformRotationVelocity; RotationModeFromChange(); if (_charge.MaxVisitorCount != 0) abMaxVisitorCount.Text = _charge.MaxVisitorCount.ToString(); if (_charge.MaxDisplayCountPerVisitor != 0) abMaxDisplayCountPerVisitor.Text = _charge.MaxDisplayCountPerVisitor.ToString(); if (_charge.MaxDisplayCount != 0) abMaxDisplayCount.Text = _charge.MaxDisplayCount.ToString(); abEnableRedirectionCount.Checked = _charge.EnableRedirectionCount; if (_charge.MaxRedirectionCount != 0) abMaxRedirectionCount.Text = _charge.MaxRedirectionCount.ToString(); if (_charge.ContentFileId > 0) { hfSLWidth.Value = _charge.ContentFile.Width.ToString(); hfSLHeight.Value = _charge.ContentFile.Height.ToString(); } } else { _charge.Code = abCode.Text; _charge.Active = abActive.Checked; //if (!AdvertisingBannerRotationPeriod.IsStartDateEmpty()) // _charge.DateOfRotationStart = AdvertisingBannerRotationPeriod.StartDate; //else // _charge.DateOfRotationStart = null; //DateTime dt; //if (!string.IsNullOrEmpty(abRotationPeriodStartTbx.Text.Trim()) && DateTime.TryParse(abRotationPeriodStartTbx.Text.Trim(), out dt)) // _charge.DateOfRotationStart = dt; // else // _charge.DateOfRotationStart = null; if (!string.IsNullOrEmpty(abRotationPeriodStartTbx.Text.Trim())) { DateTime startDate; if (DateTime.TryParse(abRotationPeriodStartTbx.Text.Trim(), out startDate)) _charge.DateOfRotationStart = startDate; else { _errorMessage = string.Format(GetMessage("Message.CouldnotParseDate"), abRotationPeriodStartTbx.Text.Trim()); _editorError = EditorMode == BXAdminPageEditorMode.Creation ? AdvertisingBannerEditorError.Creation : AdvertisingBannerEditorError.Modification; return; } } else _charge.DateOfRotationStart = null; if (!string.IsNullOrEmpty(abRotationPeriodFinishTbx.Text.Trim())) { DateTime finishDate; if (DateTime.TryParse(abRotationPeriodFinishTbx.Text.Trim(), out finishDate)) _charge.DateOfRotationFinish = finishDate; else { _errorMessage = string.Format(GetMessage("Message.CouldnotParseDate"), abRotationPeriodFinishTbx.Text.Trim()); _editorError = EditorMode == BXAdminPageEditorMode.Creation ? AdvertisingBannerEditorError.Creation : AdvertisingBannerEditorError.Modification; return; } } //DateTime dt; //if (!AdvertisingBannerRotationPeriod.IsEndDateEmpty()) // _charge.DateOfRotationFinish = AdvertisingBannerRotationPeriod.EndDate; //else // _charge.DateOfRotationFinish = null; //if (!string.IsNullOrEmpty(abRotationPeriodFinishTbx.Text.Trim()) && DateTime.TryParse(abRotationPeriodFinishTbx.Text.Trim(), out dt)) // _charge.DateOfRotationFinish = dt; //else // _charge.DateOfRotationFinish = null; if (abSpace.SelectedItem == null) _charge.SpaceId = 0; else { try { _charge.SpaceId = Convert.ToInt32(abSpace.SelectedItem.Value); } catch (Exception /*exception*/) { _charge.SpaceId = 0; } } try { _charge.Weight = Convert.ToInt32(abWeight.Text); } catch (Exception /*exc*/) { _charge.Weight = BXAdvertisingBanner.DefaultWeightValue; } _charge.Name = abName.Text; _charge.Description = abDescription.Text; _charge.XmlId = abXmlId.Text; if (!_charge.IsNew) { bool aboutContentFileDeletion = false; if (_charge.ContentType == BXAdvertisingBannerContentType.Image) aboutContentFileDeletion = abImageContentFile.AboutFileDeletion; else if (_charge.ContentType == BXAdvertisingBannerContentType.Flash) aboutContentFileDeletion = abFlashContentFile.AboutFileDeletion; else if (_charge.ContentType == BXAdvertisingBannerContentType.Silverlight) aboutContentFileDeletion = abSLContentFile.AboutFileDeletion; if (aboutContentFileDeletion) { BXFile contentFile = _charge.ContentFile; if (contentFile != null) _charge.ContentFile = null; } } //BXFile contentFile = abImageContentFile.File; //if (contentFile != null) //{ // _charge.ContentFile = contentFile; // if (contentFile.ContentType.ToUpperInvariant().StartsWith("IMAGE", StringComparison.InvariantCulture)) // contentType = BXAdvertisingBannerContentType.Image; // else if (string.Equals(contentFile.ContentType.ToUpperInvariant(), "APPLICATION/X-SHOCKWAVE-FLASH", StringComparison.InvariantCulture)) // contentType = BXAdvertisingBannerContentType.Flash; //} int flashVer = 0; string sVer = String.Empty; if (abContentType.SelectedItem != null) { BXAdvertisingBannerContentType? userContentType = null; try { userContentType = (BXAdvertisingBannerContentType)Enum.Parse(typeof(BXAdvertisingBannerContentType), abContentType.SelectedItem.Value); } catch (Exception /*exception*/) { } if (userContentType.HasValue) { BXFile contentFile = null; if (userContentType.Value == BXAdvertisingBannerContentType.Image) { contentFile = abImageContentFile.File; _charge.FlashWMode = abFlashWMode.Text; if (contentFile != null) { if (!contentFile.ContentType.ToUpperInvariant().StartsWith("IMAGE", StringComparison.InvariantCulture)) { contentFile = null; _errorMessage = GetMessage("Message.ContentTypeContradictFile"); _editorError = EditorMode == BXAdminPageEditorMode.Creation ? AdvertisingBannerEditorError.Creation : AdvertisingBannerEditorError.Modification; abImageContentFile.FileId = _charge.ContentFileId; } if (contentFile != null) { contentFile.Save(); abImageContentFile.FileId = contentFile.Id; } } } else if (userContentType.Value == BXAdvertisingBannerContentType.Flash) { _charge.FlashWMode = abFlashWMode.Text; contentFile = abFlashContentFile.File; if (contentFile != null) { if (!contentFile.ContentType.ToUpperInvariant().StartsWith("APPLICATION/X-SHOCKWAVE-FLASH", StringComparison.InvariantCulture)) { contentFile = null; _errorMessage = GetMessage("Message.ContentTypeContradictFile"); _editorError = EditorMode == BXAdminPageEditorMode.Creation ? AdvertisingBannerEditorError.Creation : AdvertisingBannerEditorError.Modification; abFlashContentFile.FileId = _charge.ContentFileId; } if (contentFile != null) { contentFile.Save(); abFlashContentFile.FileId = contentFile.Id; } } try { flashVer = Convert.ToInt32(abFlashVersion.Text); _charge.FlashVersion = flashVer.ToString(); } catch (Exception /*exc*/) { _charge.FlashVersion = string.Empty; } } else if (userContentType.Value == BXAdvertisingBannerContentType.Silverlight) { contentFile = abSLContentFile.File; if (contentFile != null) { if (!contentFile.ContentType.ToUpperInvariant().StartsWith("APPLICATION/OCTET-STREAM", StringComparison.InvariantCulture)) { contentFile = null; _errorMessage = GetMessage("Message.ContentTypeContradictFile"); _editorError = EditorMode == BXAdminPageEditorMode.Creation ? AdvertisingBannerEditorError.Creation : AdvertisingBannerEditorError.Modification; abSLContentFile.FileId = _charge.ContentFileId; } if (contentFile != null) { contentFile.Save(); abSLContentFile.FileId = contentFile.Id; } } _charge.FlashVersion = abSilverlightVersion.Text; } if (contentFile != null) _charge.ContentFile = contentFile; else { if (_charge.ContentType != userContentType.Value) _charge.ContentFile = null; _charge.ContentType = userContentType.Value; } } } _charge.TextContentType = abHtmlCode.StartMode == BXWebEditor.StartModeType.HTMLVisual ? BXAdvertisingBannerTextContentType.Html : BXAdvertisingBannerTextContentType.Plain; //_charge.FlashDynamicCreation = abFlashDynamicCreation.Checked; if (abFlashAltImageFile.AboutFileDeletion || abSLAltImageFile.AboutFileDeletion) _charge.FlashAltImageFile = null; else if (abFlashAltImageFile.File != null) _charge.FlashAltImageFile = abFlashAltImageFile.File; else if (abSLAltImageFile.File != null) _charge.FlashAltImageFile = abSLAltImageFile.File; //_charge.FlashUseCustomUrl = abFlashUseCustomUrl.Checked; _charge.TextContent = abHtmlCode.Content; switch (_charge.ContentType) { case BXAdvertisingBannerContentType.Image: _charge.LinkUrl = abLinkUrl.Text; _charge.ToolTip = abToolTip.Text; break; case BXAdvertisingBannerContentType.Flash: _charge.LinkUrl = abFlashLinkUrl.Text; _charge.ToolTip = abFlashToolTip.Text; break; case BXAdvertisingBannerContentType.Silverlight: _charge.LinkUrl = abFlashLinkUrl.Text; _charge.ToolTip = abFlashToolTip.Text; break; } LinkTargetToCharge(); _charge.RotationHourSpans.Clear(); foreach (BXWeekScheduleHourSpanControl hourSpan in abRotationWeekSchedule.HourSpans) _charge.RotationHourSpans.Add(new BXAdvertisingBannerWeekScheduleHourSpan(hourSpan.Item)); List<string> siteIdList = new List<string>(); ListItemCollection siteItems = abSites.Items; foreach (ListItem siteItem in siteItems) { if (!siteItem.Selected) continue; siteIdList.Add(siteItem.Value); } _charge.SetSiteIds(siteIdList.ToArray()); _charge.RotationUrlTemplates.Clear(); _charge.RotationUrlTemplates.AddRange(LoadUrlTemplateArrayFromString(AdvertisingPermittedForRotationUrlTemplates.Text, true)); _charge.RotationUrlTemplates.AddRange(LoadUrlTemplateArrayFromString(AdvertisingNotPermittedForRotationUrlTemplates.Text, false)); List<int> roleIdList = new List<int>(); ListItemCollection userRoleItems = abUserRoles.Items; foreach (ListItem userRoleItem in userRoleItems) { if (!userRoleItem.Selected) continue; roleIdList.Add(Convert.ToInt32(userRoleItem.Value)); } _charge.SetVisitorRoleIds(roleIdList.ToArray()); _charge.EnableRotationForVisitorRoles = EnableRotationForVisitorRoles.SelectedItem != null ? string.Equals(EnableRotationForVisitorRoles.SelectedItem.Value, "Y", StringComparison.Ordinal) : false; _charge.EnableFixedRotation = abEnableFixedRotation.Checked; //_charge.EnableUniformRotationVelocity = abEnableUniformRotationVelocity.Checked; RotationModeToCharge(); if (_charge.EnableFixedRotation) { try { int val = Convert.ToInt32(abMaxDisplayCount.Text); _charge.MaxDisplayCount = val >= 0 ? val : 0; } catch (Exception/*exc*/) { _charge.MaxDisplayCount = 0; } try { int val = Convert.ToInt32(abMaxVisitorCount.Text); _charge.MaxVisitorCount = val >= 0 ? val : 0; } catch (Exception/*exc*/) { _charge.MaxVisitorCount = 0; } try { int val = Convert.ToInt32(abMaxDisplayCountPerVisitor.Text); _charge.MaxDisplayCountPerVisitor = val >= 0 ? val : 0; } catch (Exception/*exc*/) { _charge.MaxDisplayCountPerVisitor = 0; } } _charge.EnableRedirectionCount = abEnableRedirectionCount.Checked; if (_charge.EnableRedirectionCount) { try { int val = Convert.ToInt32(abMaxRedirectionCount.Text); _charge.MaxRedirectionCount = val >= 0 ? val : 0; } catch (Exception/*exc*/) { _charge.MaxRedirectionCount = 0; } } } }