⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 benifit.java

📁 一个简单实用的网上书城,可当作原型使用
💻 JAVA
字号:
/*
 * Benifit.java
 *
 * Created on 2007年7月20日, 下午5:31
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package czm;
import java.sql.*;
/**
 *
 * @author Administrator
 */
public class Benifit {
    private float[] disCountTable={1f,0.95f,0.9f,0.85f,0.8f,0.75f};
    /** Creates a new instance of Benifit */
    public Benifit() {
    }
    
    //按会员等级打折后的价格,出错将返回原来的原价
    public float Discount(String userid,float Oprice)
    {
        String strSql="select point " +
                        "from buyerinfo " +
                       "where memberID='" +userid +"'";
        int userpoint;
        opendb opt=new opendb();
        ResultSet rs=opt.executeQuery(strSql);
        try{
            if(rs.next())
            {
                userpoint=rs.getInt(1);
                return disCountTable[MarkToGrade(userpoint)]*Oprice;
            }else
            {
                return Oprice;   //用户不存在
            }
        }catch(SQLException e)
        {
            return  Oprice;     //访问数据库出错
        }
    }
    //按公式把消费总额转换成积分。
    public int Accumulate (float Oprice)
    {   
        return (int)Oprice/10;
    }
    
    //按公式把消费总额转换成积分并加到会员的积分中。
    public boolean AccumulateToUser (String uid,float Oprice)
    {   
          String strSql="update buyerinfo " +
                        "set point=point+" +Accumulate(Oprice)+
                       " where memberID='" +uid +"'";
          return new opendb().executeUpdate(strSql); 
    }
    
    //按公式把计算用会员的等级。
    public int MarkToGrade(int Apoint)
    {  
        int grade=1;
        if(Apoint>=0&&Apoint<=30)return 1;
        if(Apoint>=31&&Apoint<=70)return 2;
        if(Apoint>=71&&Apoint<=120)return 3;
        if(Apoint>=121&&Apoint<=200)return 4;
        if(Apoint>=201)return 5;
        return grade;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -