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
| public void addOrder(OrderDTO odto, List<BasketDTO> basketList, List<GoodsDTO> goodsList) { int o_num = 0; int trade_num = 0;
Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
try{ getCon(); sql = "selct max(o_num) from itwill_order"; pstmt = con.prepareStatement(sql); rs = pstmt.executeQuery(); if(rs.next()){ o_num = rs.getInt(1)+1; } trade_num = o_num; System.out.println("trade_num= "+trade_num); System.out.println("o_num= "+o_num);
for(int i=0; i<basketList.size(); i++){ BasketDTO bkdto = (BasketDTO) basketList.get(i); GoodsDTO gdto = (GoodsDTO) goodsList.get(i);
sql = "insert into itwill_order values(?,?,?,?,?," + "?,?,?,?,?," + "?,?,?,?,?," + "?,now(),?,now(),?)"; pstmt = con.prepareStatement(sql); pstmt.setInt(1, o_num); pstmt.setString(2, sdf.format(cal.getTime())+"-"+trade_num); pstmt.setInt(3, bkdto.getB_g_num()); pstmt.setString(4, gdto.getName()); pstmt.setInt(5, bkdto.getB_g_amount());
pstmt.setString(6, bkdto.getB_g_size()); pstmt.setString(7, bkdto.getB_g_color()); pstmt.setString(8, bkdto.getB_m_id()); pstmt.setString(9, odto.getO_receive_name()); pstmt.setString(10, odto.getO_receive_addr1()); pstmt.setString(11, odto.getO_receive_addr2()); pstmt.setString(12, odto.getO_receive_phone()); pstmt.setString(13, odto.getO_receive_memo());
pstmt.setInt(14, bkdto.getB_g_amount() * gdto.getPrice());
pstmt.setString(15, odto.getO_trade_type()); pstmt.setString(16, odto.getO_trade_payer()); pstmt.setString(17, ""); pstmt.setInt(18, 0);
pstmt.executeUpdate();
o_num++; } System.out.println("DAO: 주문성공"); }catch(Exception e){ e.printStackTrace(); }finally { closeDB(); } }
|