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.

1531 lines
67 KiB

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