187 lines
8.2 KiB
C#
187 lines
8.2 KiB
C#
using SuperMap.RealEstate.Web.UI;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Web;
|
||
using System.Web.UI;
|
||
using System.Web.UI.WebControls;
|
||
using Running = SuperMap.RealEstate.Personnel.Running;
|
||
|
||
namespace SuperMap.RealEstate.Personnel.Compents.Attachment
|
||
{
|
||
public partial class ATTACHMENT : UserControl<Running.Business.ATTACHMENT>
|
||
{
|
||
public string _ModifyType;
|
||
Running.Business.PERSONNELPROINST _PERSONNELPROINST = null;
|
||
#region 方法 -> 页面加载
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (IsPostBack) return;
|
||
|
||
if (ModifyType == ModifyTypeEnum.ReadOnly || ModifyType == ModifyTypeEnum.ReadOnlyVisible)
|
||
{
|
||
_ModifyType = "0";
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 页面加载前初始化
|
||
protected override void OnInit(EventArgs e)
|
||
{
|
||
Common.PageHelper.CreateHeaderStyle(Page);
|
||
_PERSONNELPROINST = Running.Business.PERSONNELPROINST.CreateInstance(Page);
|
||
//隐藏打印受理单按钮
|
||
this.ButtonVisible = false;
|
||
base.OnInit(e);
|
||
}
|
||
#endregion
|
||
|
||
#region 载入数据
|
||
public override bool LoadData()
|
||
{
|
||
PROINST_ID.Text = _PERSONNELPROINST.PROINST_ID.ToEncrypt();
|
||
PERSONNELPROINST_ID.Text = _PERSONNELPROINST.PERSONNELPROINST_ID.ToEncrypt();
|
||
STAFF_ID.Text = Page.PassportInfo.ID.ToEncrypt();
|
||
//绑定对应的控件
|
||
BindRepick();
|
||
|
||
|
||
//如果是工作流组件请自行修改载入的逻辑,以下是功能模块的默认代码
|
||
if (!String.IsNullOrEmpty(Request["ID"]))
|
||
{
|
||
CurrObject.ATTACHMENT_ID_Encrypt = Request["ID"];
|
||
return this.Select();
|
||
}
|
||
//默认返回值,工作流组件返回True,功能模块返回False。
|
||
return (WorkFlowPage != null);
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 绑定附件
|
||
private void BindRepick()
|
||
{
|
||
//绑定对应的控件
|
||
Repeater1.DataSource = (new Running.Business.ATTACHMENT(Transaction)).ExecuteDataTable(
|
||
"SELECT * FROM T_ATTACHMENT WHERE RELATION_TABLE='T_PERSONNELPROINST' AND RELATION_ID = " + this._PERSONNELPROINST.PERSONNELPROINST_ID);
|
||
Repeater1.DataBind();
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 下载附件
|
||
protected void LinkButton_Click(object sender, EventArgs e)
|
||
{
|
||
LinkButton LinkButton = sender as LinkButton;
|
||
//下载内容
|
||
Running.Business.ATTACHMENT _ATTACHMENT = new Running.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();
|
||
|
||
LinkButton DelButton = e.Item.FindControl("DelButton") as LinkButton;
|
||
if (Request["SearchType"] == "true")
|
||
{
|
||
DelButton.Visible = false;
|
||
}
|
||
else
|
||
{
|
||
DelButton.Text = "<span><img src='/Personnel/Resources/v1_0/Images/delete.png' /></span>";
|
||
DelButton.Attributes["base-code"] = _DataRowView["ATTACHMENT_ID"].ToEncrypt();
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 删除附件
|
||
protected void DelButton_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
LinkButton LinkButton = sender as LinkButton;
|
||
Running.Business.ATTACHMENT _ATTACHMENT = new Running.Business.ATTACHMENT(Transaction);
|
||
_ATTACHMENT.ATTACHMENT_ID_Encrypt = LinkButton.Attributes["base-code"];
|
||
if (_ATTACHMENT.Select())
|
||
{
|
||
if (!string.IsNullOrEmpty(_ATTACHMENT.ATTACHMENT_DESC) && !string.IsNullOrEmpty(_ATTACHMENT.ATTACHMENT_PATH))
|
||
{
|
||
if (Directory.Exists(HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/") +
|
||
_ATTACHMENT.ATTACHMENT_DESC))
|
||
{
|
||
Directory.Delete(HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/") +
|
||
_ATTACHMENT.ATTACHMENT_PATH, true);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (Directory.Exists(HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile")) &&
|
||
File.Exists(HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/") +
|
||
_ATTACHMENT.ATTACHMENT_PATH))
|
||
{
|
||
File.Delete(HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/") +
|
||
_ATTACHMENT.ATTACHMENT_PATH);
|
||
}
|
||
}
|
||
_ATTACHMENT.Delete();
|
||
}
|
||
BindRepick();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
//回滚事务
|
||
Transaction.Rollback();
|
||
//记录日志
|
||
// ErrorLogHelper.Write(ex);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 附件刷新
|
||
protected void CallBackButton1_Click(object sender, EventArgs e)
|
||
{
|
||
BindRepick();
|
||
}
|
||
#endregion
|
||
}
|
||
} |