Package clips.contract.info.polis

Source Code of clips.contract.info.polis.PanelPolisView

/*
* DialogPolisView.java
*
* Created on 27 Май 2008 г., 12:50
*/

package clips.contract.info.polis;

import beans.contract.ContractPolisFilter;
import beans.contract.entity.Contract;
import cli_fmw.address.DialogAddressM;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.delegate.client.Address;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.main.ClipsException;
import cli_fmw.main.MainWindow;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageException;
import cli_fmw.main.PageGeneric;
import clips.delegate.client.ClientLocal;
import clips.delegate.contract.ContractLocal;
import clips.delegate.contract.PolisData;
import clips.service.PanelSerRenList;
import clips.userseach.PanelUserSearch;
import cli_fmw.utils.EmptyDialog;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.sorted_table.renderer.LabelRenderer;
import cli_fmw.utils.sorted_table.renderer.simple.DateRenderer;
import cli_fmw.utils.table_config_states.StateSaver;
import cli_fmw.utils.table_config_states.TableState;
import clips.delegate.config.ConfigLocal;
import clips.delegate.directory.simple.insurer.DirectoryInsurer;
import clips.delegate.directory.simple.insurer.DirectoryInsurerItem;
import clips.delegate.directory.simple.regionIdCode.DirectoryRegionIdCode;
import clips.login.UserInfo;
import org.infotechservice.ICalendar.components.ICDateChooserCellEditor;
import framework.utils.Converter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.border.TitledBorder;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;

/**
*
* @author  vip
*/
public class PanelPolisView extends PageGeneric {
   
    private List<PolisData> polisList;
    private ContractLocal contract;
    private JComboBox insurers;
    private JComboBox insurerRegions;
    private ContractPolisFilter filter;
    private DirectoryInsurer dirIns;

    public PanelPolisView(PageContainer container, ContractLocal contract) throws ClipsException {
        super(container);
        initComponents();

        this.contract = contract;

        filter = new ContractPolisFilter();
        polisList = contract.getPolisList(filter);

        dirIns = DirectoryLocator.getDirectory(DirectoryInsurer.class);
        insurers = new JComboBox(dirIns.toArray());
        insurerRegions = new JComboBox(DirectoryLocator.getDirectory(DirectoryRegionIdCode.class).toArray());

        refreshTable();
    resizeColumn();
    StateSaver.attachTo(this);
   }

    private void refreshTable() {
        String title = "Отображены записи: " + polisList.size() + " из " + contract.polisListSize;
        jScrollPane1.setBorder(new TitledBorder(title));
        tablePolis.setModel(new TableModelPolisView(polisList, contract));
        tablePolis.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        tablePolis.getColumnModel().getColumn(TableModelPolisView.COL_INSURER).setCellEditor(new DefaultCellEditor(insurers));
        tablePolis.getColumnModel().getColumn(TableModelPolisView.COL_INSURER_REGION).setCellEditor(new DefaultCellEditor(insurerRegions));
        tablePolis.getColumnModel().getColumn(TableModelPolisView.COL_FROMDATE).setCellEditor(new ICDateChooserCellEditor());
        tablePolis.getColumnModel().getColumn(TableModelPolisView.COL_FROMDATE).setCellRenderer(new DateRenderer());
        tablePolis.getColumnModel().getColumn(TableModelPolisView.COL_TILLDATE).setCellEditor(new ICDateChooserCellEditor());
        tablePolis.getColumnModel().getColumn(TableModelPolisView.COL_TILLDATE).setCellRenderer(new DateRenderer());
    }
   
    private void resizeColumn() {
        TableState          state = new TableState();
        state.setPreferredWidth(TableModelPolisView.COL_INSURER,        8);
        state.setPreferredWidth(TableModelPolisView.COL_INSURER_REGION,  7);
        state.setPreferredWidth(TableModelPolisView.COL_SERIES,         3);
        state.setPreferredWidth(TableModelPolisView.COL_NUMBER,   6);
        state.setPreferredWidth(TableModelPolisView.COL_FIO,          8);
        state.setPreferredWidth(TableModelPolisView.COL_BIRTHDAY,     6);
        state.setPreferredWidth(TableModelPolisView.COL_MEMBER,         4);
        state.setPreferredWidth(TableModelPolisView.COL_FROMDATE,       4);
        state.setPreferredWidth(TableModelPolisView.COL_TILLDATE,       4);
        state.setPreferredWidth(TableModelPolisView.COL_ADDRESS,        10);
        StateSaver.setDefaultState(this, tablePolis, state);
    }
   
    public TableModel getTableModel() {
        return tablePolis.getModel();
    }

    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tablePolis = new cli_fmw.utils.sorted_table.SortedTable();
        jPanel2 = new javax.swing.JPanel();
        btService = new javax.swing.JButton();
        btAddPolis = new javax.swing.JButton();
        btDelPolis = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        tfSurname = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        tfName = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        tfPathron = new javax.swing.JTextField();
        jPanel10 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        tfSeries = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        tfNumber = new javax.swing.JTextField();
        btRefresh = new javax.swing.JButton();
        jPanel11 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();

