⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updaterecord.java

📁 培训时做的学生管理系统.基于J2SE平台开发
💻 JAVA
字号:
package cn.com.studentsystem.kaoqin;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextField;

import cn.com.studentsystem.exception.NumberOutException;
import cn.com.studentsystem.log.Log;
import cn.com.util.DBConnection;
import cn.com.util.studentsystemcommon.JDatePicker;

public class UpdateRecord {
	JFrame jf;
	JDatePicker date_text;
	JTextField be_text;
	JTextField now_text;
	JTextField late_text;
	JTextField expalin_text;
	JButton addrecord_button;
	JButton cancelrecord_button;
	JOptionPane jop = new JOptionPane() ;
	public UpdateRecord(){
		
		init();
	}
	
	public void init(){
		
		jf = new JFrame("考勤记录");
		jf.setSize(420,480);
		jf.setLocationRelativeTo(null);
	    BorderLayout border = new BorderLayout();
	    FlowLayout flow = new FlowLayout(FlowLayout.CENTER,50,50);
		GridLayout grid = new GridLayout(5,1,10,10);
		ImageIcon i = new ImageIcon("image//title.png");
		jf.setIconImage(i.getImage());
		
		JSplitPane slipt_pane = new JSplitPane();
		JPanel up_pane = new JPanel();
		JPanel left_pane = new JPanel();
		JPanel right_pane = new JPanel();
		JPanel all_pane = new JPanel();
		
		up_pane.setBorder(BorderFactory.createTitledBorder("时间日期"));
		left_pane.setBorder(BorderFactory.createTitledBorder("人数统计"));
		right_pane.setBorder(BorderFactory.createTitledBorder("迟到缘由"));
		
		left_pane.setLayout(flow);
		right_pane.setLayout(flow);
		all_pane.setLayout(border);
		
		JLabel date_label = new JLabel("时间日期");
		 date_text  = new JDatePicker();
		 date_text.setEditable(false);
		
		JLabel be_label = new JLabel("应到人数");
		 be_text = new JTextField(10);
		
		JLabel now_label = new JLabel("实到人数");
	    now_text = new JTextField(10);
		

		JLabel late_person = new JLabel("迟到者");
	    late_text = new JTextField(10);
		
		JLabel  explain = new JLabel("迟到缘由");
		 expalin_text = new JTextField(10);
		
		 addrecord_button= new JButton("修改");
		 cancelrecord_button = new JButton("取消");
		
		up_pane.add(date_label);
		up_pane.add(date_text);
		
		left_pane.add(be_label);
		left_pane.add(be_text);
		left_pane.add(late_person);
		left_pane.add(late_text);
		left_pane.add(addrecord_button);
		
	    right_pane.add(now_label);
		right_pane.add(now_text);
		right_pane.add(explain);
		right_pane.add(expalin_text);
		right_pane.add(cancelrecord_button);
		 
		slipt_pane.setLeftComponent(left_pane);
		slipt_pane.setRightComponent(right_pane);
		slipt_pane.setAutoscrolls(true);
		slipt_pane.setDividerSize(2);
		slipt_pane.setDividerLocation(200);
		all_pane.add(up_pane,"North");
		all_pane.add(slipt_pane,"Center");
		
		jf.add(all_pane);
	
		class UpdateRecordAction implements ActionListener{

			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if(arg0.getActionCommand().equals("修改")){
					File file = new File("logdiary.txt");
					PrintWriter pw = null;
					try {
						 pw = new PrintWriter(new FileWriter(file,true),true);
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					Log.log("UpdateRecord的修改按钮", pw, "对考勤记录数据进行修改");
					
					int row = KaoQin.jtable.getSelectedRow();
					 if(Integer.parseInt(be_text.getText().toString())<Integer.parseInt(now_text.getText().toString())){
                    	 try {
							throw new NumberOutException(Integer.parseInt(be_text.getText().toString()),Integer.parseInt(now_text.getText().toString()),
									 "应到人数小于实到人数了");
						} catch(NumberFormatException e){
							   jop.showMessageDialog(null, "你输出的不是数字,请输入数字");
						   }	 catch (NumberOutException e) {
							// TODO Auto-generated catch block
							jop.showMessageDialog(null, "输入错误,应到人数小于实到人数了");
						}
				    }else{
				    	try {
							   KaoQin.table_model.setValueAt(be_text.getText().toString(), row, 1);
							   KaoQin.table_model.setValueAt(now_text.getText().toString(), row, 2);
							   KaoQin.table_model.setValueAt(late_text.getText().toString(), row, 3);
							   KaoQin.table_model.setValueAt(expalin_text.getText().toString(), row, 4);
							  
							   Connection con = DBConnection.getConnectionOracle();
//							  
							    PreparedStatement ps = con.prepareStatement("update attendance set all_person =?,now_person = ?,unattender = ?,reason = ? where datetime = ?");
							    ps.setInt(1, Integer.parseInt(be_text.getText().toString()));
							    ps.setInt(2, Integer.parseInt(now_text.getText().toString()));
							    ps.setString(3,late_text.getText().toString() );
							    ps.setString(4,expalin_text.getText().toString() );
							    ps.setString(5,date_text.getSelectedItem().toString().substring(0,10) );
						        ps.executeUpdate();
							    jop.showMessageDialog(null, "更新成功","消息提示",jop.INFORMATION_MESSAGE);
								jf.dispose();
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
						}
				    	
				     }
				    
					
					
					
				}else if(arg0.getActionCommand().equals("取消")){
					File file = new File("logdiary.txt");
					PrintWriter pw = null;
					try {
						 pw = new PrintWriter(new FileWriter(file,true),true);
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					Log.log("UpdateRecord的取消按钮", pw, "取消对考勤记录的修改");
					jf.dispose();
				}
				
				
				
			}
			
		}
		
		UpdateRecordAction updaterecord_action = new UpdateRecordAction();
		addrecord_button.addActionListener(updaterecord_action);
		 cancelrecord_button.addActionListener(updaterecord_action);
		jf.setVisible(true);
		
		}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -