Tao table(nhi datagirdview trong c) ketnoidb kndb; Connection conn; public String tieude={STT,Mã chức vụ,Tên chức vụ,Lương,Ghi chú}; public DefaultTableModel mode=new DefaultTableModel(tieude,0); public void resettb() { try { conn=kndb.getKetNoi(); String sql=select from Chucvu; Statement stm=conn.createStatement(); ResultSet rs=stm.executeQuery(sql); this.tBchucvu.setModel(mode); mode.setRowCount(0); int i=0; while(rs.next()) { String row={+(++i),rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4)}; mode.addRow(row); } rs.close(); } catch(Exception ex) { ex.printStackTrace(); } } Nut reset cac textbox tXtghichucv.setText(); tXtluongcv.setText(); tXtmacv.setText(); tXttencv.setText(); xay dung thu tuc tu sql va goi trong java(dung netbean) private void bTthemActionPerformed(java.awt.event.ActionEvent evt) { TODO add your handling code here: try { double luong=Double.parseDouble(tXtluongcv.getText()); conn=kndb.getKetNoi(); String sql={call spud_them_cv(?,?,?,?)}; CallableStatement cstm=conn.prepareCall(sql); cstm.setString(1, tXtmacv.getText()); cstm.setString(2, tXttencv.getText()); cstm.setDouble(3, luong); cstm.setString(4, tXtghichucv.getText()); cstm.executeUpdate(); resettb(); cstm.close(); JOptionPane.showMessageDialog(this, Thành công); } catch(Exception ex) { JOptionPane.showMessageDialog(this, ex.getMessage()+Thất bại); } } Load combobox public void loadcv() { try { conn=kndb.getKetNoi(); String sql=select Macv from Chucvu; Statement stm=conn.createStatement(); ResultSet rs=stm.executeQuery(sql); stm.executeQuery(sql); while(rs.next()) { String name=rs.getString(Macv); cBchucvu.addItem(name); } } catch(Exception e) { } Vidu if (tblCustomers.getSelectedRow() >= 0) { txtID.setText(String.valueOf(CustomersList.get(tblCustomers.getSelectedRow()).getCustomerID())); txtName.setText(CustomersList.get(tblCustomers.getSelectedRow()).getCustomerName()); txtAddress.setText(CustomersList.get(tblCustomers.getSelectedRow()).getAddress()); txtPhone.setText(String.valueOf(CustomersList.get(tblCustomers.getSelectedRow()).getPhone())); txtEmail.setText(CustomersList.get(tblCustomers.getSelectedRow()).getEmail()); btnAddNew.setEnabled(false); btnReset.setEnabled(true); btnEdit.setEnabled(true); btnGetCustomerID.setEnabled(true); hien thi table click int hang=this.tBnhanvien.getSelectedRow(); tXtmanv.setText((String) this.tBnhanvien.getValueAt(hang, 1)); cBcv.setSelectedItem((String) this.tBnhanvien.getValueAt(hang, 7)); dung truc tiep cau lenh String sql=delete Phong where Maphong=+tXtmap.getText()+; Statement stm=conn.createStatement(); stm.executeUpdate(sql); dang nhap public boolean dangnhap(String id,String pass) { try { String sql=select from Nguoidung where id=+id+ and pass=+pass+; ketnoidb kndb=new ketnoidb(); Connection conn=ketnoidb.getKetNoi(); Statement st=conn.createStatement(); ResultSet rs=st.executeQuery(sql); while(rs.next()) { kndb.gettemp(); setthanhcong(true); return true; } } catch(Exception e1) {} setthanhcong(false); return false; } if(kndb.dangnhap(tXtid.getText(), tXtpass.getText())) { if(kndb.gettemp()==1) { kndb.setthanhcong(true); frm_giaodien f=new frm_giaodien(); f.check(); this.dispose(); public String dointn(String dd,String mm,String yy) { return nsinh=dd++mm++yy; } String n=chuyendoi(txt dd=cBdd.getSelectedItem().toString(); if(JOptionPane.showConfirmDialog(this, Bạn có chắc muốn xóa nhân viên này?,Thông báo,JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION) if((frm_dangnhap.kndb.getthanhcong()==true) ) { mNchucnang.setEnabled(true); }
Tao table(nhi datagirdview c#) ketnoidb kndb; Connection conn; public String[] tieude={"STT","Mã chức vụ","Tên chức vụ","Lương","Ghi chú"}; public DefaultTableModel mode=new DefaultTableModel(tieude,0); public void resettb() { try { conn=kndb.getKetNoi(); String sql="select * from Chucvu"; Statement stm=conn.createStatement(); ResultSet rs=stm.executeQuery(sql); this.tBchucvu.setModel(mode); mode.setRowCount(0); int i=0; while(rs.next()) { String[] row={""+(+ +i),rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4)}; mode.addRow(row); } rs.close(); } catch(Exception ex) { ex.printStackTrace(); } } Nut reset cac textbox tXtghichucv.setText(""); tXtluongcv.setText(""); tXtmacv.setText(""); tXttencv.setText(""); xay dung thu tuc tu sql va goi java(dung netbean) private void bTthemActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { double luong=Double.parseDouble(tXtluongcv.getText()); conn=kndb.getKetNoi(); String sql="{call spud_them_cv(?,?,?,?)}"; CallableStatement cstm=conn.prepareCall(sql); cstm.setString(1, tXtmacv.getText()); cstm.setString(2, tXttencv.getText()); cstm.setDouble(3, luong); cstm.setString(4, tXtghichucv.getText()); cstm.executeUpdate(); resettb(); cstm.close(); JOptionPane.showMessageDialog(this, "Thành công!"); } catch(Exception ex) { JOptionPane.showMessageDialog(this, ex.getMessage()+"Thất bại!"); } } Load combobox public void loadcv() { try { conn=kndb.getKetNoi(); String sql="select Macv from Chucvu"; Statement stm=conn.createStatement(); ResultSet rs=stm.executeQuery(sql); //stm.executeQuery(sql); while(rs.next()) { String name=rs.getString("Macv"); cBchucvu.addItem(name); } } catch(Exception e) { } Vidu if (tblCustomers.getSelectedRow() >= 0) { txtID.setText(String.valueOf(CustomersList.get(tblCustom ers.getSelectedRow()).getCustomerID())); txtName.setText(CustomersList.get(tblCustomers.getSelect edRow()).getCustomerName()); txtAddress.setText(CustomersList.get(tblCustomers.getSel ectedRow()).getAddress()); txtPhone.setText(String.valueOf(CustomersList.get(tblCust omers.getSelectedRow()).getPhone())); txtEmail.setText(CustomersList.get(tblCustomers.getSelect edRow()).getEmail()); btnAddNew.setEnabled(false); btnReset.setEnabled(true); btnEdit.setEnabled(true); btnGetCustomerID.setEnabled(true); hien thi table click int hang=this.tBnhanvien.getSelectedRow(); tXtmanv.setText((String) this.tBnhanvien.getValueAt(hang, 1)); cBcv.setSelectedItem((String) this.tBnhanvien.getValueAt(hang, 7)); dung truc tiep cau lenh String sql="delete Phong where Maphong='"+tXtmap.getText()+"'"; Statement stm=conn.createStatement(); stm.executeUpdate(sql); dang nhap public boolean dangnhap(String id,String pass) { try { String sql="select * from Nguoidung where id='"+id+"' and pass='"+pass+"'"; ketnoidb kndb=new ketnoidb(); Connection conn=ketnoidb.getKetNoi(); Statement st=conn.createStatement(); ResultSet rs=st.executeQuery(sql); while(rs.next()) { kndb.gettemp(); setthanhcong(true); return true; } } catch(Exception e1) {} setthanhcong(false); return false; } if(kndb.dangnhap(tXtid.getText(), tXtpass.getText())) { //if(kndb.gettemp()==1) // { kndb.setthanhcong(true); frm_giaodien f=new frm_giaodien(); f.check(); this.dispose(); public String dointn(String dd,String mm,String yy) { return nsinh=dd+"/"+mm+"/"+yy; } String n=chuyendoi(txt dd=cBdd.getSelectedItem().toString(); if(JOptionPane.showConfirmDialog(this, "Bạn có muốn xóa nhân viên này?","Thông báo",JOptionPane.YES_NO_OPTION)==JOptionPane.YE S_OPTION) if((frm_dangnhap.kndb.getthanhcong()==true) ) { mNchucnang.setEnabled(true); } . id='"+id+"' and pass='"+pass+"'"; ketnoidb kndb=new ketnoidb(); Connection conn=ketnoidb.getKetNoi(); Statement st=conn.createStatement(); ResultSet rs=st.executeQuery(sql); . Maphong='"+tXtmap.getText()+"'"; Statement stm=conn.createStatement(); stm.executeUpdate(sql); dang nhap public boolean dangnhap(String id,String pass) { try { String sql="select * from Nguoidung. tXttencv.setText(""); xay dung thu tuc tu sql va goi trong java( dung netbean) private void bTthemActionPerformed (java. awt.event.ActionEvent evt) { // TODO add your handling code here: