/// <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); } }
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); } } } }
private void InsertObjectHandler(BaseInfo newJoinObj) { try { newJoinObj.Insert(); } catch (InvalidOperationException ex) { if (ex.Message.IndexOf("Cannot insert the value NULL into column") > -1) { AddError("One or more required fields are not defined. Please either set the Object's TypeInfo with the proper Guid, Timestamp, CodeName, and/or SiteID columns, or add the field names to these Override in the properties.<br/><br/>If the required column is not one of these system columns, then please implement a global event on the Insert before to set these values programatically.<br/><br/>" + ex.Message.Replace("\n", "<br/>")); return; } } catch (Exception ex) { AddError("An error occured.<br/><br/>" + ex.Message.Replace("\n", "<br/>")); return; } }