169 lines
5.2 KiB
C#
169 lines
5.2 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Web;
|
||
using System.Web.UI;
|
||
using System.Web.UI.WebControls;
|
||
using System.IO;
|
||
|
||
namespace VRS.Management
|
||
{
|
||
public partial class Loop_Add : BasePage
|
||
{
|
||
DataService.BLL.admin_log log = new DataService.BLL.admin_log();
|
||
DataService.BLL.pro_loop bll = new DataService.BLL.pro_loop();
|
||
|
||
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 model = new DataService.Model.pro_loop();
|
||
var type_value = type.SelectedValue;
|
||
if (type_value == "图片" && string.IsNullOrEmpty(imgTopic.ImageUrl))
|
||
{
|
||
RadAjaxManager1.Alert("图片内容不能为空!");
|
||
return;
|
||
}
|
||
if (type_value == "视频" && string.IsNullOrEmpty(video.Src))
|
||
{
|
||
RadAjaxManager1.Alert("视频内容不能为空!");
|
||
return;
|
||
}
|
||
|
||
if (type_value == "图片")
|
||
{
|
||
model.pic_url = imgTopic.ImageUrl;
|
||
}
|
||
else if (type_value == "视频")
|
||
{
|
||
model.video_url = video.Src;
|
||
}
|
||
|
||
model.id = BasePage.GetId();
|
||
model.type =type.SelectedValue;
|
||
model.head = name.Text.Trim();
|
||
model.dsc = dsc.Text.Trim();
|
||
|
||
if (bll.Add(model))
|
||
{
|
||
log.write_log("添加素材成功。" + type.SelectedText + "名称:" + name.Text.Trim() + ",素材ID:" + model.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 == "图片") //图片
|
||
{
|
||
var arrray = Util.ConfigInfo.list_pic_type;
|
||
var extension = uploadFile.GetExtension();
|
||
if (!arrray.Contains(extension))
|
||
{
|
||
RadAjaxManager1.Alert("请上传图片!");
|
||
return;
|
||
}
|
||
}
|
||
else if (upload_type == "视频") //视频,.mp4,.avi,.dat,.3gp,.mov,.rmvb
|
||
{
|
||
var arrray = Util.ConfigInfo.list_video_type;
|
||
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 == "图片")
|
||
{
|
||
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 == "图片") //图片
|
||
{
|
||
td_video.Visible = false;
|
||
td_pic.Visible = true;
|
||
}
|
||
else //视频
|
||
{
|
||
td_video.Visible = true;
|
||
td_pic.Visible = false;
|
||
}
|
||
}
|
||
}
|
||
} |