private void ConverBtn_Click(object sender, EventArgs e) { mileHandler = new MileHandler(); yardHandler = new YardHandler(); footHandler = new FootHandler(); mileHandler.SetSuccessor(yardHandler); yardHandler.SetSuccessor(footHandler); bool isGoodParse = Double.TryParse(kiloTextBox.Text, out double input); if (!isGoodParse) { MessageBox.Show("Not Valid Input!"); } else { string selectedUnit = Spinner.Text; conversionRequest = new ConversionRequest(input); conversionRequest.Unit = selectedUnit; mileHandler.HandleConversion(conversionRequest); mileHandler.DecoratedOutput = conversionRequest.Output.ToString(); HandlerDecorator handlerDecorator = new HandlerDecorator(); handlerDecorator.conversionHandler = mileHandler = new RoundDecorator(mileHandler); mileHandler = new ExpDecorator(mileHandler); mileHandler = new UnitDecorator(mileHandler); SolutionBox.Text = mileHandler.DecoratedOutput; } }
public RoundDecorator(ConversionHandler conversionHandler) { this.conversionHandler = conversionHandler; this.conversionHandler.DecoratedOutput = Math.Round(Double.Parse(this.conversionHandler.DecoratedOutput), 2).ToString(); }
public ExpDecorator(ConversionHandler conversionHandler) { this.conversionHandler = conversionHandler; this.conversionHandler.DecoratedOutput = (Double.Parse(conversionHandler.DecoratedOutput)).ToString("e"); }