//
// Created by Grishul Eugeny
//
// Copyright © Grishul Eugeny 2008
//

import java.awt.Window;
import javax.swing.JOptionPane;

public class AddTaskProgressForm extends javax.swing.JDialog {
	public DbLayer DbLayerInstance;
	
	public AddTaskProgressForm( DbLayer dblayerInstance, Window parent ) throws Throwable {
		super( parent, ModalityType.DOCUMENT_MODAL );
		DbLayerInstance = dblayerInstance;
		initComponents();

		int currentProgress = DbLayerInstance.getTaskProgressPercentage( DbLayerInstance.getLoggedInEmployee().TaskID ) + 1;
		_completion.setModel( new javax.swing.SpinnerNumberModel( currentProgress, currentProgress, 100, 1 ) );
		
		setLocationRelativeTo( parent );
	}

	@SuppressWarnings( "unchecked" )
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        _reportBuilder = new ReportControl();
        _cancel = new javax.swing.JButton();
        _ok = new javax.swing.JButton();
        _progressLabel = new javax.swing.JLabel();
        _completion = new javax.swing.JSpinner();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Создать отчет по заданию");

        _cancel.setText("Отмена");
        _cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _cancelActionPerformed(evt);
            }
        });

        _ok.setText("ОК");
        _ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _okActionPerformed(evt);
            }
        });

        _progressLabel.setText("Выполненность:");

        _completion.setModel(new javax.swing.SpinnerNumberModel(0, 0, 100, 1));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(_progressLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(_completion, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                .addComponent(_ok, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(_cancel, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(_reportBuilder, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(_reportBuilder, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(_cancel)
                    .addComponent(_ok)
                    .addComponent(_progressLabel)
                    .addComponent(_completion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void _okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__okActionPerformed
	try {
		if( _reportBuilder.getCurrentReport().Text.equals( "" ) )
		{
			JOptionPane.showMessageDialog( this, "Напиши хоть чего-нибудь!" );
			_reportBuilder.requestFocus();
			return;
		}
		
		_reportBuilder.getCurrentReport().From = DbLayerInstance.getLoggedInEmployee().ID;

		DbLayerInstance.reportTaskProgress( new DbTaskProgress( _reportBuilder.getCurrentReport(), ( Integer ) _completion.getValue(), DbLayerInstance.getLoggedInEmployee().TaskID ) );

		dispose();
	} catch( Throwable excpt ) {
		JOptionPane.showMessageDialog( this, excpt.getMessage() );
	}

}//GEN-LAST:event__okActionPerformed

private void _cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__cancelActionPerformed
	dispose();
}//GEN-LAST:event__cancelActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _cancel;
    private javax.swing.JSpinner _completion;
    private javax.swing.JButton _ok;
    private javax.swing.JLabel _progressLabel;
    private ReportControl _reportBuilder;
    // End of variables declaration//GEN-END:variables
}
Соседние файлы в папке src