📄 mattributesetinstance.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 Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.text.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Product Attribute Set Instance
*
* @author Jorg Janke
* @version $Id: MAttributeSetInstance.java,v 1.20 2005/12/17 19:55:33 jjanke Exp $
*/
public class MAttributeSetInstance extends X_M_AttributeSetInstance
{
/**
* Get Attribute Set Instance from ID or Product
* @param ctx context
* @param M_AttributeSetInstance_ID id or 0
* @param M_Product_ID required if id is 0
* @return Attribute Set Instance or null
*/
public static MAttributeSetInstance get (Properties ctx,
int M_AttributeSetInstance_ID, int M_Product_ID)
{
MAttributeSetInstance retValue = null;
// Load Instance if not 0
if (M_AttributeSetInstance_ID != 0)
{
s_log.fine("From M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID);
return new MAttributeSetInstance (ctx, M_AttributeSetInstance_ID, null);
}
// Get new from Product
s_log.fine("From M_Product_ID=" + M_Product_ID);
if (M_Product_ID == 0)
return null;
String sql = "SELECT M_AttributeSet_ID, M_AttributeSetInstance_ID "
+ "FROM M_Product "
+ "WHERE M_Product_ID=?";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, M_Product_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
int M_AttributeSet_ID = rs.getInt(1);
// M_AttributeSetInstance_ID = rs.getInt(2); // needed ?
//
retValue = new MAttributeSetInstance (ctx, 0, M_AttributeSet_ID, null);
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (SQLException ex)
{
s_log.log(Level.SEVERE, sql, ex);
}
try
{
if (pstmt != null)
pstmt.close();
}
catch (SQLException ex1)
{
}
pstmt = null;
//
return retValue;
} // get
private static CLogger s_log = CLogger.getCLogger (MAttributeSetInstance.class);
/**************************************************************************
* Standard Constructor
* @param ctx context
* @param M_AttributeSetInstance_ID id
*/
public MAttributeSetInstance (Properties ctx, int M_AttributeSetInstance_ID, String trxName)
{
super (ctx, M_AttributeSetInstance_ID, trxName);
if (M_AttributeSetInstance_ID == 0)
{
}
} // MAttributeSetInstance
/**
* Load Constructor
* @param ctx context
* @param rs result set
*/
public MAttributeSetInstance (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MAttributeSetInstance
/**
* Standard Constructor
* @param ctx context
* @param M_AttributeSetInstance_ID id
* @param M_AttributeSet_ID attribute set
*/
public MAttributeSetInstance (Properties ctx, int M_AttributeSetInstance_ID, int M_AttributeSet_ID, String trxName)
{
this (ctx, M_AttributeSetInstance_ID, trxName);
setM_AttributeSet_ID(M_AttributeSet_ID);
} // MAttributeSetInstance
/** Attribute Set */
private MAttributeSet m_mas = null;
/** Date Format */
private DateFormat m_dateFormat = DisplayType.getDateFormat(DisplayType.Date);
/**
* Set Attribute Set
* @param mas attribute set
*/
public void setMAttributeSet (MAttributeSet mas)
{
m_mas = mas;
setM_AttributeSet_ID(mas.getM_AttributeSet_ID());
} // setAttributeSet
/**
* Get Attribute Set
* @return Attrbute Set or null
*/
public MAttributeSet getMAttributeSet()
{
if (m_mas == null && getM_AttributeSet_ID() != 0)
m_mas = new MAttributeSet (getCtx(), getM_AttributeSet_ID(), get_TrxName());
return m_mas;
} // getMAttributeSet
/**
* Set Description.
* - Product Values
* - Instance Values
* - SerNo = #123
* - Lot = \u00ab123\u00bb
* - GuaranteeDate = 10/25/2003
*/
public void setDescription()
{
// Make sure we have a Attribute Set
getMAttributeSet();
if (m_mas == null)
{
setDescription ("");
return;
}
StringBuffer sb = new StringBuffer();
// Instance Attribute Values
MAttribute[] attributes = m_mas.getMAttributes(true);
for (int i = 0; i < attributes.length; i++)
{
MAttributeInstance mai = attributes[i].getMAttributeInstance(getM_AttributeSetInstance_ID());
if (mai != null && mai.getValue() != null)
{
if (sb.length() > 0)
sb.append("_");
sb.append(mai.getValue());
}
}
// SerNo
if (m_mas.isSerNo() && getSerNo() != null)
{
if (sb.length() > 0)
sb.append("_");
sb.append(m_mas.getSerNoCharStart()).append(getSerNo()).append(m_mas.getSerNoCharEnd());
}
// Lot
if (m_mas.isLot() && getLot() != null)
{
if (sb.length() > 0)
sb.append("_");
sb.append(m_mas.getLotCharStart()).append(getLot()).append(m_mas.getLotCharEnd());
}
// GuaranteeDate
if (m_mas.isGuaranteeDate() && getGuaranteeDate() != null)
{
if (sb.length() > 0)
sb.append("_");
sb.append (m_dateFormat.format(getGuaranteeDate()));
}
// Product Attribute Values
attributes = m_mas.getMAttributes(false);
for (int i = 0; i < attributes.length; i++)
{
MAttributeInstance mai = attributes[i].getMAttributeInstance(getM_AttributeSetInstance_ID());
if (mai != null && mai.getValue() != null)
{
if (sb.length() > 0)
sb.append("_");
sb.append(mai.getValue());
}
}
setDescription (sb.toString());
} // setDescription
/**
* Get Guarantee Date
* @param getNew if true calculates/sets guarantee date
* @return guarantee date or null if days = 0
*/
public Timestamp getGuaranteeDate(boolean getNew)
{
if (getNew)
{
int days = getMAttributeSet().getGuaranteeDays();
if (days > 0)
{
Timestamp ts = TimeUtil.addDays(new Timestamp(System.currentTimeMillis()), days);
setGuaranteeDate(ts);
}
}
return getGuaranteeDate();
} // getGuaranteeDate
/**
* Get Lot No
* @param getNew if true create/set new lot
* @param M_Product_ID product used if new
* @return lot
*/
public String getLot (boolean getNew, int M_Product_ID)
{
if (getNew)
createLot(M_Product_ID);
return getLot();
} // getLot
/**
* Create Lot
* @param M_Product_ID product used if new
* @return lot info
*/
public KeyNamePair createLot (int M_Product_ID)
{
KeyNamePair retValue = null;
int M_LotCtl_ID = getMAttributeSet().getM_LotCtl_ID();
if (M_LotCtl_ID != 0)
{
MLotCtl ctl = new MLotCtl (getCtx(), M_LotCtl_ID, null);
MLot lot = ctl.createLot(M_Product_ID);
setM_Lot_ID (lot.getM_Lot_ID());
setLot (lot.getName());
retValue = new KeyNamePair (lot.getM_Lot_ID(), lot.getName());
}
return retValue;
} // createLot
/**
* To to find lot and set Lot/ID
* @param Lot lot
* @param M_Product_ID product
*/
public void setLot (String Lot, int M_Product_ID)
{
// Try to find it
MLot mLot = MLot.getProductLot(getCtx(), M_Product_ID, Lot, get_TrxName());
if (mLot != null)
setM_Lot_ID(mLot.getM_Lot_ID());
setLot (Lot);
} // setLot
/**
* Exclude Lot creation
* @param AD_Column_ID column
* @param isSOTrx SO
* @return true if excluded
*/
public boolean isExcludeLot (int AD_Column_ID, boolean isSOTrx)
{
getMAttributeSet();
if (m_mas != null)
return m_mas.isExcludeLot (AD_Column_ID, isSOTrx);
return false;
} // isExcludeLot
/**
* Get Serial No
* @param getNew if true create/set new Ser No
* @return Serial Number
*/
public String getSerNo (boolean getNew)
{
if (getNew)
{
int M_SerNoCtl_ID = getMAttributeSet().getM_SerNoCtl_ID();
if (M_SerNoCtl_ID != 0)
{
MSerNoCtl ctl = new MSerNoCtl (getCtx(), M_SerNoCtl_ID, get_TrxName());
setSerNo(ctl.createSerNo());
}
}
return getSerNo();
} // getSerNo
/**
* Exclude SerNo creation
* @param AD_Column_ID column
* @param isSOTrx SO
* @return true if excluded
*/
public boolean isExcludeSerNo (int AD_Column_ID, boolean isSOTrx)
{
getMAttributeSet();
if (m_mas != null)
return m_mas.isExcludeSerNo (AD_Column_ID, isSOTrx);
return false;
} // isExcludeSerNo
} // MAttributeSetInstance
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -