IwbDataSource.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using IwbZero.IwbBase;
  3. using IwbZero.ToolCommon.StringModel;
  4. namespace IwbZero.IwbDataQuery
  5. {
  6. public class IwbDataSource
  7. {
  8. public IwbDataSource(IwbDsSourceType poDataSourceType, string pcDataSourceId)
  9. {
  10. DataSourceType = poDataSourceType;
  11. DataSourceId = pcDataSourceId;
  12. }
  13. public IwbDataSource(string pcId, string pcName, string pcDataSourceId, IwbDsSourceType peType) :this(peType,pcDataSourceId)
  14. {
  15. AutoOpen = false;
  16. DSId = pcId;
  17. DSName = pcName;
  18. }
  19. public static IwbDataSource ConvertFrom(IwbXmlNode poNode)
  20. {
  21. string childValue = poNode.GetChildValue("Id");
  22. string pcString = poNode.GetChildValue("Content");
  23. string pcName = poNode.GetChildValue("Name");
  24. bool flag = poNode.GetChildValue("Open").StrToBool();
  25. IwbDataSource source = ConvertFrom(pcString);
  26. if (source != null)
  27. {
  28. return new IwbDataSource(childValue, pcName, source.DataSourceId, source.DataSourceType) { AutoOpen = flag };
  29. }
  30. return null;
  31. }
  32. public static IwbDataSource ConvertFrom(string pcId, string pcName, string pcContent)
  33. {
  34. IwbDataSource source = ConvertFrom(pcContent);
  35. if (source != null)
  36. {
  37. return new IwbDataSource(pcId, pcName, source.DataSourceId, source.DataSourceType);
  38. }
  39. return null;
  40. }
  41. public static IwbDataSource ConvertFrom(string pcString)
  42. {
  43. Array array = pcString.StrToArray();
  44. if (array.Length != 2)
  45. {
  46. return null;
  47. }
  48. string str = array.GetValue(0).ToString().UAndT();
  49. IwbDsSourceType table = IwbDsSourceType.Table;
  50. switch (str)
  51. {
  52. case "QUERY":
  53. table = IwbDsSourceType.Query;
  54. break;
  55. case "VIEW":
  56. table = IwbDsSourceType.View;
  57. break;
  58. }
  59. return new IwbDataSource(table, array.GetValue(1).ToString());
  60. }
  61. public string DataSourceToString()
  62. {
  63. return base.ToString();
  64. }
  65. public IwbXmlNode GetXmlNode()
  66. {
  67. IwbXmlNode node = new IwbXmlNode("DataSource", "");
  68. node.AddChild(new IwbXmlNode("Id", DSId));
  69. node.AddChild(new IwbXmlNode("Content", DataSourceToString()));
  70. node.AddChild(new IwbXmlNode("Name", DSName));
  71. node.AddChild(new IwbXmlNode("Open", AutoOpen.ToString()));
  72. return node;
  73. }
  74. public override string ToString()
  75. {
  76. return DSName;
  77. }
  78. public bool AutoOpen { get; set; }
  79. public string DSId { get; }
  80. public string DSName { get; }
  81. public IwbQuery GetData()
  82. {
  83. return GetData(DataSourceId);
  84. }
  85. public IwbQuery GetData(string sourceId)
  86. {
  87. return new IwbQuery(sourceId);
  88. }
  89. public void SaveData()
  90. {
  91. Data.SaveToXml();
  92. }
  93. public IwbQuery Data { get; set; }
  94. public string DataSourceId { get; set; }
  95. public IwbDsSourceType DataSourceType { get; set; }
  96. public bool IsEmpty
  97. {
  98. get
  99. {
  100. if (DataSourceType != IwbDsSourceType.Empty)
  101. {
  102. return (DataSourceId == "");
  103. }
  104. return true;
  105. }
  106. }
  107. }
  108. }