예제 #1
0
    /// <summary>
    /// Mass action 'ok' button clicked.
    /// </summary>
    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:
            // Convert array to integer values to make sure no sql injection is possible (via string values)
            where = SqlHelperClass.GetWhereCondition <int>("ContactGroupMemberID", ContactHelper.GetSafeArray(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);
            resultMessage = GetString("om.account.massaction.removed");
            break;

        default:
            return;
        }

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

        // Reload unigrid
        gridElem.ClearSelectedItems();
        gridElem.ReloadData();
        pnlUpdate.Update();
    }
예제 #2
0
    /// <summary>
    /// Returns where condition depending on mass action selection.
    /// </summary>
    /// <param name="whatValue">Value of What dd-list; if the value is 'selected' it also contains selected items</param>
    private string GetWhereCondition(string whatValue)
    {
        string where = string.Empty;

        if (!string.IsNullOrEmpty(whatValue))
        {
            string selectedItems = null;
            string whatAction    = null;

            if (whatValue.Contains("#"))
            {
                // Char '#' devides what-value and selected items
                whatAction    = whatValue.Substring(0, whatValue.IndexOf("#"));
                selectedItems = whatValue.Substring(whatValue.IndexOf("#") + 1);
            }
            else
            {
                whatAction = whatValue;
            }

            What what = (What)ValidationHelper.GetInteger(whatAction, 0);

            switch (what)
            {
            case What.All:
                // For all items get where condition from grid setting
                where = gridElem.WhereCondition;
                break;

            case What.Selected:
                // Convert array to integer values to make sure no sql injection is possible (via string values)
                if (selectedItems != null)
                {
                    string[] items = selectedItems.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                    items  = ContactHelper.GetSafeArray(items);
                    @where = SqlHelperClass.GetWhereCondition <int>("ActivityID", items, false);
                }
                break;
            }
        }

        // Limit WHERE by Contact ID
        if (ContactID > 0)
        {
            where = SqlHelperClass.AddWhereCondition(where, "ActivityActiveContactID=" + ContactID);
        }

        return(where);
    }
예제 #3
0
    /// <summary>
    /// Returns where condition depending on mass action selection.
    /// </summary>
    /// <param name="whatValue">Value of What dd-list; if the value is 'selected' it also contains selected items</param>
    private string GetWhereCondition(string whatValue)
    {
        string where = string.Empty;

        if (!string.IsNullOrEmpty(whatValue))
        {
            string selectedItems = null;
            string whatAction    = null;

            if (whatValue.Contains("#"))
            {
                // Char '#' devides what-value and selected items
                whatAction    = whatValue.Substring(0, whatValue.IndexOf("#"));
                selectedItems = whatValue.Substring(whatValue.IndexOf("#") + 1);
            }
            else
            {
                whatAction = whatValue;
            }

            What what = (What)ValidationHelper.GetInteger(whatAction, 0);

            switch (what)
            {
            case What.All:
                // For all items get where condition from grid setting
                where = gridElem.WhereCondition;
                break;

            case What.Selected:
                // For selected items compose where condition from selected items
                string[] items = selectedItems.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                items = ContactHelper.GetSafeArray(items);
                where = SqlHelperClass.GetWhereCondition <int>("AccountID", items, false);
                break;
            }
        }

        return(where);
    }
예제 #4
0
    /// <summary>
    /// Button OK click event handler.
    /// </summary>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        if (modifyAccountContact)
        {
            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 = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, gridElem.WhereClause);
                where = string.Format("AccountID={0} AND ContactID IN (SELECT ContactID FROM View_OM_AccountContact_ContactJoined WHERE {1})", ai.AccountID, where);
                break;

            // Selected items
            case What.Selected:
                where = SqlHelperClass.GetWhereCondition <int>("AccountContactID", ContactHelper.GetSafeArray(gridElem.SelectedItems), false);
                break;

            default:
                return;
            }

            switch (action)
            {
            // Action 'Remove'
            case Action.Remove:
                // Reset account's main contact IDs if any of the contacts was set as primary or secondary contact
                AccountContactInfoProvider.ResetAccountMainContacts(ai.AccountID, 0, where);
                // Delete the relations between account and contacts
                AccountContactInfoProvider.DeleteAllAccountContacts(where);
                resultMessage = GetString("om.contact.massaction.removed");
                break;

            // Action 'Select role'
            case Action.SelectRole:
                // Get selected role ID from hidden field
                int roleId = ValidationHelper.GetInteger(hdnValue.Value, -1);
                if (roleId >= 0)
                {
                    AccountContactInfoProvider.UpdateContactRole(roleId, where);
                    resultMessage = GetString("om.contact.massaction.roleassigned");
                }
                break;

            default:
                return;
            }

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

            // Reload unigrid
            gridElem.ClearSelectedItems();
            gridElem.ReloadData();
            pnlUpdate.Update();
        }
        // No permission modify
        else
        {
            if (this.SiteID > 0)
            {
                CMSPage.RedirectToCMSDeskAccessDenied("CMS.ContactManagement", "ModifyAccounts");
            }
            else
            {
                CMSPage.RedirectToCMSDeskAccessDenied("CMS.ContactManagement", "ModifyGlobalAccounts");
            }
        }
    }