3.2.2 系统功能模块算法设计
我们设计的美食信息管理系统主要包括管理员和客户登陆两大功能模块,其中管理员功能模块中能够进行美食信息的添加、修改、删除功能,客户功能模块中能够进行美食信息的查询、打印输出功能。在设计出各个功能模块界面后,最为核心的是要实现相应功能界面中的按钮触发事件。
例如,管理员端中新添美食信息功能界面中的添加按钮触发事件、修改美食信息功能界面中的修改按钮触发事件、删除美食信息功能界面中的删除按钮触发事件,客户端中查询美食信息功能界面中查询按钮的触发事件和打印美食信息按钮的触发事件。为这些触发事件设计一个良好的算法,能够大大提高程序的运行效率。
4、调试与分析
4.1、功能模块源代码
4.1.1新添美食信息功能模块添加按钮核心代码
源代码如下:
if(arg0.getSource() == btnNewButton_6){
String B2 = \; String B3 = \;
String A1 = textField.getText();
String B1 = comboBox.getSelectedItem().toString(); String C1 = comboBox_1.getSelectedItem().toString(); String D1 = comboBox_2.getSelectedItem().toString(); String E1 = comboBox_3.getSelectedItem().toString(); String F1 = textArea.getText(); if(B1.equals(\面类\)){ }
else if(B1.equals(\粉类\)){ }
B1 = \; B1 = \;
else if(B1.equals(\水果类\)){ B1 = \;
}
else if(B1.equals(\油炸类\)){ B1 = \; }
else if(B1.equals(\火锅类\)){ B1 = \; }
else if(B1.equals(\冷品类\)){ B1 = \; }
else if(B1.equals(\熟食类\)){ B1 = \; }
else if(B1.equals(\糕点类\)){ B1 = \; }
sql = \finefoodSiteNo from [Fine food site] where provice = '\+C1+\and city = '\+D1+\+E1+\; try {
Class.forName(\); System.out.println(\加载驱动程序成功\); }
catch(Exception e) {
System.out.println(\无法加载驱动程序\); }
try{
Connection conn
=DriverManager.getConnection(\food\
+ \,\, \);
Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); if(rs.next()){ B2 = rs.getString(1); System.out.println(B2); } else{
foodTypeNo = foodTypeNo + 1; B2 = foodTypeNo + \;
sql = \ int i = stmt.executeUpdate(sql); if(i>0)
values('\+B2+\+C1+\+D1+\+E1+\;
JOptionPane.showMessageDialog(null,\添加成功\); JOptionPane.showMessageDialog(null,\添加失败\);
else
//JOptionPane.showMessageDialog(this, \不存在这样的美食\错 }
rs.close();
stmt.close(); }
catch(SQLException e) {
System.out.println(\异常\); }
sql = \+C1+\
误!\
= '\+D1+\+E1+\;
try {
Class.forName(\); System.out.println(\加载驱动程序成功\); }
catch(Exception e) {
System.out.println(\无法加载驱动程序\); }
try{
Connection conn
=DriverManager.getConnection(\food\
+ \,\, \);
Statement stmt1 = conn.createStatement(); ResultSet rs1 = stmt1.executeQuery(sql); if(rs1.next()){ foodNameNo+=1; B3 = foodNameNo + \; System.out.println(B3); System.out.println(path_file);
//rs1 = stmt1.executeQuery(\ // String B6 = rs1.getString(1);
//System.out.println(\执行成功!!!!!!!!\ sql = \ //System.out.println(\
int i = stmt1.executeUpdate(sql);
finefoodNo from [Fine food Name]\
('\+B3+\+B1+\+A1+\+F1+\+path_file+\;
if(i>0)
JOptionPane.showMessageDialog(null,\插入成功\); JOptionPane.showMessageDialog(null,\插入失败\);
else } else{
JOptionPane.showMessageDialog(this, \添加异常\, \错 }
rs1.close();
stmt1.close(); }
catch(SQLException e) {
System.out.println(\异常\); }
sql = \+C1+\
误!\,JOptionPane.ERROR_MESSAGE);
city = '\+D1+\+E1+\;
try {
Class.forName(\); System.out.println(\加载驱动程序成功\); }
catch(Exception e) {
System.out.println(\无法加载驱动程序\); }
try{
Connection conn
=DriverManager.getConnection(\food\
+ \,\, \);
Statement stmt2 = conn.createStatement(); ResultSet rs2 = stmt2.executeQuery(sql); if(rs2.next()){ B2 = rs2.getString(1); B3 = foodNameNo + \;
sql = \+B2+\+B3+\; //System.out.println(\
int i = stmt2.executeUpdate(sql); if(i>0)
JOptionPane.showMessageDialog(this, \添加异常\, \错 }
rs2.close();
stmt2.close(); }
catch(SQLException e) {
System.out.println(\异常\); }
误!\,JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null,\插入成功
1111\);
else
JOptionPane.showMessageDialog(null,\插入失败
1111\);
} else{
}
4.1.2 新添美食信息功能模块美食图片按钮核心代码(获取图片信息)
源代码如下: //按钮触发事件中代码
if(arg0.getSource() == btnNewButton_5){
}
Insert_picture chooser = new Insert_picture(); path_file = chooser.file_path; System.out.println(path_file);
//Insert_picture类代码
public class Insert_picture extends JFrame {
private JPanel contentPane; public String file_path = \; /** * */
private static final long serialVersionUID = 1L;