代码拉取完成,页面将自动刷新
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Directory.Web
{
public partial class AddItem : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ccCategories.DataSource = CategoryDataProxy.GetChildsOfCategory(WebSettings.GetInstance().RootCategoryId);
ccCategories.DataBind();
int categoryId;
if (int.TryParse(Request.QueryString["categoryId"], out categoryId))
{
IList<Directory.Model.CategoryInfo> parentPath = CategoryDataProxy.GetRecursiveParentsOfCategory(categoryId);
string path = null;
foreach (Directory.Model.CategoryInfo cat in parentPath)
{
path += cat.CategoryId.ToString() + ",";
}
if (path != null)
{
ccCategories.AutoLoad = true;
ccCategories.SelectedIndexStr = path.Remove(path.Length - 1);
}
}
else
{
ccCategories.SelectedIndex = 0;
}
}
}
// 推荐
protected void btnRecommend_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(tbTitle.Text))
{
ltMsg.Text = "标题不能为空。";
return;
}
if (string.IsNullOrEmpty(tbLinkUrl.Text))
{
ltMsg.Text = "链接地址不能为空。";
return;
}
Directory.Model.ItemInfo.ErrorCode errorCode;
try
{
string username = Page.User.Identity.IsAuthenticated ? Page.User.Identity.Name : WebSettings.GetInstance().AnonymousUserName;
ItemDataProxy.CreateItem(ccCategories.SelectedId, tbTitle.Text, string.Empty, tbDescription.Text, tbLinkUrl.Text, "/default.gif", username, username, 0, false, false, out errorCode);
}
catch
{
ltMsg.Text = "添加失败:服务器错误。";
return;
}
switch (errorCode)
{
case Directory.Model.ItemInfo.ErrorCode.Success:
ClientScript.RegisterClientScriptBlock(this.GetType(), null, "<script>alert('添加成功!');window.location.href='additem.aspx?categoryId="+ccCategories.SelectedId+"'</script>");
break;
case Directory.Model.ItemInfo.ErrorCode.InvalidTitle:
ltMsg.Text = "添加失败:标题不正确。";
break;
case Directory.Model.ItemInfo.ErrorCode.InvalidCategory:
ltMsg.Text = "添加失败:目录不可用。";
break;
default:
ltMsg.Text = "添加失败:未知错误。";
break;
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。