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

📄 user.java

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

package czm;

import java.sql.*;

public class User {
    
    public String ID;//帐号
    public String Name;//名字
    public int LogonTime;//登录次数
    public int Point;//积分
    public String Pwd;//登录密码
    public String Phone;//电话号码
    public String Zip;//邮编
    public String Address;//地址
    public String Email;//邮箱地址
    
    /** Creates a new instance of User */
    public User() {
    }
    
    private boolean isReUser() {//检查是否有相同的用户
        try {
            if(this.ID==null)return true;
            
            String sql="select * from buyerInfo where memberID='"+this.ID+"'";
            opendb dbo=new opendb();
            ResultSet rs=dbo.executeQuery(sql);
            
            return rs.next();
        } catch(Exception exc) {
            return true;
        }
    }
    
    public boolean DeleteUser() {/**删除用户*/
        try {
            if(this.ID==null)return false;
            
            String[] sqls=new String[3];
            opendb dbo=new opendb();
            //问问其他人是否还有其他表关联
            sqls[0]="delete from buyerInfo where memberID='"+this.ID+"'";
            sqls[1]="delete from orderdetail where orderdetail.memberID='"+this.ID+"'";
            sqls[2]="delete from orderInfo where orderInfo.memberID='"+this.ID+"'";
            
            return dbo.executeUpdates(sqls);
        } catch(Exception exc) {
            return false;
        }
    }
    
    public boolean RegUser() {/**注册新用户*/
        try {
            String sql;
            opendb dbo=new opendb();
            
            //检查是否有相同的用户
            if(isReUser())return false;
            
            sql="INSERT INTO buyerInfo VALUES('"+this.ID+"','"+this.Name+"',1,'"+this.Pwd+
                    "','"+this.Phone+"','"+this.Zip+"','"+this.Address+"','"+this.Email+"',0)";
            
            return dbo.executeUpdate(sql);
        } catch(Exception exc) {
            return false;
        }
    }
    
    public boolean UpdateUser() {/**修改会员信息,不能改ID号*/
        try {
            if(this.ID==null)return false;
            
            String sql="update buyerInfo set membername='"+this.Name+
                    "', logonTimes="+this.LogonTime+
                    ", phoneCode='"+this.Phone+"', zipcode='"+this.Zip+
                    "', address='"+this.Address+"', email='"+this.Email+
                    "', point="+this.Point+" where memberID='"+this.ID+"'";
            opendb dbo=new opendb();
            
            return dbo.executeUpdate(sql);
        } catch(Exception exc) {
            return false;
        }
    }
    
    public boolean UpdatePwd(String newPwd, String oldPwd) {
        try{
            if(ShowUser()==false)return false;
            if(this.Pwd.compareTo(oldPwd)!=0)return false;
            
            String sql="update buyerInfo set pwd='"+newPwd+"' where memberID='"+this.ID+"'";
            opendb dbo=new opendb();
            return dbo.executeUpdate(sql);
        } catch(Exception Exc){
            return false;
        }
    }
    
    public boolean UpdateScore(int dtScore) {
        try{
            if(this.ID==null)return false;
            
            String sql="update buyerInfo set point=point+"+dtScore+" where memberID='"+this.ID+"'" ;
            opendb dbo=new opendb();
            
            boolean flag=dbo.executeUpdate(sql);
            if(flag)this.Point+=dtScore;
            
            return flag;
        } catch(Exception exc){
            return false;
        }
    }
    
    public boolean ShowUser() {/**读入用户信息*/
        try {
            if(this.ID==null)return false;
            
            String sql;
            opendb dbo=new opendb();
            ResultSet rs;
            
            sql="select * from buyerInfo where memberID='"+this.ID+"'";
            
            rs=dbo.executeQuery(sql);
            
            if(rs.next()) {
                //this.ID=rs.getString("memberID");
                this.Name=rs.getString("membername");
                this.LogonTime=rs.getInt("logonTimes");
                this.Point=rs.getInt("point");
                this.Pwd=rs.getString("pwd");
                this.Phone=rs.getString("phoneCode");
                this.Zip=rs.getString("zipcode");
                this.Address=rs.getString("address");
                this.Email=rs.getString("email");
                rs.close();
                return true;
            }
            
            return false;
        } catch(Exception Exc) {
            return false;
        }
    }
    
    public static ResultSet getAllUsers() {
        try {
            ResultSet rs;
            String sql="select * from buyerInfo";
            opendb dbo=new opendb();
            rs=dbo.executeQuery(sql);
            return rs;
        } catch(Exception exc){
            return null;
        }
    }
}

⌨️ 快捷键说明

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