Exemplo n.º 1
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="clientRow"></param>
    /// <param name="proposedActive"></param>
    /// <param name="message"></param>
    /// <param name="reasonRequired"></param>
    /// <param name="reason"></param>
    /// <returns>true = save was allowed, false = further action required</returns>
    public bool CheckClientActiveRules(DataRowView clientRow, bool proposedActive, out string message, out bool reasonRequired, string reason = null)
    {
      //nugget: this DataTable.ColumnChanging => Exception based approach doesn't really work out... 
      //nugget: good to document and remember since it's conceptually appealing
      //nugget: unfortunately the UI checkbox still flips itself even if the underlying field doesn't
      //nugget: DataTable.ColumnChanging: if (error) { e.Row.CancelEdit(); e.Row.SetColumnError(e.Column, err); throw (new Exception(err)); }

      message = null;
      reasonRequired = false;

      //sponsor rules...
      if (clientRow.Field<bool>("IsSponsor"))
      {
        //make sure not PCS'ed, which should be resolved via PCS specific logic elsewhere
        if (IsPCS) 
        {
          message = "Resolving PCS status will clear de-active.";
          return (false);
        }
        //otherwise get Reason for hitting Active ...
        if (reason == null) //... and no reason has been provided yet, ...
        {
          message = !proposedActive ? "Why deactivating this Household?\n(if Suspension or PCS, use those buttons)" :
                                                                                                                      "Why allowing this Household to be active again?";
          reasonRequired = true; // indicate reason required
          return (false);
        }

// ReSharper disable InconsistentNaming
        using (var Sponsor_Active_u = new iTRAACProc("Sponsor_Active_u"))
// ReSharper restore InconsistentNaming
        {
          Sponsor_Active_u["@SponsorGUID"] = GUID;
          Sponsor_Active_u["@RemarkTypeId"] = 23 * (!proposedActive ? 1 : -1); //! necessary because it's a "deactivated" oriented status 
          Sponsor_Active_u["@Reason"] = reason;
          CacheTables(Sponsor_Active_u);
        }
        if (!proposedActive) ShowDeactiveMembers = true;
        OnPropertyChanged("ShowDeactiveMembers");
        HouseMembers = HouseMembers; //for some reason OnPropertyChanged("HouseMembers") didn't refresh the Members Grid, i don't have a good guess but this little hack worked immediately so i'm moving on
        OnPropertyChanged("Fields");

        return (true); //no further processing desired after special sponsor level sproc
      }

      //spousal rules...
      //if attempting to deactivate spouse, let them know the rules...
      if (clientRow.Field<bool>("IsSpouse") && !proposedActive)
      {
        message = "Only valid way to deactivate Spouse is by *official* divorce (\"Legal Separation\" is not sufficient).\r\n"+
                  "Use the hidden Divorce button to the left of the Spouse.";
        return (false);
      }

        //if this is just a fresh new row the user doesn't want to fill out, just whack it straight away
      if (clientRow.Row.RowState == DataRowState.Added)
      {
        clientRow.DetachRow();
        //can't track an IsModified "undo" anymore now that i've had to move to a flat property that's set by everything that can be dirty:
        //OnPropertyChanged("IsModified");
        return (true);
      }

      //finally!  set the flag... 
      clientRow.Row.SetReadonlyField("Active", proposedActive);
      OnPropertyChanged("DependentsSelectionList");
      IsModified = true;
      return (true); //return success
    }
Exemplo n.º 2
0
    static public void Remove(DataRowView remarkRow, string comments)
    {
      //if this remark row hasn't been saved to the DB yet, then just whack it here client side and forget about it
      if (remarkRow.Row.RowState == DataRowState.Added)
      {
        remarkRow.DetachRow();
        return;
      }

      remarkRow.Row.SetReadonlyField("DeleteReason", comments);

      /* this going straight to the DB approach was a little overzealous i think...
      RemarkRow.AcceptChanges(); //nix the dirty flag for this edit because we're saving to DB immediately

      //can't using() because scope drops and nulls out the Proc object out before the background thread executes
      //but ExecuteNonQueryBackground() calls Dispose when it's done so should be ok
      iTRAACProc Remark_d = new iTRAACProc("Remark_d");
      Remark_d["@RemarkGUID"] = RemarkRow["RowGUID"];
      Remark_d["@Reason"] = Comments;
      Remark_d.ExecuteNonQueryBackground("Delete Remark: ", false);
      */
    }