宁虹看板
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1543 lines
68 KiB

using NFine.Code;
using NFine.Domain.Entity.SystemManage;
using NFine.Domain.IRepository.SystemManage;
using NFine.Repository.SystemManage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.Common;
using System.Text;
using NFine.Data.Extensions;
using NFine.Repository;
using System.Data.SqlClient;
using NFine.Domain._03_Entity.SystemManage;
using Newtonsoft.Json;
using System.Reflection;
using Newtonsoft.Json.Linq;
namespace NFine.Application.SystemManage
{
public class CommonReportApp : RepositoryFactory<ModuleEntity>
{
//查询数据
public DataTable GetGridJson(string sqlTxt, string DBName, string TempName, ref Pagination jqgridparam)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
string SqlText = sqlTxt;
if (SqlText.Contains("[AppConfig.WorkPointCode]"))
{
SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location);
}
if (SqlText.Contains("[AppConfig.UserId]"))
{
SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId);
}
if (SqlText.Contains("[AppConfig.UserCode]"))
{
SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode);
}
if (SqlText.Contains("[AppConfig.UserName]"))
{
SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName);
}
List<DbParameter> parameter = new List<DbParameter>();
// return SqlHelper.GetDataTableBySql_OtherConn(SqlText, DBName, ref jqgridparam, null);
if (!string.IsNullOrEmpty(TempName))
{
return Repository().FindTablePageBySql_OtherTemp(SqlText, " " + TempName + " ", " ", DBName, parameter.ToArray(), ref jqgridparam);
}
else
{
return Repository().FindTablePageBySql_Other(SqlText, DBName, parameter.ToArray(), ref jqgridparam);
}
}
//查询数据
public DataTable GetGridJsonNew(string MenuID, string sqlTxt_Condition, string DBName, string TempName, ref Pagination jqgridparam)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
DataTable dt = GetMenuSQL(MenuID);
string SqlText = dt.Rows[0]["SqlTxt"].ToString();
if (!string.IsNullOrEmpty(sqlTxt_Condition) && sqlTxt_Condition != "[]")
{
ConditionSQLClass[] list = JsonConvert.DeserializeObject<ConditionSQLClass[]>(sqlTxt_Condition);
if (list != null && list.Length > 0)
{
for (int i = 0; i < list.Length; i++)
{
SqlText = SqlText.Replace(list[i].CIndex,list[i].Content);
}
}
}
if (SqlText.Contains("[AppConfig.WorkPointCode]"))
{
SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location);
}
if (SqlText.Contains("[AppConfig.UserId]"))
{
SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId);
}
if (SqlText.Contains("[AppConfig.UserCode]"))
{
SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode);
}
if (SqlText.Contains("[AppConfig.UserName]"))
{
SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName);
}
List<DbParameter> parameter = new List<DbParameter>();
// return SqlHelper.GetDataTableBySql_OtherConn(SqlText, DBName, ref jqgridparam, null);
if (!string.IsNullOrEmpty(TempName))
{
return Repository().FindTablePageBySql_OtherTemp(SqlText, " " + TempName + " ", " ", DBName, parameter.ToArray(), ref jqgridparam);
}
else
{
return Repository().FindTablePageBySql_Other(SqlText, DBName, parameter.ToArray(), ref jqgridparam);
}
}
public DataTable ExportAll(string sqlTxt, string DBName, string TempName, string MenuID)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
string SqlText = sqlTxt;
if (SqlText.Contains("[AppConfig.WorkPointCode]"))
{
SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location);
}
if (SqlText.Contains("[AppConfig.UserId]"))
{
SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId);
}
if (SqlText.Contains("[AppConfig.UserCode]"))
{
SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode);
}
if (SqlText.Contains("[AppConfig.UserName]"))
{
SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName);
}
// return SqlHelper.GetDataTableBySql_OtherConn(SqlText, DBName, null);
if (!string.IsNullOrEmpty(TempName))
{
SqlText = SqlText + " select * from " + TempName + " ";
}
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, DBName, null);
//栏位权限控制
string sql2 = @"
select distinct ColCaption,ColFiledName from (
SELECT rr.ColCaption,rr.ColFiledName, rr.VisbleFlag,
(case when (select count(1) from Sys_FormColsVisible vv
where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"')
>0 then '1' else '0' end) RoleVisible
FROM dbo.Sys_ColsOfGridReport rr
left join Sys_FormDataSource ss on rr.SourceId=ss.id
where ss.menuid='" + MenuID + @"' ) fff
where VisbleFlag=1 and RoleVisible='1'
";
DataTable dtcol = Repository().FindTableBySql(sql2);
if (dtcol != null && dtcol.Rows.Count > 0)
{
List<int> DelList = new List<int>();
for (int i = 0; i < dt.Columns.Count; i++)
{
DataRow[] dr = dtcol.Select("ColFiledName='" + dt.Columns[i].ColumnName + "'");
if (dr != null && dr.Length > 0)
{
dt.Columns[i].ColumnName = dr[0]["ColCaption"].ToString();
}
else
{
// dt.Columns.Remove(dt.Columns[i].ColumnName);这样子是错误的 删除的过程中 i会变化
DelList.Add(i);
}
}
for (int j = DelList.Count - 1; j >= 0; j--)
{
dt.Columns.Remove(dt.Columns[DelList[j]]);
}
return dt;
}
return null;
}
public DataTable ExportAllNew(string sqlTxt_Condition, string DBName, string TempName, string MenuID)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
DataTable dt2 = GetMenuSQL(MenuID);
string SqlText = dt2.Rows[0]["SqlTxt"].ToString();
if (!string.IsNullOrEmpty(sqlTxt_Condition) && sqlTxt_Condition != "[]")
{
ConditionSQLClass[] list = JsonConvert.DeserializeObject<ConditionSQLClass[]>(sqlTxt_Condition);
if (list != null && list.Length > 0)
{
for (int i = 0; i < list.Length; i++)
{
SqlText = SqlText.Replace(list[i].CIndex, list[i].Content);
}
}
}
if (SqlText.Contains("[AppConfig.WorkPointCode]"))
{
SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location);
}
if (SqlText.Contains("[AppConfig.UserId]"))
{
SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId);
}
if (SqlText.Contains("[AppConfig.UserCode]"))
{
SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode);
}
if (SqlText.Contains("[AppConfig.UserName]"))
{
SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName);
}
// return SqlHelper.GetDataTableBySql_OtherConn(SqlText, DBName, null);
if (!string.IsNullOrEmpty(TempName))
{
SqlText = SqlText + " select * from " + TempName + " ";
}
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, DBName, null);
//栏位权限控制
string sql2 = @"
select distinct ColCaption,ColFiledName from (
SELECT rr.ColCaption,rr.ColFiledName, rr.VisbleFlag,
(case when (select count(1) from Sys_FormColsVisible vv
where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"')
>0 then '1' else '0' end) RoleVisible
FROM dbo.Sys_ColsOfGridReport rr
left join Sys_FormDataSource ss on rr.SourceId=ss.id
where ss.menuid='" + MenuID + @"' ) fff
where VisbleFlag=1 and RoleVisible='1'
";
DataTable dtcol = Repository().FindTableBySql(sql2);
if (dtcol != null && dtcol.Rows.Count > 0)
{
List<int> DelList = new List<int>();
for (int i = 0; i < dt.Columns.Count; i++)
{
DataRow[] dr = dtcol.Select("ColFiledName='" + dt.Columns[i].ColumnName + "'");
if (dr != null && dr.Length > 0)
{
dt.Columns[i].ColumnName = dr[0]["ColCaption"].ToString();
}
else
{
// dt.Columns.Remove(dt.Columns[i].ColumnName);这样子是错误的 删除的过程中 i会变化
DelList.Add(i);
}
}
for (int j = DelList.Count - 1; j >= 0; j--)
{
dt.Columns.Remove(dt.Columns[DelList[j]]);
}
return dt;
}
return null;
}
public DataTable GetGridJson(string sqlTxt, string DBName, string TempName)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
string SqlText = sqlTxt;
if (SqlText.Contains("[AppConfig.WorkPointCode]"))
{
SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location);
}
if (SqlText.Contains("[AppConfig.UserId]"))
{
SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId);
}
if (SqlText.Contains("[AppConfig.UserCode]"))
{
SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode);
}
if (SqlText.Contains("[AppConfig.UserName]"))
{
SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName);
}
if (!string.IsNullOrEmpty(TempName))
{
SqlText = SqlText + " select * from " + TempName + " ";
}
return Repository().GetDataTableBySql_Other(SqlText, DBName, null);
}
public DataTable GetGridJsonText(string sqlTxt, string DBName, string TempName)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
string SqlText = sqlTxt;
if (SqlText.Contains("[AppConfig.WorkPointCode]"))
{
SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location);
}
if (SqlText.Contains("[AppConfig.UserId]"))
{
SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId);
}
if (SqlText.Contains("[AppConfig.UserCode]"))
{
SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode);
}
if (SqlText.Contains("[AppConfig.UserName]"))
{
SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName);
}
if (!string.IsNullOrEmpty(TempName))
{
SqlText = SqlText + " select top 1 * from " + TempName + " ";
}
return Repository().GetDataTableBySql_Other(SqlText, DBName, null);
}
//获取数据源DB
public DataTable GetAllDataBase()
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
//string sql = @" select DBSourceName,DBSourceDesc ,ID DbId from Sys_DataBase where WorkCode='" + oo.Location + "' ";
string sql = @" select DBSourceName,DBSourceDesc ,ID DbId from Sys_DataBase ";
return Repository().FindTableBySql(sql);
}
//GetMenuID
public DataTable GetMenuID(string MenuTag)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
string sql = @"
SELECT f_id MenuID FROM Sys_SRM_Module where F_UrlAddress like '%MenuTag=" + MenuTag + "' ";
return Repository().FindTableBySql(sql);
}
//获取数据源sql等数据
public DataTable GetMenuSQL(string MenuID)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
string sql = @"
SELECT
isnull(ss.SqlTxt,'') SqlTxt ,
isnull(ss.FormatSql,'') FormatSql ,
isnull(SS.SysDataSourceFlag,'') SysDataSourceFlag,
isnull(ss.DbId,'') DbId ,
isnull(ss.id,newid()) SourceID,
mm.f_id MenuID,
CASE WHEN ss.SysDataSourceFlag= '1' THEN 'connstr'
ELSE ( SELECT DBSourceName FROM sys_database db WHERE db.id = ss.dbid )
END DBName ,
case when ss.id is null then '0' else '1' end IsExistsDataSource,
isnull(STUFF((select',' + ColFiledName
from (SELECT DISTINCT ColFiledName FROM Sys_ColsOfGridReport
where ColSumFlag=1 and SourceId=ss.id
) DD for xml path('')),1,1,'') ,'') footercols,
isnull(STUFF((select',' + ColFiledName
from (SELECT DISTINCT ColFiledName FROM Sys_ColsOfGridReport
where ColMerFlag=1 and SourceId=ss.id
) DD for xml path('')),1,1,'') ,'') Mergercols,
isnull((select top 1 ColSumFlag from Sys_ColsOfGridReport where ColSumFlag=1 and SourceId=ss.id ),0) footerrow,
mm.F_FullName ReportName,
ss.TempName TempName,
ss.DbParameters,
isnull(ss.XCol,'') XCol
FROM Sys_SRM_Module mm
LEFT JOIN Sys_FormDataSource ss ON mm.f_id= ss.MenuID
where mm.f_id='" + MenuID + @"' ";
return Repository().FindTableBySql(sql);
}
//获取列信息
public string GetMenuCols(string SourceID)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
string sql = @" SELECT * FROM dbo.Sys_ColsOfGridReport WHERE SourceID='" + SourceID + "' order by COrder ";
// ColCaption ColFiledName DataType DefineFlag FunctionString DeciamlNum ColWidth ColMerFlag ColMerKeyFlag ColSumFlag HeaderId COrder VisbleFlag SortFlag
DataTable dt = Repository().FindTableBySql(sql);
if (dt != null && dt.Rows.Count > 0)
{
DataRow[] visidr = dt.Select("VisbleFlag=1", " COrder asc");
if (visidr != null && visidr.Count() > 0)
{
Object[] colModel = new Object[visidr.Length + 1];
for (int i = 0; i < visidr.Length; i++)
{
DataRow dr = visidr[i];
string ColCaption = dr["ColCaption"].ToString();
string ColFiledName = dr["ColFiledName"].ToString();
int DataType = Convert.ToInt32(dr["DataType"].ToString());
string DataTypeStr = Enum.GetName(typeof(DataTypeEnum), DataType);
int ColWidth = Convert.ToInt32(dr["ColWidth"].ToString());
int DeciamlNum = Convert.ToInt32(dr["DeciamlNum"].ToString());
// bool VisbleFlag = !dr["VisbleFlag"].ToString().ToBool();
bool SortFlag = dr["SortFlag"].ToString().ToBool();
bool ColMerFlag = dr["ColMerFlag"].ToString().ToBool();
string ReportName = dr["ReportName"].ToString();
dynamic col = new System.Dynamic.ExpandoObject();
col.label = ColCaption;
col.name = ColFiledName;
col.width = ColWidth;
col.align = "left";
col.sortable = SortFlag;
col.ReportName = ReportName;
switch (DataTypeStr)
{
case "数值型":
var Formatoptions = new { decimalPlaces = DeciamlNum };
col.formatter = "number";
col.formatoptions = Formatoptions;
break;
case "字符型":
case "日期型":
case "布尔值":
break;
}
if (ColMerFlag)
{
/////!!!!!!!???待做//
col.cellattr = "MerFunction";
}
colModel[i] = col;
}
var collast = new { label = "", name = "", width = "20", align = "left" };
colModel[visidr.Length] = collast;
return colModel.ToJson();
}
}
else
{
}
return null;
}
//获取列项json 可见列版本
#region 可见列版本 old
public string GetMenuColsNew20210204(string SourceID)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
string sql = @" SELECT rr.*,(case when (select count(1) from Sys_FormatOfGridReport ff where ff.colid=rr.id)>0 then '1' else '0' end ) IsFormat,
(case when (select count(1) from Sys_FormColsVisible vv
where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"')
>0 then '1' else '0' end) RoleVisible
FROM dbo.Sys_ColsOfGridReport rr
left join Sys_FormDataSource ss on rr.SourceId=ss.id
WHERE SourceID='" + SourceID + "' order by COrder ";
// ColCaption ColFiledName DataType DefineFlag FunctionString DeciamlNum ColWidth ColMerFlag ColMerKeyFlag ColSumFlag HeaderId COrder VisbleFlag SortFlag
DataTable dt = Repository().FindTableBySql(sql);
if (dt != null && dt.Rows.Count > 0)
{
DataRow[] visidr = dt.Select("VisbleFlag=1 and RoleVisible='1' ", " COrder asc");
if (visidr != null && visidr.Count() > 0)
{
Object[] colModel = new Object[visidr.Length];
for (int i = 0; i < visidr.Length; i++)
{
DataRow dr = visidr[i];
string ColCaption = dr["ColCaption"].ToString();
string ColFiledName = dr["ColFiledName"].ToString();
int DataType = Convert.ToInt32(dr["DataType"].ToString());
string DataTypeStr = Enum.GetName(typeof(DataTypeEnum), DataType);
int ColWidth = Convert.ToInt32(dr["ColWidth"].ToString());
int DeciamlNum = Convert.ToInt32(dr["DeciamlNum"].ToString());
// bool VisbleFlag = !dr["VisbleFlag"].ToString().ToBool();
bool SortFlag = dr["SortFlag"].ToString().ToBool();
bool ColMerFlag = dr["ColMerFlag"].ToString().ToBool();
string IsFormat = dr["IsFormat"].ToString();
dynamic col = new System.Dynamic.ExpandoObject();
col.ColCaption = ColCaption;
col.ColFiledName = ColFiledName;
col.DataType = DataType;
col.DataTypeStr = DataTypeStr;
col.ColWidth = ColWidth;
col.DeciamlNum = DeciamlNum;
col.sortable = SortFlag;
col.ColMerFlag = ColMerFlag;
col.IsFormat = IsFormat;
colModel[i] = col;
}
return colModel.ToJson();
}
}
else
{
}
return null;
}
#endregion
public string GetMenuColsNew(string SourceID)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
string sql = @" SELECT rr.*,(case when (select count(1) from Sys_FormatOfGridReport ff where ff.colid=rr.id)>0 then '1' else '0' end ) IsFormat,
(case when (select count(1) from Sys_FormColsVisible vv
where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"')
>0 then '1' else '0' end) RoleVisible
FROM dbo.Sys_ColsOfGridReport rr
left join Sys_FormDataSource ss on rr.SourceId=ss.id
WHERE SourceID='" + SourceID + "' order by COrder ";
// ColCaption ColFiledName DataType DefineFlag FunctionString DeciamlNum ColWidth ColMerFlag ColMerKeyFlag ColSumFlag HeaderId COrder VisbleFlag SortFlag
DataTable dt = Repository().FindTableBySql(sql);
if (dt != null && dt.Rows.Count > 0)
{
Object[] colModel = new Object[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
string ColCaption = dr["ColCaption"].ToString();
string ColFiledName = dr["ColFiledName"].ToString();
int DataType = Convert.ToInt32(dr["DataType"].ToString());
string DataTypeStr = Enum.GetName(typeof(DataTypeEnum), DataType);
int ColWidth = Convert.ToInt32(dr["ColWidth"].ToString());
int DeciamlNum = Convert.ToInt32(dr["DeciamlNum"].ToString());
// bool VisbleFlag = !dr["VisbleFlag"].ToString().ToBool();
bool SortFlag = dr["SortFlag"].ToString().ToBool();
bool ColMerFlag = dr["ColMerFlag"].ToString().ToBool();
string IsFormat = dr["IsFormat"].ToString();
dynamic col = new System.Dynamic.ExpandoObject();
col.ColCaption = ColCaption;
col.ColFiledName = ColFiledName;
col.DataType = DataType;
col.DataTypeStr = DataTypeStr;
col.ColWidth = ColWidth;
col.DeciamlNum = DeciamlNum;
col.sortable = SortFlag;
col.ColMerFlag = ColMerFlag;
col.IsFormat = IsFormat;
colModel[i] = col;
}
return colModel.ToJson();
}
return null;
}
//获取不可见列 json
public string UnVisiblecols(string SourceID)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
string sql = @" select distinct ColFiledName from ( SELECT rr.*,(case when (select count(1) from Sys_FormatOfGridReport ff where ff.colid=rr.id)>0 then '1' else '0' end ) IsFormat,
(case when (select count(1) from Sys_FormColsVisible vv
where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"')
>0 then '1' else '0' end) RoleVisible
FROM dbo.Sys_ColsOfGridReport rr
left join Sys_FormDataSource ss on rr.SourceId=ss.id
WHERE SourceID='" + SourceID + "' ) fff where VisbleFlag=0 or RoleVisible='0' ";
DataTable dt = Repository().FindTableBySql(sql);
if (dt != null && dt.Rows.Count > 0)
{
Object[] colModel = new Object[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
string ColFiledName = dr["ColFiledName"].ToString();
dynamic col = new System.Dynamic.ExpandoObject();
col.ColFiledName = ColFiledName;
colModel[i] = col;
}
return colModel.ToJson();
}
return null;
}
//获取列个性化
public DataTable Getformatcols(string SourceID)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
string sql = @" select ff.*,cc.ColFiledName,
CASE
cc.datatype
WHEN 0 THEN '数值型'
WHEN 1 THEN '字符型'
WHEN 2 THEN '日期型'
WHEN 3 THEN '布尔值'
ELSE ''
END DataType
from Sys_FormatOfGridReport ff
left join Sys_ColsOfGridReport cc on cc.id=ff.colid
where cc.SourceID='" + SourceID + "' ";
DataTable dt = Repository().FindTableBySql(sql);
return dt;
}
//提交数据源sql等信息
public void SetDataSource(string SysDataSourceFlag, string FormatSql, string DbId, string MenuID, string DbParameters, string SourceID, string TempName, string XCol)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
string sql = @" SELECT mm.f_id MenuID,ss.SqlTxt,SS.SysDataSourceFlag,ss.DbId ,isnull(ss.id,'') id--,oo.id otherSetid
FROM Sys_SRM_Module mm
left join Sys_FormDataSource ss on mm.f_id=ss.MenuID
-- left join Sys_FormDataSource_Other oo on oo.menuid=mm.f_id
where mm.f_id='" + MenuID + @"' ";
DataTable dt = Repository().FindTableBySql(sql);
string SqlTxt = "";
string[] strs = DbParameters.Split(',');
if (strs.Length == 0)
{
SqlTxt = FormatSql;
}
else
{
List<string> pList = new List<string>();
foreach (string str in strs)
{
if (!string.IsNullOrEmpty(str))
{
pList.Add(str);
}
}
if (pList.Count > 0)
{
SqlTxt = string.Format(FormatSql, pList.ToArray());
}
else
{
SqlTxt = FormatSql;
}
}
if (dt != null && dt.Rows.Count > 0 && !string.IsNullOrEmpty(dt.Rows[0]["id"].ToString()))
{
string sqlupdate = @" update Sys_FormDataSource
set SqlTxt=N'" + ReSetStringTosql(SqlTxt) + @"',
SysDataSourceFlag='" + SysDataSourceFlag + @"',
DbId='" + DbId + @"',
FormatSql='" + ReSetStringTosql(FormatSql) + @"',
DbParameters='" + DbParameters + @"',
TempName='" + TempName + @"',
XCol='" + ReSetStringTosql(XCol) + @"'
WHERE ID='" + SourceID + @"' ";
StringBuilder sqlb = new StringBuilder(sqlupdate);
Repository().ExecuteBySql(sqlb);
}
else
{
if (!string.IsNullOrEmpty(MenuID))
{
string sqlupdate = @" insert into Sys_FormDataSource
(ID,MenuId,FilterButtonName,SysDataSourceFlag,DbId,
SqlTxt,FormatSql,DbParameters,AllowDbClickFlag,FormParameters,
DbClickMenuId,RowIndexWidth,ShowRowIndexFlag,ManyHeaderFlag,TempName,
XCol)
select '" + SourceID + @"','" + MenuID + @"','btnConfig','" + SysDataSourceFlag + @"','" + DbId + @"'
,'" + ReSetStringTosql(SqlTxt) + @"','" + ReSetStringTosql(FormatSql) + @"','" + DbParameters + @"','0',''
,'',35,'1','0' ,'" + TempName + @"',
'" + ReSetStringTosql(XCol) + @"' ";
StringBuilder sqlb = new StringBuilder(sqlupdate);
Repository().ExecuteBySql(sqlb);
}
else
{
throw new Exception("菜单信息异常:未找到菜单");
}
}
#region 设置默认看板信息
//if (dt != null && dt.Rows.Count > 0 && string.IsNullOrEmpty(dt.Rows[0]["otherSetid"].ToString()))
//{
// string sqlupdate = @" insert into Sys_FormDataSource_Other
// (ID,MenuId,PanelType,PanelGunDongTime,PanelGunDongNum,
// PanelRefreshTime,MUSER,MUSERName,MTIME,WorkPoint )
// select newid(),'" + MenuID + @"','1',120,0
// ,9000,'" + oo.UserCode + @"','" + oo.UserName + @"',getdate(),'"+oo.Location+@"' ";
// StringBuilder sqlb = new StringBuilder(sqlupdate);
// Repository().ExecuteBySql(sqlb);
//}
#endregion
//重新生成列信息
// ReSetFormCols(MenuID);
}
public void SetDataSourceText(string SysDataSourceFlag, string FormatSql, string DbId, string DbParameters, string TempName, string XCol)
{
try
{
Pagination jqgridparam = new Pagination();
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
string DBName = "connstr";
if (SysDataSourceFlag != "1")
{
string sql = @" SELECT DBSourceName FROM sys_database db WHERE db.id = '" + DbId + @" ' ";
DataTable dt = Repository().FindTableBySql(sql);
if (dt != null && dt.Rows.Count > 0)
{
DBName = dt.Rows[0][0].ToString();
}
else
{
throw new Exception("查找数据库异常");
}
}
string SqlTxt = "";
string[] strs = DbParameters.Split(',');
if (strs.Length == 0)
{
SqlTxt = FormatSql;
}
else
{
List<string> pList = new List<string>();
foreach (string str in strs)
{
if (!string.IsNullOrEmpty(str))
{
pList.Add(str);
}
}
if (pList.Count > 0)
{
SqlTxt = string.Format(FormatSql, pList.ToArray());
}
else
{
SqlTxt = FormatSql;
}
}
if (SqlTxt.Contains("[AppConfig.WorkPointCode]"))
{
SqlTxt = SqlTxt.Replace("[AppConfig.WorkPointCode]", oo.Location);
}
if (SqlTxt.Contains("[AppConfig.UserId]"))
{
SqlTxt = SqlTxt.Replace("[AppConfig.UserId]", oo.UserId);
}
if (SqlTxt.Contains("[AppConfig.UserCode]"))
{
SqlTxt = SqlTxt.Replace("[AppConfig.UserCode]", oo.UserCode);
}
if (SqlTxt.Contains("[AppConfig.UserName]"))
{
SqlTxt = SqlTxt.Replace("[AppConfig.UserName]", oo.UserName);
}
if (!string.IsNullOrEmpty(TempName))
{
SqlTxt = SqlTxt + " select * from " + TempName + " ";
}
SqlHelper.GetDataTableBySql_OtherConn(SqlTxt, DBName, ref jqgridparam, null);
if (!string.IsNullOrEmpty(TempName))
{
SqlTxt = SqlTxt + " select * from " + TempName + " ";
}
if (!string.IsNullOrEmpty(XCol.Trim()))
{
SqlTxt = SqlTxt + " order by " + XCol.Trim() + " ";
}
Repository().GetDataTableBySql_Other(SqlTxt, DBName, null);
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
}
private string ReSetStringTosql(string sql)
{
sql = sql.Replace("'", "''");
sql = sql.Replace("\r", "\r ");
sql = sql.Replace("\r\n", "\r\n ");
sql = sql.Replace("\n", "\n ");
return sql;
}
public void ReSetCols(string MenuID)
{
ReSetFormCols(MenuID);
}
public void ReSetFormCols(string MenuID)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
DataTable dt = GetMenuSQL(MenuID);//获取菜单配置信息
if (dt != null && dt.Rows.Count > 0)
{
String SourceID = dt.Rows[0]["SourceID"].ToString();
string SqlText = dt.Rows[0]["SqlTxt"].ToString();
string DBName = dt.Rows[0]["DBName"].ToString();
string TempName = dt.Rows[0]["TempName"].ToString();
//抓取现有列
string sqlcol = @" SELECT * FROM Sys_ColsOfGridReport WHERE SourceID='" + SourceID + "' ";
// ColCaption ColFiledName DataType DefineFlag FunctionString DeciamlNum ColWidth ColMerFlag
//ColMerKeyFlag ColSumFlag HeaderId COrder VisbleFlag SortFlag
DataTable dtcol = Repository().FindTableBySql(sqlcol);
//查询数据
DataTable data = GetGridJsonText(SqlText, DBName, TempName);
if (data != null && data.Columns.Count > 0)
{
string InsertSQL = "";
// DataRow drFirst = data.Rows[0];//首行
for (int i = 0; i < data.Columns.Count; i++)
{
DataRow[] EXISRow = dtcol.Select("ColFiledName='" + data.Columns[i].ColumnName + "'");
if (EXISRow == null || EXISRow.Count() == 0)
{
ColsOfGridClass CC = new ColsOfGridClass();
Type dataType = data.Columns[i].DataType;
#region CC.dataType
if (dataType == typeof(int))
{
CC.DataType = ((int)DataTypeEnum.).ToString();
}
if (dataType == typeof(Int16))
{
CC.DataType = ((int)DataTypeEnum.).ToString();
}
if (dataType == typeof(Int32))
{
CC.DataType = ((int)DataTypeEnum.).ToString();
}
if (dataType == typeof(Int64))
{
CC.DataType = ((int)DataTypeEnum.).ToString();
}
if (dataType == typeof(float))
{
CC.DataType = ((int)DataTypeEnum.).ToString();
}
if (dataType == typeof(Decimal))
{
CC.DataType = ((int)DataTypeEnum.).ToString();
}
if (dataType == typeof(decimal))
{
CC.DataType = ((int)DataTypeEnum.).ToString();
}
if (dataType == typeof(Double))
{
CC.DataType = ((int)DataTypeEnum.).ToString();
}
if (dataType == typeof(double))
{
CC.DataType = ((int)DataTypeEnum.).ToString();
}
if (dataType == typeof(DateTime))
{
CC.DataType = ((int)DataTypeEnum.).ToString();
}
if (dataType == typeof(string))
{
CC.DataType = ((int)DataTypeEnum.).ToString();
}
if (dataType == typeof(String))
{
CC.DataType = ((int)DataTypeEnum.).ToString();
}
if (dataType == typeof(Boolean))
{
CC.DataType = ((int)DataTypeEnum.).ToString();
}
if (dataType == typeof(bool))
{
CC.DataType = ((int)DataTypeEnum.).ToString();
}
#endregion
CC.ColCaption = data.Columns[i].ColumnName;
CC.ColFiledName = data.Columns[i].ColumnName;
CC.DefineFlag = false;
CC.FunctionString = "";
CC.DeciamlNum = 2;
CC.ColWidth = 90;
CC.ColMerFlag = false;
CC.ColMerKeyFlag = false;
CC.ColSumFlag = false;
CC.HeaderId = "";
CC.COrder = i + 1;
CC.VisbleFlag = true;
CC.SortFlag = false;
InsertSQL += @" insert into Sys_ColsOfGridReport
(Id, SourceID , ColCaption, ColFiledName, DataType,
DefineFlag, FunctionString, DeciamlNum, ColWidth, ColMerFlag,
ColMerKeyFlag, ColSumFlag, HeaderId, COrder, VisbleFlag,
SortFlag)
select newid(),'" + SourceID + @"','" + CC.ColCaption + @"','" + CC.ColFiledName + @"','" + CC.DataType + @"',
" + BoolToInt(CC.DefineFlag) + @",'" + ReSetStringTosql(CC.FunctionString) + @"'," + CC.DeciamlNum + @"," + CC.ColWidth + @"," + BoolToInt(CC.ColMerFlag) + @",
" + BoolToInt(CC.ColMerKeyFlag) + @"," + BoolToInt(CC.ColSumFlag) + @",'" + CC.HeaderId + @"','" + CC.COrder.ToString() + @"'," + BoolToInt(CC.VisbleFlag) + @",
" + BoolToInt(CC.SortFlag) + @"
where NOT EXISTS(SELECT 1 FROM Sys_ColsOfGridReport WHERE SourceID='" + SourceID + @"' AND ColCaption='" + CC.ColCaption + @"' )
";
}
}
StringBuilder sqlb = new StringBuilder(InsertSQL);
Repository().ExecuteBySql(sqlb);
}
}
}
private int BoolToInt(bool flag)
{
if (flag)
{
return 1;
}
return 0;
}
public DataTable GetCondition(string SourceID)
{
string sql = @" SELECT con.id IDStr, '0' IsNew, CSortSeq 排序,NotNullFlag 必填, CCaption 条件名称, CFiledName 字段名称, CIndex 替代符号,
CDefaultLogStirng 默认逻辑符号, CDataType 数据类型,CDefaultLogStirng 默认逻辑符号Data, CDataType 数据类型Data,
CDefaultValue 默认值 ,CSelectFlag 参照选择, CSelectSqlTxt 参照语句, CSelectSourceId 其他数据源,
SysDataSourceFlag 本系统数据源, ReturnCol 返回字段,CSelectSourceId 其他数据源Data
from Sys_FormFilterCondition con
where con.SourceID='" + SourceID + @"' order by CSortSeq";
return Repository().FindTableBySql(sql);
}
public void SetCondition(string SourceID, string List_Condition)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
if (!string.IsNullOrEmpty(List_Condition) && List_Condition != "[]")
{
ConditionClass[] list = JsonConvert.DeserializeObject<ConditionClass[]>(List_Condition);
if (list != null)
{
string sql = "";
string sqldel = "";
string sqldel2 = "";
string sqlinsert = "";
string sqlupdate = "";
//@" delete from Sys_FormFilterCondition where SourceID='" + SourceID + @"' ";
foreach (ConditionClass item in list)
{
if (item.ID == "")//insert
{
sqlinsert += @" INSERT INTO [Sys_FormFilterCondition]
([ID],[SourceID] ,[NotNullFlag],[CCaption],[CFiledName],
[CIndex],[CLogString],[CDefaultLogStirng],[CDataType],[CDefaultValue],
[CSelectFlag],[CSelectSqlTxt],[CSelectSourceID],[SysDataSourceFlag],[ReturnCol],
[CSortSeq] )
select newid(),'" + SourceID + @"'," + item.NotNullFlag + @",'" + item.CCaption + @"','" + ReSetStringTosql(item.CFiledName) + @"',
'" + item.CIndex + @"','" + item.CLogString + @"','" + item.CDefaultLogStirng + @"','" + item.CDataType + @"','" + item.CDefaultValue + @"',
" + item.CSelectFlag + @",'" + ReSetStringTosql(item.CSelectSqlTxt) + @"','" + item.CSelectSourceId + @"'," + item.SysDataSourceFlag + @",'" + item.ReturnCol + @"',
" + item.CSortSeq + @" ";
}
else//update
{
sqlupdate += @" update [Sys_FormFilterCondition]
set
[NotNullFlag]=" + item.NotNullFlag + @",
[CCaption]='" + item.CCaption + @"',
[CFiledName]='" + ReSetStringTosql(item.CFiledName) + @"',
[CIndex]='" + item.CIndex + @"',
[CLogString]='" + item.CLogString + @"',
[CDefaultLogStirng]='" + item.CDefaultLogStirng + @"',
[CDataType]='" + item.CDataType + @"',
[CDefaultValue]='" + item.CDefaultValue + @"',
[CSelectFlag]=" + item.CSelectFlag + @",
[CSelectSqlTxt]='" + ReSetStringTosql(item.CSelectSqlTxt) + @"',
[CSelectSourceID]='" + item.CSelectSourceId + @"',
[SysDataSourceFlag]=" + item.SysDataSourceFlag + @",
[ReturnCol]='" + item.ReturnCol + @"',
[CSortSeq]=" + item.CSortSeq + @"
where id='" + item.ID + "' and SourceID='" + SourceID + @"'
";
sqldel2 += " and FilterID!='" + item.ID + "' ";
sqldel += " and ID!='" + item.ID + "' ";
}
}
sql = @" delete from Sys_FormFilterCondition where SourceID = '" + SourceID + @"' " +
sqldel + sqlupdate + sqlinsert;
sql += " delete from Sys_ColsDefaultRecord where SourceID = '" + SourceID + @"' " + sqldel2;
StringBuilder sqlb = new StringBuilder(sql);
Repository().ExecuteBySql(sqlb);
}
}
else
{
string sql = @" delete from Sys_FormFilterCondition where SourceID='" + SourceID + @"'
delete from Sys_ColsDefaultRecord where SourceID='" + SourceID + @"'";
StringBuilder sqlb = new StringBuilder(sql);
Repository().ExecuteBySql(sqlb);
}
}
public void SetDefaultRecord(string SourceID, string List_Record)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
if (!string.IsNullOrEmpty(List_Record) && List_Record != "[]")
{
DefaultRecordClass[] list = JsonConvert.DeserializeObject<DefaultRecordClass[]>(List_Record);
if (list != null)
{
string sql = "delete from Sys_ColsDefaultRecord where SourceID='" + SourceID + @"' ";
foreach (DefaultRecordClass item in list)
{
sql += @" INSERT INTO [dbo].[Sys_ColsDefaultRecord]
([Id],[SourceId],[FilterID],[F_Account],[CCaption],
[CDefaultLogStirng],[CDefaultValue1],[CDefaultValue2],[WorkPoint],[MUSER],
[MUSERName],[MTIME],[EATTRIBUTE1],[EATTRIBUTE2])
select
newid(),
'" + SourceID + @"',
'" + item.FilterID + @"',
'" + oo.UserCode + @"',
'" + ReSetStringTosql(item.CCaption) + @"',
'" + item.CDefaultLogStirng + @"',
'" + ReSetStringTosql(item.CDefaultValue1) + @"',
'" + ReSetStringTosql(item.CDefaultValue2) + @"',
'" + oo.Location + @"',
'" + oo.UserCode + @"',
'" + oo.UserName + @"',
getdate(),
null,
null
";
}
StringBuilder sqlb = new StringBuilder(sql);
Repository().ExecuteBySql(sqlb);
}
}
else
{
string sql = @" delete from Sys_ColsDefaultRecord where SourceID='" + SourceID + @"' ";
StringBuilder sqlb = new StringBuilder(sql);
Repository().ExecuteBySql(sqlb);
}
}
public DataTable GetCols(string SourceID)
{
string sql = @" SELECT Id IDStr, SourceID SourceID , ColCaption , ColFiledName , DataType ,
DefineFlag , FunctionString , DeciamlNum , ColWidth , ColMerFlag ,
ColMerKeyFlag , ColSumFlag , HeaderId , COrder , VisbleFlag ,
SortFlag , ColCaption 显示名称, ColFiledName 字段名称, DataType 数据类型, DefineFlag 自定义项,
FunctionString 自定义公式, DeciamlNum 小数点位数, ColWidth 字段宽度, ColMerFlag 合并相同项, ColMerKeyFlag as [合并相同项Key],
ColSumFlag 汇总, HeaderId 从属表头, COrder 显示顺序, VisbleFlag 显示, SortFlag 允许排序
from Sys_ColsOfGridReport
where SourceID='" + SourceID + @"' order by COrder ";
return Repository().FindTableBySql(sql);
}
public DataTable GetGridFormat(string ColId)
{
string sql = @" SELECT * from Sys_formatofgridreport where ColId='" + ColId + @"' ";
return Repository().FindTableBySql(sql);
}
public void SetCols(string SourceID, string List_Cols)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
if (!string.IsNullOrEmpty(List_Cols) && List_Cols != "[]")
{
ColsStrOfGridClass[] list = JsonConvert.DeserializeObject<ColsStrOfGridClass[]>(List_Cols);
if (list != null)
{
string sql = "";
string del_sql = "";
List<string> IDList = new List<string>();
string sql_s = @" select id from Sys_ColsOfGridReport where SourceID='" + SourceID + @"' ";
DataTable dtid = Repository().FindTableBySql(sql_s);
if (dtid != null && dtid.Rows.Count > 0)
{
foreach (DataRow dr in dtid.Rows)
{
IDList.Add(dr["id"].ToString());
}
}
foreach (ColsStrOfGridClass item in list)
{
if (string.IsNullOrEmpty(item.DefineFlag))
{
item.DefineFlag = "0";
}
if (string.IsNullOrEmpty(item.DeciamlNum))
{
item.DeciamlNum = "2";
}
if (string.IsNullOrEmpty(item.ColWidth))
{
item.ColWidth = "90";
}
if (string.IsNullOrEmpty(item.ColMerFlag))
{
item.ColMerFlag = "0";
}
if (string.IsNullOrEmpty(item.ColMerKeyFlag))
{
item.ColMerKeyFlag = "0";
}
if (string.IsNullOrEmpty(item.ColSumFlag))
{
item.ColSumFlag = "0";
}
if (string.IsNullOrEmpty(item.VisbleFlag))
{
item.VisbleFlag = "1";
}
if (string.IsNullOrEmpty(item.SortFlag))
{
item.SortFlag = "0";
}
if (string.IsNullOrEmpty(item.COrder))
{
item.COrder = "0";
}
if (IDList.Contains(item.Id))
{
del_sql += " and id!='" + item.Id + "' ";
sql += @" update [Sys_ColsOfGridReport]
set ColCaption='" + item.ColCaption + @"',
ColFiledName ='" + item.ColFiledName + @"',
DataType ='" + item.DataType + @"',
DefineFlag=" + item.DefineFlag + @",
FunctionString ='" + ReSetStringTosql(item.FunctionString) + @"',
DeciamlNum =" + item.DeciamlNum + @",
ColWidth =" + item.ColWidth + @",
ColMerFlag=" + item.ColMerFlag + @",
ColMerKeyFlag =" + item.ColMerKeyFlag + @",
ColSumFlag =" + item.ColSumFlag + @",
HeaderId ='" + item.HeaderId + @"',
COrder =" + item.COrder + @",
VisbleFlag =" + item.VisbleFlag + @",
SortFlag=" + item.SortFlag + @"
where SourceID='" + SourceID + @"' and ID='" + item.Id + @"' ";
}
else
{
sql += @" INSERT INTO [Sys_ColsOfGridReport]
([ID],[SourceID], ColCaption , ColFiledName , DataType ,
DefineFlag , FunctionString , DeciamlNum , ColWidth , ColMerFlag ,
ColMerKeyFlag , ColSumFlag , HeaderId , COrder , VisbleFlag ,
SortFlag)
select newid(),'" + SourceID + @"','" + item.ColCaption + @"','" + item.ColFiledName + @"','" + item.DataType + @"',
" + item.DefineFlag + @",'" + ReSetStringTosql(item.FunctionString) + @"'," + item.DeciamlNum + @"," + item.ColWidth + @"," + item.ColMerFlag + @",
" + item.ColMerKeyFlag + @"," + item.ColSumFlag + @",'" + item.HeaderId + @"'," + item.COrder + @"," + item.VisbleFlag + @",
" + item.SortFlag + @" ";
}
}
if (!string.IsNullOrEmpty(del_sql))
{
del_sql = @"
----删除sys_ColsOfGridReport 先删对应的Sys_formatofgridreport
delete from Sys_formatofgridreport
where ColId in(select id from sys_ColsOfGridReport where SourceID='" + SourceID + @"' " + del_sql + @" )
delete from sys_ColsOfGridReport where SourceID='" + SourceID + @"' " + del_sql;
}
sql = del_sql + sql;
StringBuilder sqlb = new StringBuilder(sql);
Repository().ExecuteBySql(sqlb);
}
else
{
string sql_D = @" DELETE from Sys_ColsOfGridReport where SourceID='" + SourceID + @"' ";
StringBuilder sqlb = new StringBuilder(sql_D);
Repository().ExecuteBySql(sqlb);
}
}
}
public void SetGridFormat(string ColId, string List_GridFormat)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
if (!string.IsNullOrEmpty(List_GridFormat) && List_GridFormat != "[]")
{
GridFormatClass[] list = JsonConvert.DeserializeObject<GridFormatClass[]>(List_GridFormat);
if (list != null)
{
string sql = @" delete from Sys_formatofgridreport where ColId='" + ColId + @"' ";
foreach (GridFormatClass item in list)
{
sql += @" INSERT INTO [Sys_formatofgridreport]
(ID,ColId,LogStr,SValue,DValue,Color,AllRowFlag)
select newid(),'" + ColId + @"','" + item.LogStr + @"','" + item.SValue + @"','" + item.DValue + @"',
'" + item.Color + @"', " + item.AllRowFlag + @" ";
}
StringBuilder sqlb = new StringBuilder(sql);
Repository().ExecuteBySql(sqlb);
}
}
else
{
string sql = @" delete from Sys_formatofgridreport where ColId='" + ColId + @"' ";
StringBuilder sqlb = new StringBuilder(sql);
Repository().ExecuteBySql(sqlb);
}
}
public DataTable GetFilter(string SourceID)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
// 替代符号, 字段名称,数据类型,默认逻辑符号,默认值,条件名称,逻辑符号,起始值,结束值
string sql = @"
SELECT con.id FilterID, con.NotNullFlag 必填, con.CCaption 条件名称, con.CFiledName 字段名称, con.CIndex 替代符号,
isnull(rr.CDefaultLogStirng,con.CDefaultLogStirng) 默认逻辑符号, con.CDataType 数据类型, isnull(rr.CDefaultValue1,con.CDefaultValue) 默认值 ,'' 逻辑符号,
'' 起始值,'' 结束值,isnull(rr.CDefaultValue2,'') 默认值2,con.CSelectFlag 参照选择,con.ReturnCol 返回字段
from Sys_FormFilterCondition con
left join Sys_ColsDefaultRecord rr on rr.FilterID=con.id and rr.F_Account='" + oo.UserCode + @"' and con.SourceID=rr.SourceID
where con.SourceID='" + SourceID + @"' order by con.CSortSeq";
return Repository().FindTableBySql(sql);
}
// 获取栏位的栏位筛选条件数据
public DataTable GetColsSelectData(string SourceID, string ColsName, string InputKey)
{
string sql = @" SELECT top 1 CSelectSqlTxt ,
CASE WHEN SysDataSourceFlag= '1' THEN 'connstr'
ELSE ( SELECT DBSourceName FROM sys_database db WHERE db.id = CSelectSourceID )
END DBName
from Sys_FormFilterCondition
where SourceID='" + SourceID + @"' and CCaption =N'" + ColsName + "' ";
DataTable dt = Repository().FindTableBySql(sql);
if (dt != null && dt.Rows.Count > 0)
{
string sqlcols = dt.Rows[0]["CSelectSqlTxt"].ToString();
string DBName = dt.Rows[0]["DBName"].ToString();
sqlcols = string.Format(sqlcols, InputKey);
DataTable dtcols = SqlHelper.GetDataTableBySql_OtherConn(sqlcols, DBName, null);
return dtcols;
}
return null;
}
public string GetColsSelectCols(DataTable dt)
{
if (dt != null && dt.Columns.Count > 0)
{
Object[] colModel = new Object[dt.Columns.Count + 1];
for (int i = 0; i < dt.Columns.Count; i++)
{
string ColCaption = dt.Columns[i].ColumnName;
string ColFiledName = dt.Columns[i].ColumnName;
var col = new Object();
col = new
{
label = ColCaption,
name = ColFiledName,
align = "left",
};
colModel[i] = col;
}
var collast = new { label = "", name = "", width = "20", align = "left" };
colModel[dt.Columns.Count] = collast;
return colModel.ToJson();
}
return "";
}
public void ClearAll(string MenuID)
{
string sql = @" DECLARE @SourceId VARCHAR (100)
SELECT @SourceId=id FROM Sys_FormDataSource WHERE menuid='" + MenuID + @"'
DELETE FROM Sys_formatofgridreport WHERE colid IN (SELECT id FROM Sys_ColsOfGridReport WHERE SourceId=@SourceId)
DELETE FROM Sys_HeaderOfGridReport WHERE Sourceid=@SourceId
DELETE FROM Sys_FormFilterCondition WHERE SourceId=@SourceId
DELETE FROM Sys_ColsOfGridReport WHERE SourceId=@SourceId
delete from Sys_FormDataSource WHERE id=@SourceId
delete from Sys_ColsDefaultRecord where SourceId=@SourceId
-- delete from Sys_FormDataSource_Other where menuid='" + MenuID + @"'
";
StringBuilder sqlb = new StringBuilder(sql);
Repository().ExecuteBySql(sqlb);
}
public DataTable GetColsVisible(string MenuID, string Roles, string Cols, ref Pagination jqgridparam)
{
string sql = @" select cc.ID,FieldName 列字段, mm.f_fullname 角色 from Sys_FormColsVisible cc
left join Sys_SRM_role mm on mm.f_id =cc.RoleId where cc.MenuId='" + MenuID + "' ";
if (!string.IsNullOrEmpty(Roles.Trim()))
{
sql += " and cc.RoleId in('" + Roles.Replace(",", "','") + "') ";
}
if (!string.IsNullOrEmpty(Cols.Trim()))
{
sql += " and FieldName in('" + Cols.Replace(",", "','") + "') ";
}
DataTable dt = Repository().FindTablePageBySql(sql, ref jqgridparam);
return dt;
}
public DataTable GetRoles()
{
string sql = @" select distinct mm.f_fullname Roles,f_id RolesID from Sys_SRM_role mm order by mm.f_fullname";
DataTable dt = Repository().FindTableBySql(sql);
return dt;
}
public DataTable GetColsFiledName(string MenuID)
{
string sql = @" select distinct cc.ColFiledName FiledName from Sys_SRM_Module mm
left join Sys_FormDataSource ss on ss.menuid=mm.f_id
left join Sys_ColsOfGridReport cc on cc.SourceId=ss.id and cc.visbleflag=1
where mm.f_id='" + MenuID + @"'
and isnull(cc.ColFiledName ,'')!='' order by cc.ColFiledName";
DataTable dt = Repository().FindTableBySql(sql);
return dt;
}
public void SetColsVisibleALL(string Cols, string IsCommon, string MenuID)
{
if (IsCommon == "Y")//通用报表
{
string sql = @" delete from Sys_FormColsVisible where MenuId='" + MenuID + @"'
insert into Sys_FormColsVisible(ID ,MenuId ,RoleId ,FieldName, VisibleFlag, WorkPoint)
select newid(),'" + MenuID + @"',RoleId,FiledName,1,'001'
from (
select distinct cc.ColFiledName FiledName ,rr.f_fullname,rr.f_id RoleId
from Sys_SRM_Module mm
left join Sys_FormDataSource ss on ss.menuid=mm.f_id
left join Sys_ColsOfGridReport cc on cc.SourceId=ss.id and cc.visbleflag=1
left join Sys_SRM_role rr on 1=1
where 1=1
and mm.f_id='" + MenuID + @"'
and isnull(cc.ColFiledName ,'')!=''
) fff
";
StringBuilder sqlb = new StringBuilder(sql);
Repository().ExecuteBySql(sqlb);
}
else//非通用报表
{
if (!string.IsNullOrEmpty(Cols))
{
string sql2 = @" delete from Sys_FormColsVisible where MenuId='" + MenuID + @"'
";
sql2 += @" insert into Sys_FormColsVisible(ID ,MenuId ,RoleId ,FieldName, VisibleFlag, WorkPoint)
select newid(),'" + MenuID + @"',RoleId,FiledName,1,'001'
from (
select distinct DDD.FiledName , rr.f_id RoleId
from (select distinct cc.items FiledName
from [dbo].[splitl]('" + Cols.Trim() + @"',',') cc
where isnull(cc.items,'')!='' ) DDD
left join Sys_SRM_role rr on 1=1
) fff
";
StringBuilder sqlb2 = new StringBuilder(sql2);
Repository().ExecuteBySql(sqlb2);
}
}
}
public void SetColsVisibleAdd(string Cols, string Roles, string MenuID)
{
if (!string.IsNullOrEmpty(Cols.Trim()) && !string.IsNullOrEmpty(Roles.Trim()))
{
string sql2 = @"
insert into Sys_FormColsVisible(ID ,MenuId ,RoleId ,FieldName, VisibleFlag, WorkPoint)
select newid(),'" + MenuID + @"',rr.items RoleId,cc.items FiledName,1,'001'
from [dbo].[splitl]('" + Cols.Trim() + @"',',') cc
left join [dbo].[splitl]('" + Roles.Trim() + @"',',') rr on 1=1
where isnull(cc.items,'')!=''
and isnull(rr.items,'')!=''
";
StringBuilder sqlb2 = new StringBuilder(sql2);
Repository().ExecuteBySql(sqlb2);
}
}
public void SetColsVisibleDel(string MenuID, string IDList)
{
if (!string.IsNullOrEmpty(IDList))
{
string sql2 = @"
delete from Sys_FormColsVisible where MenuId='" + MenuID + @"'
and id in('" + IDList.Replace(",", "','") + @"')
";
StringBuilder sqlb2 = new StringBuilder(sql2);
Repository().ExecuteBySql(sqlb2);
}
}
public DataTable GetHiddenCols(string MenuID, string Cols)
{
OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
// 栏位权限控制
string sql2 = @"
select distinct cc.items Col from [dbo].[splitl]('" + Cols.Trim() + @"',',') cc
left join Sys_FormColsVisible vv on cc.items=FieldName and vv.menuid='" + MenuID + @"' and vv.RoleId='" + oo.RoleId + @"'
where vv.id is null
";
DataTable dtcol = Repository().FindTableBySql(sql2);
return dtcol;
}
}
}