IwbLinkQuery.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Collections;
  2. using System.Data;
  3. using IwbZero.ToolCommon.StringModel;
  4. namespace IwbZero.IwbDataQuery
  5. {
  6. public class IwbLinkQuery
  7. {
  8. private readonly ArrayList _CascadeFields;
  9. private readonly string _ChildLinkFields;
  10. public IwbQuery _ChildQuery { get; private set; }
  11. private readonly ArrayList _LinkFields;
  12. private readonly string _MyLinkFields;
  13. public IwbLinkQuery(string pcLinkMappings, string pcCascadeValues, IwbQuery poChildQuery)
  14. {
  15. _LinkFields = pcLinkMappings.MappingToArrayList();
  16. _CascadeFields = pcCascadeValues.MappingToArrayList();
  17. _MyLinkFields = "";
  18. _ChildLinkFields = "";
  19. foreach (IwbIdName name in _LinkFields)
  20. {
  21. _MyLinkFields = _MyLinkFields + ((_MyLinkFields == "") ? "" : ",") + name.Name;
  22. _ChildLinkFields = _ChildLinkFields + ((_ChildLinkFields == "") ? "" : ",") + name.Id;
  23. }
  24. _ChildQuery = poChildQuery;
  25. }
  26. public void CascadeFieldValues(IwbQuery poParent, DataRow poParentRow, string pcColumn, string pcNewValue, string pcOldValue)
  27. {
  28. pcColumn = pcColumn.UAndT();
  29. foreach (IwbIdName name in _CascadeFields)
  30. {
  31. if (name.Name.UAndT() == pcColumn)
  32. {
  33. CascadeValueForField(poParent, poParentRow, pcColumn, pcNewValue, name.Id);
  34. }
  35. }
  36. foreach (IwbIdName name2 in _LinkFields)
  37. {
  38. if (name2.Name.UAndT() == pcColumn)
  39. {
  40. CascadeValueForField(poParent, poParentRow, pcColumn, pcNewValue, name2.Id);
  41. }
  42. }
  43. }
  44. private void CascadeValueForField(IwbQuery poParent, DataRow poParentRow, string pcParentColumn, string pcNewValue, string pcChildColumn)
  45. {
  46. string fieldValues = poParent.GetFieldValues(_MyLinkFields, poParentRow);
  47. foreach (DataRow row in _ChildQuery.CurrentTable.Rows)
  48. {
  49. if (((row.RowState != DataRowState.Deleted) && (row.RowState != DataRowState.Detached)) && _ChildQuery.IsValuesMatch(row, _ChildLinkFields, fieldValues))
  50. {
  51. _ChildQuery.SetField(pcChildColumn, pcNewValue, row);
  52. }
  53. }
  54. }
  55. }
  56. }