Skip to content

Commit

Permalink
8/23
Browse files Browse the repository at this point in the history
  • Loading branch information
charliecat22 committed Aug 23, 2017
0 parents commit 5707d8d
Show file tree
Hide file tree
Showing 52 changed files with 2,424 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="E:/迅雷下载/how2j/Swing样式大全-全56种经典/Swing样式大全(全56种经典)/5种经典的Alloy和liquidlnf/liquidlnf.jar"/>
<classpathentry kind="lib" path="libs/chart.jar"/>
<classpathentry kind="lib" path="libs/swingx-core-1.6.2.jar"/>
<classpathentry kind="lib" path="libs/mysql-connector-java-5.0.8-bin.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>hutibill</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Binary file added img/backup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/category1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/category2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/record.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/restore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added libs/chart.jar
Binary file not shown.
Binary file added libs/liquidlnf.jar
Binary file not shown.
Binary file added libs/mysql-connector-java-5.0.8-bin.jar
Binary file not shown.
Binary file added libs/swingx-core-1.6.2.jar
Binary file not shown.
137 changes: 137 additions & 0 deletions src/dao/CategoryDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import entity.Category;
import util.DBUtil;

public class CategoryDAO {

public int getTotal() {
int total = 0;
try (Connection c = DBUtil.getConnection();Statement s = c.createStatement();){
String sql = "select count(*) from category";
ResultSet rs = s.executeQuery(sql);
while(rs.next()){
total = rs.getInt(1);
}
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
return total;
}


public void add(Category category) {

String sql = "insert into category values(null,?)";
try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {

ps.setString(1, category.name);

ps.execute();

ResultSet rs = ps.getGeneratedKeys();
if (rs.next()) {
int id = rs.getInt(1);
category.id = id;
}
} catch (SQLException e) {

e.printStackTrace();
}
}

public void update(Category category) {

String sql = "update category set name= ? where id = ?";
try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {

ps.setString(1, category.name);
ps.setInt(2, category.id);

ps.execute();

} catch (SQLException e) {

e.printStackTrace();
}

}

public void delete(int id) {

try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) {

String sql = "delete from category where id = " + id;

s.execute(sql);

} catch (SQLException e) {

e.printStackTrace();
}
}

public Category get(int id) {
Category category = null;

try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) {

String sql = "select * from category where id = " + id;

ResultSet rs = s.executeQuery(sql);

if (rs.next()) {
category = new Category();
String name = rs.getString(2);
category.name = name;
category.id = id;
}

} catch (SQLException e) {

e.printStackTrace();
}
return category;
}

public List<Category> list() {
return list(0, Short.MAX_VALUE);
}

public List<Category> list(int start, int count) {
List<Category> categorys = new ArrayList<Category>();

String sql = "select * from category order by id desc limit ?,? ";

try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {

ps.setInt(1, start);
ps.setInt(2, count);

ResultSet rs = ps.executeQuery();

while (rs.next()) {
Category category = new Category();
int id = rs.getInt(1);
String name = rs.getString(2);
category.id = id;
category.name = name;
categorys.add(category);
}
} catch (SQLException e) {

e.printStackTrace();
}
return categorys;
}

}
171 changes: 171 additions & 0 deletions src/dao/ConfigDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package dao;

import java.sql.Connection;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import entity.Config;
import util.DBUtil;

public class ConfigDAO {

public int getTotal() {
int total = 0;
try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) {

String sql = "select count(*) from config";

ResultSet rs = s.executeQuery(sql);
while (rs.next()) {
total = rs.getInt(1);
}

System.out.println("total:" + total);

} catch (SQLException e) {

e.printStackTrace();
}
return total;
}

public void add(Config config) {

String sql = "insert into config values(null,?,?)";
try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {
ps.setString(1, config.key);
ps.setString(2, config.value);
ps.execute();
ResultSet rs = ps.getGeneratedKeys();
if (rs.next()) {
int id = rs.getInt(1);
config.id = id;
}
} catch (SQLException e) {

e.printStackTrace();
}
}

public void update(Config config) {

String sql = "update config set key_= ?, value=? where id = ?";
try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {

ps.setString(1, config.key);
ps.setString(2, config.value);
ps.setInt(3, config.id);

ps.execute();

} catch (SQLException e) {

e.printStackTrace();
}

}

public void delete(int id) {

try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) {

String sql = "delete from config where id = " + id;

s.execute(sql);

} catch (SQLException e) {

e.printStackTrace();
}
}

public Config get(int id) {
Config config = null;

try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) {

String sql = "select * from config where id = " + id;

ResultSet rs = s.executeQuery(sql);

if (rs.next()) {
config = new Config();
String key = rs.getString("key_");
String value = rs.getString("value");
config.key = key;
config.value = value;
config.id = id;
}

} catch (SQLException e) {

e.printStackTrace();
}
return config;
}

public List<Config> list() {
return list(0, Short.MAX_VALUE);
}

public List<Config> list(int start, int count) {
List<Config> configs = new ArrayList<Config>();

String sql = "select * from config order by id desc limit ?,? ";

try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {

ps.setInt(1, start);
ps.setInt(2, count);

ResultSet rs = ps.executeQuery();

while (rs.next()) {
Config config = new Config();
int id = rs.getInt(1);
String key = rs.getString("key_");
String value = rs.getString("value");
config.id = id;
config.key = key;
config.value = value;
configs.add(config);
}
} catch (SQLException e) {

e.printStackTrace();
}
return configs;
}

public Config getByKey(String key) {
Config config = null;
String sql = "select * from config where key_ = ?" ;
try (Connection c = DBUtil.getConnection();
PreparedStatement ps = c.prepareStatement(sql);
) {

ps.setString(1, key);
ResultSet rs =ps.executeQuery();

if (rs.next()) {
config = new Config();
int id = rs.getInt("id");
String value = rs.getString("value");
config.key = key;
config.value = value;
config.id = id;
}

} catch (SQLException e) {

e.printStackTrace();
}
return config;
}

}
Loading

0 comments on commit 5707d8d

Please sign in to comment.