307 lines
16 KiB
C#
307 lines
16 KiB
C#
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<Business.MOBILEPAYCONFIG>(ObjectDataSource1, GridPageEx1);
|
||
//工具条按钮事件
|
||
GridViewEx1.SetOpenControl(ButtonNew);
|
||
}
|
||
|
||
#region 方法 -> 数据行绑定
|
||
//翻页事件
|
||
protected void GridPageEx1_CallBackPageChanged(object src, ClientSetEventArgs e)
|
||
{
|
||
GridViewEx1.Pagging<Business.MOBILEPAYCONFIG>(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<Business.MOBILEPAYCONFIG>(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("<?xml version=\"1.0\"?>");
|
||
sw.WriteLine("<configuration>");
|
||
sw.WriteLine(" <appSettings>");
|
||
sw.WriteLine(" <add key=\"ShopCode\" value=\"" + shopcode.TrimEnd(',') + "\"/>");
|
||
sw.WriteLine(" <add key=\"Business_Code\" value=\"" + businesscode.TrimEnd(',') + "\"/>");
|
||
sw.WriteLine(" <add key=\"term_Code\" value=\"" + termcode.TrimEnd(',') + "\"/>");
|
||
sw.WriteLine(" <add key=\"connectstring\" value=\"" + dt.Rows[0][9] + "\"/>");
|
||
sw.WriteLine(" <add key=\"connectstringbld\" value=\"" + dt.Rows[0][10] + "\"/>");
|
||
sw.WriteLine(" <add key=\"OracleHelperString\" value=\"" + dt.Rows[0][11] + "\"/>");
|
||
sw.WriteLine(" <add key=\"OracleHelperStringsp\" value=\"" + dt.Rows[0][12] + "\"/>");
|
||
sw.WriteLine(" <add key=\"OracleHelperStringps\" value=\"" + dt.Rows[0][13] + "\"/>");
|
||
sw.WriteLine(" </appSettings>");
|
||
sw.WriteLine(" <connectionStrings/>");
|
||
sw.WriteLine(" <system.web>");
|
||
sw.WriteLine(" <compilation debug=\"true\" targetFramework=\"4.0\"/>");
|
||
sw.WriteLine(" <!--");
|
||
sw.WriteLine(" 通过 <authentication> 节,可配置 ");
|
||
sw.WriteLine(" ASP.NET 用于识别进入用户的 ");
|
||
sw.WriteLine(" 安全身份验证模式。");
|
||
sw.WriteLine(" -->");
|
||
sw.WriteLine(" <authentication mode=\"Windows\"/>");
|
||
sw.WriteLine(" <!--");
|
||
sw.WriteLine(" 通过 <customErrors> 节,可以配置");
|
||
sw.WriteLine(" 在执行请求的过程中出现未处理的错误时要执行 ");
|
||
sw.WriteLine(" 的操作。具体而言,");
|
||
sw.WriteLine(" 开发人员通过该节可配置要显示的 html 错误页,");
|
||
sw.WriteLine(" 以代替错误堆栈跟踪。");
|
||
sw.WriteLine("");
|
||
sw.WriteLine(" <customErrors mode=\"RemoteOnly\" defaultRedirect=\"GenericErrorPage.htm\"");
|
||
sw.WriteLine(" <error statusCode=\"403\" redirect=\"NoAccess.htm\" />");
|
||
sw.WriteLine(" <error statusCode=\"404\" redirect=\"FileNotFound.htm\" />");
|
||
sw.WriteLine(" </customErrors>");
|
||
sw.WriteLine(" -->");
|
||
sw.WriteLine(" <pages controlRenderingCompatibilityVersion=\"4.0\" clientIDMode=\"AutoID\"/>");
|
||
sw.WriteLine(" </system.web>");
|
||
sw.WriteLine("</configuration>");
|
||
#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<Business.MOBILEPAYCONFIG>(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("<script>alert('删除成功!')</script>");
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 压缩单个文件
|
||
/// </summary>
|
||
/// <param name="fileToZip">要进行压缩的文件名</param>
|
||
/// <param name="zipedFile">压缩后生成的压缩文件名</param>
|
||
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
|
||
}
|
||
} |