215 lines
10 KiB
C#
215 lines
10 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;
|
|
using SuperMap.RealEstate.CoreFrameWork;
|
|
using HZQR.Common.Common;
|
|
using SuperMap.RealEstate.CoreFrameWork.Dictionary.Business;
|
|
|
|
namespace SuperMap.RealEstate.HighWay.Modules.ContractTemplated
|
|
{
|
|
public partial class AttachmentDownL : BasePage
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (IsPostBack) return;
|
|
|
|
if (!string.IsNullOrEmpty(Request["PRODEF_ID"]) && !string.IsNullOrEmpty(Request["CONTRACT_TYPE"]))
|
|
{
|
|
divType.Attributes["style"] = "display:none;";
|
|
BindRepick();
|
|
}
|
|
else
|
|
{
|
|
string _ProvinceCode = "";
|
|
foreach (FieldEnum _FieldEnum in (new FieldEnum(this.Transaction)).FillCollection(
|
|
"where FieldEnum_Value in('" + Request["BASEVALUE"].ToDecrypt() + "')"))
|
|
{
|
|
Storage.Business.SERVERPART _SERVERPART = new Storage.Business.SERVERPART(this.Transaction);
|
|
_SERVERPART.AddSearchParameter("FIELDENUM_ID", _FieldEnum.FieldEnum_ID);
|
|
if (_SERVERPART.Search())
|
|
{
|
|
_ProvinceCode = Storage.Business.CommonHelper.GetProvinceCode(_SERVERPART.PROVINCE_CODE, Transaction);
|
|
}
|
|
}
|
|
|
|
CONTRACT_TYPE.Items.Clear();
|
|
if (Request["PRODEF_NAME"].ToDecrypt().Contains("油"))
|
|
{
|
|
DictionaryHelper.BindingDropDownList("COMPACT_TYPE_SY", CONTRACT_TYPE.Items, this.Transaction);
|
|
}
|
|
else if (Request["BASEVALUE"].ToDecrypt() == "310010")
|
|
{
|
|
DictionaryHelper.BindingDropDownList("COMPACT_TYPE_ZX", CONTRACT_TYPE.Items, this.Transaction);
|
|
}
|
|
else
|
|
{
|
|
switch (_ProvinceCode)
|
|
{
|
|
case "420000":
|
|
CommonHelper.BindingDropDownList("COMPACT_CHARACTER", CONTRACT_TYPE.Items, "", "", true, Transaction, 1);
|
|
break;
|
|
case "451200":
|
|
case "520000":
|
|
case "620000":
|
|
case "630000":
|
|
CommonHelper.BindingDropDownList("COMPACT_CHARACTER", CONTRACT_TYPE.Items,
|
|
"", _ProvinceCode.Substring(0, 2) + "%", true, Transaction, 6);
|
|
break;
|
|
default:
|
|
DictionaryHelper.BindingDropDownList("COMPACT_CHARACTER", CONTRACT_TYPE.Items, this.Transaction);
|
|
break;
|
|
}
|
|
}
|
|
BindRepick();
|
|
}
|
|
}
|
|
|
|
private void BindRepick()
|
|
{
|
|
if (!string.IsNullOrEmpty(Request["CONTRACT_TYPE"]))
|
|
{
|
|
//绑定对应的控件
|
|
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");
|
|
}
|
|
else
|
|
{
|
|
Repeater1.DataSource = (new Business.CONTRACTTEMPLATE(this.Transaction)).FillDataTable(
|
|
"WHERE PRODEF_ID = '" + Request["PRODEF_ID"].ToDecrypt() + "' AND CONTRACT_TYPE = " +
|
|
CONTRACT_TYPE.SelectedValue + " 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;
|
|
//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();
|
|
}
|
|
|
|
protected void CONTRACT_TYPE_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
BindRepick();
|
|
}
|
|
}
|
|
} |