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.

1639 lines
71 KiB

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