220 lines
6.8 KiB
C#
220 lines
6.8 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;
|
|
using Telerik.Web.UI;
|
|
|
|
namespace VRS.Management.VSAT
|
|
{
|
|
public partial class ExamTheoryBase_Pic : BasePage
|
|
{
|
|
DataService.BLL.admin_log log = new DataService.BLL.admin_log();
|
|
DataService.BLL.pro_theory_base bll_theory_base = new DataService.BLL.pro_theory_base();
|
|
DataService.BLL.pro_file bll_file = new DataService.BLL.pro_file();
|
|
protected override void Page_Load(object sender, EventArgs e)
|
|
{
|
|
base.Page_Load(sender, e);
|
|
if (!IsPostBack)
|
|
{
|
|
hid_baseid.Value = Request.Params["Id"];
|
|
|
|
var model = bll_theory_base.GetModel(hid_baseid.Value);
|
|
if (null != model)
|
|
{
|
|
span_question.InnerHtml = model.question;
|
|
}
|
|
|
|
DataLoad();
|
|
}
|
|
}
|
|
|
|
public static readonly string answer = "answer";
|
|
|
|
private void DataLoad()
|
|
{
|
|
var theory_base_id = hid_baseid.Value;
|
|
var query = string.Format(" theory_base_id = '{0}' and out_id ='{1}' ", theory_base_id, answer);
|
|
var list = bll_file.GetModelList(query).OrderBy(s => s.create_time).ToList();
|
|
if (list.Count >= 3)
|
|
{
|
|
//hid_showpic.Value = "0";
|
|
//table_pic.Visible = false;
|
|
//panel.Visible = false;
|
|
btnAddItem.Visible = false;
|
|
btnUpload.Visible = false;
|
|
btnRemove.Visible = false;
|
|
RadAsyncUpload1.Enabled = false;
|
|
}
|
|
else
|
|
{
|
|
//hid_showpic.Value = "1";
|
|
//table_pic.Visible = true;
|
|
//panel.Visible = true;
|
|
|
|
btnAddItem.Visible = true;
|
|
btnUpload.Visible = true;
|
|
btnRemove.Visible = true;
|
|
RadAsyncUpload1.Enabled = true;
|
|
}
|
|
dataList.DataSource = list;
|
|
dataList.Rebind();
|
|
}
|
|
|
|
protected void GridList_PageIndexChanged(object sender, GridPageChangedEventArgs e)
|
|
{
|
|
DataLoad();
|
|
}
|
|
|
|
protected void GridList_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
|
|
{
|
|
DataLoad();
|
|
}
|
|
|
|
protected void GridList_SortCommand(object sender, GridSortCommandEventArgs e)
|
|
{
|
|
DataLoad();
|
|
}
|
|
|
|
protected void GrdList_DeleteCommand(object sender, GridCommandEventArgs e)
|
|
{
|
|
/*
|
|
string Id = (e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"].ToString();
|
|
bll.Delete(Id);
|
|
DataLoad();
|
|
*/
|
|
DataLoad();
|
|
}
|
|
protected void btnSure_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(imgTopic.ImageUrl))
|
|
{
|
|
RadAjaxManager1.Alert("图片不能为空!");
|
|
return;
|
|
}
|
|
var theory_base_id = hid_baseid.Value;
|
|
var query = string.Format(" theory_base_id = '{0}' and out_id ='{1}' ", theory_base_id, answer);
|
|
var list = bll_file.GetModelList(query).OrderBy(s => s.create_time).ToList();
|
|
if (list.Count >= 3)
|
|
{
|
|
imgTopic.ImageUrl = "";
|
|
RadAjaxManager1.Alert("图片不能超过三张!");
|
|
return;
|
|
}
|
|
|
|
DataService.Model.pro_file model = new DataService.Model.pro_file();
|
|
model.file_id = BasePage.GetId();
|
|
model.out_id = answer;
|
|
model.theory_base_id = hid_baseid.Value;
|
|
model.file_url = imgTopic.ImageUrl;
|
|
model.create_time = DateTime.Now;
|
|
if (bll_file.Add(model))
|
|
{
|
|
imgTopic.ImageUrl = "";
|
|
|
|
DataLoad();
|
|
}
|
|
else
|
|
{
|
|
RadAjaxManager1.Alert("添加失败!");
|
|
}
|
|
}
|
|
|
|
public void upload_click(RadAsyncUpload Upload1, Image img)
|
|
{
|
|
if (Upload1.UploadedFiles.Count < 1)
|
|
{
|
|
RadAjaxManager1.Alert("未选择图片!");
|
|
return;
|
|
}
|
|
|
|
var uploadFile = Upload1.UploadedFiles[0];
|
|
var extension = uploadFile.GetExtension();
|
|
var extension_list = new string[] { ".jpg", ".png", ".jpeg", ".bmp", ".gif" };
|
|
if (!extension_list.Contains(extension))
|
|
{
|
|
RadAjaxManager1.Alert("文件格式错误!");
|
|
return;
|
|
}
|
|
|
|
if (BasePage.SaveFileWithDir(uploadFile, Context, "answer", out string filePath))
|
|
{
|
|
img.ImageUrl = "~" + filePath;
|
|
}
|
|
else
|
|
{
|
|
RadAjaxManager1.Alert("上传失败!");
|
|
}
|
|
}
|
|
|
|
protected void btnUpload_Click(object sender, EventArgs e)
|
|
{
|
|
upload_click(RadAsyncUpload1, imgTopic);
|
|
}
|
|
protected void btnUpload_Click2(object sender, EventArgs e)
|
|
{
|
|
upload_click(RadAsyncUpload2, imgTopic2);
|
|
}
|
|
protected void btnUpload_Click3(object sender, EventArgs e)
|
|
{
|
|
upload_click(RadAsyncUpload3, imgTopic3);
|
|
}
|
|
|
|
|
|
|
|
public void Remove_Click(Image img)
|
|
{
|
|
if (!string.IsNullOrEmpty(img.ImageUrl))
|
|
{
|
|
string path = Server.MapPath(img.ImageUrl);
|
|
if (File.Exists(path))
|
|
{
|
|
File.Delete(path);
|
|
}
|
|
img.ImageUrl = "";
|
|
}
|
|
}
|
|
|
|
protected void btnRemove_Click(object sender, EventArgs e)
|
|
{
|
|
Remove_Click(imgTopic);
|
|
|
|
}
|
|
protected void btnRemove_Click2(object sender, EventArgs e)
|
|
{
|
|
Remove_Click(imgTopic2);
|
|
}
|
|
|
|
protected void btnRemove_Click3(object sender, EventArgs e)
|
|
{
|
|
Remove_Click(imgTopic3);
|
|
}
|
|
|
|
protected void dataList_ItemDataBound(object sender, GridItemEventArgs e)
|
|
{
|
|
if (e.Item is GridDataItem)
|
|
{
|
|
GridDataItem item = e.Item as GridDataItem;
|
|
Label lbno = e.Item.FindControl("lbno") as Label;
|
|
lbno.Text = (e.Item.ItemIndex + 1).ToString();
|
|
}
|
|
}
|
|
|
|
protected void btnDelete_Click(object sender, EventArgs e)
|
|
{
|
|
var id = IdInput.Value;
|
|
var model = bll_file.GetModel(id);
|
|
if (bll_file.Delete(id))
|
|
{
|
|
string path = Server.MapPath(model.file_url);
|
|
if (File.Exists(path))
|
|
{
|
|
File.Delete(path);
|
|
}
|
|
DataLoad();
|
|
}
|
|
}
|
|
}
|
|
} |