Beispiel #1
0
        private void appbarbtnCalculate_Click(object sender, EventArgs e)
        {
            double _Pressure           = 0.0f;
            double _Rate               = 0.0f;
            double stdFlowRateOfNozzle = 0f;
            double flowRate            = 0f;
            double _result;
            string _resultText = "Could not compute spray rate.";

            if (string.IsNullOrWhiteSpace(txtNozzleCode.Text))
            {
                MessageBox.Show("A nozzle code is required.\nE.G.: 03 or 025 etc..");
                txtNozzleCode.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(txtInputPressure.Text))
            {
                MessageBox.Show("The spraying pressure is required.");
                txtInputPressure.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(txtInputRate.Text))
            {
                MessageBox.Show("The required spray rate is required.");
                txtInputRate.Focus();
                return;
            }

            if (!double.TryParse(txtInputPressure.Text, out _Pressure))
            {
                MessageBox.Show("The pressure could not be converted to a number.\nEnter the value in bar.");
                txtInputPressure.Focus();
                return;
            }
            ;

            if (!double.TryParse(txtInputRate.Text, out _Rate))
            {
                MessageBox.Show("The required spray rate could not be converted to a number.\nEnter the value in litres / ha");
                txtInputRate.Focus();
                return;
            }
            ;

            if (_Rate <= 0)
            {
                MessageBox.Show("The spray rate must be greater than zero.\nEnter the value in litres / ha");
                txtInputRate.Focus();
                return;
            }
            else
            {
                if (_Pressure <= 0)
                {
                    MessageBox.Show("The pressure must be greater than zero.\nEnter the value for the required pressure in bar");
                    txtInputPressure.Focus();
                    return;
                }
                else
                {
                    Nozzles _nozzles = new Nozzles();
                    stdFlowRateOfNozzle = _nozzles.getStdFlowRate(txtNozzleCode.Text);
                    flowRate            = Spraying.getFlowRate(_Pressure, stdFlowRateOfNozzle);
                    _result             = Spraying.getSpeed(_Rate, flowRate, 0.5f);
                }
            }
            _resultText         = String.Format("The required spraying speed is {0:f1} kph.", _result);
            _resultText         = _resultText + String.Format("\nStandard flow rate of the nozzle is {0:f3} l/min.", stdFlowRateOfNozzle);
            _resultText         = _resultText + String.Format("\nFlow rate at {0:f1} bar is {1:f3} l/min.", _Pressure, flowRate);
            txtOutputSpeed.Text = _resultText;
            this.Focus();
        }
        private async void appbarbtnCalculate_Click(object sender, EventArgs e)
        {
            double _Pressure           = 0.0f;
            double _Rate               = 0.0f;
            double stdFlowRateOfNozzle = 0f;
            double flowRate            = 0f;
            double _result;
            string _resultText = "Could not compute spray rate.";

            if (string.IsNullOrWhiteSpace(txtNozzleCode.Text))
            {
                //Creating instance for the MessageDialog Class
                //and passing the message in it's Constructor
                MessageDialog msgbox = new MessageDialog("A nozzle code is required.\nE.G.: 03 or 025 etc..");
                //Calling the Show method of MessageDialog class
                //which will show the MessageBox
                await msgbox.ShowAsync();

                // return focus to text box
                // txtNozzleCode.GotFocus();
                return;
            }

            if (string.IsNullOrWhiteSpace(txtInputPressure.Text))
            {
                //Creating instance for the MessageDialog Class
                //and passing the message in it's Constructor
                MessageDialog msgbox = new MessageDialog("The spraying pressure is required.");
                //Calling the Show method of MessageDialog class
                //which will show the MessageBox
                await msgbox.ShowAsync();

                // MessageBox.Show("The spraying pressure is required.");
                // txtInputPressure
                return;
            }

            if (string.IsNullOrWhiteSpace(txtInputRate.Text))
            {
                //Creating instance for the MessageDialog Class
                //and passing the message in it's Constructor
                MessageDialog msgbox = new MessageDialog("The required spray rate is required.");
                //Calling the Show method of MessageDialog class
                //which will show the MessageBox
                await msgbox.ShowAsync();

                //                txtInputRate.Focus();
                return;
            }

            if (!double.TryParse(txtInputPressure.Text, out _Pressure))
            {
                //Creating instance for the MessageDialog Class
                //and passing the message in it's Constructor
                MessageDialog msgbox = new MessageDialog("The pressure could not be converted to a number.\nEnter the value in bar.");
                //Calling the Show method of MessageDialog class
                //which will show the MessageBox
                await msgbox.ShowAsync();

                //                txtInputPressure.Focus();
                return;
            }
            ;

            if (!double.TryParse(txtInputRate.Text, out _Rate))
            {
                //Creating instance for the MessageDialog Class
                //and passing the message in it's Constructor
                MessageDialog msgbox = new MessageDialog("The required spray rate could not be converted to a number.\nEnter the value in litres / ha.");
                //Calling the Show method of MessageDialog class
                //which will show the MessageBox
                await msgbox.ShowAsync();

                //                txtInputRate.Focus();
                return;
            }
            ;

            if (_Rate <= 0)
            {
                //Creating instance for the MessageDialog Class
                //and passing the message in it's Constructor
                MessageDialog msgbox = new MessageDialog("The spray rate must be greater than zero.\nEnter the value in litres / ha.");
                //Calling the Show method of MessageDialog class
                //which will show the MessageBox
                await msgbox.ShowAsync();

                //                txtInputRate.Focus();
                return;
            }
            else
            {
                if (_Pressure <= 0)
                {
                    //Creating instance for the MessageDialog Class
                    //and passing the message in it's Constructor
                    MessageDialog msgbox = new MessageDialog("The pressure must be greater than zero.\nEnter the value for the required pressure in bar.");
                    //Calling the Show method of MessageDialog class
                    //which will show the MessageBox
                    await msgbox.ShowAsync();

                    // txtInputPressure.Focus();
                    return;
                }
                else
                {
                    Nozzles _nozzles = new Nozzles();
                    stdFlowRateOfNozzle = _nozzles.getStdFlowRate(txtNozzleCode.Text);
                    flowRate            = Spraying.getFlowRate(_Pressure, stdFlowRateOfNozzle);
                    _result             = Spraying.getSpeed(_Rate, flowRate, 0.5f);
                }
            }
            _resultText         = String.Format("The required spraying speed is {0:f1} kph.", _result);
            _resultText         = _resultText + String.Format("\nStandard flow rate of the nozzle is {0:f3} l/min.", stdFlowRateOfNozzle);
            _resultText         = _resultText + String.Format("\nFlow rate at {0:f1} bar is {1:f3} l/min.", _Pressure, flowRate);
            txtOutputSpeed.Text = _resultText;
            // this.Focus();
        }