161 lines
5.6 KiB
C#
161 lines
5.6 KiB
C#
using BLL;
|
|
using Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Web.UI.WebControls;
|
|
|
|
namespace FineUIPro.Web.Evaluation
|
|
{
|
|
public partial class EvaluationUpload : PageBase
|
|
{
|
|
#region 加载
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
hidFo.Text = Request["fo"];
|
|
Panel1.Title = "File Management(" + hidFo.Text + ")";
|
|
hidIsEvaluateType.Text = Request["evaluatetype"];
|
|
if (!string.IsNullOrEmpty(hidFo.Text))
|
|
{
|
|
BindGrid(hidFo.Text);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 绑定数据
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
public void BindGrid(string FoNo)
|
|
{
|
|
var fileManageList = new List<Model.FilesManagement>();
|
|
Expression<Func<Model.FilesManagement, bool>> express = PredicateExtensions.True<Model.FilesManagement>();
|
|
if (!string.IsNullOrEmpty(FoNo))
|
|
{
|
|
express = express.And(p => p.FO == FoNo.Trim());
|
|
}
|
|
fileManageList = Funs.DB.FilesManagement.Where(express).OrderByDescending(p => p.UploadDate).ToList();
|
|
Grid1.RecordCount = fileManageList.Count;
|
|
var table = this.GetPagedDataTable(Grid1, fileManageList);
|
|
Grid1.DataSource = table;
|
|
Grid1.DataBind();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|
{
|
|
Grid1.PageIndex = e.NewPageIndex;
|
|
BindGrid(hidFo.Text);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 排序
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
|
|
{
|
|
Grid1.SortDirection = e.SortDirection;
|
|
Grid1.SortField = e.SortField;
|
|
BindGrid(hidFo.Text);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 保存
|
|
/// <summary>
|
|
/// 保存
|
|
/// </summary>
|
|
protected void btnSubmit_Click(object sender, EventArgs e)
|
|
{
|
|
if (hidIsEvaluateType.Text == "1")
|
|
{
|
|
Alert.ShowInParent("You have already evaluated " + hidFo.Text + "!");
|
|
return;
|
|
}
|
|
|
|
Model.FilesManagement fileModel = new Model.FilesManagement();
|
|
if (foFile.HasFile)
|
|
{
|
|
string fileName = foFile.ShortFileName;
|
|
//文件预上传路径
|
|
string url = "File\\" + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
|
|
string path = Funs.RootPath + url;
|
|
|
|
//文件路径
|
|
string filePath = foFile.PostedFile.FileName;
|
|
if (!string.IsNullOrEmpty(filePath))
|
|
{
|
|
if (!Directory.Exists(path))
|
|
{
|
|
Directory.CreateDirectory(path);
|
|
}
|
|
string filePathUrl = path + fileName;
|
|
foFile.SaveAs(filePathUrl);
|
|
fileModel.FileName = fileName;
|
|
fileModel.FileType = ddlType.SelectedValue;
|
|
fileModel.FileLength = foFile.PostedFile.ContentLength.ToString();
|
|
fileModel.FileUrl = url + fileName;
|
|
}
|
|
|
|
}
|
|
|
|
fileModel.FileId = Guid.NewGuid().ToString();
|
|
fileModel.FO = hidFo.Text;
|
|
fileModel.UploadUser = CurrUser.UserName;
|
|
fileModel.UploadDate = DateTime.Now;
|
|
fileModel.Remark = txtRemark.Text.Trim();
|
|
Funs.DB.FilesManagement.InsertOnSubmit(fileModel);
|
|
Funs.DB.SubmitChanges();
|
|
|
|
Form2.Reset();
|
|
BindGrid(hidFo.Text);
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 列点击事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
|
|
{
|
|
if (hidIsEvaluateType.Text == "1")
|
|
{
|
|
Alert.ShowInParent("You have already evaluated " + hidFo.Text + "!");
|
|
return;
|
|
}
|
|
|
|
if (e.CommandName == "Delete")
|
|
{
|
|
var fileid = Grid1.DataKeys[e.RowIndex][0].ToString();
|
|
if (!string.IsNullOrEmpty(fileid))
|
|
{
|
|
var fileModel = Funs.DB.FilesManagement.FirstOrDefault(p => p.FileId == fileid);
|
|
if (fileModel.FileUrl != null)
|
|
{
|
|
//var filePath = Server.MapPath("~/") + fileModel.FileUrl.Replace(fileModel.FileName, "");
|
|
if (File.Exists(Server.MapPath("~/") + fileModel.FileUrl))
|
|
{
|
|
//File.Delete(Server.MapPath("~/") + fileModel.FileUrl);
|
|
Directory.Delete(Server.MapPath("~/") + fileModel.FileUrl.Replace(fileModel.FileName, ""), true);
|
|
}
|
|
}
|
|
Funs.DB.FilesManagement.DeleteOnSubmit(fileModel);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
BindGrid(hidFo.Text);
|
|
ShowNotify("Delete Successful!");
|
|
}
|
|
}
|
|
}
|
|
} |