private void btnApprove_Click(object sender, EventArgs e) { Material material = new Material { MaterialID = Guid.NewGuid(), Name = txtName.Text, PartNumber = txtPartNumber.Text, DrawingNumber = txtDrawingNumber.Text, Budget = decimal.Parse(txtBudget.Text) }; Approver bob = new EngineeringApprover(); Approver ted = new PurchasingApprover(); Approver alice = new FinanceApprover(); bob.SetNextApprover(ted); ted.SetNextApprover(alice); string reason = ""; if (bob.ApproveMaterial(material, ref reason)) { reason = "Approved. " + reason; } else { reason = "Disapproved. " + reason; } txtResult.Text = reason; }
public override bool ApproveMaterial(Material material, ref string reason) { if (material.Budget < 100000) { if (NextApprover != null) { // finance may be the end of the chain, but this allows changes later NextApprover.ApproveMaterial(material, ref reason); } return true; } else { reason = "This is way too much - find another way!"; return false; } }
public override bool ApproveMaterial(Material material, ref string reason) { bool isValid = true; if (string.IsNullOrWhiteSpace(material.DrawingNumber)) { isValid = false; reason = "There is no drawing for this material"; } if (string.IsNullOrWhiteSpace(material.PartNumber)) { isValid = false; reason = "There is no part number for this material"; } if (isValid) { if (NextApprover != null) { return NextApprover.ApproveMaterial(material, ref reason); } } return isValid; }
public abstract bool ApproveMaterial(Material material, ref string reason);