📄 mregion.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.model;
import java.util.*;
import java.sql.*;
import java.io.Serializable;
import org.compiere.util.*;
/**
* Localtion Region Model (Value Object)
*
* @author Jorg Janke
* @version $Id: MRegion.java,v 1.2 2003/03/10 05:37:53 jjanke Exp $
*/
public final class MRegion
implements Comparator, Serializable
{
/**
* Create empty Region
*/
public MRegion ()
{
} // MRegion
/**
* Create Region from current row in ResultSet
* @param rs result set
*/
public MRegion (ResultSet rs)
{
if (rs == null)
return;
try
{
AD_Client_ID = rs.getInt("AD_Client_ID");
AD_Org_ID = rs.getInt("AD_Org_ID");
//
C_Region_ID = rs.getInt("C_Region_ID");
C_Country_ID = rs.getInt("C_Country_ID");
Name = rs.getString("Name");
if (Name == null)
Name = "";
Description = rs.getString("Description");
if (Description == null)
Description = "";
}
catch (SQLException e)
{
Log.error("MRegion", e);
C_Region_ID = 0;
}
} // MRegion
public int AD_Client_ID = 0;
public int AD_Org_ID = 0;
public int C_Country_ID = 0;
public int C_Region_ID = 0;
public String Name = "";
public String Description = "";
/**
* Return Name
* @return Name
*/
public String toString()
{
return Name;
} // toString
/**
* Compare
* @param o1 object 1
* @param o2 object 2
* @return -1,0, 1
*/
public int compare(Object o1, Object o2)
{
String s1 = o1.toString();
if (s1 == null)
s1 = "";
String s2 = o2.toString();
if (s2 == null)
s2 = "";
return s1.compareTo(s2);
} // compare
/**
* Save Region
* @param ctx properties
* @return true if saved
*/
public boolean save (Properties ctx)
{
String sql = "";
// new
if (C_Region_ID == 0)
{
sql = "INSERT INTO C_Region "
+ "(Updated,UpdatedBy," // 1..2
+ "Name,Description," // 3..4
+ "C_Country_ID,C_Region_ID," // 5..6
+ "AD_Client_ID,AD_Org_ID,IsActive,"// 7..8
+ "Created,CreatedBy) " // 9..10
+ "VALUES(?,?, ?,?, ?,?, ?,?,'Y', ?,?)";
}
else
{
sql = "UPDATE C_Location SET "
+ "Updated=?,UpdatedBy=?,"
+ "Name=?,Description=?,"
+ "C_COUNTRY_ID=? "
+ "WHERE C_Region_ID=?";
}
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
// fill variables
java.sql.Date date = new java.sql.Date(System.currentTimeMillis());
pstmt.setDate(1, date);
int user = Env.getContextAsInt(ctx, "#AD_User_ID");
pstmt.setInt(2, user);
//
pstmt.setString(3, Name);
pstmt.setString(4, Description);
//
pstmt.setInt(5, C_Country_ID);
// if new, get addl info
if (C_Region_ID == 0)
{
// get new ID
int AD_Client_ID = Env.getContextAsInt(ctx, 0, "AD_Client_ID");
C_Region_ID = DB.getKeyNextNo(ctx, AD_Client_ID, "C_Region");
// fill "New" variables 7-11
pstmt.setInt(7, AD_Client_ID);
pstmt.setInt(8, Env.getContextAsInt(ctx, 0, "AD_Org_ID"));
//
pstmt.setDate(9, date);
pstmt.setInt(10, user);
}
pstmt.setInt(7, C_Region_ID);
int no = pstmt.executeUpdate();
if (no != 1)
{
Log.error("MRegion.save - No record updated/inserted");
return false;
}
}
catch (SQLException e)
{
Log.error("MRegion.save", e);
return false;
}
//
Log.trace(Log.l3_Util, "MRegion.save - ID=" + C_Region_ID);
return true;
} // save
} // MRegion
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -