2023-08-25
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
using BLL;
|
||||
using Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
namespace FineUIPro.Web.PHTGL.ContractCompile
|
||||
{
|
||||
public partial class ContractTrackIn : PageBase
|
||||
{
|
||||
#region 加载
|
||||
|
||||
public string ContractId
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)ViewState["ContractId"];
|
||||
|
||||
}
|
||||
set
|
||||
{
|
||||
ViewState["ContractId"] = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 加载页面
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
ContractId = Request.Params["ContractId"];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#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 = new ResponeData();
|
||||
responeData = PHTGL_ContractTrackService.ImportData(fileName, ContractId, this.CurrUser.LoginProjectId);
|
||||
|
||||
|
||||
if (responeData.code == 1)
|
||||
{
|
||||
ShowNotify("数据导入成功!", MessageBoxIcon.Success);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowNotify(responeData.message, MessageBoxIcon.Error);
|
||||
|
||||
|
||||
}
|
||||
|
||||
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
||||
}
|
||||
|
||||
#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.TemContractTrackTemplateUrl;
|
||||
var filePath = Const.TemContractTrackTemplateUrl;
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user