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

📄 infoproduct.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
 * 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.search;

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

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

import org.compiere.apps.*;
import org.compiere.util.*;
import org.compiere.grid.ed.*;
import org.compiere.minigrid.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
import org.compiere.model.*;

/**
 *	Search Product and return selection
 *
 *  @author     Jorg Janke
 *  @version    $Id: InfoProduct.java,v 1.11 2002/09/03 05:11:09 jjanke Exp $
 */
public final class InfoProduct extends Info implements ActionListener
{
	/**
	 *	Standard Constructor

	 * @param frame frame
	 * @param modal modal
	 * @param WindowNo window no
	 * @param M_Warehouse_ID warehouse
	 * @param M_PriceList_ID price list
	 * @param value    Query Value or Name if enclosed in @
	 * @param multiSelection multiple selections
	 * @param whereClause where clause
	 */
	public InfoProduct(Frame frame, boolean modal, int WindowNo,
		int M_Warehouse_ID, int M_PriceList_ID, String value,
		boolean multiSelection, String whereClause)
	{
		super (frame, modal, WindowNo, "p", "M_Product_ID", multiSelection, whereClause);
		Log.trace(Log.l1_User, "InfoProduct", value + ", Wh=" + M_Warehouse_ID + ", PL=" + M_PriceList_ID + ", WHERE=" + whereClause);
		setTitle(Msg.getMsg(Env.getCtx(), "InfoProduct"));
		//
		statInit();
		initInfo (value, M_Warehouse_ID, M_PriceList_ID);
		//
		int no = m_table.getRowCount();
		setStatusLine(Integer.toString(no) + " " + Msg.getMsg(Env.getCtx(), "SearchRows_EnterQuery"), false);
		setStatusDB(Integer.toString(no));
		//	AutoQuery
		if (value != null && value.length() > 0)
			executeQuery();
		m_loadedOK = true;
		//	Focus
		fieldValue.requestFocus();

		AEnv.positionCenterWindow(frame, this);
	}	//	InfoProduct

	/**  Array of Column Info    */
	private static final Info_Column[] s_productLayout = {
		new Info_Column(" ", "p.M_Product_ID", IDColumn.class),
		new Info_Column(Msg.translate(Env.getCtx(), "Discontinued").substring(0, 1), "p.Discontinued", Boolean.class),
		new Info_Column(Msg.translate(Env.getCtx(), "Value"), "p.Value", String.class),
		new Info_Column(Msg.translate(Env.getCtx(), "Name"), "p.Name", String.class),
		new Info_Column(Msg.translate(Env.getCtx(), "QtyAvailable"), "BOM_Qty_Available(p.M_Product_ID,?) AS QtyAvailable", Double.class, true, true, null),
		new Info_Column(Msg.translate(Env.getCtx(), "PriceList"), "BOM_PriceList(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceList",  BigDecimal.class),
		new Info_Column(Msg.translate(Env.getCtx(), "PriceStd"), "BOM_PriceStd(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceStd", BigDecimal.class),
		new Info_Column(Msg.translate(Env.getCtx(), "QtyOnHand"), "BOM_Qty_OnHand(p.M_Product_ID,?) AS QtyOnHand", Double.class),
		new Info_Column(Msg.translate(Env.getCtx(), "QtyReserved"), "BOM_Qty_Reserved(p.M_Product_ID,?) AS QtyReserved", Double.class),
		new Info_Column(Msg.translate(Env.getCtx(), "QtyOrdered"), "BOM_Qty_Ordered(p.M_Product_ID,?) AS QtyOrdered", Double.class),
		new Info_Column(Msg.translate(Env.getCtx(), "Margin"), "BOM_PriceStd(p.M_Product_ID, pr.M_PriceList_Version_ID)-BOM_PriceLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS Margin", BigDecimal.class),
		new Info_Column(Msg.translate(Env.getCtx(), "PriceLimit"), "BOM_PriceLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceLimit", BigDecimal.class)
	};

	//
	private CLabel labelValue = new CLabel();
	private CLabel labelName = new CLabel();
	private CTextField fieldValue = new CTextField(10);
	private CTextField fieldName = new CTextField(10);
	private VComboBox pickPriceList = new VComboBox();
	private VComboBox pickWarehouse = new VComboBox();
	private CLabel labelWarehouse = new CLabel();
	private CLabel labelPriceList = new CLabel();

	/**
	 *	Static Setup - add fields to parameterPanel
	 */
	private void statInit()
	{
		labelValue.setText(Msg.getMsg(Env.getCtx(), "Value"));
		labelValue.setHorizontalAlignment(JLabel.LEADING);
		fieldValue.setBackground(CompierePLAF.getInfoBackground());
		fieldValue.addActionListener(this);
		labelName.setText(Msg.getMsg(Env.getCtx(), "Name"));
		labelName.setHorizontalAlignment(JLabel.LEADING);
		fieldName.setBackground(CompierePLAF.getInfoBackground());
		fieldName.addActionListener(this);
		labelWarehouse.setText(Msg.getMsg(Env.getCtx(), "Warehouse"));
		labelWarehouse.setHorizontalAlignment(JLabel.LEADING);
		pickWarehouse.setBackground(CompierePLAF.getInfoBackground());
		labelPriceList.setText(Msg.getMsg(Env.getCtx(), "PriceListVersion"));
		labelPriceList.setHorizontalAlignment(JLabel.LEADING);
		pickPriceList.setBackground(CompierePLAF.getInfoBackground());
		//
		parameterPanel.setLayout(new ALayout());
		//
		parameterPanel.add(labelValue, new ALayoutConstraint(0,0));
		parameterPanel.add(labelName, null);
		parameterPanel.add(labelWarehouse, null);
		parameterPanel.add(labelPriceList, null);
		//
		parameterPanel.add(fieldValue, new ALayoutConstraint(1,0));
		parameterPanel.add(fieldName, null);
		parameterPanel.add(pickWarehouse, null);
		parameterPanel.add(pickPriceList, null);
	}	//	statInit

