/// <summary>
        /// Binds the data.
        /// </summary>
        /// <param name="siteActionTemplateId">The site action template id.</param>
        private void BindData(Guid?siteActionTemplateId)
        {
            var siteId = ((LeadForceBasePage)Page).SiteId;

            plNotBase.Visible = false;

            dcbParentTemplate.SelectedId   = Guid.Empty;
            dcbParentTemplate.SelectedText = string.Empty;

            dcbParentTemplate.SiteID = siteId;

            ddlReplaceLinks.Items.Clear();

            EnumHelper.EnumToDropDownList <ReplaceLinks>(ref ddlReplaceLinks, false);

            rUserColumnValues.DataSource = DataManager.SiteColumns.SelectAll(siteId);
            rUserColumnValues.DataBind();

            ddlActionType.DataSource     = DataManager.ActionTypes.SelectAll();
            ddlActionType.DataTextField  = "Title";
            ddlActionType.DataValueField = "ID";
            ddlActionType.DataBind();

            if (siteActionTemplateId.HasValue)
            {
                rtsTabs.Tabs[1].Selected            = true;
                RadMultiPage1.PageViews[1].Selected = true;

                var siteActionTemplate = DataManager.SiteActionTemplate.SelectById(siteId, (Guid)siteActionTemplateId);
                if (siteActionTemplate != null)
                {
                    dcbParentTemplate.Filters.Add(new DictionaryOnDemandComboBox.DictionaryFilterColumn
                    {
                        Name      = "ID",
                        DbType    = DbType.Guid,
                        Operation = FilterOperation.NotEqual,
                        Value     = siteActionTemplate.ID.ToString()
                    });

                    if (siteActionTemplate.UsageID.HasValue && siteActionTemplate.SiteActionTemplateCategoryID.HasValue)
                    {
                        switch ((SiteActionTemplateCategory)siteActionTemplate.SiteActionTemplateCategoryID)
                        {
                        case SiteActionTemplateCategory.MassMail:
                            var massMail = DataManager.MassMail.SelectById(siteId, (Guid)siteActionTemplate.UsageID);
                            if (massMail != null)
                            {
                                hlUsage.NavigateUrl = UrlsData.AP_MassMail(massMail.ID);
                                hlUsage.Text        = massMail.Name;
                            }
                            break;

                        case SiteActionTemplateCategory.Workflow:
                            var workflowTemplate = DataManager.WorkflowTemplate.SelectById(siteId, (Guid)siteActionTemplate.UsageID);
                            if (workflowTemplate != null)
                            {
                                hlUsage.NavigateUrl = UrlsData.AP_WorkflowTemplateEdit(workflowTemplate.ID);
                                hlUsage.Text        = workflowTemplate.Name;
                            }
                            break;

                        case SiteActionTemplateCategory.Event:
                            var siteEventTemplate = DataManager.SiteEventTemplates.SelectById((Guid)siteActionTemplate.UsageID);
                            if (siteEventTemplate != null)
                            {
                                hlUsage.NavigateUrl = UrlsData.AP_SiteEventTemplate(siteEventTemplate.ID);
                                hlUsage.Text        = siteEventTemplate.Title;
                            }
                            break;
                        }
                    }

                    if (siteActionTemplate.SiteActionTemplateCategoryID.HasValue &&
                        siteActionTemplate.SiteActionTemplateCategoryID != (int)SiteActionTemplateCategory.BaseTemplate)
                    {
                        plNotBase.Visible = true;
                    }

                    ddlActionType.SelectedIndex   = ddlActionType.FindItemIndexByValue(siteActionTemplate.ActionTypeID.ToString());
                    ddlReplaceLinks.SelectedIndex = ddlReplaceLinks.FindItemIndexByValue(siteActionTemplate.ReplaceLinksID.ToString());
                    txtFromEmail.Text             = siteActionTemplate.FromEmail;
                    txtFromName.Text       = siteActionTemplate.FromName;
                    txtToEmail.Text        = siteActionTemplate.ToEmail;
                    txtReplyEmail.Text     = siteActionTemplate.ReplyToEmail;
                    txtReplyName.Text      = siteActionTemplate.ReplyToName;
                    txtMessageCaption.Text = siteActionTemplate.MessageCaption;
                    ucHtmlEditor.Content   = siteActionTemplate.MessageBody;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            Title = "Шаблоны сообщений - LeadForce";

            access = Access.Check();
            if (!access.Write)
            {
                BtnUpdate.Visible = false;
            }

            var siteActionTemplateId = Page.RouteData.Values["ID"] as string;

            siteID = ((LeadForceBasePage)Page).SiteId;

            hlCancel.NavigateUrl = UrlsData.AP_SiteActionTemplates();

            if (!string.IsNullOrEmpty(siteActionTemplateId))
            {
                Guid.TryParse(siteActionTemplateId, out _siteActionTemplateId);
            }

            ucSelectSiteActionTemplate.SiteActionTemplateId = _siteActionTemplateId;

            if (!Page.IsPostBack)
            {
                BindData();

                var ddlSiteTemplateCategory = ((DropDownList)fvSiteActionTemplate.FindControl("ddlSiteTemplateCategory"));
                EnumHelper.EnumToDropDownList <SiteActionTemplateCategory>(ref ddlSiteTemplateCategory, false);

                var dcbParentTemplate = ((DictionaryOnDemandComboBox)fvSiteActionTemplate.FindControl("dcbParentTemplate"));
                dcbParentTemplate.SiteID = siteID;
                dcbParentTemplate.Filters.Add(new DictionaryOnDemandComboBox.DictionaryFilterColumn
                {
                    Name      = "ID",
                    DbType    = DbType.Guid,
                    Operation = FilterOperation.NotEqual,
                    Value     = _siteActionTemplateId.ToString()
                });

                var siteActionTemplate = DataManager.SiteActionTemplate.SelectById(_siteActionTemplateId);

                ((DropDownList)fvSiteActionTemplate.FindControl("ddlActionType")).DataSource     = DataManager.ActionTypes.SelectAll();
                ((DropDownList)fvSiteActionTemplate.FindControl("ddlActionType")).DataTextField  = "Title";
                ((DropDownList)fvSiteActionTemplate.FindControl("ddlActionType")).DataValueField = "ID";
                (fvSiteActionTemplate.FindControl("ddlActionType")).DataBind();

                BindReplaceLinks();
                var ddlReplaceLinks = ((DropDownList)fvSiteActionTemplate.FindControl("ddlReplaceLinks"));

                ddlReplaceLinks.SelectedIndex = ddlReplaceLinks.Items.IndexOf(ddlReplaceLinks.Items.FindByValue(((int)ReplaceLinks.GoogleLinks).ToString()));

                if (_siteActionTemplateId != Guid.Empty && siteActionTemplate != null)
                {
                    ddlSiteTemplateCategory.SelectedIndex =
                        ddlSiteTemplateCategory.FindItemIndexByValue(
                            siteActionTemplate.SiteActionTemplateCategoryID.ToString());

                    if (siteActionTemplate.SiteActionTemplateCategoryID.HasValue)
                    {
                        if (siteActionTemplate.UsageID.HasValue)
                        {
                            var hlUsage = ((HyperLink)fvSiteActionTemplate.FindControl("hlUsage"));
                            switch ((SiteActionTemplateCategory)siteActionTemplate.SiteActionTemplateCategoryID)
                            {
                            case SiteActionTemplateCategory.MassMail:
                                var massMail = DataManager.MassMail.SelectById(siteID, (Guid)siteActionTemplate.UsageID);
                                if (massMail != null)
                                {
                                    hlUsage.NavigateUrl = UrlsData.AP_MassMail(massMail.ID);
                                    hlUsage.Text        = massMail.Name;
                                }
                                break;

                            case SiteActionTemplateCategory.Workflow:
                                var workflowTemplate = DataManager.WorkflowTemplate.SelectById(siteID, (Guid)siteActionTemplate.UsageID);
                                if (workflowTemplate != null)
                                {
                                    hlUsage.NavigateUrl = UrlsData.AP_WorkflowTemplateEdit(workflowTemplate.ID);
                                    hlUsage.Text        = workflowTemplate.Name;
                                }
                                break;

                            case SiteActionTemplateCategory.Event:
                                var siteEventTemplate = DataManager.SiteEventTemplates.SelectById((Guid)siteActionTemplate.UsageID);
                                if (siteEventTemplate != null)
                                {
                                    hlUsage.NavigateUrl = UrlsData.AP_SiteEventTemplate(siteEventTemplate.ID);
                                    hlUsage.Text        = siteEventTemplate.Title;
                                }
                                break;
                            }
                        }

                        if (siteActionTemplate.SiteActionTemplateCategoryID != (int)SiteActionTemplateCategory.BaseTemplate)
                        {
                            fvSiteActionTemplate.FindControl("plNotBase").Visible = true;
                        }
                    }

                    if (siteActionTemplate.ParentID.HasValue)
                    {
                        var parentSiteAction = DataManager.SiteActionTemplate.SelectById(siteActionTemplate.ID);
                        dcbParentTemplate.SelectedId   = parentSiteAction.ID;
                        dcbParentTemplate.SelectedText = parentSiteAction.Title;
                        dcbParentTemplate.Enabled      = true;
                    }

                    ((DropDownList)fvSiteActionTemplate.FindControl("ddlActionType")).Items.FindByValue(siteActionTemplate.ActionTypeID.ToString()).Selected = true;

                    ddlReplaceLinks.SelectedIndex = ddlReplaceLinks.Items.IndexOf(ddlReplaceLinks.Items.FindByValue(siteActionTemplate.ReplaceLinksID.ToString()));

                    if ((ActionType)siteActionTemplate.ActionTypeID == ActionType.EmailToFixed)
                    {
                        (fvSiteActionTemplate.FindControl("pToEmail")).Visible = true;
                    }

                    var siteActions = DataManager.SiteAction.SelectBySiteActionTemplateID(siteID, _siteActionTemplateId).Where(a => (ActionStatus)a.ActionStatusID == ActionStatus.Done).ToList();
                    if (siteActions != null)
                    {
                        var sendingCount   = siteActions.Count;
                        var resoponseCount = siteActions.Count(a => a.ResponseDate != null);
                        litSending.Text  = sendingCount.ToString();
                        litResponse.Text = resoponseCount.ToString();
                        if (resoponseCount != 0)
                        {
                            litConversion.Text = string.Format("{0}%", Math.Round(((double)resoponseCount / sendingCount) * 100, 2));
                        }

                        BindActionLinks();
                    }
                }
                else
                {
                    pStats.Visible = false;
                    rtsTabs.FindTabByValue("tab-action-links").Visible = false;
                }

                rUserColumnValues.DataSource = DataManager.SiteColumns.SelectAll(siteID);
                rUserColumnValues.DataBind();
            }
        }