📄 vtrxmaterial.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.form;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.beans.*;
import java.sql.*;
import java.util.*;
import org.compiere.util.*;
import org.compiere.apps.*;
import org.compiere.grid.ed.*;
import org.compiere.grid.*;
import org.compiere.model.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
/**
* Material Transaction History
*
* @author Jorg Janke
* @version $Id: VTrxMaterial.java,v 1.13 2002/09/03 05:11:09 jjanke Exp $
*/
public class VTrxMaterial extends CPanel
implements FormPanel, ActionListener, VetoableChangeListener
{
/**
* Construvctor
*/
public VTrxMaterial()
{
} // VTrxMaterial
/** Window No */
private int m_WindowNo = 0;
/** FormFrame */
private FormFrame m_frame;
/** GridController */
private GridController m_gridController = null;
/** MWindow */
private MWindow m_mWindow = null;
/** MTab pointer */
private MTab m_mTab = null;
private MQuery m_staticQuery = null;
//
private CPanel mainPanel = new CPanel();
private BorderLayout mainLayout = new BorderLayout();
private CPanel parameterPanel = new CPanel();
private JLabel orgLabel = new JLabel();
private VLookup orgField;
private JLabel locatorLabel = new JLabel();
private VLocator locatorField;
private JLabel productLabel = new JLabel();
private VLookup productField;
private JLabel dateFLabel = new JLabel();
private VDate dateFField;
private JLabel dateTLabel = new JLabel();
private VDate dateTField;
private JLabel mtypeLabel = new JLabel();
private VLookup mtypeField;
private GridBagLayout parameterLayout = new GridBagLayout();
private CPanel southPanel = new CPanel();
private BorderLayout southLayout = new BorderLayout();
private ConfirmPanel confirmPanel = new ConfirmPanel(true, true, false, false, true, true);
private StatusBar statusBar = new StatusBar();
/**
* Initialize Panel
* @param WindowNo window
* @param frame frame
*/
public void init (int WindowNo, FormFrame frame)
{
Log.trace(Log.l1_User, "VTrxMaterial.init");
m_WindowNo = WindowNo;
m_frame = frame;
try
{
dynParameter();
jbInit();
dynInit();
frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
frame.getContentPane().add(statusBar, BorderLayout.SOUTH);
}
catch(Exception ex)
{
Log.error("VTrxMaterial.init", ex);
}
} // init
/**
* Static Init
* @throws Exception
*/
void jbInit() throws Exception
{
CompiereColor.setBackground(this);
mainPanel.setLayout(mainLayout);
mainLayout.setVgap(10);
parameterPanel.setLayout(parameterLayout);
//
orgLabel.setText(Msg.translate(Env.getCtx(), "AD_Org_ID"));
locatorLabel.setText(Msg.translate(Env.getCtx(), "M_Locator_ID"));
productLabel.setText(Msg.translate(Env.getCtx(), "M_Product_ID"));
dateFLabel.setText(Msg.translate(Env.getCtx(), "DateFrom"));
dateTLabel.setText(Msg.translate(Env.getCtx(), "DateTo"));
mtypeLabel.setText(Msg.translate(Env.getCtx(), "MovementType"));
//
mainPanel.add(parameterPanel, BorderLayout.NORTH);
parameterPanel.add(orgLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
parameterPanel.add(orgField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 5), 0, 0));
parameterPanel.add(mtypeLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
parameterPanel.add(mtypeField, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 5), 0, 0));
parameterPanel.add(dateFLabel, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
parameterPanel.add(dateFField, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 5), 0, 0));
parameterPanel.add(locatorLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
parameterPanel.add(locatorField, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 5), 0, 0));
parameterPanel.add(productLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
parameterPanel.add(productField, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 5), 0, 0));
parameterPanel.add(dateTLabel, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
parameterPanel.add(dateTField, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 5), 0, 0));
//
southPanel.setLayout(southLayout);
southPanel.add(confirmPanel, BorderLayout.NORTH);
southPanel.add(statusBar, BorderLayout.SOUTH);
mainPanel.add(southPanel, BorderLayout.SOUTH);
} // jbInit
/**
* Initialize Parameter fields
* @throws Exception if Lookups cannot be initialized
*/
private void dynParameter() throws Exception
{
Properties ctx = Env.getCtx();
// Organization
MLookup orgLookup = MLookupFactory.create (ctx, 3660, m_WindowNo, DisplayType.TableDir, false);
orgField = new VLookup("AD_Org_ID", false, false, true, orgLookup, DisplayType.TableDir, m_WindowNo);
// orgField.addVetoableChangeListener(this);
// Locator
MLocator locatorLookup = new MLocator(ctx, m_WindowNo);
locatorField = new VLocator("M_Locator_ID", false, false, true, locatorLookup);
// locatorField.addVetoableChangeListener(this);
// Product
MLookup productLookup = MLookupFactory.create (ctx, 3668, m_WindowNo, DisplayType.Search, false);
productField = new VLookup("M_Product_ID", false, false, true, productLookup, DisplayType.Search, m_WindowNo);
productField.addVetoableChangeListener(this);
// Movement Type
MLookup mtypeLookup = MLookupFactory.create (ctx, 3666, m_WindowNo, DisplayType.List, false);
mtypeField = new VLookup("MovementType", false, false, true, mtypeLookup, DisplayType.List, m_WindowNo);
// Dates
dateFField = new VDate("DateFrom", false, false, true, DisplayType.Date, Msg.getMsg(Env.getCtx(), "DateFrom"));
dateTField = new VDate("DateTo", false, false, true, DisplayType.Date, Msg.getMsg(Env.getCtx(), "DateTo"));
//
confirmPanel.addActionListener(this);
statusBar.setStatusLine("");
} // dynParameter
/**
* Dynamic Layout (Grid)
*/
private void dynInit()
{
m_staticQuery = new MQuery();
m_staticQuery.addRestriction("AD_Client_ID", MQuery.EQUAL, Env.getContextAsInt(Env.getCtx(), "#AD_Client_ID"));
MWindowVO wVO = AEnv.getMWindowVO (m_WindowNo, 223, 0);
if (wVO == null)
return;
m_mWindow = new MWindow (wVO);
m_mTab = m_mWindow.getTab(0);
//
m_gridController = new GridController();
m_gridController.initGrid(m_mTab, true, m_WindowNo, null);
mainPanel.add(m_gridController, BorderLayout.CENTER);
//
m_mTab.setQuery(MQuery.getEqualQuery("1", "2"));
m_mTab.query(false);
statusBar.setStatusLine(" ", false);
statusBar.setStatusDB(" ");
} // dynInit
/**
* Dispose
*/
public void dispose()
{
if (m_gridController != null)
m_gridController.dispose();
m_gridController = null;
m_mTab = null;
if (m_mWindow != null)
m_mWindow.dispose();
m_mWindow = null;
orgField = null;
locatorField = null;
productField = null;
mtypeField = null;
dateFField = null;
dateTField = null;
//
m_frame.dispose();
} // dispose
/*************************************************************************/
/**
* Action Listener
* @param e event
*/
public void actionPerformed (ActionEvent e)
{
if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
dispose();
else if (e.getActionCommand().equals(ConfirmPanel.A_REFRESH)
|| e.getActionCommand().equals(ConfirmPanel.A_OK))
refresh();
else if (e.getActionCommand().equals(ConfirmPanel.A_ZOOM))
zoom();
} // actionPerformed
/*************************************************************************/
/**
* Property Listener
* @param e event
*/
public void vetoableChange (PropertyChangeEvent e)
{
if (e.getPropertyName().equals("M_Product_ID"))
productField.setValue(e.getNewValue());
} // vetoableChange
/*************************************************************************/
/**
* Refresh - Create Query and refresh grid
*/
private void refresh()
{
/**
* Create Where Clause
*/
MQuery query = m_staticQuery.deepCopy();
// Organization
Object value = orgField.getValue();
if (value != null && value.toString().length() > 0)
query.addRestriction("AD_Org_ID", MQuery.EQUAL, value);
// Locator
value = locatorField.getValue();
if (value != null && value.toString().length() > 0)
query.addRestriction("M_Locator_ID", MQuery.EQUAL, value);
// Product
value = productField.getValue();
if (value != null && value.toString().length() > 0)
query.addRestriction("M_Product_ID", MQuery.EQUAL, value);
// MovementType
value = mtypeField.getValue();
if (value != null && value.toString().length() > 0)
query.addRestriction("MovementType", MQuery.EQUAL, value);
// DateFrom
Timestamp ts = (Timestamp)dateFField.getValue();
if (ts != null)
query.addRestriction("TRUNC(MovementDate)", MQuery.GREATER_EQUAL, ts);
// DateTO
ts = (Timestamp)dateTField.getValue();
if (ts != null)
query.addRestriction("TRUNC(MovementDate)", MQuery.LESS_EQUAL, ts);
Log.trace(Log.l1_User, "VTrxMaterial.refresh query=" + query.toString());
/**
* Refresh/Requery
*/
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "StartSearch"), false);
//
m_mTab.setQuery(query);
m_mTab.query(false);
//
setCursor(Cursor.getDefaultCursor());
int no = m_mTab.getRowCount();
statusBar.setStatusLine(" ", false);
statusBar.setStatusDB(Integer.toString(no));
} // refresh
/**
* Zoom
*/
private void zoom()
{
Log.trace(Log.l1_User, "VTrxMaterial.zoom");
//
int AD_Window_ID = 0;
String ColumnName = null;
String SQL = null;
boolean isSOTrx = false;
//
int lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_InOutLine_ID");
if (lineID != 0)
{
Log.trace(Log.l6_Database, "VTrxMaterial.zoom - M_InOutLine_ID=" + lineID);
if (Env.getContext(Env.getCtx(), m_WindowNo, "MovementType").startsWith("C"))
{
AD_Window_ID = 169; // Customer
isSOTrx = true;
}
else
{
AD_Window_ID = 184; // Vendor
isSOTrx = false;
}
ColumnName = "M_InOut_ID";
SQL = "SELECT M_InOut_ID FROM M_InOutLine WHERE M_InOutLine_ID=?";
}
else
{
lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_InventoryLine_ID");
if (lineID != 0)
{
Log.trace(Log.l6_Database, "VTrxMaterial.zoom - M_InventoryLine_ID=" + lineID);
AD_Window_ID = 168;
ColumnName = "M_Inventory_ID";
SQL = "SELECT M_Inventory_ID FROM M_InventoryLine WHERE M_InventoryLine_ID=?";
}
else
{
lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_MovementLine_ID");
if (lineID != 0)
{
Log.trace(Log.l6_Database, "VTrxMaterial.zoom - M_MovementLine_ID=" + lineID);
AD_Window_ID = 170;
ColumnName = "M_Movement_ID";
SQL = "SELECT M_Movement_ID FROM M_MovementLine WHERE M_MovementLine_ID=?";
}
else
{
lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_ProductionLine_ID");
if (lineID != 0)
{
Log.trace(Log.l6_Database, "VTrxMaterial.zoom - M_ProductionLine_ID=" + lineID);
AD_Window_ID = 191;
ColumnName = "M_Production_ID";
SQL = "SELECT M_Production_ID FROM M_ProductionLine WHERE M_ProductionLine_ID=?";
}
else
Log.trace(Log.l6_Database, "VTrxMaterial.zoom - not found WindowNo=" + m_WindowNo);
}
}
}
if (AD_Window_ID == 0)
return;
// Get Parent ID
int parentID = 0;
try
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setInt(1, lineID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
parentID = rs.getInt(1);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error ("VTrxMaterial.zoom - " + SQL, e);
}
MQuery query = MQuery.getEqualQuery(ColumnName, parentID);
Log.trace(Log.l2_Sub, "Zoom: AD_Window_ID=" + AD_Window_ID + " - " + query);
if (parentID == 0)
Log.error("VTrxMaterial.zoom - No ParentValue - " + SQL + " - " + lineID);
// Zoom
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
AWindow frame = new AWindow();
if (!frame.initWindow(AD_Window_ID, query, isSOTrx))
{
setCursor(Cursor.getDefaultCursor());
return;
}
AEnv.showCenterScreen(frame);
frame = null;
setCursor(Cursor.getDefaultCursor());
} // zoom
} // VTrxMaterial
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -