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.

1591 lines
69 KiB

4 days ago
  1. using NFine.Code;
  2. using NFine.Domain.Entity.SystemManage;
  3. using NFine.Domain.IRepository.SystemManage;
  4. using NFine.Repository.SystemManage;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Data;
  9. using System.Data.Common;
  10. using System.Text;
  11. using NFine.Data.Extensions;
  12. using NFine.Repository;
  13. using System.Data.SqlClient;
  14. using NFine.Domain._03_Entity.SystemManage;
  15. using Newtonsoft.Json;
  16. using System.Reflection;
  17. using Newtonsoft.Json.Linq;
  18. using System.Configuration;
  19. using System.Xml;
  20. namespace NFine.Application.SystemManage
  21. {
  22. public class CommonReportApp : RepositoryFactory<ModuleEntity>
  23. {
  24. DataActionApp actionapp = new DataActionApp();
  25. //查询数据
  26. public DataTable GetGridJson(string sqlTxt, string DBName, string TempName, ref Pagination jqgridparam)
  27. {
  28. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  29. string SqlText = sqlTxt;
  30. if (SqlText.Contains("[AppConfig.WorkPointCode]"))
  31. {
  32. SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location);
  33. }
  34. if (SqlText.Contains("[AppConfig.UserId]"))
  35. {
  36. SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId);
  37. }
  38. if (SqlText.Contains("[AppConfig.UserCode]"))
  39. {
  40. SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode);
  41. }
  42. if (SqlText.Contains("[AppConfig.UserName]"))
  43. {
  44. SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName);
  45. }
  46. if (SqlText.Contains("[AppConfig.RoleCode]"))
  47. {
  48. SqlText = SqlText.Replace("[AppConfig.RoleCode]", oo.RoleEnCode);
  49. }
  50. List<DbParameter> parameter = new List<DbParameter>();
  51. // return SqlHelper.GetDataTableBySql_OtherConn(SqlText, DBName, ref jqgridparam, null);
  52. if (!string.IsNullOrEmpty(TempName))
  53. {
  54. return Repository().FindTablePageBySql_OtherTemp(SqlText, " " + TempName + " ", " ", DBName, parameter.ToArray(), ref jqgridparam);
  55. }
  56. else
  57. {
  58. return Repository().FindTablePageBySql_Other(SqlText, DBName, parameter.ToArray(), ref jqgridparam);
  59. }
  60. }
  61. //查询数据
  62. public DataTable GetGridJsonNew(string MenuID, string sqlTxt_Condition, string DBName, string TempName, ref Pagination jqgridparam)
  63. {
  64. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  65. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  66. DataTable dt = GetMenuSQL(MenuID);
  67. string SqlText = dt.Rows[0]["SqlTxt"].ToString();
  68. if (!string.IsNullOrEmpty(sqlTxt_Condition) && sqlTxt_Condition != "[]")
  69. {
  70. ConditionSQLClass[] list = JsonConvert.DeserializeObject<ConditionSQLClass[]>(sqlTxt_Condition);
  71. if (list != null && list.Length > 0)
  72. {
  73. for (int i = 0; i < list.Length; i++)
  74. {
  75. SqlText = SqlText.Replace(list[i].CIndex,list[i].Content);
  76. }
  77. }
  78. }
  79. if (SqlText.Contains("[AppConfig.WorkPointCode]"))
  80. {
  81. SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location);
  82. }
  83. if (SqlText.Contains("[AppConfig.UserId]"))
  84. {
  85. SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId);
  86. }
  87. if (SqlText.Contains("[AppConfig.UserCode]"))
  88. {
  89. SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode);
  90. }
  91. if (SqlText.Contains("[AppConfig.UserName]"))
  92. {
  93. SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName);
  94. }
  95. if (SqlText.Contains("[AppConfig.RoleCode]"))
  96. {
  97. SqlText = SqlText.Replace("[AppConfig.RoleCode]", oo.RoleEnCode);
  98. }
  99. SqlText += " " + DataActionsql;
  100. List<DbParameter> parameter = new List<DbParameter>();
  101. // return SqlHelper.GetDataTableBySql_OtherConn(SqlText, DBName, ref jqgridparam, null);
  102. if (!string.IsNullOrEmpty(TempName))
  103. {
  104. return Repository().FindTablePageBySql_OtherTemp(SqlText, " " + TempName + " ", " ", DBName, parameter.ToArray(), ref jqgridparam);
  105. }
  106. else
  107. {
  108. return Repository().FindTablePageBySql_Other(SqlText, DBName, parameter.ToArray(), ref jqgridparam);
  109. }
  110. }
  111. public DataTable ExportAll(string sqlTxt, string DBName, string TempName, string MenuID)
  112. {
  113. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  114. string SqlText = sqlTxt;
  115. if (SqlText.Contains("[AppConfig.WorkPointCode]"))
  116. {
  117. SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location);
  118. }
  119. if (SqlText.Contains("[AppConfig.UserId]"))
  120. {
  121. SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId);
  122. }
  123. if (SqlText.Contains("[AppConfig.UserCode]"))
  124. {
  125. SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode);
  126. }
  127. if (SqlText.Contains("[AppConfig.UserName]"))
  128. {
  129. SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName);
  130. }
  131. if (SqlText.Contains("[AppConfig.RoleCode]"))
  132. {
  133. SqlText = SqlText.Replace("[AppConfig.RoleCode]", oo.RoleEnCode);
  134. }
  135. // return SqlHelper.GetDataTableBySql_OtherConn(SqlText, DBName, null);
  136. if (!string.IsNullOrEmpty(TempName))
  137. {
  138. SqlText = SqlText + " select * from " + TempName + " ";
  139. }
  140. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, DBName, null);
  141. //栏位权限控制
  142. string sql2 = @"
  143. select distinct ColCaption,ColFiledName from (
  144. SELECT rr.ColCaption,rr.ColFiledName, rr.VisbleFlag,
  145. (case when (select count(1) from Sys_FormColsVisible vv
  146. where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"')
  147. >0 then '1' else '0' end) RoleVisible
  148. FROM dbo.Sys_ColsOfGridReport rr
  149. left join Sys_FormDataSource ss on rr.SourceId=ss.id
  150. where ss.menuid='" + MenuID + @"' ) fff
  151. where VisbleFlag=1 and RoleVisible='1'
  152. ";
  153. DataTable dtcol = Repository().FindTableBySql(sql2);
  154. if (dtcol != null && dtcol.Rows.Count > 0)
  155. {
  156. List<int> DelList = new List<int>();
  157. for (int i = 0; i < dt.Columns.Count; i++)
  158. {
  159. DataRow[] dr = dtcol.Select("ColFiledName='" + dt.Columns[i].ColumnName + "'");
  160. if (dr != null && dr.Length > 0)
  161. {
  162. dt.Columns[i].ColumnName = dr[0]["ColCaption"].ToString();
  163. }
  164. else
  165. {
  166. // dt.Columns.Remove(dt.Columns[i].ColumnName);这样子是错误的 删除的过程中 i会变化
  167. DelList.Add(i);
  168. }
  169. }
  170. for (int j = DelList.Count - 1; j >= 0; j--)
  171. {
  172. dt.Columns.Remove(dt.Columns[DelList[j]]);
  173. }
  174. return dt;
  175. }
  176. return null;
  177. }
  178. public DataTable ExportAllNew(string sqlTxt_Condition, string DBName, string TempName, string MenuID,string XCol)
  179. {
  180. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  181. DataTable dt2 = GetMenuSQL(MenuID);
  182. string SqlText = dt2.Rows[0]["SqlTxt"].ToString();
  183. if (!string.IsNullOrEmpty(sqlTxt_Condition) && sqlTxt_Condition != "[]")
  184. {
  185. ConditionSQLClass[] list = JsonConvert.DeserializeObject<ConditionSQLClass[]>(sqlTxt_Condition);
  186. if (list != null && list.Length > 0)
  187. {
  188. for (int i = 0; i < list.Length; i++)
  189. {
  190. SqlText = SqlText.Replace(list[i].CIndex, list[i].Content);
  191. }
  192. }
  193. }
  194. if (SqlText.Contains("[AppConfig.WorkPointCode]"))
  195. {
  196. SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location);
  197. }
  198. if (SqlText.Contains("[AppConfig.UserId]"))
  199. {
  200. SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId);
  201. }
  202. if (SqlText.Contains("[AppConfig.UserCode]"))
  203. {
  204. SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode);
  205. }
  206. if (SqlText.Contains("[AppConfig.UserName]"))
  207. {
  208. SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName);
  209. }
  210. if (SqlText.Contains("[AppConfig.RoleCode]"))
  211. {
  212. SqlText = SqlText.Replace("[AppConfig.RoleCode]", oo.RoleEnCode);
  213. }
  214. // return SqlHelper.GetDataTableBySql_OtherConn(SqlText, DBName, null);
  215. if (!string.IsNullOrEmpty(TempName))
  216. {
  217. SqlText = SqlText + " select * from " + TempName + " ";
  218. }
  219. if (!string.IsNullOrEmpty(XCol))
  220. {
  221. SqlText += " Order by " + XCol + "";
  222. }
  223. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, DBName, null);
  224. //栏位权限控制
  225. string sql2 = @"
  226. select distinct ColCaption,ColFiledName from (
  227. SELECT rr.ColCaption,rr.ColFiledName, rr.VisbleFlag,
  228. (case when (select count(1) from Sys_FormColsVisible vv
  229. where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"')
  230. >0 then '1' else '0' end) RoleVisible
  231. FROM dbo.Sys_ColsOfGridReport rr
  232. left join Sys_FormDataSource ss on rr.SourceId=ss.id
  233. where ss.menuid='" + MenuID + @"' ) fff
  234. where VisbleFlag=1 and RoleVisible='1'
  235. ";
  236. DataTable dtcol = Repository().FindTableBySql(sql2);
  237. if (dtcol != null && dtcol.Rows.Count > 0)
  238. {
  239. List<int> DelList = new List<int>();
  240. for (int i = 0; i < dt.Columns.Count; i++)
  241. {
  242. DataRow[] dr = dtcol.Select("ColFiledName='" + dt.Columns[i].ColumnName + "'");
  243. if (dr != null && dr.Length > 0)
  244. {
  245. dt.Columns[i].ColumnName = dr[0]["ColCaption"].ToString();
  246. }
  247. else
  248. {
  249. // dt.Columns.Remove(dt.Columns[i].ColumnName);这样子是错误的 删除的过程中 i会变化
  250. DelList.Add(i);
  251. }
  252. }
  253. for (int j = DelList.Count - 1; j >= 0; j--)
  254. {
  255. dt.Columns.Remove(dt.Columns[DelList[j]]);
  256. }
  257. return dt;
  258. }
  259. return null;
  260. }
  261. public DataTable GetGridJson(string sqlTxt, string DBName, string TempName)
  262. {
  263. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  264. string SqlText = sqlTxt;
  265. if (SqlText.Contains("[AppConfig.WorkPointCode]"))
  266. {
  267. SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location);
  268. }
  269. if (SqlText.Contains("[AppConfig.UserId]"))
  270. {
  271. SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId);
  272. }
  273. if (SqlText.Contains("[AppConfig.UserCode]"))
  274. {
  275. SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode);
  276. }
  277. if (SqlText.Contains("[AppConfig.UserName]"))
  278. {
  279. SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName);
  280. }
  281. if (SqlText.Contains("[AppConfig.RoleCode]"))
  282. {
  283. SqlText = SqlText.Replace("[AppConfig.RoleCode]", oo.RoleEnCode);
  284. }
  285. if (!string.IsNullOrEmpty(TempName))
  286. {
  287. SqlText = SqlText + " select * from " + TempName + " ";
  288. }
  289. return Repository().GetDataTableBySql_Other(SqlText, DBName, null);
  290. }
  291. public DataTable GetGridJsonText(string sqlTxt, string DBName, string TempName)
  292. {
  293. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  294. string SqlText = sqlTxt;
  295. if (SqlText.Contains("[AppConfig.WorkPointCode]"))
  296. {
  297. SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location);
  298. }
  299. if (SqlText.Contains("[AppConfig.UserId]"))
  300. {
  301. SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId);
  302. }
  303. if (SqlText.Contains("[AppConfig.UserCode]"))
  304. {
  305. SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode);
  306. }
  307. if (SqlText.Contains("[AppConfig.UserName]"))
  308. {
  309. SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName);
  310. }
  311. if (SqlText.Contains("[AppConfig.RoleCode]"))
  312. {
  313. SqlText = SqlText.Replace("[AppConfig.RoleCode]", oo.RoleEnCode);
  314. }
  315. if (!string.IsNullOrEmpty(TempName))
  316. {
  317. SqlText = SqlText + " select top 1 * from " + TempName + " ";
  318. }
  319. return Repository().GetDataTableBySql_Other(SqlText, DBName, null);
  320. }
  321. //获取数据源DB
  322. public DataTable GetAllDataBase()
  323. {
  324. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  325. //string sql = @" select DBSourceName,DBSourceDesc ,ID DbId from Sys_DataBase where WorkCode='" + oo.Location + "' ";
  326. string sql = @" select DBSourceName,DBSourceDesc ,ID DbId from Sys_DataBase ";
  327. return Repository().FindTableBySql(sql);
  328. }
  329. //GetMenuID
  330. public DataTable GetMenuID(string MenuTag)
  331. {
  332. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  333. string sql = @"
  334. SELECT f_id MenuID FROM Sys_SRM_Module where F_UrlAddress like '%MenuTag=" + MenuTag + "' ";
  335. return Repository().FindTableBySql(sql);
  336. }
  337. //获取数据源sql等数据
  338. public DataTable GetMenuSQL(string MenuID)
  339. {
  340. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  341. string sql = @"
  342. SELECT
  343. isnull(ss.SqlTxt,'') SqlTxt ,
  344. isnull(ss.FormatSql,'') FormatSql ,
  345. isnull(SS.SysDataSourceFlag,'') SysDataSourceFlag,
  346. isnull(ss.DbId,'') DbId ,
  347. isnull(ss.id,newid()) SourceID,
  348. mm.f_id MenuID,
  349. CASE WHEN ss.SysDataSourceFlag= '1' THEN 'connstr'
  350. ELSE ( SELECT DBSourceName FROM sys_database db WHERE db.id = ss.dbid )
  351. END DBName ,
  352. case when ss.id is null then '0' else '1' end IsExistsDataSource,
  353. isnull(STUFF((select',' + ColFiledName
  354. from (SELECT DISTINCT ColFiledName FROM Sys_ColsOfGridReport
  355. where ColSumFlag=1 and SourceId=ss.id
  356. ) DD for xml path('')),1,1,'') ,'') footercols,
  357. isnull(STUFF((select',' + ColFiledName
  358. from (SELECT DISTINCT ColFiledName FROM Sys_ColsOfGridReport
  359. where ColMerFlag=1 and SourceId=ss.id
  360. ) DD for xml path('')),1,1,'') ,'') Mergercols,
  361. isnull((select top 1 ColSumFlag from Sys_ColsOfGridReport where ColSumFlag=1 and SourceId=ss.id ),0) footerrow,
  362. mm.F_FullName ReportName,
  363. ss.TempName TempName,
  364. ss.DbParameters,
  365. isnull(ss.XCol,'') XCol
  366. FROM Sys_SRM_Module mm
  367. LEFT JOIN Sys_FormDataSource ss ON mm.f_id= ss.MenuID
  368. where mm.f_id='" + MenuID + @"' ";
  369. return Repository().FindTableBySql(sql);
  370. }
  371. //获取列信息
  372. public string GetMenuCols(string SourceID)
  373. {
  374. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  375. string sql = @" SELECT * FROM dbo.Sys_ColsOfGridReport WHERE SourceID='" + SourceID + "' order by COrder ";
  376. // ColCaption ColFiledName DataType DefineFlag FunctionString DeciamlNum ColWidth ColMerFlag ColMerKeyFlag ColSumFlag HeaderId COrder VisbleFlag SortFlag
  377. DataTable dt = Repository().FindTableBySql(sql);
  378. if (dt != null && dt.Rows.Count > 0)
  379. {
  380. DataRow[] visidr = dt.Select("VisbleFlag=1", " COrder asc");
  381. if (visidr != null && visidr.Count() > 0)
  382. {
  383. Object[] colModel = new Object[visidr.Length + 1];
  384. for (int i = 0; i < visidr.Length; i++)
  385. {
  386. DataRow dr = visidr[i];
  387. string ColCaption = dr["ColCaption"].ToString();
  388. string ColFiledName = dr["ColFiledName"].ToString();
  389. int DataType = Convert.ToInt32(dr["DataType"].ToString());
  390. string DataTypeStr = Enum.GetName(typeof(DataTypeEnum), DataType);
  391. int ColWidth = Convert.ToInt32(dr["ColWidth"].ToString());
  392. int DeciamlNum = Convert.ToInt32(dr["DeciamlNum"].ToString());
  393. // bool VisbleFlag = !dr["VisbleFlag"].ToString().ToBool();
  394. bool SortFlag = dr["SortFlag"].ToString().ToBool();
  395. bool ColMerFlag = dr["ColMerFlag"].ToString().ToBool();
  396. string ReportName = dr["ReportName"].ToString();
  397. dynamic col = new System.Dynamic.ExpandoObject();
  398. col.label = ColCaption;
  399. col.name = ColFiledName;
  400. col.width = ColWidth;
  401. col.align = "left";
  402. col.sortable = SortFlag;
  403. col.ReportName = ReportName;
  404. switch (DataTypeStr)
  405. {
  406. case "数值型":
  407. var Formatoptions = new { decimalPlaces = DeciamlNum };
  408. col.formatter = "number";
  409. col.formatoptions = Formatoptions;
  410. break;
  411. case "字符型":
  412. case "日期型":
  413. case "布尔值":
  414. break;
  415. }
  416. if (ColMerFlag)
  417. {
  418. /////!!!!!!!???待做//
  419. col.cellattr = "MerFunction";
  420. }
  421. colModel[i] = col;
  422. }
  423. var collast = new { label = "", name = "", width = "20", align = "left" };
  424. colModel[visidr.Length] = collast;
  425. return colModel.ToJson();
  426. }
  427. }
  428. else
  429. {
  430. }
  431. return null;
  432. }
  433. //获取列项json 可见列版本
  434. #region 可见列版本 old
  435. public string GetMenuColsNew20210204(string SourceID)
  436. {
  437. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  438. 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,
  439. (case when (select count(1) from Sys_FormColsVisible vv
  440. where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"')
  441. >0 then '1' else '0' end) RoleVisible
  442. FROM dbo.Sys_ColsOfGridReport rr
  443. left join Sys_FormDataSource ss on rr.SourceId=ss.id
  444. WHERE SourceID='" + SourceID + "' order by COrder ";
  445. // ColCaption ColFiledName DataType DefineFlag FunctionString DeciamlNum ColWidth ColMerFlag ColMerKeyFlag ColSumFlag HeaderId COrder VisbleFlag SortFlag
  446. DataTable dt = Repository().FindTableBySql(sql);
  447. if (dt != null && dt.Rows.Count > 0)
  448. {
  449. DataRow[] visidr = dt.Select("VisbleFlag=1 and RoleVisible='1' ", " COrder asc");
  450. if (visidr != null && visidr.Count() > 0)
  451. {
  452. Object[] colModel = new Object[visidr.Length];
  453. for (int i = 0; i < visidr.Length; i++)
  454. {
  455. DataRow dr = visidr[i];
  456. string ColCaption = dr["ColCaption"].ToString();
  457. string ColFiledName = dr["ColFiledName"].ToString();
  458. int DataType = Convert.ToInt32(dr["DataType"].ToString());
  459. string DataTypeStr = Enum.GetName(typeof(DataTypeEnum), DataType);
  460. int ColWidth = Convert.ToInt32(dr["ColWidth"].ToString());
  461. int DeciamlNum = Convert.ToInt32(dr["DeciamlNum"].ToString());
  462. // bool VisbleFlag = !dr["VisbleFlag"].ToString().ToBool();
  463. bool SortFlag = dr["SortFlag"].ToString().ToBool();
  464. bool ColMerFlag = dr["ColMerFlag"].ToString().ToBool();
  465. string IsFormat = dr["IsFormat"].ToString();
  466. dynamic col = new System.Dynamic.ExpandoObject();
  467. col.ColCaption = ColCaption;
  468. col.ColFiledName = ColFiledName;
  469. col.DataType = DataType;
  470. col.DataTypeStr = DataTypeStr;
  471. col.ColWidth = ColWidth;
  472. col.DeciamlNum = DeciamlNum;
  473. col.sortable = SortFlag;
  474. col.ColMerFlag = ColMerFlag;
  475. col.IsFormat = IsFormat;
  476. colModel[i] = col;
  477. }
  478. return colModel.ToJson();
  479. }
  480. }
  481. else
  482. {
  483. }
  484. return null;
  485. }
  486. #endregion
  487. public string GetMenuColsNew(string SourceID)
  488. {
  489. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  490. 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,
  491. (case when (select count(1) from Sys_FormColsVisible vv
  492. where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"')
  493. >0 then '1' else '0' end) RoleVisible
  494. FROM dbo.Sys_ColsOfGridReport rr
  495. left join Sys_FormDataSource ss on rr.SourceId=ss.id
  496. WHERE SourceID='" + SourceID + "' order by COrder ";
  497. // ColCaption ColFiledName DataType DefineFlag FunctionString DeciamlNum ColWidth ColMerFlag ColMerKeyFlag ColSumFlag HeaderId COrder VisbleFlag SortFlag
  498. DataTable dt = Repository().FindTableBySql(sql);
  499. if (dt != null && dt.Rows.Count > 0)
  500. {
  501. Object[] colModel = new Object[dt.Rows.Count];
  502. for (int i = 0; i < dt.Rows.Count; i++)
  503. {
  504. DataRow dr = dt.Rows[i];
  505. string ColCaption = dr["ColCaption"].ToString();
  506. string ColFiledName = dr["ColFiledName"].ToString();
  507. int DataType = Convert.ToInt32(dr["DataType"].ToString());
  508. string DataTypeStr = Enum.GetName(typeof(DataTypeEnum), DataType);
  509. int ColWidth = Convert.ToInt32(dr["ColWidth"].ToString());
  510. int DeciamlNum = Convert.ToInt32(dr["DeciamlNum"].ToString());
  511. // bool VisbleFlag = !dr["VisbleFlag"].ToString().ToBool();
  512. bool SortFlag = dr["SortFlag"].ToString().ToBool();
  513. bool ColMerFlag = dr["ColMerFlag"].ToString().ToBool();
  514. string IsFormat = dr["IsFormat"].ToString();
  515. dynamic col = new System.Dynamic.ExpandoObject();
  516. col.ColCaption = ColCaption;
  517. col.ColFiledName = ColFiledName;
  518. col.DataType = DataType;
  519. col.DataTypeStr = DataTypeStr;
  520. col.ColWidth = ColWidth;
  521. col.DeciamlNum = DeciamlNum;
  522. col.sortable = SortFlag;
  523. col.ColMerFlag = ColMerFlag;
  524. col.IsFormat = IsFormat;
  525. colModel[i] = col;
  526. }
  527. return colModel.ToJson();
  528. }
  529. return null;
  530. }
  531. //获取不可见列 json
  532. public string UnVisiblecols(string SourceID)
  533. {
  534. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  535. 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,
  536. (case when (select count(1) from Sys_FormColsVisible vv
  537. where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"')
  538. >0 then '1' else '0' end) RoleVisible
  539. FROM dbo.Sys_ColsOfGridReport rr
  540. left join Sys_FormDataSource ss on rr.SourceId=ss.id
  541. WHERE SourceID='" + SourceID + "' ) fff where VisbleFlag=0 or RoleVisible='0' ";
  542. DataTable dt = Repository().FindTableBySql(sql);
  543. if (dt != null && dt.Rows.Count > 0)
  544. {
  545. Object[] colModel = new Object[dt.Rows.Count];
  546. for (int i = 0; i < dt.Rows.Count; i++)
  547. {
  548. DataRow dr = dt.Rows[i];
  549. string ColFiledName = dr["ColFiledName"].ToString();
  550. dynamic col = new System.Dynamic.ExpandoObject();
  551. col.ColFiledName = ColFiledName;
  552. colModel[i] = col;
  553. }
  554. return colModel.ToJson();
  555. }
  556. return null;
  557. }
  558. //获取列个性化
  559. public DataTable Getformatcols(string SourceID)
  560. {
  561. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  562. string sql = @" select ff.*,cc.ColFiledName,
  563. CASE
  564. cc.datatype
  565. WHEN 0 THEN ''
  566. WHEN 1 THEN ''
  567. WHEN 2 THEN ''
  568. WHEN 3 THEN ''
  569. ELSE ''
  570. END DataType
  571. from Sys_FormatOfGridReport ff
  572. left join Sys_ColsOfGridReport cc on cc.id=ff.colid
  573. where cc.SourceID='" + SourceID + "' ";
  574. DataTable dt = Repository().FindTableBySql(sql);
  575. return dt;
  576. }
  577. //提交数据源sql等信息
  578. public void SetDataSource(string SysDataSourceFlag, string FormatSql, string DbId, string MenuID, string DbParameters, string SourceID, string TempName, string XCol)
  579. {
  580. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  581. string sql = @" SELECT mm.f_id MenuID,ss.SqlTxt,SS.SysDataSourceFlag,ss.DbId ,isnull(ss.id,'') id
  582. FROM Sys_SRM_Module mm
  583. left join Sys_FormDataSource ss on mm.f_id=ss.MenuID
  584. where mm.f_id='" + MenuID + @"' ";
  585. DataTable dt = Repository().FindTableBySql(sql);
  586. string SqlTxt = "";
  587. string[] strs = DbParameters.Split(',');
  588. if (strs.Length == 0)
  589. {
  590. SqlTxt = FormatSql;
  591. }
  592. else
  593. {
  594. List<string> pList = new List<string>();
  595. foreach (string str in strs)
  596. {
  597. if (!string.IsNullOrEmpty(str))
  598. {
  599. pList.Add(str);
  600. }
  601. }
  602. if (pList.Count > 0)
  603. {
  604. SqlTxt = string.Format(FormatSql, pList.ToArray());
  605. }
  606. else
  607. {
  608. SqlTxt = FormatSql;
  609. }
  610. }
  611. if (dt != null && dt.Rows.Count > 0 && !string.IsNullOrEmpty(dt.Rows[0]["id"].ToString()))
  612. {
  613. string sqlupdate = @" update Sys_FormDataSource
  614. set SqlTxt=N'" + ReSetStringTosql(SqlTxt) + @"',
  615. SysDataSourceFlag='" + SysDataSourceFlag + @"',
  616. DbId='" + DbId + @"',
  617. FormatSql='" + ReSetStringTosql(FormatSql) + @"',
  618. DbParameters='" + DbParameters + @"',
  619. TempName='" + TempName + @"',
  620. XCol='" + ReSetStringTosql(XCol) + @"'
  621. WHERE ID='" + SourceID + @"' ";
  622. StringBuilder sqlb = new StringBuilder(sqlupdate);
  623. Repository().ExecuteBySql(sqlb);
  624. }
  625. else
  626. {
  627. if (!string.IsNullOrEmpty(MenuID))
  628. {
  629. string sqlupdate = @" insert into Sys_FormDataSource
  630. (ID,MenuId,FilterButtonName,SysDataSourceFlag,DbId,
  631. SqlTxt,FormatSql,DbParameters,AllowDbClickFlag,FormParameters,
  632. DbClickMenuId,RowIndexWidth,ShowRowIndexFlag,ManyHeaderFlag,TempName,
  633. XCol)
  634. select '" + SourceID + @"','" + MenuID + @"','btnConfig','" + SysDataSourceFlag + @"','" + DbId + @"'
  635. ,'" + ReSetStringTosql(SqlTxt) + @"','" + ReSetStringTosql(FormatSql) + @"','" + DbParameters + @"','0',''
  636. ,'',35,'1','0' ,'" + TempName + @"',
  637. '" + ReSetStringTosql(XCol) + @"' ";
  638. StringBuilder sqlb = new StringBuilder(sqlupdate);
  639. Repository().ExecuteBySql(sqlb);
  640. }
  641. else
  642. {
  643. throw new Exception("菜单信息异常:未找到菜单");
  644. }
  645. }
  646. //重新生成列信息
  647. // ReSetFormCols(MenuID);
  648. }
  649. public void SetDataSourceText(string SysDataSourceFlag, string FormatSql, string DbId, string DbParameters, string TempName, string XCol)
  650. {
  651. try
  652. {
  653. Pagination jqgridparam = new Pagination();
  654. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  655. string DBName = "connstr";
  656. if (SysDataSourceFlag != "1")
  657. {
  658. string sql = @" SELECT DBSourceName FROM sys_database db WHERE db.id = '" + DbId + @" ' ";
  659. DataTable dt = Repository().FindTableBySql(sql);
  660. if (dt != null && dt.Rows.Count > 0)
  661. {
  662. DBName = dt.Rows[0][0].ToString();
  663. }
  664. else
  665. {
  666. throw new Exception("查找数据库异常");
  667. }
  668. }
  669. string SqlTxt = "";
  670. string[] strs = DbParameters.Split(',');
  671. if (strs.Length == 0)
  672. {
  673. SqlTxt = FormatSql;
  674. }
  675. else
  676. {
  677. List<string> pList = new List<string>();
  678. foreach (string str in strs)
  679. {
  680. if (!string.IsNullOrEmpty(str))
  681. {
  682. pList.Add(str);
  683. }
  684. }
  685. if (pList.Count > 0)
  686. {
  687. SqlTxt = string.Format(FormatSql, pList.ToArray());
  688. }
  689. else
  690. {
  691. SqlTxt = FormatSql;
  692. }
  693. }
  694. if (SqlTxt.Contains("[AppConfig.WorkPointCode]"))
  695. {
  696. SqlTxt = SqlTxt.Replace("[AppConfig.WorkPointCode]", oo.Location);
  697. }
  698. if (SqlTxt.Contains("[AppConfig.UserId]"))
  699. {
  700. SqlTxt = SqlTxt.Replace("[AppConfig.UserId]", oo.UserId);
  701. }
  702. if (SqlTxt.Contains("[AppConfig.UserCode]"))
  703. {
  704. SqlTxt = SqlTxt.Replace("[AppConfig.UserCode]", oo.UserCode);
  705. }
  706. if (SqlTxt.Contains("[AppConfig.UserName]"))
  707. {
  708. SqlTxt = SqlTxt.Replace("[AppConfig.UserName]", oo.UserName);
  709. }
  710. if (SqlTxt.Contains("[AppConfig.RoleCode]"))
  711. {
  712. SqlTxt = SqlTxt.Replace("[AppConfig.RoleCode]", oo.RoleEnCode);
  713. }
  714. if (!string.IsNullOrEmpty(TempName))
  715. {
  716. SqlTxt = SqlTxt + " select * from " + TempName + " ";
  717. }
  718. SqlHelper.GetDataTableBySql_OtherConn(SqlTxt, DBName, ref jqgridparam, null);
  719. if (!string.IsNullOrEmpty(TempName))
  720. {
  721. SqlTxt = SqlTxt + " select * from " + TempName + " ";
  722. }
  723. if (!string.IsNullOrEmpty(XCol.Trim()))
  724. {
  725. SqlTxt = SqlTxt + " order by " + XCol.Trim() + " ";
  726. }
  727. Repository().GetDataTableBySql_Other(SqlTxt, DBName, null);
  728. }
  729. catch (Exception ex)
  730. {
  731. throw new Exception(ex.ToString());
  732. }
  733. }
  734. private string ReSetStringTosql(string sql)
  735. {
  736. sql = sql.Replace("'", "''");
  737. sql = sql.Replace("\r", "\r ");
  738. sql = sql.Replace("\r\n", "\r\n ");
  739. sql = sql.Replace("\n", "\n ");
  740. return sql;
  741. }
  742. public void ReSetCols(string MenuID)
  743. {
  744. ReSetFormCols(MenuID);
  745. }
  746. public void ReSetFormCols(string MenuID)
  747. {
  748. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  749. DataTable dt = GetMenuSQL(MenuID);//获取菜单配置信息
  750. if (dt != null && dt.Rows.Count > 0)
  751. {
  752. String SourceID = dt.Rows[0]["SourceID"].ToString();
  753. string SqlText = dt.Rows[0]["SqlTxt"].ToString();
  754. string DBName = dt.Rows[0]["DBName"].ToString();
  755. string TempName = dt.Rows[0]["TempName"].ToString();
  756. //抓取现有列
  757. string sqlcol = @" SELECT * FROM Sys_ColsOfGridReport WHERE SourceID='" + SourceID + "' ";
  758. // ColCaption ColFiledName DataType DefineFlag FunctionString DeciamlNum ColWidth ColMerFlag
  759. //ColMerKeyFlag ColSumFlag HeaderId COrder VisbleFlag SortFlag
  760. DataTable dtcol = Repository().FindTableBySql(sqlcol);
  761. //查询数据
  762. DataTable data = GetGridJsonText(SqlText, DBName, TempName);
  763. if (data != null && data.Columns.Count > 0)
  764. {
  765. string InsertSQL = "";
  766. // DataRow drFirst = data.Rows[0];//首行
  767. for (int i = 0; i < data.Columns.Count; i++)
  768. {
  769. DataRow[] EXISRow = dtcol.Select("ColFiledName='" + data.Columns[i].ColumnName + "'");
  770. if (EXISRow == null || EXISRow.Count() == 0)
  771. {
  772. ColsOfGridClass CC = new ColsOfGridClass();
  773. Type dataType = data.Columns[i].DataType;
  774. #region CC.dataType
  775. if (dataType == typeof(int))
  776. {
  777. CC.DataType = ((int)DataTypeEnum.).ToString();
  778. }
  779. if (dataType == typeof(Int16))
  780. {
  781. CC.DataType = ((int)DataTypeEnum.).ToString();
  782. }
  783. if (dataType == typeof(Int32))
  784. {
  785. CC.DataType = ((int)DataTypeEnum.).ToString();
  786. }
  787. if (dataType == typeof(Int64))
  788. {
  789. CC.DataType = ((int)DataTypeEnum.).ToString();
  790. }
  791. if (dataType == typeof(float))
  792. {
  793. CC.DataType = ((int)DataTypeEnum.).ToString();
  794. }
  795. if (dataType == typeof(Decimal))
  796. {
  797. CC.DataType = ((int)DataTypeEnum.).ToString();
  798. }
  799. if (dataType == typeof(decimal))
  800. {
  801. CC.DataType = ((int)DataTypeEnum.).ToString();
  802. }
  803. if (dataType == typeof(Double))
  804. {
  805. CC.DataType = ((int)DataTypeEnum.).ToString();
  806. }
  807. if (dataType == typeof(double))
  808. {
  809. CC.DataType = ((int)DataTypeEnum.).ToString();
  810. }
  811. if (dataType == typeof(DateTime))
  812. {
  813. CC.DataType = ((int)DataTypeEnum.).ToString();
  814. }
  815. if (dataType == typeof(string))
  816. {
  817. CC.DataType = ((int)DataTypeEnum.).ToString();
  818. }
  819. if (dataType == typeof(String))
  820. {
  821. CC.DataType = ((int)DataTypeEnum.).ToString();
  822. }
  823. if (dataType == typeof(Boolean))
  824. {
  825. CC.DataType = ((int)DataTypeEnum.).ToString();
  826. }
  827. if (dataType == typeof(bool))
  828. {
  829. CC.DataType = ((int)DataTypeEnum.).ToString();
  830. }
  831. #endregion
  832. CC.ColCaption = data.Columns[i].ColumnName;
  833. CC.ColFiledName = data.Columns[i].ColumnName;
  834. CC.DefineFlag = false;
  835. CC.FunctionString = "";
  836. CC.DeciamlNum = 2;
  837. CC.ColWidth = 90;
  838. CC.ColMerFlag = false;
  839. CC.ColMerKeyFlag = false;
  840. CC.ColSumFlag = false;
  841. CC.HeaderId = "";
  842. CC.COrder = i + 1;
  843. CC.VisbleFlag = true;
  844. CC.SortFlag = false;
  845. InsertSQL += @" insert into Sys_ColsOfGridReport
  846. (Id, SourceID , ColCaption, ColFiledName, DataType,
  847. DefineFlag, FunctionString, DeciamlNum, ColWidth, ColMerFlag,
  848. ColMerKeyFlag, ColSumFlag, HeaderId, COrder, VisbleFlag,
  849. SortFlag)
  850. select newid(),'" + SourceID + @"','" + CC.ColCaption + @"','" + CC.ColFiledName + @"','" + CC.DataType + @"',
  851. " + BoolToInt(CC.DefineFlag) + @",'" + ReSetStringTosql(CC.FunctionString) + @"'," + CC.DeciamlNum + @"," + CC.ColWidth + @"," + BoolToInt(CC.ColMerFlag) + @",
  852. " + BoolToInt(CC.ColMerKeyFlag) + @"," + BoolToInt(CC.ColSumFlag) + @",'" + CC.HeaderId + @"','" + CC.COrder.ToString() + @"'," + BoolToInt(CC.VisbleFlag) + @",
  853. " + BoolToInt(CC.SortFlag) + @"
  854. where NOT EXISTS(SELECT 1 FROM Sys_ColsOfGridReport WHERE SourceID='" + SourceID + @"' AND ColCaption='" + CC.ColCaption + @"' )
  855. ";
  856. }
  857. }
  858. StringBuilder sqlb = new StringBuilder(InsertSQL);
  859. Repository().ExecuteBySql(sqlb);
  860. }
  861. }
  862. }
  863. private int BoolToInt(bool flag)
  864. {
  865. if (flag)
  866. {
  867. return 1;
  868. }
  869. return 0;
  870. }
  871. public DataTable GetCondition(string SourceID)
  872. {
  873. string sql = @" SELECT con.id IDStr, '0' IsNew, CSortSeq 排序,NotNullFlag 必填, CCaption 条件名称, CFiledName 字段名称, CIndex 替代符号,
  874. CDefaultLogStirng , CDataType ,CDefaultLogStirng Data, CDataType Data,
  875. CDefaultValue ,CSelectFlag , CSelectSqlTxt , CSelectSourceId ,
  876. SysDataSourceFlag , ReturnCol ,CSelectSourceId Data
  877. from Sys_FormFilterCondition con
  878. where con.SourceID='" + SourceID + @"' order by CSortSeq";
  879. return Repository().FindTableBySql(sql);
  880. }
  881. public void SetCondition(string SourceID, string List_Condition)
  882. {
  883. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  884. if (!string.IsNullOrEmpty(List_Condition) && List_Condition != "[]")
  885. {
  886. ConditionClass[] list = JsonConvert.DeserializeObject<ConditionClass[]>(List_Condition);
  887. if (list != null)
  888. {
  889. string sql = "";
  890. string sqldel = "";
  891. string sqldel2 = "";
  892. string sqlinsert = "";
  893. string sqlupdate = "";
  894. //@" delete from Sys_FormFilterCondition where SourceID='" + SourceID + @"' ";
  895. foreach (ConditionClass item in list)
  896. {
  897. if (item.ID == "")//insert
  898. {
  899. sqlinsert += @" INSERT INTO [Sys_FormFilterCondition]
  900. ([ID],[SourceID] ,[NotNullFlag],[CCaption],[CFiledName],
  901. [CIndex],[CLogString],[CDefaultLogStirng],[CDataType],[CDefaultValue],
  902. [CSelectFlag],[CSelectSqlTxt],[CSelectSourceID],[SysDataSourceFlag],[ReturnCol],
  903. [CSortSeq] )
  904. select newid(),'" + SourceID + @"'," + item.NotNullFlag + @",'" + item.CCaption + @"','" + ReSetStringTosql(item.CFiledName) + @"',
  905. '" + item.CIndex + @"','" + item.CLogString + @"','" + item.CDefaultLogStirng + @"','" + item.CDataType + @"','" + item.CDefaultValue + @"',
  906. " + item.CSelectFlag + @",'" + ReSetStringTosql(item.CSelectSqlTxt) + @"','" + item.CSelectSourceId + @"'," + item.SysDataSourceFlag + @",'" + item.ReturnCol + @"',
  907. " + item.CSortSeq + @" ";
  908. }
  909. else//update
  910. {
  911. sqlupdate += @" update [Sys_FormFilterCondition]
  912. set
  913. [NotNullFlag]=" + item.NotNullFlag + @",
  914. [CCaption]='" + item.CCaption + @"',
  915. [CFiledName]='" + ReSetStringTosql(item.CFiledName) + @"',
  916. [CIndex]='" + item.CIndex + @"',
  917. [CLogString]='" + item.CLogString + @"',
  918. [CDefaultLogStirng]='" + item.CDefaultLogStirng + @"',
  919. [CDataType]='" + item.CDataType + @"',
  920. [CDefaultValue]='" + item.CDefaultValue + @"',
  921. [CSelectFlag]=" + item.CSelectFlag + @",
  922. [CSelectSqlTxt]='" + ReSetStringTosql(item.CSelectSqlTxt) + @"',
  923. [CSelectSourceID]='" + item.CSelectSourceId + @"',
  924. [SysDataSourceFlag]=" + item.SysDataSourceFlag + @",
  925. [ReturnCol]='" + item.ReturnCol + @"',
  926. [CSortSeq]=" + item.CSortSeq + @"
  927. where id='" + item.ID + "' and SourceID='" + SourceID + @"'
  928. ";
  929. sqldel2 += " and FilterID!='" + item.ID + "' ";
  930. sqldel += " and ID!='" + item.ID + "' ";
  931. }
  932. }
  933. sql = @" delete from Sys_FormFilterCondition where SourceID = '" + SourceID + @"' " +
  934. sqldel + sqlupdate + sqlinsert;
  935. sql += " delete from Sys_ColsDefaultRecord where SourceID = '" + SourceID + @"' " + sqldel2;
  936. StringBuilder sqlb = new StringBuilder(sql);
  937. Repository().ExecuteBySql(sqlb);
  938. }
  939. }
  940. else
  941. {
  942. string sql = @" delete from Sys_FormFilterCondition where SourceID='" + SourceID + @"'
  943. delete from Sys_ColsDefaultRecord where SourceID='" + SourceID + @"'";
  944. StringBuilder sqlb = new StringBuilder(sql);
  945. Repository().ExecuteBySql(sqlb);
  946. }
  947. }
  948. public void SetDefaultRecord(string SourceID, string List_Record)
  949. {
  950. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  951. if (!string.IsNullOrEmpty(List_Record) && List_Record != "[]")
  952. {
  953. DefaultRecordClass[] list = JsonConvert.DeserializeObject<DefaultRecordClass[]>(List_Record);
  954. if (list != null)
  955. {
  956. string sql = "delete from Sys_ColsDefaultRecord where SourceID='" + SourceID + @"' ";
  957. foreach (DefaultRecordClass item in list)
  958. {
  959. sql += @" INSERT INTO [dbo].[Sys_ColsDefaultRecord]
  960. ([Id],[SourceId],[FilterID],[F_Account],[CCaption],
  961. [CDefaultLogStirng],[CDefaultValue1],[CDefaultValue2],[WorkPoint],[MUSER],
  962. [MUSERName],[MTIME],[EATTRIBUTE1],[EATTRIBUTE2])
  963. select
  964. newid(),
  965. '" + SourceID + @"',
  966. '" + item.FilterID + @"',
  967. '" + oo.UserCode + @"',
  968. '" + ReSetStringTosql(item.CCaption) + @"',
  969. '" + item.CDefaultLogStirng + @"',
  970. '" + ReSetStringTosql(item.CDefaultValue1) + @"',
  971. '" + ReSetStringTosql(item.CDefaultValue2) + @"',
  972. '" + oo.Location + @"',
  973. '" + oo.UserCode + @"',
  974. '" + oo.UserName + @"',
  975. getdate(),
  976. null,
  977. null
  978. ";
  979. }
  980. StringBuilder sqlb = new StringBuilder(sql);
  981. Repository().ExecuteBySql(sqlb);
  982. }
  983. }
  984. else
  985. {
  986. string sql = @" delete from Sys_ColsDefaultRecord where SourceID='" + SourceID + @"' ";
  987. StringBuilder sqlb = new StringBuilder(sql);
  988. Repository().ExecuteBySql(sqlb);
  989. }
  990. }
  991. public DataTable GetCols(string SourceID)
  992. {
  993. string sql = @" SELECT Id IDStr, SourceID SourceID , ColCaption , ColFiledName , DataType ,
  994. DefineFlag , FunctionString , DeciamlNum , ColWidth , ColMerFlag ,
  995. ColMerKeyFlag , ColSumFlag , HeaderId , COrder , VisbleFlag ,
  996. SortFlag , ColCaption , ColFiledName , DataType , DefineFlag ,
  997. FunctionString , DeciamlNum , ColWidth , ColMerFlag , ColMerKeyFlag as [Key],
  998. ColSumFlag , HeaderId , COrder , VisbleFlag , SortFlag
  999. from Sys_ColsOfGridReport
  1000. where SourceID='" + SourceID + @"' order by COrder ";
  1001. return Repository().FindTableBySql(sql);
  1002. }
  1003. public DataTable GetGridFormat(string ColId)
  1004. {
  1005. string sql = @" SELECT * from Sys_formatofgridreport where ColId='" + ColId + @"' ";
  1006. return Repository().FindTableBySql(sql);
  1007. }
  1008. public void SetCols(string SourceID, string List_Cols)
  1009. {
  1010. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  1011. if (!string.IsNullOrEmpty(List_Cols) && List_Cols != "[]")
  1012. {
  1013. ColsStrOfGridClass[] list = JsonConvert.DeserializeObject<ColsStrOfGridClass[]>(List_Cols);
  1014. if (list != null)
  1015. {
  1016. string sql = "";
  1017. string del_sql = "";
  1018. List<string> IDList = new List<string>();
  1019. string sql_s = @" select id from Sys_ColsOfGridReport where SourceID='" + SourceID + @"' ";
  1020. DataTable dtid = Repository().FindTableBySql(sql_s);
  1021. if (dtid != null && dtid.Rows.Count > 0)
  1022. {
  1023. foreach (DataRow dr in dtid.Rows)
  1024. {
  1025. IDList.Add(dr["id"].ToString());
  1026. }
  1027. }
  1028. foreach (ColsStrOfGridClass item in list)
  1029. {
  1030. if (string.IsNullOrEmpty(item.DefineFlag))
  1031. {
  1032. item.DefineFlag = "0";
  1033. }
  1034. if (string.IsNullOrEmpty(item.DeciamlNum))
  1035. {
  1036. item.DeciamlNum = "2";
  1037. }
  1038. if (string.IsNullOrEmpty(item.ColWidth))
  1039. {
  1040. item.ColWidth = "90";
  1041. }
  1042. if (string.IsNullOrEmpty(item.ColMerFlag))
  1043. {
  1044. item.ColMerFlag = "0";
  1045. }
  1046. if (string.IsNullOrEmpty(item.ColMerKeyFlag))
  1047. {
  1048. item.ColMerKeyFlag = "0";
  1049. }
  1050. if (string.IsNullOrEmpty(item.ColSumFlag))
  1051. {
  1052. item.ColSumFlag = "0";
  1053. }
  1054. if (string.IsNullOrEmpty(item.VisbleFlag))
  1055. {
  1056. item.VisbleFlag = "1";
  1057. }
  1058. if (string.IsNullOrEmpty(item.SortFlag))
  1059. {
  1060. item.SortFlag = "0";
  1061. }
  1062. if (string.IsNullOrEmpty(item.COrder))
  1063. {
  1064. item.COrder = "0";
  1065. }
  1066. if (IDList.Contains(item.Id))
  1067. {
  1068. del_sql += " and id!='" + item.Id + "' ";
  1069. sql += @" update [Sys_ColsOfGridReport]
  1070. set ColCaption='" + item.ColCaption + @"',
  1071. ColFiledName ='" + item.ColFiledName + @"',
  1072. DataType ='" + item.DataType + @"',
  1073. DefineFlag=" + item.DefineFlag + @",
  1074. FunctionString ='" + ReSetStringTosql(item.FunctionString) + @"',
  1075. DeciamlNum =" + item.DeciamlNum + @",
  1076. ColWidth =" + item.ColWidth + @",
  1077. ColMerFlag=" + item.ColMerFlag + @",
  1078. ColMerKeyFlag =" + item.ColMerKeyFlag + @",
  1079. ColSumFlag =" + item.ColSumFlag + @",
  1080. HeaderId ='" + item.HeaderId + @"',
  1081. COrder =" + item.COrder + @",
  1082. VisbleFlag =" + item.VisbleFlag + @",
  1083. SortFlag=" + item.SortFlag + @"
  1084. where SourceID='" + SourceID + @"' and ID='" + item.Id + @"' ";
  1085. }
  1086. else
  1087. {
  1088. sql += @" INSERT INTO [Sys_ColsOfGridReport]
  1089. ([ID],[SourceID], ColCaption , ColFiledName , DataType ,
  1090. DefineFlag , FunctionString , DeciamlNum , ColWidth , ColMerFlag ,
  1091. ColMerKeyFlag , ColSumFlag , HeaderId , COrder , VisbleFlag ,
  1092. SortFlag)
  1093. select newid(),'" + SourceID + @"','" + item.ColCaption + @"','" + item.ColFiledName + @"','" + item.DataType + @"',
  1094. " + item.DefineFlag + @",'" + ReSetStringTosql(item.FunctionString) + @"'," + item.DeciamlNum + @"," + item.ColWidth + @"," + item.ColMerFlag + @",
  1095. " + item.ColMerKeyFlag + @"," + item.ColSumFlag + @",'" + item.HeaderId + @"'," + item.COrder + @"," + item.VisbleFlag + @",
  1096. " + item.SortFlag + @" ";
  1097. }
  1098. }
  1099. if (!string.IsNullOrEmpty(del_sql))
  1100. {
  1101. del_sql = @"
  1102. ----sys_ColsOfGridReport Sys_formatofgridreport
  1103. delete from Sys_formatofgridreport
  1104. where ColId in(select id from sys_ColsOfGridReport where SourceID='" + SourceID + @"' " + del_sql + @" )
  1105. delete from sys_ColsOfGridReport where SourceID='" + SourceID + @"' " + del_sql;
  1106. }
  1107. sql = del_sql + sql;
  1108. StringBuilder sqlb = new StringBuilder(sql);
  1109. Repository().ExecuteBySql(sqlb);
  1110. }
  1111. else
  1112. {
  1113. string sql_D = @" DELETE from Sys_ColsOfGridReport where SourceID='" + SourceID + @"' ";
  1114. StringBuilder sqlb = new StringBuilder(sql_D);
  1115. Repository().ExecuteBySql(sqlb);
  1116. }
  1117. }
  1118. }
  1119. public void SetGridFormat(string ColId, string List_GridFormat)
  1120. {
  1121. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  1122. if (!string.IsNullOrEmpty(List_GridFormat) && List_GridFormat != "[]")
  1123. {
  1124. GridFormatClass[] list = JsonConvert.DeserializeObject<GridFormatClass[]>(List_GridFormat);
  1125. if (list != null)
  1126. {
  1127. string sql = @" delete from Sys_formatofgridreport where ColId='" + ColId + @"' ";
  1128. foreach (GridFormatClass item in list)
  1129. {
  1130. sql += @" INSERT INTO [Sys_formatofgridreport]
  1131. (ID,ColId,LogStr,SValue,DValue,Color,AllRowFlag)
  1132. select newid(),'" + ColId + @"','" + item.LogStr + @"','" + item.SValue + @"','" + item.DValue + @"',
  1133. '" + item.Color + @"', " + item.AllRowFlag + @" ";
  1134. }
  1135. StringBuilder sqlb = new StringBuilder(sql);
  1136. Repository().ExecuteBySql(sqlb);
  1137. }
  1138. }
  1139. else
  1140. {
  1141. string sql = @" delete from Sys_formatofgridreport where ColId='" + ColId + @"' ";
  1142. StringBuilder sqlb = new StringBuilder(sql);
  1143. Repository().ExecuteBySql(sqlb);
  1144. }
  1145. }
  1146. public DataTable GetFilter(string SourceID)
  1147. {
  1148. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  1149. // 替代符号, 字段名称,数据类型,默认逻辑符号,默认值,条件名称,逻辑符号,起始值,结束值
  1150. string sql = @"
  1151. SELECT con.id FilterID, con.NotNullFlag , con.CCaption , con.CFiledName , con.CIndex ,
  1152. isnull(rr.CDefaultLogStirng,con.CDefaultLogStirng) , con.CDataType , isnull(rr.CDefaultValue1,con.CDefaultValue) ,'' ,
  1153. '' ,'' ,isnull(rr.CDefaultValue2,'') 2,con.CSelectFlag ,con.ReturnCol
  1154. from Sys_FormFilterCondition con
  1155. left join Sys_ColsDefaultRecord rr on rr.FilterID=con.id and rr.F_Account='" + oo.UserCode + @"' and con.SourceID=rr.SourceID
  1156. where con.SourceID='" + SourceID + @"' order by con.CSortSeq";
  1157. return Repository().FindTableBySql(sql);
  1158. }
  1159. // 获取栏位的栏位筛选条件数据
  1160. public DataTable GetColsSelectData(string SourceID, string ColsName, string InputKey)
  1161. {
  1162. string sql = @" SELECT top 1 CSelectSqlTxt ,
  1163. CASE WHEN SysDataSourceFlag= '1' THEN 'connstr'
  1164. ELSE ( SELECT DBSourceName FROM sys_database db WHERE db.id = CSelectSourceID )
  1165. END DBName
  1166. from Sys_FormFilterCondition
  1167. where SourceID='" + SourceID + @"' and CCaption =N'" + ColsName + "' ";
  1168. DataTable dt = Repository().FindTableBySql(sql);
  1169. if (dt != null && dt.Rows.Count > 0)
  1170. {
  1171. string sqlcols = dt.Rows[0]["CSelectSqlTxt"].ToString();
  1172. string DBName = dt.Rows[0]["DBName"].ToString();
  1173. sqlcols = string.Format(sqlcols, InputKey);
  1174. DataTable dtcols = SqlHelper.GetDataTableBySql_OtherConn(sqlcols, DBName, null);
  1175. return dtcols;
  1176. }
  1177. return null;
  1178. }
  1179. public string GetColsSelectCols(DataTable dt)
  1180. {
  1181. if (dt != null && dt.Columns.Count > 0)
  1182. {
  1183. Object[] colModel = new Object[dt.Columns.Count + 1];
  1184. for (int i = 0; i < dt.Columns.Count; i++)
  1185. {
  1186. string ColCaption = dt.Columns[i].ColumnName;
  1187. string ColFiledName = dt.Columns[i].ColumnName;
  1188. var col = new Object();
  1189. col = new
  1190. {
  1191. label = ColCaption,
  1192. name = ColFiledName,
  1193. align = "left",
  1194. };
  1195. colModel[i] = col;
  1196. }
  1197. var collast = new { label = "", name = "", width = "20", align = "left" };
  1198. colModel[dt.Columns.Count] = collast;
  1199. return colModel.ToJson();
  1200. }
  1201. return "";
  1202. }
  1203. public void ClearAll(string MenuID)
  1204. {
  1205. string sql = @" DECLARE @SourceId VARCHAR (100)
  1206. SELECT @SourceId=id FROM Sys_FormDataSource WHERE menuid='" + MenuID + @"'
  1207. DELETE FROM Sys_formatofgridreport WHERE colid IN (SELECT id FROM Sys_ColsOfGridReport WHERE SourceId=@SourceId)
  1208. DELETE FROM Sys_HeaderOfGridReport WHERE Sourceid=@SourceId
  1209. DELETE FROM Sys_FormFilterCondition WHERE SourceId=@SourceId
  1210. DELETE FROM Sys_ColsOfGridReport WHERE SourceId=@SourceId
  1211. delete from Sys_FormDataSource WHERE id=@SourceId
  1212. delete from Sys_ColsDefaultRecord where SourceId=@SourceId ";
  1213. StringBuilder sqlb = new StringBuilder(sql);
  1214. Repository().ExecuteBySql(sqlb);
  1215. }
  1216. public DataTable GetColsVisible(string MenuID, string Roles, string Cols, ref Pagination jqgridparam)
  1217. {
  1218. string sql = @" select cc.ID,FieldName 列字段, mm.f_fullname 角色 from Sys_FormColsVisible cc
  1219. left join Sys_SRM_role mm on mm.f_id =cc.RoleId where cc.MenuId='" + MenuID + "' ";
  1220. if (!string.IsNullOrEmpty(Roles.Trim()))
  1221. {
  1222. sql += " and cc.RoleId in('" + Roles.Replace(",", "','") + "') ";
  1223. }
  1224. if (!string.IsNullOrEmpty(Cols.Trim()))
  1225. {
  1226. sql += " and FieldName in('" + Cols.Replace(",", "','") + "') ";
  1227. }
  1228. DataTable dt = Repository().FindTablePageBySql(sql, ref jqgridparam);
  1229. return dt;
  1230. }
  1231. public DataTable GetRoles()
  1232. {
  1233. string sql = @" select distinct mm.f_fullname Roles,f_id RolesID from Sys_SRM_role mm order by mm.f_fullname";
  1234. DataTable dt = Repository().FindTableBySql(sql);
  1235. return dt;
  1236. }
  1237. public DataTable GetColsFiledName(string MenuID)
  1238. {
  1239. string sql = @" select distinct cc.ColFiledName FiledName from Sys_SRM_Module mm
  1240. left join Sys_FormDataSource ss on ss.menuid=mm.f_id
  1241. left join Sys_ColsOfGridReport cc on cc.SourceId=ss.id and cc.visbleflag=1
  1242. where mm.f_id='" + MenuID + @"'
  1243. and isnull(cc.ColFiledName ,'')!='' order by cc.ColFiledName";
  1244. DataTable dt = Repository().FindTableBySql(sql);
  1245. return dt;
  1246. }
  1247. public void SetColsVisibleALL(string Cols, string IsCommon, string MenuID)
  1248. {
  1249. if (IsCommon == "Y")//通用报表
  1250. {
  1251. string sql = @" delete from Sys_FormColsVisible where MenuId='" + MenuID + @"'
  1252. insert into Sys_FormColsVisible(ID ,MenuId ,RoleId ,FieldName, VisibleFlag, WorkPoint)
  1253. select newid(),'" + MenuID + @"',RoleId,FiledName,1,'001'
  1254. from (
  1255. select distinct cc.ColFiledName FiledName ,rr.f_fullname,rr.f_id RoleId
  1256. from Sys_SRM_Module mm
  1257. left join Sys_FormDataSource ss on ss.menuid=mm.f_id
  1258. left join Sys_ColsOfGridReport cc on cc.SourceId=ss.id and cc.visbleflag=1
  1259. left join Sys_SRM_role rr on 1=1
  1260. where 1=1
  1261. and mm.f_id='" + MenuID + @"'
  1262. and isnull(cc.ColFiledName ,'')!=''
  1263. ) fff
  1264. ";
  1265. StringBuilder sqlb = new StringBuilder(sql);
  1266. Repository().ExecuteBySql(sqlb);
  1267. }
  1268. else//非通用报表
  1269. {
  1270. if (!string.IsNullOrEmpty(Cols))
  1271. {
  1272. string sql2 = @" delete from Sys_FormColsVisible where MenuId='" + MenuID + @"'
  1273. ";
  1274. sql2 += @" insert into Sys_FormColsVisible(ID ,MenuId ,RoleId ,FieldName, VisibleFlag, WorkPoint)
  1275. select newid(),'" + MenuID + @"',RoleId,FiledName,1,'001'
  1276. from (
  1277. select distinct DDD.FiledName , rr.f_id RoleId
  1278. from (select distinct cc.items FiledName
  1279. from [dbo].[splitl]('" + Cols.Trim() + @"',',') cc
  1280. where isnull(cc.items,'')!='' ) DDD
  1281. left join Sys_SRM_role rr on 1=1
  1282. ) fff
  1283. ";
  1284. StringBuilder sqlb2 = new StringBuilder(sql2);
  1285. Repository().ExecuteBySql(sqlb2);
  1286. }
  1287. }
  1288. }
  1289. public void SetColsVisibleAdd(string Cols, string Roles, string MenuID)
  1290. {
  1291. if (!string.IsNullOrEmpty(Cols.Trim()) && !string.IsNullOrEmpty(Roles.Trim()))
  1292. {
  1293. string sql2 = @"
  1294. insert into Sys_FormColsVisible(ID ,MenuId ,RoleId ,FieldName, VisibleFlag, WorkPoint)
  1295. select newid(),'" + MenuID + @"',rr.items RoleId,cc.items FiledName,1,'001'
  1296. from [dbo].[splitl]('" + Cols.Trim() + @"',',') cc
  1297. left join [dbo].[splitl]('" + Roles.Trim() + @"',',') rr on 1=1
  1298. where isnull(cc.items,'')!=''
  1299. and isnull(rr.items,'')!=''
  1300. ";
  1301. StringBuilder sqlb2 = new StringBuilder(sql2);
  1302. Repository().ExecuteBySql(sqlb2);
  1303. }
  1304. }
  1305. public void SetColsVisibleDel(string MenuID, string IDList)
  1306. {
  1307. if (!string.IsNullOrEmpty(IDList))
  1308. {
  1309. string sql2 = @"
  1310. delete from Sys_FormColsVisible where MenuId='" + MenuID + @"'
  1311. and id in('" + IDList.Replace(",", "','") + @"')
  1312. ";
  1313. StringBuilder sqlb2 = new StringBuilder(sql2);
  1314. Repository().ExecuteBySql(sqlb2);
  1315. }
  1316. }
  1317. public DataTable GetHiddenCols(string MenuID, string Cols)
  1318. {
  1319. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  1320. // 栏位权限控制
  1321. string sql2 = @"
  1322. select distinct cc.items Col from [dbo].[splitl]('" + Cols.Trim() + @"',',') cc
  1323. left join Sys_FormColsVisible vv on cc.items=FieldName and vv.menuid='" + MenuID + @"' and vv.RoleId='" + oo.RoleId + @"'
  1324. where vv.id is null
  1325. ";
  1326. DataTable dtcol = Repository().FindTableBySql(sql2);
  1327. return dtcol;
  1328. }
  1329. public string GetFilePath()
  1330. {
  1331. string FilePath="";
  1332. try
  1333. {
  1334. FilePath = ConfigurationManager.ConnectionStrings["FilePath"].ConnectionString;
  1335. }
  1336. catch (Exception ex)
  1337. {
  1338. if (ex.Message!="")
  1339. {
  1340. FilePath = "";
  1341. }
  1342. }
  1343. return FilePath;
  1344. }
  1345. }
  1346. }