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.CoreFrameWork; using SuperMap.RealEstate.ServiceModel; using SuperMap.RealEstate.Utility; using SuperMap.RealEstate.Web.UI; using SuperMap.RealEstate.Web.UI.WebControls; using SuperMap.RealEstate.Web.Utility; using Business = SuperMap.RealEstate.Finance.Storage.Business; namespace SuperMap.RealEstate.Finance.Modules.SearchFinanceProinst { public partial class ATTACHMENT1 : UserControl { protected override void OnInit(EventArgs e) { base.OnInit(e); } protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) return; } //在此加入界面的数据初始化(Page_Load之前),如DropDownList的数据源绑定等 public override void InitializeWebControl() { } //载入数据 public override bool LoadData() { PROINST_ID.Text = Request["PROINST_ID"].ToDecrypt(); //绑定对应的控件 BindRepick(); //如果是工作流组件请自行修改载入的逻辑,以下是功能模块的默认代码 //if (!String.IsNullOrEmpty(Request["ID"])) //{ // CurrObject.ATTACHMENT_ID_Encrypt = Request["ID"]; // return this.Select(); //} //默认返回值,工作流组件返回True,功能模块返回False。 return (WorkFlowPage != null); } //OnDataAction_XXXXX 有一个系列可用,在此加入界面的逻辑处理 //e.CancelDataAction 来处理是否取消该动作; //失败的原因可以用Page.Alert()传递到页面 public override void OnDataAction_BeforeSave(DataActionEventArgs e) { base.OnDataAction_BeforeSave(e); } private void BindRepick() { //绑定对应的控件 Repeater1.DataSource = (new Business.ATTACHMENT(Transaction)).ExecuteDataTable( "SELECT * FROM T_ATTACHMENT where ATTACHMENT_DESC IS NULL AND PROINST_ID = " + Request["PROINST_ID"].ToDecrypt()); Repeater1.DataBind(); DataTable _DataTable = (new Business.ATTACHMENT(Transaction)).ExecuteDataTable( "SELECT * FROM T_ATTACHMENT where ATTACHMENT_DESC IS NOT NULL AND PROINST_ID = " + Request["PROINST_ID"].ToDecrypt()); if (_DataTable.Rows.Count > 0) { _DataTable.DefaultView.RowFilter = "ATTACHMENT_DESC = '1000'"; DataTable SourceTable = _DataTable.DefaultView.ToTable(); if (SourceTable.Rows.Count > 0) { Fieldset1.Visible = true; Repeater2.DataSource = SourceTable.Copy(); Repeater2.DataBind(); } _DataTable.DefaultView.RowFilter = "ATTACHMENT_DESC = '2000'"; SourceTable = _DataTable.DefaultView.ToTable(); if (SourceTable.Rows.Count > 0) { Fieldset2.Visible = true; Repeater3.DataSource = SourceTable.Copy(); Repeater3.DataBind(); } _DataTable.DefaultView.RowFilter = "ATTACHMENT_DESC = '3000'"; SourceTable = _DataTable.DefaultView.ToTable(); if (SourceTable.Rows.Count > 0) { Fieldset3.Visible = true; Repeater4.DataSource = SourceTable.Copy(); Repeater4.DataBind(); } _DataTable.DefaultView.RowFilter = "ATTACHMENT_DESC = '4000'"; SourceTable = _DataTable.DefaultView.ToTable(); if (SourceTable.Rows.Count > 0) { Fieldset4.Visible = true; Repeater5.DataSource = SourceTable.Copy(); Repeater5.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.ATTACHMENT _ATTACHMENT = new Business.ATTACHMENT(Transaction); _ATTACHMENT.ATTACHMENT_ID_Encrypt = LinkButton.Attributes["base-code"]; if (_ATTACHMENT.Select()) { string uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/FINANCEPROINST/") + "\\" + ((!string.IsNullOrEmpty(_ATTACHMENT.PRESONNAME) && !string.IsNullOrEmpty(_ATTACHMENT.ATTACHMENT_DESC)) ? _ATTACHMENT.PRESONNAME + "\\" + _ATTACHMENT.ATTACHMENT_DESC : _ATTACHMENT.ATTACHMENT_NAME); string FileName = System.Web.HttpUtility.UrlEncode(!string.IsNullOrEmpty(_ATTACHMENT.ATTACHMENT_DESC) ? _ATTACHMENT.ATTACHMENT_DESC : _ATTACHMENT.ATTACHMENT_NAME, System.Text.Encoding.UTF8); System.IO.MemoryStream ms = new System.IO.MemoryStream(); 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["ATTACHMENT_DESC"].ToString()) && !string.IsNullOrEmpty(_DataRowView["PRESONNAME"].ToString())) ? _DataRowView["ATTACHMENT_DESC"].ToString() : _DataRowView["ATTACHMENT_NAME"].ToString(); LinkButton.Text = "" + (LinkButton.ToolTip.Length > 30 ? LinkButton.ToolTip.Substring(0, 25) + "..." : LinkButton.ToolTip) + ""; LinkButton.Attributes["base-code"] = _DataRowView["ATTACHMENT_ID"].ToEncrypt(); } } protected void DelButton_Click(object sender, EventArgs e) { try { LinkButton LinkButton = sender as LinkButton; new Business.ATTACHMENT(Transaction).Delete(int.Parse(LinkButton.Attributes["base-code"].ToDecrypt())); BindRepick(); } catch { } } protected void CallBackButton1_Click(object sender, EventArgs e) { BindRepick(); } public override bool Save(bool AutoBindData = true) { return true; } } }