📄 impformat.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.impexp;
import java.util.*;
import java.sql.*;
import org.compiere.util.*;
/**
* Import Format a Row
*
* @author Jorg Janke
* @version $Id: ImpFormat.java,v 1.11 2003/01/20 05:39:20 jjanke Exp $
*/
public final class ImpFormat
{
/**
* Format
* @param name name
* @param AD_Table_ID table
* @param formatType format type
*/
public ImpFormat (String name, int AD_Table_ID, String formatType)
{
setName(name);
setTable(AD_Table_ID);
setFormatType(formatType);
} // ImpFormat
private String m_name;
private String m_formatType;
/** The Table to be imported */
private int m_AD_Table_ID;
private String m_tableName;
private String m_tablePK;
private String m_tableUnique1;
private String m_tableUnique2;
private String m_tableUniqueParent;
private String m_tableUniqueChild;
//
private String m_BPartner;
private ArrayList m_rows = new ArrayList();
/**
* Set Name
* @param newName new name
*/
public void setName(String newName)
{
if (newName == null || newName.length() == 0)
throw new IllegalArgumentException("Name must be at least 1 char");
else
m_name = newName;
}
/**
* Get Name
* @return name
*/
public String getName()
{
return m_name;
} // getName
/**
* Import Table
* @param AD_Table_ID table
*/
public void setTable (int AD_Table_ID)
{
m_AD_Table_ID = AD_Table_ID;
m_tableName = null;
m_tablePK = null;
String sql = "SELECT t.TableName,c.ColumnName "
+ "FROM AD_Table t INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID AND c.IsKey='Y') "
+ "WHERE t.AD_Table_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, AD_Table_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
m_tableName = rs.getString(1);
m_tablePK = rs.getString(2);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error("ImpFormat.setTable", e);
}
if (m_tableName == null || m_tablePK == null)
Log.error("ImpFormat.setTable - Data not forund for AD_Table_ID=" + AD_Table_ID);
// Set Additional Table Info
m_tableUnique1 = "";
m_tableUnique2 = "";
m_tableUniqueParent = "";
m_tableUniqueChild = "";
if (m_AD_Table_ID == 311) // I_061_SyncItem
{
m_tableUnique1 = "H_UPC"; // UPC = unique
m_tableUnique2 = "Value";
m_tableUniqueChild = "H_Commodity1"; // Vendor No may not be unique !
m_tableUniqueParent = "H_PartnrID"; // Makes it unique
}
else if (m_AD_Table_ID == 532) // I_Product
{
m_tableUnique1 = "UPC"; // UPC = unique
m_tableUnique2 = "Value";
m_tableUniqueChild = "VendorProductNo"; // Vendor No may not be unique !
m_tableUniqueParent = "BPartner_Value"; // Makes it unique
}
else if (m_AD_Table_ID == 533) // I_BPartner
{
m_tableUnique1 = "Value"; // the key
}
else if (m_AD_Table_ID == 534) // I_ElementValue
{
m_tableUniqueParent = "ElementName"; // the parent key
m_tableUniqueChild = "Value"; // the key
}
else if (m_AD_Table_ID == 535) // I_ReportLine
{
m_tableUniqueParent = "ReportLineSetName"; // the parent key
m_tableUniqueChild = "Name"; // the key
}
} // setTable
/**
* Get Import Table Name
* @return AD_Table_ID
*/
public int getAD_Table_ID()
{
return m_AD_Table_ID;
} // getAD_Table_ID
/**
* Format Type
*/
public static final String FORMATTYPE_FIXED = "F";
public static final String FORMATTYPE_COMMA = "C";
public static final String FORMATTYPE_TAB = "T";
public static final String FORMATTYPE_XML = "X";
/**
* Set Format Type
* @param newFormatType - F/C/T/X
*/
public void setFormatType(String newFormatType)
{
if (newFormatType.equals(FORMATTYPE_FIXED) || newFormatType.equals(FORMATTYPE_COMMA)
|| newFormatType.equals(FORMATTYPE_TAB) || newFormatType.equals(FORMATTYPE_XML))
m_formatType = newFormatType;
else
throw new IllegalArgumentException("FormatType must be F/C/T/X");
} // setFormatType
/**
* Set Format Type
* @return format type - F/C/T/X
*/
public String getFormatType()
{
return m_formatType;
} // getFormatType
/**
* Set Business Partner
* @param newBPartner (value)
*/
public void setBPartner(String newBPartner)
{
m_BPartner = newBPartner;
} // setBPartner
/**
* Get Business Partner
* @return BPartner (value)
*/
public String getBPartner()
{
return m_BPartner;
} // getVPartner
/*************************************************************************/
/**
* Add Format Row
* @param row row
*/
public void addRow (ImpFormatRow row)
{
m_rows.add (row);
} // addRow
/**
* Get Row
* @param index index
* @return Import Format Row
*/
public ImpFormatRow getRow (int index)
{
if (index >=0 && index < m_rows.size())
return (ImpFormatRow)m_rows.get(index);
return null;
} // getRow
/**
* Get Row Count
* @return row count
*/
public int getRowCount()
{
return m_rows.size();
} // getRowCount
/*************************************************************************/
/**
* Factory load
* @param name name
* @return Import Format
*/
public static ImpFormat load (String name)
{
Log.trace(Log.l3_Util, "ImpFormat.load - " + name);
ImpFormat retValue = null;
String SQL = "SELECT * FROM AD_ImpFormat WHERE Name=?";
int ID = 0;
try
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setString (1, name);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
retValue = new ImpFormat (name, rs.getInt("AD_Table_ID"), rs.getString("FormatType"));
ID = rs.getInt ("AD_ImpFormat_ID");
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error ("ImpFormat.load", e);
return null;
}
loadRows (retValue, ID);
return retValue;
} // getFormat
/**
* Load Format Rows with ID
* @param format format
* @param ID id
*/
private static void loadRows (ImpFormat format, int ID)
{
String SQL = "SELECT f.SeqNo,c.ColumnName,f.StartNo,f.EndNo,f.DataType,c.FieldLength," // 1..6
+ "f.DataFormat,f.DecimalPoint,f.DivideBy100,f.ConstantValue,f.Callout " // 7..11
+ "FROM AD_ImpFormat_Row f,AD_Column c "
+ "WHERE AD_ImpFormat_ID=? AND f.AD_Column_ID=c.AD_Column_ID "
+ "ORDER BY SeqNo";
try
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setInt (1, ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
ImpFormatRow row = new ImpFormatRow (rs.getInt(1),
rs.getString(2), rs.getInt(3), rs.getInt(4), rs.getString(5), rs.getInt(6));
//
row.setFormatInfo(rs.getString(7), rs.getString(8),
rs.getString(9).equals("Y"),
rs.getString(10), rs.getString(11));
//
format.addRow (row);
}
rs.close();
pstmt.close();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -