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

📄 wwindow.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************
 * 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 java.sql.*;
import java.math.BigDecimal;
import java.text.*;

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

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

/**
 *  Web Window Servlet
 *
 *  @author Jorg Janke
 *  @version  $Id: WWindow.java,v 1.2 2003/04/29 09:31:58 jpedersen Exp $
 */
public class WWindow 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("WWindow.init");
	}   //  init

	/**
	 * Get Servlet information
	 * @return info
	 */
	public String getServletInfo()
	{
		return "Compiere Web Window";
	}	//	getServletInfo

	/**
	 * Clean up resources
	 */
	public void destroy()
	{
		Log.trace(Log.l1_User, "WWindow.destroy");
	}   //  destroy

	/** Window Number Counter                   */
	private static int          s_WindowNo  = 1;
	/** Form Name                               */
	private static final String FORM_NAME   = "WForm";

	/**  Hidden Parameter   Command - Button    */
	private static final String P_Command   = "PCommand";
	/** Hidden Parameter - Tab No               */
	private static final String P_Tab       = "PTab";
	/** Hidden Parameter - MultiRow Row No      */
	private static final String P_MR_RowNo  = "PMRRowNo";

	//  CSS Classes
	private static final String C_MANDATORY = "Cmandatory";
	private static final String C_ERROR     = "Cerror";

	/** Multi Row Lines per Screen          */
	private static final int    MAX_LINES   = 12;
	/** Indicator for last line             */
	private static final int    LAST_LINE   = 999999;

	/** Error Indicator                     */
	private static final String ERROR       = " ERROR! ";

	/**
	 *  Process the HTTP Get request - Initial Call.
	 *  <br>
	 *  http://localhost/compiere/WWindow?AD_Window_ID=123
	 *  <br>
	 *  Create Window with request parameters
	 *  AD_Window_ID
	 *  AD_Menu_ID
	 *
	 *  Clean up old/existing window
	 *
	 *  @param request
	 *  @param response
	 *  @throws ServletException
	 *  @throws IOException
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		Log.trace(Log.l1_User, "WWindow.doGet");
		//  Get Session attributes
		HttpSession sess = request.getSession();
		Properties ctx = (Properties)sess.getAttribute(WEnv.SA_CONTEXT);
		String loginInfo = (String)sess.getAttribute(WEnv.SA_LOGININFO);
		if (ctx == null)
		{
			WUtil.createTimeoutPage(request, response, this, null, null);
			return;
		}

		//  Parameter: AD_Window_ID
		int AD_Window_ID = WUtil.getParameterAsInt(request, "AD_Window_ID");
		//  Get Parameter: Menu_ID
		int AD_Menu_ID = WUtil.getParameterAsInt(request, "AD_Menu_ID");
		Log.trace(Log.l4_Data, "AD_Window_ID=" + AD_Window_ID
			+ "; AD_Menu_ID=" + AD_Menu_ID);

		//  Clean up old Window
		WWindowStatus ws = (WWindowStatus)sess.getAttribute(WEnv.SA_WINDOW);
		if (ws != null)
		{
			int WindowNo = ws.mWindow.getWindowNo();
			Log.trace(Log.l4_Data, "WWindow.doGet - disposing",
				"WindowNo=" + WindowNo + ", ID=" + ws.mWindow.getAD_Window_ID());
			ws.mWindow.dispose();
			Env.clearWinContext(ctx, WindowNo);
		}

		/**
		 *  New Window data
		 */
		MWindowVO mWindowVO = MWindowVO.create (ctx, s_WindowNo++, AD_Window_ID, AD_Menu_ID);
		if (mWindowVO == null)
		{
			String msg = Msg.translate(ctx, "AD_Window_ID") + " "
				+ Msg.getMsg(ctx, "NotFound") + ", ID=" + AD_Window_ID + "/" + AD_Menu_ID;
			WUtil.createErrorPage(request, response, this, ws==null ? null : ws.ctx, msg);
			sess.setAttribute(WEnv.SA_WINDOW, null);
			return;
		}
		//  Create New Window
		ws = new WWindowStatus(mWindowVO);
		sess.setAttribute(WEnv.SA_WINDOW, ws);


		//  Query
		ws.curTab.query(ws.mWindow.isTransaction());
		ws.curTab.navigate(0);

		/**
		 *  Build Page
		 */
		WDoc doc = preparePage(ws);

		//	Body
		body b = doc.getBody();
		if (ws.curTab.isSingleRow())
			b.addElement(getSR_Form(request.getRequestURI(), ws, loginInfo));
		else
			b.addElement(getMR_Form(request.getRequestURI(), ws, loginInfo));

		//	fini
		Log.trace(Log.l1_User, "WWindow.doGet", "fini");
	//	Log.trace(Log.l6_Database, doc.toString());
		WUtil.createResponse (request, response, this, null, doc, true);
		Log.trace(Log.l1_User, "WWindow.doGet - closed");
	}   //  doGet


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

	/**
	 *  Process the HTTP Post request
	 *
	 *  @param request
	 *  @param response
	 *  @throws ServletException
	 *  @throws IOException
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		Log.trace(Log.l1_User, "WWindow.doPost");

		//  Get Session Info
		HttpSession sess = request.getSession();
		WWindowStatus ws = null;
		if (sess != null)
			ws = (WWindowStatus)sess.getAttribute(WEnv.SA_WINDOW);
		if (ws == null)
		{
			Properties ctx = (Properties)sess.getAttribute(WEnv.SA_CONTEXT);
			if (ctx == null)
				WUtil.createTimeoutPage(request, response, this, ctx, "No Context");
			else
				doGet(request, response);
			return;
		}
		String loginInfo = (String)sess.getAttribute(WEnv.SA_LOGININFO);

		//  Get Parameter: Command
		String p_cmd = request.getParameter(P_Command);

		/**
		 *  Exit
		 */
		if (p_cmd.equals("Exit"))
		{
			WUtil.createLoginPage(request, response, this, ws.ctx, "Exit");
			return;
		}
		executeCommand(request, p_cmd, ws);

		/**************************************************
		 *  Build Page
		 */
		WDoc doc = preparePage(ws);

		//	Body
		body b = doc.getBody();
		//  Create Simgle/Multi Row
		if (ws.curTab.isSingleRow())
			b.addElement(getSR_Form(request.getRequestURI(), ws, loginInfo));
		else
			b.addElement(getMR_Form(request.getRequestURI(), ws, loginInfo));

		//
		Log.trace(Log.l1_User, "WWindow.doPost - fini");
	//	Log.trace(Log.l6_Database, doc.toString());
		WUtil.createResponse (request, response, this, null, doc, true);
	}   //  doPost

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

	/**
	 *  Prepare Page.
	 *  - Set Header
	 *
	 *  @param ws
	 *  @return WDoc page
	 */
	private WDoc preparePage(WWindowStatus ws)
	{
		WDoc doc = WDoc.create (ws.mWindow.getName());
		head header = doc.getHead();
		//  add window.js & .css
		header.addElement(new script("", WEnv.getBaseDirectory("window.js")));
		header.addElement(new link().setRel("stylesheet").setHref(WEnv.getBaseDirectory("window.css")));
		//
		//  Set Variables
		script script = new script("deleteText='" + Msg.getMsg(ws.ctx, "DeleteRecord?") + "';");
		doc.getBody().addElement(script);
		//
		return doc;
	}   //  preparePage

	/**
	 *  Execute Command
	 *
	 *  @param request
	 *  @param p_cmd
	 *  @param ws
	 */
	private void executeCommand (HttpServletRequest request, String p_cmd, WWindowStatus ws)
	{
		//  Get Parameter: Command and Tab changes
		String p_tab = request.getParameter(P_Tab);
		String p_row = request.getParameter(P_MR_RowNo);    //  MR Row Command
		Log.trace(Log.l4_Data, "WWindow.executeCommand",
			p_cmd + " - Tab=" + p_tab + " - Row=" + p_row);

		/**
		 *  Multi-Row Selection (i.e. display single row)
		 */
		if (p_row != null && p_row.length() > 0)
		{
			try
			{
				int newRowNo = Integer.parseInt (p_row);
				ws.curTab.navigate(newRowNo);
				ws.curTab.setSingleRow(true);
			}
			catch (Exception e)
			{
				Log.error("WWindow.executeCommand - Parse RowNo="+ p_row, e);
			}
		}

		/**
		 *  Tab Change
		 */
		else if (p_tab != null && p_tab.length() > 0)
		{
			int newTabNo = 0;
			try
			{
				newTabNo = Integer.parseInt (p_tab);
			}
			catch (Exception e)
			{
				Log.error("WWindow.executeCommand - Parse TabNo="+ p_tab, e);
			}
			//  move to detail
			if (newTabNo > ws.curTab.getTabNo())
			{
				ws.curTab = ws.mWindow.getTab(newTabNo);
				ws.curTab.query(false);
				ws.curTab.navigate(0);
			}
			//  move back
			else if (newTabNo < ws.curTab.getTabNo())
			{
				ws.curTab = ws.mWindow.getTab(newTabNo);
				ws.curTab.dataRefresh();
			}
		}

		/**
		 *  Multi-Row Toggle
		 */
		else if (p_cmd.equals("Multi"))
		{
			boolean single = ws.curTab.isSingleRow();
			ws.curTab.setSingleRow(!single);
			if (single)
				ws.curTab.navigate(0);
		}

		/**
		 *  Position Commands
		 */
		else if (p_cmd.equals("First"))
		{
			ws.curTab.navigate(0);
		}
		else if (p_cmd.equals("Next"))
		{
			ws.curTab.navigateRelative(+1);     //  multi row is positioned at last displayed row
		}
		else if (p_cmd.equals("Previous"))
		{
			int rows = ws.curTab.isSingleRow() ? -1 : -2*MAX_LINES;
			ws.curTab.navigateRelative(rows);
		}
		else if (p_cmd.equals("Last"))
		{
			ws.curTab.navigateRelative(999999);
		}


		/**
		 *  Find
		 */
		else if (p_cmd.equals("Find"))
		{
			/** @todo Find */
		}

		/**
		 *  Refresh
		 */
		else if (p_cmd.equals("Refresh"))
		{
			ws.curTab.dataRefreshAll();
		}

		/**
		 *  Attachment
		 */
		else if (p_cmd.equals("Attachment"))
		{
			/** @todo Attachment */
		}

		/**
		 *  History
		 */
		else if (p_cmd.equals("History"))
		{
			if (ws.mWindow.isTransaction() && ws.curTab.getWindowNo() == 0)
			{
				ws.curTab.query( !ws.curTab.isOnlyCurrentRows() );
				ws.curTab.navigate(0);
			}
		}

		/**
		 *  Report
		 */
		else if (p_cmd.equals("Report"))
		{
			/** @todo Report */
		}

		/**
		 *  Print
		 */
		else if (p_cmd.equals("Print"))
		{
			/** @todo Print */
		}

		/**
		 *  New
		 */
		else if (p_cmd.equals("New"))
		{
			if (!ws.curTab.dataNew(false))
				ws.curTab.dataIgnore();
		}

		/**
		 *  Delete
		 */
		else if (p_cmd.equals("Delete"))
		{
			ws.curTab.dataDelete();
		}

		/**
		 *  Save - Check for changed values
		 */
		else if (p_cmd.equals("Save"))
		{
			executeSave (request, ws);
		}
	}   //  executeCommand

	/**

⌨️ 快捷键说明

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