/// <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();
    }
    /// <summary>
    /// Gets Where condition for filtering by the state. When using separated database, materializes the nested query on the other DB.
    /// </summary>
    private string GetStateCondition(TextSimpleFilter filter)
    {
        string originalQuery = filter.WhereCondition;

        if (String.IsNullOrEmpty(originalQuery))
        {
            return(string.Empty);
        }

        // Query with AccountInfo context has to be used in order to be able to determine DB context of the query (otherwise the materialization would not perform).
        var query = AccountInfoProvider.GetAccounts()
                    .WhereIn("AccountStateID", StateInfoProvider
                             .GetStates()
                             .Where(originalQuery)
                             .Column(StateInfo.TYPEINFO.IDColumn)
                             );

        if (filter.FilterOperator == WhereBuilder.NOT_LIKE || filter.FilterOperator == WhereBuilder.NOT_EQUAL)
        {
            query = query.Or(new WhereCondition().WhereNull("AccountStateID"));
        }

        query.EnsureParameters();
        return(query.Parameters.Expand(query.WhereCondition));
    }
Example #3
0
        private AccountInfo CreateAccount(string accountName)
        {
            var accountObj1 = AccountInfoProvider.GetAccounts()
                              .FirstOrDefault(
                acc => acc.AccountName == accountName);

            if (accountObj1 != null)
            {
                AccountInfoProvider.DeleteAccountInfo(accountObj1);
            }

            var accountObj2 = new AccountInfo();

            accountObj2.AccountName = accountName;
            AccountInfoProvider.SetAccountInfo(accountObj2);
            return(accountObj2);
        }
