private void formulaListBox_SelectedIndexChanged(object sender, EventArgs e) { formulaTitle.Text = ((Formula)formulaListBox.SelectedItem).title; formula.Text = ((Formula)formulaListBox.SelectedItem).formula; FormulaGetter getter = new FormulaGetter(formula.Text, stock); result.Text = getter.getResult() + "\n\n=====================================\n" + tipStr; }
private void save_Click(object sender, EventArgs e) { FormulaGetter getter = new FormulaGetter(formula.Text, stock); if (getter.getResult().Contains("表达式错误!")) { result.Text = "公式错误!禁止保存错误的公式,请检查并修改!\n" + "\n\n=====================================\n" + tipStr; } else { SaveFormulaToList(); SaveFormulaToDB(); result.Text = "保存成功!\n" + "\n\n=====================================\n" + tipStr; BindFormulaList(); } }
private String calculateForm(Queue <String> formula) { ////test //String s = formula.Dequeue(); //while (formula.Count() != 0) { // s += formula.Dequeue(); //} //Console.WriteLine(s); //匹配各种函数: formula的形式是:pow[o1,o2] if (formula.Peek().Equals("pow")) { formula.Dequeue(); String[] t = breakFormula(formula, ","); Decimal o1 = getResult(t); t = breakFormula(formula, "]"); Decimal o2 = getResult(t); String result = Function.pow(o1, o2).ToString(); return(result); } else if (formula.Peek().Equals("if")) { formula.Dequeue(); String[] t = breakFormula(formula, ","); FormulaGetter f = new FormulaGetter(t.ToString(), stock); string o0 = f.getResult(); t = breakFormula(formula, ","); Decimal o1 = getResult(t); t = breakFormula(formula, "]"); Decimal o2 = getResult(t); if (o0.Equals("true")) { return(o1.ToString()); } else { return(o2.ToString()); } } else if (formula.Peek().Equals("nif")) { formula.Dequeue(); String[] t = breakFormula(formula, ","); FormulaGetter f = new FormulaGetter(t.ToString(), stock); string o0 = f.getResult(); t = breakFormula(formula, ","); Decimal o1 = getResult(t); t = breakFormula(formula, "]"); Decimal o2 = getResult(t); if (o0.Equals("false")) { return(o1.ToString()); } else { return(o2.ToString()); } } else if (formula.Peek().Equals("acos")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.ACOS(o).ToString(); return(result); } else if (formula.Peek().Equals("asin")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.ASIN(o).ToString(); return(result); } else if (formula.Peek().Equals("atan")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.ATAN(o).ToString(); return(result); } else if (formula.Peek().Equals("sin")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.SIN(o).ToString(); return(result); } else if (formula.Peek().Equals("cos")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.COS(o).ToString(); return(result); } else if (formula.Peek().Equals("tan")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.TAN(o).ToString(); return(result); } else if (formula.Peek().Equals("exp")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.EXP(o).ToString(); return(result); } else if (formula.Peek().Equals("ln")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.LN(o).ToString(); return(result); } else if (formula.Peek().Equals("log")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.LOG(o).ToString(); return(result); } else if (formula.Peek().Equals("sqrt")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.SQRT(o).ToString(); return(result); } else if (formula.Peek().Equals("abs")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.ABS(o).ToString(); return(result); } else if (formula.Peek().Equals("ceiling")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.CEILING(o).ToString(); return(result); } else if (formula.Peek().Equals("floor")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.FLOOR(o).ToString(); return(result); } else if (formula.Peek().Equals("intpart")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.INTPART(o).ToString(); return(result); } else if (formula.Peek().Equals("rand")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.RAND(o).ToString(); return(result); } else if (formula.Peek().Equals("sign")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.SIGN(o).ToString(); return(result); } else if (formula.Peek().Equals("round")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.ROUND(o).ToString(); return(result); } else if (formula.Peek().Equals("fracpart")) { formula.Dequeue(); String[] t = breakFormula(formula, "]"); Decimal o = getResult(t); String result = Function.FRACPART(o).ToString(); return(result); } else if (formula.Peek().Equals("max")) { formula.Dequeue(); String[] t = breakFormula(formula, ","); Decimal o1 = getResult(t); t = breakFormula(formula, "]"); Decimal o2 = getResult(t); String result = Function.MAX(o1, o2).ToString(); return(result); } else if (formula.Peek().Equals("min")) { formula.Dequeue(); String[] t = breakFormula(formula, ","); Decimal o1 = getResult(t); t = breakFormula(formula, "]"); Decimal o2 = getResult(t); String result = Function.MIN(o1, o2).ToString(); return(result); } else if (formula.Peek().Equals("mod")) { formula.Dequeue(); String[] t = breakFormula(formula, ","); Decimal o1 = getResult(t); t = breakFormula(formula, "]"); Decimal o2 = getResult(t); String result = Function.MOD(o1, o2).ToString(); return(result); } return(new String('1', 1)); }
private void calculate_Click(object sender, EventArgs e) { FormulaGetter getter = new FormulaGetter(formula.Text, stock); result.Text = getter.getResult() + "\n\n=====================================\n" + tipStr; }