158 lines
5.2 KiB
C#
158 lines
5.2 KiB
C#
using BLL;
|
|
using Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web;
|
|
|
|
namespace FineUIPro.Web.HSSE.PostTraining
|
|
{
|
|
public partial class StandardDataIn : PageBase
|
|
{
|
|
#region 加载
|
|
|
|
|
|
/// <summary>
|
|
///加载页面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 导入
|
|
|
|
/// <summary>
|
|
/// 错误集合
|
|
/// </summary>
|
|
public static List<Model.ErrorInfo> errorList = new List<Model.ErrorInfo>();
|
|
|
|
/// <summary>
|
|
///导入
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnImport_Click(object sender, EventArgs e)
|
|
{
|
|
errorList.Clear();
|
|
var message = string.Empty;
|
|
errorInfos = string.Empty;
|
|
if (fuAttachUrl.HasFile == false)
|
|
{
|
|
ShowNotify("请选择Excel文件!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
|
|
var IsXls = Path.GetExtension(fuAttachUrl.FileName).Trim().ToLower();
|
|
if (IsXls != ".xlsx")
|
|
{
|
|
ShowNotify("只能选择Excel文件!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
if (!string.IsNullOrEmpty(errorInfos)) errorInfos = string.Empty;
|
|
var rootPath = Server.MapPath("~/");
|
|
var initFullPath = rootPath + initPath;
|
|
if (!Directory.Exists(initFullPath)) Directory.CreateDirectory(initFullPath);
|
|
//指定上传文件名称
|
|
hdFileName.Text = Funs.GetNewFileName() + IsXls;
|
|
//上传文件路径
|
|
var filePath = initFullPath + hdFileName.Text;
|
|
//文件上传服务器
|
|
fuAttachUrl.PostedFile.SaveAs(filePath);
|
|
//文件上传服务器后的名称
|
|
var fileName = rootPath + initPath + hdFileName.Text;
|
|
|
|
ResponeData responeData;
|
|
responeData = PostTrainingStandardService.ImportData(fuAttachUrl.FileName, fileName, this.CurrUser.LoginProjectId, this.CurrUser.UserId,ref errorList);
|
|
|
|
this.gvErrorInfo.DataSource = errorList;
|
|
this.gvErrorInfo.DataBind();
|
|
if (responeData.code == 1)
|
|
{
|
|
ShowNotify("数据导入成功!", MessageBoxIcon.Success);
|
|
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
|
}
|
|
else if(errorList.Any())
|
|
{
|
|
Alert alert = new Alert();
|
|
alert.Message = responeData.message;
|
|
alert.MessageBoxIcon = MessageBoxIcon.Error;
|
|
alert.Show();
|
|
}
|
|
else
|
|
{
|
|
Alert alert = new Alert();
|
|
alert.Message = responeData.message;
|
|
alert.MessageBoxIcon = MessageBoxIcon.Error;
|
|
alert.Show();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 定义项
|
|
|
|
/// <summary>
|
|
///上传预设的虚拟路径
|
|
/// </summary>
|
|
private readonly string initPath = Const.ExcelUrl; //"File\\Excel\\DataIn\\";
|
|
|
|
/// <summary>
|
|
///错误集合
|
|
/// </summary>
|
|
public static string errorInfos = string.Empty;
|
|
|
|
#endregion
|
|
|
|
#region 模板下载
|
|
|
|
/// <summary>
|
|
///模板下载
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnDownLoad_Click(object sender, EventArgs e)
|
|
{
|
|
PageContext.RegisterStartupScript(Confirm.GetShowReference("确定要下载模板吗?", string.Empty,
|
|
MessageBoxIcon.Question, PageManager1.GetCustomEventReference(false, "Confirm_OK"),
|
|
PageManager1.GetCustomEventReference("Confirm_Cancel")));
|
|
}
|
|
|
|
/// <summary>
|
|
///下载导入模板
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void PageManager1_CustomEvent(object sender, CustomEventArgs e)
|
|
{
|
|
if (e.EventArgument == "Confirm_OK")
|
|
{
|
|
var rootPath = Server.MapPath("~/");
|
|
var uploadfilepath = rootPath + Const.PostTrainingStandardTemplateUrl;
|
|
var filePath = Const.PostTrainingStandardTemplateUrl;
|
|
var fileName = Path.GetFileName(filePath);
|
|
var info = new FileInfo(uploadfilepath);
|
|
var fileSize = info.Length;
|
|
Response.ClearContent();
|
|
Response.AddHeader("Content-Disposition",
|
|
"attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8));
|
|
Response.ContentType = "excel/plain";
|
|
Response.ContentEncoding = Encoding.UTF8;
|
|
Response.AddHeader("Content-Length", fileSize.ToString().Trim());
|
|
Response.TransmitFile(uploadfilepath, 0, fileSize);
|
|
Response.End();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |