using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DSWeb.EntityDA;
using System.Xml;
using System.Text;
using System.Text.RegularExpressions;
namespace DSWeb.FeeCodes
{
public partial class FeeCodeService : System.Web.UI.Page
{
private string strMark;
private string strPos;
private int iPos = 0;
private string strHandle;
private string strFeeName;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string strPost = Request.Url.ToString();
if (Request.QueryString["mask"] != null)
{
strMark = Request.QueryString["mask"].ToString();
}
if (Request.QueryString["pos"] != null)
{
strPos = Request.QueryString["pos"].ToString();
iPos = int.Parse(strPos);
}
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString();
}
if (Request.QueryString["feename"] != null)
{
UnicodeEncoding unicode = new UnicodeEncoding();
if (Request.QueryString["feename"].ToString().Trim().IndexOf("/") >= 0)
{
strFeeName = Request.QueryString["feename"].ToString().Trim();
}
else
{
strFeeName = UnicodeToGB(unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["feename"].ToString()))));
}
}
if (Request.QueryString["isbeing"] != null)
{
string strBeing = Request.QueryString["isbeing"].ToString();
T_ALL_DA T_ALL_DA = new T_ALL_DA();
strBeing = T_ALL_DA.GetBeingCodeFee(strBeing);
Response.Write(strBeing.Trim());
return;
}
if (strHandle != null)
{
if (strHandle == "feecode")
{ //返回code_fee费用名称JSON字符串
Response.Write(GetFeeNameJson());
}
else if (strHandle == "getcurrency")
{ //通过费用名称获取费用代码表(code_fee)币别汇率信息
Response.Write(GetFeeCodeCurrencyJson(strFeeName));
}
else if (strHandle == "all")
{
XmlDocument docs = GetDoc();
Response.ContentType = "text/xml";
Response.Write(docs.OuterXml.ToString());
}
}
else
{
XmlDocument docs = GetDoc();
Response.ContentType = "text/xml";
Response.Write(docs.OuterXml.ToString());
}
}
}
public string BuildXML()
{
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.Append("");
resultBuilder.AppendFormat("", iPos == 0 ? string.Empty : " add=\"true\"");
if (!string.IsNullOrEmpty(strMark))
{
if (strHandle == "all")
{
resultBuilder.AppendFormat("", "0", "ALL | 全部");
}
DataTable feeCodeTable = new DataTable();
FeeCodeDA feeCodeDA = new FeeCodeDA();
feeCodeTable = feeCodeDA.GetExcuteSql("SELECT ISNULL(FEECODE,'')+' | '+ISNULL(Name,'') AS FULLNAME,FEECODE,name FROM code_fee order by name desc").Tables[0];
if (feeCodeTable.Rows.Count > 0)
{
for (int i = 0; i < feeCodeTable.Rows.Count; i++)
{
resultBuilder.AppendFormat("", feeCodeTable.Rows[i]["name"].ToString(), feeCodeTable.Rows[i]["FULLNAME"].ToString());
}
}
}
resultBuilder.Append("");
return resultBuilder.ToString().Replace("&", "&");
}
public XmlDocument GetDoc()
{
XmlDocument xmldoc = new XmlDocument();
string content = BuildXML();
try
{
xmldoc.LoadXml(content);
}
catch (Exception)
{
}
return xmldoc;
}
#region 返回code_fee费用名称JSON字符串
///
/// 返回code_fee费用名称JSON字符串
/// code_fee费用名称设置
///
/// 返回code_fee费用名称JSON字符串
public string GetFeeNameJson()
{
FeeCodeDA feeCodeDA = new FeeCodeDA();
DataTable sourceTable = new DataTable();
string strSql = "SELECT GID,ISNULL(FEECODE,'')+' '+ISNULL(Name,'') AS FullName,Name FROM code_fee ORDER BY FEECODE ASC";
if (Cache["feecodes"] != null)
{
sourceTable = (DataTable)Cache["feecodes"];
}
else
{
sourceTable = feeCodeDA.GetExcuteSql(strSql).Tables[0];
Cache.Insert("feecodes", sourceTable);
}
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("feecode:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
if (i == 0)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
}
else
{
sourceBuilder.Append(",{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
}
sourceBuilder.Append("\"code\":\"" + sourceTable.Rows[i][1].ToString() + "\",");
sourceBuilder.Append("\"name\":\"" + sourceTable.Rows[i][2].ToString() + "\"}");
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 通过费用名称获取费用代码表(code_fee)币别汇率信息
///
/// 通过费用名称获取费用代码表(code_fee)币别汇率信息
///
///
/// 返回汇率信息
private string GetFeeCodeCurrencyJson(string tempFeeCodeName)
{
FeeCodeDA feeCodeDA = new FeeCodeDA();
DataTable sourceTable;
string strSql = String.Format(" SELECT GID,ISNULL(FEECODE,'') as FEECODE,ISNULL(Name,'') AS NAME,DEFAULTCURR,ISSEA,ISAIR,DEFAULTUNIT,DEFAULTDEBIT,DEFAULTCREDIT FROM code_fee WHERE NAME = '{0}'",tempFeeCodeName);
sourceTable = feeCodeDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("feecode:[");
if (sourceTable.Rows.Count > 0)
{
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
if (i == 0)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
}
else
{
sourceBuilder.Append(",{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
}
sourceBuilder.Append("\"code\":\"" + sourceTable.Rows[i][1].ToString() + "\",");
sourceBuilder.Append("\"name\":\"" + sourceTable.Rows[i][2].ToString() + "\",");
sourceBuilder.Append("\"cur\":\"" + sourceTable.Rows[i][3].ToString() + "\",");
sourceBuilder.Append("\"issea\":" + (sourceTable.Rows[i][4].ToString().ToLower().Equals("true") ? 1 : 0) + ",");
sourceBuilder.Append("\"isair\":\"" + (sourceTable.Rows[i][5].ToString().ToLower().Equals("true") ? 1 : 0) + "\",");
sourceBuilder.Append("\"unit\":\"" + sourceTable.Rows[i][6].ToString() + "\",");
sourceBuilder.Append("\"debit\":\"" + sourceTable.Rows[i][7].ToString() + "\",");
sourceBuilder.Append("\"credit\":\"" + sourceTable.Rows[i][8].ToString() + "\"");
sourceBuilder.Append("}");
}
}
else
{
sourceBuilder.Append("{id:\"\",");
sourceBuilder.Append("\"code\":\"\",");
sourceBuilder.Append("\"name\":\"\",");
sourceBuilder.Append("\"cur\":\"\",");
sourceBuilder.Append("\"issea\":-1,");
sourceBuilder.Append("\"isair\":-1,");
sourceBuilder.Append("\"unit\":0,");
sourceBuilder.Append("\"debit\":0,");
sourceBuilder.Append("\"credit\":0");
sourceBuilder.Append("}");
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region Unicode-GB Code转换
///
/// Unicode-GB Code转换
///
/// 将Unicode编码字符转换成GB编码字符
/// GB Code字符串
public string UnicodeToGB(string text)
{
UnicodeEncoding unicode = new UnicodeEncoding();
text = unicode.GetString(unicode.GetBytes(Regex.Unescape(text.Trim())));
return text;
}
///
/// Unicode-GB Code转换
///
/// 将Unicode编码字符转换成GB编码字符
/// GB Code字符串
public string UnicodeToGB_Old(string text)
{
MatchCollection mc = Regex.Matches(text, "([\\w]+)|(\\\\u([\\w]{4}))");
if (mc != null && mc.Count > 0)
{
StringBuilder sb = new StringBuilder();
foreach (Match m2 in mc)
{
string v = m2.Value;
if (v.IndexOf("\\") >= 0)
{
string word = v.Substring(2);
byte[] codes = new byte[2];
int code = Convert.ToInt32(word.Substring(0, 2), 16);
int code2 = Convert.ToInt32(word.Substring(2), 16);
codes[0] = (byte)code2;
codes[1] = (byte)code;
sb.Append(Encoding.Unicode.GetString(codes));
}
else
{
sb.Append(v);
}
}
return sb.ToString();
}
else
{
return text;
}
}
#endregion
}
}