IwbBaseAttribute.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System.Collections;
  2. using System.Data;
  3. namespace IwbZero.IwbDataQuery
  4. {
  5. public class IwbBaseAttribute
  6. {
  7. protected readonly Hashtable _htProperties = new Hashtable();
  8. protected int _rowIndex = -1;
  9. public bool addToTable(DataTable dt)
  10. {
  11. DataRow row;
  12. if (_rowIndex == -1)
  13. {
  14. row = dt.NewRow();
  15. _rowIndex = dt.Rows.Count;
  16. }
  17. else
  18. {
  19. row = dt.Rows[_rowIndex];
  20. }
  21. row.BeginEdit();
  22. for (int i = 0; i < row.Table.Columns.Count; i++)
  23. {
  24. string str = row.Table.Columns[i].ColumnName.ToUpper().Trim();
  25. row[str] = this[str];
  26. }
  27. row.EndEdit();
  28. if (_rowIndex == dt.Rows.Count)
  29. {
  30. dt.Rows.Add(row);
  31. }
  32. return false;
  33. }
  34. public virtual void loadFromDataRow(DataRow dr)
  35. {
  36. _htProperties.Clear();
  37. for (int i = 0; i < dr.Table.Columns.Count; i++)
  38. {
  39. string key = dr.Table.Columns[i].ColumnName.ToUpper().Trim();
  40. _htProperties.Add(key, dr[i]);
  41. }
  42. }
  43. public void loadFromTable(DataTable dt, int index)
  44. {
  45. loadFromDataRow(dt.Rows[index]);
  46. _rowIndex = index;
  47. }
  48. //public void UpdateValueToTable(npTable poFormTable)
  49. //{
  50. // foreach (string str in _htProperties.Keys)
  51. // {
  52. // if (poFormTable.Columns.Contains(str))
  53. // {
  54. // poFormTable.SetField(str, _htProperties[str].ToString());
  55. // }
  56. // }
  57. //}
  58. public object this[string pcColName]
  59. {
  60. get
  61. {
  62. object obj2 = "";
  63. string key = pcColName.Trim().ToUpper();
  64. if (_htProperties.ContainsKey(key))
  65. {
  66. obj2 = _htProperties[key];
  67. }
  68. return obj2;
  69. }
  70. set
  71. {
  72. string key = pcColName.Trim().ToUpper();
  73. if (_htProperties.ContainsKey(key))
  74. {
  75. _htProperties[key] = value;
  76. }
  77. else
  78. {
  79. _htProperties.Add(key, value);
  80. }
  81. }
  82. }
  83. }
  84. }