gyhlw_dotnet/网站项目/VRS/Management/ZHC/Task_Proc_Material_Add.aspx.cs

169 lines
5.6 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_Add : 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();
DataService.BLL.zhc_task_proc bll_task_proc = new DataService.BLL.zhc_task_proc();
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;
}
*/
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;
}
string proc_id = Request.Params["proc_id"];
var proc = bll_task_proc.GetModel(proc_id);
DataService.Model.zhc_task_proc_material model = new DataService.Model.zhc_task_proc_material();
model.material_id = bll.GetNewId();
model.proc_id = proc_id;
model.taskId = proc.taskId;
model.name = name.Text.Trim();
model.type = int.Parse(type.SelectedValue);
model.url = url;
model.position = bll.GetPosition(proc_id);
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];
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))
{
//imgTopic.ImageUrl = "~" + filePath;
if (upload_type == "0")
{
td_pic.Visible = true;
td_video.Visible = false;
imgTopic.ImageUrl = "~" + filePath;
}
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 = "";
}
}
protected void type_SelectedIndexChanged(object sender, Telerik.Web.UI.DropDownListEventArgs e)
{
if (type.SelectedValue == "0") //图片
{
td_video.Visible = false;
td_pic.Visible = true;
}
else //视频
{
td_video.Visible = true;
td_pic.Visible = false;
}
}
}
}