⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waccount.java

📁 Java写的ERP系统
💻 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.www;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import org.apache.ecs.*;

import org.apache.ecs.*;
import org.apache.ecs.xhtml.*;

import org.compiere.util.*;
import org.compiere.model.*;

/**
 *  WAccount Servlet.
 *  <p>
 *  The servlet is invoked by a parent window via
 *  <code>
 *  WAccount?FormName=formName%ColumnName=columnName
 *  </code>
 *  and assumes that in the opening window/form there are two fields
 *  <code>
 *  opener.document.formName.columnName - The (hidden) field for the ID
 *  opener.document.formName.columnName_D - The display field for the value
 *  </code>
 *  When selecting an entry, the window is closed and the value of the two fields set.
 *
 *  @author Jorg Janke
 *  @version  $Id: WAccount.java,v 1.1.1.1 2002/10/12 01:06:54 jjanke Exp $
 */
public class WAccount extends HttpServlet
{
	/**
	 * Initialize global variables
	 *
	 * @param config
	 * @throws ServletException
	 */
	public void init(ServletConfig config) throws ServletException
	{
		super.init(config);
		if (!WEnv.initWeb(config))
			throw new ServletException("WAccount.init");
	}   //  init

	/**
	 * Process the HTTP Get request - initial Start
	 * Needs to have parameters FormName and ColumnName
	 *
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		Log.trace(Log.l3_Util, "WAccount.doGet");
		HttpSession sess = request.getSession(false);
		WWindowStatus ws = null;
		if (sess != null)
			ws = (WWindowStatus)sess.getAttribute(WEnv.SA_WINDOW);
		if (ws == null)
		{
			WUtil.createTimeoutPage(request, response, this, null, null);
			return;
		}
		//  Get Mandatory Parameters
		String formName = request.getParameter("FormName");
		String columnName = request.getParameter("ColumnName");
		//
		MField mField = ws.curTab.getField(columnName);
		Log.trace(Log.l4_Data, "FormName=" + formName, "ColumnName=" + columnName + ", MField=" + mField.toString());
		if (mField == null || formName == null || columnName == null || formName.equals("") || columnName.equals(""))
		{
			WUtil.createTimeoutPage(request, response, this, ws.ctx, Msg.getMsg(ws.ctx, "ParameterMissing"));
			return;
		}
	//	Object value = ws.curTab.getValue(columnName);
		String target = "opener.document." + formName + "." + columnName;

		//  Create Document
		WDoc doc = WDoc.create (mField.getHeader());
		body body = doc.getBody();
		body.setOnBlur("self.focus();");
		body.addElement(fillTable(ws, mField, target));

		//  Reset, Cancel
		button reset = new button();
		reset.addElement("Reset");                      //  translate
		reset.setOnClick(target + ".value='';" + target + "_D.value='';window.close();");
		button cancel = new button();
		cancel.addElement("Cancel");                    //  translate
		cancel.setOnClick("window.close();");
		body.addElement(new p(AlignType.right)
			.addElement(reset)
			.addElement("&nbsp")
			.addElement(cancel));
		//
	//	Log.trace(Log.l6_Database, doc.toString());
		WUtil.createResponse (request, response, this, null, doc, false);
	}   //  doGet


	/**
	 *  Process the HTTP Post request - perform doGet
	 *  @param request
	 *  @param response
	 *  @throws ServletException
	 *  @throws IOException
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		Log.trace(Log.l3_Util, "WAccount.doPost");
		doGet(request, response);
	}   //  doPost


	/*************************************************************************/

	/**
	 *  Fill Table (Generic)
	 *
	 * @param ws        WindowStatus
	 * @param mField    the Field
	 * @param target    target field string
	 * @return  Table with selection
	 */
	private table fillTable (WWindowStatus ws, MField mField, String target)
	{
		table table = new table("1");
		tr line = new tr();
		line.addElement(new th("&nbsp")).addElement(new th(Msg.translate(ws.ctx, "Name")));
		table.addElement(line);

		//  Fill & list options
		Lookup lookup = mField.getLookup();
		lookup.fillComboBox(mField.isMandatory(false), true, true, true);   //  no context check
		int size = lookup.getSize();
		for (int i = 0; i < size; i++)
		{
			Object lValue = lookup.getElementAt(i);
			if (!(lValue != null && lValue instanceof KeyNamePair))
				continue;
			//
		//	Log.trace(Log.l6_Database, lValue.toString());
			KeyNamePair np = (KeyNamePair)lValue;
			button button = new button();
			button.addElement("&gt;");
			StringBuffer script = new StringBuffer(target);
			script.append(".value='").append(np.getKey()).append("';")
				.append(target).append("_D.value='").append(np.getName()).append("';window.close();");
			button.setOnClick(script.toString());
			//
			line = new tr();
			line.addElement(new td(button));
			String name = np.getName();
			if (name == null || name.length() == 0)
				name = "&nbsp";
			line.addElement(new td(name));
			table.addElement(line);
		}
		//  Restore
		lookup.fillComboBox(true);
		return table;
	}   //  fillTable

}   //  WAccount

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -