Exemplo n.º 1
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
                PageTitle.TitleText = GetString("om.account.deletetitle");
                btnCancel.Attributes.Add("onclick", ctlAsync.GetCancelScript(true) + "return false;");

                titleElemAsync.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", "AccountSiteID");

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

                    // Data set contains only one item
                    if (rows.Count == 1)
                    {
                        PageTitle.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
                        PageTitle.TitleText         = GetString("om.account.deletetitlemultiple");
                        headQuestion.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()
                             .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"));
        }
    }
 /// <summary>
 /// Deletes group of accounts on SQL server.
 /// </summary>
 /// <param name="where">WHERE specifying group of accounts</param>
 private void BatchDeleteItems(StringBuilder where)
 {
     where.Remove(where.Length - 1, 1);
     where.Append(")");
     AccountInfoProvider.DeleteAccountInfos(where.ToString(), chkBranches.Checked);
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!QueryHelper.ValidateHash("hash") || Parameters == null)
        {
            StopProcessing = true;
            return;
        }

        PageTitle.TitleText = GetString("om.contactrole.select");
        Page.Title          = PageTitle.TitleText;

        // Check if the dialog was opened from mass actions
        isMassAction = Parameters.ContainsKey("ismassaction");
        if (isMassAction)
        {
            siteId = ValidationHelper.GetInteger(Parameters["siteid"], 0);
        }
        else
        {
            int accountContactId = ValidationHelper.GetInteger(Parameters["accountcontactid"], 0);
            aci = AccountContactInfoProvider.GetAccountContactInfo(accountContactId);
            if (aci != null)
            {
                AccountInfo ai = AccountInfoProvider.GetAccountInfo(aci.AccountID);
                if (ai != null)
                {
                    siteId = ai.AccountSiteID;
                }
            }
        }

        // Show all global configuration to authorized users ..
        bool allowGlobal = ConfigurationHelper.AuthorizedReadConfiguration(UniSelector.US_GLOBAL_RECORD, false);

        // .. but just in SiteManager - fake it in CMSDesk so that even Global Admin sees user configuration
        // as Site Admins (depending on settings).
        bool isSiteManager = ValidationHelper.GetBoolean(Parameters["issitemanager"], false);

        allowGlobal &= (isSiteManager || SettingsKeyInfoProvider.GetBoolValue(SiteInfoProvider.GetSiteName(siteId) + ".cmscmglobalconfiguration"));

        bool allowSite;

        if (siteId > 0)
        {
            allowSite = ConfigurationHelper.AuthorizedReadConfiguration(siteId, false);
        }
        else
        {
            allowSite = ConfigurationHelper.AuthorizedReadConfiguration(SiteContext.CurrentSiteID, false);
        }

        // Check read permission
        if ((siteId > 0) && !allowSite && !allowGlobal)
        {
            RedirectToAccessDenied("cms.contactmanagement", "ReadConfiguration");
            return;
        }
        else if ((siteId == 0) && !allowGlobal)
        {
            RedirectToAccessDenied("cms.contactmanagement", "ReadGlobalConfiguration");
            return;
        }

        if (siteId > 0)
        {
            if (allowSite)
            {
                gridElem.WhereCondition = "ContactRoleSiteID = " + siteId;
            }

            // Check if global config is allowed for the site
            if (allowGlobal)
            {
                // Add contact roles from global configuration
                gridElem.WhereCondition = SqlHelper.AddWhereCondition(gridElem.WhereCondition, "ContactRoleSiteID IS NULL", "OR");
            }
        }
        else if ((siteId == 0) && allowGlobal)
        {
            gridElem.WhereCondition = "ContactRoleSiteID IS NULL";
        }

        gridElem.OnExternalDataBound  += gridElem_OnExternalDataBound;
        gridElem.Pager.DefaultPageSize = 10;

        // Display 'Reset' button when 'none' role is allowed
        if (ValidationHelper.GetBoolean(Parameters["allownone"], false))
        {
            btnReset.Visible         = true;
            btnReset.Click          += btn_Click;
            btnReset.CommandArgument = "0";
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// Mass operation button "OK" click.
    /// </summary>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        string resultMessage = string.Empty;

        // 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 = gridElem.WhereCondition;
            break;

        // Selected items
        case What.Selected:
            where = SqlHelperClass.GetWhereCondition <int>("AccountID", (string[])gridElem.SelectedItems.ToArray(typeof(string)), 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(hdnIdentificator.Value, -1);
            // If status ID is 0, the status will be removed
            if (statusId >= 0)
            {
                AccountInfoProvider.UpdateAccountStatus(statusId, where);
                resultMessage = 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(hdnIdentificator.Value, 0);
            if (groupId > 0)
            {
                ArrayList accountIds = null;
                switch (what)
                {
                // All items
                case What.All:
                    // Get selected IDs based on where condition
                    DataSet accounts = AccountInfoProvider.GetAccounts(where, null, 0, "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)
                {
                    int accountId = 0;
                    // Add each selected account to the contact group, skip accounts that are already members of the group
                    foreach (string item in accountIds)
                    {
                        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)
                    {
                        resultMessage = String.Format(GetString("om.account.massaction.addedtogroup"), 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(hdnIdentificator.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;
        }

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

        // Reload unigrid
        gridElem.ClearSelectedItems();
        gridElem.ReloadData();
        pnlUpdate.Update();
    }
Exemplo n.º 5
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;

        default:
            return;
        }

        // Reload UniGrid
        gridElem.ResetSelection();
        gridElem.ReloadData();
        pnlUpdate.Update();
    }
Exemplo n.º 6
0
    /// <summary>
    /// Save data.
    /// </summary>
    protected void Save()
    {
        if (IsValid())
        {
            bool redirect = false;

            // Create new account
            if (ai == null)
            {
                ai           = new AccountInfo();
                EditedObject = ai;
                redirect     = true;
            }

            // Set values
            ai.AccountName               = txtName.Text.Trim();
            ai.AccountSubsidiaryOfID     = parentAccount.AccountID;
            ai.AccountOwnerUserID        = ValidationHelper.GetInteger(accountOwner.Value, 0);
            ai.AccountStatusID           = accountStatus.AccountStatusID;
            ai.AccountAddress1           = txtAddress1.Text.Trim();
            ai.AccountAddress2           = txtAddress2.Text.Trim();
            ai.AccountCity               = txtCity.Text.Trim();
            ai.AccountZIP                = txtZip.Text.Trim();
            ai.AccountCountryID          = countrySelector.CountryID;
            ai.AccountStateID            = countrySelector.StateID;
            ai.AccountPhone              = txtPhone.Text.Trim();
            ai.AccountFax                = txtFax.Text.Trim();
            ai.AccountEmail              = ValidationHelper.GetString(emailInput.Value, null);
            ai.AccountWebSite            = txtURL.Text.Trim();
            ai.AccountPrimaryContactID   = primaryContact.ContactID;
            ai.AccountSecondaryContactID = secondaryContact.ContactID;
            ai.AccountNotes              = htmlNotes.Value;
            ai.AccountSiteID             = SiteID;

            try
            {
                // Save account changes
                AccountInfoProvider.SetAccountInfo(ai);
                if (AssignContacts())
                {
                    ShowChangesSaved();
                }

                RaiseOnSaved();

                // Redirect page after newly created item is saved
                if (redirect)
                {
                    string url = "Frameset.aspx?accountId=" + ai.AccountID + "&saved=1";
                    url = URLHelper.AddParameterToUrl(url, "siteid", SiteID.ToString());
                    if (ContactHelper.IsSiteManager)
                    {
                        url = URLHelper.AddParameterToUrl(url, "issitemanager", "1");
                    }

                    URLHelper.Redirect(url);
                }
            }
            catch (Exception e)
            {
                ShowError(GetString("general.saveerror"), e.Message, null);
            }
        }
    }