Example #4
0
    /// <summary>
    /// Mass operation button "OK" click.
    /// </summary>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // Get where condition depending on mass action selection
        string where = null;

        What what = (What)ValidationHelper.GetInteger(drpWhat.SelectedValue, 0);

        switch (what)
        {
        // All items
        case What.All:
            where = SqlHelper.AddWhereCondition(gridElem.WhereCondition, gridElem.WhereClause);
            break;

        // Selected items
        case What.Selected:
            where = SqlHelper.GetWhereCondition <int>("AccountID", gridElem.SelectedItems, false);
            break;
        }

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

        switch (action)
        {
        // Action 'Change status'
        case Action.ChangeStatus:
        {
            // Get selected status ID from hidden field
            int statusId = ValidationHelper.GetInteger(hdnIdentifier.Value, -1);
            // If status ID is 0, the status will be removed
            if (statusId >= 0)
            {
                AccountInfoProvider.UpdateAccountStatus(statusId, where);
                ShowConfirmation(GetString("om.account.massaction.statuschanged"));
            }
        }
        break;

        // Action 'Add to contact group'
        case Action.AddToGroup:
        {
            // Get contact group ID from hidden field
            int groupId = ValidationHelper.GetInteger(hdnIdentifier.Value, 0);
            if (groupId > 0)
            {
                IEnumerable <string> accountIds = null;

                switch (what)
                {
                // All items
                case What.All:
                    // Get selected IDs based on where condition
                    DataSet accounts = AccountInfoProvider.GetAccounts().Where(where).Column("AccountID");
                    if (!DataHelper.DataSourceIsEmpty(accounts))
                    {
                        // Get array list with IDs
                        accountIds = DataHelper.GetUniqueValues(accounts.Tables[0], "AccountID", true);
                    }
                    break;

                // Selected items
                case What.Selected:
                    // Get selected IDs from UniGrid
                    accountIds = gridElem.SelectedItems;
                    break;
                }

                if (accountIds != null)
                {
                    // Add each selected account to the contact group, skip accounts that are already members of the group
                    foreach (string item in accountIds)
                    {
                        int accountId = ValidationHelper.GetInteger(item, 0);
                        if ((accountId > 0) && (ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(groupId, accountId, ContactGroupMemberTypeEnum.Account) == null))
                        {
                            ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(groupId, accountId, ContactGroupMemberTypeEnum.Account, MemberAddedHowEnum.Account);
                        }
                    }
                    // Get contact group to show result message with its display name
                    ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo(groupId);
                    if (group != null)
                    {
                        ShowConfirmation(String.Format(GetString("om.account.massaction.addedtogroup"), ResHelper.LocalizeString(group.ContactGroupDisplayName)));
                    }
                }
            }
        }
        break;


        // Merge click
        case Action.Merge:
            DataSet selectedAccounts = AccountHelper.GetAccounListInfos(null, where, null, -1, null);
            if (!DataHelper.DataSourceIsEmpty(selectedAccounts))
            {
                // Get selected account ID from hidden field
                int accountID = ValidationHelper.GetInteger(hdnIdentifier.Value, -1);
                // If account ID is 0 then new contact must be created
                if (accountID == 0)
                {
                    int siteID;
                    if (filter.DisplaySiteSelector || filter.DisplayGlobalOrSiteSelector)
                    {
                        siteID = filter.SelectedSiteID;
                    }
                    else
                    {
                        siteID = SiteID;
                    }

                    SetDialogParameters(selectedAccounts, AccountHelper.GetNewAccount(AccountHelper.MERGED, siteID));
                }
                // Selected contact to be merged into
                else if (accountID > 0)
                {
                    SetDialogParameters(selectedAccounts, AccountInfoProvider.GetAccountInfo(accountID));
                }
                OpenWindow();
            }
            break;

        default:
            return;
        }

        // Reload UniGrid
        gridElem.ResetSelection();
        gridElem.ReloadData();
        pnlUpdate.Update();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check hash validity
        if (QueryHelper.ValidateHash("hash"))
        {
            // Initialize events
            ctlAsyncLog.OnFinished += ctlAsync_OnFinished;
            ctlAsyncLog.OnError    += ctlAsync_OnError;
            ctlAsyncLog.OnCancel   += ctlAsync_OnCancel;

            ctlAsyncLog.MaxLogLines = 1000;

            if (!RequestHelper.IsCallback())
            {
                // Setup page title text and image
                PageTitle.TitleText = GetString("om.account.deletetitle");

                ctlAsyncLog.TitleText = GetString("om.account.deleting");
                // Set visibility of panels
                pnlContent.Visible = true;
                pnlLog.Visible     = false;

                // Get names of the accounts that are to be deleted
                DataSet ds = AccountInfoProvider.GetAccounts()
                             .Where(WhereCondition)
                             .OrderBy("AccountName")
                             .TopN(1000)
                             .Columns("AccountID", "AccountName");

                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    DataRowCollection rows = ds.Tables[0].Rows;

                    // Data set contains only one item
                    if (rows.Count == 1)
                    {
                        PageTitle.TitleText += " \"" + HTMLHelper.HTMLEncode(DataHelper.GetStringValue(rows[0], "AccountName", "N/A")) + "\"";
                        accountIds           = new List <string>(1);
                        accountIds.Add(DataHelper.GetStringValue(rows[0], "AccountID"));
                        numberOfDeletedAccounts = 1;
                    }
                    else if (rows.Count > 1)
                    {
                        // Modify title and question for multiple items
                        PageTitle.TitleText         = GetString("om.account.deletetitlemultiple");
                        headQuestion.ResourceString = "om.account.deletemultiplequestion";

                        // Display list with names of deleted items
                        pnlAccountList.Visible = true;

                        StringBuilder builder = new StringBuilder();

                        for (int i = 0; i < rows.Count; i++)
                        {
                            string name = DataHelper.GetStringValue(rows[i], "AccountName");

                            builder.Append("<div>");
                            builder.Append(HTMLHelper.HTMLEncode(name));
                            builder.Append("</div>");
                        }

                        // Display three dots after last record
                        if (rows.Count == 1000)
                        {
                            builder.Append("...");
                        }

                        lblAccounts.Text = builder.ToString();

                        // Get all IDs of deleted items
                        ds = AccountInfoProvider.GetAccounts()
                             .Where(WhereCondition)
                             .OrderBy("AccountID")
                             .Column("AccountID");

                        accountIds = DataHelper.GetStringValues(ds.Tables[0], "AccountID");
                        numberOfDeletedAccounts = ds.Tables[0].Rows.Count;
                    }
                }
                else
                {
                    // Hide everything
                    pnlContent.Visible = false;
                }
            }
        }
        else
        {
            pnlDelete.Visible = false;
            ShowError(GetString("dialogs.badhashtext"));
        }
    }
