예제 #1
0
        public void Page_Load(object sender, EventArgs e)
        {
            var request = SiteServer.Plugin.Context.GetCurrentRequest();

            _siteId    = request.GetQueryInt("siteId");
            _contentId = request.GetQueryInt("contentId");

            if (!request.AdminPermissions.HasSitePermissions(_siteId, Main.PluginId))
            {
                Response.Write("<h1>未授权访问</h1>");
                Response.End();
                return;
            }

            if (!string.IsNullOrEmpty(Request.QueryString["delete"]) &&
                !string.IsNullOrEmpty(Request.QueryString["idCollection"]))
            {
                var list = Request.QueryString["idCollection"].Split(',').Select(s => Convert.ToInt32(s)).ToList();
                ArticleDao.Delete(list);
                LtlMessage.Text = Utils.GetMessageHtml("删除成功!", true);
            }

            SpArticles.ControlToPaginate = RptArticles;
            SpArticles.ItemsPerPage      = 30;
            SpArticles.SelectCommand     = ArticleDao.GetSelectString(_siteId, _contentId);
            SpArticles.SortField         = nameof(ArticleInfo.Taxis);
            SpArticles.SortMode          = "ASC";
            RptArticles.ItemDataBound   += RptArticles_ItemDataBound;

            if (IsPostBack)
            {
                return;
            }

            SpArticles.DataBind();

            BtnAdd.Attributes.Add("onclick",
                                  $"location.href = '{GetRedirectUrl(_siteId, _contentId)}&addArticle={true}';return false;");

            BtnDelete.Attributes.Add("onclick", Utils.ReplaceNewline($@"
var ids = [];
$(""input[name='idCollection']:checked"").each(function () {{
    ids.push($(this).val());}}
);
if (ids.length > 0){{
    {Utils.SwalWarning("删除文章", "此操作将删除所选文章,确定吗?", "取 消", "删 除",
	            $"location.href='{GetRedirectUrl(_siteId, _contentId)}&delete={true}&idCollection=' + ids.join(',')")}
}} else {{
    {Utils.SwalError("请选择需要删除的文章!", string.Empty)}
}}
;return false;", string.Empty));

            BtnTaxis.Attributes.Add("onclick", Utils.ReplaceNewline($@"
var ids = [];
$(""input[name='idCollection']:checked"").each(function () {{
    ids.push($(this).val());}}
);
if (ids.length > 0){{
    location.href = '{GetRedirectUrl(_siteId, _contentId)}&taxis={true}&idCollection=' + ids.join(',')
}} else {{
    {Utils.SwalError("请选择需要排序的文章!", string.Empty)}
}}
;return false;", string.Empty));

            if (!string.IsNullOrEmpty(Request.QueryString["addArticle"]))
            {
                PhModalAdd.Visible = true;

                var articleId = Convert.ToInt32(Request.QueryString["articleId"]);

                var jsUrl = SiteServer.Plugin.Context.PluginApi.GetPluginUrl(Main.PluginId, "assets/script.js");

                LtlModalAddTitle.Text  = articleId > 0 ? "编辑表单内容" : "新增表单内容";
                LtlModalAddTitle.Text += $@"<script type=""text/javascript"" src=""{jsUrl}""></script>";
                if (articleId > 0)
                {
                    var articleInfo = ArticleDao.GetArticleInfo(articleId);
                    TbTitle.Text = articleInfo.Title;
                    Utils.SelectListItems(DdlIsFree, articleInfo.IsFree.ToString());
                    TbContent.Text = articleInfo.Content;
                }
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["taxis"]) &&
                     !string.IsNullOrEmpty(Request.QueryString["idCollection"]))
            {
                PhModalTaxis.Visible = true;
            }
        }