1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
| package Cart;
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */
/** * * @author anthony */ import Mysql.MysqlBean; import java.sql.*; public class CountPriceByDb { private String username; private double n_apple; private double n_orange; private double n_watermalon; private double n_fires; private double p_apple; private double p_orange; private double p_watermalon; private double p_fires; private double s_apple; private double s_orange; private double s_watermalon; private double s_fires; private double totalprice; private static final MysqlBean MB = new MysqlBean();; private ResultSet rs;
public CountPriceByDb() throws Exception{ //MB = new MysqlBean(); rs = MB.getRs("SELECT * FROM cart_goods"); while(rs.next()){ switch (rs.getString("gname")) { case "苹果": this.s_apple = rs.getDouble("gprice"); break; case "橘子": this.s_orange = rs.getDouble("gprice"); break; case "西瓜": this.s_watermalon = rs.getDouble("gprice"); break; case "火龙果": this.s_fires = rs.getDouble("gprice"); break; } } } /** * @return the n_apple */ public double getN_apple() { return n_apple; }
/** * @param n_apple the n_apple to set */ public void setN_apple(double n_apple) { this.n_apple = n_apple; this.setP_apple(n_apple*s_apple); int num = MB.executeUpdate("INSERT INTO cart_lists (username,gid,gnumber,gtprice) VALUES (\""+this.getUsername()+"\",1,\""+n_apple+"\",\""+this.getP_apple()+"\")"); System.out.println("影响:"+num); }
/** * @return the n_orange */ public double getN_orange() { return n_orange; }
/** * @param n_orange the n_orange to set */ public void setN_orange(double n_orange) { this.n_orange = n_orange; this.setP_orange(n_orange*s_orange); int num = MB.executeUpdate("INSERT INTO cart_lists (username,gid,gnumber,gtprice) VALUES (\""+this.getUsername()+"\",2,\""+n_orange+"\",\""+this.getP_orange()+"\")"); System.out.println("影响:"+num); }
/** * @return the n_watermalon */ public double getN_watermalon() { return n_watermalon; }
/** * @param n_watermalon the n_watermalon to set */ public void setN_watermalon(double n_watermalon) { this.n_watermalon = n_watermalon; this.setP_watermalon(n_watermalon*s_watermalon); int num = MB.executeUpdate("INSERT INTO cart_lists (username,gid,gnumber,gtprice) VALUES (\""+this.getUsername()+"\",3,\""+n_watermalon+"\",\""+this.getP_watermalon()+"\")"); System.out.println("影响:"+num); }
/** * @return the n_fires */ public double getN_fires() { return n_fires; }
/** * @param n_fires the n_fires to set */ public void setN_fires(double n_fires) { this.n_fires = n_fires; this.setP_fires(n_fires*s_fires); int num = MB.executeUpdate("INSERT INTO cart_lists (username,gid,gnumber,gtprice) VALUES (\""+this.getUsername()+"\",4,\""+n_fires+"\",\""+this.getP_fires()+"\")"); System.out.println("影响:"+num); }
/** * @return the totalprice */ public double getTotalprice() throws Exception { ResultSet rs = MB.getRs("SELECT SUM(gtprice) tol from cart_lists where `username`=\""+this.getUsername()+"\";"); while(rs.next()){ this.totalprice = rs.getDouble("tol"); } //this.totalprice = this.getP_apple()+this.getP_fires()+this.getP_orange()+this.getP_watermalon(); return totalprice; }
/** * @return the p_apple */ public double getP_apple() { return p_apple; }
/** * @return the p_orange */ public double getP_orange() { return p_orange; }
/** * @return the p_watermalon */ public double getP_watermalon() { return p_watermalon; }
/** * @return the p_fires */ public double getP_fires() { return p_fires; }
/** * @param p_apple the p_apple to set */ public void setP_apple(double p_apple) { this.p_apple = p_apple; }
/** * @param p_orange the p_orange to set */ public void setP_orange(double p_orange) { this.p_orange = p_orange; }
/** * @param p_watermalon the p_watermalon to set */ public void setP_watermalon(double p_watermalon) { this.p_watermalon = p_watermalon; }
/** * @param p_fires the p_fires to set */ public void setP_fires(double p_fires) { this.p_fires = p_fires; }
public String getListtag() throws Exception{ String tag = ""; ResultSet rs = MB.getRs("SELECT * FROM cart_lists a left join cart_goods b on a.`gid`=b.`id` where a.username = \""+this.getUsername()+"\""); while(rs.next()){ tag += "<tr>"; tag += "<td>"+rs.getString("gname")+"</td>"+"<td>"+rs.getDouble("gprice")+"</td>"+"<td>"+rs.getDouble("gnumber")+"</td>"+"<td>"+rs.getDouble("gtprice")+"</td><td>[移除该商品](\)</td>"; tag += "</tr>"; } return tag; }
/** * @return the username */ public String getUsername() { return username; }
/** * @param username the username to set */ public void setUsername(String username) { System.out.println(username); this.username = username; } }
|