170 lines
8.1 KiB
C#
170 lines
8.1 KiB
C#
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 SuperMap.RealEstate.Utility;
|
|
using Business = SuperMap.RealEstate.HighWay.Storage.Business;
|
|
|
|
namespace SuperMap.RealEstate.HighWay.Modules.ContractTemplated
|
|
{
|
|
public partial class Attachment : BasePage
|
|
{
|
|
public string _ModifyType;
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (IsPostBack) return;
|
|
|
|
if (Request["SearchType"] == "true")
|
|
{
|
|
_ModifyType = "0";
|
|
}
|
|
if (string.IsNullOrEmpty(Request["PRODEF_ID"]) || string.IsNullOrEmpty(Request["CONTRACT_TYPE"]))
|
|
{
|
|
Alert("请保存流程信息后上传合同模板!");
|
|
ClosePopDialog();
|
|
}
|
|
else
|
|
{
|
|
PRODEF_ID.Text = Request["PRODEF_ID"].ToDecrypt() + "," + Request["CONTRACT_TYPE"].ToDecrypt();
|
|
BindRepick();
|
|
}
|
|
}
|
|
|
|
private void BindRepick()
|
|
{
|
|
//绑定对应的控件
|
|
Repeater1.DataSource = (new Business.CONTRACTTEMPLATE(this.Transaction)).FillDataTable(
|
|
"WHERE PRODEF_ID = '" + Request["PRODEF_ID"].ToDecrypt() + "' AND CONTRACT_TYPE = " +
|
|
Request["CONTRACT_TYPE"].ToDecrypt() + " AND TEMPLATE_PATH IS NOT NULL");
|
|
Repeater1.DataBind();
|
|
|
|
}
|
|
|
|
public byte[] StreamToBytes(Stream stream)
|
|
{
|
|
byte[] bytes = new byte[stream.Length];
|
|
stream.Read(bytes, 0, bytes.Length);
|
|
// 设置当前流的位置为流的开始
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
return bytes;
|
|
}
|
|
|
|
protected void LinkButton_Click(object sender, EventArgs e)
|
|
{
|
|
LinkButton LinkButton = sender as LinkButton;
|
|
//下载内容
|
|
Business.CONTRACTTEMPLATE _CONTRACTTEMPLATE = new Business.CONTRACTTEMPLATE(this.Transaction);
|
|
_CONTRACTTEMPLATE.CONTRACTTEMPLATE_ID_Encrypt = LinkButton.Attributes["base-code"];
|
|
if (_CONTRACTTEMPLATE.Select())
|
|
{
|
|
System.IO.MemoryStream ms = new System.IO.MemoryStream();
|
|
|
|
//解决文件名乱码
|
|
string FileName = System.Web.HttpUtility.UrlEncode(!string.IsNullOrEmpty(_CONTRACTTEMPLATE.CONTRACTTEMPLATE_DESC) ?
|
|
_CONTRACTTEMPLATE.CONTRACTTEMPLATE_DESC : _CONTRACTTEMPLATE.TEMPLATE_PATH, System.Text.Encoding.UTF8);
|
|
|
|
string uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/ContractTemplate/") + "\\" +
|
|
((!string.IsNullOrEmpty(_CONTRACTTEMPLATE.CONTRACTTEMPLATE_DESC) && !string.IsNullOrEmpty(_CONTRACTTEMPLATE.TEMPLATE_PATH)) ?
|
|
_CONTRACTTEMPLATE.TEMPLATE_PATH + "\\" + _CONTRACTTEMPLATE.CONTRACTTEMPLATE_DESC : _CONTRACTTEMPLATE.TEMPLATE_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();
|
|
}
|
|
|
|
}
|
|
|
|
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["CONTRACTTEMPLATE_DESC"].ToString()) &&
|
|
!string.IsNullOrEmpty(_DataRowView["TEMPLATE_PATH"].ToString())) ? _DataRowView["CONTRACTTEMPLATE_DESC"].ToString() :
|
|
_DataRowView["TEMPLATE_NAME"].ToString();
|
|
LinkButton.Text = "<span><img src='/HighWay/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["CONTRACTTEMPLATE_ID"].ToEncrypt();
|
|
|
|
LinkButton DelButton = e.Item.FindControl("DelButton") as LinkButton;
|
|
if (Request["SearchType"] == "true")
|
|
{
|
|
DelButton.Visible = false;
|
|
}
|
|
else
|
|
{
|
|
DelButton.Text = "<span><img src='/HighWay/Resources/v1_0/Images/delete.png' /></span>";
|
|
DelButton.Attributes["base-code"] = _DataRowView["CONTRACTTEMPLATE_ID"].ToEncrypt();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void DelButton_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
LinkButton LinkButton = sender as LinkButton;
|
|
Business.CONTRACTTEMPLATE _CONTRACTTEMPLATE = new Business.CONTRACTTEMPLATE(Transaction);
|
|
_CONTRACTTEMPLATE.CONTRACTTEMPLATE_ID_Encrypt = LinkButton.Attributes["base-code"].ToString();
|
|
if (_CONTRACTTEMPLATE.Select())
|
|
{
|
|
//if (Directory.Exists(HttpContext.Current.Server.MapPath("~/UploadImageDir/ContractTemplate")) &&
|
|
// File.Exists(HttpContext.Current.Server.MapPath("~/UploadImageDir/ContractTemplate/") + "\\" +
|
|
// _CONTRACTTEMPLATE.TEMPLATE_PATH))
|
|
//{
|
|
// File.Delete(HttpContext.Current.Server.MapPath("~/UploadImageDir/ContractTemplate/") + "\\" +
|
|
// _CONTRACTTEMPLATE.TEMPLATE_PATH);
|
|
//}
|
|
if (!string.IsNullOrEmpty(_CONTRACTTEMPLATE.CONTRACTTEMPLATE_DESC) && !string.IsNullOrEmpty(_CONTRACTTEMPLATE.TEMPLATE_PATH))
|
|
{
|
|
if (Directory.Exists(HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/") +
|
|
_CONTRACTTEMPLATE.CONTRACTTEMPLATE_DESC))
|
|
{
|
|
Directory.Delete(HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/") +
|
|
_CONTRACTTEMPLATE.TEMPLATE_PATH, true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (Directory.Exists(HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile")) &&
|
|
File.Exists(HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/") +
|
|
_CONTRACTTEMPLATE.TEMPLATE_PATH))
|
|
{
|
|
File.Delete(HttpContext.Current.Server.MapPath("~/UploadImageDir/CompactFile/") +
|
|
_CONTRACTTEMPLATE.TEMPLATE_PATH);
|
|
}
|
|
}
|
|
_CONTRACTTEMPLATE.Delete();
|
|
}
|
|
BindRepick();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//回滚事务
|
|
Transaction.Rollback();
|
|
//记录日志
|
|
ErrorLogHelper.Write(ex);
|
|
}
|
|
}
|
|
|
|
protected void CallBackButton1_Click(object sender, EventArgs e)
|
|
{
|
|
BindRepick();
|
|
}
|
|
}
|
|
} |