Files
g.hnyhua.cn/Mtxfw.shop/_Admin/admin_Download_add.aspx.cs

100 lines
3.8 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace Mtxfw.shop._Admin
{
public partial class admin_Download_add : Mtxfw.Utility.AdminPage
{
public Mtxfw.DAL.Article daoArt = new Mtxfw.DAL.Article();
public String TitName;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!IsPostBack)
{
Hidd_Url.Value = Request.UrlReferrer.ToString();
if (Request.QueryString["action"] == "add")
{
TitName = "添加下载文件";
Btn_Update.Visible = false;
}
else
{
TitName = "更新下载文件";
Btn_Insert.Visible = false;
Mtxfw.Model.Article model = daoArt.GetModel(int.Parse(Request.QueryString["ID"]));
Text_Title.Text = model.Title;
filepath.Text = model.Paths;
Hidd_C.Value = model.CategoryId;
}
}
Btn_Insert.Click += delegate(object s, EventArgs ex)
{
Mtxfw.Model.Article model = new Mtxfw.Model.Article();
model.Title = Text_Title.Text;
model.ParentID = 10;
model.CategoryId = "0";
model.AddTime = DateTime.Now;
model.Author = IdentityName;
model.Content = "";
model.Paths = filepath.Text;
daoArt.Add(model);
Mtxfw.Utility.Tools.Message("添加下载文件成功!", Hidd_Url.Value);
};
Btn_Update.Click += delegate(object s, EventArgs ex)
{
Int32 ID = int.Parse(Request.QueryString["ID"]);
Mtxfw.Model.Article model = daoArt.GetModel(ID);
model.Title = Text_Title.Text;
model.ParentID = 10;
model.CategoryId = Hidd_C.Value;
model.AddTime = DateTime.Now;
model.Author = IdentityName;
model.Content = "";
model.Paths = filepath.Text;
model.id = ID;
daoArt.Update(model);
Mtxfw.Utility.Tools.Message("更新下载文件成功!", Hidd_Url.Value);
};
}
protected void Button5_Click(object sender, System.EventArgs e)
{
if (uploadfile.PostedFile.ContentLength > 0)
{
string FileName, FileType, Folders;
Folders = "/uploadfile/";
FileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Millisecond.ToString();
FileType = uploadfile.PostedFile.FileName.Substring(uploadfile.PostedFile.FileName.LastIndexOf("."));
if (!Directory.Exists(Server.MapPath(Folders)))
{
Directory.CreateDirectory(Server.MapPath(Folders));
}
string strPilePath = Folders + FileName + FileType;
uploadfile.PostedFile.SaveAs(Server.MapPath(strPilePath));
if (filepath.Text != "")
{
if (!File.Exists(Server.MapPath(strPilePath)))
{
File.Delete(Server.MapPath(strPilePath));
}
}
filepath.Text = strPilePath;
}
else
{
Response.Write("<script language='javascript'>alert('请选择要上传的文件!')</script>");
}
}
}
}