Beispiel #1
0
        private void btnGoEngine_Click(object sender, EventArgs e)
        {
            StringBuilder stringBuilder    = null;
            string        messageText      = "";
            Exception     exceptionDetails = null;
            Director      director         = null;
            EngineBuilder engineBuilder    = null;

            string[] parameters = null;
            int      value      = 0;
            bool     buildOk    = false;

            string[] lines = null;
            char[]   sep   = new char[] { '\n' };
            try
            {
                ResetListBoxes();
                ResetErrorMessages();
                if ((CheckPartInputs() == true) && (CheckEngineInputs() == true))
                {
                    if (int.TryParse(tbCylinder.Text, out value) == true)
                    {
                        parameters = new string[] { tbYear.Text, cmbMake.SelectedText, tbModel.Text, tbName.Text, value.ToString() };


                        if (parameters != null)
                        {
                            director = new Director();
                            if (director != null)
                            {
                                engineBuilder = new EngineBuilder();
                                if (engineBuilder != null)
                                {
                                    buildOk = director.Construct(engineBuilder, parameters);
                                    if (buildOk == true)
                                    {
                                        if (engineBuilder.BuildResult != null)
                                        {
                                            messageText = engineBuilder.BuildResult.FormatDisplayString();
                                            lines       = messageText.Split(sep);
                                            foreach (string s in lines)
                                            {
                                                lbEngine.Items.Add(s);
                                            }
                                        }
                                        else
                                        {
                                            lbEngine.Items.Add("engineBuilder.BuildResult = null!");
                                        }
                                    }
                                    else
                                    {
                                        lbEngine.Items.Add("buildOk = false!");
                                    }
                                }
                                else
                                {
                                    lbEngine.Items.Add("engineBuilder = null!");
                                }
                            }
                            else
                            {
                                lbEngine.Items.Add("director = null!");
                            }
                        }
                        else
                        {
                            lbEngine.Items.Add("parameters null, couldn't create engine!");
                        }
                    }
                    else
                    {
                        lbEngine.Items.Add("int.tryparse failed, couldn't create engine");
                    }
                }
            }
            catch (Exception exception)
            {
                stringBuilder    = new StringBuilder();
                exceptionDetails = exception;

                while (exceptionDetails != null)
                {
                    messageText = "\r\nMessage: " + exceptionDetails.Message + "\r\nSource: " + exceptionDetails.Source + "\r\nStack Trace: " + exceptionDetails.StackTrace + "\r\n----------\r\n";

                    stringBuilder.Append(messageText);

                    exceptionDetails = exceptionDetails.InnerException;
                }

                messageText = stringBuilder.ToString();
                MessageBox.Show(messageText, "Inheritance - Error", MessageBoxButtons.OK);
            }
        }
Beispiel #2
0
        private void btnGoTransmission_Click(object sender, EventArgs e)
        {
            StringBuilder       stringBuilder       = null;
            string              messageText         = "";
            Exception           exceptionDetails    = null;
            Director            director            = null;
            TransmissionBuilder transmissionBuilder = null;

            string[] parameters = null;
            Boolean  automatic  = false;
            Boolean  manual     = false;
            bool     buildOk    = false;

            string[] lines = null;
            char[]   sep   = new char[] { '\n' };
            try
            {
                ResetListBoxes();
                ResetErrorMessages();
                if ((CheckPartInputs() == true) && (CheckTransmissionInputs() == true))
                {
                    if (rbAutomatic.Checked == true)
                    {
                        automatic = true;
                        manual    = false;
                    }
                    if (rbManual.Checked == true)
                    {
                        automatic = false;
                        manual    = true;
                    }

                    parameters = new string[] { tbYear.Text, cmbMake.SelectedItem.ToString(), tbModel.Text, tbName.Text, automatic.ToString(), manual.ToString() };

                    if (parameters != null)
                    {
                        director = new Director();
                        if (director != null)
                        {
                            transmissionBuilder = new TransmissionBuilder();
                            if (transmissionBuilder != null)
                            {
                                buildOk = director.Construct(transmissionBuilder, parameters);
                                if (buildOk == true)
                                {
                                    if (transmissionBuilder.BuildResult != null)
                                    {
                                        messageText = transmissionBuilder.BuildResult.FormatDisplayString();
                                        lines       = messageText.Split(sep);

                                        foreach (string s in lines)
                                        {
                                            lbTransmission.Items.Add(s);
                                        }
                                    }
                                    else
                                    {
                                        lbTransmission.Items.Add("transmissionBuilder.BuildResult = null!");
                                    }
                                }
                                else
                                {
                                    lbTransmission.Items.Add("buildOk = false!");
                                }
                            }
                            else
                            {
                                lbTransmission.Items.Add("transmissionBuilder = null!");
                            }
                        }
                        else
                        {
                            lbTransmission.Items.Add("director = null!");
                        }
                    }
                    else
                    {
                        lbTransmission.Items.Add("parameters null, couldn't create transmission!");
                    }
                }
            }
            catch (Exception exception)
            {
                stringBuilder    = new StringBuilder();
                exceptionDetails = exception;

                while (exceptionDetails != null)
                {
                    messageText = "\r\nMessage: " + exceptionDetails.Message + "\r\nSource: " + exceptionDetails.Source + "\r\nStack Trace: " + exceptionDetails.StackTrace + "\r\n----------\r\n";

                    stringBuilder.Append(messageText);

                    exceptionDetails = exceptionDetails.InnerException;
                }

                messageText = stringBuilder.ToString();
                MessageBox.Show(messageText, "Inheritance - Error", MessageBoxButtons.OK);
            }
        }