protected void gridItems_OnAction(string actionName, object actionArgument) { switch (actionName.ToLower()) { case "delete": // Look for info on relationship being removed int leftObjId = ValidationHelper.GetInteger(Request.Params["leftObjId"], -1); string leftObjType = ValidationHelper.GetString(Request.Params["leftObjType"], ""); int relationshipId = ValidationHelper.GetInteger(Request.Params["relationshipId"], -1); int rightObjId = ValidationHelper.GetInteger(Request.Params["rightObjId"], -1); string rightObjType = ValidationHelper.GetString(Request.Params["rightObjType"], ""); // Remove the relationship if all the necessary information available if ((leftObjId > -1) && (leftObjType.Trim() != "") && (relationshipId > -1) && (rightObjId > -1) && (rightObjType.Trim() != "")) { ObjectRelationshipInfoProvider.RemoveRelationship(leftObjId, leftObjType, rightObjId, rightObjType, relationshipId); } // Reload the data ReloadData(); break; default: break; } }
/// <summary> /// Gets the where condition for the selected object type. /// </summary> /// <param name="selectedObjectType">Selected object type</param> public string GetWhereCondition(string selectedObjectType) { if (Object != null) { string where = null; var relatedObject = RelatedObject; if (relatedObject != null) { // Get the site name var relatedTypeInfo = relatedObject.TypeInfo; if (relatedTypeInfo.SiteIDColumn != ObjectTypeInfo.COLUMN_NAME_UNKNOWN) { if (siteSelector.DropDownSingleSelect.Items.Count == 0) { siteSelector.Value = SiteContext.CurrentSiteID; } if (siteSelector.HasData) { // Set the site name for registration int selectedSiteId = ValidationHelper.GetInteger(siteSelector.Value, 0); if (selectedSiteId >= 0) { var siteCondition = (selectedSiteId > 0) ? new WhereCondition().WhereEquals(relatedTypeInfo.SiteIDColumn, selectedSiteId) : new WhereCondition().WhereNull(relatedTypeInfo.SiteIDColumn); string siteQuery = new DataQuery(relatedTypeInfo.ObjectType, null) .Column(relatedTypeInfo.IDColumn) .Where(siteCondition) .QueryText; // Where condition for the left object string rightWhere = ObjectRelationshipInfoProvider.GetWhereCondition(ObjectID, ObjectType, 0, false, true, selectedObjectType); rightWhere += " AND RelationshipLeftObjectID IN (" + siteQuery + ")"; // Where condition for the left object string leftWhere = ObjectRelationshipInfoProvider.GetWhereCondition(ObjectID, ObjectType, 0, true, false, selectedObjectType); leftWhere += " AND RelationshipRightObjectID IN (" + siteQuery + ")"; // --- Add site conditions here where = SqlHelper.AddWhereCondition(leftWhere, rightWhere, "OR"); } } } } if (String.IsNullOrEmpty(where)) { // Get using regular where where = ObjectRelationshipInfoProvider.GetWhereCondition(ObjectID, ObjectType, 0, true, true, selectedObjectType); } return(where); } return(null); }
/// <summary> /// Gets the where condition for the selected object type. /// </summary> /// <param name="selectedObjectType">Selected object type</param> public string GetWhereCondition(string selectedObjectType) { if (Object != null) { string where = null; if (RelatedObject != null) { // Get the site name if ((RelatedObject.SiteIDColumn != TypeInfo.COLUMN_NAME_UNKNOWN) && (CMSObjectHelper.GetSiteBindingObject(RelatedObject) == null)) { if (siteSelector.DropDownSingleSelect.Items.Count == 0) { siteSelector.Value = CMSContext.CurrentSiteID; } if (siteSelector.HasData) { // Set the site name for registration int selectedSiteId = ValidationHelper.GetInteger(siteSelector.Value, 0); if (selectedSiteId >= 0) { string siteWhere = QueryProvider.GetQuery(RelatedObject.ObjectType + ".selectall", RelatedObject.IDColumn, SqlHelperClass.GetSiteIDWhereCondition(RelatedObject.SiteIDColumn, selectedSiteId), null, 0); // Where condition for the left object string rightWhere = ObjectRelationshipInfoProvider.GetWhereCondition(ObjectID, ObjectType, 0, false, true, selectedObjectType); rightWhere += " AND RelationshipLeftObjectID IN (" + siteWhere + ")"; // Where condition for the left object string leftWhere = ObjectRelationshipInfoProvider.GetWhereCondition(ObjectID, ObjectType, 0, true, false, selectedObjectType); leftWhere += " AND RelationshipRightObjectID IN (" + siteWhere + ")"; // --- Add site conditions here where = SqlHelperClass.AddWhereCondition(leftWhere, rightWhere, "OR"); } } } } if (String.IsNullOrEmpty(where)) { // Get using regular where where = ObjectRelationshipInfoProvider.GetWhereCondition(ObjectID, ObjectType, 0, true, true, selectedObjectType); } return(where); } return(null); }
/// <summary> /// Inserts the new relationship according the selected values. /// </summary> private bool AddRelationship() { if (ObjectID > 0) { if (drpRelationship.SelectedItem == null) { lblError.Text = GetString("ObjRelationship.MustSelect"); lblError.Visible = true; return(false); } // Get information on type of the selected relationship int selectedRelationshipId = ValidationHelper.GetInteger(drpRelationship.SelectedItem.Value, -1); string selectedObjType = null; // If the main objectis on the left side selected object is taken from rifht drop-down list bool currentOnLeft = !ActiveLeft; int selectedObjId = currentOnLeft ? ValidationHelper.GetInteger(selRightObj.Value, -1) : ValidationHelper.GetInteger(selLeftObj.Value, -1); // Get information on type of the selected object selectedObjType = drpRelatedObjType.SelectedItem.Value; // If all the necessary information are present if ((selectedObjId <= 0) || (selectedRelationshipId <= 0) || (selectedObjType == null)) { lblError.Text = GetString("ObjRelationship.MustSelect"); lblError.Visible = true; return(false); } if (currentOnLeft) { ObjectRelationshipInfoProvider.AddRelationship(ObjectID, ObjectType, selectedObjId, selectedObjType, selectedRelationshipId); return(true); } else { ObjectRelationshipInfoProvider.AddRelationship(selectedObjId, selectedObjType, ObjectID, ObjectType, selectedRelationshipId); return(true); } } return(false); }