📄 mtab.java
字号:
* @return true if single row
*/
public boolean isSingleRow()
{
return m_vo.IsSingleRow;
} // isSingleRow;
/**
* Set Single Row.
* Temporary store of current value
* @param isSingleRow toggle
*/
public void setSingleRow (boolean isSingleRow)
{
m_vo.IsSingleRow = isSingleRow;
} // setSingleRow
/**
* Has Tree
* @return true if tree exists
*/
public boolean isTreeTab()
{
return m_vo.HasTree;
} // isTreeTab
/**
* Get Table ID
* @return Table ID
*/
public int getAD_Table_ID()
{
return m_vo.AD_Table_ID;
} // getAD_Table_ID
/**
* Get TableName
* @return Table Name
*/
public String getTableName()
{
return m_vo.TableName;
} // getTableName
/**
* Get Tab Where Clause
* @return where clause
*/
public String getWhereClause()
{
return m_vo.WhereClause;
} // getWhereClause
/**
* Is Sort Tab
* @return true if sort tab
*/
public boolean isSortTab()
{
return m_vo.IsSortTab;
} // isSortTab
/**
* Get Order column for sort tab
* @return AD_Column_ID
*/
public int getAD_ColumnSortOrder_ID()
{
return m_vo.AD_ColumnSortOrder_ID;
} // getAD_ColumnSortOrder_ID
/**
* Get Yes/No column for sort tab
* @return AD_Column_ID
*/
public int getAD_ColumnSortYesNo_ID()
{
return m_vo.AD_ColumnSortYesNo_ID;
} // getAD_ColumnSortYesNo_ID
/*************************************************************************/
/**
* Get extended Where Clause (parent link)
* @return parent link
*/
public String getWhereExtended()
{
return m_extendedWhere;
} // getWhereExtended
/**
* Get Order By Clause
* @param onlyCurrentRows only current rows
* @return Order By Clause
*/
private String getOrderByClause(boolean onlyCurrentRows)
{
// If there is no Tab Order By - use info from Fields
if (m_vo.OrderByClause.length() == 0 && m_OrderBys[0] != null)
{
m_vo.OrderByClause = m_OrderBys[0];
if (onlyCurrentRows && !isDetail()) // transaction order descending
m_vo.OrderByClause += " DESC";
if (m_OrderBys[1] != null)
m_vo.OrderByClause += "," + m_OrderBys[1];
}
return m_vo.OrderByClause;
} // getOrderByClause
/*************************************************************************/
/**
* Transaction support.
* Depending on Table returns transaction info
* @return info
*/
public String getTrxInfo()
{
// Order || Invoice
if (m_vo.TableName.startsWith("C_Order") || m_vo.TableName.startsWith("C_Invoice"))
{
int Record_ID;
boolean isOrder = m_vo.TableName.startsWith("C_Order");
//
StringBuffer sql = new StringBuffer("SELECT COUNT(*) AS Lines,c.ISO_Code,o.TotalLines,o.GrandTotal,"
+ "C_Base_Convert(o.GrandTotal,o.C_Currency_ID,o.AD_Client_ID,SysDate,o.AD_Org_ID) AS ConvAmt ");
if (isOrder)
{
Record_ID = Env.getContextAsInt(m_vo.ctx, m_vo.WindowNo, "C_Order_ID");
sql.append("FROM C_Order o, C_Currency c, C_OrderLine l "
+ "WHERE o.C_Currency_ID=c.C_Currency_ID"
+ " AND o.C_Order_ID=?"
+ " AND o.C_Order_ID=l.C_Order_ID ");
}
else
{
Record_ID = Env.getContextAsInt(m_vo.ctx, m_vo.WindowNo, "C_Invoice_ID");
sql.append("FROM C_Invoice o, C_Currency c, C_InvoiceLine l "
+ "WHERE o.C_Currency_ID=c.C_Currency_ID"
+ " AND o.C_Invoice_ID=?"
+ " AND o.C_Invoice_ID=l.C_Invoice_ID ");
}
sql.append("GROUP BY o.C_Currency_ID, c.ISO_Code, o.TotalLines, o.GrandTotal, o.AD_Client_ID, o.AD_Org_ID");
Log.trace(Log.l3_Util, "MTab.getTrxInfo " + m_vo.TableName + " - " + Record_ID);
MessageFormat mf = null;
try
{
mf = new MessageFormat(Msg.getMsg(Env.getAD_Language(m_vo.ctx), "OrderSummary"));
}
catch (Exception e)
{
Log.error("MTab.getTrxInfo - OrderSummary=" + Msg.getMsg(Env.getAD_Language(m_vo.ctx), "OrderSummary"), e);
}
if (mf == null)
return " ";
/**********************************************************************
* ** Message: OrderSummary **
* {0} Line(s) - {1,number,#,##0.00} - Toral: {2,number,#,##0.00} {3} = {4,number,#,##0.00}
*
* {0} - Number of lines
* {1} - Line toral
* {2} - Grand total (including tax, etc.)
* {3} - Currency
* (4) - Grand total converted to local currency
*/
Object[] arguments = new Object[5];
boolean filled = false;
//
try
{
PreparedStatement pstmt = DB.prepareStatement(sql.toString());
pstmt.setInt(1, Record_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
// {0} - Number of lines
Integer lines = new Integer(rs.getInt(1));
arguments[0] = lines;
// {1} - Line toral
Double lineTotal = new Double(rs.getDouble(3));
arguments[1] = lineTotal;
// {2} - Grand total (including tax, etc.)
Double grandTotal = new Double(rs.getDouble(4));
arguments[2] = grandTotal;
// {3} - Currency
String currency = rs.getString(2);
arguments[3] = currency;
// (4) - Grand total converted to Euro
Double grandEuro = new Double(rs.getDouble(5));
arguments[4] = grandEuro;
filled = true;
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error("MTab.getTrxInfo " + m_vo.TableName + "\nSQL=" + sql, e);
}
if (filled)
return mf.format (arguments);
return " ";
} // Order || Invoice
// Expense Report
else if (m_vo.TableName.startsWith("S_TimeExpense") && m_vo.TabNo == 0)
{
int Record_ID = Env.getContextAsInt(m_vo.ctx, m_vo.WindowNo, "S_TimeExpense_ID");
Log.trace(Log.l3_Util, "MTab.getTrxInfo " + m_vo.TableName + " - " + Record_ID);
MessageFormat mf = null;
try
{
mf = new MessageFormat(Msg.getMsg(Env.getAD_Language(m_vo.ctx), "ExpenseSummary"));
}
catch (Exception e)
{
Log.error("MTab.getTrxInfo - ExpenseSummary=" + Msg.getMsg(Env.getAD_Language(m_vo.ctx), "ExpenseSummary"), e);
}
if (mf == null)
return " ";
/**********************************************************************
* ** Message: ExpenseSummary **
* {0} Line(s) - Total: {1,number,#,##0.00} {2}
*
* {0} - Number of lines
* {1} - Toral
* {2} - Currency
*/
Object[] arguments = new Object[3];
boolean filled = false;
//
String SQL = "SELECT COUNT(*) AS Lines, SUM(ConvertedAmt*Qty) "
+ "FROM S_TimeExpenseLine "
+ "WHERE S_TimeExpense_ID=?";
//
try
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setInt(1, Record_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
// {0} - Number of lines
Integer lines = new Integer(rs.getInt(1));
arguments[0] = lines;
// {1} - Line toral
Double total = new Double(rs.getDouble(2));
arguments[1] = total;
// {3} - Currency
arguments[2] = " ";
filled = true;
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error("MTab.getTrxInfo " + m_vo.TableName + "\nSQL=" + SQL, e);
}
if (filled)
return mf.format (arguments);
return " ";
} // S_TimeExpense
// Default - No Trx Info
return null;
} // getTrxInfo
/**
* Load Dependant Information
*/
private void loadDependentInfo()
{
/**
* Load Order Type from C_DocTypeTarget_ID
*/
if (m_vo.TableName.equals("C_Order"))
{
int C_DocTyp_ID = 0;
Integer target = (Integer)getValue("C_DocTypeTarget_ID");
if (target != null)
C_DocTyp_ID = target.intValue();
if (C_DocTyp_ID == 0)
return;
String sql = "SELECT DocSubTypeSO FROM C_DocType WHERE C_DocType_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, C_DocTyp_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
Env.setContext(m_vo.ctx, m_vo.WindowNo, "OrderType", rs.getString(1));
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error("MTab.loadOrderType", e);
}
} // loadOrderInfo
} // loadDependentInfo
/*************************************************************************/
/**
* Load Attachments for this table
*/
public void loadAttachments()
{
Log.trace(Log.l3_Util, "MTab.loadAttachments #" + m_vo.TabNo);
if (!canHaveAttachment())
return;
String SQL = "SELECT AD_Attachment_ID, Record_ID FROM AD_Attachment "
+ "WHERE AD_Table_ID=?";
try
{
if (m_Attachment == null)
m_Attachment = new HashMap();
else
m_Attachment.clear();
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setInt(1, m_vo.AD_Table_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
Integer key = new Integer(rs.getInt(2));
Integer value = new Integer(rs.getInt(1));
m_Attachment.put(key, value);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error("MTab.loadAttachments", e);
}
Log.trace(Log.l4_Data, "Attachments=" + m_Attachment.size());
} // loadAttachment
/**
* Can this tab have Attachments?.
* <p>
* It can have an attachment if it has a key column ending with _ID.
* The key column is empty, if there is no single identifying key.
* @return true if record can have attachment
*/
public boolean canHaveAttachment()
{
if (getKeyColumnName().endsWith("_ID"))
return true;
return false;
} // canHaveAttachment
/**
* Returns true, if current row has an Attachment
* @return true if record has attchment
*/
public boolean hasAttachment()
{
if (m_Attachment == null)
loadAttachments();
if (m_Attachment == null || m_Attachment.isEmpty())
return false;
//
Integer key = new Integer(m_mTable.getKeyID (m_currentRow));
return m_Attachment.containsKey(key);
} // hasAttachment
/**
* Get Attachment_ID.
* @return ID or 0, if not found
*/
public int getAD_AttachmentID()
{
if (m_Attachment == null)
loadAttachments();
if (m_Attachment.isEmpty())
return 0;
//
Integer key = new Integer(m_mTable.getKeyID (m_currentRow));
Integer value = (Integer)m_Attachment.get(key);
if (value == null)
return 0;
else
return value.intValue();
} // getAttachmentID
/*************************************************************************/
/**
* Data Status Listener from MTable.
* - get raw info and add current row information
* - update the current row
* - redistribute (fire) Data Status event
* @param e event
*/
public void dataStatusChanged (DataStatusEvent e)
{
Log.trace(Log.l3_Util, "MTab.dataStatusChanged #" + m_vo.TabNo, e.toString());
int oldCurrentRow = e.getCurrentRow();
m_DataStatusEvent = e; // save it
// when sorted set current row to 0
String msg = m_DataStatusEvent.getAD_Message();
if (msg != null && msg.equals("Sorted"))
setCurrentRow(0, true);
// set current row
m_DataStatusEvent.setCurrentRow(m_currentRow);
// Same row - update value
if (oldCurrentRow == m_currentRow)
{
MField field = m_mTable.getField(e.getChangedColumn());
Object value = m_mTable.getValueAt(m_currentRow, e.getChangedColumn());
field.setValue(value, m_mTable.isInserting());
}
else // Redistribute Info with current row info
fireDataStatusChanged(m_DataStatusEvent);
// Log.trace(Log.l3_Util, "MTab.dataStatusChanged #" + m_vo.TabNo + "- fini", e.toString());
} // dataStatusChanged
/**
* Inform Listeners and build WHO info
* @param e event
*/
private void fireDataStatusChanged (DataStatusEvent e)
{
Log.trace(Log.l4_Data, "MTab.fireDataStatusChanged", e.toString());
if (m_dataStatusListeners != null)
{
// WHO Info
if (e.getCurrentRow() >= 0)
{
e.Created = (Timestamp)getValue("Created");
e.CreatedBy = getValue("CreatedBy");
e.Updated = (Timestamp)getValue("Updated");
e.UpdatedBy = getValue("UpdatedBy");
// Info
StringBuffer info = new StringBuffer(getTableName());
// We have a key column
if (m_keyColumnName != null && m_keyColumnName.length() > 0)
{
info.append(" - ")
.append(m_keyColumnName).append("=").append(getValue(m_keyColumnName));
}
else // we have multiple parents
{
for (int i = 0; i < m_parents.size(); i++)
{
String keyCol = (String)m_parents.get(i);
info.append(" - ")
.append(keyCol).append("=").append(getValue(keyCol));
}
}
e.Info = info.toString();
}
e.setInserting(m_mTable.isInserting());
// Distribute/fire it
Vector listeners = m_dataStatusListeners;
int count = listeners.size();
for (int i = 0; i < count; i++)
((DataStatusListener) listeners.elementAt(i)).dataStatusChanged(e);
}
// Log.trace(Log.l4_Data, "MTab.fireDataStatusChanged - fini", e.toString());
} // fireDataStatusChanged
/**
* Create and fire Data Status Error Event
* @param AD_Message message
* @param info info
*/
protected void fireDataStatusEEvent(String AD_Message, String info)
{
m_mTable.fireDataStatusEEvent(AD_Message, info);
} // fireDataStatusEvent
/**
* Create and fire Data Status Error Event (from Error Log)
* @param errorLog log
*/
protected void fireDataStatusEEvent (ValueNamePair errorLog)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -