报刊订阅管理系统源代码+ER图 第5页

报刊订阅管理系统源代码+ER图 第5页
throws SQLException {
  Vector<String> currentRow = new Vector<String>();
  for (int i = 1; i <= rsmd.getColumnCount(); ++i)
   currentRow.addElement(rs.getString(i));
  return currentRow; // 返回一条记录
}
//-----------------------------------------------------------------------------
//所属类:Utilities
//功能:创建空白EXCEL文件,并将统计查询结果导出到该EXCEL文件
//说明:使用到org.apache的POI包,表示感谢
public static boolean outPut(ResultSet rs, File file) {
  if (rs == null)
   return false;
  try {
   HSSFWorkbook wb = new HSSFWorkbook();
   HSSFSheet sheet = wb.createSheet("first sheet");
   sheet.setDefaultColumnWidth((short) 20);
   ResultSetMetaData metadata = rs.getMetaData();
   int columnCount = metadata.getColumnCount();// 获取属性列数
   HSSFRow row = sheet.createRow((short) 0);
   for (int i = 1; i <= columnCount; i++) {// 填写表格列名
    row.createCell((short) (i - 1)).setCellValue(
      metadata.getColumnName(i));
   }
   // 按行填写记录
   rs.beforeFirst();
   short counter = 1;
   while (rs.next()) {
    row = sheet.createRow(counter++);
    for (int i = 1; i <= columnCount; i++) {
     row.createCell((short) (i - 1)).setCellValue(
       String.valueOf(rs.getObject(i)));
    }
   }
   FileOutputStream fileOut = new FileOutputStream(file);
   wb.write(fileOut);// 结果输出到文件
   fileOut.close();// 关闭输出流
  } catch (Exception exc) {
   exc.printStackTrace();
  }
  return true;
 }
}
//-----------------------------------------------------------------------------
//所属类:Newspaper
//功能:统计查询
final JMenuItem menuItem_9 = new JMenuItem();
  menuItem_9.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
    String sql = "SELECT Diretory.Did AS 刊物编号,Dname AS 刊物名称,"
      + "SUM(Quantity*QiShu) AS 总订阅数,SUM(Total) AS 总金额"
  + " FROM Diretory LEFT JOIN OrderDetail ON (OrderDetail.Did=Diretory.Did) "
      + " GROUP BY Diretory.Did,Diretory.Dname "
      + " ORDER BY SUM(Total) DESC";
    try {
     Utilities.rs = Utilities.stmt.executeQuery(sql);// 执行统计查询
     Utilities.displayResultSet(table, Utilities.rs);//显示查询结果
    } catch (SQLException exc) {
     exc.printStackTrace();
    }
   }
  });
//-----------------------------------------------------------------------------//所属类:UserCreateDlg
//功能:创建新用户
final JButton button = new JButton();
  button.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
    if (textField_1.getText().trim().length() != 0
      && textField_2.getText().trim().length() != 0
      && textField_3.getText().trim().length() != 0) {
     String sql = "INSERT INTO Customer(Cid,Cname,Phone,Address) "
       + "VALUES('"
       + textField.getText().trim()
       + "','"
       + textField_1.getText().trim()
       + "','"
       + textField_2.getText().trim()
       + "','"
       + textField_3.getText().trim() + "')";
     try {
      Utilities.stmt.executeUpdate(sql);// 执行数据行插入
      JOptionPane.showMessageDialog(dialog, "用户:"
        + textField_1.getText() + "添加成功\nID:"
        + textField.getText(), "Success !",
        JOptionPane.INFORMATION_MESSAGE);
      dispose();
     } catch (SQLException exc) {
      exc.printStackTrace();
     }
    } else {
     JOptionPane.showMessageDialog(dialog, "信息不全,无法添加",
       "Check your input !", JOptionPane.ERROR_MESSAGE);
    }
   }
 });
//-----------------------------------------------------------------------------//所属类:UserModifyDlg
//功能:用户信息更新修改
button_2 = new JButton();
  button_2.setEnabled(false);
  button_2.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
    if (textField_1.getText().trim().length() != 0
      && textField_2.getText().trim().length() != 0
      && textField_3.getText().trim().length() != 0) {
     try {
      Utilities.rs.updateString("Cname", textField_1
        .getText().trim());
      Utilities.rs.updateString("Phone", textField_2
        .getText().trim());
      Utilities.rs.updateString("Address", textField_3
        .getText().trim());
      Utilities.rs.updateRow();// 更新数据行
      JOptionPane.showMessageDialog(dialog, "更新成功!",
        "Success !", JOptionPane.INFORMATION_MESSAGE);
      dispose();
     } catch (SQLException exc) {
     }
    } else {
     JOptionPane.showMessageDialog(dialog, "信息不全,无法修改",
       "Check your input !", JOptionPane.ERROR_MESSAGE);
    }
   }
  });
//-----------------------------------------------------------------------------//所属类:BookingDlg
//功能:读取订单数据,向系统添加订单
button_1 = new JButton();
  button_1.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
    try {
     String sql = "SELECT UnitPrice FROM Diretory WHERE Did='"
       + comboBox.getSelectedItem() + "'";
     Utilities.rs = Utilities.stmt.executeQuery(sql);
// 查询当前选择目录刊物的单价
     if (Utilities.rs.next()) {
      unitPrice = Utilities.rs.getFloat("UnitPrice");
      quantity = Integer.parseInt(textField_1.getText());
      qishu = Integer.parseInt(textField_2.getText());
      total = unitPrice * quantity * qishu;
      sum += total;
  sql = "INSERT INTO OrderDetail (ONo, Did, Quantity, QiShu, UnitPrice, total)"
        + "VALUES('"
        + label_2.getText()
        + "','"
        + comboBox.getSelectedItem()
        + "',"
        + quantity
        + ","
        + qishu
        + ","
        + unitPrice
        + ","
        + total
        + ")";
      sqls.add(sql);// 寄存订单细节插入语句
      comboBox.removeItem(comboBox.getSelectedItem());
   // 将已选择目录从下拉选择框中移除(一个订单不能有两个目录相同的订单项)
     }
    } catch (SQLException exc) {
     exc.printStackTrace();
    } catch (NumberFormatException exc) {
     JOptionPane.showMessageDialog(dialog, "错误数字输入",
       "Check again !", JOptionPane.ERROR_MESSAGE);
    }
   }
  });
  button_1.setEnabled(false);
  button_1.setText("添加订单项");
  panel_1.add(button_1);
  button_2 = new JButton();
  button_2.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
    if (sqls.size() > 1) {
  // 容器第一个空间放插入Order的sql语句,其它空间放插入OrderDetail的sql语句
     // sqls.size()==1表示只有一张空订单,不予插入
    int ans = JOptionPane.showConfirmDialog(dialog, "一共需要支付订金:"
       + sum + "元\nContinue?", "We need your money",
www.751com.cn
       }
       dispose();
       JOptionPane
         .showMessageDialog(dialog, "订单添加成功!",
           "Success!",
           JOptionPane.INFORMATION_MESSAGE);
      } catch (SQLException exc) {
       exc.printStackTrace();
      }
     } else if (ans == JOptionPane.NO_OPTION) {
      dispose();
     }
    } else {
     JOptionPane.showMessageDialog(dialog,
      "订单为空,不能提交,请选择需要订阅的期刊", "Check again !",
       JOptionPane.ERROR_MESSAGE);
    }
   }
  });
  button_2.setEnabled(false);
  button_2.setText("提交订单");
  panel_1.add(button_2);

上一页  [1] [2] [3] [4] [5] [6] [7] 下一页

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有