package kaoqing;
import javax.swing.*;
import common.DataOperation;
import java.awt.*;
import java.awt.event.*;
import java.io.UnsupportedEncodingException;
import java.sql.*;
public class AddKaoqing extends JFrame implements ActionListener {
private JLabel label;
private JButton saveButton;
private JButton exitButton;
private JTextField textField;
private JComboBox comboBox1;
private JComboBox comboBox2;
private JComboBox comboBox3;
private JComboBox comboBox4;
private JComboBox comboBox5;
private JComboBox comboBox6;
String[] month = { " 1", " 2",
" 3", " 4",
" 5", " 6",
" 7", " 8",
" 9", " 10",
" 11", " 12" };
String[] str = { " 0", " 1",
" 2", " 3",
" 4", " 5",
" 6", " 7",
" 8", " 9",
" 10", " 11",
" 12" };
Font font = new Font("楷体_GB2312", Font.BOLD, 15);
String[] Columname = { "编号", "月份", "应出勤", "迟到", "早退", "请假", "旷工" };
public AddKaoqing() {
super("增加员工考勤信息界面");
Container container = this.getContentPane();// 获得容器
container.setLayout(new GridBagLayout());
GridBagConstraints cp = new GridBagConstraints();
cp.insets = new Insets(10, 3, 10, 3);// 设置布局管理器中的组件距窗体上,左,下,右的距离分别为10,3,10,3
cp.gridheight = 1; // 设置一排组件占一行
// ********* 第一行 ***********
label = new JLabel("编号:");
label.setFont(font);
cp.gridx = 0; // 该组件在第一行第一列
cp.gridy = 0;
cp.gridwidth = 1; // 描述组件在布局中的所占的网格的个数为1
this.getContentPane().add(label, cp); // 将label添加到布局管理器中
textField = new JTextField(10);
textField.setText("");
cp.gridx = GridBagConstraints.RELATIVE; // 紧贴着左边的组件放置该组件
cp.gridwidth = 4; // 描述组件在布局中的所占的网格的个数为4
this.getContentPane().add(textField, cp); // 将textfield添加到布局管理器中
label = new JLabel("月份:");
label.setFont(font);
cp.gridx = 5;
cp.gridwidth = 1;// 描述组件在布局中的所占的网格的个数为1
this.getContentPane().add(label, cp);// 将label添加到布局管理器中
comboBox1 = new JComboBox(month);
cp.gridx = GridBagConstraints.RELATIVE;
cp.gridwidth = 4;// 描述组件在布局中的所占的网格的个数为4
this.getContentPane().add(comboBox1, cp);
this.getContentPane().add(comboBox1, cp);// 将textfield添加到布局管理器中
// ************ 第二行 ********************
label = new JLabel("应出勤:");
label.setFont(font);
cp.gridx = 0; // 设置该组件为第二行第一列
cp.gridy = GridBagConstraints.RELATIVE;// 与上一行的第一个对齐
cp.gridwidth = 1;// 描述组件在布局中的所占的网格的个数为1
this.getContentPane().add(label, cp);// 将label添加到布局管理器中
comboBox2 = new JComboBox(str);
cp.gridx = 1;
cp.gridwidth = 4;// 描述组件在布局中的所占的网格的个数为4
this.getContentPane().add(comboBox2, cp);
this.getContentPane().add(comboBox2, cp);// 将textfield添加到布局管理器中
label = new JLabel("迟到:");
label.setFont(font);
cp.gridx = 5;
cp.gridwidth = 1;// 描述组件在布局中的所占的网格的个数为1
this.getContentPane().add(label, cp);// 将label添加到布局管理器中
comboBox3 = new JComboBox(str);
cp.gridx = 6;
cp.gridwidth = 4;// 描述组件在布局中的所占的网格的个数为4
this.getContentPane().add(comboBox3, cp);
// ************ 第三行 ********************
label = new JLabel("早退");
label.setFont(font);
cp.gridx = 0;// 设置该组件为第三行第一列
cp.gridy = 2;
cp.gridwidth = 1;// 描述组件在布局中的所占的网格的个数为1
this.getContentPane().add(label, cp);// 将label添加到布局管理器中
comboBox4 = new JComboBox(str);
cp.gridx = 1;
cp.gridwidth = 4;// 描述组件在布局中的所占的网格的个数为4
this.getContentPane().add(comboBox4, cp);
label = new JLabel("请假:");
label.setFont(font);
cp.gridx = 5;
cp.gridwidth = 1;// 描述组件在布局中的所占的网格的个数为1
this.getContentPane().add(label, cp);// 将label添加到布局管理器中
comboBox5 = new JComboBox(str);
cp.gridx = 6;
cp.gridwidth = 4;// 描述组件在布局中的所占的网格的个数为4
this.getContentPane().add(comboBox5, cp);
// ************ 第四行 ********************
label = new JLabel("旷工:");
label.setFont(font);
cp.gridx = 0;// 设置该组件为第四行第一列
cp.gridy = 3;
cp.gridwidth = 1; // 描述组件在布局中的所占的网格的个数
this.getContentPane().add(label, cp); // 将label添加到布局管理器中
comboBox6 = new JComboBox(str);
cp.gridx = 1;
cp.gridwidth = 4;// 描述组件在布局中的所占的网格的个数为4
this.getContentPane().add(comboBox6, cp);
saveButton = new JButton("保存");
saveButton.setFont(font);
saveButton.addActionListener(this);
saveButton.setActionCommand("保存");
cp.gridx = 3;
cp.gridy = 4;
cp.gridwidth = 2;
this.getContentPane().add(saveButton, cp);// 将button添加到布局管理器中
exitButton = new JButton("退出");
exitButton.setFont(font);
exitButton.addActionListener(this);
exitButton.setActionCommand("退出");
cp.gridx = GridBagConstraints.RELATIVE;
this.getContentPane().add(exitButton, cp);
setSize(600, 300); // 设置窗体长为600,宽为300
setLocation(280, 180); // 设置窗体在坐标(280,180)处显示
setVisible(true);
}
public void inial() {
if (textField.getText().length() == 0) {
JOptionPane.showMessageDialog(this, "编号不能为空~!");
} else {
String str = textField.getText() + "','"
+ comboBox1.getSelectedItem() + "','"
+ comboBox2.getSelectedItem() + "','"
+ comboBox3.getSelectedItem() + "','"
+ comboBox4.getSelectedItem() + "','"
+ comboBox5.getSelectedItem() + "','"
+ comboBox6.getSelectedItem();
int n = JOptionPane.showConfirmDialog(this, "您输入的信息为编号:" + str,
"确定吗?", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
this.dispose();
}
DataOperation dbopt = new DataOperation();
String sql = "INSERT INTO CQQKB VALUES ('" + textField.getText()
+ "','" + comboBox1.getSelectedItem() + "','"
+ comboBox2.getSelectedItem() + "','"
+ comboBox3.getSelectedItem() + "','"
+ comboBox4.getSelectedItem() + "','"
+ comboBox5.getSelectedItem() + "','"
+ comboBox6.getSelectedItem() + "');";
dbopt.setQuerystatement(sql);
try {
dbopt.updateRecord();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
dbopt.connStop();
}
}
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals("保存")) {
inial();
} else if ((command.equals("退出"))) {
int n = JOptionPane.showConfirmDialog(this, "您确定要退出吗?", "",
JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
this.dispose();
}
}
}
}