⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 processdialog.java

📁 Java写的ERP系统
💻 JAVA
字号:
/******************************************************************************
 * The contents of this file are subject to the   Compiere License  Version 1.1
 * ("License"); You may not use this file except in compliance with the License
 * You may obtain a copy of the License at http://www.compiere.org/license.html
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Original Code is                  Compiere  ERP & CRM  Business Solution
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
 * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
 * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
 * Contributor(s): ______________________________________.
 *****************************************************************************/
package org.compiere.apps;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

import java.sql.*;
import java.util.*;
import java.text.*;

import org.compiere.print.*;
import org.compiere.util.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
import org.compiere.process.*;

/**
 *	Dialog to Start process.
 *	Displays information about the process
 *		and lets the user decide to start it
 *  	and displays results (optionally print them).
 *  Calls ProcessCtl to execute.
 *
 *  @author 	Jorg Janke
 *  @version 	$Id: ProcessDialog.java,v 1.21 2003/02/15 06:31:42 jjanke Exp $
 */
public class ProcessDialog extends JFrame
	implements ActionListener, ASyncProcess
{
	/**
	 *	Dialog to start Process
	 *
	 * @param AD_Process_ID process
	 * @param isSOTrx is sales trx
	 */
	public ProcessDialog (int AD_Process_ID, boolean isSOTrx)
	{
		super();
		Log.trace(Log.l1_User, "ProcessDialog - Process=" + AD_Process_ID + "; SOTrx=" + isSOTrx);
		enableEvents(AWTEvent.WINDOW_EVENT_MASK);
		m_AD_Process_ID = AD_Process_ID;
		m_WindowNo = Env.createWindowNo (this);
		Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", isSOTrx ? "Y" : "N");
		try
		{
			jbInit();
		}
		catch(Exception ex)
		{
			Log.error("ProcessDialog", ex);
		}
	}	//	ProcessDialog

	private int 		    m_AD_Process_ID;
	private int			    m_WindowNo;
	private String		    m_Name = null;
	private boolean		    m_IsReport = false;
	private ArrayList	    m_items;
	private boolean	        m_isLocked = false;
	//

	private CPanel dialog = new CPanel();
	private BorderLayout mainLayout = new BorderLayout();
	private CPanel southPanel = new CPanel();
	private JButton bOK = new JButton();
	private FlowLayout southLayout = new FlowLayout();
	private CText message = new CText();
	private CButton bPrint = new CButton();

	/**
	 *	Static Layout
	 *  @throws Exception
	 */
	private void jbInit() throws Exception
	{
		CompiereColor.setBackground(this);
		this.setIconImage(org.compiere.Compiere.getImage16());
		//
		dialog.setLayout(mainLayout);
		bOK.setHorizontalTextPosition(SwingConstants.LEFT);
		bOK.setIcon(Env.getImageIcon("Ok24.gif"));
		bOK.addActionListener(this);
		bPrint.setIcon(Env.getImageIcon("Print24.gif"));
		bPrint.setMargin(new Insets(2, 2, 2, 2));
		bPrint.addActionListener(this);
		//
		southPanel.setLayout(southLayout);
		southLayout.setAlignment(FlowLayout.RIGHT);
		dialog.setPreferredSize(new Dimension(500, 150));
		message.setReadWrite(false);
		message.setLineWrap(true);
		message.setWrapStyleWord(true);
		getContentPane().add(dialog);
		dialog.add(southPanel, BorderLayout.SOUTH);
		southPanel.add(bPrint, null);
		southPanel.add(bOK, null);
		dialog.add(message, BorderLayout.CENTER);
	}	//	jbInit

	/**
	 *	Dispose
	 */
	public void dispose()
	{
		Env.clearWinContext(m_WindowNo);
		super.dispose();
	}	//	dispose


	/**
	 *	Dynamic Init
	 *  @return true, if there is something to process (start from menu)
	 */
	public boolean init()
	{
		Log.trace(Log.l3_Util, "ProcessDialog.init");
		//
		boolean trl = !Env.isBaseLanguage(Env.getCtx(), "AD_Process");
		String SQL = "SELECT Name, Description, Help, IsReport "
				+ "FROM AD_Process "
				+ "WHERE AD_Process_ID=?";;
		if (trl)
			SQL = "SELECT t.Name, t.Description, t.Help, p.IsReport "
				+ "FROM AD_Process p, AD_Process_Trl t "
				+ "WHERE p.AD_Process_ID=t.AD_Process_ID"
				+ " AND p.AD_Process_ID=? AND t.AD_Language=?";
		String msg = null;
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(SQL);
			pstmt.setInt(1, m_AD_Process_ID);
			if (trl)
				pstmt.setString(2, Env.getAD_Language(Env.getCtx()));
			ResultSet rs = pstmt.executeQuery();
			if (rs.next())
			{
				m_Name = rs.getString(1);
				m_IsReport = rs.getString(4).equals("Y");
				//
				String s = rs.getString(2);
				if (rs.wasNull())
					msg = Msg.getMsg(Env.getCtx(), "StartProcess?");
				else
					msg = s;
				s = rs.getString(3);
				if (!rs.wasNull())
					msg += "\n\n" + s;
			}

			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			Log.error("ProcessDialog.init", e);
			return false;
		}

		if (m_Name == null)
			return false;
		//
		this.setTitle(m_Name);
		message.setText(msg);
		bOK.setText(Msg.getMsg(Env.getCtx(), "Start"));

		//	Start Reports w/o asking
		if (m_IsReport)
		{
			bOK.doClick();
			return false;		//	don't show
		}

		return true;
	}	//	init

	/**
	 *	ActionListener
	 *  @param e ActionEvent
	 */
	public void actionPerformed (ActionEvent e)
	{
		if (e.getSource() == bOK)
		{
			if (bOK.getText().length() == 0)
				dispose();
			else
			{
				//	Similar to APanel.actionButton
				ProcessInfo pi = new ProcessInfo(m_Name, m_AD_Process_ID, 0);
				message.append("\n** ");
				message.append(m_Name);
				ProcessCtl.process(this, m_WindowNo, pi);
			}
		}

		else if (e.getSource() == bPrint)
			printScreen();
	}	//	actionPerformed


	/**
	 *  Lock User Interface
	 *  Called from the Worker before processing
	 *  @param pi process info
	 */
	public void lockUI (ProcessInfo pi)
	{
		bOK.setText("");
		bOK.setEnabled(false);
		this.setEnabled(false);
		m_isLocked = true;
	}   //  lockUI

	/**
	 *  Unlock User Interface.
	 *  Called from the Worker when processing is done
	 *  @param pi process info
	 */
	public void unlockUI (ProcessInfo pi)
	{
		pi.setProcessLog();
		message.append("\n** ");
		message.append(pi.Summary);
		message.append("\n");
		message.append(pi.LogInfo);
		message.setCaretPosition(message.getText().length());	//	scroll down
		m_items = pi.getIDList();
		//
		bOK.setEnabled(true);
		this.setEnabled(true);
		m_isLocked = false;
		//
		afterProcessTask();
	}   //  unlockUI

	/**
	 *  Is the UI locked (Internal method)
	 *  @return true, if UI is locked
	 */
	public boolean isUILocked()
	{
		return m_isLocked;
	}   //  isLoacked

	/**
	 *  Method to be executed async.
	 *  Called from the ASyncProcess worker
	 *  @param pi process info
	 */
	public void executeASync (ProcessInfo pi)
	{
		Log.trace(Log.l3_Util, "ProcessDialog.executeASync");
	}   //  executeASync

	/*************************************************************************/

	/**
	 *	Optional Processing Task
	 */
	private void afterProcessTask()
	{
		//  something to do?
		if (m_items.size() > 0)
		{
			Log.trace(Log.l3_Util, "ProcessDialog.afterProcessTask");
			//	Print invoices
			if (m_AD_Process_ID == 119)
				printInvoices();
			else if (m_AD_Process_ID == 118)
				printShipments();
		}

	}	//	afterProcessTask

	/*************************************************************************/

	/**
	 *	Print Shipments
	 */
	private void printShipments()
	{
		if (!ADialog.ask(m_WindowNo, this, "PrintShipments"))
			return;
		message.append("\n\n");
		message.append(Msg.getMsg(Env.getCtx(), "PrintShipments"));
		do
		{
			//	Loop through all items
			for (int i = 0; i < m_items.size(); i++)
			{
				Integer M_InOut_ID = (Integer)m_items.get(i);
				ReportCtl.startDocumentPrint(ReportCtl.SHIPMENT, M_InOut_ID.intValue(), true);
			}
		}
		while (!ADialog.ask(m_WindowNo, this, "PrintoutOK?"));
	}	//	printInvoices

	/**
	 *	Print Invoices
	 */
	private void printInvoices()
	{
		if (!ADialog.ask(m_WindowNo, this, "PrintInvoices"))
			return;
		message.append("\n\n");
		message.append(Msg.getMsg(Env.getCtx(), "PrintInvoices"));
		do
		{
			//	Loop through all items
			for (int i = 0; i < m_items.size(); i++)
			{
				Integer AD_Invoice_ID = (Integer)m_items.get(i);
				ReportCtl.startDocumentPrint(ReportCtl.INVOICE, AD_Invoice_ID.intValue(), true);
			}
		}
		while (!ADialog.ask(m_WindowNo, this, "PrintoutOK?"));
	}	//	printInvoices

	/**
	 *	Print Screen
	 */
	private void printScreen()
	{
		PrintScreenPainter.printScreen (this);
	}	//	printScreen

}	//	ProcessDialog

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -