📄 infopattribute.java
字号:
list.add(new KeyNamePair(-1, ""));
String sql = MRole.getDefault().addAccessSQL(
"SELECT M_Lot_ID, Name FROM M_Lot WHERE IsActive='Y' ORDER BY 2",
"M_Lot", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql, null);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
list.add(new KeyNamePair(rs.getInt(1), rs.getString(2)));
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
// Create List
KeyNamePair[] items = new KeyNamePair[list.size()];
list.toArray(items);
lotSelection = new VComboBox(items);
} // initLotSelection
/**
* Action Listener
* @param e event
*/
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals(ConfirmPanel.A_OK))
{
createQuery();
dispose();
}
else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
{
m_query = null;
dispose();
}
} // actionPerformed
/**
* Create Query
* <code>
* Available synonyms:
* M_Product p
* M_ProductPrice pr
* M_AttributeSet pa
* </code>
* @return query
*/
private String createQuery()
{
/** Base Query
SELECT *
FROM M_Product p
INNER JOIN M_ProductPrice pr ON (p.M_Product_ID=pr.M_Product_ID)
LEFT OUTER JOIN M_AttributeSet pa ON (p.M_AttributeSet_ID=pa.M_AttributeSet_ID)
WHERE
**/
/*** Instance Attributes */
StringBuffer sb = new StringBuffer();
// Serial No
String s = serNoField.getText();
if (s != null && s.length() > 0)
{
sb.append(" AND asi.SerNo");
if (s.indexOf('%') == -1 && s.indexOf('_') == 1)
sb.append("=");
else
sb.append(" LIKE ");
sb.append(DB.TO_STRING(s));
}
// Lot Number
s = lotField.getText();
if (s != null && s.length() > 0)
{
sb.append(" AND asi.Lot");
if (s.indexOf('%') == -1 && s.indexOf('_') == 1)
sb.append("=");
else
sb.append(" LIKE ");
sb.append(DB.TO_STRING(s));
}
// Lot ID
KeyNamePair pp = (KeyNamePair)lotSelection.getSelectedItem();
if (pp != null && pp.getKey() != -1)
{
int ID = pp.getKey();
sb.append(" AND asi.M_Lot_ID=").append(ID);
}
// Guarantee Date
Timestamp ts = (Timestamp)guaranteeDateField.getValue();
if (ts != null)
{
sb.append(" AND TRUNC(asi.GuaranteeDate)");
int index = guaranteeDateSelection.getSelectedIndex(); // < = >
if (index == 0)
sb.append("<");
else if (index == 1)
sb.append("=");
else
sb.append(">");
sb.append(DB.TO_DATE(ts,true));
}
// Instance Editors
for (int i = 0; i < m_instanceEditors.size(); i++)
{
StringBuffer iAttr = new StringBuffer();
Component c = (Component)m_instanceEditors.get(i);
Component cTo = (Component)m_instanceEditorsTo.get(i);
int M_Attribute_ID = Integer.parseInt(c.getName());
if (c instanceof VComboBox)
{
VComboBox field = (VComboBox)c;
pp = (KeyNamePair)field.getSelectedItem();
if (pp != null && pp.getKey() != -1)
{
iAttr.append("M_Attribute_ID=").append(M_Attribute_ID)
.append(" AND M_AttributeValue_ID=").append(pp.getKey());
}
}
else if (c instanceof VNumber)
{
VNumber field = (VNumber)c;
BigDecimal value = (BigDecimal)field.getValue();
VNumber fieldTo = (VNumber)cTo;
BigDecimal valueTo = (BigDecimal)fieldTo.getValue();
if (value != null || valueTo != null)
{
iAttr.append("M_Attribute_ID=").append(M_Attribute_ID)
.append(" AND ValueNumber");
if (value != null && valueTo == null)
iAttr.append("=").append(value);
else if (value == null && valueTo != null)
iAttr.append("<=").append(valueTo);
else if (value != null && valueTo != null)
iAttr.append(" BETWEEN ").append(value)
.append(" AND ").append(valueTo);
}
}
else
{
VString field = (VString)c;
String value = field.getText();
if (value != null && value.length() > 0)
{
iAttr.append("M_Attribute_ID=").append(M_Attribute_ID)
.append(" AND Value");
if (value.indexOf('%') == -1 && value.indexOf('_') == -1)
iAttr.append("=");
else
iAttr.append(" LIKE ");
iAttr.append(DB.TO_STRING(value));
}
}
// Add to where
if (iAttr.length() > 0)
sb.append(" AND asi.M_AttributeSetInstance_ID IN "
+ "(SELECT M_AttributeSetInstance_ID FROM M_AttributeInstance "
+ "WHERE ")
.append(iAttr).append(")");
}
// finish Instance Attributes
if (sb.length() > 0)
{
sb.insert(0, " AND EXISTS (SELECT * FROM M_Storage s"
+ " INNER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID) "
+ "WHERE s.M_Product_ID=p.M_Product_ID");
sb.append(")");
}
// Product Attributes
for (int i = 0; i < m_productEditors.size(); i++)
{
StringBuffer pAttr = new StringBuffer();
Component c = (Component)m_productEditors.get(i);
Component cTo = (Component)m_productEditorsTo.get(i);
int M_Attribute_ID = Integer.parseInt(c.getName());
if (c instanceof VComboBox)
{
VComboBox field = (VComboBox)c;
pp = (KeyNamePair)field.getSelectedItem();
if (pp != null && pp.getKey() != -1)
{
pAttr.append("M_Attribute_ID=").append(M_Attribute_ID)
.append(" AND M_AttributeValue_ID=").append(pp.getKey());
}
}
else if (c instanceof VNumber)
{
VNumber field = (VNumber)c;
BigDecimal value = (BigDecimal)field.getValue();
VNumber fieldTo = (VNumber)cTo;
BigDecimal valueTo = (BigDecimal)fieldTo.getValue();
if (value != null || valueTo != null)
{
pAttr.append("M_Attribute_ID=").append(M_Attribute_ID)
.append(" AND ValueNumber");
if (value != null && valueTo == null)
pAttr.append("=").append(value);
else if (value == null && valueTo != null)
pAttr.append("<=").append(valueTo);
else if (value != null && valueTo != null)
pAttr.append(" BETWEEN ").append(value)
.append(" AND ").append(valueTo);
}
}
else
{
VString field = (VString)c;
String value = field.getText();
if (value != null && value.length() > 0)
{
pAttr.append("M_Attribute_ID=").append(M_Attribute_ID)
.append(" AND Value");
if (value.indexOf('%') == -1 && value.indexOf('_') == -1)
pAttr.append("=");
else
pAttr.append(" LIKE ");
pAttr.append(DB.TO_STRING(value));
}
}
// Add to Where
if (pAttr.length() > 0)
sb.append(" AND p.M_AttributeSetInstance_ID IN "
+ "(SELECT M_AttributeSetInstance_ID "
+ "FROM M_AttributeInstance WHERE ")
.append(pAttr).append(")");
}
//
m_query = null;
if (sb.length() > 0)
m_query = sb.toString();
log.config(m_query);
return m_query;
} // createQuery
/**
* Get resulting Query WHERE
* @return query or null
*/
public String getWhereClause()
{
return m_query;
} // getQuery
} // InfoPAttribute
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -