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_Add : 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) { base.Page_Load(sender, e); if (!IsPostBack) { } } protected void btnSure_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(name.Text)) { RadAjaxManager1.Alert("素材名称不能为空!"); return; } /* if (bll.GetRecordCount(string.Format(" device_name = '{0}' ", device_name.Text.Trim())) > 0) { RadAjaxManager1.Alert("设备名称禁止重复!"); return; } */ if (string.IsNullOrEmpty(imgTopic.ImageUrl)) { RadAjaxManager1.Alert("素材内容不能为空!"); return; } string taskId = Request.Params["taskId"]; DataService.Model.zhc_task_material model = new DataService.Model.zhc_task_material(); model.material_id = bll.GetNewId(); model.taskId = taskId; model.name = name.Text.Trim(); model.type = int.Parse(type.SelectedValue); model.url = imgTopic.ImageUrl; model.position = bll.GetPosition(taskId); if (bll.Add(model)) { log.write_log("添加素材成功。" + type.SelectedText+ "名称:" +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 = ""; } } } }