<!--sqlservice start-->
<object id="BusinessUnitSQLService" type="HraWeb.BusinessUnitSQLService, HraWeb">
</object>
<object id="CountPartySQLService" type="HraWeb.CountPartySQLService, HraWeb">
</object>
<object id="InStrumentSQLService" type="HraWeb.InStrumentSQLService, HraWeb">
</object>
<object id="LegalEntitySQLService" type="HraWeb.LegalEntitySQLService, HraWeb">
</object>
<object id="PortfolioSQLService" type="HraWeb.PortfolioSQLService, HraWeb">
</object>
<object id="RskFactorSQLService" type="HraWeb.RskFactorSQLService, HraWeb">
</object>
<object id="TraderSQLService" type="HraWeb.TraderSQLService, HraWeb">
</object>
<!--sqlservice end-->
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bll;
using Common;
using Framework;
using HraWeb.Common;
using HraWeb.ReportEg.To38Validate.ValidateGenericInterface;
using WebApp.Common;
using Contract.Domain;
using System.Collections;
namespace HraWeb
{
public interface IFilterGroupSQL
{
string SetGroupJoinSQL(String sql,string RiskBookId);
}
public class FilterGroupChain
{
public IList<IFilterGroupSQL> filterChains = new List<IFilterGroupSQL>();
public FilterGroupChain AddFilterGroupChain(IFilterGroupSQL filter)
{
filterChains.Add(filter);
return this;
}
public string SetGroupJoinSQL(string RiskBookId)
{
string s = string.Empty;
foreach (var f in filterChains)
{
s = f.SetGroupJoinSQL(s,RiskBookId);
}
s = Regex.Replace(s, @"(\w*)(UNION\s)$", ReplaceMethod);
return s;
}
private string ReplaceMethod(Match match)
{
string s = "";
s = match.Groups[1].ToString();
return s;
}
}
public class PortfolioSQLService : IFilterGroupSQL
{
public string SetGroupJoinSQL(string sql,string RiskBookId)
{
//注意这是一个空格
string space = " ";
sql += string.Format(@"select DISTINCT {0},
'PORTFOLIO',
PORTFOLIO_ID,
1
from rsk_delta_position
where PORTFOLIO_ID <> 0 UNION"+space, (RiskBookId));
return sql;
}
}
public class InStrumentSQLService : IFilterGroupSQL
{
public string SetGroupJoinSQL(string sql, string RiskBookId)
{
//注意这是一个空格
string space = " ";
sql += string.Format(@"select DISTINCT {0},
'INSTRUMENT_TYPE',
inst_type_id,
1
from rsk_delta_position
where inst_type_id <> 0 UNION" + space, RiskBookId, space);
return sql;
}
}
public class CountPartySQLService : IFilterGroupSQL
{
public string SetGroupJoinSQL(string sql, string RiskBookId)
{
//注意这是一个空格
string space = " ";
sql += string.Format(@"select DISTINCT {0},
'COUNTERPARTY',
COUNTERPARTY_ID,
1
from rsk_delta_position
where COUNTERPARTY_ID <> 0 UNION" + space, RiskBookId, space);
return sql;
}
}
public class BusinessUnitSQLService : IFilterGroupSQL
{
public string SetGroupJoinSQL(string sql, string RiskBookId)
{
//注意这是一个空格
string space = " ";
sql += string.Format(@"select DISTINCT {0},
'BUSINESS_UNIT',
INT_BUS_UNIT_ID,
1
from rsk_delta_position
where INT_BUS_UNIT_ID <> 0 UNION" + space, RiskBookId, space);
return sql;
}
}
public class LegalEntitySQLService : IFilterGroupSQL
{
public string SetGroupJoinSQL(string sql, string RiskBookId)
{
//注意这是一个空格
string space = " ";
sql += string.Format(@"select DISTINCT {0},
'LEGAL_ENTITY',
INT_LEGAL_ENTITY_ID,
1
from rsk_delta_position
where INT_LEGAL_ENTITY_ID <> 0 UNION" + space, RiskBookId, space);
return sql;
}
}
public class RskFactorSQLService : IFilterGroupSQL
{
public string SetGroupJoinSQL(string sql, string RiskBookId)
{
//注意这是一个空格
string space = " ";
sql += string.Format(@"select DISTINCT {0},
'RISK_FACTOR',
RISK_FACTOR_ID,
1
from rsk_delta_position
where RISK_FACTOR_ID <> 0 UNION" + space, RiskBookId, space);
return sql;
}
}
public class TraderSQLService : IFilterGroupSQL
{
public string SetGroupJoinSQL(string sql, string RiskBookId)
{
//注意这是一个空格
string space = " ";
sql += string.Format(@"select DISTINCT {0},
'TRADER',
TRADER_id,
1
from rsk_delta_position
where TRADER_id <> 0 UNION" + space, RiskBookId, space);
return sql;
}
}
public partial class RskBookFilterManage : JQEntityManage<Contract.Domain.RskBookFilter>
{
protected override void Page_Load(object sender, EventArgs e)
{
//给基类服务接口复制,可不付
//base.svc = Psvc;
switch (Request["_method"])
{
case "SetCheckRowIds":
SetCheckRowIds();
break;
case "IsCheckAllSelection":
IsCheckAllSelection();
break;
case "UnCheckAllSelection":
UnCheckAllSelection();
break;
}
if (!IsPostBack)
{
FillRiskBookFilter();
}
base.Page_Load(sender,e);
}
private void UnCheckAllSelection()
{
ArrayList array = new ArrayList();
string RiskBookId = Request["param_RiskBookId"];
string FilteredGroup = Request["param_FilteredGroup"];
QueryInfo info = new QueryInfo("RskBookFilter");
if (!string.IsNullOrEmpty(RiskBookId))
{
info.AddParam("RiskBookId", RiskBookId);
}
if (!string.IsNullOrEmpty(FilteredGroup))
{
info.AddParam("FilteredGroup", FilteredGroup);
}
info = Dao.FindByQueryInfo(info);
IList list = info.List;
foreach (var r in list)
{
RskBookFilter rb = r as RskBookFilter;
rb.SelectedFlag = 0;
rb.State.MarkDirty();
array.Add(rb);
}
Dao.SaveOrUpdateAll(array);
}
private void IsCheckAllSelection()
{
ArrayList array = new ArrayList();
string RiskBookId = Request["param_RiskBookId"];
string FilteredGroup = Request["param_FilteredGroup"];
QueryInfo info = new QueryInfo("RskBookFilter");
if (!string.IsNullOrEmpty(RiskBookId))
{
info.AddParam("RiskBookId", RiskBookId);
}
if (!string.IsNullOrEmpty(FilteredGroup))
{
info.AddParam("FilteredGroup", FilteredGroup);
}
info = Dao.FindByQueryInfo(info);
IList list = info.List;
foreach (var r in list)
{
RskBookFilter rb = r as RskBookFilter;
rb.SelectedFlag = 1;
rb.State.MarkDirty();
array.Add(rb);
}
Dao.SaveOrUpdateAll(array);
}
private void SetCheckRowIds()
{
string CheckRowIds = Request["RowidList"];
if (!string.IsNullOrEmpty(CheckRowIds))
{
ArrayList checkList=new ArrayList();
List<CheckSeletedStruc> list= Newtonsoft.Json.JsonConvert.DeserializeObject<List<CheckSeletedStruc>>(CheckRowIds);
foreach (CheckSeletedStruc check in list)
{
RskBookFilter r = Dao.FindById(typeof (RskBookFilter).Name, check.Id) as RskBookFilter;
r.SelectedFlag = check.SelectedFlag.ToLower() == "yes" ? 1 : 0;
r.State.MarkDirty();
checkList.Add(r);
}
Dao.SaveOrUpdateAll(checkList);
}
}
public Dictionary<string, string> dic = new Dictionary<string, string>();
public override void ChangeList(QueryInfo infoList)
{
IList rskList = Dao.FindList(new QueryInfo("RskBook"));
foreach (RskBook r in rskList)
{
dic.Add(r.Id, r.RiskBookName);
}
foreach (var b in infoList.List)
{
RskBookFilter r = b as RskBookFilter;
r.RiskBookName = dic[r.RiskBookId.ToString()];
r.RiskGroupItemName = getRiskGroupItemName(r.FilteredGroup,r.FilteredValue);
}
}
public string getRiskGroupItemName(string FilteredGroup, string FilteredValue)
{
QueryInfo info=new QueryInfo();
string tbName = string.Empty;
tbName = FilteredGroup;
info.CustomSQL = string.Format("select {0}_NAME from BAS_{1} where {2}_ID={3}", tbName, tbName,
tbName, FilteredValue);
string s = string.Empty;
try
{
if (FilteredGroup == "RISK_FACTOR")
{
info.CustomSQL =
string.Format("select risk_factor_name from RSK_FACTOR where risk_factor_id={0}",
FilteredValue);
s = Dao.ExcuteDataSet(info).Tables[0].Rows[0]["risk_factor_name"].ToString();
return s;
}
if (FilteredGroup == "TRADER")
{
info.CustomSQL =
string.Format("select user_name from BAS_BUSINESS_PERSON where BUSINESS_PERSON_ID={0}",
FilteredValue);
s = Dao.ExcuteDataSet(info).Tables[0].Rows[0]["USER_NAME"].ToString();
}
else
{
s = Dao.ExcuteDataSet(info).Tables[0].Rows[0][FilteredGroup + "_NAME"].ToString();
}
}
catch (Exception)
{
;
}
return s;
return null;
}
public void FillRiskBookFilter()
{
IList RiskBookFilterList = Dao.FindList(new QueryInfo("RskBookFilter"));
if (RiskBookFilterList == null || RiskBookFilterList.Count == 0)
{
InsertRskBookFilter();
}
}
public void InsertRskBookFilter()
{
QueryInfo RskBookInfo=new QueryInfo("RskBook");
IList rskList = Dao.FindList(RskBookInfo);
QueryInfo SysDictinfo = new QueryInfo("SysDict");
SysDictinfo.AddParam("TypeCode", "RISK_GROUP_TYPE");
SysDictinfo = Dao.FindByQueryInfo(SysDictinfo);
//IList sysdicList = SysDictinfo.List;"transaction".ToUpper(), "trader".ToUpper(),
//List<string> sysdicList = new List<string>() { "counterparty".ToUpper(), "INSTRUMENT_TYPE".ToUpper(), "portfolio".ToUpper(), "TRADER" };
ArrayList arrayList=new ArrayList();
//DateTime dt=Convert.ToDateTime("2015-3-16");
string ResultType = "EOD_PROCESS";
QueryInfo RskBookFilterInfo=new QueryInfo();
RskBookFilterInfo.CustomSQL = @"insert into RSK_BOOK_FILTER
(risk_book_id,
filtered_group,
filtered_value,
selected_flag)";
int j = 0;
string sql = string.Empty;
for (int i = 0; i < rskList.Count; i++)
{
FilterGroupChain filterGroupChain = new FilterGroupChain();
filterGroupChain.AddFilterGroupChain(BusinessUnitSQLService)
.AddFilterGroupChain(CountPartySQLService)
.AddFilterGroupChain(InStrumentSQLService)
.AddFilterGroupChain(LegalEntitySQLService)
.AddFilterGroupChain(PortfolioSQLService).
AddFilterGroupChain(RskFactorService)
.AddFilterGroupChain(TraderSQLService);
sql+= filterGroupChain.SetGroupJoinSQL((rskList[i] as RskBook).Id);
if (i != rskList.Count - 1)
{
sql += " UNION ";
}
}
RskBookFilterInfo.CustomSQL += sql;
Dao.ExecuteNonQuery(RskBookFilterInfo);
//删除分组值为0的数据
QueryInfo delInfo = new QueryInfo();
delInfo.CustomSQL="delete from RskBookFilter where FilteredValue=0";
Dao.ExecuteUpdate(delInfo);
}
private string ToEntityColumnName(string columnName)
{
string s1 = string.Empty;
List<String> StrList = columnName.Split('_').ToList();
foreach (string s in StrList)
{
s1 += Regex.Replace(s, @"([A-Za-z]{1})([A-Za-z]*)", Convert2TrancashflowProperty);
}
return s1;
}
public string Convert2TrancashflowProperty(Match match)
{
return match.Groups[1].Value.ToUpper() + match.Groups[2].Value.ToLower();
}
/// <summary>
/// 设置查询条件或者语句
/// </summary>
/// <returns></returns>
protected override Framework.QueryInfo SetInfo()
{
info= base.SetInfo();
return info;
}
/// <summary>
/// 初始化页面控件
/// </summary>
protected override void InitPage()
{
base.InitPage();
// BindDrop(drp_Unit, "SPSW", true);
}
//filterGroupChain.AddFilterGroupChain(new BusinessUnitSQLService())
// .AddFilterGroupChain(new CountPartySQLService())
// .AddFilterGroupChain(new InStrumentSQLService())
// .AddFilterGroupChain(new LegalEntitySQLService())
// .AddFilterGroupChain(new PortfolioSQLService()).
// AddFilterGroupChain(new RskFactorSQLService())
// .AddFilterGroupChain(new TraderSQLService());
private IFilterGroupSQL _businessUnitSQLService;
private IFilterGroupSQL _countPartySQLService;
private IFilterGroupSQL _inStrumentSQLService;
private IFilterGroupSQL _legalEntitySQLService;
private IFilterGroupSQL _portfolioSQLService;
private IFilterGroupSQL _rskFactorService;
private IFilterGroupSQL _traderSQLService;
//private Contract.IService.IRskBookFilterService psvc;
///// <summary>
///// 初始化
///// </summary>
//Contract.IService.IRskBookFilterService Psvc
//{
// get
// {
// if (psvc == null)
// {
// psvc = ctx.GetObject("RskBookFilterService") as Contract.IService.IRskBookFilterService;
// }
// return psvc;
// }
//}
public IFilterGroupSQL BusinessUnitSQLService
{
get
{
if (_businessUnitSQLService == null) _businessUnitSQLService = ctx["BusinessUnitSQLService"] as IFilterGroupSQL;
return _businessUnitSQLService;
}
set { _businessUnitSQLService = value; }
}
public IFilterGroupSQL CountPartySQLService
{
get {
if (_countPartySQLService == null)
{
_countPartySQLService = ctx["CountPartySQLService"] as IFilterGroupSQL;
}
return _countPartySQLService;
}
set { _countPartySQLService = value; }
}
public IFilterGroupSQL InStrumentSQLService
{
get
{
if (_inStrumentSQLService == null)
{
_inStrumentSQLService = ctx["InStrumentSQLService"] as IFilterGroupSQL;
}
return _inStrumentSQLService;
}
set { _inStrumentSQLService = value; }
}
public IFilterGroupSQL LegalEntitySQLService
{
get
{
if (_legalEntitySQLService == null)
{
_legalEntitySQLService = ctx["LegalEntitySQLService"] as IFilterGroupSQL;
}
return _legalEntitySQLService;
}
set { _legalEntitySQLService = value; }
}
public IFilterGroupSQL PortfolioSQLService
{
get
{
if (_portfolioSQLService == null)
{
_portfolioSQLService = ctx["PortfolioSQLService"] as IFilterGroupSQL;
}
return _portfolioSQLService;
}
set { _portfolioSQLService = value; }
}
public IFilterGroupSQL RskFactorService
{
get
{
if (_rskFactorService == null)
{
_rskFactorService = ctx["RskFactorSQLService"] as IFilterGroupSQL;
}
return _rskFactorService;
}
set { _rskFactorService = value; }
}
public IFilterGroupSQL TraderSQLService
{
get
{
if (_traderSQLService == null)
{
_traderSQLService = ctx["TraderSQLService"] as IFilterGroupSQL;
}
return _traderSQLService;
}
set { _traderSQLService = value; }
}
}
public class CheckSeletedStruc
{
public string Id { get; set; }
public string SelectedFlag { get; set; }
}
}