        setLayout(new java.awt.BorderLayout());

        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Отображаются первые 50 найденные записи"));
        jScrollPane1.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                jScrollPane1ComponentResized(evt);
            }
        });

        tablePolis.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tablePolis.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablePolisMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tablePolis);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        btService.setText("   Услуги   ");
        btService.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btServiceActionPerformed(evt);
            }
        });
        jPanel2.add(btService);

        btAddPolis.setText("Добавить");
        btAddPolis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddPolisActionPerformed(evt);
            }
        });
        jPanel2.add(btAddPolis);

        btDelPolis.setText(" Удалить ");
        btDelPolis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDelPolisActionPerformed(evt);
            }
        });
        jPanel2.add(btDelPolis);

        add(jPanel2, java.awt.BorderLayout.SOUTH);

        jPanel1.setLayout(new java.awt.BorderLayout(0, 3));

        jPanel9.setLayout(new java.awt.GridLayout(1, 0, 5, 0));

        jPanel3.setLayout(new java.awt.GridLayout(2, 1));

        jLabel1.setText("Фамилия");
        jPanel3.add(jLabel1);

        tfSurname.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfSurnameActionPerformed(evt);
            }
        });
        jPanel3.add(tfSurname);

        jPanel9.add(jPanel3);

        jPanel4.setLayout(new java.awt.GridLayout(2, 1));

        jLabel2.setText("Имя");
        jPanel4.add(jLabel2);

        tfName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfNameActionPerformed(evt);
            }
        });
        jPanel4.add(tfName);

        jPanel9.add(jPanel4);

        jPanel5.setLayout(new java.awt.GridLayout(2, 1));

        jLabel3.setText("Отчество");
        jPanel5.add(jLabel3);

        tfPathron.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfPathronActionPerformed(evt);
            }
        });
        jPanel5.add(tfPathron);

        jPanel9.add(jPanel5);

        jPanel10.setLayout(new java.awt.GridLayout(1, 0, 5, 0));

        jPanel7.setLayout(new java.awt.GridLayout(2, 1));

        jLabel5.setText("Серия полиса");
        jPanel7.add(jLabel5);

        tfSeries.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfSeriesActionPerformed(evt);
            }
        });
        jPanel7.add(tfSeries);

        jPanel10.add(jPanel7);

        jPanel6.setLayout(new java.awt.GridLayout(2, 1));

        jLabel4.setText("Номер полиса");
        jPanel6.add(jLabel4);

        tfNumber.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfNumberActionPerformed(evt);
            }
        });
        jPanel6.add(tfNumber);

        jPanel10.add(jPanel6);

        btRefresh.setText("Обновить");
        btRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRefreshActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btRefresh)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btRefresh)
                    .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jPanel1.add(jPanel8, java.awt.BorderLayout.CENTER);

        jPanel11.setLayout(new java.awt.BorderLayout());

        jLabel6.setText("Критерии поиска");
        jPanel11.add(jLabel6, java.awt.BorderLayout.PAGE_START);

        jPanel1.add(jPanel11, java.awt.BorderLayout.PAGE_START);

        add(jPanel1, java.awt.BorderLayout.PAGE_START);
    }// </editor-fold>//GEN-END:initComponents

    private void jScrollPane1ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jScrollPane1ComponentResized

    }//GEN-LAST:event_jScrollPane1ComponentResized

    private void btAddPolisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddPolisActionPerformed
        try {
            EmptyDialog dialog = new EmptyDialog(MainWindow.mainWindow, "Выбор члена договора", getAuditManager());
            PanelUserSearch panel = new PanelUserSearch(dialog, PanelUserSearch.MODE_MULTISELECT);
            dialog.addNewPage((PageGeneric) panel, null);
            dialog.setVisible(true);
            if(dialog.getDlgResult() == ModalDialog.DLG_OK) {
                ArrayList<ClientLocal> clientList = panel.getSelectedClientList();
                DirectoryInsurerItem insItem;
                if (polisList.size() > 0) {
                    insItem = polisList.get(0).getInsurer();
                }
                else {
                    insItem = UserInfo.get().getCollaborator().getLpu().getDefaultInsurer();
                }
                for(int i = 0; i < clientList.size(); i++) {
                    //проверка на добавку уже существующего договормембера
                    if (contract.isClientNotYetInContract(clientList.get(i))) {
                        PolisData polisData = new PolisData(contract, clientList.get(i));
                        polisData.setNumber("");
                        polisData.setSeries("");
                        polisData.setMember(true);
                        polisData.setRegionCode(ConfigLocal.getInstance().getConfigRegionCode());
                        if (contract.getType() == Contract.TYPE_OMI){
                            polisData.setInsurer(insItem);
                        }
                        contract.savePolisData(polisData);
                        polisList.add(polisData);
                    }
                    else {
                        MessageBox.showInfo("Пациент уже является участником данного договора");
                        return;
                    }
                }
            }
            refreshTable();
        } catch(PageException ex) {
            MessageBox.showException(ex);
        } catch(Exception ex) {
            MessageBox.showException(ex);
        }
}//GEN-LAST:event_btAddPolisActionPerformed

    private void btDelPolisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDelPolisActionPerformed
        try {
            if(tablePolis.getSelectedRowCount() != 0) {
                if(MessageBox.showConfirmYesNo(MessageBox.C_DEL_CLIENT) == MessageBox.ANSWER_OK) {
                    int[] indexes = tablePolis.getSelectedRowsSorted();
                    for(int i = indexes.length - 1; i >= 0; i--) {
                        PolisData polis = polisList.get(indexes[i]);
                        contract.removePolisData(polis);
                        polisList.remove(indexes[i]);
                    }
                    refreshTable();
                }
            } else {
                MessageBox.showWarning(MessageBox.W_LIST_ELEMENT_NOT_SELECT);
            }
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
}//GEN-LAST:event_btDelPolisActionPerformed

