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

📄 configurationpanel.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		//	Database User Info
		m_databaseUser = fDatabaseUser.getText();	//	UID
		m_databasePassword = new String(fDatabasePassword.getPassword());	//	PWD
		//	Ignore result as it might not be imported
		if (testJDBC(m_databaseUser, m_databasePassword))
			System.out.println("OK: Database UserID = " + m_databaseUser + "/" + m_databasePassword);
		else
			System.out.println("Not created yet: Database UserID = " + m_databaseUser + "/" + m_databasePassword);
		m_properties.setProperty(COMPIERE_DB_USER, m_databaseUser);
		m_properties.setProperty(COMPIERE_DB_PASSWORD, m_databasePassword);


		//	TNS Name Info
		m_errorString = res.getString("ErrorTNS");
		m_statusBar.setText(lTNSName.getText());
		m_TNSName = (String)fTNSName.getSelectedItem();
		if (!testTNS("system", m_systemPassword))
		{
			System.err.println("Error Database TNS Name = " + m_TNSName);
			return;
		}
		System.out.println("OK: Database TNS Name = " + m_TNSName);
		m_properties.setProperty(COMPIERE_DB_TNS, m_TNSName);


		//	Mail Server
		m_errorString = res.getString("ErrorMailServer");
		m_statusBar.setText(lMailServer.getText());
		server = fMailServer.getText();
		if (server == null || server.length() == 0)
		{
			System.err.println("Error Mail Server = " + server);
			return;
		}
		m_mailServer = InetAddress.getByName(server);
		System.out.println("OK: Mail Server = " + m_mailServer);
		m_properties.setProperty(COMPIERE_MAIL_SERVER, m_mailServer.getHostName());


		//	Mail User
		m_errorString = "ErrorMailUser";
		m_statusBar.setText(lMailUser.getText());
		m_mailUser = fMailUser.getText();
		m_mailPassword = new String(fMailPassword.getPassword());
		m_properties.setProperty(COMPIERE_MAIL_USER, m_mailUser);
		m_properties.setProperty(COMPIERE_MAIL_PASSWORD, m_mailPassword);
		System.out.println("  Mail User = " + m_mailUser + "/" + m_mailPassword);

		//	Mail Address
		m_errorString = res.getString("ErrorMail");
		m_adminEMail = new InternetAddress (fAdminEMail.getText());
		//
		if (testMail())
			System.out.println("OK: Admin EMail = " + m_adminEMail);
		else
			System.out.println("Not verified Admin EMail = " + m_adminEMail);
		m_properties.setProperty(COMPIERE_ADMIN_EMAIL, m_adminEMail.toString());

		//
		m_statusBar.setText(res.getString("Ok"));
		System.out.println("** Test OK **");
		bSave.setEnabled(true);
		m_errorString = null;
	}	//	test


	/**
	 * 	Test Apps Server Port (client perspective)
	 *  @param protocol protocol (http, ..)
	 *  @param server server name
	 *  @param port port
	 *  @param file file name
	 *  @return true if able to connect
	 */
	private boolean testPort (String protocol, String server, int port, String file)
	{
		URL url = null;
		try
		{
			url = new URL (protocol, server, port, file);
		}
		catch (MalformedURLException ex)
		{
			ex.printStackTrace();
			return false;
		}
		System.out.println("  URL=" + url);
		try
		{
			URLConnection c = url.openConnection();
			Object o = c.getContent();
			System.err.println("  URL Connection in use=" + url);	//	error
		}
		catch (Exception ex)
		{
			return false;
		}
		return true;
	}	//	testPort

	/**
	 * 	Test Server Port
	 *  @param port port
	 *  @return true if able to create
	 */
	private boolean testServerPort (int port)
	{
		try
		{
			ServerSocket ss = new ServerSocket (port);
			System.out.println("  ServerPort " + ss.getInetAddress() + ":" + ss.getLocalPort());
			ss.close();
		}
		catch (Exception ex)
		{
			System.err.println(ex);
			return false;
		}
		return true;
	}	//	testPort


	/**
	 * 	Test Port
	 *  @param host host
	 *  @param port port
	 *  @param shouldBenUsed true if it should be used
	 *  @return true if some server answered on port
	 */
	public boolean testPort (InetAddress host, int port, boolean shouldBenUsed)
	{
		Socket pingSocket = null;
		try
		{
			pingSocket = new Socket(host, port);
		}
		catch (Exception e)
		{
			if (shouldBenUsed)
				System.err.println("  Open Socket " + host + " on " + port + ": " + e.getMessage());
			return false;
		}
		if (!shouldBenUsed)
			System.err.println("  Open Socket " + host + " on " + port);
		if (pingSocket == null)
			return false;
		//	success
		try
		{
			pingSocket.close();
		}
		catch (IOException e)
		{
			System.out.println("  CloseSocket=" + e.toString());
		}
		return true;
	}	//	testPort

	/**
	 * 	Test JDBC Connection to Server
	 *  @param uid user id
	 *  @param pwd password
	 * 	@return true if OK
	 */
	private boolean testJDBC (String uid, String pwd)
	{
		//	jdbc:oracle:thin:@dev:1521:dev1
		m_connectionString = "jdbc:oracle:thin:@"
			+ m_databaseServer.getHostName() + ":" + m_databasePort + ":" + m_databaseName;
		System.out.println("  JDBC = " + m_connectionString);

		try
		{
			if (s_driver == null)
			{
				s_driver = new OracleDriver();
				DriverManager.registerDriver(s_driver);
			}
			Connection con = DriverManager.getConnection(m_connectionString,
				uid, pwd);
		}
		catch (Exception e)
		{
			System.err.println(e.toString());
			return false;
		}
		return true;
	}	//	testJDBC

	/**
	 * 	Test TNS Connection
	 *  @param uid user id
	 *  @param pwd password
	 * 	@return true if OK
	 */
	private boolean testTNS (String uid, String pwd)
	{
		String connectionString = "jdbc:oracle:oci8:@" + m_TNSName;
		System.out.println("  TNS = " + connectionString);
		try
		{
			if (s_driver == null)
			{
				s_driver = new OracleDriver();
				DriverManager.registerDriver(s_driver);
			}
			Connection con = DriverManager.getConnection(connectionString,
				uid, pwd);
		}
		catch (UnsatisfiedLinkError ule)
		{
			System.err.println("Check setup of Oracle Server / Oracle Client / LD_LIBRARY_PATH");
			System.err.println(ule.toString());
			return false;
		}
		catch (Exception e)
		{
			System.err.println(e.toString());
			return false;
		}
		return true;
	}	//	testTNS

	/**
	 * 	Test Mail
	 *  @return true of OK
	 */
	private boolean testMail()
	{
		boolean smtpOK = false;
		boolean imapOK = false;
		if (testPort (m_mailServer, 25, true))
		{
			System.out.println("OK: SMTP Server contacted");
			smtpOK = true;
		}
		else
			System.err.println("Error: SMTP Server NOT available");
		//
		if (testPort (m_mailServer, 110, true))
			System.out.println("OK: POP3 Server contacted");
		else
			System.err.println("Error: POP3 Server NOT available");
		if (testPort (m_mailServer, 143, true))
		{
			System.out.println("OK: IMAP4 Server contacted");
			imapOK = true;
		}
		else
			System.err.println("Error: IMAP4 Server NOT available");
		//
		if (!smtpOK)
			return false;
		//
		EMail em = new EMail(m_mailServer.getHostName(),
			m_adminEMail.toString(), m_adminEMail.toString(),
			"Compiere Server Setup Test", "Test: " + m_properties);
		if (EMail.SENT_OK.equals(em.send()))
			System.out.println("OK: Send Test Email to " + m_adminEMail);
		else
			System.err.println("Error: Could NOT send Email to " + m_adminEMail);

		//
		if (!imapOK)
			return false;
		//	Test Mail Access
		Properties props = new Properties();
		props.put("mail.store.protocol", "smtp");
		props.put("mail.transport.protocol", "smtp");
		props.put("mail.host", m_mailServer.getHostName());
		props.put("mail.user", m_mailUser);
		Session session = Session.getDefaultInstance(props, null);
		//	Connect to Store
		Store store;
		try
		{
			store = session.getStore("imap");
		}
		catch (NoSuchProviderException nsp)
		{
			System.err.println("Error Mail IMAP " + nsp.getMessage());
			return false;
		}
		try
		{
			store.connect(m_mailServer.getHostName(), m_mailUser, m_mailPassword);
			Folder folder = store.getDefaultFolder();
			Folder inbox = folder.getFolder("INBOX");
			System.out.println("OK: Mail Connect to " + inbox.getFullName() + " #Msg=" + inbox.getMessageCount());
			//
			store.close();
		}
		catch (MessagingException mex)
		{
			System.err.println("Error Mail Connect " + mex.getMessage());
			return false;
		}
		return true;
	}	//	testMail

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

	/**
	 * 	Save Settings
	 */
	private void save()
	{
		SwingWorker sw = startTest();
		while (sw.isAlive())
		{
			try
			{
				Thread.currentThread().sleep(2000);
			}
			catch (InterruptedException ex)
			{
				System.err.println("save-waiting: " + ex);
			}
		}
		sw.get();	//	block
		if (!m_success)
			return;

		//	Add
		m_properties.setProperty("COMPIERE_MAIN_VERSION", Compiere.MAIN_VERSION);
		m_properties.setProperty("COMPIERE_DATE_VERSION", Compiere.DATE_VERSION);
		m_properties.setProperty("COMPIERE_DB_VERSION", Compiere.DB_VERSION);



		//	Before we save, load Ini
		Ini.setClient(false);
		String fileName = m_compiereHome.getAbsolutePath() + File.separator + Ini.COMPIERE_PROPERTY_FILE;
		Ini.loadProperties(fileName);

		//	Save Environment
		fileName = m_compiereHome.getAbsolutePath() + File.separator + COMPIERE_ENV_FILE;
		try
		{
			FileOutputStream fos = new FileOutputStream(new File(fileName));
			m_properties.store(fos, COMPIERE_ENV_FILE);
			fos.flush();
			fos.close();
		}
		catch (Exception e)
		{
			System.err.println ("Cannot save Properties to " + fileName + " - " + e.toString());
			JOptionPane.showConfirmDialog(this, res.getString("ErrorSave"), res.getString("CompiereServerSetup"),
				JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
			return;
		}
		catch (Throwable t)
		{
			System.err.println ("Cannot save Properties to " + fileName + " - " + t.toString());
			JOptionPane.showConfirmDialog(this, res.getString("ErrorSave"), res.getString("CompiereServerSetup"),
				JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
			return;
		}
		System.out.println("Properties saved to " + fileName);

		//	Sync Properties
		Ini.setCompiereHome(m_compiereHome.getAbsolutePath());
		CConnection cc = CConnection.get (Database.DB_ORACLE,
			m_databaseServer.getHostName(), m_databasePort, m_databaseName,
			m_databaseUser, m_databasePassword);
		cc.setAppsHost(m_appsServer.getHostName());
                cc.setRMIoverHTTP(m_RMIoverHTTP);
		Ini.setProperty(Ini.P_CONNECTION, cc.toStringLong());
		Ini.saveProperties(false);


		JOptionPane.showConfirmDialog(this, res.getString("EnvironmentSaved"),
			res.getString("CompiereServerSetup"),
			JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);

		((Frame)SwingUtilities.getWindowAncestor(this)).dispose();
		System.exit(0);		//	remains active when License Dialog called
	}

  void cbRMIoverHTTP_actionPerformed(ActionEvent e) {
    fJNPPort.setEnabled(!cbRMIoverHTTP.isSelected());
    lJNPPort.setEnabled(!cbRMIoverHTTP.isSelected());
  }


//	save

}	//	ConfigurationPanel

class ConfigurationPanel_cbRMIoverHTTP_actionAdapter implements java.awt.event.ActionListener {
  ConfigurationPanel adaptee;

  ConfigurationPanel_cbRMIoverHTTP_actionAdapter(ConfigurationPanel adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.cbRMIoverHTTP_actionPerformed(e);
  }
}



⌨️ 快捷键说明

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