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

1528 lines
67 KiB

3 years 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
  549. FROM Sys_SRM_Module mm
  550. left join Sys_FormDataSource ss on mm.f_id=ss.MenuID
  551. where mm.f_id='" + MenuID + @"' ";
  552. DataTable dt = Repository().FindTableBySql(sql);
  553. string SqlTxt = "";
  554. string[] strs = DbParameters.Split(',');
  555. if (strs.Length == 0)
  556. {
  557. SqlTxt = FormatSql;
  558. }
  559. else
  560. {
  561. List<string> pList = new List<string>();
  562. foreach (string str in strs)
  563. {
  564. if (!string.IsNullOrEmpty(str))
  565. {
  566. pList.Add(str);
  567. }
  568. }
  569. if (pList.Count > 0)
  570. {
  571. SqlTxt = string.Format(FormatSql, pList.ToArray());
  572. }
  573. else
  574. {
  575. SqlTxt = FormatSql;
  576. }
  577. }
  578. if (dt != null && dt.Rows.Count > 0 && !string.IsNullOrEmpty(dt.Rows[0]["id"].ToString()))
  579. {
  580. string sqlupdate = @" update Sys_FormDataSource
  581. set SqlTxt=N'" + ReSetStringTosql(SqlTxt) + @"',
  582. SysDataSourceFlag='" + SysDataSourceFlag + @"',
  583. DbId='" + DbId + @"',
  584. FormatSql='" + ReSetStringTosql(FormatSql) + @"',
  585. DbParameters='" + DbParameters + @"',
  586. TempName='" + TempName + @"',
  587. XCol='" + ReSetStringTosql(XCol) + @"'
  588. WHERE ID='" + SourceID + @"' ";
  589. StringBuilder sqlb = new StringBuilder(sqlupdate);
  590. Repository().ExecuteBySql(sqlb);
  591. }
  592. else
  593. {
  594. if (!string.IsNullOrEmpty(MenuID))
  595. {
  596. string sqlupdate = @" insert into Sys_FormDataSource
  597. (ID,MenuId,FilterButtonName,SysDataSourceFlag,DbId,
  598. SqlTxt,FormatSql,DbParameters,AllowDbClickFlag,FormParameters,
  599. DbClickMenuId,RowIndexWidth,ShowRowIndexFlag,ManyHeaderFlag,TempName,
  600. XCol)
  601. select '" + SourceID + @"','" + MenuID + @"','btnConfig','" + SysDataSourceFlag + @"','" + DbId + @"'
  602. ,'" + ReSetStringTosql(SqlTxt) + @"','" + ReSetStringTosql(FormatSql) + @"','" + DbParameters + @"','0',''
  603. ,'',35,'1','0' ,'" + TempName + @"',
  604. '" + ReSetStringTosql(XCol) + @"' ";
  605. StringBuilder sqlb = new StringBuilder(sqlupdate);
  606. Repository().ExecuteBySql(sqlb);
  607. }
  608. else
  609. {
  610. throw new Exception("菜单信息异常:未找到菜单");
  611. }
  612. }
  613. //重新生成列信息
  614. // ReSetFormCols(MenuID);
  615. }
  616. public void SetDataSourceText(string SysDataSourceFlag, string FormatSql, string DbId, string DbParameters, string TempName, string XCol)
  617. {
  618. try
  619. {
  620. Pagination jqgridparam = new Pagination();
  621. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  622. string DBName = "connstr";
  623. if (SysDataSourceFlag != "1")
  624. {
  625. string sql = @" SELECT DBSourceName FROM sys_database db WHERE db.id = '" + DbId + @" ' ";
  626. DataTable dt = Repository().FindTableBySql(sql);
  627. if (dt != null && dt.Rows.Count > 0)
  628. {
  629. DBName = dt.Rows[0][0].ToString();
  630. }
  631. else
  632. {
  633. throw new Exception("查找数据库异常");
  634. }
  635. }
  636. string SqlTxt = "";
  637. string[] strs = DbParameters.Split(',');
  638. if (strs.Length == 0)
  639. {
  640. SqlTxt = FormatSql;
  641. }
  642. else
  643. {
  644. List<string> pList = new List<string>();
  645. foreach (string str in strs)
  646. {
  647. if (!string.IsNullOrEmpty(str))
  648. {
  649. pList.Add(str);
  650. }
  651. }
  652. if (pList.Count > 0)
  653. {
  654. SqlTxt = string.Format(FormatSql, pList.ToArray());
  655. }
  656. else
  657. {
  658. SqlTxt = FormatSql;
  659. }
  660. }
  661. if (SqlTxt.Contains("[AppConfig.WorkPointCode]"))
  662. {
  663. SqlTxt = SqlTxt.Replace("[AppConfig.WorkPointCode]", oo.Location);
  664. }
  665. if (SqlTxt.Contains("[AppConfig.UserId]"))
  666. {
  667. SqlTxt = SqlTxt.Replace("[AppConfig.UserId]", oo.UserId);
  668. }
  669. if (SqlTxt.Contains("[AppConfig.UserCode]"))
  670. {
  671. SqlTxt = SqlTxt.Replace("[AppConfig.UserCode]", oo.UserCode);
  672. }
  673. if (SqlTxt.Contains("[AppConfig.UserName]"))
  674. {
  675. SqlTxt = SqlTxt.Replace("[AppConfig.UserName]", oo.UserName);
  676. }
  677. if (!string.IsNullOrEmpty(TempName))
  678. {
  679. SqlTxt = SqlTxt + " select * from " + TempName + " ";
  680. }
  681. SqlHelper.GetDataTableBySql_OtherConn(SqlTxt, DBName, ref jqgridparam, null);
  682. if (!string.IsNullOrEmpty(TempName))
  683. {
  684. SqlTxt = SqlTxt + " select * from " + TempName + " ";
  685. }
  686. if (!string.IsNullOrEmpty(XCol.Trim()))
  687. {
  688. SqlTxt = SqlTxt + " order by " + XCol.Trim() + " ";
  689. }
  690. Repository().GetDataTableBySql_Other(SqlTxt, DBName, null);
  691. }
  692. catch (Exception ex)
  693. {
  694. throw new Exception(ex.ToString());
  695. }
  696. }
  697. private string ReSetStringTosql(string sql)
  698. {
  699. sql = sql.Replace("'", "''");
  700. sql = sql.Replace("\r", "\r ");
  701. sql = sql.Replace("\r\n", "\r\n ");
  702. sql = sql.Replace("\n", "\n ");
  703. return sql;
  704. }
  705. public void ReSetCols(string MenuID)
  706. {
  707. ReSetFormCols(MenuID);
  708. }
  709. public void ReSetFormCols(string MenuID)
  710. {
  711. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  712. DataTable dt = GetMenuSQL(MenuID);//获取菜单配置信息
  713. if (dt != null && dt.Rows.Count > 0)
  714. {
  715. String SourceID = dt.Rows[0]["SourceID"].ToString();
  716. string SqlText = dt.Rows[0]["SqlTxt"].ToString();
  717. string DBName = dt.Rows[0]["DBName"].ToString();
  718. string TempName = dt.Rows[0]["TempName"].ToString();
  719. //抓取现有列
  720. string sqlcol = @" SELECT * FROM Sys_ColsOfGridReport WHERE SourceID='" + SourceID + "' ";
  721. // ColCaption ColFiledName DataType DefineFlag FunctionString DeciamlNum ColWidth ColMerFlag
  722. //ColMerKeyFlag ColSumFlag HeaderId COrder VisbleFlag SortFlag
  723. DataTable dtcol = Repository().FindTableBySql(sqlcol);
  724. //查询数据
  725. DataTable data = GetGridJsonText(SqlText, DBName, TempName);
  726. if (data != null && data.Columns.Count > 0)
  727. {
  728. string InsertSQL = "";
  729. // DataRow drFirst = data.Rows[0];//首行
  730. for (int i = 0; i < data.Columns.Count; i++)
  731. {
  732. DataRow[] EXISRow = dtcol.Select("ColFiledName='" + data.Columns[i].ColumnName + "'");
  733. if (EXISRow == null || EXISRow.Count() == 0)
  734. {
  735. ColsOfGridClass CC = new ColsOfGridClass();
  736. Type dataType = data.Columns[i].DataType;
  737. #region CC.dataType
  738. if (dataType == typeof(int))
  739. {
  740. CC.DataType = ((int)DataTypeEnum.).ToString();
  741. }
  742. if (dataType == typeof(Int16))
  743. {
  744. CC.DataType = ((int)DataTypeEnum.).ToString();
  745. }
  746. if (dataType == typeof(Int32))
  747. {
  748. CC.DataType = ((int)DataTypeEnum.).ToString();
  749. }
  750. if (dataType == typeof(Int64))
  751. {
  752. CC.DataType = ((int)DataTypeEnum.).ToString();
  753. }
  754. if (dataType == typeof(float))
  755. {
  756. CC.DataType = ((int)DataTypeEnum.).ToString();
  757. }
  758. if (dataType == typeof(Decimal))
  759. {
  760. CC.DataType = ((int)DataTypeEnum.).ToString();
  761. }
  762. if (dataType == typeof(decimal))
  763. {
  764. CC.DataType = ((int)DataTypeEnum.).ToString();
  765. }
  766. if (dataType == typeof(Double))
  767. {
  768. CC.DataType = ((int)DataTypeEnum.).ToString();
  769. }
  770. if (dataType == typeof(double))
  771. {
  772. CC.DataType = ((int)DataTypeEnum.).ToString();
  773. }
  774. if (dataType == typeof(DateTime))
  775. {
  776. CC.DataType = ((int)DataTypeEnum.).ToString();
  777. }
  778. if (dataType == typeof(string))
  779. {
  780. CC.DataType = ((int)DataTypeEnum.).ToString();
  781. }
  782. if (dataType == typeof(String))
  783. {
  784. CC.DataType = ((int)DataTypeEnum.).ToString();
  785. }
  786. if (dataType == typeof(Boolean))
  787. {
  788. CC.DataType = ((int)DataTypeEnum.).ToString();
  789. }
  790. if (dataType == typeof(bool))
  791. {
  792. CC.DataType = ((int)DataTypeEnum.).ToString();
  793. }
  794. #endregion
  795. CC.ColCaption = data.Columns[i].ColumnName;
  796. CC.ColFiledName = data.Columns[i].ColumnName;
  797. CC.DefineFlag = false;
  798. CC.FunctionString = "";
  799. CC.DeciamlNum = 2;
  800. CC.ColWidth = 90;
  801. CC.ColMerFlag = false;
  802. CC.ColMerKeyFlag = false;
  803. CC.ColSumFlag = false;
  804. CC.HeaderId = "";
  805. CC.COrder = i + 1;
  806. CC.VisbleFlag = true;
  807. CC.SortFlag = false;
  808. InsertSQL += @" insert into Sys_ColsOfGridReport
  809. (Id, SourceID , ColCaption, ColFiledName, DataType,
  810. DefineFlag, FunctionString, DeciamlNum, ColWidth, ColMerFlag,
  811. ColMerKeyFlag, ColSumFlag, HeaderId, COrder, VisbleFlag,
  812. SortFlag)
  813. select newid(),'" + SourceID + @"','" + CC.ColCaption + @"','" + CC.ColFiledName + @"','" + CC.DataType + @"',
  814. " + BoolToInt(CC.DefineFlag) + @",'" + ReSetStringTosql(CC.FunctionString) + @"'," + CC.DeciamlNum + @"," + CC.ColWidth + @"," + BoolToInt(CC.ColMerFlag) + @",
  815. " + BoolToInt(CC.ColMerKeyFlag) + @"," + BoolToInt(CC.ColSumFlag) + @",'" + CC.HeaderId + @"','" + CC.COrder.ToString() + @"'," + BoolToInt(CC.VisbleFlag) + @",
  816. " + BoolToInt(CC.SortFlag) + @"
  817. where NOT EXISTS(SELECT 1 FROM Sys_ColsOfGridReport WHERE SourceID='" + SourceID + @"' AND ColCaption='" + CC.ColCaption + @"' )
  818. ";
  819. }
  820. }
  821. StringBuilder sqlb = new StringBuilder(InsertSQL);
  822. Repository().ExecuteBySql(sqlb);
  823. }
  824. }
  825. }
  826. private int BoolToInt(bool flag)
  827. {
  828. if (flag)
  829. {
  830. return 1;
  831. }
  832. return 0;
  833. }
  834. public DataTable GetCondition(string SourceID)
  835. {
  836. string sql = @" SELECT con.id IDStr, '0' IsNew, CSortSeq 排序,NotNullFlag 必填, CCaption 条件名称, CFiledName 字段名称, CIndex 替代符号,
  837. CDefaultLogStirng , CDataType ,CDefaultLogStirng Data, CDataType Data,
  838. CDefaultValue ,CSelectFlag , CSelectSqlTxt , CSelectSourceId ,
  839. SysDataSourceFlag , ReturnCol ,CSelectSourceId Data
  840. from Sys_FormFilterCondition con
  841. where con.SourceID='" + SourceID + @"' order by CSortSeq";
  842. return Repository().FindTableBySql(sql);
  843. }
  844. public void SetCondition(string SourceID, string List_Condition)
  845. {
  846. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  847. if (!string.IsNullOrEmpty(List_Condition) && List_Condition != "[]")
  848. {
  849. ConditionClass[] list = JsonConvert.DeserializeObject<ConditionClass[]>(List_Condition);
  850. if (list != null)
  851. {
  852. string sql = "";
  853. string sqldel = "";
  854. string sqldel2 = "";
  855. string sqlinsert = "";
  856. string sqlupdate = "";
  857. //@" delete from Sys_FormFilterCondition where SourceID='" + SourceID + @"' ";
  858. foreach (ConditionClass item in list)
  859. {
  860. if (item.ID == "")//insert
  861. {
  862. sqlinsert += @" INSERT INTO [Sys_FormFilterCondition]
  863. ([ID],[SourceID] ,[NotNullFlag],[CCaption],[CFiledName],
  864. [CIndex],[CLogString],[CDefaultLogStirng],[CDataType],[CDefaultValue],
  865. [CSelectFlag],[CSelectSqlTxt],[CSelectSourceID],[SysDataSourceFlag],[ReturnCol],
  866. [CSortSeq] )
  867. select newid(),'" + SourceID + @"'," + item.NotNullFlag + @",'" + item.CCaption + @"','" + ReSetStringTosql(item.CFiledName) + @"',
  868. '" + item.CIndex + @"','" + item.CLogString + @"','" + item.CDefaultLogStirng + @"','" + item.CDataType + @"','" + item.CDefaultValue + @"',
  869. " + item.CSelectFlag + @",'" + ReSetStringTosql(item.CSelectSqlTxt) + @"','" + item.CSelectSourceId + @"'," + item.SysDataSourceFlag + @",'" + item.ReturnCol + @"',
  870. " + item.CSortSeq + @" ";
  871. }
  872. else//update
  873. {
  874. sqlupdate += @" update [Sys_FormFilterCondition]
  875. set
  876. [NotNullFlag]=" + item.NotNullFlag + @",
  877. [CCaption]='" + item.CCaption + @"',
  878. [CFiledName]='" + ReSetStringTosql(item.CFiledName) + @"',
  879. [CIndex]='" + item.CIndex + @"',
  880. [CLogString]='" + item.CLogString + @"',
  881. [CDefaultLogStirng]='" + item.CDefaultLogStirng + @"',
  882. [CDataType]='" + item.CDataType + @"',
  883. [CDefaultValue]='" + item.CDefaultValue + @"',
  884. [CSelectFlag]=" + item.CSelectFlag + @",
  885. [CSelectSqlTxt]='" + ReSetStringTosql(item.CSelectSqlTxt) + @"',
  886. [CSelectSourceID]='" + item.CSelectSourceId + @"',
  887. [SysDataSourceFlag]=" + item.SysDataSourceFlag + @",
  888. [ReturnCol]='" + item.ReturnCol + @"',
  889. [CSortSeq]=" + item.CSortSeq + @"
  890. where id='" + item.ID + "' and SourceID='" + SourceID + @"'
  891. ";
  892. sqldel2 += " and FilterID!='" + item.ID + "' ";
  893. sqldel += " and ID!='" + item.ID + "' ";
  894. }
  895. }
  896. sql = @" delete from Sys_FormFilterCondition where SourceID = '" + SourceID + @"' " +
  897. sqldel + sqlupdate + sqlinsert;
  898. sql += " delete from Sys_ColsDefaultRecord where SourceID = '" + SourceID + @"' " + sqldel2;
  899. StringBuilder sqlb = new StringBuilder(sql);
  900. Repository().ExecuteBySql(sqlb);
  901. }
  902. }
  903. else
  904. {
  905. string sql = @" delete from Sys_FormFilterCondition where SourceID='" + SourceID + @"'
  906. delete from Sys_ColsDefaultRecord where SourceID='" + SourceID + @"'";
  907. StringBuilder sqlb = new StringBuilder(sql);
  908. Repository().ExecuteBySql(sqlb);
  909. }
  910. }
  911. public void SetDefaultRecord(string SourceID, string List_Record)
  912. {
  913. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  914. if (!string.IsNullOrEmpty(List_Record) && List_Record != "[]")
  915. {
  916. DefaultRecordClass[] list = JsonConvert.DeserializeObject<DefaultRecordClass[]>(List_Record);
  917. if (list != null)
  918. {
  919. string sql = "delete from Sys_ColsDefaultRecord where SourceID='" + SourceID + @"' ";
  920. foreach (DefaultRecordClass item in list)
  921. {
  922. sql += @" INSERT INTO [dbo].[Sys_ColsDefaultRecord]
  923. ([Id],[SourceId],[FilterID],[F_Account],[CCaption],
  924. [CDefaultLogStirng],[CDefaultValue1],[CDefaultValue2],[WorkPoint],[MUSER],
  925. [MUSERName],[MTIME],[EATTRIBUTE1],[EATTRIBUTE2])
  926. select
  927. newid(),
  928. '" + SourceID + @"',
  929. '" + item.FilterID + @"',
  930. '" + oo.UserCode + @"',
  931. '" + ReSetStringTosql(item.CCaption) + @"',
  932. '" + item.CDefaultLogStirng + @"',
  933. '" + ReSetStringTosql(item.CDefaultValue1) + @"',
  934. '" + ReSetStringTosql(item.CDefaultValue2) + @"',
  935. '" + oo.Location + @"',
  936. '" + oo.UserCode + @"',
  937. '" + oo.UserName + @"',
  938. getdate(),
  939. null,
  940. null
  941. ";
  942. }
  943. StringBuilder sqlb = new StringBuilder(sql);
  944. Repository().ExecuteBySql(sqlb);
  945. }
  946. }
  947. else
  948. {
  949. string sql = @" delete from Sys_ColsDefaultRecord where SourceID='" + SourceID + @"' ";
  950. StringBuilder sqlb = new StringBuilder(sql);
  951. Repository().ExecuteBySql(sqlb);
  952. }
  953. }
  954. public DataTable GetCols(string SourceID)
  955. {
  956. string sql = @" SELECT Id IDStr, SourceID SourceID , ColCaption , ColFiledName , DataType ,
  957. DefineFlag , FunctionString , DeciamlNum , ColWidth , ColMerFlag ,
  958. ColMerKeyFlag , ColSumFlag , HeaderId , COrder , VisbleFlag ,
  959. SortFlag , ColCaption , ColFiledName , DataType , DefineFlag ,
  960. FunctionString , DeciamlNum , ColWidth , ColMerFlag , ColMerKeyFlag as [Key],
  961. ColSumFlag , HeaderId , COrder , VisbleFlag , SortFlag
  962. from Sys_ColsOfGridReport
  963. where SourceID='" + SourceID + @"' order by COrder ";
  964. return Repository().FindTableBySql(sql);
  965. }
  966. public DataTable GetGridFormat(string ColId)
  967. {
  968. string sql = @" SELECT * from Sys_formatofgridreport where ColId='" + ColId + @"' ";
  969. return Repository().FindTableBySql(sql);
  970. }
  971. public void SetCols(string SourceID, string List_Cols)
  972. {
  973. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  974. if (!string.IsNullOrEmpty(List_Cols) && List_Cols != "[]")
  975. {
  976. ColsStrOfGridClass[] list = JsonConvert.DeserializeObject<ColsStrOfGridClass[]>(List_Cols);
  977. if (list != null)
  978. {
  979. string sql = "";
  980. string del_sql = "";
  981. List<string> IDList = new List<string>();
  982. string sql_s = @" select id from Sys_ColsOfGridReport where SourceID='" + SourceID + @"' ";
  983. DataTable dtid = Repository().FindTableBySql(sql_s);
  984. if (dtid != null && dtid.Rows.Count > 0)
  985. {
  986. foreach (DataRow dr in dtid.Rows)
  987. {
  988. IDList.Add(dr["id"].ToString());
  989. }
  990. }
  991. foreach (ColsStrOfGridClass item in list)
  992. {
  993. if (string.IsNullOrEmpty(item.DefineFlag))
  994. {
  995. item.DefineFlag = "0";
  996. }
  997. if (string.IsNullOrEmpty(item.DeciamlNum))
  998. {
  999. item.DeciamlNum = "2";
  1000. }
  1001. if (string.IsNullOrEmpty(item.ColWidth))
  1002. {
  1003. item.ColWidth = "90";
  1004. }
  1005. if (string.IsNullOrEmpty(item.ColMerFlag))
  1006. {
  1007. item.ColMerFlag = "0";
  1008. }
  1009. if (string.IsNullOrEmpty(item.ColMerKeyFlag))
  1010. {
  1011. item.ColMerKeyFlag = "0";
  1012. }
  1013. if (string.IsNullOrEmpty(item.ColSumFlag))
  1014. {
  1015. item.ColSumFlag = "0";
  1016. }
  1017. if (string.IsNullOrEmpty(item.VisbleFlag))
  1018. {
  1019. item.VisbleFlag = "1";
  1020. }
  1021. if (string.IsNullOrEmpty(item.SortFlag))
  1022. {
  1023. item.SortFlag = "0";
  1024. }
  1025. if (string.IsNullOrEmpty(item.COrder))
  1026. {
  1027. item.COrder = "0";
  1028. }
  1029. if (IDList.Contains(item.Id))
  1030. {
  1031. del_sql += " and id!='" + item.Id + "' ";
  1032. sql += @" update [Sys_ColsOfGridReport]
  1033. set ColCaption='" + item.ColCaption + @"',
  1034. ColFiledName ='" + item.ColFiledName + @"',
  1035. DataType ='" + item.DataType + @"',
  1036. DefineFlag=" + item.DefineFlag + @",
  1037. FunctionString ='" + ReSetStringTosql(item.FunctionString) + @"',
  1038. DeciamlNum =" + item.DeciamlNum + @",
  1039. ColWidth =" + item.ColWidth + @",
  1040. ColMerFlag=" + item.ColMerFlag + @",
  1041. ColMerKeyFlag =" + item.ColMerKeyFlag + @",
  1042. ColSumFlag =" + item.ColSumFlag + @",
  1043. HeaderId ='" + item.HeaderId + @"',
  1044. COrder =" + item.COrder + @",
  1045. VisbleFlag =" + item.VisbleFlag + @",
  1046. SortFlag=" + item.SortFlag + @"
  1047. where SourceID='" + SourceID + @"' and ID='" + item.Id + @"' ";
  1048. }
  1049. else
  1050. {
  1051. sql += @" INSERT INTO [Sys_ColsOfGridReport]
  1052. ([ID],[SourceID], ColCaption , ColFiledName , DataType ,
  1053. DefineFlag , FunctionString , DeciamlNum , ColWidth , ColMerFlag ,
  1054. ColMerKeyFlag , ColSumFlag , HeaderId , COrder , VisbleFlag ,
  1055. SortFlag)
  1056. select newid(),'" + SourceID + @"','" + item.ColCaption + @"','" + item.ColFiledName + @"','" + item.DataType + @"',
  1057. " + item.DefineFlag + @",'" + ReSetStringTosql(item.FunctionString) + @"'," + item.DeciamlNum + @"," + item.ColWidth + @"," + item.ColMerFlag + @",
  1058. " + item.ColMerKeyFlag + @"," + item.ColSumFlag + @",'" + item.HeaderId + @"'," + item.COrder + @"," + item.VisbleFlag + @",
  1059. " + item.SortFlag + @" ";
  1060. }
  1061. }
  1062. if (!string.IsNullOrEmpty(del_sql))
  1063. {
  1064. del_sql = @"
  1065. ----sys_ColsOfGridReport Sys_formatofgridreport
  1066. delete from Sys_formatofgridreport
  1067. where ColId in(select id from sys_ColsOfGridReport where SourceID='" + SourceID + @"' " + del_sql + @" )
  1068. delete from sys_ColsOfGridReport where SourceID='" + SourceID + @"' " + del_sql;
  1069. }
  1070. sql = del_sql + sql;
  1071. StringBuilder sqlb = new StringBuilder(sql);
  1072. Repository().ExecuteBySql(sqlb);
  1073. }
  1074. else
  1075. {
  1076. string sql_D = @" DELETE from Sys_ColsOfGridReport where SourceID='" + SourceID + @"' ";
  1077. StringBuilder sqlb = new StringBuilder(sql_D);
  1078. Repository().ExecuteBySql(sqlb);
  1079. }
  1080. }
  1081. }
  1082. public void SetGridFormat(string ColId, string List_GridFormat)
  1083. {
  1084. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  1085. if (!string.IsNullOrEmpty(List_GridFormat) && List_GridFormat != "[]")
  1086. {
  1087. GridFormatClass[] list = JsonConvert.DeserializeObject<GridFormatClass[]>(List_GridFormat);
  1088. if (list != null)
  1089. {
  1090. string sql = @" delete from Sys_formatofgridreport where ColId='" + ColId + @"' ";
  1091. foreach (GridFormatClass item in list)
  1092. {
  1093. sql += @" INSERT INTO [Sys_formatofgridreport]
  1094. (ID,ColId,LogStr,SValue,DValue,Color,AllRowFlag)
  1095. select newid(),'" + ColId + @"','" + item.LogStr + @"','" + item.SValue + @"','" + item.DValue + @"',
  1096. '" + item.Color + @"', " + item.AllRowFlag + @" ";
  1097. }
  1098. StringBuilder sqlb = new StringBuilder(sql);
  1099. Repository().ExecuteBySql(sqlb);
  1100. }
  1101. }
  1102. else
  1103. {
  1104. string sql = @" delete from Sys_formatofgridreport where ColId='" + ColId + @"' ";
  1105. StringBuilder sqlb = new StringBuilder(sql);
  1106. Repository().ExecuteBySql(sqlb);
  1107. }
  1108. }
  1109. public DataTable GetFilter(string SourceID)
  1110. {
  1111. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  1112. // 替代符号, 字段名称,数据类型,默认逻辑符号,默认值,条件名称,逻辑符号,起始值,结束值
  1113. string sql = @"
  1114. SELECT con.id FilterID, con.NotNullFlag , con.CCaption , con.CFiledName , con.CIndex ,
  1115. isnull(rr.CDefaultLogStirng,con.CDefaultLogStirng) , con.CDataType , isnull(rr.CDefaultValue1,con.CDefaultValue) ,'' ,
  1116. '' ,'' ,isnull(rr.CDefaultValue2,'') 2,con.CSelectFlag ,con.ReturnCol
  1117. from Sys_FormFilterCondition con
  1118. left join Sys_ColsDefaultRecord rr on rr.FilterID=con.id and rr.F_Account='" + oo.UserCode + @"' and con.SourceID=rr.SourceID
  1119. where con.SourceID='" + SourceID + @"' order by con.CSortSeq";
  1120. return Repository().FindTableBySql(sql);
  1121. }
  1122. // 获取栏位的栏位筛选条件数据
  1123. public DataTable GetColsSelectData(string SourceID, string ColsName, string InputKey)
  1124. {
  1125. string sql = @" SELECT top 1 CSelectSqlTxt ,
  1126. CASE WHEN SysDataSourceFlag= '1' THEN 'connstr'
  1127. ELSE ( SELECT DBSourceName FROM sys_database db WHERE db.id = CSelectSourceID )
  1128. END DBName
  1129. from Sys_FormFilterCondition
  1130. where SourceID='" + SourceID + @"' and CCaption =N'" + ColsName + "' ";
  1131. DataTable dt = Repository().FindTableBySql(sql);
  1132. if (dt != null && dt.Rows.Count > 0)
  1133. {
  1134. string sqlcols = dt.Rows[0]["CSelectSqlTxt"].ToString();
  1135. string DBName = dt.Rows[0]["DBName"].ToString();
  1136. sqlcols = string.Format(sqlcols, InputKey);
  1137. DataTable dtcols = SqlHelper.GetDataTableBySql_OtherConn(sqlcols, DBName, null);
  1138. return dtcols;
  1139. }
  1140. return null;
  1141. }
  1142. public string GetColsSelectCols(DataTable dt)
  1143. {
  1144. if (dt != null && dt.Columns.Count > 0)
  1145. {
  1146. Object[] colModel = new Object[dt.Columns.Count + 1];
  1147. for (int i = 0; i < dt.Columns.Count; i++)
  1148. {
  1149. string ColCaption = dt.Columns[i].ColumnName;
  1150. string ColFiledName = dt.Columns[i].ColumnName;
  1151. var col = new Object();
  1152. col = new
  1153. {
  1154. label = ColCaption,
  1155. name = ColFiledName,
  1156. align = "left",
  1157. };
  1158. colModel[i] = col;
  1159. }
  1160. var collast = new { label = "", name = "", width = "20", align = "left" };
  1161. colModel[dt.Columns.Count] = collast;
  1162. return colModel.ToJson();
  1163. }
  1164. return "";
  1165. }
  1166. public void ClearAll(string MenuID)
  1167. {
  1168. string sql = @" DECLARE @SourceId VARCHAR (100)
  1169. SELECT @SourceId=id FROM Sys_FormDataSource WHERE menuid='" + MenuID + @"'
  1170. DELETE FROM Sys_formatofgridreport WHERE colid IN (SELECT id FROM Sys_ColsOfGridReport WHERE SourceId=@SourceId)
  1171. DELETE FROM Sys_HeaderOfGridReport WHERE Sourceid=@SourceId
  1172. DELETE FROM Sys_FormFilterCondition WHERE SourceId=@SourceId
  1173. DELETE FROM Sys_ColsOfGridReport WHERE SourceId=@SourceId
  1174. delete from Sys_FormDataSource WHERE id=@SourceId
  1175. delete from Sys_ColsDefaultRecord where SourceId=@SourceId ";
  1176. StringBuilder sqlb = new StringBuilder(sql);
  1177. Repository().ExecuteBySql(sqlb);
  1178. }
  1179. public DataTable GetColsVisible(string MenuID, string Roles, string Cols, ref Pagination jqgridparam)
  1180. {
  1181. string sql = @" select cc.ID,FieldName 列字段, mm.f_fullname 角色 from Sys_FormColsVisible cc
  1182. left join Sys_SRM_role mm on mm.f_id =cc.RoleId where cc.MenuId='" + MenuID + "' ";
  1183. if (!string.IsNullOrEmpty(Roles.Trim()))
  1184. {
  1185. sql += " and cc.RoleId in('" + Roles.Replace(",", "','") + "') ";
  1186. }
  1187. if (!string.IsNullOrEmpty(Cols.Trim()))
  1188. {
  1189. sql += " and FieldName in('" + Cols.Replace(",", "','") + "') ";
  1190. }
  1191. DataTable dt = Repository().FindTablePageBySql(sql, ref jqgridparam);
  1192. return dt;
  1193. }
  1194. public DataTable GetRoles()
  1195. {
  1196. string sql = @" select distinct mm.f_fullname Roles,f_id RolesID from Sys_SRM_role mm order by mm.f_fullname";
  1197. DataTable dt = Repository().FindTableBySql(sql);
  1198. return dt;
  1199. }
  1200. public DataTable GetColsFiledName(string MenuID)
  1201. {
  1202. string sql = @" select distinct cc.ColFiledName FiledName from Sys_SRM_Module mm
  1203. left join Sys_FormDataSource ss on ss.menuid=mm.f_id
  1204. left join Sys_ColsOfGridReport cc on cc.SourceId=ss.id and cc.visbleflag=1
  1205. where mm.f_id='" + MenuID + @"'
  1206. and isnull(cc.ColFiledName ,'')!='' order by cc.ColFiledName";
  1207. DataTable dt = Repository().FindTableBySql(sql);
  1208. return dt;
  1209. }
  1210. public void SetColsVisibleALL(string Cols, string IsCommon, string MenuID)
  1211. {
  1212. if (IsCommon == "Y")//通用报表
  1213. {
  1214. string sql = @" delete from Sys_FormColsVisible where MenuId='" + MenuID + @"'
  1215. insert into Sys_FormColsVisible(ID ,MenuId ,RoleId ,FieldName, VisibleFlag, WorkPoint)
  1216. select newid(),'" + MenuID + @"',RoleId,FiledName,1,'001'
  1217. from (
  1218. select distinct cc.ColFiledName FiledName ,rr.f_fullname,rr.f_id RoleId
  1219. from Sys_SRM_Module mm
  1220. left join Sys_FormDataSource ss on ss.menuid=mm.f_id
  1221. left join Sys_ColsOfGridReport cc on cc.SourceId=ss.id and cc.visbleflag=1
  1222. left join Sys_SRM_role rr on 1=1
  1223. where 1=1
  1224. and mm.f_id='" + MenuID + @"'
  1225. and isnull(cc.ColFiledName ,'')!=''
  1226. ) fff
  1227. ";
  1228. StringBuilder sqlb = new StringBuilder(sql);
  1229. Repository().ExecuteBySql(sqlb);
  1230. }
  1231. else//非通用报表
  1232. {
  1233. if (!string.IsNullOrEmpty(Cols))
  1234. {
  1235. string sql2 = @" delete from Sys_FormColsVisible where MenuId='" + MenuID + @"'
  1236. ";
  1237. sql2 += @" insert into Sys_FormColsVisible(ID ,MenuId ,RoleId ,FieldName, VisibleFlag, WorkPoint)
  1238. select newid(),'" + MenuID + @"',RoleId,FiledName,1,'001'
  1239. from (
  1240. select distinct DDD.FiledName , rr.f_id RoleId
  1241. from (select distinct cc.items FiledName
  1242. from [dbo].[splitl]('" + Cols.Trim() + @"',',') cc
  1243. where isnull(cc.items,'')!='' ) DDD
  1244. left join Sys_SRM_role rr on 1=1
  1245. ) fff
  1246. ";
  1247. StringBuilder sqlb2 = new StringBuilder(sql2);
  1248. Repository().ExecuteBySql(sqlb2);
  1249. }
  1250. }
  1251. }
  1252. public void SetColsVisibleAdd(string Cols, string Roles, string MenuID)
  1253. {
  1254. if (!string.IsNullOrEmpty(Cols.Trim()) && !string.IsNullOrEmpty(Roles.Trim()))
  1255. {
  1256. string sql2 = @"
  1257. insert into Sys_FormColsVisible(ID ,MenuId ,RoleId ,FieldName, VisibleFlag, WorkPoint)
  1258. select newid(),'" + MenuID + @"',rr.items RoleId,cc.items FiledName,1,'001'
  1259. from [dbo].[splitl]('" + Cols.Trim() + @"',',') cc
  1260. left join [dbo].[splitl]('" + Roles.Trim() + @"',',') rr on 1=1
  1261. where isnull(cc.items,'')!=''
  1262. and isnull(rr.items,'')!=''
  1263. ";
  1264. StringBuilder sqlb2 = new StringBuilder(sql2);
  1265. Repository().ExecuteBySql(sqlb2);
  1266. }
  1267. }
  1268. public void SetColsVisibleDel(string MenuID, string IDList)
  1269. {
  1270. if (!string.IsNullOrEmpty(IDList))
  1271. {
  1272. string sql2 = @"
  1273. delete from Sys_FormColsVisible where MenuId='" + MenuID + @"'
  1274. and id in('" + IDList.Replace(",", "','") + @"')
  1275. ";
  1276. StringBuilder sqlb2 = new StringBuilder(sql2);
  1277. Repository().ExecuteBySql(sqlb2);
  1278. }
  1279. }
  1280. public DataTable GetHiddenCols(string MenuID, string Cols)
  1281. {
  1282. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  1283. // 栏位权限控制
  1284. string sql2 = @"
  1285. select distinct cc.items Col from [dbo].[splitl]('" + Cols.Trim() + @"',',') cc
  1286. left join Sys_FormColsVisible vv on cc.items=FieldName and vv.menuid='" + MenuID + @"' and vv.RoleId='" + oo.RoleId + @"'
  1287. where vv.id is null
  1288. ";
  1289. DataTable dtcol = Repository().FindTableBySql(sql2);
  1290. return dtcol;
  1291. }
  1292. }
  1293. }