112 lines
3.5 KiB
C#
112 lines
3.5 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Web;
|
||
using System.Web.UI;
|
||
using System.Web.UI.WebControls;
|
||
|
||
namespace VRS.Management.ZHC
|
||
{
|
||
public partial class Task_Material_Edit : BasePage
|
||
{
|
||
DataService.BLL.admin_log log = new DataService.BLL.admin_log();
|
||
DataService.BLL.zhc_task_material bll = new DataService.BLL.zhc_task_material();
|
||
protected override void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
DataLoad();
|
||
}
|
||
}
|
||
protected void DataLoad()
|
||
{
|
||
string Id = Request.Params["Id"];
|
||
if (!string.IsNullOrWhiteSpace(Id))
|
||
{
|
||
var model = bll.GetModel(Id);
|
||
name.Text = model.name;
|
||
type.SelectedValue = model.type.ToString();
|
||
position.Text = model.position.ToString();
|
||
if (!string.IsNullOrEmpty(model.url))
|
||
{
|
||
imgTopic.ImageUrl = model.url;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
OnError(null);
|
||
}
|
||
}
|
||
|
||
protected void btnSure_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(name.Text))
|
||
{
|
||
RadAjaxManager1.Alert("素材名称不能为空!");
|
||
return;
|
||
}
|
||
|
||
|
||
if (string.IsNullOrEmpty(position.Text))
|
||
{
|
||
RadAjaxManager1.Alert("顺序不能为空!");
|
||
return;
|
||
}
|
||
int pos = 0;
|
||
if (!int.TryParse(position.Text,out pos))
|
||
{
|
||
RadAjaxManager1.Alert("顺序值为整数!");
|
||
return;
|
||
}
|
||
DataService.Model.zhc_task_material model = bll.GetModel(Request.Params["Id"]);
|
||
model.name = name.Text.Trim();
|
||
model.type = int.Parse(type.SelectedValue);
|
||
model.url = imgTopic.ImageUrl;
|
||
|
||
model.position = pos;
|
||
if (bll.Update(model))
|
||
{
|
||
log.write_log("修改素材成功。" + "素材名称:" + name.Text.Trim() + ",ID:" + model.material_id);
|
||
RadAjaxManager1.ResponseScripts.Add("alert('修改成功!');CloseAndRebind();");
|
||
}
|
||
else
|
||
RadAjaxManager1.Alert("修改失败!");
|
||
}
|
||
|
||
protected void btnUpload_Click(object sender, EventArgs e)
|
||
{
|
||
if (RadAsyncUpload1.UploadedFiles.Count < 1)
|
||
{
|
||
RadAjaxManager1.Alert("未选择图片!");
|
||
return;
|
||
}
|
||
|
||
var uploadFile = RadAsyncUpload1.UploadedFiles[0];
|
||
if (uploadFile.GetExtension() != ".jpg" && uploadFile.GetExtension() != ".png")
|
||
{
|
||
RadAjaxManager1.Alert("文件格式错误!");
|
||
return;
|
||
}
|
||
|
||
if (BasePage.SaveFile(uploadFile, Context, out string filePath))
|
||
{
|
||
imgTopic.ImageUrl = "~" + filePath;
|
||
}
|
||
else
|
||
{
|
||
RadAjaxManager1.Alert("上传失败!");
|
||
}
|
||
}
|
||
|
||
protected void btnRemove_Click(object sender, EventArgs e)
|
||
{
|
||
if (!string.IsNullOrEmpty(imgTopic.ImageUrl))
|
||
{
|
||
string path = Server.MapPath(imgTopic.ImageUrl);
|
||
File.Delete(path);
|
||
imgTopic.ImageUrl = "";
|
||
}
|
||
}
|
||
}
|
||
} |