Skip to content

Commit

Permalink
添加初始化按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
houyi committed Oct 15, 2014
1 parent 91d2832 commit cd1ab26
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 14 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.2-GA</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion resources/applicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<context:property-placeholder location="classpath*:/lottery.properties"/>

<!--<context:component-scan base-package="com.lottery"/>-->
<context:component-scan base-package="com.lottery"/>

<!-- 使用 annotation -->
<context:annotation-config />
Expand Down
9 changes: 9 additions & 0 deletions resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### set log levels ###
log4j.rootLogger = INFO,console
log4j.logger.org.hibernate.type=TRACE
log4j.logger.com.itec.bdp=DEBUG
#console
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.Target = System.out
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern = %-d{HH:mm:ss} [%t:%r] - [%p] %m%n
3 changes: 2 additions & 1 deletion resources/lottery.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ javax.persistence.validation.mode=none

#------------ H2 ------------
h2.jdbc.driver=org.h2.Driver
h2.jdbc.url=jdbc:h2:tcp://127.0.0.1/~/lottery
#h2.jdbc.url=jdbc:h2:tcp://127.0.0.1/~/lottery
h2.jdbc.url=jdbc:h2:~/lottery
h2.hibernate.dialect=org.hibernate.dialect.H2Dialect
h2.jdbc.username=lottery
h2.jdbc.password=lottery
Expand Down
1 change: 1 addition & 0 deletions src/com/lottery/Launcher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lottery;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
Expand Down
9 changes: 5 additions & 4 deletions src/com/lottery/action/ImportBtnAction.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lottery.action;

import com.lottery.model.LotteryAll;
import com.lottery.model.LotteryAny;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