Example #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check hash validity
        if (QueryHelper.ValidateHash("hash"))
        {
            // Initialize events
            ctlAsync.OnFinished   += ctlAsync_OnFinished;
            ctlAsync.OnError      += ctlAsync_OnError;
            ctlAsync.OnRequestLog += ctlAsync_OnRequestLog;
            ctlAsync.OnCancel     += ctlAsync_OnCancel;

            issitemanager = ValidationHelper.GetBoolean(Parameters["issitemanager"], false);

            if (!RequestHelper.IsCallback())
            {
                // Setup page title text and image
                CurrentMaster.Title.TitleText  = GetString("om.account.deletetitle");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/OM_Account/delete.png");

                btnCancel.Attributes.Add("onclick", ctlAsync.GetCancelScript(true) + "return false;");

                titleElemAsync.TitleText  = GetString("om.account.deleting");
                titleElemAsync.TitleImage = GetImageUrl("Objects/OM_Account/delete.png");

                // Set visibility of panels
                pnlContent.Visible = true;
                pnlLog.Visible     = false;

                // Get names of the accounts that are to be deleted
                DataSet ds = AccountInfoProvider.GetAccounts(WhereCondition, "AccountName", 1000, "AccountID, AccountName, AccountSiteID");

                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    DataRowCollection rows = ds.Tables[0].Rows;

                    // Data set contains only one item
                    if (rows.Count == 1)
                    {
                        CurrentMaster.Title.TitleText += " \"" + HTMLHelper.HTMLEncode(ValidationHelper.GetString(DataHelper.GetDataRowValue(rows[0], "AccountName"), "N/A")) + "\"";
                        accountIds = new List <string>(1);
                        accountIds.Add(ValidationHelper.GetString(DataHelper.GetDataRowValue(rows[0], "AccountID"), string.Empty));
                        accountSiteId           = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(rows[0], "AccountSiteID"), 0);
                        numberOfDeletedAccounts = 1;
                    }
                    else if (rows.Count > 1)
                    {
                        // Modify title and question for multiple items
                        CurrentMaster.Title.TitleText = GetString("om.account.deletetitlemultiple");
                        lblQuestion.ResourceString    = "om.account.deletemultiplequestion";

                        // Display list with names of deleted items
                        pnlAccountList.Visible = true;

                        string        name    = null;
                        StringBuilder builder = new StringBuilder();

                        for (int i = 0; i < rows.Count; i++)
                        {
                            name = ValidationHelper.GetString(DataHelper.GetDataRowValue(rows[i], "AccountName"), string.Empty);
                            builder.Append(HTMLHelper.HTMLEncode(name));
                            builder.Append("<br />");
                        }
                        // Display three dots after last record
                        if (rows.Count == 1000)
                        {
                            builder.Append("...");
                        }

                        lblAccounts.Text = builder.ToString();

                        accountSiteId = SiteID;
                        // Get all IDs of deleted items
                        ds         = AccountInfoProvider.GetAccounts(WhereCondition, "AccountID", 0, "AccountID");
                        accountIds = SqlHelperClass.GetStringValues(ds.Tables[0], "AccountID");
                        numberOfDeletedAccounts = ds.Tables[0].Rows.Count;
                    }
                }
                else
                {
                    // Hide everything
                    pnlContent.Visible = false;
                }
            }
        }
        else
        {
            pnlDelete.Visible = false;
            lblError.Text     = GetString("dialogs.badhashtext");
        }
    }