/// <summary> /// Reload data from node to controls. /// </summary> private void ReloadData() { // Sets the checkbox checked if AMP filter is enabled for current node GUID ObjectQuery <AmpFilterInfo> q = GetAmpFilterInfoForGuid(Node.NodeGUID.ToString()); chkEnableAmpFilter.Checked = q.Count != 0; AmpFilterInfo ampInfo = q.FirstOrDefault(); // Set controls if (q.Count != 0 && ampInfo != null) { ShowControls(true); chkDefaultCss.Checked = ampInfo.UseDefaultStylesheet; selectStyleSheet.Value = ampInfo.StylesheetID.ToString(); bool useDefaultChecked = chkDefaultCss.Checked; selectStyleSheet.Visible = !useDefaultChecked; labelSelectCss.Visible = !useDefaultChecked; } else { ShowControls(false); chkDefaultCss.Checked = true; selectStyleSheet.Visible = false; labelSelectCss.Visible = false; } }
/// <summary> /// Creates or removes a record in database for current page according to state of amp filter (enabled/disabled) /// </summary> /// <param name="sender">Sender object</param> /// <param name="e">Event arguments</param> protected void DocumentManager_OnSaveData(object sender, DocumentManagerEventArgs e) { if (Node != null) { string nodeGuid = Node.NodeGUID.ToString(); ObjectQuery <AmpFilterInfo> q = GetAmpFilterInfoForGuid(nodeGuid); if (chkEnableAmpFilter.Checked) { AmpFilterInfo ampInfo; // First check if any record exists for this page if (q.Count == 0) { // Insert new record to AmpFilterInfo table ampInfo = new AmpFilterInfo(); } else { // Update existing record ampInfo = q.FirstOrDefault(); } if (ampInfo != null) { // Update object properties ampInfo.PageNodeGUID = nodeGuid; ampInfo.SiteID = SiteContext.CurrentSiteID; ampInfo.UseDefaultStylesheet = chkDefaultCss.Checked; ampInfo.StylesheetID = ValidationHelper.GetInteger(selectStyleSheet.Value, 0); AmpFilterInfoProvider.SetAmpFilterInfo(ampInfo); } } else { // First check if any record exists for this page if (q.Count != 0) { // Remove record from AmpFilterInfo table AmpFilterInfoProvider.DeleteAmpFilterInfo(q.FirstOrDefault()); } } } }