📄 mlocation.java
字号:
PostalAdd = rs.getString(8);
if (PostalAdd == null)
PostalAdd = "";
//
C_Location_ID = rs.getInt(9);
RegionName = rs.getString(10);
if (RegionName == null)
RegionName = "";
//
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.error("loadBPLocation - " + C_BPartner_Location_ID, e);
C_Location_ID = 0;
return false;
}
mCountry = (MCountry)s_countries.get (String.valueOf(C_Country_ID));
mRegion = (MRegion)s_regions.get (String.valueOf(C_Region_ID));
return true;
} // loadBPLocation
/**
* Save to database
* @return C_Location_ID
*/
public int save()
{
log.debug("save " + Address1 + ", " + City + ", " + C_Region_ID + "; " + C_Country_ID);
// Size check
if (Address1.length() > 60)
Address1 = Address1.substring(0,59);
if (Address2.length() > 60)
Address2 = Address2.substring(0,59);
if (City.length() > 60)
City = City.substring(0,59);
if (Postal.length() > 10)
Postal = Postal.substring(0,9);
if (PostalAdd.length() > 10)
PostalAdd = PostalAdd.substring(0,9);
String sql = "";
if (C_Location_ID == 0)
{
sql = "INSERT INTO C_Location "
+ "(Updated,UpdatedBy," // 1..2
+ "Address1,Address2,City," // 3..5
+ "C_Country_ID,C_Region_ID," // 6..7
+ "Postal,Postal_Add,RegionName," // 8..10
+ "AD_Client_ID,AD_Org_ID,IsActive," // 11..12
+ "C_Location_ID,Created,CreatedBy) " // 13..15
+ "VALUES(?,?, ?,?,?, ?,?, ?,?,?, ?,?,'Y', ?,?,?)";
}
else
{
sql = "UPDATE C_Location SET "
+ "Updated=?,UpdatedBy=?," // 1..2
+ "ADDRESS1=?,ADDRESS2=?,CITY=?," // 3..5
+ "C_COUNTRY_ID=?,C_REGION_ID=?," // 6..7
+ "POSTAL=?,POSTAL_ADD=?,RegionName=?" // 8..10
+ " WHERE C_Location_ID=" + C_Location_ID;
}
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
// fill variables 1-10
java.sql.Date date = new java.sql.Date(System.currentTimeMillis());
pstmt.setDate(1, date);
int user = Env.getContextAsInt(m_ctx, "#AD_User_ID");
pstmt.setInt(2, user);
//
pstmt.setString(3, Address1);
pstmt.setString(4, Address2);
pstmt.setString(5, City);
//
pstmt.setInt(6, C_Country_ID);
if (mCountry.HasRegion && C_Region_ID != 0)
pstmt.setInt(7, C_Region_ID);
else
pstmt.setNull(7, Types.INTEGER);
//
pstmt.setString(8, Postal);
pstmt.setString(9, PostalAdd);
pstmt.setString(10, RegionName);
// if new, get addl info
if (C_Location_ID == 0)
{
// fill variables 11-15
int AD_Client_ID = Env.getContextAsInt(m_ctx, m_WindowNo, "AD_Client_ID");
pstmt.setInt(11, AD_Client_ID);
pstmt.setInt(12, Env.getContextAsInt(m_ctx, m_WindowNo, "AD_Org_ID"));
// get new ID
C_Location_ID = DB.getKeyNextNo(m_ctx, AD_Client_ID, "C_Location");
pstmt.setInt(13, C_Location_ID);
//
pstmt.setDate(14, date);
pstmt.setInt(15, user);
}
int no = pstmt.executeUpdate();
if (no != 1)
{
log.error("save - No record updated/inserted");
return 0;
}
}
catch (SQLException e)
{
log.error("save - " + sql, e);
C_Location_ID = 0;
return 0;
}
//
log.debug("save - C_Location_ID=" + C_Location_ID);
return C_Location_ID;
} // save
/**
* Parse according Ctiy/Postal/Region according to displaySequence.
* @C@ - City @R@ - Region @P@ - Postal @A@ - PostalAdd
* @param c country
* @return parsed String
*/
private String parseCRP (MCountry c)
{
if (c == null)
return "CountryNotFound";
String token;
String inStr = c.DisplaySequence;
StringBuffer outStr = new StringBuffer();
int i = inStr.indexOf("@");
while (i != -1)
{
outStr.append (inStr.substring(0, i)); // up to @
inStr = inStr.substring(i+1, inStr.length()); // from first @
int j = inStr.indexOf("@"); // next @
if (j < 0)
{
token = ""; // no second tag
j = i+1;
}
else
token = inStr.substring(0, j);
//
if (token.equals("C"))
{
outStr.append(City);
}
else if (token.equals("R"))
{
MRegion r = (MRegion)s_regions.get(String.valueOf(C_Region_ID));
if (r != null)
outStr.append(r.Name);
else if (RegionName != null && RegionName.length() > 0)
outStr.append(RegionName);
}
else if (token.equals("P"))
{
outStr.append(Postal);
}
else if (token.equals("A"))
{
if (PostalAdd != null && PostalAdd.length() > 0)
outStr.append("-").append(PostalAdd);
}
else
outStr.append("@").append(token).append("@");
inStr = inStr.substring(j+1, inStr.length()); // from second @
i = inStr.indexOf("@");
}
outStr.append(inStr); // add the rest of the string
// Print Region Name if entered and not part of pattern
if (RegionName != null && RegionName.length() > 0 && c.DisplaySequence.indexOf("@R@") == -1)
outStr.append(" ").append(RegionName);
return outStr.toString();
} // parseContext
/**
* Load Countries and Regions
* @param ctx context
*/
private static void loadCountries(Properties ctx)
{
MCountry tableDefault = null;
MCountry preferenceDefault = null;
// Get Country Preference
int pC_Country_ID = 0;
String s = Env.getPreference(ctx, 0, "C_Country_ID", false);
if (s.length() > 0)
pC_Country_ID = Integer.parseInt(s);
//
String SQL = "SELECT * FROM C_Country WHERE IsActive='Y'";
try
{
Statement stmt = DB.createStatement();
ResultSet rs = stmt.executeQuery(SQL);
while(rs.next())
{
MCountry c = new MCountry (rs);
s_countries.put(String.valueOf(c.C_Country_ID), c);
if (rs.getString("IsDefault").equals("Y"))
tableDefault = c;
if (c.C_Country_ID == pC_Country_ID)
preferenceDefault = c;
}
rs.close();
stmt.close();
}
catch (SQLException e)
{
s_log.error("loadCountries - Countries", e);
}
// Default Country
s_mCountry = preferenceDefault;
if (s_mCountry == null)
s_mCountry = tableDefault;
if (s_mCountry == null) // Still no default
s_mCountry = (MCountry)s_countries.get("100"); // US
s_log.debug("loadCountries - Countries #=" + s_countries.size()
+ " - Default="+s_mCountry.Name);
// Regions
int pC_Region_ID = 0;
s = Env.getPreference(ctx, 0, "C_Region_ID", false);
if (s.length() > 0)
pC_Region_ID = Integer.parseInt(s);
SQL = "SELECT * FROM C_Region ORDER BY Name";
try
{
Statement stmt = DB.createStatement();
ResultSet rs = stmt.executeQuery(SQL);
while(rs.next())
{
MRegion r = new MRegion(rs);
s_regions.put(String.valueOf(r.C_Region_ID), r);
if (r.C_Region_ID == pC_Region_ID)
s_mRegion = r;
}
rs.close();
stmt.close();
}
catch (SQLException e)
{
s_log.error("loadCountries - Regions", e);
}
s_log.debug("loadCountries - Regions #=" + s_countries.size());
} // load countries
/**
* Return Countries as Array
* @return MCountry Array
*/
public static MCountry[] getCountries()
{
MCountry[] retValue = new MCountry[s_countries.size()];
s_countries.values().toArray(retValue);
Arrays.sort(retValue, new MCountry());
return retValue;
} // getCountries
/**
* Return Array of all Regions
* @return MRegion Array
*/
protected MRegion[] getRegions()
{
MRegion[] retValue = new MRegion[s_regions.size()];
s_regions.values().toArray(retValue);
Arrays.sort(retValue, new MRegion());
return retValue;
} // getRegions
/**
* Return Array of Regions of Country
* @param C_Country_ID country
* @return MRegion Array
*/
public static MRegion[] getRegions (int C_Country_ID)
{
ArrayList list = new ArrayList();
Iterator it = s_regions.values().iterator();
while (it.hasNext())
{
MRegion r = (MRegion)it.next();
if (r.C_Country_ID == C_Country_ID)
list.add(r);
}
// Sort it
MRegion[] retValue = new MRegion[list.size()];
list.toArray(retValue);
Arrays.sort(retValue, new MRegion());
return retValue;
} // getRegions
/**
* Get underlying fully qualified Table.Column Name
* @return ""
*/
public String getColumnName()
{
return "";
} // getColumnName
/**
* Return data as sorted Array - not implemented
* @param mandatory mandatory
* @param onlyValidated only validated
* @param onlyActive only active
* @return null
*/
public ArrayList getData (boolean mandatory, boolean onlyValidated, boolean onlyActive)
{
log.error("getData - not implemented");
return null;
} // getArray
/*************************************************************************/
/**
* Get Region Name
* @return region Name or ""
*/
public String getRegionName()
{
if (C_Region_ID == 0)
return RegionName;
MRegion r = (MRegion)s_regions.get (String.valueOf(C_Region_ID));
if (r != null)
return r.Name;
return RegionName;
} // getRegionName
/**
* Set Region Name
* @param region region
*/
public void setRegionName(String region)
{
RegionName = region;
if (RegionName == null)
RegionName = "";
} // setRegionName
/**
* Get Country Name
* @return Country Name or ""
*/
public String getCountryName()
{
if (C_Country_ID == 0)
return "";
MCountry c = (MCountry)s_countries.get (String.valueOf(C_Country_ID));
if (c != null)
return c.Name;
return "";
} // getCountryName
/**
* Set Country Name - NOP
* @param country country
*/
public void setCountryName(String country)
{
} // setCountryName
} // MLocation
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -