1 Star 0 Fork 0

luweijun/tosouth

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
AddItem.aspx.cs 2.42 KB
一键复制 编辑 原始数据 按行查看 历史
luweijun 提交于 2018-04-28 11:23 . first commit
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;
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/luweijun/tosouth.git
git@gitee.com:luweijun/tosouth.git
luweijun
tosouth
tosouth
master

搜索帮助