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

422 lines
18 KiB
C#

2 years ago
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.Text;
using System.Xml;
using DSWeb.EntityDA;
using DSWeb.Models;
using System.Text.RegularExpressions;
namespace DSWeb.FeeCodes
{
public partial class OpSeaServices : System.Web.UI.Page
{
#region 私有成员
private string strHandle;
private string strCodeType;//请求返回字符串方式 json/xml
private string strMark;
private string strPos;
private int iPos = 0;
private string strUserID;
private string strCompanyID;//公司GID
private string strShowName;//用户显示名
private string strDeptName;//部门名称
private string strUserType;//用户类型 op-操作 sale-销售 doc-单证 cust-客服 finan-财务
private string strCheckClientShowName;//要查询的往来单位显示名称
private string strClientContactType;//委托单位的收、发货人和通知人信息 ship-发货人 cons-收货人 notify-通知人
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString();
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString().Trim().ToLower();
}
if(Request.QueryString["ctype"] != null)
{
strCodeType = Request.QueryString["ctype"].ToString().Trim().ToLower();
}
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["utype"] != null)
{
strUserType = Request.QueryString["utype"].ToString().Trim().ToLower();
}
if (Request.QueryString["checkname"] != null)
{
strCheckClientShowName = UnicodeToGB(Request.QueryString["checkname"].ToString());
}
if (Request.QueryString["contact"] != null)
{
strClientContactType = Request.QueryString["contact"].ToString().Trim().ToLower();
}
if (strHandle != null)
{
//市场来源信息
if (strHandle == "codesource")
{
if (strCodeType == "xml")
{
XmlDocument docs = GetDoc(GetCodeSource());
Response.ContentType = "text/xml";
Response.Write(docs.OuterXml.ToString());
}
}
//
if (strHandle == "deptinfo")
{
if (strCodeType == "xml")
{
XmlDocument docs = GetDoc(GetDeptInfo());
Response.ContentType = "text/xml";
Response.Write(docs.OuterXml.ToString());
}
}
if (strHandle == "user" && strUserType != null)
{
if (strCodeType == "xml")
{
XmlDocument docs = GetDoc(GetUserInfo(strUserType));
Response.ContentType = "text/xml";
Response.Write(docs.OuterXml.ToString());
}
}
if (strHandle == "clientcontact" && strUserType != null && strCheckClientShowName != null)
{
if (strCodeType == "xml")
{
XmlDocument docs = GetDoc(GetClientContact(strUserType, strCheckClientShowName));
Response.ContentType = "text/xml";
Response.Write(docs.OuterXml.ToString());
}
}
if (strHandle == "clientinfo" && strClientContactType != null)
{
if (strCodeType == "xml")
{
XmlDocument docs = GetDoc(GetClientInfo(strClientContactType, strCheckClientShowName));
Response.ContentType = "text/xml";
Response.Write(docs.OuterXml.ToString());
}
}
}
}
#region 获取市场来源信息
/// <summary>
/// 获取市场来源信息
/// </summary>
/// <returns></returns>
private string GetCodeSource()
{
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.Append("<?xml version=\"1.0\" ?>");
resultBuilder.AppendFormat("<complete{0}>", iPos == 0 ? string.Empty : " add=\"true\"");
if (!string.IsNullOrEmpty(strMark))
{
CodeSourceDA codeSourceDA = new CodeSourceDA();
DataTable sourceTable = new DataTable();
string strSql = String.Format(" SELECT * FROM code_source WHERE ISNULL(CORPID,'') = '{0}' OR ISNULL(CORPID,'') = '' ORDER BY SOURCENAME ASC ", strCompanyID);
sourceTable = codeSourceDA.GetExcuteSql(strSql).Tables[0];
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", sourceTable.Rows[i]["SOURCEID"].ToString().Trim(), sourceTable.Rows[i]["SOURCENAME"].ToString().Trim());
}
}
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", "", "");
resultBuilder.Append("</complete>");
return resultBuilder.ToString().Replace("&", "&amp;");
}
#endregion
private string GetDeptInfo()
{
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.Append("<?xml version=\"1.0\" ?>");
resultBuilder.AppendFormat("<complete{0}>", iPos == 0 ? string.Empty : " add=\"true\"");
if (!string.IsNullOrEmpty(strMark))
{
SysDeptDA sysDeptDA = new SysDeptDA();
DataTable sourceTable = new DataTable();
string strSql = String.Format(" SELECT * FROM sys_dept WHERE LINKID = '{0}' ORDER BY DEPTNO ASC ", strCompanyID);
sourceTable = sysDeptDA.GetExcuteSql(strSql).Tables[0];
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
string strOptionName = sourceTable.Rows[i]["DEPTNO"].ToString().Trim()+" | "+sourceTable.Rows[i]["DEPTNAME"].ToString().Trim();
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", sourceTable.Rows[i]["DEPTNO"].ToString().Trim(), strOptionName);
}
}
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", "", "");
resultBuilder.Append("</complete>");
return resultBuilder.ToString().Replace("&", "&amp;");
}
#region 通过所属职位类型获取用户信息
/// <summary>
/// 通过所属职位类型获取用户信息
/// </summary>
/// <param name="tempUserType">用户信息</param>
/// <returns>返回XML信息</returns>
private string GetUserInfo(string tempUserType)
{
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.Append("<?xml version=\"1.0\" ?>");
resultBuilder.AppendFormat("<complete{0}>", iPos == 0 ? string.Empty : " add=\"true\"");
if (!string.IsNullOrEmpty(strMark))
{
UserDA userDA = new UserDA();
DataTable sourceTable = new DataTable();
string strCondition = "";
switch (tempUserType)
{
case "op"://操作
strCondition = " AND B.VALUE = 'true' AND C.NAME = 'isOperator' ";
break;
case "sale"://销售(揽货人)
strCondition = " AND B.VALUE = 'true' AND C.NAME = 'isSaleMan' ";
break;
case "doc"://单证
strCondition = " AND B.VALUE = 'true' AND C.NAME = 'isDocument' ";
break;
case "cust"://客服
strCondition = " AND B.VALUE = 'true' AND C.NAME = 'isCustomsService' ";
break;
}
string strSql = String.Format(" SELECT D.CODENAME,D.SHOWNAME FROM (SELECT A.GID,A.CODENAME,A.SHOWNAME FROM [user] as A "
+ " INNER JOIN user_userattribute AS B ON A.GID = B.USERID INNER JOIN user_attribute AS C ON B.ATTRIBUTEID = C.GID "
+ " WHERE 1 > 0 " + strCondition + " ) AS D INNER JOIN user_company AS E ON D.GID = E.USERID"
+ " INNER JOIN company as F ON E.COMPANYID = F.GID WHERE F.GID = '{0}' ORDER BY D.CODENAME ASC ", strCompanyID);
sourceTable = userDA.GetExcuteSql(strSql).Tables[0];
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
string strOptionName = sourceTable.Rows[i]["CODENAME"].ToString().Trim() + " | " + sourceTable.Rows[i]["SHOWNAME"].ToString().Trim();
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", sourceTable.Rows[i]["SHOWNAME"].ToString().Trim(), strOptionName);
}
}
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", "", "");
resultBuilder.Append("</complete>");
return resultBuilder.ToString().Replace("&", "&amp;");
}
#endregion
#region 通过所属职位类型获取客户维护信息
/// <summary>
/// 通过所属职位类型获取客户维护信息
/// </summary>
/// <param name="tempUserType">用户信息</param>
/// <returns>返回XML信息</returns>
private string GetClientContact(string tempUserType,string tempClientName)
{
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.Append("<?xml version=\"1.0\" ?>");
resultBuilder.AppendFormat("<complete{0}>", iPos == 0 ? string.Empty : " add=\"true\"");
if (!string.IsNullOrEmpty(strMark))
{
UserDA userDA = new UserDA();
DataTable sourceTable = new DataTable();
string strCondition = "";
switch (tempUserType)
{
case "op"://操作
strCondition = " AND B.ISOPERATOR = 1 ";
break;
case "finan"://财务
strCondition = " AND B.ISFINANCIALSTAFF = 1 ";
break;
}
string strSql = String.Format(" SELECT B.CODENAME,B.SHOWNAME FROM info_client AS A INNER JOIN info_client_contact AS B ON A.GID = B.LINKID WHERE A.SHORTNAME = '{0}' " + strCondition
+ " ORDER BY B.CODENAME ASC ", tempClientName);
sourceTable = userDA.GetExcuteSql(strSql).Tables[0];
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
string strOptionName = "";
if (sourceTable.Rows[i]["CODENAME"].ToString().Trim() != "")
{
strOptionName = sourceTable.Rows[i]["CODENAME"].ToString().Trim() + " | " + sourceTable.Rows[i]["SHOWNAME"].ToString().Trim();
}
else
{
strOptionName = sourceTable.Rows[i]["SHOWNAME"].ToString().Trim();
}
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", sourceTable.Rows[i]["SHOWNAME"].ToString().Trim(), strOptionName);
}
}
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", "", "");
resultBuilder.Append("</complete>");
return resultBuilder.ToString().Replace("&", "&amp;");
}
#endregion
#region 获取委托单位的收、发货人和通知人信息
/// <summary>
/// 获取委托单位的收、发货人和通知人信息
/// </summary>
/// <param name="tempClientContactType">委托单位的收、发货人和通知人信息 ship-发货人 cons-收货人 notify-通知人</param>
/// <param name="tempCheckClientShowName">委托单位SHOWNAME</param>
/// <returns>返回XML</returns>
private string GetClientInfo(string tempClientContactType, string tempCheckClientShowName)
{
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.Append("<?xml version=\"1.0\" ?>");
resultBuilder.AppendFormat("<complete{0}>", iPos == 0 ? string.Empty : " add=\"true\"");
if (!string.IsNullOrEmpty(strMark))
{
CodeSourceDA codeSourceDA = new CodeSourceDA();
DataTable sourceTable = new DataTable();
string strCondition = "";
switch (tempClientContactType)
{
case "ship"://发货人
strCondition = " AND ISNULL(B.SHIPPERTYPE,0) = 2 ";
break;
case "cons"://收货人
strCondition = " AND ISNULL(B.SHIPPERTYPE,0) = 1 ";
break;
case "notify"://通知人
break;
}
string strSql = String.Format(" SELECT B.SHIPPERID,B.SHORTNAME FROM info_client AS A LEFT JOIN info_shipper AS B ON A.CODENAME = B.CODENAME "
+ " WHERE A.SHORTNAME = '{0}' AND A.ISSTOP = 0 " + strCondition + " ORDER BY SHIPPERID ASC ", tempCheckClientShowName);
sourceTable = codeSourceDA.GetExcuteSql(strSql).Tables[0];
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", sourceTable.Rows[i]["SHIPPERID"].ToString().Trim(), sourceTable.Rows[i]["SHIPPERID"].ToString().Trim() + " | "+sourceTable.Rows[i]["SHORTNAME"].ToString().Trim());
}
}
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", "", "");
resultBuilder.Append("</complete>");
return resultBuilder.ToString().Replace("&", "&amp;");
}
#endregion
public XmlDocument GetDoc(string tempXml)
{
XmlDocument xmldoc = new XmlDocument();
string content = tempXml;
try
{
xmldoc.LoadXml(content);
}
catch (Exception)
{
}
return xmldoc;
}
#region Unicode-GB Code转换
/// <summary>
/// Unicode-GB Code转换
/// </summary>
/// <param name="text">将Unicode编码字符转换成GB编码字符</param>
/// <returns>GB Code字符串</returns>
public string UnicodeToGB(string text)
{
UnicodeEncoding unicode = new UnicodeEncoding();
text = unicode.GetString(unicode.GetBytes(Regex.Unescape(text.Trim())));
return text;
}
/// <summary>
/// Unicode-GB Code转换
/// </summary>
/// <param name="text">将Unicode编码字符转换成GB编码字符</param>
/// <returns>GB Code字符串</returns>
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
}
}