	/**
	 *	Dynamic Init
	 *
	 * @param value value
	 * @param M_Warehouse_ID warehouse
	 * @param M_PriceList_ID price list
	 */
	private void initInfo (String value, int M_Warehouse_ID, int M_PriceList_ID)
	{
		//	Pick init
		fillPicks(M_PriceList_ID);
		int M_PriceList_Version_ID = findPLV (M_PriceList_ID);
		//	Set Value or Name
		if (value.startsWith("@") && value.endsWith("@"))
			fieldName.setText(value.substring(1,value.length()-1));
		else
			fieldValue.setText(value);
		//	Set Warehouse
		if (M_Warehouse_ID == 0)
			M_Warehouse_ID = Env.getContextAsInt(Env.getCtx(), "#M_Warehouse_ID");
		if (M_Warehouse_ID != 0)
			setWarehouse (M_Warehouse_ID);
		// 	Set PriceList Version
		if (M_PriceList_Version_ID != 0)
			setPriceListVersion (M_PriceList_Version_ID);

		//	Create Grid
		StringBuffer where = new StringBuffer();
		where.append("p.M_Product_ID=pr.M_Product_ID AND p.IsSummary='N' AND p.IsActive='Y' AND pr.IsActive='Y'");
		//  dynamic Where Clause
		if (m_whereClause != null && m_whereClause.length() > 0)
			where.append(" AND ")   //  replace fully qalified name with alias
				.append(Util.replace(m_whereClause, "M_Product.", "p."));
		//
		prepareTable(getProductLayout(),
			"M_Product p, M_ProductPrice pr",
			where.toString(),
			"QtyAvailable DESC, Margin DESC");

		//
		pickWarehouse.addActionListener(this);
		pickPriceList.addActionListener(this);
	}	//	initInfo

	/**
	 *	Fill Picks with values
	 *
	 * @param M_PriceList_ID price list
	 */
	private void fillPicks (int M_PriceList_ID)
	{
		//	Price List
		String SQL = "SELECT M_PriceList_Version.M_PriceList_Version_ID,"
			+ " M_PriceList_Version.Name || ' - ' || c.Iso_Code AS ValueName "
			+ "FROM M_PriceList_Version, M_PriceList p, C_Currency c "
			+ "WHERE M_PriceList_Version.M_PriceList_ID=p.M_PriceList_ID"
			+ " AND p.C_Currency_ID=c.C_Currency_ID"
			+ " AND M_PriceList_Version.IsActive='Y'";
		//	Same PL currency as original one
		if (M_PriceList_ID != 0)
			SQL += " AND EXISTS (SELECT * FROM M_PriceList xp WHERE xp.M_PriceList_ID=" + M_PriceList_ID
				+ " AND p.C_Currency_ID=xp.C_Currency_ID)";
		//	Add Access & Order
		SQL = Access.addROAccessSQL (Env.getCtx(), SQL, "M_PriceList_Version", true)
			+ " ORDER BY M_PriceList_Version.Name";
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(SQL);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next())
			{
				KeyNamePair kn = new KeyNamePair
					(rs.getInt("M_PriceList_Version_ID"), rs.getString("ValueName"));
				pickPriceList.addItem(kn);
			}
			rs.close();
			pstmt.close();

			//	Warehouse
			SQL = Access.addROAccessSQL (Env.getCtx(),
				"SELECT M_Warehouse_ID, Value || ' - ' || Name AS ValueName "
				+ "FROM M_Warehouse "
				+ "WHERE IsActive='Y'",
					"M_PriceList_Version", false)
				+ " ORDER BY Value";
			pstmt = DB.prepareStatement(SQL);
			rs = pstmt.executeQuery();
			while (rs.next())
			{
				KeyNamePair kn = new KeyNamePair
					(rs.getInt("M_Warehouse_ID"), rs.getString("ValueName"));
				pickWarehouse.addItem(kn);
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			Log.error ("InfoProduct.fillPicks", e);
			setStatusLine(e.getLocalizedMessage(), true);
		}
	}	//	fillPicks

	/**
	 *	Set Warehouse
	 *
	 * @param M_Warehouse_ID warehouse
	 */
	private void setWarehouse(int M_Warehouse_ID)
	{
		for (int i = 0; i < pickWarehouse.getItemCount(); i++)
		{
			KeyNamePair kn = (KeyNamePair)pickWarehouse.getItemAt(i);
			if (kn.getKey() == M_Warehouse_ID)
			{
				pickWarehouse.setSelectedIndex(i);
				return;
			}
		}
	}	//	setWarehouse

	/**
	 *	Set PriceList
	 *
	 * @param M_PriceList_Version_ID price list
	 */

⌨️ 快捷键说明

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