using System; using System.IO; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; 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 SuperMap.RealEstate.ExchangeData.Modules.CashRegisterControl; using SuperMap.RealEstate.HighWay.Storage.Business; using System.Drawing; using HZQR.Common; using NPOI.HSSF.UserModel; using System.Web; using System.Net; using System.Web.UI.HtmlControls; using ICSharpCode.SharpZipLib.Checksums; using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.GZip; using System.IO.Compression; namespace SuperMap.RealEstate.ExchangeData.Modules.WebConfig { public partial class Default : BasePage { protected string download = ""; protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) return; //初始化并加载列表 GridViewEx1.SelectingWithInit(ObjectDataSource1, GridPageEx1); //工具条按钮事件 GridViewEx1.SetOpenControl(ButtonNew); } #region 方法 -> 数据行绑定 //翻页事件 protected void GridPageEx1_CallBackPageChanged(object src, ClientSetEventArgs e) { GridViewEx1.Pagging(ObjectDataSource1, GridPageEx1); //设置UI变化 e.SetValue(GridViewEx1); } //查询SQL设置 protected void GridViewEx1_SelectMethodParameters(object sender, SelectMethodParametersArgs e) { if (!string.IsNullOrEmpty(TextBox_Search.Text)) e.AddOrParams(GridViewSearch1, TextBox_Search.Text); e.AddAndParams("MOBILEPAYCONFIG_TYPE", "1"); e.AddOrderByParams("SERVERPART_CODE", false); } protected void GridViewEx1_RowDataBound(object sender, GridViewRowEventArgs e) { int shopcount = 0; if (e.Row.RowType == DataControlRowType.DataRow) { string MOBILEPAYCONFIG_ID = GridViewEx1.DataKeys[e.Row.RowIndex].Values["MOBILEPAYCONFIG_ID"].ToEncrypt(); string _SERVERPART = GridViewEx1.DataKeys[e.Row.RowIndex].Values["SERVERPART_ID"].ToEncrypt(); string _SERVERPARTNAME = GridViewEx1.DataKeys[e.Row.RowIndex].Values["SERVERPART_NAME"].ToString(); LinkButton MoreInfo = (LinkButton)e.Row.FindControl("MoreInfo"); LinkButton PurchaseInfo = (LinkButton)e.Row.FindControl("PurchaseInfo"); MoreInfo.OnClientClick = GridViewEx1.GetOpenPopDialogClientScript("ConfigList.aspx?ID=" + _SERVERPART, 600, 500); PurchaseInfo.OnClientClick = GridViewEx1.GetOpenPopDialogClientScript("InfoPage.aspx?ID=" + MOBILEPAYCONFIG_ID, 800, 500); DataTable dt_select = new Business.MOBILEPAYCONFIG(this.Transaction).ExecuteDataTable( "SELECT SHOPCODE FROM HIGHWAY_EXCHANGE.T_MOBILEPAYCONFIG WHERE MOBILEPAYCONFIG_ID=" + MOBILEPAYCONFIG_ID.ToDecrypt()); if (dt_select.Rows.Count > 0 && !string.IsNullOrEmpty(dt_select.Rows[0][0].ToString())) { shopcount = dt_select.Rows[0][0].ToString().Length - dt_select.Rows[0][0].ToString().Replace(",", "").Length + 1; } else { shopcount = 0; } e.Row.Cells[4].Text = shopcount.ToString(); } } #endregion #region 方法 -> 绑定列表数据 //查询 protected void ButtonSearch_CallBackClick(object sender, ClientSetEventArgs e) { GridViewEx1.Selecting(ObjectDataSource1, GridPageEx1); //设置UI变化 e.SetValue(GridViewEx1); //e.SetValue(GridPageEx1); } #endregion #region 方法 -> 生成配置文件 protected void SubmitButton_CallBackClick(object sender, ClientSetEventArgs e) { string shopcode = ""; string businesscode = ""; string termcode = ""; CallBackButton _button = (CallBackButton)sender; GridViewRow _Row = (GridViewRow)_button.NamingContainer; string _Key_ID = GridViewEx1.DataKeys[_Row.RowIndex][0].ToString(); DataTable dt = new Business.CHECKCOMMODITY(this.Transaction).ExecuteDataTable( "SELECT * FROM HIGHWAY_EXCHANGE.T_MOBILEPAYCONFIG WHERE MOBILEPAYCONFIG_ID=" + _Key_ID + ""); DataTable dt_config = new Business.CHECKCOMMODITY(this.Transaction).ExecuteDataTable( "SELECT * FROM HIGHWAY_EXCHANGE.T_MOBILEPAYCONFIG WHERE SERVERPART_ID=" + dt.Rows[0][1] + " AND MOBILEPAYCONFIG_ID NOT IN (" + _Key_ID + ")"); if (string.IsNullOrEmpty(dt.Rows[0][9].ToString())) { e.ExcuteClientScript(GetAlertStr("请填写基本信息!", 3)); return; } else if (dt_config.Rows.Count == 0) { e.ExcuteClientScript(GetAlertStr("请填写配置信息!", 3)); return; } else { for (int i = 0; i < dt_config.Rows.Count; i++) { shopcode += dt_config.Rows[i][5].ToString() + ","; businesscode += dt_config.Rows[i][7].ToString() + ","; termcode += dt_config.Rows[i][8].ToString() + ","; } //如果不存在就创建file文件夹 if (Directory.Exists(Server.MapPath("../../Modules/WebConfig/" + dt.Rows[0][3] + "")) == false) { Directory.CreateDirectory(Server.MapPath("../../Modules/WebConfig/" + dt.Rows[0][3] + "")); } FileInfo myFile1 = new FileInfo(Server.MapPath("../../Modules/WebConfig/" + dt.Rows[0][3] + "") + "/Web.config"); StreamWriter sw = myFile1.CreateText(); #region 文本内容 sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine(""); #endregion sw.Close(); e.ExcuteClientScript(GetAlertStr("生成成功!", 3)); string info = PassportInfo.Name + "于" + DateTime.Now + "更新了配置文件。"; new Business.MOBILEPAYCONFIG(this.Transaction).ExecuteNonQuery( "UPDATE HIGHWAY_EXCHANGE.T_MOBILEPAYCONFIG SET MOBILEPAYCONFIGDESC = '" + info + "' WHERE MOBILEPAYCONFIG_ID=" + _Key_ID, null); GridViewEx1.Pagging(ObjectDataSource1, GridPageEx1); //设置UI变化 e.SetValue(GridViewEx1); } } #endregion #region 方法 -> 下载事件 protected void down_Click(object sender, EventArgs e) { bool ifsuccess = false; LinkButton _lb = (LinkButton)sender; GridViewRow _Row = (GridViewRow)_lb.NamingContainer; string _Key_ID = GridViewEx1.DataKeys[_Row.RowIndex][0].ToString(); Business.MOBILEPAYCONFIG _MOBILEPAYCONFIG = new Business.MOBILEPAYCONFIG(this.Transaction); _MOBILEPAYCONFIG.MOBILEPAYCONFIG_ID = int.Parse(_Key_ID); if (_MOBILEPAYCONFIG.Select()) { if (Directory.Exists(Server.MapPath("../../Modules/WebConfig/" + _MOBILEPAYCONFIG.SERVERPART_NAME + "")) == false) { Alert("请生成配置文件", 3); } else { try { string path = Request.MapPath("../../Modules/WebConfig/" + _MOBILEPAYCONFIG.SERVERPART_NAME + ""); ZipFile(path + "/Web.config", path + "/Web.zip"); Response.ContentType = "application/x-zip-compressed"; Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(_MOBILEPAYCONFIG.SERVERPART_NAME + ".zip")); string filename = Server.MapPath("../../Modules/WebConfig/" + _MOBILEPAYCONFIG.SERVERPART_NAME + "/Web.zip"); Response.TransmitFile(filename); ifsuccess = true; #region 下载方法2 //string[] files = System.IO.Directory.GetFiles(path); //获取所有文件名 //if (files.Length > 0) //{ // for (int i = 0; i < files.Length; i++) // { // string fileName = files[i].Substring(files[i].LastIndexOf("\\") + 1, // files[i].Length - files[i].LastIndexOf("\\") - 1);//客户端保存的文件名 // string filePath = files[i];//路径 // System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath); // string cerattime = fileInfo.CreationTime.ToString(); // if (fileInfo.Exists == true) // { // const long ChunkSize = 102400;//100K 每次读取文件,只读取100K,这样可以缓解服务器的压力 // byte[] buffer = new byte[ChunkSize]; // Response.Clear(); // System.IO.FileStream iStream = System.IO.File.OpenRead(filePath); // long dataLengthToRead = iStream.Length;//获取下载的文件总大小 // Response.ContentType = "application/octet-stream"; // Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(_MOBILEPAYCONFIG.SERVERPART_NAME + fileName)); // while (dataLengthToRead > 0 && Response.IsClientConnected) // { // int lengthRead = iStream.Read(buffer, 0, Convert.ToInt32(ChunkSize));//读取的大小 // Response.OutputStream.Write(buffer, 0, lengthRead); // Response.Flush(); // dataLengthToRead = dataLengthToRead - lengthRead; // } // Response.Close(); // } // else // { // Alert("下载失败,未找到工具!"); // } // } //} //else //{ // Alert("下载失败,未找到工具!"); //} #endregion } catch (Exception ex) { throw new Exception(ex.Message); } } } if (ifsuccess) { Response.Write(""); } } /// /// 压缩单个文件 /// /// 要进行压缩的文件名 /// 压缩后生成的压缩文件名 public static void ZipFile(string fileToZip, string zipedFile) { //如果文件没有找到,则报错 if (!File.Exists(fileToZip)) { throw new System.IO.FileNotFoundException("指定要压缩的文件: " + fileToZip + " 不存在!"); } using (FileStream fs = File.OpenRead(fileToZip)) { byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); fs.Close(); using (FileStream ZipFile = File.Create(zipedFile)) { using (ZipOutputStream ZipStream = new ZipOutputStream(ZipFile)) { string fileName = fileToZip.Substring(fileToZip.LastIndexOf("\\") + 1); ZipEntry ZipEntry = new ZipEntry(fileName); ZipStream.PutNextEntry(ZipEntry); ZipStream.SetLevel(5); ZipStream.Write(buffer, 0, buffer.Length); ZipStream.Finish(); ZipStream.Close(); } } } } #endregion } }