纽威
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

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