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.

70 lines
2.4 KiB

  1. using System.Collections.Generic;
  2. using System.Collections;
  3. using System.Data;
  4. namespace Swift.DAL.SwiftDAL
  5. {
  6. public class GridDao : SwiftDao
  7. {
  8. public ArrayList GetGridDataSource(string sql, bool hasFilter, bool loadGridOnFilterOnly)
  9. {
  10. var dataSource = new ArrayList();
  11. var columnList = new ArrayList();
  12. List<Hashtable> rows = null;
  13. DataSet ds;
  14. if (loadGridOnFilterOnly)
  15. {
  16. if (hasFilter)
  17. {
  18. ds = ExecuteDataset(sql);
  19. dataSource.Add(ds.Tables[0].Rows[0]["totalRow"].ToString());
  20. rows = new List<Hashtable>();
  21. foreach (DataRow dataRow in ds.Tables[1].Rows)
  22. {
  23. var row = new Hashtable();
  24. foreach (DataColumn dataColumn in ds.Tables[1].Columns)
  25. {
  26. var columnName = dataColumn.ColumnName;
  27. columnList.Add(columnName);
  28. row.Add(columnName.ToLower().Replace(' ', '_'), dataRow[columnName].ToString());
  29. }
  30. rows.Add(row);
  31. }
  32. dataSource.Add(rows);
  33. dataSource.Add(columnList);
  34. }
  35. else
  36. {
  37. dataSource.Add("0");
  38. dataSource.Add(null);
  39. dataSource.Add(null);
  40. }
  41. }
  42. else
  43. {
  44. ds = ExecuteDataset(sql);
  45. dataSource.Add(ds.Tables[0].Rows[0]["totalRow"].ToString());
  46. rows = new List<Hashtable>();
  47. foreach (DataRow dataRow in ds.Tables[1].Rows)
  48. {
  49. var row = new Hashtable();
  50. foreach (DataColumn dataColumn in ds.Tables[1].Columns)
  51. {
  52. var columnName = dataColumn.ColumnName;
  53. columnList.Add(columnName);
  54. row.Add(columnName.ToLower().Replace(' ', '_'), dataRow[columnName].ToString());
  55. }
  56. rows.Add(row);
  57. }
  58. dataSource.Add(rows);
  59. dataSource.Add(columnList);
  60. }
  61. return dataSource;
  62. }
  63. }
  64. }