Compare commits
3 Commits
9f2583baab
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 4616bbda41 | |||
| ce67127d0d | |||
| b072f82a8f |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -39,7 +39,7 @@ public class MenuBar extends JMenuBar {
|
|||||||
bookSearch.addActionListener(new ActionListener() {
|
bookSearch.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new SearchDIalog("books");
|
new SearchDIalog("books").setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 创建查询学生信息菜单项
|
// 创建查询学生信息菜单项
|
||||||
@@ -47,7 +47,7 @@ public class MenuBar extends JMenuBar {
|
|||||||
// 为查询学生信息菜单项添加事件监听器,当点击时弹出学生信息查询对话框
|
// 为查询学生信息菜单项添加事件监听器,当点击时弹出学生信息查询对话框
|
||||||
studentSearch.addActionListener(new ActionListener() {
|
studentSearch.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new SearchDIalog("students");
|
new SearchDIalog("students").setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 创建查询借阅信息菜单项
|
// 创建查询借阅信息菜单项
|
||||||
@@ -55,7 +55,7 @@ public class MenuBar extends JMenuBar {
|
|||||||
// 为查询借阅信息菜单项添加事件监听器,当点击时弹出借阅信息查询对话框
|
// 为查询借阅信息菜单项添加事件监听器,当点击时弹出借阅信息查询对话框
|
||||||
rentSearch.addActionListener(new ActionListener() {
|
rentSearch.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new SearchDIalog("rents");
|
new SearchDIalog("rents").setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 将查询图书信息菜单项添加到查询菜单
|
// 将查询图书信息菜单项添加到查询菜单
|
||||||
@@ -72,7 +72,7 @@ public class MenuBar extends JMenuBar {
|
|||||||
// 为添加图书信息菜单项添加事件监听器,当点击时弹出图书信息添加对话框
|
// 为添加图书信息菜单项添加事件监听器,当点击时弹出图书信息添加对话框
|
||||||
bookAdd.addActionListener(new ActionListener() {
|
bookAdd.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new BookAdder();
|
new BookAdder().setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 创建添加学生信息菜单项
|
// 创建添加学生信息菜单项
|
||||||
|
|||||||
@@ -83,8 +83,6 @@ public class BookAdder extends JDialog {
|
|||||||
pack();
|
pack();
|
||||||
// 设置对话框位置
|
// 设置对话框位置
|
||||||
setLocation();
|
setLocation();
|
||||||
// 设置对话框可见
|
|
||||||
setVisible(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
<constraints/>
|
<constraints/>
|
||||||
<properties>
|
<properties>
|
||||||
<font name="PingFang SC" size="14"/>
|
<font name="PingFang SC" size="14"/>
|
||||||
<text value="https://gitee.com/msksbr"/>
|
<text value="https://msksbr.com/msksbr"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
</children>
|
</children>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<component id="a6e23" class="javax.swing.JLabel">
|
<component id="a6e23" class="javax.swing.JLabel">
|
||||||
<constraints/>
|
<constraints/>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="本项目已在gitee.com开源"/>
|
<text value="本项目已在git.msksbr.com开源"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
</children>
|
</children>
|
||||||
|
|||||||
@@ -59,8 +59,6 @@ public class SearchDIalog extends JDialog {
|
|||||||
pack();
|
pack();
|
||||||
// 设置对话框位置
|
// 设置对话框位置
|
||||||
setLocation();
|
setLocation();
|
||||||
// 设置对话框可见
|
|
||||||
setVisible(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="10" left="10" bottom="10" right="10"/>
|
<margin top="10" left="10" bottom="10" right="10"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<xy x="48" y="54" width="573" height="297"/>
|
<xy x="48" y="54" width="601" height="297"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
<constraints/>
|
<constraints/>
|
||||||
<properties>
|
<properties>
|
||||||
<font name="PingFang SC" size="14"/>
|
<font name="PingFang SC" size="14"/>
|
||||||
<text value="https://gitee.com/msksbr/system-homework-in-the-library"/>
|
<text value="https://git.msksbr.com/msksbr/system-homework-in-the-library"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
</children>
|
</children>
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="本软件完全免费,如果您从任何渠道购买到此软件及其源码,请联系作者:3141661556@qq.com"/>
|
<text value="本软件完全免费,如果您从任何渠道购买到此软件及其源码,请联系作者:gugugulaocuchen@gmail.com"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
</children>
|
</children>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class Connector {
|
|||||||
// SQL语句执行对象
|
// SQL语句执行对象
|
||||||
private Statement stmt;
|
private Statement stmt;
|
||||||
// 数据库连接URL
|
// 数据库连接URL
|
||||||
private String url = "jdbc:mysql://192.168.154.139:3306/book";
|
private String url = "jdbc:mysql://localhost:3306/book";
|
||||||
// 数据库用户名
|
// 数据库用户名
|
||||||
private String user = "root";
|
private String user = "root";
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ public class Connector {
|
|||||||
* 构造方法,初始化数据库连接。
|
* 构造方法,初始化数据库连接。
|
||||||
*
|
*
|
||||||
* @throws ClassNotFoundException 如果找不到MySQL驱动类。
|
* @throws ClassNotFoundException 如果找不到MySQL驱动类。
|
||||||
* @throws SQLException 如果数据库连接失败。
|
* @throws SQLException 如果数据库连接失败。
|
||||||
*/
|
*/
|
||||||
public Connector() throws ClassNotFoundException, SQLException {
|
public Connector() throws ClassNotFoundException, SQLException {
|
||||||
// 加载MySQL驱动类
|
// 加载MySQL驱动类
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import com.msksbr.SQL.Connector
|
||||||
|
import org.junit.jupiter.api.AfterEach
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertNotNull
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class TestDao {
|
||||||
|
private var connector: Connector? = null
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun setUp() {
|
||||||
|
connector = Connector()
|
||||||
|
connector?.executeUpdate(
|
||||||
|
"CREATE TABLE test_table(\n" +
|
||||||
|
"\ttest_string CHAR(35),\n" +
|
||||||
|
"\ttest_int INT\n" +
|
||||||
|
");"
|
||||||
|
)
|
||||||
|
connector?.executeUpdate(
|
||||||
|
"INSERT INTO test_table\n" +
|
||||||
|
"VALUES (\n" +
|
||||||
|
" '1',1\n" +
|
||||||
|
" );"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
fun tearDown() {
|
||||||
|
connector?.executeUpdate("DROP TABLE test_table")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testQuery() {
|
||||||
|
val rs = connector!!.executeQuery("SELECT * FROM test_table")
|
||||||
|
assertNotNull(rs,"result was null")
|
||||||
|
assertTrue(rs.next(),"No results found")
|
||||||
|
assertEquals(rs.getString("test_string"), "1","test_string is not \"1\"")
|
||||||
|
assertEquals(rs.getInt("test_int"), 1,"test_int is not 1")
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
fun testUpdate(){
|
||||||
|
val rs = connector!!.executeUpdate("INSERT INTO test_table\n" +
|
||||||
|
"VALUES (\n" +
|
||||||
|
" '2',2\n" +
|
||||||
|
" );")
|
||||||
|
val rs_q=connector!!.executeQuery("SELECT * FROM test_table WHERE test_string = '2';")
|
||||||
|
assertNotNull(rs,"result was null")
|
||||||
|
assertNotNull(rs_q,"result_q was null")
|
||||||
|
assertTrue(rs_q.next(),"no results found")
|
||||||
|
assertEquals(rs_q.getString("test_string"), "2","test_string is not \"2\"")
|
||||||
|
assertEquals(rs_q.getInt("test_int"), 2,"test_int is not 1")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import com.msksbr.MainFrm.MenuItemDiaog.Adder.BookAdder
|
||||||
|
import com.msksbr.MainFrm.MenuItemDiaog.SearchDIalog
|
||||||
|
import com.msksbr.SQL.Connector
|
||||||
|
import org.junit.jupiter.api.AfterEach
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.assertNotNull
|
||||||
|
|
||||||
|
class TestService {
|
||||||
|
var connector: Connector? = null
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun init() {
|
||||||
|
connector = Connector()
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
fun tearDown() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testGetBookMaxID() {
|
||||||
|
val bookAdder = BookAdder()
|
||||||
|
val max_id_from_ui = bookAdder.getBookMaxID()
|
||||||
|
bookAdder.dispose()
|
||||||
|
val rs = connector?.executeQuery("SELECT MAX(book_id) FROM books;")
|
||||||
|
rs?.next()
|
||||||
|
val max_id_from_sql = rs?.getInt(1)
|
||||||
|
|
||||||
|
assertNotNull(max_id_from_ui, "Get null value from function")
|
||||||
|
assertEquals(max_id_from_ui, max_id_from_sql, "Not equals to the query from sql")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import com.msksbr.MainFrm.MenuItemDiaog.Adder.BookAdder
|
||||||
|
import com.msksbr.SQL.Connector
|
||||||
|
import org.junit.jupiter.api.AfterEach
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.assertNotNull
|
||||||
|
|
||||||
|
class testUI {
|
||||||
|
var connector: Connector? = null;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun init() {
|
||||||
|
connector = Connector();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
fun tearDown() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testUIBeCenter() {
|
||||||
|
val bookAdder = BookAdder();
|
||||||
|
val location = bookAdder.location
|
||||||
|
val size = bookAdder.size
|
||||||
|
val screenSize = java.awt.Toolkit.getDefaultToolkit().screenSize
|
||||||
|
|
||||||
|
val expectedX = (screenSize.width - size.width) / 2
|
||||||
|
val expectedY = (screenSize.height - size.height) / 2
|
||||||
|
|
||||||
|
assertNotNull(location,"location is null")
|
||||||
|
assertEquals(expectedX, location.x, "x-coordinate is not be center")
|
||||||
|
assertEquals(expectedY, location.y, "y-coordinate is not be center")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user