/*
* SicklistContinueDlg.java
*
* Created on 21 Март 2008 г., 18:41
*/
package clips.doctor.sicklist.dialogs;
import cli_fmw.delegate.utils.TimeLocal;
import cli_fmw.main.ClipsException;
import cli_fmw.main.audit.AuditManager;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.client.ClientLocal;
import clips.delegate.service.SerRenLocal;
import framework.utils.Converter;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import framework.utils.DateTimeUtils;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import org.infotechservice.ICalendar.DateEvent;
import org.infotechservice.ICalendar.DateListener;
/**
* Диалог продления больничного
* @author axe
*/
public class DialogSicklistContinue extends ModalDialog {
private GregorianCalendar dateTill;//дата до которой будет продлён
private GregorianCalendar lastDate;//последняя дата
List<SerRenLocal> serrenList;
/** Creates new form SicklistContinueDlg
* @param parent
* @param lastDate
*/
public DialogSicklistContinue(java.awt.Frame parent, ClientLocal client, final GregorianCalendar lastDate, AuditManager am) throws ClipsException {
super(parent, "Продление больничного", am);
initComponents();
this.lastDate = (GregorianCalendar) lastDate.clone();
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle dlgSize = this.getBounds();
this.setLocation((scrSize.width - dlgSize.width) / 2, (scrSize.height -
dlgSize.height) / 2);
for (int i = 1; i <= 30; i++) {
cbDays.addItem(new Integer(i));
}
dateTill = (GregorianCalendar) this.lastDate.clone();
dateTill.add(GregorianCalendar.DAY_OF_YEAR, 1);
dchTill.setDate(dateTill.getTime());
dchTill.addDateListener(new DateListener() {
@Override
public void dateChanged(DateEvent evt) {
System.out.println("Попытка изменить конечную дату");
Date to = evt.getNewValue();
Integer daysBetween = new Integer((int)DateTimeUtils.daysBetween(lastDate.getTime(), to)) + 1;
if (daysBetween <= 0) {
MessageBox.showWarning("Дата окончания должна быть больше даты начала");
dchTill.setDate(evt.getOldValue());
} else if (cbDays.getSelectedItem() == null || !cbDays.getSelectedItem().equals(daysBetween)) {
if (daysBetween > 30) {
MessageBox.showWarning("Срок продления составляет " + daysBetween + " суток");
}
cbDays.setSelectedItem(daysBetween);
}
}
});
// Найдем все услуги и посещения на текущую дату
GregorianCalendar currentTime = TimeLocal.getCurrentTime();
Date begin = DateTimeUtils.getDateOnly(currentTime.getTime());
currentTime.add(Calendar.DAY_OF_YEAR, 1);
Date end = DateTimeUtils.getDateOnly(currentTime.getTime());
serrenList = client.getSerRenList(begin, end, null);
DefaultComboBoxModel cbModel = new DefaultComboBoxModel();
for (int i = 0; i < serrenList.size(); i++) {
SerRenLocal serRenLocal = serrenList.get(i);
String item = Converter.dateToString(serRenLocal.getSerDate())
+ serRenLocal.getService().getTitle();
cbModel.addElement(item);
}
if (serrenList.size() == 0) {
cbModel.addElement("На текущую дату у пациента не найден талон");
cbSerren.setEnabled(false);
btOK.setEnabled(false);
}
cbSerren.setModel(cbModel);
cbSerren.setSelectedIndex(0);
StateSaver.attachTo(this);
}
/**
* Геттер для даты
* @return дата до которой будет продлён больничный
*/
public Calendar getDateTill(){
return dateTill;
}
public SerRenLocal getSerren() {
return serrenList.get(cbSerren.getSelectedIndex());
}
/** 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() {
buttonGroup1 = new javax.swing.ButtonGroup();
jPanel4 = new javax.swing.JPanel();
durationPanel = new javax.swing.JPanel();
rbDurationDays = new javax.swing.JRadioButton();
cbDays = new javax.swing.JComboBox();
rbDurationTillDate = new javax.swing.JRadioButton();
dchTill = new org.infotechservice.ICalendar.components.ICDateChooser();
jLabel1 = new javax.swing.JLabel();
cbSerren = new javax.swing.JComboBox();
jPanel1 = new javax.swing.JPanel();
btOK = new javax.swing.JButton();
btCancel = new javax.swing.JButton();
buttonGroup1.add(rbDurationDays);
buttonGroup1.add(rbDurationTillDate);
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
jPanel4.setLayout(new javax.swing.BoxLayout(jPanel4, javax.swing.BoxLayout.PAGE_AXIS));
durationPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Продлить на ...", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, btOK.getFont()));
rbDurationDays.setSelected(true);
rbDurationDays.setText("Дней");
rbDurationDays.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rbDurationDaysActionPerformed(evt);
}
});
cbDays.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbDaysActionPerformed(evt);
}
});
rbDurationTillDate.setText("До даты, включительно");
rbDurationTillDate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rbDurationTillDateActionPerformed(evt);
}
});
dchTill.setEnabled(false);
dchTill.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
dchTillPropertyChange(evt);
}
});
jLabel1.setText("Талон или услуга:");
javax.swing.GroupLayout durationPanelLayout = new javax.swing.GroupLayout(durationPanel);
durationPanel.setLayout(durationPanelLayout);
durationPanelLayout.setHorizontalGroup(
durationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(durationPanelLayout.createSequentialGroup()
.addGroup(durationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(durationPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(durationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(durationPanelLayout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(dchTill, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE))
.addGroup(durationPanelLayout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(cbDays, 0, 242, Short.MAX_VALUE))
.addComponent(rbDurationDays)
.addComponent(rbDurationTillDate)
.addComponent(jLabel1)))
.addGroup(durationPanelLayout.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(cbSerren, 0, 242, Short.MAX_VALUE)))
.addContainerGap())
);
durationPanelLayout.setVerticalGroup(
durationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(durationPanelLayout.createSequentialGroup()
.addComponent(rbDurationDays)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbDays, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(rbDurationTillDate)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(dchTill, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbSerren, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(92, Short.MAX_VALUE))
);
jPanel4.add(durationPanel);
btOK.setText("Принять");
btOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btOKActionPerformed(evt);
}
});
jPanel1.add(btOK);
btCancel.setText("Отмена");
btCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btCancelActionPerformed(evt);
}
});
jPanel1.add(btCancel);
jPanel4.add(jPanel1);
getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* Клик на "Принять"
* @param evt
*/
private void btOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOKActionPerformed
setDlgResult(ModalDialog.DLG_OK);
setVisible(false);
}//GEN-LAST:event_btOKActionPerformed
/**
* радиобатон "дни"
* @param evt
*/
private void rbDurationDaysActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbDurationDaysActionPerformed
cbDays.setEnabled(rbDurationDays.isSelected());
dchTill.setEnabled(rbDurationTillDate.isSelected());
if (cbDays.getSelectedItem() != null) {//дни ненулевые
Integer integ = (Integer) cbDays.getSelectedItem();//берём выбранный
dateTill = (GregorianCalendar) lastDate.clone();
dateTill.add(GregorianCalendar.DATE, integ);//и прибавляем к текущей дате
dchTill.setDate(dateTill.getTime());
}
}//GEN-LAST:event_rbDurationDaysActionPerformed
/**
* радиобатон "до даты"
* @param evt
*/
private void rbDurationTillDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbDurationTillDateActionPerformed
dchTill.setEnabled(rbDurationTillDate.isSelected());
cbDays.setEnabled(rbDurationDays.isSelected());
}//GEN-LAST:event_rbDurationTillDateActionPerformed
/**
* Клик на "Отмена"
* @param evt
*/
private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed
setDlgResult(ModalDialog.DLG_CANCEL);
dateTill = null;
setVisible(false);
}//GEN-LAST:event_btCancelActionPerformed
private void cbDaysActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDaysActionPerformed
if (cbDays.getSelectedItem() != null) {//дни ненулевые
Integer integ = (Integer) cbDays.getSelectedItem();//берём выбранный
dateTill = (GregorianCalendar) lastDate.clone();
dateTill.add(GregorianCalendar.DATE, integ - 1);//и прибавляем к текущей дате
dchTill.setDate(dateTill.getTime());
}
}//GEN-LAST:event_cbDaysActionPerformed
private void dchTillPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dchTillPropertyChange
Calendar cal = dchTill.getCalendar();
if (cal != null) {
dateTill = new GregorianCalendar();
dateTill.setTime(cal.getTime());//её и вернём
}
}//GEN-LAST:event_dchTillPropertyChange
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btCancel;
private javax.swing.JButton btOK;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JComboBox cbDays;
private javax.swing.JComboBox cbSerren;
private org.infotechservice.ICalendar.components.ICDateChooser dchTill;
private javax.swing.JPanel durationPanel;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel4;
private javax.swing.JRadioButton rbDurationDays;
private javax.swing.JRadioButton rbDurationTillDate;
// End of variables declaration//GEN-END:variables
}