예제 #1
0
        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;
            }
        }
예제 #2
0
 public RoundDecorator(ConversionHandler conversionHandler)
 {
     this.conversionHandler = conversionHandler;
     this.conversionHandler.DecoratedOutput =
         Math.Round(Double.Parse(this.conversionHandler.DecoratedOutput), 2).ToString();
 }
예제 #3
0
 public ExpDecorator(ConversionHandler conversionHandler)
 {
     this.conversionHandler = conversionHandler;
     this.conversionHandler.DecoratedOutput =
         (Double.Parse(conversionHandler.DecoratedOutput)).ToString("e");
 }