如何在c#中按用户创建自定义公式 [英] how to creating custom formula by user in c#

查看:154
本文介绍了如何在c#中按用户创建自定义公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好



我正在编写会计软件。我希望用户根据预定义的参数构建公式。每个参数都是根据函数计算的。

例如:

参数是:

1)成本(由函数f1根据数据库的某些字段计算)

2)count(由函数f2根据数据库的某些字段计算)

3)时间(根据数据库的某些字段按函数f3计算)

4 )重量(由函数f4根据数据库的某些字段计算)

5)...



和用户定义此公式:

A =成本/数量*重量

B =计数/时间

最终成本= A + B



如何在数据库中保存这个公式?

以及如何允许用户根据旧公式(A和B)定义新公式(最终成本)?





谢谢。

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.

推荐答案

看看:如何在sqlserver中保存公式并在app中使用此公式 [ ^ ]



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

Quote:

我想你必须在数据库中保存准确的公式,当您想要使用它时,使用replace方法处理公式字符串。你应该得到Variabl1,Variable2数据并使用这段代码:



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) ;



然后处理f来运行公式。对于奔跑你可以使用



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



并为你想要的所有数学运算符使用这个替换代码。

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.









但是就像我在评论中写的那样,这个任务更容易使用Excel:)





But like I wrote in comment this would be easier to use Excel for this task :)


这篇关于如何在c#中按用户创建自定义公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