2025-03-27 15:05:14 +08:00

88 lines
4.2 KiB
C#

using SuperMap.RealEstate.Web.UI;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business = SuperMap.RealEstate.Personnel.Storage.Business;
namespace Personnel.WebSite.Modules.Employ
{
public partial class EMPLOYAttachment : SuperMap.RealEstate.Web.UI.PageValid
{
#region ->
protected void Page_Load(object sender, EventArgs e)
{
//绑定对应的控件
BindRepick();
}
#endregion
#region ->
private void BindRepick()
{
//绑定对应的控件
Repeater1.DataSource = (new Business.ATTACHMENT(Transaction)).ExecuteDataTable(
"SELECT * FROM PERSONNEL_STORAGE.T_ATTACHMENT WHERE RELATION_TABLE='T_PERSONNELPROINST' AND RELATION_ID = " + Request["RELATION_ID"].ToDecrypt());
Repeater1.DataBind();
}
#endregion
#region ->
protected void LinkButton_Click(object sender, EventArgs e)
{
LinkButton LinkButton = sender as LinkButton;
//下载内容
Business.ATTACHMENT _ATTACHMENT = new Business.ATTACHMENT(this.Transaction);
_ATTACHMENT.ATTACHMENT_ID_Encrypt = LinkButton.Attributes["base-code"];
if (_ATTACHMENT.Select())
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
//解决文件名乱码
string FileName = System.Web.HttpUtility.UrlEncode(!string.IsNullOrEmpty(_ATTACHMENT.ATTACHMENT_DESC) ?
_ATTACHMENT.ATTACHMENT_DESC : _ATTACHMENT.ATTACHMENT_PATH, System.Text.Encoding.UTF8);
string uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/") + "\\" +
((!string.IsNullOrEmpty(_ATTACHMENT.ATTACHMENT_DESC) && !string.IsNullOrEmpty(_ATTACHMENT.ATTACHMENT_PATH)) ?
_ATTACHMENT.ATTACHMENT_PATH : _ATTACHMENT.ATTACHMENT_PATH);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");//设置输出流为简体中文
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=" +
FileName, DateTime.Now.ToString("yyyyMMddHHmmssfff")));
HttpContext.Current.Response.BinaryWrite(System.IO.File.ReadAllBytes(uploadPath));
HttpContext.Current.Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
HttpContext.Current.Response.End();
ms.Close();
ms.Dispose();
}
}
#endregion
#region ->
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Item ||
e.Item.ItemType == System.Web.UI.WebControls.ListItemType.AlternatingItem ||
e.Item.ItemType == System.Web.UI.WebControls.ListItemType.SelectedItem)
{
DataRowView _DataRowView = (DataRowView)e.Item.DataItem;
LinkButton LinkButton = e.Item.FindControl("LinkButton") as LinkButton;
LinkButton.ToolTip = (!string.IsNullOrEmpty(_DataRowView["ATTACHMENT_DESC"].ToString()) &&
!string.IsNullOrEmpty(_DataRowView["ATTACHMENT_PATH"].ToString())) ? _DataRowView["ATTACHMENT_DESC"].ToString() :
_DataRowView["ATTACHMENT_PATH"].ToString();
LinkButton.Text = "<span><img src='/Personnel/Resources/v1_0/Images/4950_old-versions.png' />" +
(LinkButton.ToolTip.Length > 30 ? LinkButton.ToolTip.Substring(0, 25) + "..." : LinkButton.ToolTip) + "</span>";
LinkButton.Attributes["base-code"] = _DataRowView["ATTACHMENT_ID"].ToEncrypt();
}
}
#endregion
}
}