📄 calloutuser.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 com.compiere.custom;
import java.sql.*;
import java.util.*;
import org.compiere.util.*;
import org.compiere.model.*;
/**
* Static methods
*
* @author Jorg Janke
* @version $Id: CalloutUser.java,v 1.5 2002/12/29 00:46:11 jjanke Exp $
*/
public class CalloutUser implements Callout
{
/**************************************************************************
* Start Callout.
* <p>
* Callout's are used for cross field validation and setting values in other fields
* when returning a non empty (error message) string, an exception is raised
* <p>
* When invoked, the Tab model has the new value!
*
* @param ctx Context
* @param method Method name
* @param WindowNo current Window No
* @param mTab Model Tab
* @param mField Model Field
* @param value The new value
* @param oldValue The old value
* @return Error message or ""
*/
public String start(Properties ctx, String method, int WindowNo,
MTab mTab, MField mField, Object value, Object oldValue)
{
String retValue = "";
try
{
if (method.equals("JustAnExample"))
retValue = JustAnExample (ctx, WindowNo, mTab, mField, value, oldValue);
//
else
retValue = "CalloutMethodInvalid - " + method;
}
catch (Exception e)
{
Log.error ("CalloutUser " + method, e);
e.printStackTrace(System.err);
retValue = e.getLocalizedMessage();
}
return retValue;
} // start
/**
* JustAnExample
* @return error message or "" of OK
*
* @param ctx Context
* @param WindowNo current Window No
* @param mTab Model Tab
* @param mField Model Field
* @param value The new value
* @param oldValue The old value
* @return Error message or ""
*/
private static String JustAnExample (Properties ctx, int WindowNo,
MTab mTab, MField mField, Object value, Object oldValue)
{
Log.trace(Log.l3_Util, "CalloutUser.JustAnExample");
return "";
} // JustAnExample
/*************************************************************************/
/**
* User Conversion Rules.
*
* Convert a String
*
* @param method in notation User_Function
* @param value the value
* @return converted String or Null if no method found
*/
public String convert (String method, String value)
{
String retValue = null;
try
{
if (method.equals("Frie_Name"))
retValue = Frie_Name (value);
else if (method.equals("Frie_Value"))
retValue = Frie_Value (value);
else if (method.equals("Frie_Status"))
retValue = Frie_Status (value);
}
catch (Exception e)
{
Log.error ("CalloutUser " + method + " - " + e.getMessage());
e.printStackTrace(System.err);
}
if (retValue == null)
Log.error("CalloutUser.convert error - Method: " + method + "; Value=" + value);
return retValue;
} // convert
/**
* Frie Value - convert to standardized Name
*
* @param value Name
* @return Name
*/
private static String Frie_Name (String value)
{
if (value == null || value.length() == 0)
return "";
//
String retValue = value;
String SQL = "SELECT FRIE_Name(?) FROM DUAL";
try
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setString(1, value);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
retValue = rs.getString(1);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error ("CalloutUser.Frie_Name", e);
}
return retValue;
} // Frie_Name
/**
* Frie Value - convert Name to Value
*
* @param value Name
* @return Value of Name
*/
private static String Frie_Value (String value)
{
if (value == null || value.length() == 0)
return "";
//
String retValue = value;
String SQL = "SELECT FRIE_Value(FRIE_Name(?)) FROM DUAL";
try
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setString(1, value);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
retValue = rs.getString(1);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error ("CalloutUser.Frie_Value", e);
}
return retValue;
} // Frie_Value
/**
* Frie Status - convert to Status.
*
* @param value value
* @return Status
*/
private static String Frie_Status (String value)
{
String retValue = "A"; // default (A)ctive
if (value != null && value.equals("A")) // Auslaufartikel
retValue = "O"; // (O)bsolete
return retValue;
} // Frie_Status
} // CalloutUser
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -