gyhlw_dotnet/网站项目/VRS/Management/ZHC/Task_Proc_Material_Edit.asp...

173 lines
5.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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_Proc_Material_Edit : BasePage
{
DataService.BLL.admin_log log = new DataService.BLL.admin_log();
DataService.BLL.zhc_task_proc_material bll = new DataService.BLL.zhc_task_proc_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 (model.type == 0)
{
td_video.Visible = false;
td_pic.Visible = true;
imgTopic.ImageUrl = model.url;
}
else
{
td_video.Visible = true;
td_pic.Visible = false;
video.Src= model.url;
}
}
else
{
OnError(null);
}
}
protected void btnSure_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(name.Text))
{
RadAjaxManager1.Alert("素材名称不能为空!");
return;
}
var type_value = type.SelectedValue;
if (type_value == "0" && string.IsNullOrEmpty(imgTopic.ImageUrl))
{
RadAjaxManager1.Alert("图片内容不能为空!");
return;
}
if (type_value == "1" && string.IsNullOrEmpty(video.Src))
{
RadAjaxManager1.Alert("视频内容不能为空!");
return;
}
var url = imgTopic.ImageUrl;
if (type_value == "1")
{
url = video.Src;
}
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_proc_material model = bll.GetModel(Request.Params["Id"]);
model.name = name.Text.Trim();
model.type = int.Parse(type.SelectedValue);
model.url = url;
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)
{
var uploadFile = RadAsyncUpload1.UploadedFiles[0];
var upload_type = type.SelectedValue;
if (upload_type == "0") //图片
{
var arrray = new string[] { ".jpg", ".png", ".bmp", ".jpeg" };
var extension = uploadFile.GetExtension();
if (!arrray.Contains(extension))
{
RadAjaxManager1.Alert("请上传图片!");
return;
}
}
else if (upload_type == "1") //视频,.mp4,.avi,.dat,.3gp,.mov,.rmvb
{
var arrray = new string[] { ".mp4", ".avi", ".dat", ".3gp", ".mov", ".rmvb" };
var extension = uploadFile.GetExtension();
if (!arrray.Contains(extension))
{
RadAjaxManager1.Alert("请上传视频!");
return;
}
}
if (BasePage.SaveFile(uploadFile, Context, out string filePath))
{
if (upload_type == "0")
{
imgTopic.ImageUrl = "~" + filePath;
td_pic.Visible = true;
td_video.Visible = false;
}
else
{
td_pic.Visible = false;
td_video.Visible = true;
video.Src = "~" + filePath;
}
}
else
{
RadAjaxManager1.Alert("上传失败!");
}
}
protected void btnRemove_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(imgTopic.ImageUrl))
{
string path = Server.MapPath(imgTopic.ImageUrl);
if (File.Exists(path))
{
File.Delete(path);
}
imgTopic.ImageUrl = "";
}
if (!string.IsNullOrEmpty(video.Src))
{
string path = Server.MapPath(video.Src);
if (File.Exists(path))
{
File.Delete(path);
}
video.Src = "";
}
}
}
}