2024-09-18 10:48:34 +08:00
|
|
|
|
using BLL;
|
|
|
|
|
|
using Model;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
|
|
|
|
|
|
namespace FineUIPro.Web.CLGL
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class InPlanMasterDataIn : 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>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
protected void btnImport_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
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;
|
2025-10-10 14:33:21 +08:00
|
|
|
|
responeData = TwInOutplanmasterService.ImportData(fuAttachUrl.FileName, fileName, this.CurrUser.LoginProjectId, this.CurrUser.PersonId);
|
2024-09-18 10:48:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (responeData.code == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowNotify("数据导入成功!", MessageBoxIcon.Success);
|
|
|
|
|
|
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Alert alert = new Alert();
|
|
|
|
|
|
alert.Message = responeData.message;
|
|
|
|
|
|
alert.MessageBoxIcon = MessageBoxIcon.Error;
|
2025-10-10 14:33:21 +08:00
|
|
|
|
alert.Show();
|
|
|
|
|
|
}
|
2024-09-18 10:48:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#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.Tw_InPlanMasteTemplateUrl;
|
|
|
|
|
|
var filePath = Const.Tw_InPlanMasteTemplateUrl;
|
|
|
|
|
|
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
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|