package com.zhong.DAO;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
public class FlowerDao implements BaseDao{
private Object[][] obj;
private Object[] object;
public Object[][] showall(String tablename){
int val = 0;
Connection conn = null;
PreparedStatement ps = null;
Statement s = null;
ResultSet rs = null;
ResultSet rs0 = null;
String sql = "select fname,fprice,fsold,fnum from " + tablename;
String sql0 = "select count(*) from " + tablename;
try {
int count = 0;
conn = new ConnectionFactory().getConnection();
ps = conn.prepareStatement(sql);
s = conn.createStatement();
rs0 = s.executeQuery(sql0);
while(rs0.next()){
val = (int) rs0.getObject(1);
}
obj = new Object[val][4];
rs = ps.executeQuery();
while(rs.next()){
obj[count][0] = rs.getObject(1);
obj[count][1] = rs.getObject(2);
obj[count][2] = rs.getObject(3);
obj[count][3] = rs.getObject(4);
count++;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showInternalMessageDialog(null, "杩炴帴鏁版嵁搴撳け璐�,璇峰皾璇曢噸鏂拌繛鎺�");
}finally{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showInternalMessageDialog(null, "娌℃湁鍏抽棴鏁版嵁搴撹鍏抽棴鏁版嵁搴�");
}
}
return obj;
}
public Object[][] image(){
int val = 0;
Connection conn = null;
PreparedStatement ps = null;
Statement s = null;
ResultSet rs = null;
ResultSet rs0 = null;
String sql = "select fname,fprice,fnum,fimg from Flower";
String sql0 = "select count(*) from Flower";
try {
int count = 0;
conn = new ConnectionFactory().getConnection();
ps = conn.prepareStatement(sql);
s = conn.createStatement();
rs0 = s.executeQuery(sql0);
while(rs0.next()){
val = Integer.parseInt(rs0.getObject(1).toString());
}
obj = new Object[val][4];
rs = ps.executeQuery();
while(rs.next()){
obj[count][0] = rs.getObject(1);
obj[count][1] = rs.getObject(2);
obj[count][2] = rs.getObject(3);
obj[count][3] = rs.getObject(4);
count++;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showInternalMessageDialog(null, "杩炴帴鏁版嵁搴撳け璐�,璇峰皾璇曢噸鏂拌繛鎺�");
}finally{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showInternalMessageDialog(null, "娌℃湁鍏抽棴鏁版嵁搴撹鍏抽棴鏁版嵁搴�");
}
}
return obj;
}
public Object[][] RankbySold(String name){
int val = 0;
Connection conn = null;
PreparedStatement ps = null;
Statement s = null;
ResultSet rs = null;
ResultSet rs0 = null;
String sql = "select fname,fcome,fprice,fsold from Flower order by "+name+" desc";
String sql0 = "select count(*) from Flower";
try {
int count = 0;
conn = new ConnectionFactory().getConnection();
ps = conn.prepareStatement(sql);
s = conn.createStatement();
rs0 = s.executeQuery(sql0);
while(rs0.next()){
val = (int) rs0.getObject(1);
}
obj = new Object[val][5];
rs = ps.executeQuery();
while(rs.next()){
obj[count][0] = rs.getObject(1);
obj[count][1] = rs.getObject(2);
obj[count][2] = rs.getObject(3);
obj[count][3] = rs.getObject(4);
obj[count][4] = (Float.parseFloat(obj[count][2].toString())-Float.parseFloat(obj[count][1].toString()))*Integer.parseInt(obj[count][3].toString());
count++;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showInternalMessageDialog(null, "杩炴帴鏁版嵁搴撳け璐�,璇峰皾璇曢噸鏂拌繛鎺�");
}finally{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showInternalMessageDialog(null, "娌℃湁鍏抽棴鏁版嵁搴撹鍏抽棴鏁版嵁搴�");
}
}
return obj;
}
public Object[][] showall(){
int val = 0;
Connection conn = null;
PreparedStatement ps = null;
Statement s = null;
ResultSet rs = null;
ResultSet rs0 = null;
String sql = "select fname,fcome,fprice,fsold from Flower";
String sql0 = "select count(*) from Flower";
try {
int count = 0;
conn = new ConnectionFactory().getConnection();
ps = conn.prepareStatement(sql);
s = conn.createStatement();
rs0 = s.executeQuery(sql0);
while(rs0.next()){
val = (int) rs0.getObject(1);
}
obj = new Object[val][5];
rs = ps.executeQuery();
while(rs.next()){
obj[count][0] = rs.getObject(1);
obj[count][1] = rs.getObject(2);
obj[count][2] = rs.getObject(3);
obj[count][3] = rs.getObject(4);
obj[count][4] = (Float.parseFloat(obj[count][2].toString())-Float.parseFloat(obj[count][1].toString()))*Integer.parseInt(obj[count][3].toString());
count++;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showInternalMessageDialog(null, "杩炴帴鏁版嵁搴撳け璐�,璇峰皾璇曢噸鏂拌繛鎺�");
}finally{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showInternalMessageDialog(null, "娌℃湁鍏抽棴鏁版嵁搴撹鍏抽棴鏁版嵁搴�");
}
}
return obj;
}
public Object[][] FinaceShow(){
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select top 6 fname,fsold,fprice,fcome from Flower order by fsold*(fprice-fcome) desc";
try {
int count = 0;
conn = new ConnectionFactory().getConnection();
ps = conn.prepareStatement(sql);
obj = new Object[6][2];
rs = ps.executeQuery();
while(rs.next()){
obj[count][0] = rs.getObject(1);
obj[count][1] = (Integer.parseInt((rs.getObject(2).toString()))*((Float.parseFloat(rs.getObject(3).toString())-(Float.parseFloat(rs.getObject(4).toString())))));
count++;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showInternalMessageDialog(null, "杩炴帴鏁版嵁搴撳け璐�,璇峰皾璇曢噸鏂拌繛鎺�");
}finally{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showInternalMessageDialog(null, "娌℃湁鍏抽棴鏁版嵁搴撹鍏抽棴鏁版嵁搴�");
}
}
return obj;
}
public Object[] FindShow(String name){
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select fname,fcome,fnum,fprice,fsold,fimg from Flower where fname like '%"+name+"%'";
try {
conn = new ConnectionFactory().getConnection();
ps = conn.prepareStatement(sql);
object = new Object[6];
rs = ps.executeQuery();
while(rs.next()){
object[0] = rs.getObject(1);
object[1] = rs.getObject(2);
object[2] = rs.getObject(3);
object[3] = rs.getObject(4);
object[4] = rs.getObject(5);
object[5] = rs.getObject(6);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showInternalMessageDialog(null, "杩炴帴鏁版嵁搴撳け璐�,璇峰皾璇曢噸鏂拌繛鎺�");
}finally{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showInternalMessageDialog(null, "娌℃湁鍏抽棴鏁版嵁搴撹鍏抽棴鏁版嵁搴�");
}
}
return object;
}
@Override
public Boolean delete(String tablename,int id) {
// TODO Auto-generated method stub
int count;
Connection conn = null;
Prepared