/// <summary>
/// Url字段值替换,无该字段则加入
/// </summary>
/// <param name="strRepSource">须要改动的源URL</param>
/// <param name="strRepField">字段,注意区分大写和小写。如:ID或Key37</param>
/// <param name="strNewValue">新值</param>
/// <returns>替换后新Url</returns>
public static string UrlReplace(string strRepSource, string strRepField, string strNewValue)
{
System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
bool bSwitch = false;
if (strRepSource.Contains("&" + strRepField + "="))
{
strRepField = "&" + strRepField + "=";
bSwitch = true;
}
else if (strRepSource.Contains("?" + strRepField + "="))
{
strRepField = "?" + strRepField + "=";
bSwitch = true;
}
if (bSwitch)
{
string[] strArray = strRepSource.Split(new string[] { strRepField }, 2, StringSplitOptions.RemoveEmptyEntries);
strBuilder.Append(strArray[0]);
strBuilder.Append(strRepField);
strBuilder.Append(strNewValue);
if (strArray.Length == 2 && strArray[1].Contains("&"))
{
string[] strAy = strArray[1].Split(new char[] { ‘&‘ }, 2, StringSplitOptions.RemoveEmptyEntries);
strBuilder.Append("&" + strAy[strAy.Length - 1]);
}
}
else
{
strBuilder.Append(strRepSource);
strBuilder.Append(‘&‘);
strBuilder.Append(strRepField);
strBuilder.Append(‘=‘);
strBuilder.Append(strNewValue);
}
return strBuilder.ToString();
}
/// <summary>
/// Url字段值替换。无该字段则加入
/// </summary>
/// <param name="strRepSource">须要改动的源URL</param>
/// <param name="strRepField">字段,注意区分大写和小写。如:ID或Key37</param>
/// <param name="iNewValue">新值</param>
/// <returns>替换后新Url</returns>
public static string UrlReplace(string strRepSource, string strRepField, int iNewValue)
{
return UrlReplace(strRepSource, strRepField, iNewValue.ToString());
}
/// <summary>
/// Url构造函数
/// </summary>
/// <param name="strUrl">原Url</param>
/// <param name="strIdField">实体ID字段</param>
/// <param name="iIdValue">ID值</param>
/// <param name="strJvalue">选择值。实现相应选择卡凹陷</param>
/// <returns>构造后的Url,包含Key37和Key58值的加入</returns>
public static string UrlStructure(string strUrl, string strIdField, string iIdValue, string strJvalue)
{
strUrl = UrlReplace(strUrl, strIdField, iIdValue);
strUrl = UrlReplace(strUrl, "Key37", iIdValue);
strUrl = UrlReplace(strUrl, "Key58", iIdValue);
if (!string.IsNullOrEmpty(strJvalue))
{
strUrl = UrlReplace(strUrl, "J", strJvalue);
}
return strUrl;
}
/// <summary>
/// 加入參数
/// </summary>
public static string AddParameters(string url, string k, string v)
{
if (!string.IsNullOrEmpty(k))
{
url = UrlReplace(url, k, v);
}
return url;
}
/// <summary>
/// Url构造函数
/// </summary>
/// <param name="strUrl">原Url</param>
/// <param name="strIdField">实体ID字段</param>
/// <param name="iIdValue">ID值</param>
/// <returns>构造后的Url。包含Key37和Key58值的加入</returns>
public static string UrlStructure(string strUrl, string strIdField, int iIdValue)
{
strUrl = UrlStructure(strUrl, strIdField, iIdValue.ToString(), string.Empty);
return strUrl;
}
/// <summary>
/// Url构造函数
/// </summary>
/// <param name="strUrl">原Url</param>
/// <param name="strIdField">实体ID字段</param>
/// <param name="iIdValue">ID值</param>
/// <returns>构造后的Url。包含Key37和Key58值的加入</returns>
public static string UrlStructure(string strUrl, string strIdField, string iIdValue)
{
strUrl = UrlStructure(strUrl, strIdField, iIdValue, string.Empty);
return strUrl;
}