之前做了一个外卖点餐系统之后点此查看详情,这段时间在这个系统的基础上改了改帮几位同学实现了其他的几个系统,本文所述的电力收费系统就是其中之一。
一、数据库表及字段
1、员工表
2、用电类型表
3、顾客表
4、用电信息表
5、费用表
6、缴费表
7、结余表
二、系统运行界面图(部分)
1、登陆界面
2、注册界面
3、用户的首界面
4、用户的缴费界面
5、管理员首界面
6、用户消费统计
7、业务员管理
管理中心里面的功能基本都差不多,所以就列举上面几个,下面展示主要代码。
三、部分核心代码
1、登录功能
private static final long serialVersionUID = 1L;
static String Cusername;
static String Cpassword;
String url = "jdbc:sqlserver://localhost:1433;DatabaseName=Electricity charging system";
String username = "sa";
String password = "123";
Connection connection = null;
PreparedStatement ps=null;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel2;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTextField;
private javax.swing.JToggleButton jToggleButton1;
public shouye() {
initComponents();
}
private void connectdb() {
try {
Class.forName( "com.microsoft.sqlserver.jdbc.SQLServerDriver" );
connection = DriverManager.getConnection(url, username, password );
}
catch ( ClassNotFoundException cnfex ) {
System.err.println(
"装载 JDBC/ODBC 驱动程序失败。" );
cnfex.printStackTrace();
System.exit( 1 );
}
catch ( SQLException sqlex ) {
System.err.println( "无法连接数据库" );
sqlex.printStackTrace();
System.exit( 1 );
}
}
private void initComponents() {
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextField = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jToggleButton1 = new javax.swing.JToggleButton();
jButton3 = new javax.swing.JButton();
jPasswordField1 = new javax.swing.JPasswordField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel2.setBackground(new java.awt.Color(18 ,161, 130));
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "电力收费管理系统", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("微软雅黑", 1, 24), new java.awt.Color(255, 255, 255))); // NOI18N
jPanel2.setAutoscrolls(true);
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel1.setText("账号:");
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel2.setText("密码:");
jTextField.setColumns(20);
jScrollPane1.setViewportView(jTextField);
jButton1.setText("登录");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
try {
jButton1ActionPerformed(evt);
} catch (SQLException e) {
e.printStackTrace();
}
}
});
jButton2.setText("注册");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jToggleButton1.setText("退出");
jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton1ActionPerformed(evt);
}
});
jButton3.setText("管理员登录");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jToggleButton1))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(162, 162, 162)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jButton1)
.addGap(85, 85, 85)
.addComponent(jButton2))
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jPasswordField1, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)))
.addContainerGap(171, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(69, 69, 69)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(51, 51, 51)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(36, 36, 36)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(41, 41, 41)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 118, Short.MAX_VALUE)
.addComponent(jToggleButton1))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton3)
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(113, 113, 113)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(290, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(44, 44, 44)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(441, Short.MAX_VALUE))
);
pack();
}
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) throws SQLException {
Cusername=jTextField.getText();
Cpassword=jPasswordField1.getText();
String sql="select customerId,customerPassword from customer where customerId=? and customerPassword=? ";
connectdb();
ps=connection.prepareStatement(sql);
ps.setString(1, Cusername);
ps.setString(2, Cpassword);
ResultSet rs=ps.executeQuery();
if(rs.next()) {
shouye.this.setVisible(false);
menu menu =new menu();
menu.setVisible(true);
}
else {
JOptionPane.showMessageDialog(null,"密码或用户名错误!!!!");
}
connection.close();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
shouye.this.setVisible(false);
zhuce Zhuce=new zhuce();
Zhuce.setVisible(true);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
shouye.this.setVisible(false);
guanlidenglu Guanlidenglu=new guanlidenglu();
Guanlidenglu.setVisible(true);
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(shouye.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(shouye.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(shouye.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(shouye.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new shouye().setVisible(true);
}
});
}
2、缴费功能
float sum=0;
float actuallyPrice=0;
float shouldPrice=0;
int actYear=0;
int actMouth=0;
String newDate;
boolean falg=false;
public String num1;
public int row;
String url = "jdbc:sqlserver://localhost:1433;DatabaseName=Electricity charging system";
String username = "sa";
String password = "123";
Connection conn=null;
PreparedStatement pstm=null;
Statement stmt = null;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JToggleButton jToggleButton1;
private javax.swing.JToggleButton jToggleButton2;
public pay() {
initComponents();
}
private void connectdb() {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException cnfe) {
JOptionPane.showMessageDialog(null, "数据源错误", "错误", JOptionPane.ERROR_MESSAGE);
} catch (SQLException sqle) {
JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE);
}
}
private void initComponents() {
jPanel2 = new javax.swing.JPanel();
jToggleButton1 = new javax.swing.JToggleButton();
jToggleButton2 = new javax.swing.JToggleButton();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton2 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jTextField2 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel2.setBackground(new java.awt.Color(18 ,161, 130));
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "电力收费管理系统", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("微软雅黑", 1, 24), new java.awt.Color(255, 255, 255))); // NOI18N
jPanel2.setAutoscrolls(true);
jToggleButton1.setText("退出");
jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton1ActionPerformed(evt);
}
});
jToggleButton2.setText("返回");
jToggleButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton2ActionPerformed(evt);
}
});
jButton1.setText("搜索");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton3.setText("查询所有");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(jTable1);
jButton2.setText("选择缴费");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton4.setText("确认支付");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jLabel1.setText("总金额");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton1))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(49, 49, 49)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 308, Short.MAX_VALUE)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton4)
.addComponent(jButton3)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jToggleButton2)
.addGap(18, 18, 18)
.addComponent(jToggleButton1))))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1)
.addComponent(jButton3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton4)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jToggleButton1)
.addComponent(jToggleButton2))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(61, 61, 61)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(245, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(49, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(101, 101, 101))
);
pack();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String text=jTextField1.getText();
try {
String sql = "select feeInfo.year,feeInfo.feeMark,feeInfo.mouth,shouldFee,actuallyFee,balanceFee from feeInfo,balanceInfo where feeInfo.customerId=balanceInfo.customerId and feeInfo.mouth=balanceInfo.mouth and feeInfo.year=balanceInfo.year and balanceInfo.balanceFee>0 and balanceInfo.customerId='"+shouye.Cusername+"' and (feeInfo.mouth='"+text+"' or feeInfo.year='"+text+"') ";
connectdb();
pstm = conn.prepareStatement(sql);
ResultSet rs = pstm.executeQuery();
int count = 0;
while (rs.next()) {
count++;
}
rs = pstm.executeQuery();
Object[][] info = new Object[count][6];
count = 0;
while (rs.next()) {
info[count][0] = Integer.valueOf(rs.getInt("year"));
info[count][1] = Integer.valueOf(rs.getInt("mouth"));
info[count][2] = Float.valueOf(rs.getFloat("shouldFee"));
info[count][3] = Float.valueOf(rs.getFloat("actuallyFee"));
info[count][4] = rs.getString("feeMark");
info[count][5] = Float.valueOf(rs.getFloat("balanceFee"));
count++;
}
String[] title = { "年份","月份", "应缴费用","实缴费用","缴费标志","结余费用"};
this.jTable1 = new JTable(info, title);
this.jScrollPane1.getViewport().add(jTable1);
conn.close();
}catch (SQLException sqle) {
JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE);
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
row=jTable1.getSelectedRow();
actuallyPrice=(Float) jTable1.getValueAt(row, 3);
shouldPrice=(Float) jTable1.getValueAt(row, 2);
System.out.println(actuallyPrice);
System.out.println(jTable1.getValueAt(row,1));
actMouth=(Integer) jTable1.getValueAt(row,1);
actYear=(Integer) jTable1.getValueAt(row,0);
System.out.println(actMouth);
System.out.println(actYear);
num1=JOptionPane.showInputDialog("您选择的缴费项为:"+jTable1.getValueAt(row, 0)+"年"+jTable1.getValueAt(row, 1)+"月,"+"请输入支付金额:");
sum=Float.parseFloat(num1);
if(sum<=0){
JOptionPane.showMessageDialog(null,"请输入大于0的金额!");
return;
}else if (sum==actuallyPrice){
falg=true;
}
jTextField2.setText(String.valueOf(sum));
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
try {
connectdb();
String sql = "select feeInfo.year,feeInfo.feeMark,feeInfo.mouth,shouldFee,actuallyFee,balanceFee from feeInfo,balanceInfo where feeInfo.customerId=balanceInfo.customerId and feeInfo.mouth=balanceInfo.mouth and feeInfo.year=balanceInfo.year and balanceInfo.balanceFee>0 and balanceInfo.customerId='"+shouye.Cusername+"'";
pstm = conn.prepareStatement(sql);
ResultSet rs = pstm.executeQuery();
int count = 0;
while (rs.next()) {
count++;
}
rs = pstm.executeQuery();
Object[][] info = new Object[count][6];
count = 0;
while (rs.next()) {
info[count][0] = Integer.valueOf(rs.getInt("year"));
info[count][1] = Integer.valueOf(rs.getInt("mouth"));
info[count][2] = Float.valueOf(rs.getFloat("shouldFee"));
info[count][3] = Float.valueOf(rs.getFloat("actuallyFee"));
info[count][4] = rs.getString("feeMark");
info[count][5] = Float.valueOf(rs.getFloat("balanceFee"));
count++;
}
String[] title = { "年份","月份", "应缴费用","实缴费用","缴费标志","结余费用"};
this.jTable1 = new JTable(info, title);
this.jScrollPane1.getViewport().add(jTable1);
conn.close();
}catch (SQLException sqle) {
JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE);
}
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
if(sum==0) {
JOptionPane.showMessageDialog(null, "请选择缴费项后再进行支付!!!");
return;
}
try {
connectdb();
stmt = conn.createStatement();
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd mm:ss");
newDate=simpleDateFormat.format(new Date());
System.out.println(newDate);
// String sex=JOptionPane.showInputDialog("请输入缴费日期:");
// if (sex.equals("")){
// JOptionPane.showMessageDialog(null,"您输入了空值");
// return;
// }
String sql3="insert into chargeInfo(customerId,year,mouth,chargeTime,shouldFee,actuallyFee)" + "values('"+shouye.Cusername+"','"+actYear+"','"+actMouth+"','"+new Date()+"','"+shouldPrice+"','"+sum+"')";
stmt.executeUpdate(sql3);
if(falg){
String sql1 = "update feeInfo set feeMark='已缴清' where customerId='"+shouye.Cusername+"' and year='"+actYear+"' and mouth='"+actMouth+"'";
String sql2 = "update balanceInfo set actuallyFee='"+actuallyPrice+"',balanceFee=0 where customerId='"+shouye.Cusername+"' and year='"+actYear+"' and mouth='"+actMouth+"'";
stmt.executeUpdate(sql1);
stmt.executeUpdate(sql2);
}else{
String sql1 = "update balanceInfo set actuallyFee='"+sum+"'+actuallyFee,balanceFee=shouldFee-actuallyFee-'"+sum+"' where customerId='"+shouye.Cusername+"' and year='"+actYear+"' and mouth='"+actMouth+"'";
stmt.executeUpdate(sql1);
}
conn.close();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "数据源错误!!!");
return;
}
JOptionPane.showMessageDialog(null, "支付成功!祝您生活愉快!");
pay.this.setVisible(false);
pay pay =new pay();
pay.setVisible(true);
}
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {
pay.this.setVisible(false);
menu menu =new menu();
menu.setVisible(true);
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(pay.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(pay.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(pay.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(pay.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new pay().setVisible(true);
}
});
}
3、业务员管理功能
Connection conn = null;
Statement stmt = null;
PreparedStatement pstm =null;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
private javax.swing.JToggleButton jToggleButton1;
private javax.swing.JToggleButton jToggleButton2;
public yewuyuanguanli() {
initComponents();
}
private void connectdb() {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=Electricity charging system","sa", "123");
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private void initComponents() {
jPanel2 = new javax.swing.JPanel();
jToggleButton1 = new javax.swing.JToggleButton();
jToggleButton2 = new javax.swing.JToggleButton();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel2.setBackground(new java.awt.Color(18 ,161, 130));
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "电力收费管理系统", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("微软雅黑", 1, 24), new java.awt.Color(255, 255, 255))); // NOI18N
jPanel2.setAutoscrolls(true);
jToggleButton1.setText("退出");
jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton1ActionPerformed(evt);
}
});
jToggleButton2.setText("返回");
jToggleButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton2ActionPerformed(evt);
}
});
jButton1.setText("修改");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(jTable1);
jButton8.setText("刷新");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton8ActionPerformed(evt);
}
});
jButton9.setText("删除");
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton9ActionPerformed(evt);
}
});
jButton10.setText("查询");
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton10ActionPerformed(evt);
}
});
jButton2.setText("增加");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGap(0, 699, Short.MAX_VALUE)
.addComponent(jToggleButton2)
.addGap(18, 18, 18)
.addComponent(jToggleButton1))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jScrollPane1)
.addContainerGap())
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton8)
.addGap(54, 54, 54))))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGap(15, 15, 15)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton10)
.addComponent(jButton1)
.addComponent(jButton9)
.addComponent(jButton8)
.addComponent(jButton2))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jToggleButton1)
.addComponent(jToggleButton2))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(47, 47, 47)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(282, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(50, 50, 50)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(359, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String No=JOptionPane.showInputDialog("请输入你要修改的业务员的编号:");
if (No.equals("")){
JOptionPane.showMessageDialog(null, "您输入了空值!!!");
return;
}
String Name=JOptionPane.showInputDialog("请输入新的业务员姓名:");
if (Name.equals("")){
JOptionPane.showMessageDialog(null, "您输入了空值!!!");
return;
}
String tel=JOptionPane.showInputDialog("请输入新的业务员电话号码:");
if (tel.equals("")){
JOptionPane.showMessageDialog(null, "您输入了空值!!!");
return;
}
String adress=JOptionPane.showInputDialog("请输入新的业务员住址:");
if (adress.equals("")){
JOptionPane.showMessageDialog(null, "您输入了空值!!!");
return;
}
try {
connectdb();
String sql = "update employee set employeeName='"+Name+"',employeeTel='"+tel+"',employeeAddress='"+adress+"' where employeeId='"+No+"'";
stmt = conn.createStatement();
stmt.executeUpdate(sql);
JOptionPane.showMessageDialog(null, "修改成功!!!");
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String No=JOptionPane.showInputDialog("请输入业务员编号:");
if (No.equals("")){
JOptionPane.showMessageDialog(null, "您输入了空值!!!");
return;
}
String Name=JOptionPane.showInputDialog("请输入业务员姓名:");
if (Name.equals("")){
JOptionPane.showMessageDialog(null, "您输入了空值!!!");
return;
}
String tel=JOptionPane.showInputDialog("请输入业务员电话:");
if (tel.equals("")){
JOptionPane.showMessageDialog(null, "您输入了空值!!!");
return;
}
String adress=JOptionPane.showInputDialog("请输入业务员地址:");
if (adress.equals("")){
JOptionPane.showMessageDialog(null, "您输入了空值!!!");
return;
}
String sex=JOptionPane.showInputDialog("请输入业务员性别:");
if (sex.equals("")){
JOptionPane.showMessageDialog(null, "您输入了空值!!!");
return;
}
Integer randPassword=(int)(Math.random()*(999999)+1);
String empPassword=String.format("%06d",randPassword);
try {
connectdb();
String sql = "insert into employee(employeeId,employeeName,employeeTel,employeeAddress,employeeSex,employeePassword)"+"values('"+No+"','"+Name+"','"+tel+"','"+adress+"','"+sex+"','"+empPassword+"')";
stmt = conn.createStatement();
stmt.executeUpdate(sql);
JOptionPane.showMessageDialog(null, "添加成功,该业务员初始密码为:"+empPassword+"请牢记!");
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
try {
connectdb();
String sql = "select * from employee";
pstm = conn.prepareStatement(sql);
ResultSet rs = pstm.executeQuery();
int count = 0;
while (rs.next()) {
count++;
}
rs = pstm.executeQuery();
Object[][] info = new Object[count][6];
count = 0;
while (rs.next()) {
info[count][0] = Integer.valueOf(rs.getInt("employeeId"));
info[count][1] = rs.getString("employeeName");
info[count][2] = rs.getString("employeeTel");
info[count][3] = rs.getString("employeeAddress");
info[count][4] = rs.getString("employeeSex");
count++;
}
String[] title = { "业务员编号", "业务员名称","业务员电话","业务员地址","业务员性别" };
this.jTable1 = new JTable(info, title);
this.jScrollPane1.getViewport().add(jTable1);
conn.close();
}catch (SQLException sqle) {
JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE);
}
}
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
String No=JOptionPane.showInputDialog("请输入你要删除的业务员编号:");
if (No.equals("")){
JOptionPane.showMessageDialog(null, "您输入了空值!!!");
return;
}
try {
connectdb();
String sql = "delete from employee where employeeId='"+No+"';";
stmt = conn.createStatement();
stmt.executeUpdate(sql);
JOptionPane.showMessageDialog(null, "删除成功!!!");
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {
String text=jTextField1.getText();
try {
connectdb();
String sql = "select * from employee where employeeName like '%"+text+"%'";
pstm = conn.prepareStatement(sql);
ResultSet rs = pstm.executeQuery();
int count = 0;
while (rs.next()) {
count++;
}
rs = pstm.executeQuery();
Object[][] info = new Object[count][6];
count = 0;
while (rs.next()) {
info[count][0] = Integer.valueOf(rs.getInt("employeeId"));
info[count][1] = rs.getString("employeeName");
info[count][2] = rs.getString("employeeTel");
info[count][3] = rs.getString("employeeAddress");
info[count][4] = rs.getString("employeeSex");
count++;
}
String[] title = { "业务员编号", "业务员名称","业务员电话","业务员地址","业务员性别" };
this.jTable1 = new JTable(info, title);
this.jScrollPane1.getViewport().add(jTable1);
conn.close();
}catch (SQLException sqle) {
JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE);
}
}
private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {
yewuyuanguanli.this.setVisible(false);
guanli Guanli=new guanli();
Guanli.setVisible(true);
}
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(yewuyuanguanli.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(yewuyuanguanli.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(yewuyuanguanli.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(yewuyuanguanli.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new yewuyuanguanli().setVisible(true);
}
});
}
因篇幅有限,只展示此三个主要模块的代码。以上三个模块的代码基本覆盖了整个系统代码的实现方法,其他模块的基本按照上述代码写法复制粘贴即可,如果有需要完整源代码的可以v我(备注来源):ES-Lad或者自行下载:https://download.csdn.net/download/weixin_46671666/73818561