2012-03-18 56 views
1

我正在为我的妻子创建一个小小的患者管理软件。该程序功能齐全,但一旦我更新患者数据或排除任何注册表,我就会遇到问题。 我有一个搜索表单,可以让所有患者(使用日期,名称...)然后选择所需患者(来自上次访问),并将所有患者的数据显示为另一种形式。我可以更新数据,排除这次访问,但是,一旦我保存它,这个表单(secundary)就会关闭(dispose)。但主要形式(搜索表单)拥有以前的值。 如何在关闭secundary形式后刷新主窗体? THX很多关闭secundary表格后更新主表

编辑:忘了说了它的Java - SRY)

Edited2: 这是使用调用secundary形式的法林。我使用Netbeans创建该项目。

private void btn_selecionaActionPerformed(java.awt.event.ActionEvent evt) {            
     try{ 
     int sel = tabela.getSelectedRow(); 

     if (sel != -1){ 
      String sql = "select * from agendados " 
        + "where numag = " + modelo.getValueAt(sel, 5); 
      con_mnt.executaSQL(sql); 
      func = new Funcoes(); 
      func.carregaDados(dados, con_mnt.rs); 
      new CarregarAgendamento(func.getDados()).setVisible(true); 

     } else{ 
      JOptionPane.showMessageDialog(null, "Selecione algum paciente antes.", " Atenção!!!", JOptionPane.ERROR_MESSAGE); 
     } 

     } 
     catch(SQLException | NumberFormatException e){ 
      JOptionPane.showMessageDialog(null, "Nao existe dados ainda", " Atenção!!!", JOptionPane.ERROR_MESSAGE); 
     } 
    } 

编辑3: 保存,删除和salvarAgendamento方法:

private void btn_salvaActionPerformed(java.awt.event.ActionEvent evt) {           
    salvarAgendamento(); 
    dispose(); 
}           

private void btn_deleteActionPerformed(java.awt.event.ActionEvent evt) {           
    if(javax.swing.JOptionPane.showConfirmDialog(null,"Deseja realmente Excluir este Agendamento?","ATENÇÃO ",javax.swing.JOptionPane.YES_NO_OPTION)==0) 
    { 
     con_ag = new Firebird(func.fullPath("/db/manutencao.fdb")); 
     con_ag.removeFDB("agendados", "numag", jt_cod.getText()); 
     Agendados.refresh = 1; 
     this.dispose(); 
    } 

} 

public void salvarAgendamento(){ 
     ArrayList<Object> colunas = new ArrayList<>(); 
     ArrayList<Object> valores = new ArrayList<>(); 
     calendario = new Calendario(); 

     if (jcb_motivo.getSelectedIndex() == -1) 
     { 
      JOptionPane.showMessageDialog(null, "Faltou o Motivo do Agendamento!"); 
      jcb_motivo.requestFocus(); 
     } 
     else if (jt_dataAg.getText().equals("")) 
     { 
      JOptionPane.showMessageDialog(null, "Faltou a Data do Agendamento!"); 
      jt_dataAg.requestFocus(); 
     } 
     else if (dados.getStatusAg() == 0) 
     { 
      JOptionPane.showMessageDialog(null, "Faltou selecionar o Status do Agendamento!"); 
      jcb_status.requestFocus(); 
     } 
     else 
     { 
      calendario.dataFormatada("dd/mm/yyyy", "yyyy-mm-dd", jt_dataAg.getText()); 
      dados.setDataAg(calendario.getDataFormatada() + " 00:00:00"); 

      colunas.add("statusag"); 
      colunas.add("obs"); 

      valores.add(jt_tel1.getText()); 
      valores.add(jt_tel2.getText()); 
      valores.add(jt_cel.getText()); 
      valores.add(dados.getConvenioNum()); //convnum 
      valores.add(dados.getDentistaNum()); //dentnum 
      valores.add(jcb_motivo.getSelectedItem()); 
      valores.add(dados.getDataAg()); //dataag 
      valores.add(dados.getStatusAg()); //statusag 
      valores.add(area_obs.getText()); 
      valores.add(jt_cod.getText()); 

      grava(valores); 
      JOptionPane.showMessageDialog(null, "Agendamento alterado com sucesso!"); 
      dispose(); 
     } 
    } 
+0

的编程语言是那些形式的书面吗? – 2012-03-18 13:03:39

+0

其Java,,, sry ^^ – Galla 2012-03-18 13:11:42

回答

1

我会做这样的:

假设,你已经 “关闭” 按钮第二个形式。

1)我想第一种形式发送到的第二种形式的第二

SecondForm second = new SecondForm(this); 

或者

SecondForm second = new SecondForm(firstForm); 

