Esempio n. 1
0
        public Tests()
        {
            x = new StringToFormula();

            InitializeComponent();
        }
Esempio n. 2
0
        public MainWindow()
        {
            InitializeComponent();
            // ------------------------------- Initialize all variables. ------------------------------------------

            stf     = new StringToFormula();                            // Object Used to compute expressions
            prev_op = "";                                               // Represents the previous operation.
            res_op  = true;

            // State variables used for [Monomial Operator Button]
            MonoString = "";                                            // Stores the entire Expression(String) of repeated [Monomial operators]
            oldHist    = "";                                            // Stores the value of the history window before the first [Monomial Operator] is pressed

            // State Variables used for [Parenthesis Operator Button]
            perCount = 0;                                               // Counts the number of mismatched parenthesis



            // --------------- (Bind all buttons to a function based off of name)-------------------------------

            /*
             *
             *
             *  EXPLAINATION OF BINDING CODE
             *  ---------------------------------------------------------------------------------
             *  Naming conventions of buttons are (View XAML Code for all the names):
             *      1. [Classification]_[Name]
             *      2. [Classification]_[Type]_[Name]
             *
             *  The following code splits the buttons Name splits the data into the variable <calcButtonNameArr>
             *              calcButtonNameArr = {"[Classifcation]", "[Type]","[Name]"}
             *  and binds the button based on its [Classification] and [Type]
             *
             *  Examples:
             *           ---------------------
             | Operation_Bin_plus  | ---->  Classification = Operation , Type = Bin , Name = plus
             |           ---------------------
             |
             |           ---------------------
             |       Number_1      | ---->  Classification = Operation   and Name = 1
             |           ---------------------
             |  ---------------------------------------------------------------------------------
             */


            for (int i = 0; i < grid.Children.Count; i++)
            {
                Button   calcButton        = (Button)grid.Children[i];   // Grabs button from buttonGrid
                String[] calcButtonNameArr = calcButton.Name.Split('_'); // Splits the name
                String   calcButtonClfctin = calcButtonNameArr[0];       // Grabs the button classification

                switch (calcButtonClfctin)
                {
                case "Number":
                    calcButton.Click += new RoutedEventHandler(Numbers_Clicked);
                    break;

                case "Constant":
                    calcButton.Click += new RoutedEventHandler(Constants_Clicked);
                    break;

                case "Operation":
                    String calcButtonType = calcButtonNameArr[1];
                    switch (calcButtonType)
                    {
                    // binary operations (+,-,/,*)
                    case "Bin":
                        calcButton.Click += new RoutedEventHandler(Operations_Clicked);
                        break;

                    // Monomial Operations
                    case "Mon":
                        calcButton.Click += new RoutedEventHandler(Operations_mono_Clicked);
                        break;

                    // Parenthesis
                    case "Per":
                        calcButton.Click += new RoutedEventHandler(Operations_Per_Clicked);
                        break;

                    // Equal to operation (=)
                    case "Result":
                        calcButton.Click += new RoutedEventHandler(Operations_Res_Clicked);
                        break;

                    // Clear opeartion
                    case "clr":
                        calcButton.Click += new RoutedEventHandler(Operations_clr_Clicked);
                        break;
                    }
                    break;
                }


                // Update grid button
                grid.Children[i] = calcButton;
            }
        }