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/AttributeAdapter.aspx.cs

154 lines
5.7 KiB
C#

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 System.Xml;
using System.Text;
using DSWeb.EntityDA;
using DSWeb.Models;
namespace DSWeb.FeeCodes
{
public partial class AttributeAdapter : System.Web.UI.Page
{
private string strMark;
private string strPos;
private int iPos = 0;
public string strIS = String.Empty;
private string strHandle;
private string strAttributeID;
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["strIS"] != null)
{
strIS = Request.QueryString["strIS"].ToString();
}
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString().Trim().ToLower();
}
if (Request.QueryString["attrid"] != null)
{
strAttributeID = Request.QueryString["attrid"].ToString().Trim();
}
if (strHandle != null)
{
if (strHandle == "attrinfo")
{
Response.Write(GetAttributeInfo());
}
}
else
{
XmlDocument docs = GetDoc();
Response.ContentType = "text/xml";
Response.Write(docs.OuterXml.ToString());
}
}
}
private string GetAttributeInfo()
{
AttributeCompanyDA attributeCompanyDA = new AttributeCompanyDA();
DataTable sourceTable;
string tempAttrSql = "";
if(strAttributeID != null)
{
tempAttrSql = " AND A.GID = '" + strAttributeID + "'";
}
string strSql = String.Format("SELECT A.GID,A.NAME,A.DESCRIPTION,A.DEFAULTVALUE,B.NAME AS TYPENAME,A.TYPEID from attribute as A INNER JOIN attribute_type as B ON A.TYPEID = B.GID WHERE 1 > 0 "
+ " AND ISNULL(A.ISDELETE,0) <> 1 AND ISNULL(B.ISDELETE,0) <> 1 {0} ORDER BY A.DESCRIPTION ASC", tempAttrSql);
sourceTable = attributeCompanyDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("attr:[");
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("\"name\":\"" + sourceTable.Rows[i][1].ToString() + "\",");
sourceBuilder.Append("\"desp\":\"" + sourceTable.Rows[i][2].ToString() + "\",");
sourceBuilder.Append("\"dval\":\"" + sourceTable.Rows[i][3].ToString() + "\",");
sourceBuilder.Append("\"type\":\"" + sourceTable.Rows[i][4].ToString() + "\",");
sourceBuilder.Append("\"typeid\":\"" + sourceTable.Rows[i][5].ToString() + "\"}");
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.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))
{
AttributeCompanyDA attributeCompanyDA = new AttributeCompanyDA();
string strSql = "SELECT GID,DESCRIPTION FROM attribute WHERE ISNULL(ISDELETE,0) <> 1 ORDER BY DESCRIPTION ASC ";
DataTable sourceTable = attributeCompanyDA.GetExcuteSql(strSql).Tables[0];
if (sourceTable.Rows.Count > 0)
{
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
string strName = sourceTable.Rows[i][1].ToString().Trim();
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", sourceTable.Rows[i][0].ToString().Trim(), strName);
}
}
}
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;
}
}
}