初始化函数将保持firstForm实例和关闭的时候,我会去像即:

public void actionPerformed(ActionEvent e){ 
firstForm.update(); 
this.close(); 
} 

对不起,只发布了一小块代码,但想法是:

  • 必须通过按钮或通过“X”按钮,右上方存储第一种形式的实例在第二种形式
  • 当关闭第二种形式,通过第一的形式公开

编辑更新第一种形式 我不会说西班牙语(对不起,如果多数民众赞成在另一种语言:)),所以我会做一些假设:tabela是组件,它显示数据。我不是那样进入JTable,但仍然有update()函数。现在该怎么做。我行

new CarregarAgendamento(func.getDados()).setVisible(true); 

改变

new CarregarAgendamento(func.getDados(), this).setVisible(true); 

现在,this reffers到第一窗体类。因为我不知道它是如何调用的,我会进一步称它为FirstForm。好?

因此,CarregarAgendamento是(另一种假设)的第二种形式。我会更新的init这样

public class CarregarAgendamento 
//all previous private field 
private FirstForm first; 

/* Here I assume that the func.getDados() returns Funcoes. If not, change it */ 
public CarregarAgendamento(Funcoes func, FirstForm f){ 
//leave everything as it was, just add the line below 
this.first = f; 
} 

现在的功能:

private void btn_salvaActionPerformed(java.awt.event.ActionEvent evt) {           
    salvarAgendamento(); 
    first.getTabela().update(); //method to update the table. 
    dispose(); 
}           

private void btn_deleteActionPerformed(java.awt.event.ActionEvent evt) {            
    if(javax.swing.JOptionPane.showConfirmDialog(null,"Deseja realmente Excluir este Agendamento?","ATENÇÃO ",javax.swing.JOptionPane.YES_NO_OPTION)==0) 
    { 
     con_ag = new Firebird(func.fullPath("/db/manutencao.fdb")); 
     con_ag.removeFDB("agendados", "numag", jt_cod.getText()); 
     Agendados.refresh = 1; 
     first.getTabela().update(); //method to update the table. 
     this.dispose(); 
    } 

} 

public void salvarAgendamento(){ 
     ArrayList<Object> colunas = new ArrayList<>(); 
     ArrayList<Object> valores = new ArrayList<>(); 
     calendario = new Calendario(); 

     if (jcb_motivo.getSelectedIndex() == -1) 
     { 
      JOptionPane.showMessageDialog(null, "Faltou o Motivo do Agendamento!"); 
      jcb_motivo.requestFocus(); 
     } 
     else if (jt_dataAg.getText().equals("")) 
     { 
      JOptionPane.showMessageDialog(null, "Faltou a Data do Agendamento!"); 
      jt_dataAg.requestFocus(); 
     } 
     else if (dados.getStatusAg() == 0) 
     { 
      JOptionPane.showMessageDialog(null, "Faltou selecionar o Status do Agendamento!"); 
      jcb_status.requestFocus(); 
     } 
     else 
     { 
      calendario.dataFormatada("dd/mm/yyyy", "yyyy-mm-dd", jt_dataAg.getText()); 
      dados.setDataAg(calendario.getDataFormatada() + " 00:00:00"); 

      colunas.add("statusag"); 
      colunas.add("obs"); 

      valores.add(jt_tel1.getText()); 
      valores.add(jt_tel2.getText()); 
      valores.add(jt_cel.getText()); 
      valores.add(dados.getConvenioNum()); //convnum 
      valores.add(dados.getDentistaNum()); //dentnum 
      valores.add(jcb_motivo.getSelectedItem()); 
      valores.add(dados.getDataAg()); //dataag 
      valores.add(dados.getStatusAg()); //statusag 
      valores.add(area_obs.getText()); 
      valores.add(jt_cod.getText()); 

      grava(valores); 
      first.getTabela().update(); //method to update the table. 
      JOptionPane.showMessageDialog(null, "Agendamento alterado com sucesso!"); 
      dispose(); 
     } 
    } 

如前所述之前 - 我从来没有与JTable的工作,所以我完全不知道如何更新它。只是希望,它会起作用。显然,你有这个功能的地方添加到您的FirstForm:

public JTable getTabela(){ 
    return tabela; 
    } 

如果你没有它已经

+0

我添加了加载第二个表单的方法。你可以检查它吗? thx – Galla 2012-03-18 14:15:51

+0

以及你如何关闭它? – 2012-03-18 15:40:36

+0

我只需要刷新主表单,当我点击保存按钮或删除按钮。然后它将应用更改或删除注册并关闭此表单。我添加保存和删除操作方法。 – Galla 2012-03-18 17:15:36