Esempio n. 1
0
    public void PotentialMatchesSearchExecute(PotentialClientMatchesState state)
    {
// ReSharper disable InconsistentNaming
      Proc Sponsor_New_Search = null;
// ReSharper restore InconsistentNaming
      switch (state.FieldType)
      {
        case PotentialMatchFieldType.SSN:
          Sponsor_New_Search = new Proc("Sponsor_New_SearchSSN");
          Sponsor_New_Search["@SSN1"] = state.ClientRow["SSN1"];
          Sponsor_New_Search["@SSN2"] = state.ClientRow["SSN2"];
          Sponsor_New_Search["@SSN3"] = state.ClientRow["SSN3"];
          break;
        case PotentialMatchFieldType.Name: Sponsor_New_Search = new Proc("Sponsor_New_SearchName");
          Sponsor_New_Search["@FirstName"] = state.ClientRow["FName"];
          Sponsor_New_Search["@LastName"] = state.ClientRow["LName"];
          break;
      }
      Debug.Assert(Sponsor_New_Search != null, "Sponsor_New_Search != null");

      using (Sponsor_New_Search)
      {
        Sponsor_New_Search["@MatchType"] = string.Format("Matched on {0} {1}",
          state.ClientRow.Field<bool>("IsSponsor") ? "Sponsor" :
            state.ClientRow.Field<bool>("IsSpouse") ? "Spouse" :
              "Dependent",
          state.FieldType);

        Sponsor_New_Search.ExecuteDataSet();

        // if this is the first time through, just take sproc result as our backdrop table
        if (PotentialClientMatches == null)
        {
          Sponsor_New_Search.Table0.Columns.Add("RecordCountId", typeof(int)); //backdrop table's RecordCount has to be a real value since a computed Count() would always be the same for all rows in this table
          foreach (DataRow r in Sponsor_New_Search.Table0.Rows) r["RecordCountId"] = Sponsor_New_Search.Table0.Rows.Count; //fyi, can't use expression based count column because that would reflect the total rows 
          PotentialClientMatches = new DataView(Sponsor_New_Search.Table0) {Sort = "RecordCountId, LName, FName"};
          //sort by ascending RecordCount so that the more specific matches are at the top
        }
        else //otherwise, just keep merging new results into the backdrop table
        {
          // clear out any existing match rows of the same match type, because each NewMatches batch of the same type should be considered an entirely new list of hits specific to the most recent inputs
          using (var v = new DataView(PotentialClientMatches.Table))
          {
            v.RowFilter = String.Format("MatchType = '{0}'", Sponsor_New_Search["@MatchType"]);
            v.DetachRowsAndDispose(true);
          }

          Sponsor_New_Search.Table0.Columns.Add("RecordCountId", typeof(int), "Count(LName)"); //bring the new rows in with their own count
          PotentialClientMatches.Table.Merge(Sponsor_New_Search.Table0);
        }
      }

    }
    private void ClearPreviousMatches(string MatchType)
    {
      if (PotentialMatches.Rows.Count == 0) return;

      //clear out any existing match rows of the same match type, because each batch should be considered an entirely new list of hits
      using (DataView v = new DataView(PotentialMatches))
      {
        v.RowFilter = "MatchType = '" + MatchType + "'";
        v.DetachRowsAndDispose();
      }
    }