Click here to Skip to main content
14,970,330 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello

I am writing accounting software.I want the user to build a formula based on pre-defined parameters.Each parameter is calculated based on a function.
for example:
parameters are:
1)cost(calculated by function f1 based on some field of database)
2)count (calculated by function f2 based on some field of database)
3)time(calculated by function f3 based on some field of database)
4)weight (calculated by function f4 based on some field of database)
5) ...

and user define this formula :
A = cost/count* weight
B=count/Time
final cost=A+B

how to save this formula in database?
and how to allow user to define new formula(final cost) based old formula(A and B)?


Thanks.
Posted
Comments
Leo Chapiro 8-Jul-15 7:20am
   
It would be easier by using Excel

1 solution

Take a look: How to save Formula in sqlserver and use this formula in app[^]

Quote:
I think you have to save the exactly formula in database and when you want to use it, process the formula string using replace method. you should get Variabl1,Variable2 data and use this code:

string f="Variabl1+Variable2*3.2+200";
f= System.Text.RegularExpressions.Regex.Replace(f, "Variabl1", TxBxVar1.Text);
f= System.Text.RegularExpressions.Regex.Replace(f, "Variabl2", TxBxVar2.Text);

and then process f to run the formula. for run you can use

System.Text.RegularExpressions.Regex.Split(f, "+");

and use this replace code for all math operators that you want.




But like I wrote in comment this would be easier to use Excel for this task :)
   
v2
Comments
sahar11 10-Jul-15 15:35pm
   
hi Thank you very much.
I can not use Excel. This is just a small part of my project.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900