2

我有一个 asp.net 电子商务应用程序,我在其中添加了折扣功能:

如果totalPurchase amount >=200, then 5% disc,如果它is >=500, then 7%..喜欢那样。

问题是折扣百分比应该通过管理员登录动态更改。即我不允许在代码隐藏中编写此代码。

if(totalPurchase>=200 && totalPurchase<700)
{ // code for 5% discount }

我正在尝试实现记录以遍历数据库表折扣,其字段是..

DiscID -1

DiscPer -5

DiscAmount -200 

等等..

4

2 回答 2

1

我觉得您缺少一个数据库列来存储您的折扣金额范围等200700我假设数据库表名是Discounts并且范围列是AmountFromand AmountTo。这是我为您提供的解决方案:

OleDbConnection connect = new OleDbConnection();
connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Data.accdb;Persist Security Info=False;";
connect.Open();

OleDbCommand command = new OleDbCommand();
command.CommandText = "SELECT AmountFrom, AmountTo, DiscPer FROM Discounts";
command.Connection = connect;

OleDbReader reader = command.ExecuteReader();

while(reader.Read())
{   
    int from = int.Parse(reader['AmountFrom'].toString());
    int to = int.Parse(reader['AmountTo'].toString());
    int discount = int.Parse(reader['DiscPer'].toString());

    if(totalPurchase >= from && totalPurchase < to) {
        MessageBox.Show("You got a discount of " + discount + "%");
    }
}
connect.Close();
于 2012-08-09T10:37:40.423 回答
0

这个 SO 问题可能会为您提供解决折扣问题的好方法数据库设计头脑风暴:销售价格

于 2012-08-09T10:25:46.740 回答