private decimal AmountConverter(string formula) { var execute = new System.Data.DataTable().Compute(formula, null); var result = decimal.Parse(execute.ToString()); return(Math.Round(result, 2, MidpointRounding.AwayFromZero)); }
private void button18_Click(object sender, RoutedEventArgs e) { textBox.Text = textBox1.Text; var compute = new System.Data.DataTable().Compute(textBox1.Text, null); textBox1.Text = compute.ToString(); textBox1.Text = textBox1.Text.Replace(',', '.'); }
public List <string> getDataBaseCliente(int dni) { List <string> lista = new List <string>(); SqlConnection connection; SqlCommand command; string sql = ""; SqlDataReader dataReader; System.Data.DataTable dt = new System.Data.DataTable(); sql = "SELECT " + "uId AS 'FORMA DE PAGO' " + ",[iNroY] AS 'NÚMERO DE Y' " + ",[iNroZ] AS 'NÚMERO DE Z' " + ",[iNroPos] AS 'NÚMERO DE POS' " + ",[iNroSuc] AS 'NÚMERO DE SUCURSAL' " + ",[iNroUser] AS 'LEGAJO CAJERO' " + ",[cDescripcion] AS 'DESCRIPCIÓN FORMA DE PAGO' " + ",REPLACE(CONVERT(VARCHAR,[dImporte]), '.', ',') AS 'IMPORTE' " + ",[dRecDesc] AS 'RECARGO/DESCUENTO' " + ",[cComprobante] AS 'COMPROBANTE' " + ",[cCliente] AS 'TARJETA CLIENTE' " + ",[cBarCode] AS 'PLAN TARJETA' " + ",[cPlan] AS 'CPLAN' " + ",[fTimeSynchro] AS 'FECHA Y HORA' " + ",[vData] AS 'DATOS DEL CLIENTE (TIPO TELEFONO, NRO DE TELEFONO, DNI)' " + "FROM dE_DDMP " + "WHERE vData LIKE '%" + dni + "%'"; connection = new SqlConnection(connectionString); try { connection.Open(); command = new SqlCommand(sql, connection); dataReader = command.ExecuteReader(); /*while (dataReader.Read()) * {*/ dt.Load(dataReader); //} dataReader.Close(); command.Dispose(); connection.Close(); } catch (Exception ex) { dt = null; } lista.Add(dt.ToString()); return(lista); }
/// <summary> /// You can work with strings like "3*(6+7)-73/5" without Spaces or equal signs /// </summary> /// <returns></returns> public string Calculate() { try { var result = new System.Data.DataTable().Compute(inputString1, ""); return(result.ToString()); } catch (Exception ex) { var errormassage = ex; return("error"); } }
private void Perc_Click(object sender, RoutedEventArgs e) { if (resultbox_Copy.Text != "0") { if (numburbuttonpressed & resultbox_Copy.Text == "") { resultbox_Copy.Text = "0"; resultbox.Text = "0"; } else { string substring = resultbox_Copy.Text.Substring(resultbox_Copy.Text.Length - 1, 1); resultbox_Copy.Text = resultbox_Copy.Text.Remove(resultbox_Copy.Text.Length - 2, 2); if (resultbox_Copy.Text.Contains(",")) { resultbox_Copy.Text = resultbox_Copy.Text.Replace(",", "."); } object oper = new System.Data.DataTable().Compute(resultbox_Copy.Text, ""); string op = oper.ToString(); double bb = double.Parse(op); //double d = double.Parse(resultbox_Copy.Text); resultbox.Text = (double.Parse(resultbox.Text).ToString()); double result = (bb * double.Parse(resultbox.Text)) / 100; resultbox_Copy.Text += " " + substring + " " + result.ToString(); resultbox.Text = result.ToString(); if (operationpressed) { int num = resultbox_Copy.Text.IndexOf(operation); resultbox_Copy.Text.Remove(num, num); } } } percentbutton = true; }
public static int ProcessMathQuestion(string question) { question = question.Replace(" ", ""); string[] array = question.ToArray().Select(c => { string str = string.Empty; switch (c) { case '零': str = "0"; break; case '一': str = "1"; break; case '二': str = "2"; break; case '三': str = "3"; break; case '四': str = "4"; break; case '五': str = "5"; break; case '六': str = "6"; break; case '七': str = "7"; break; case '八': str = "8"; break; case '九': str = "9"; break; case '十': str = "x"; break; case '加': str = "+"; break; case '减': str = "-"; break; case '+': str = "+"; break; case '-': str = "-"; break; default: str = string.Empty; break; } if (Regex.IsMatch(c.ToString(), @"\d")) { str = c.ToString(); } return(str); } ).Where(str => !str.Equals("")).Select(str => str).ToArray(); for (int i = 0; i < array.Length; i++) { if (array[i].Equals("x")) { if (i - 1 >= 0 && Regex.IsMatch(array[i - 1], @"\d")) { if (i + 1 < array.Length && Regex.IsMatch(array[i + 1], @"\d")) { array[i] = string.Empty; } else { array[i] = "0"; } } else { if (i + 1 < array.Length && Regex.IsMatch(array[i + 1], @"\d")) { array[i] = "1"; } else { array[i] = "10"; } } } } StringBuilder sb = new StringBuilder(); foreach (string str in array.Where(str => !string.IsNullOrEmpty(str)).Select(str => str).ToArray()) { sb.Append(str); } Console.WriteLine("=================================================捣蛋鬼问题,解析公式完成,公式是" + sb.ToString()); var result = new System.Data.DataTable().Compute(sb.ToString(), ""); Console.WriteLine("=================================================计算结果是" + result.ToString()); return((int)result); }
private void Operation_Click(object sender, RoutedEventArgs e) { operationpressed = true; if (nth) { Nthroot_Click(sender, e); } if (nthpower) { Npow_Click(sender, e); } if (numburbuttonpressed || mathbuttonpressed) { string operation1 = ""; /*secvvale )gamo*/ if (resultbox_Copy.Text != "") { if (rclicked == false) { Button c = (Button)sender; operation1 = (string)c.Content; /*sevcvale ) gamo*/ if (mathbuttonpressed) { resultbox_Copy.Text = resultbox_Copy.Text + " " + operation1; } if (percentbutton) /*percentbuttton*/ { resultbox_Copy.Text = resultbox_Copy.Text + " " + operation1; } if (mathbuttonpressed == false) /*/*added*/ /*was written else */ { resultbox_Copy.Text = resultbox_Copy.Text + " " + resultbox.Text + " " + operation1; } } //int charLocation = resultbox_Copy.Text.IndexOf("(", 0); string op; if (result == 0 & operationpressed == false) /*davamate operationressed radgan 0 * 2 gamoived*/ { op = resultbox.Text; } string abc = resultbox_Copy.Text; int Count = 0; foreach (char c in abc) { if (c == '(') { Count++; } } int l = Count; bool left = l % 2 == 0; int Count1 = 0; foreach (char c in abc) { if (c == ')') { Count1++; } } int r = Count1; bool right = r % 2 == 0; Dictionary <string, string> st = new Dictionary <string, string>() { { "sqrt", double.Parse(resultbox.Text).ToString() }, { "reciproc", (1 / (double.Parse(resultbox.Text))).ToString() }, //"fact", //"sin", //"cos", //"tan", //"sinh", //"cosh", //"tanh", //"exp", //"log", //"ln", //"powten", //"sqr", //"cube", //"cuberoot", //"^", }; bool b = false; string currentmath = ""; for (int i = 0; i < st.Count; i++) { var item = st.ElementAt(i); var itemkey = item.Key; var itemvalue = item.Value; b = resultbox_Copy.Text.Contains(itemkey); if (b) { currentmath = itemvalue.ToString(); break; } } if (mathbuttonpressed == false && (lftclicked && rclicked || lftclicked && rclicked == false && resultbox_Copy.Text.Contains(")") && left == true && right == true || lftclicked && rclicked == false && resultbox_Copy.Text.Contains(")") && left == false && right == false || left == false && right == false && mathbuttonpressed)) { if (lftclicked && rclicked == false && resultbox_Copy.Text.Contains(")")) { int i = resultbox_Copy.Text.LastIndexOf("("); string sub = resultbox_Copy.Text.Substring(i); /*right part*/ string sub1 = resultbox_Copy.Text.Substring(0, resultbox_Copy.Text.Length - sub.Length); /*Left part*/ string ss = sub.Remove(sub.Length - 2); object ob = new System.Data.DataTable().Compute(ss, ""); op = sub1 + ob.ToString(); //if (b) //{ // op = //} } else if (b) { int i = resultbox_Copy.Text.LastIndexOf("("); string sub = resultbox_Copy.Text.Substring(i); string ss = sub.Remove(sub.Length - 2); op = currentmath + operation + sub; if (op.Contains(",")) { op = op.Replace(",", "."); } object obj = new System.Data.DataTable().Compute(op, ""); obj.ToString(); } else { object obj = new System.Data.DataTable().Compute(resultbox_Copy.Text, ""); op = obj.ToString(); } } else { op = result.ToString() + operation + resultbox.Text; } if (op.Contains(",")) { op = op.Replace(",", "."); } //if (b) //{ // op = result.ToString() + operation + resultbox.Text; // object ob = new System.Data.DataTable().Compute(op, ""); // ob.ToString(); //} object oper = new System.Data.DataTable().Compute(op, ""); resultbox.Text = oper.ToString(); result = double.Parse(resultbox.Text); operation = operation1; } else { Button b = (Button)sender; operation = (string)b.Content; result = double.Parse(resultbox.Text); resultbox_Copy.Text = result.ToString() + " " + operation; } } else { string operation2; Button b = (Button)sender; operation2 = (string)b.Content; if (resultbox_Copy.Text.Length - 1 < 0) { resultbox_Copy.Text = resultbox.Text + " " + operation2; operation = operation2; } else if (resultbox_Copy.Text.Length - 1 > 0 && rclicked || resultbox_Copy.Text.Length - 1 > 0 && rclicked) /*)gamo*/ { resultbox_Copy.Text = resultbox_Copy.Text + operation2; operation = operation2; } else { resultbox_Copy.Text = resultbox_Copy.Text.Remove(resultbox_Copy.Text.Length - 1, 1) + operation2; operation = operation2; } //resultbox_Copy.Text = resultbox_Copy.Text + " " + operation2 + " "; } mathbuttonpressed = false; numburbuttonpressed = false; nth = false; nthpower = false; percentbutton = false; #region }
private void Equals_Click(object sender, RoutedEventArgs e) { operationpressed = true; if (lftclicked) { string sub = ""; //int i = resultbox_Copy.Text.LastIndexOf("("); if (rclicked) { sub = resultbox_Copy.Text; } else { sub = resultbox_Copy.Text + resultbox.Text; /*right part*/ } /*string sub1 = resultbox_Copy.Text.Substring(0, resultbox_Copy.Text.Length - sub.Length);*/ /*Left part*/ object ob = new System.Data.DataTable().Compute(sub, ""); if (ob.ToString() != "") { resultbox.Text = ob.ToString(); resultbox_Copy.Text = string.Empty; backspaceallowed = false; operation = ""; } } else { //resultbox_Copy.Text = string.Empty; switch (operation) { case "+": resultbox.Text = (result + double.Parse(resultbox.Text)).ToString(); break; case "-": resultbox.Text = (result - double.Parse(resultbox.Text)).ToString(); break; case "/": resultbox.Text = (result / double.Parse(resultbox.Text)).ToString(); break; case "*": resultbox.Text = (result * double.Parse(resultbox.Text)).ToString(); break; default: break; } if (nth) { Nthroot_Click(sender, e); } if (nthpower) { Npow_Click(sender, e); } resultbox_Copy.Text = string.Empty; backspaceallowed = false; operation = ""; result = 0; } }