📄 downloads_class_modi.aspx.cs
字号:
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Data;
using System.Runtime;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class admin_downloads_class_modi : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["shang_admin"] == null)
{
Response.Redirect("get_your_passport.aspx");
}
Label1.Text = "请慎重修改下载分类,新闻分类修改会移动该分类下的所有文件!";
if (!IsPostBack)
{
SqlConnection con = db.CreateConnection();
con.Open();
string strsql = "select * from download_class where bh='" + Request.QueryString["bh"] + "'";
SqlCommand cmd = new SqlCommand(strsql, con);
SqlDataAdapter ad = new SqlDataAdapter(strsql, con);
DataSet ds = new DataSet();
ad.Fill(ds, "aa");
TextBox1.Text = ds.Tables["aa"].Rows[0]["classname"].ToString();
TextBox3.Text = ds.Tables["aa"].Rows[0]["bh"].ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox2.Text != "")
{
SqlConnection con = db.CreateConnection();
con.Open();
string strsql = "update download_class set classname='" + TextBox2.Text + "' where bh='" + TextBox3.Text + "'";
SqlCommand cmd = new SqlCommand(strsql, con);
cmd.ExecuteNonQuery();
con.Close();
SqlConnection con2 = db.CreateConnection();
con2.Open();
string strsql2 = "update downloads set bigclassname='" + TextBox2.Text + "' where bigclassname='" + TextBox1.Text + "'";
SqlCommand cmd2 = new SqlCommand(strsql2, con2);
cmd2.ExecuteNonQuery();
con2.Close();
//生成文件夹
DirectoryInfo dirinfo = Directory.CreateDirectory(Server.MapPath("../downloads/" + TextBox2.Text));
//开始读取模板
string template;
SqlConnection con1 = db.CreateConnection();
con1.Open();
string strsql1 = "select * from example";
SqlDataAdapter ad1 = new SqlDataAdapter(strsql1, con1);
DataSet ds1 = new DataSet();
ad1.Fill(ds1, "bb");
//开始读取内容
SqlConnection con3 = db.CreateConnection();
con3.Open();
string strsql3 = "select * from downloads where bigclassname='" + TextBox2.Text + "'";
SqlDataAdapter ad3 = new SqlDataAdapter(strsql3, con3);
DataSet ds3 = new DataSet();
ad3.Fill(ds3, "cc");
for (int i = 0; i < ad3.Fill(ds3, "cc"); i++)
{
template = ds1.Tables["bb"].Rows[1]["example"].ToString();
template = Regex.Replace(template, "E_name", ds3.Tables["cc"].Rows[i]["name"].ToString());
template = Regex.Replace(template, "E_pic", ds3.Tables["cc"].Rows[i]["pic"].ToString());
template = Regex.Replace(template, "E_infor", ds3.Tables["cc"].Rows[i]["infor"].ToString());
template = Regex.Replace(template, "E_bigclassname", ds3.Tables["cc"].Rows[i]["bigclassname"].ToString());
template = Regex.Replace(template, "E_place", ds3.Tables["cc"].Rows[i]["place"].ToString());
template = Regex.Replace(template, "E_now", ds3.Tables["cc"].Rows[i]["time"].ToString());
template = Regex.Replace(template, "E_num", ds3.Tables["cc"].Rows[i]["bh"].ToString());
StreamWriter sw = File.CreateText(Server.MapPath("../downloads/" + ds3.Tables["cc"].Rows[i]["bigclassname"].ToString() + "/" + ds3.Tables["cc"].Rows[i]["bh"].ToString() + ".aspx"));
sw.Write(template);
}
if (Directory.Exists(Server.MapPath("../downloads/" + TextBox1.Text)))
{
Directory.Delete(Server.MapPath("../downloads/" + TextBox1.Text));
}
Response.Redirect("class_manage.aspx");
}
else
{
Label1.Text = "新的分类名称(文件夹名)不能为空";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -