private void Form_OnAfterSave(object sender, EventArgs e) { bool bindObjects = ValidationHelper.GetBoolean(Value, false); if ((bindObjects || !Form.IsInsertMode) && Visible) { GeneralizedInfo obj = (BaseInfo)Form.Data; if (obj != null) { try { BaseInfo bindingObj = ModuleManager.GetObject(Form.ResolveMacros(ObjectType)); int targetObjectID = ValidationHelper.GetInteger(Form.ResolveMacros(TargetObjectID), 0); var idColumn = obj.TypeInfo.IDColumn; if ((bindingObj != null) && (bindingObj.ColumnNames.Count >= 2) && (bindingObj.ContainsColumn(idColumn)) && (targetObjectID > 0)) { // Select proper column for target object string targetObjectColumn = (bindingObj.ColumnNames.IndexOf(idColumn) == 0) ? bindingObj.ColumnNames[1] : bindingObj.ColumnNames[0]; bindingObj.SetValue(idColumn, obj.ObjectID); bindingObj.SetValue(targetObjectColumn, targetObjectID); if (bindObjects) { // Bind objects bindingObj.Insert(); } else { // Remove binding bindingObj.Delete(); } } else { EventLogProvider.LogEvent(EventType.ERROR, "ObjectBinding", "BindObject", "Object " + obj.ObjectDisplayName + " cannot be bound."); } } catch (Exception ex) { EventLogProvider.LogException("ObjectBinding", "BindObject", ex); } } } }
/// <summary> /// Saves binding relationships for edited object. /// </summary> private void Form_OnAfterSave(object sender, EventArgs e) { // Check if object for which are binding objects created exists if (CurrentObjectInfo == null) { return; } // Resolve binding object type name string resolvedObjectType = Form.ResolveMacros(BindingObjectType); // Update binding objects try { string originalValues = GetOriginalSelectorData(); // Remove old items string newValues = ValidationHelper.GetString(uniSelector.Value, null); string items = DataHelper.GetNewItemsInList(newValues, originalValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); // Remove bindings foreach (string item in newItems) { BaseInfo bindingObj = SetBindingObject(item.ToInteger(0), resolvedObjectType); bindingObj.Delete(); } } // Add new items items = DataHelper.GetNewItemsInList(originalValues, newValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); // Create new binding foreach (string item in newItems) { BaseInfo bindingObj = SetBindingObject(item.ToInteger(0), resolvedObjectType); bindingObj.Insert(); } } } catch (Exception ex) { EventLogProvider.LogException("ObjectBinding", "BindObject", ex); } }
/// <summary> /// Store selected (unselected) roles. /// </summary> private void SaveData() { if (!editElem.Enabled) { ShowError(GetString("ui.notauthorizemodified")); return; } // Remove old items string newValues = ValidationHelper.GetString(editElem.Value, null); string deletedItems = DataHelper.GetNewItemsInList(newValues, currentValues); string addedItems = DataHelper.GetNewItemsInList(currentValues, newValues); if (!String.IsNullOrEmpty(deletedItems) || !String.IsNullOrEmpty(addedItems)) { bool saved = false; // Find column names for both binding Tuple <String, String> columns = GetBindingColumnNames(); String objCol = columns.Item1; String targetCol = columns.Item2; if (!String.IsNullOrEmpty(targetCol) && !String.IsNullOrEmpty(objCol)) { if (!String.IsNullOrEmpty(deletedItems)) { string[] newItems = deletedItems.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems.Length > 0) { // If provider object has object ID column, retrieve all changed objects by single query if (objProvider.Generalized.IDColumn != ObjectTypeInfo.COLUMN_NAME_UNKNOWN) { // For each retrieved object, create BaseInfo and delete it var q = objProvider.Generalized.GetDataQuery(false, s => s .WhereEquals(objCol, ObjectID) .WhereIn(targetCol, newItems.ToList()) , false ); DataSet ds = q.Result; if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { // Load base info based on datarow BaseInfo bi = ModuleManager.GetObject(dr, objProvider.Generalized.ObjectType); bi.Delete(); saved = true; } } } else { foreach (string item in newItems) { int bindingObjectID = ValidationHelper.GetInteger(item, 0); objProvider.SetValue(objCol, ObjectID); objProvider.SetValue(targetCol, bindingObjectID); objProvider.Delete(); saved = true; } } } } // Add new items if (!String.IsNullOrEmpty(addedItems)) { string[] newItems = addedItems.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { // Add all new items to site foreach (string item in newItems) { int bindingObjectID = ValidationHelper.GetInteger(item, 0); objProvider.SetValue(objCol, ObjectID); objProvider.SetValue(targetCol, bindingObjectID); objProvider.Insert(); saved = true; } } } if (saved) { obj.TypeInfo.InvalidateAllObjects(); ShowChangesSaved(); } } } }
/// <summary> /// Handles delete action. /// </summary> /// <param name="eventArgument">Objecttype(item or itemcategory);objectid</param> public void RaisePostBackEvent(string eventArgument) { string[] values = eventArgument.Split(';'); if (values.Length == 3) { int id = ValidationHelper.GetInteger(values[1], 0); int parentId = ValidationHelper.GetInteger(values[2], 0); BaseInfo biParent = BaseAbstractInfoProvider.GetInfoById(categoryObjectType, parentId); if (biParent == null) { return; } String categoryPath = ValidationHelper.GetString(biParent.GetValue(categoryPathColumn), String.Empty); int parentID = ValidationHelper.GetInteger(biParent.GetValue(categoryParentColumn), 0); //Test permission if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource(ResourceName, "Modify")) { String url = CMSPage.GetAccessDeniedUrl(UIHelper.ACCESSDENIED_PAGE, ResourceName, "modify", String.Empty, String.Empty); // Display access denied page in conent frame and select deleted item again String denyScript = @"$cmsj(document).ready(function(){ frames['paneContentTMain'].location = '" + ResolveUrl(url) + "';" + SelectAfterLoad(categoryPath + "/", id, values[0], parentId, false, false) + "});"; ltlScript.Text += ScriptHelper.GetScript(denyScript); return; } string script = String.Empty; switch (values[0]) { case "item": BaseInfo bi = BaseAbstractInfoProvider.GetInfoById(objectType, id); if (bi != null) { bi.Delete(); } break; case "category": try { BaseInfo biCate = BaseAbstractInfoProvider.GetInfoById(categoryObjectType, id); if (biCate != null) { biCate.Delete(); } } catch (Exception ex) { // Make alert with exception message, most probable cause is deleting category with subcategories script = String.Format("alert('{0}');\n", ex.Message); // Current node stays selected parentId = id; } break; } // After delete select first tab always tabIndexStr = String.Empty; script = SelectAfterLoad(categoryPath + "/", parentId, "category", parentID, true, true) + script; ltlScript.Text += ScriptHelper.GetScript(script); } }
/// <summary> /// Handles delete action. /// </summary> /// <param name="eventArgument">Objecttype(item or itemcategory);objectid</param> public void RaisePostBackEvent(string eventArgument) { string[] values = eventArgument.Split(';'); if (values.Length == 3) { int id = ValidationHelper.GetInteger(values[1], 0); int parentId = ValidationHelper.GetInteger(values[2], 0); BaseInfo biParent = ProviderHelper.GetInfoById(categoryObjectType, parentId); if (biParent == null) { return; } String categoryPath = ValidationHelper.GetString(biParent.GetValue(categoryPathColumn), String.Empty); int parentID = ValidationHelper.GetInteger(biParent.GetValue(categoryParentColumn), 0); //Test permission if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource(ResourceName, "Modify")) { String url = CMSPage.GetAccessDeniedUrl(AdministrationUrlHelper.ADMIN_ACCESSDENIED_PAGE, ResourceName, "modify", String.Empty, String.Empty); // Display access denied page in conent frame and select deleted item again String denyScript = @"$cmsj(document).ready(function(){ frames['paneContentTMain'].location = '" + ResolveUrl(url) + "';" + SelectAfterLoad(categoryPath + "/", id, values[0], parentId, false, false) + "});"; ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), ClientID + "_AccessDenied", ScriptHelper.GetScript(denyScript)); return; } switch (values[0]) { case "item": BaseInfo bi = ProviderHelper.GetInfoById(objectType, id); if (bi != null) { bi.Delete(); } break; case "category": try { BaseInfo biCate = ProviderHelper.GetInfoById(categoryObjectType, id); if (biCate != null) { biCate.Delete(); } } catch (Exception ex) { // Make alert with exception message, most probable cause is deleting category with subcategories var script = $"alert('{ScriptHelper.GetString(ex.Message, false)}');\n"; script += SelectAfterLoad(categoryPath + "/", id, "category", parentID, true, true); ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), ClientID + "_AfterLoad", ScriptHelper.GetScript(script)); return; } break; } // After delete select first tab always tabIndexStr = String.Empty; var location = UIContextHelper.GetElementUrl(UIContext.UIElement, UIContext); location = URLHelper.RemoveParameterFromUrl(location, "objectid"); location = URLHelper.UpdateParameterInUrl(location, "parentobjectid", parentId.ToString()); URLHelper.Redirect(location); } }