public Form1() { InitializeComponent(); lbHistory.SelectedIndexChanged -= new EventHandler(lbHistory_SelectedIndexChanged); lbHistory.DataSource = CalculationHistory.FetchEntireHistory(); lbHistory.SelectedIndexChanged += new EventHandler(lbHistory_SelectedIndexChanged); }
private void btnEquals_Click(object sender, EventArgs e) { lblResult.Text = Calculation.NetStandard.Calculator.Calculate(lblResult.Text).ToString(); lbHistory.SelectedIndexChanged -= new EventHandler(lbHistory_SelectedIndexChanged); lbHistory.DataSource = CalculationHistory.FetchEntireHistory(); lbHistory.SelectedIndexChanged += new EventHandler(lbHistory_SelectedIndexChanged); }
/// <summary> /// Calculates the result from the number values /// </summary> /// <returns></returns> public string Calculate() { //Check for left and right characters that are not numbers var theOperator = Operator; double result = 0; try { switch (theOperator) { case MathOperator.Add: { result = Left + Right; } break; case MathOperator.Subtract: { result = Left - Right; } break; case MathOperator.Multiply: { result = Left * Right; if (result >= double.MaxValue) { result = 0; ErrorMessage = OverflowMessage; } } break; case MathOperator.Divide: { result = Right.Equals(0) ? 0 : Left / Right; if (result >= double.MaxValue) { result = 0; ErrorMessage = OverflowMessage; } } break; } } catch (Exception ex) { return(ex.Message); } CalculationResult = result; CalculationHistory.Add(result); return(result.ToString(CultureInfo.InvariantCulture)); }
public async Task <int> SaveAsync(SumResource sumResource, string result) { ApplicationUser applicationUser = GetUserForCalculationHistory(sumResource); var calculationHistory = new CalculationHistory { ApplicationUser = applicationUser, CalculationDate = DateTime.UtcNow, FirstNumber = sumResource.FirstNumber, SecondNumber = sumResource.SecondNumber, Result = result }; unitOfWork.CalculationHistoryRepository.Add(calculationHistory); var completeResult = await unitOfWork.CompleteAsync(); return(completeResult); }
/// <summary> /// Do some amazing calculations. Store calculation and result in SQL. /// </summary> private async void EqualsButton_Click(object sender, RoutedEventArgs e) { if (MyInkCanvas.InkPresenter.StrokeContainer.GetStrokes().Any()) { var inkRecognizerContainer = new InkRecognizerContainer(); var results = await inkRecognizerContainer.RecognizeAsync(MyInkCanvas.InkPresenter.StrokeContainer, InkRecognitionTarget.All); var recognizedText = string.Concat(results.Select(i => i.GetTextCandidates()[0])); ResultsTextBlock.Text = Calculation.NetStandard.Calculator.Calculate(recognizedText).ToString(); MyInkCanvas.InkPresenter.StrokeContainer.Clear(); } else { ResultsTextBlock.Text = Calculation.NetStandard.Calculator.Calculate(ResultsTextBlock.Text).ToString(); } HistoryCollection = new ObservableCollection <string>(CalculationHistory.FetchEntireHistory()); }
private void AddToCalculationHistory(string opPressed) { if (CalculationHistory.Length > 0) { Operation = opPressed; if (Operation == "1/x") { CalculationHistory += ("1 / " + HiddenNumber); } else if (Operation == "\u221a") { CalculationHistory = CalculationHistory.Remove(CalculationHistory.Length - 1, 1); CalculationHistory += "\u221a (" + ((decimal)Math.Pow(double.Parse(OnScreenDisplay), 2)).ToString() + ")"; } else { CalculationHistory += " " + Operation + " "; } } }
public static void Activate(ICalculatorComponent calculator, ILogger <CalculatorManager> logger) { string choice = ""; while (!choice.Equals("6")) { Prompts.Options(); choice = Console.ReadLine(); CalculationHistory.Activate(calculator, choice); // | 3 | Create New Calculations while (choice.Equals("3")) { WriteToConsole.Write("\n"); Receiver.Activate(calculator, logger); choice = "pass"; } // | 4 | Display What The Calculator Is Capable Of Doing (In Its Current State) while (choice.Equals("4")) { Prompts.Capability(); Receiver.DisplayOperations(calculator, ""); Prompts.Back(); String enter = Console.ReadLine(); choice = "pass"; } while ((!choice.Equals("1")) && (!choice.Equals("2")) && (!choice.Equals("3")) && (!choice.Equals("4") && (!choice.Equals("5")) && (!choice.Equals("6")) && (!choice.Equals("pass")))) { Prompts.Unavailable(); String enter = Console.ReadLine(); choice = "pass"; } } }
/// <summary> /// Fetch history item from SQL database. /// </summary> private void HistoryItem_Click(object sender, ItemClickEventArgs e) { ResultsTextBlock.Text = CalculationHistory.FetchFromHistory(e.ClickedItem.ToString()).ToString(); }
public MainPage() { this.InitializeComponent(); HistoryCollection = new ObservableCollection <string>(CalculationHistory.FetchEntireHistory()); }
private void Clear_Click(object sender, RoutedEventArgs e) { CalculationHistory.ClearHistory(); HistoryCollection = new ObservableCollection <string>(); }
/// <summary> /// Clears the screen. /// </summary> private void CButton_Click(object sender, RoutedEventArgs e) { HistoryCollection = new ObservableCollection <string>(CalculationHistory.FetchEntireHistory()); }
/// <summary> /// Does math! /// </summary> /// <param name="calculation">The string representing the calculation.</param> /// <returns>The calculated value.</returns> public static double Calculate(string calculation) { int startIndex = 0; double result = 0d; string operation = string.Empty; for (var i = 0; i < calculation.Length; i++) { if (calculation[i] == '+' || calculation[i] == '-' || calculation[i] == (char)215 || calculation[i] == 'x' || calculation[i] == '/') { switch (operation) { case "+": result += double.Parse(calculation.Substring(startIndex, i - startIndex)); break; case "-": result -= double.Parse(calculation.Substring(startIndex, i - startIndex)); break; case "x": result *= double.Parse(calculation.Substring(startIndex, i - startIndex)); break; case "/": result /= double.Parse(calculation.Substring(startIndex, i - startIndex)); break; default: result = double.Parse(calculation.Substring(startIndex, i - startIndex)); break; } operation = calculation[i] == (char)215 ? "x" : calculation[i].ToString(); startIndex = ++i; } } switch (operation) { case "+": result += double.Parse(calculation.Substring(startIndex)); break; case "-": result -= double.Parse(calculation.Substring(startIndex)); break; case "x": result *= double.Parse(calculation.Substring(startIndex)); break; case "/": result /= double.Parse(calculation.Substring(startIndex)); break; default: result = double.Parse(calculation.Substring(startIndex)); break; } // Add the caluclation to the history. CalculationHistory.AddToHistory(calculation, result); return(result); }
private void ClearDatabase_Click(object sender, EventArgs e) { CalculationHistory.ClearHistory(); lbHistory.DataSource = CalculationHistory.FetchEntireHistory(); }
private void lbHistory_SelectedIndexChanged(object sender, EventArgs e) { var selectedItem = lbHistory.SelectedItem.ToString(); lblResult.Text = CalculationHistory.FetchFromHistory(selectedItem).ToString(); }