You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/FeeCodes/CurrencyAdapter.aspx.cs

138 lines
4.8 KiB
C#

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
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 System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Xml;
using DSWeb.Models;
using DSWeb.EntityDA;
namespace DSWeb.FeeCodes
{
public partial class CurrencyAdapter : System.Web.UI.Page
{
private string strMark;
private string strPos;
private int iPos = 0;
private string strHandle;//值drate表示获取默认币别汇率
protected void Page_Load(object sender, EventArgs e)
{
string strPost = Request.Url.ToString();
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString().ToLower();
}
if (strHandle != null)
{
if (strHandle == "drate")
{ //返回币别code_currency汇率JSON字符串
Response.Write(GetCurrencyRateJson());
}
}
else
{
if (Request.QueryString["mask"] != null)
{
strMark = Request.QueryString["mask"].ToString();
}
if (Request.QueryString["pos"] != null)
{
strPos = Request.QueryString["pos"].ToString();
iPos = int.Parse(strPos);
}
XmlDocument docs = GetDoc();
Response.ContentType = "text/xml";
Response.Write(docs.OuterXml.ToString());
}
}
public string BuildXML()
{
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.Append("<?xml version=\"1.0\" ?>");
resultBuilder.AppendFormat("<complete{0}>", iPos == 0 ? string.Empty : " add=\"true\"");
if (!string.IsNullOrEmpty(strMark))
{
CurrencyDA currencyDA = new CurrencyDA();
IList<CurrencyEntity> currencyEntities = currencyDA.GetAllCurrency();
foreach (CurrencyEntity currencyEntity in currencyEntities)
{
if (currencyEntity.GID.ToString().Trim() != "" || currencyEntity.CodeName.ToString().Trim() != "")
{
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", currencyEntity.GID, currencyEntity.CodeName);
}
}
}
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", "", "");
resultBuilder.Append("</complete>");
return resultBuilder.ToString().Replace("&", "&amp;");
}
public XmlDocument GetDoc()
{
XmlDocument xmldoc = new XmlDocument();
string content = BuildXML();
try
{
xmldoc.LoadXml(content);
}
catch (Exception)
{
}
return xmldoc;
}
#region 返回币别code_currency汇率JSON字符串
/// <summary>
/// 返回币别code_currency汇率JSON字符串
/// </summary>
/// <returns>返回币别code_currency汇率JSON字符串</returns>
public string GetCurrencyRateJson()
{
CurrencyDA currencyDA = new CurrencyDA();
DataTable sourceTable;
string strSql = "SELECT GID, CODENAME, NAME, DESCRIPTION, DEFAULTRATE FROM code_currency";
sourceTable = currencyDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("drate:[");
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("\"desc\":\"" + sourceTable.Rows[i][3].ToString() + "\",");
sourceBuilder.Append("\"drate\":\"" + sourceTable.Rows[i][4].ToString() + "\"}");
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
}
}