private void btServiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btServiceActionPerformed
        int pos = tablePolis.getSelectedRowSorted();
        if (pos >= 0) {
            try {
                PanelSerRenList panel = new PanelSerRenList(MainWindow.mainWindow,
                        polisList.get(pos).getClient(getAuditManager()),
                        polisList.get(pos).getContract(),
                        null,
                        PanelSerRenList.MODE_BY_PERIOD);
                MainWindow.mainWindow.addNewPage(panel, MainWindow.mainWindow.getActivePage());
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
            }
        } else {
            MessageBox.showWarning(MessageBox.W_LIST_ELEMENT_NOT_SELECT);
        }       
}//GEN-LAST:event_btServiceActionPerformed

private void tablePolisMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablePolisMouseClicked
    try {
        int col = tablePolis.columnAtPoint(evt.getPoint());
        TableColumn coll = tablePolis.getColumnModel().getColumn(col);
        col = coll.getModelIndex();
        int row = tablePolis.getSelectedRowSorted();
        if (evt.getClickCount() < 2 || col < 0 || row < 0) {
            return;
        }
        PolisData polis = polisList.get(row);
        if (col == TableModelPolisView.COL_ADDRESS) {
            Address address = UserInfo.get().getCollaborator().getLpu().getAddress();
            DialogAddressM dialog = new DialogAddressM(MainWindow.mainWindow, polis.getAddress(), address, getAuditManager());
            dialog.setVisible(true);
            if (dialog.getDlgResult() == ModalDialog.DLG_CANCEL) {
                return;
            }
            if (!dialog.getAddress().equals(polis.getAddress())){
                polis.setAddress(dialog.getAddress());
                contract.savePolisData(polis);
            }
        }
        getContainer().contentStateChanged();
    } catch (ClipsException ex) {
        MessageBox.showException(ex);
    }
}//GEN-LAST:event_tablePolisMouseClicked

private void btRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRefreshActionPerformed
    try {
        filter.surname = tfSurname.getText().trim().isEmpty() ? null : Converter.firstUpper(tfSurname.getText().trim(), true);
        filter.name = tfName.getText().trim().isEmpty() ? null : Converter.firstUpper(tfName.getText().trim(), true);
        filter.pathron = tfPathron.getText().trim().isEmpty() ? null : Converter.firstUpper(tfPathron.getText().trim(), true);
        filter.polisSeries = tfSeries.getText().trim().isEmpty() ? null : tfSeries.getText().trim().toUpperCase();
        filter.polisNumber = tfNumber.getText().trim().isEmpty() ? null : tfNumber.getText().trim();
        polisList = contract.getPolisList(filter);
        refreshTable();
    } catch (ClipsException ex) {
        MessageBox.showException(ex);
    }
}//GEN-LAST:event_btRefreshActionPerformed

private void tfSurnameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfSurnameActionPerformed
    btRefreshActionPerformed(evt);
}//GEN-LAST:event_tfSurnameActionPerformed

private void tfNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfNameActionPerformed
    btRefreshActionPerformed(evt);
}//GEN-LAST:event_tfNameActionPerformed

private void tfPathronActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfPathronActionPerformed
    btRefreshActionPerformed(evt);
}//GEN-LAST:event_tfPathronActionPerformed

private void tfSeriesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfSeriesActionPerformed
    btRefreshActionPerformed(evt);
}//GEN-LAST:event_tfSeriesActionPerformed

private void tfNumberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfNumberActionPerformed
    btRefreshActionPerformed(evt);
}//GEN-LAST:event_tfNumberActionPerformed
  
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAddPolis;
    private javax.swing.JButton btDelPolis;
    private javax.swing.JButton btRefresh;
    private javax.swing.JButton btService;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private cli_fmw.utils.sorted_table.SortedTable tablePolis;
    private javax.swing.JTextField tfName;
    private javax.swing.JTextField tfNumber;
    private javax.swing.JTextField tfPathron;
    private javax.swing.JTextField tfSeries;
    private javax.swing.JTextField tfSurname;
    // End of variables declaration//GEN-END:variables

    @Override
    public String getPageTitle() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public DelegateLine2 getDelegate() {
        return contract;
    }
}
TOP

Related Classes of clips.contract.info.polis.PanelPolisView

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.