Expand Down Expand Up @@ -63,14 +64,14 @@ private void processImport(File file) {
try {
List<String> lines = FileUtils.readLines(file);

List<LotteryAll> lotteryAlls = new ArrayList<LotteryAll>();
List<LotteryAny> lotteryAnys = new ArrayList<LotteryAny>();
for (String line : lines) {
LotteryAll lotteryAll = new LotteryAll();
LotteryAny lotteryAny = new LotteryAny();

lotteryAlls.add(lotteryAll);
lotteryAnys.add(lotteryAny);
}

//TODO 保存 lotteryAlls
//TODO 保存 lotteryAnys


} catch (IOException e) {
Expand Down
20 changes: 20 additions & 0 deletions src/com/lottery/action/InitDataAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.lottery.action;

import com.lottery.service.LotteryAllService;
import org.springframework.beans.factory.annotation.Autowired;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
* Created by houyi on 2014/10/15.
*/
public class InitDataAction implements ActionListener {
@Autowired
private LotteryAllService lotteryAllService;

@Override
public void actionPerformed(ActionEvent e) {
lotteryAllService.initLotteryData();
}
}
42 changes: 42 additions & 0 deletions src/com/lottery/service/LotteryAllService.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.lottery.service;

import com.lottery.model.LotteryAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lottery.dao.LotteryAllDao;
import org.springframework.transaction.annotation.Transactional;

/**
* @author houyi
Expand All @@ -13,4 +15,44 @@
public class LotteryAllService {
@Autowired
private LotteryAllDao lotteryAllDao;

@Transactional
public void initLotteryData(){
for (int i = 0 ; i <= 99999 ; i ++){
LotteryAll lotteryAll = new LotteryAll();
if(i >= 0 && i < 10){
lotteryAll.setFront_one(0);
lotteryAll.setFront_two(0);
lotteryAll.setFront_three(0);
lotteryAll.setFront_four(0);
lotteryAll.setFront_five(i);
}else if(i >= 10 && i < 100){
lotteryAll.setFront_one(0);
lotteryAll.setFront_two(0);
lotteryAll.setFront_three(0);
lotteryAll.setFront_four(Integer.parseInt(String.valueOf(i).substring(0, 1)));
lotteryAll.setFront_five(Integer.parseInt(String.valueOf(i).substring(1)));
}else if(i >= 100 && i < 1000){
lotteryAll.setFront_one(0);
lotteryAll.setFront_two(0);
lotteryAll.setFront_three(Integer.parseInt(String.valueOf(i).substring(0, 1)));
lotteryAll.setFront_four(Integer.parseInt(String.valueOf(i).substring(1, 2)));
lotteryAll.setFront_five(Integer.parseInt(String.valueOf(i).substring(2)));
}else if(i >= 1000 && i < 10000){
lotteryAll.setFront_one(0);
lotteryAll.setFront_two(Integer.parseInt(String.valueOf(i).substring(0, 1)));
lotteryAll.setFront_three(Integer.parseInt(String.valueOf(i).substring(1, 2)));
lotteryAll.setFront_four(Integer.parseInt(String.valueOf(i).substring(2, 3)));
lotteryAll.setFront_five(Integer.parseInt(String.valueOf(i).substring(3)));
}else if(i >= 10000 && i <= 99999){
lotteryAll.setFront_one(Integer.parseInt(String.valueOf(i).substring(0, 1)));
lotteryAll.setFront_two(Integer.parseInt(String.valueOf(i).substring(1, 2)));
lotteryAll.setFront_three(Integer.parseInt(String.valueOf(i).substring(2, 3)));
lotteryAll.setFront_four(Integer.parseInt(String.valueOf(i).substring(3, 4)));
lotteryAll.setFront_five(Integer.parseInt(String.valueOf(i).substring(4)));
}
lotteryAll.setStatus("N");
lotteryAllDao.save(lotteryAll);
}
}
}
1 change: 1 addition & 0 deletions src/com/lottery/service/LotteryAnyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
public class LotteryAnyService {
@Autowired
private LotteryAnyDao lotteryAnyDao;

}
23 changes: 15 additions & 8 deletions src/com/lottery/ui/MainUI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lottery.ui;

import com.lottery.action.ImportBtnAction;
import com.lottery.action.InitDataAction;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
Expand Down Expand Up @@ -34,21 +35,22 @@ public void run() {
* Create the frame.
*/
public MainUI() {
setTitle("\u5927\u4E50\u900F\u5206\u6790\u7CFB\u7EDF");
setTitle("大乐透分析系统");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);

JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);

JMenu mnNewMenu = new JMenu("\u6587\u4EF6");
JMenu mnNewMenu = new JMenu("文 件");
menuBar.add(mnNewMenu);

JMenuItem menuItem = new JMenuItem("\u5BFC\u5165\u6570\u636E");
JMenuItem menuItem = new JMenuItem("导入数据");
mnNewMenu.add(menuItem);

JMenuItem menuItem_1 = new JMenuItem("\u9000\u51FA");
JMenuItem menuItem_1 = new JMenuItem("退 出");
mnNewMenu.add(menuItem_1);

contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
Expand All @@ -58,17 +60,22 @@ public MainUI() {
toolBar.setEnabled(false);
contentPane.add(toolBar, BorderLayout.NORTH);

JButton importBtn = new JButton("\u5BFC\u5165\u6570\u636E");
JButton initBtn = new JButton("初始化数据");
initBtn.addActionListener(new InitDataAction());
initBtn.setPreferredSize(new Dimension(100, 30));
toolBar.add(initBtn);

JButton importBtn = new JButton("导入数据");
importBtn.addActionListener(new ImportBtnAction());
importBtn.setPreferredSize(new Dimension(60, 30));
importBtn.setPreferredSize(new Dimension(80, 30));
toolBar.add(importBtn);

JComboBox<Object> comboBox_1 = new JComboBox<Object>();
comboBox_1.setPreferredSize(new Dimension(400, 30));
comboBox_1.setPreferredSize(new Dimension(350, 30));
toolBar.add(comboBox_1);

JComboBox<Object> comboBox = new JComboBox<Object>();
comboBox.setPreferredSize(new Dimension(400, 30));
comboBox.setPreferredSize(new Dimension(350, 30));
toolBar.add(comboBox);
}

Expand Down

0 comments on commit cd1ab26

Please sign in to comment.