/// <summary>
    /// Mass action 'ok' button clicked.
    /// </summary>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        CheckModifyPermissions();

        Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0);
        What   what   = (What)ValidationHelper.GetInteger(drpWhat.SelectedItem.Value, 0);

        var where = new WhereCondition()
                    .WhereEquals("ContactGroupMemberContactGroupID", cgi.ContactGroupID)
                    // Set constraint for account relations only
                    .WhereEquals("ContactGroupMemberType", 1);

        switch (what)
        {
        // All items
        case What.All:
            var accountIds = AccountInfoProvider.GetAccounts()
                             .Where(gridElem.WhereCondition)
                             .Where(gridElem.WhereClause)
                             .AsIDQuery();

            where.WhereIn("ContactGroupMemberRelatedID", accountIds);
            break;

        // Selected items
        case What.Selected:
            // Convert array to integer values to make sure no sql injection is possible (via string values)
            where.WhereIn("ContactGroupMemberRelatedID", gridElem.SelectedItems);
            break;

        default:
            return;
        }

        switch (action)
        {
        // Action 'Remove'
        case Action.Remove:
            // Delete the relations between contact group and accounts
            ContactGroupMemberInfoProvider.DeleteContactGroupMembers(where.ToString(true), cgi.ContactGroupID, true, true);
            // Show result message
            if (what == What.Selected)
            {
                ShowConfirmation(GetString("om.account.massaction.removed"));
            }
            else
            {
                ShowConfirmation(GetString("om.account.massaction.removedall"));
            }
            break;

        default:
            return;
        }

        // Reload unigrid
        gridElem.ClearSelectedItems();
        gridElem.ReloadData();
        pnlUpdate.Update();
    }
Exemple #2
0
    /// <summary>
    /// OnBeforeSave event handler.
    /// </summary>
    protected void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        // Set site ID only when creating new object
        if ((EditForm.EditedObject != null))
        {
            int groupId = EditForm.EditedObject.Generalized.ObjectID;

            if (groupId == 0)
            {
                if (SiteID > 0)
                {
                    EditForm.Data["ContactGroupSiteID"] = SiteID;
                }
                else
                {
                    EditForm.Data["ContactGroupSiteID"] = null;
                }
            }
            else
            {
                if (!chkDynamic.Checked)
                {
                    // Remove dynamic condition
                    EditForm.Data.SetValue("ContactGroupDynamicCondition", null);

                    // Remove dynamically created members
                    if (ValidationHelper.GetBoolean(hdnConfirmDelete.Value, false))
                    {
                        ContactGroupMemberInfoProvider.DeleteContactGroupMembers("ContactGroupMemberContactGroupID = " + groupId + " AND (ContactGroupMemberFromCondition = 1 AND (ContactGroupMemberFromAccount = 0 OR ContactGroupMemberFromAccount IS NULL) AND (ContactGroupMemberFromManual = 0 OR ContactGroupMemberFromManual IS NULL))", groupId, false, false);
                    }
                }
                else
                {
                    // Get new condition
                    string condition = EditForm.FieldControls["ContactGroupDynamicCondition"].Value.ToString();

                    // Display error if the condition is empty
                    if (string.IsNullOrEmpty(condition))
                    {
                        EditForm.StopProcessing  = true;
                        EditForm.ErrorLabel.Text = GetString("om.contactgroup.nocondition");
                    }
                    else
                    {
                        // Get current object to compare dynamic conditions
                        ContactGroupInfo currentGroup = ContactGroupInfoProvider.GetContactGroupInfo(EditForm.EditedObject.Generalized.ObjectID);
                        if ((currentGroup != null) && (!condition.EqualsCSafe(currentGroup.ContactGroupDynamicCondition, true)))
                        {
                            // Set 'Rebuild required' status
                            EditForm.Data["ContactGroupStatus"] = 2;
                        }
                    }
                }
            }
        }
    }
    /// <summary>
    /// Mass action 'ok' button clicked.
    /// </summary>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0);
        What   what   = (What)ValidationHelper.GetInteger(drpWhat.SelectedItem.Value, 0);

        string where = string.Empty;

        switch (what)
        {
        // All items
        case What.All:
            where = CMSContext.ResolveMacros("ContactGroupMemberContactGroupID = " + cgi.ContactGroupID);
            break;

        // Selected items
        case What.Selected:
            // Convert array to integer values to make sure no sql injection is possible (via string values)
            where = SqlHelperClass.GetWhereCondition <int>("ContactGroupMemberRelatedID", gridElem.SelectedItems, false);
            where = SqlHelperClass.AddWhereCondition(where, "ContactGroupMemberContactGroupID = " + cgi.ContactGroupID);
            break;

        default:
            return;
        }

        // Set constraint for account relations only
        where = SqlHelperClass.AddWhereCondition(where, "(ContactGroupMemberType = 1)");

        switch (action)
        {
        // Action 'Remove'
        case Action.Remove:
            // Delete the relations between contact group and accounts
            ContactGroupMemberInfoProvider.DeleteContactGroupMembers(where, cgi.ContactGroupID, true, true);
            // Show result message
            if (what == What.Selected)
            {
                ShowConfirmation(GetString("om.account.massaction.removed"));
            }
            else
            {
                ShowConfirmation(GetString("om.account.massaction.removedall"));
            }
            break;

        default:
            return;
        }

        // Reload unigrid
        gridElem.ClearSelectedItems();
        gridElem.ReloadData();
        pnlUpdate.Update();
    }
Exemple #4
0
    protected void btnOk_Click(object sender, EventArgs e)
    {
        string resultMessage = string.Empty;

        Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0);
        What   what   = (What)ValidationHelper.GetInteger(drpWhat.SelectedItem.Value, 0);

        string where = string.Empty;

        switch (what)
        {
        // All items
        case What.All:
            where = CMSContext.ResolveMacros("ContactGroupMemberContactGroupID = " + cgi.ContactGroupID);
            break;

        // Selected items
        case What.Selected:
            where = SqlHelperClass.GetWhereCondition <int>("ContactGroupMemberRelatedID", ContactHelper.GetSafeArray(gridElem.SelectedItems), false);
            where = SqlHelperClass.AddWhereCondition(where, "ContactGroupMemberContactGroupID = " + cgi.ContactGroupID);
            break;

        default:
            return;
        }

        // Set constraint for contact relations only
        where = SqlHelperClass.AddWhereCondition(where, "(ContactGroupMemberType = 0)");

        switch (action)
        {
        // Action 'Remove'
        case Action.Remove:
            // Delete the relations between contact group and contacts
            ContactGroupMemberInfoProvider.DeleteContactGroupMembers(where, cgi.ContactGroupID, false, false);
            resultMessage = GetString("om.contact.massaction.removed");
            break;

        default:
            return;
        }

        if (!string.IsNullOrEmpty(resultMessage))
        {
            lblInfo.Text    = resultMessage;
            lblInfo.Visible = true;
        }

        // Reload unigrid
        gridElem.ClearSelectedItems();
        gridElem.ReloadData();
        pnlUpdate.Update();
    }
    private void RemoveContacts(What what, string where)
    {
        ContactGroupMemberInfoProvider.DeleteContactGroupMembers(where, cgi.ContactGroupID, false, false);

        switch (what)
        {
        case What.All:
            ShowConfirmation(GetString("om.contact.massaction.removedall"));
            break;

        case What.Selected:
            ShowConfirmation(GetString("om.contact.massaction.removed"));
            break;
        }
    }