| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System.Collections;
- using System.Data;
- using IwbZero.ToolCommon.StringModel;
- namespace IwbZero.IwbDataQuery
- {
- public class IwbLinkQuery
- {
- private readonly ArrayList _CascadeFields;
- private readonly string _ChildLinkFields;
- public IwbQuery _ChildQuery { get; private set; }
- private readonly ArrayList _LinkFields;
- private readonly string _MyLinkFields;
- public IwbLinkQuery(string pcLinkMappings, string pcCascadeValues, IwbQuery poChildQuery)
- {
- _LinkFields = pcLinkMappings.MappingToArrayList();
- _CascadeFields = pcCascadeValues.MappingToArrayList();
- _MyLinkFields = "";
- _ChildLinkFields = "";
- foreach (IwbIdName name in _LinkFields)
- {
- _MyLinkFields = _MyLinkFields + ((_MyLinkFields == "") ? "" : ",") + name.Name;
- _ChildLinkFields = _ChildLinkFields + ((_ChildLinkFields == "") ? "" : ",") + name.Id;
- }
- _ChildQuery = poChildQuery;
- }
- public void CascadeFieldValues(IwbQuery poParent, DataRow poParentRow, string pcColumn, string pcNewValue, string pcOldValue)
- {
- pcColumn = pcColumn.UAndT();
- foreach (IwbIdName name in _CascadeFields)
- {
- if (name.Name.UAndT() == pcColumn)
- {
- CascadeValueForField(poParent, poParentRow, pcColumn, pcNewValue, name.Id);
- }
- }
- foreach (IwbIdName name2 in _LinkFields)
- {
- if (name2.Name.UAndT() == pcColumn)
- {
- CascadeValueForField(poParent, poParentRow, pcColumn, pcNewValue, name2.Id);
- }
- }
- }
- private void CascadeValueForField(IwbQuery poParent, DataRow poParentRow, string pcParentColumn, string pcNewValue, string pcChildColumn)
- {
- string fieldValues = poParent.GetFieldValues(_MyLinkFields, poParentRow);
- foreach (DataRow row in _ChildQuery.CurrentTable.Rows)
- {
- if (((row.RowState != DataRowState.Deleted) && (row.RowState != DataRowState.Detached)) && _ChildQuery.IsValuesMatch(row, _ChildLinkFields, fieldValues))
- {
- _ChildQuery.SetField(pcChildColumn, pcNewValue, row);
- }
- }
- }
- }
- }
|