1. Trang chủ
  2. » Công Nghệ Thông Tin

LẬP TRÌNH JAVA CHO KẾ TOÁN

72 254 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 72
Dung lượng 55,38 KB

Nội dung

1. Quản lý lương (pakage: Luong) a. Nguoi.java To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. package QLLuong; public class Nguoi { protected String hoten; protected int tuoi; protected String quequan; public void Nguoi(String hoten,int tuoi,String quequan) { this.hoten = hoten; this.tuoi = tuoi; this.quequan = quequan; } public Stringhienthithongtin() { String arr={this.hoten,String.valueOf(this.tuoi),this.quequan}; return arr; } public void nhapthongtin(String hoten,int tuoi,String quequan) { this.hoten = hoten; this.tuoi = tuoi; this.quequan = quequan; } } b. Nhanvien.java To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. package QLLuong; public class Nhanvien extends Nguoi { protected String manv; protected String phongban; protected float hesoluong; protected float hesochucvu=0; protected float phucap; protected float luongcb = 6000000; public String hienthithongtin() { String arr={this.hoten,String.valueOf(this.tuoi),this.quequan,this.manv,this.phongban,String.valueOf(this.hesoluong),String.valueOf(this.hesochucvu),String.valueOf(this.phucap)}; return arr; } public void nhapthongtin(String hoten,int tuoi,String quequan,String manv,String phongban,float hesoluong,float hesochucvu,float phucap) { this.hoten = hoten; this.tuoi = tuoi; this.quequan = quequan; this.manv = manv; this.phongban = phongban; this.hesoluong = hesoluong; this.hesochucvu = hesochucvu; this.phucap = phucap; } public float tinhluong() { float luong=0; if(this.hesochucvu =0) { luong=this.luongcbthis.hesoluong(1+this.hesochucvu)+this.phucap; } else { luong=this.luongcbthis.hesoluong+this.phucap; } return luong; }

1 1 Quản lý lương (pakage: Luong) a Nguoi.java /* * To change this license header, choose License Headers in Project Properties * To change this template file, choose Tools | Templates * and open the template in the editor */ package QLLuong; public class Nguoi { protected String hoten; protected int tuoi; protected String quequan; public void Nguoi(String hoten,int tuoi,String quequan) { this.hoten = hoten; this.tuoi = tuoi; this.quequan = quequan; } public String[]hienthithongtin() { String arr[]={this.hoten,String.valueOf(this.tuoi),this.quequan}; return arr; } public void nhapthongtin(String hoten,int tuoi,String quequan) { this.hoten = hoten; this.tuoi = tuoi; this.quequan = quequan; } } 2 b Nhanvien.java /* * To change this license header, choose License Headers in Project Properties * To change this template file, choose Tools | Templates * and open the template in the editor */ package QLLuong; public class Nhanvien extends Nguoi { protected String manv; protected String phongban; protected float hesoluong; protected float hesochucvu=0; protected float phucap; protected float luongcb = 6000000; public String[] hienthithongtin() { String arr[]={this.hoten,String.valueOf(this.tuoi),this.quequan,this.man v,this.phongban,String.valueOf(this.hesoluong),String.valueOf(t his.hesochucvu),String.valueOf(this.phucap)}; return arr; } public void nhapthongtin(String hoten,int tuoi,String quequan,String manv,String phongban,float hesoluong,float hesochucvu,float phucap) { this.hoten = hoten; this.tuoi = tuoi; this.quequan = quequan; this.manv = manv; this.phongban = phongban; 3 this.hesoluong = hesoluong; this.hesochucvu = hesochucvu; this.phucap = phucap; c } public float tinhluong() { float luong=0; if(this.hesochucvu !=0) { luong=this.luongcb*this.hesoluong*(1+this.hesochucvu) +this.phucap; } else { luong=this.luongcb*this.hesoluong+this.phucap; } return luong; } } GUI.java /* * To change this license header, choose License Headers in Project Properties * To change this template file, choose Tools | Templates * and open the template in the editor */ package QLLuong; import java.util.ArrayList; import javax.swing.JComboBox; import javax.swing.JOptionPane; import javax.swing.JTextField; import javax.swing.table.DefaultTableModel; 4 public class GUI extends javax.swing.JFrame { ArrayList DSNhanvien =new ArrayList(); DefaultTableModel model1=new DefaultTableModel(); public boolean ktra(String manv){ if(DSNhanvien.size()>0) { for(Nhanvien nv : DSNhanvien) { if(nv.manv.equalsIgnoreCase(manv)) return true; } } return false; } public void lamsach(){ while (model1.getRowCount() > 0) { model1.removeRow(0); } } public void hienthithongtin(){ lamsach(); if(DSNhanvien.size()>0) { String tencot[]={"Mã NV","Họ tên","Tuổi","Quê quán","Phòng ban","Lương CB","Hệ Số Lương","Hệ Số Chức Vụ","Phụ Cấp","Tổng Lương"}; model1.setColumnIdentifiers(tencot); 5 for(Nhanvien nv : DSNhanvien) { String row[]={nv.manv,nv.hoten,String.valueOf(nv.tuoi),nv.quequan,n v.phongban,String.valueOf(nv.luongcb),String.valueOf(nv.hesol uong),String.valueOf(nv.hesochucvu),String.valueOf(nv.phucap ),String.valueOf(nv.tinhluong())}; model1.addRow(row); } tableNhanvien.setModel(model1); } } /** * Creates new form GUI */ public GUI() { initComponents(); } /** * This method is called from within the constructor to initialize the form * WARNING: Do NOT modify this code The content of this method is always * regenerated by the Form Editor */ @SuppressWarnings("unchecked") // private void initComponents() { 6 jPanel1 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); tableNhanvien = new javax.swing.JTable(); jMenuBar1 = new javax.swing.JMenuBar(); menuBar = new javax.swing.JMenu(); menuAdd = new javax.swing.JMenuItem(); menuUpdate = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT _ON_CLOSE); setTitle("Hệ Thống Quản Lý Lương Nhân Viên"); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorde r("Danh sách Nhân viên")); jScrollPane1.setViewportView(tableNhanvien); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.A lignment.LEADING) addGroup(jPanel1Layout.createSequentialGroup() addContainerGap() addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 632, Short.MAX_VALUE) addContainerGap()) ); jPanel1Layout.setVerticalGroup( 7 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.A lignment.LEADING) addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 369, Short.MAX_VALUE) ); menuBar.setText("Menu"); menuAdd.setText("Thêm Nhân viên"); menuAdd.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { menuAddActionPerformed(evt); } }); menuBar.add(menuAdd); menuUpdate.setText("Cập nhật thông tin"); menuUpdate.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { menuUpdateActionPerformed(evt); } }); menuBar.add(menuUpdate); jMenuBar1.add(menuBar); setJMenuBar(jMenuBar1); 8 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING) addGroup(layout.createSequentialGroup() addContainerGap() addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING) addGroup(layout.createSequentialGroup() addGap(30, 30, 30) addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) addContainerGap()) ); pack(); }// private void menuAddActionPerformed(java.awt.event.ActionEvent evt) { 9 // TODO add your handling code here: JTextField txtmanv = new JTextField(); JTextField txthoten = new JTextField(); JTextField txttuoi = new JTextField(); JTextField txtquequan = new JTextField(); JTextField txtphongban = new JTextField(); JTextField txthsluong = new JTextField(); JTextField txthschucvu = new JTextField(); JTextField txtphucap = new JTextField(); Object[] message = { "Mã NV",txtmanv, "Họ tên",txthoten, "Tuổi",txttuoi, "Quê quán",txtquequan, "Phòng ban",txtphongban, "Hệ số lương",txthsluong, "Hệ số chức vụ",txthschucvu, "Phụ cấp",txtphucap }; int option = JOptionPane.showConfirmDialog(rootPane, message, "Thêm Nhân Viên", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION ) { String manv = txtmanv.getText(); if(ktra(manv)==false ) { Nhanvien nv =new Nhanvien(); 10 10 nv.nhapthongtin(txthoten.getText(),Integer.valueOf(txttuoi.getT ext()), txtquequan.getText(), manv, txtphongban.getText(), Float.valueOf(txthsluong.getText()),Float.valueOf(txthschucvu getText()) ,Float.valueOf(txtphucap.getText())); DSNhanvien.add(nv); } else JOptionPane.showMessageDialog(rootPane, "Trung Tên Nhân Viên"); hienthithongtin(); } } private void menuUpdateActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: JComboBox combo =new JComboBox(); for(Nhanvien nv : DSNhanvien) { combo.addItem(nv.manv); } JTextField txthoten = new JTextField(); JTextField txttuoi = new JTextField(); JTextField txtquequan = new JTextField(); JTextField txtphongban = new JTextField(); JTextField txthsluong = new JTextField(); JTextField txthschucvu = new JTextField(); JTextField txtphucap = new JTextField(); 10 58 58 MenuEdit.setText("Sửa"); MenuEdit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { MenuEditActionPerformed(evt); } }); jMenu1.add(MenuEdit); MenuRemove.setText("Xóa"); MenuRemove.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { MenuRemoveActionPerformed(evt); } }); jMenu1.add(MenuRemove); jMenuBar1.add(jMenu1); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING) addGroup(layout.createSequentialGroup() addContainerGap() 58 59 59 addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING) addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); }// private void MenuAddActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: JTextField field1 = new JTextField(); JTextField field2 = new JTextField(); JTextField field3 = new JTextField(); JTextField field4 = new JTextField(); JTextField field5 = new JTextField(); JComboBox combo= new JComboBox(); combo.addItem("Nhẫn"); combo.addItem("Dây chuyền"); combo.addItem("Khác"); Object[] message = { "Số hiệu:", field1, 59 60 60 "Mô tả:", field2, "Chất liêu", field3, "Giá bán buôn", field4, "Kích cỡ || Hình dạng:", field5 , "Type: ",combo, }; int option = JOptionPane.showConfirmDialog(rootPane, message, "Thêm mặt hàng", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION && ! field1.getText().equalsIgnoreCase("")&& ! field2.getText().equalsIgnoreCase("")) { String sohieu = field1.getText(); String mota = field2.getText(); String chatlieu = field3.getText(); float giabanbuon = Float.valueOf(field4.getText()); String value = field5.getText(); //String value = field3.getText(); //String decrip = field4.getText(); String type = combo.getSelectedItem().toString(); if(checkMatHang(sohieu)==false ) { if(type.equalsIgnoreCase("Nhẫn")) { Nhan n = new Nhan(); n.setsohieu(sohieu); n.setmota(mota); 60 61 61 n.setchatlieu(chatlieu); //int count= Integer.valueOf(value); //pc.setPassenger(count); n.setkichco(value); n.setgiabanbuon(giabanbuon); NhanList.add(n); } if(type.equalsIgnoreCase("Dây Chuyền")) { DayChuyen d = new DayChuyen(); d.setsohieu(sohieu); d.setmota(mota); d.setchatlieu(chatlieu); d.sethinhdang(value); d.setgiabanbuon(giabanbuon); //gc.setgianiemyet(weight); //float count= Float.valueOf(value); //gc.setWeight_goods(count); //gc.setGoods_decrip(decrip); DayChuyenList.add(d); } if(type.equalsIgnoreCase("Khác")) { MatHang k =new MatHang(); k.setsohieu(sohieu); k.setmota(mota); k.setchatlieu(chatlieu); 61 62 62 k.setgiabanbuon(giabanbuon); //rc.setgianiemyet(weight); MatHangList.add(k); } } else JOptionPane.showMessageDialog(rootPane, "Số Hiệu tồn tại!"); showInfo(); } } private void MenuSaleActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: JTextField field1 = new JTextField(); JComboBox combo= new JComboBox(); if(NhanList.size()>0) for(MatHang item : NhanList) { combo.addItem(item.getsohieu()); } if(DayChuyenList.size()>0) for(DayChuyen item : DayChuyenList) { combo.addItem(item.getsohieu()); } if(MatHangList.size()>0) for(MatHang item : MatHangList) 62 63 63 { combo.addItem(item.getsohieu()); } Object[] message = { "Chon Mat Hàng: ",combo, "Sale:", field1, }; int option = JOptionPane.showConfirmDialog(rootPane, message, "Sale Off", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION && ! field1.getText().equalsIgnoreCase("")) { int num = Integer.valueOf(field1.getText()); String name = combo.getSelectedItem().toString(); int index=0; for (Nhan item : NhanList) { index++; if(name.equalsIgnoreCase(item.getsohieu())) { item.setSale(num); NhanList.set(index-1, item); } break; } 63 64 64 index=0; for (DayChuyen item : DayChuyenList) { index++; if(name.equalsIgnoreCase(item.getsohieu())) { item.setSale(num); DayChuyenList.set(index-1, item); } break; } index=0; for (MatHang item : MatHangList) { index++; if(name.equalsIgnoreCase(item.getsohieu())) { item.setSale(num); MatHangList.set(index-1, item); } break; } 64 65 65 showInfo(); } } private void MenuEditActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: JTextField field1 = new JTextField(); JTextField field2 = new JTextField(); JTextField field3 = new JTextField(); JTextField field4 = new JTextField(); JComboBox comboSohieu= new JComboBox(); if(NhanList.size()>0) for(MatHang item : NhanList) { comboSohieu.addItem(item.getsohieu()); } if(DayChuyenList.size()>0) for(DayChuyen item : DayChuyenList) { comboSohieu.addItem(item.getsohieu()); } if(MatHangList.size()>0) for(MatHang item : MatHangList) { comboSohieu.addItem(item.getsohieu()); } Object[] message = { "Số hiệu:", comboSohieu, "Mô tả:", field1, 65 66 66 "Chất liêu", field2, "Giá bán buôn", field3, "Kích cỡ || Hình dạng:", field4 , }; int option = JOptionPane.showConfirmDialog(rootPane, message, "Edit", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION ) { String sohieu = comboSohieu.getSelectedItem().toString(); String mota = field1.getText(); String chatlieu = field2.getText(); float giabanbuon = Float.valueOf(field3.getText()); String value = field4.getText(); int index=0; for (Nhan item : NhanList) { index++; if(sohieu.equalsIgnoreCase(item.getsohieu())) { item.setsohieu(sohieu); item.setmota(mota); item.setchatlieu(chatlieu); //int count= Integer.valueOf(value); //pc.setPassenger(count); item.setkichco(value); item.setgiabanbuon(giabanbuon); NhanList.set(index-1, item); 66 67 67 } break; } index=0; for (DayChuyen item : DayChuyenList) { index++; if(sohieu.equalsIgnoreCase(item.getsohieu())) { item.setsohieu(sohieu); item.setmota(mota); item.setchatlieu(chatlieu); item.sethinhdang(value); item.setgiabanbuon(giabanbuon); DayChuyenList.set(index-1, item); } break; } index=0; for (MatHang item : MatHangList) { index++; if(sohieu.equalsIgnoreCase(item.getsohieu())) { item.setsohieu(sohieu); item.setmota(mota); 67 68 68 item.setchatlieu(chatlieu); item.setgiabanbuon(giabanbuon); MatHangList.set(index-1, item); } break; } showInfo(); } } private void MenuRemoveActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: JComboBox combo= new JComboBox(); if(NhanList.size()>0) for(MatHang item : NhanList) { combo.addItem(item.getsohieu()); } if(DayChuyenList.size()>0) for(DayChuyen item : DayChuyenList) { combo.addItem(item.getsohieu()); } if(MatHangList.size()>0) for(MatHang item : MatHangList) { 68 69 69 combo.addItem(item.getsohieu()); } Object[] message = { "Chọn Măt Hàng: ",combo, }; int option = JOptionPane.showConfirmDialog(rootPane, message, "Remove", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION) { String name = combo.getSelectedItem().toString(); int index=0; for (Nhan item : NhanList) { index++; if(name.equalsIgnoreCase(item.getsohieu())) { NhanList.remove(index-1); break; } } index=0; for (DayChuyen item : DayChuyenList) { index++; if(name.equalsIgnoreCase(item.getsohieu())) 69 70 70 { DayChuyenList.remove(index-1); break; } } index=0; for (MatHang item : MatHangList) { index++; if(name.equalsIgnoreCase(item.getsohieu())) { MatHangList.remove(index-1); break; } } showInfo(); } } 70 71 71 /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ // /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/ plaf.html */ 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(GUI.class.getName()).log(ja va.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(GUI.class.getName()).log(ja va.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(GUI.class.getName()).log(ja va.util.logging.Level.SEVERE, null, ex); 71 72 72 } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(GUI.class.getName()).log(ja va.util.logging.Level.SEVERE, null, ex); } // /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new GUI().setVisible(true); } }); } // Variables declaration - not modify private javax.swing.JMenuItem MenuAdd; private javax.swing.JMenuItem MenuEdit; private javax.swing.JMenuItem MenuRemove; private javax.swing.JMenuItem MenuSale; private javax.swing.JMenu jMenu1; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JTable tableList1; private javax.swing.JTable tableList2; private javax.swing.JTable tableList3; // End of variables declaration } 72

Ngày đăng: 07/07/2016, 11:24

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w