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.

204 lines
7.0 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BP.DA;
using BP.Difference;
using BP.En;
namespace BP.Difference
{
/// <summary>
/// 获得IP
/// </summary>
public static class Glo
{
public static string DealExp(string exp, Hashtable ht)
{
if (exp == null)
exp = string.Empty;
exp = exp.Replace("~", "'");
exp = exp.Replace("/#", "+"); //为什么?
exp = exp.Replace("/$", "-"); //为什么?
if (exp.Contains("@WebUser.No"))
exp = exp.Replace("@WebUser.No", BP.Web.WebUser.No);
if (exp.Contains("@WebUser.Name"))
exp = exp.Replace("@WebUser.Name", BP.Web.WebUser.Name);
if (exp.Contains("@WebUser.FK_DeptName"))
exp = exp.Replace("@WebUser.FK_DeptName", BP.Web.WebUser.DeptName);
if (exp.Contains("@WebUser.FK_Dept"))
exp = exp.Replace("@WebUser.FK_Dept", BP.Web.WebUser.DeptNo);
if (exp.Contains("@") == true && ht != null)
{
foreach (string key in ht.Keys)
{
//值为空或者null不替换
if (ht[key] == null || ht[key].Equals("") == true)
continue;
if (exp.Contains("@" + key))
exp = exp.Replace("@" + key, ht[key].ToString());
//不包含@则返回SQL语句
if (exp.Contains("@") == false)
break;
}
}
if (exp.Contains("@") && BP.Difference.SystemConfig.isBSsystem == true)
{
/*如果是bs*/
foreach (string key in HttpContextHelper.RequestParamKeys)
{
if (string.IsNullOrEmpty(key))
continue;
exp = exp.Replace("@" + key, HttpContextHelper.RequestParams(key));
}
}
//if (exp.Contains("@") == true)
// throw new Exception("@外键类型SQL错误," + exp + "部分查询条件没有被替换.");
return exp;
}
/// <summary>
/// 表达式替换
/// </summary>
/// <param name="exp"></param>
/// <param name="en"></param>
/// <returns></returns>
public static string DealExp(string exp, Entity en, string errInfo = "")
{
//替换字符
exp = exp.Replace("~~", "\"");
exp = exp.Replace("~", "'");
if (exp.Contains("@") == false)
return exp;
//首先替换加; 的。
exp = exp.Replace("@WebUser.No;", BP.Web.WebUser.No);
exp = exp.Replace("@WebUser.Name;", BP.Web.WebUser.Name);
exp = exp.Replace("@WebUser.FK_DeptName;", BP.Web.WebUser.DeptName);
exp = exp.Replace("@WebUser.FK_Dept;", BP.Web.WebUser.DeptNo);
// 替换没有 ; 的 .
exp = exp.Replace("@WebUser.No", BP.Web.WebUser.No);
exp = exp.Replace("@WebUser.Name", BP.Web.WebUser.Name);
exp = exp.Replace("@WebUser.FK_DeptName", BP.Web.WebUser.DeptName);
exp = exp.Replace("@WebUser.FK_Dept", BP.Web.WebUser.DeptNo);
exp = exp.Replace("@WebUser.OrgNo", BP.Web.WebUser.OrgNo);
exp = exp.Replace("@RDT", DataType.CurrentDateTime);
if (exp.Contains("@") == false)
return exp;
//增加对新规则的支持. @MyField; 格式.
if (en != null)
{
Attrs attrs = en.EnMap.Attrs;
BP.En.Row row = en.Row;
//特殊判断.
if (row.ContainsKey("OID") == true)
exp = exp.Replace("@WorkID", row["OID"].ToString());
if (exp.Contains("@") == false)
return exp;
bool isHaveFenHao = exp.Contains(';');
foreach (string key in row.Keys)
{
//值为空或者null不替换
if (row[key] == null)
continue;
if (exp.Contains("@" + key + ";"))
{
//先替换有单引号的.
exp = exp.Replace("'@" + key + ";'", "'" + row[key].ToString() + "'");
//在更新没有单引号的.
exp = exp.Replace("@" + key + ";", row[key].ToString());
}
if (exp.Contains("@" + key))
{
//先替换有单引号的.
exp = exp.Replace("'@" + key + "'", "'" + row[key].ToString() + "'");
//在更新没有单引号的.
exp = exp.Replace("@" + key, row[key].ToString());
}
//不包含@则返回SQL语句
if (exp.Contains("@") == false)
return exp;
}
}
if (exp.Contains("@") && BP.Difference.SystemConfig.isBSsystem == true)
{
/*如果是bs*/
foreach (string key in HttpContextHelper.RequestParamKeys)
{
if (string.IsNullOrEmpty(key))
continue;
exp = exp.Replace("@" + key, HttpContextHelper.RequestParams(key));
}
}
exp = exp.Replace("~", "'");
return exp;
}
public static string DealSQLStringEnumFormat(string cfgString)
{
//把这个string,转化SQL. @tuanyuan=团员@dangyuan=党员
AtPara ap = new AtPara(cfgString);
string sql = "";
foreach (string item in ap.HisHT.Keys)
{
sql += " SELECT '" + item + "' as No, '" + ap.GetValStrByKey(item) + "' as Name FROM Port_Emp WHERE No = 'admin' UNION ";
}
sql = sql.Substring(0, sql.Length - 6);
return sql;
}
/// <summary>
/// 获得ID地址
/// </summary>
public static string GetIP
{
get
{
return HttpContextHelper.Request.ServerVariables["REMOTE_ADDR"].ToString();
}
}
public static string RequestParas
{
get
{
string urlExt = "";
string rawUrl = System.Web.HttpContext.Current.Request.RawUrl;
rawUrl = "&" + rawUrl.Substring(rawUrl.IndexOf('?') + 1);
string[] paras = rawUrl.Split('&');
foreach (string para in paras)
{
if (para == null
|| para.Equals("")
|| para.Contains("=") == false)
continue;
urlExt += "&" + para;
}
return urlExt;
}
}
}
}