📄 channeland.aspx.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using YXShop.DBUtility;
using System.Web.UI.WebControls;
using System.IO;
using System.Web;
using Shop.Web.UI;
namespace YXShop.Web.Admin.Article.InforChannel
{
public partial class ChannelAnd : System.Web.UI.Page
{
BasePage bp = null;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string title = "频道添加";
if (!string.IsNullOrEmpty(Request.QueryString["id"]))
{
if (!PowerTree.PowerPass.isPass("009004004", PowerTree.PowerPanel.PowerType.update))
{
bp = new BasePage();
bp.PageError("对不起,你没有修改频道的权限!", "../index.aspx");
}
title = "频道修改";
BindData();
txtFolder.Enabled = false;
}
else
{
if (!PowerTree.PowerPass.isPass("009004002", PowerTree.PowerPanel.PowerType.add))
{
bp = new BasePage();
bp.PageError("对不起,你没有添加频道的权限!", "../index.aspx");
}
}
Title = title;
//((Label)(Master.FindControl("lblName"))).Text = title;
}
}
void BindData()
{
int id = 0;
try
{
id = int.Parse(Request.QueryString["id"]);
}
catch { ClientScript.RegisterClientScriptBlock(GetType(), "error", "alert('参数不正确');", true); }
string strSql = "Select * from YX_InforChannel where YX_ID=" + id;
try
{
SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransactionHr, CommandType.Text, strSql, null);
if (dr.Read())
{
txtName.Text = YXShop.Common.WebUtility.HtmlToString(dr["YX_Name"].ToString());
txtFolder.Text = YXShop.Common.WebUtility.HtmlToString(dr["YX_DirName"].ToString());
rblType.Text = dr["Type"].ToString();
}
dr.Close();
}
catch { }
}
protected void submit_Click(object sender, EventArgs e)
{
string name = YXShop.Common.WebUtility.StringToHtml(txtName.Text);
string folder = YXShop.Common.WebUtility.StringToHtml(txtFolder.Text);
if (!string.IsNullOrEmpty(Request.QueryString["id"]))
{
try
{
string sqlUpdate = string.Format("Update YX_InforChannel set YX_Name='{0}',Type={1} where YX_ID={2}",
name, rblType.Text, int.Parse(Request.QueryString["id"]));
if (SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransactionHr, CommandType.Text, sqlUpdate, null) > 0)
ClientScript.RegisterStartupScript(GetType(), "OK", "alert('修改频道成功');location.href='ChannelManage.aspx';", true);
else ClientScript.RegisterStartupScript(GetType(), "error", "alert('修改频道失败');", true);
}
catch { }
}
else
{
#region 判断文件是否存在
try
{
DirectoryInfo dInfo = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/"));
foreach (DirectoryInfo dir in dInfo.GetDirectories())
{
if (folder == dir.ToString())
{
ClientScript.RegisterStartupScript(GetType(), "error", "alert('文件夹名称已经存在!');", true);
return;
}
}
#endregion
string sqlInsert = string.Format("Insert YX_InforChannel(YX_Name,YX_DirName,Type) Values('{0}','{1}',{2})",
name, folder, rblType.Text);
if (SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransactionHr, CommandType.Text, sqlInsert, null) > 0)
{
string oldfile = HttpContext.Current.Server.MapPath("~/ChanneModel");
string newfile = HttpContext.Current.Server.MapPath("~/" + folder) + "\\";
Directory.CreateDirectory(newfile);
fileHelper file = new fileHelper();
file.CopyTo(oldfile + @"\Index.aspx", newfile + "Index.aspx", false);
file.CopyTo(oldfile + @"\info.aspx", newfile + "info.aspx", false);
file.CopyTo(oldfile + @"\list.aspx", newfile + "list.aspx", false);
file.CopyTo(oldfile + @"\Onepage.aspx", newfile + "Onepage.aspx", false);
ClientScript.RegisterStartupScript(GetType(), "OK", "alert('添加频道成功');location.href='ChannelManage.aspx';", true);
}
else ClientScript.RegisterStartupScript(GetType(), "error", "alert('添加频道失败');", true);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -