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

📄 vbpartner.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			//
			OldGreetingBP = rs.getInt("C_GreetingBP_ID");
			if (rs.wasNull())
				OldGreetingBP = -1;
			fGreetingBP.setSelectedItem(getGreeting(OldGreetingBP));
			//
			OldName = rs.getString("Name");
			if (OldName == null)
				OldName = "";
			fName.setText(OldName);
			//
			OldName2 = rs.getString("Name2");
			if (OldName2 == null)
				OldName2 = "";
			fName2.setText(OldName2);
			//
			OldGreetingC = rs.getInt("C_Greeting_ID");
			if (rs.wasNull())
				OldGreetingC = -1;
			fGreetingC.setSelectedItem(getGreeting(OldGreetingC));
			//
			OldContact = rs.getString("Contact");
			if (OldContact == null)
				OldContact = "";
			fContact.setText(OldContact);
			//
			OldTitle = rs.getString("Title");
			if (OldTitle == null)
				OldTitle = "";
			fTitle.setText(OldTitle);
			//
			OldPhone = rs.getString("Phone");
			if (OldPhone == null)
				OldPhone = "";
			fPhone.setText(OldPhone);
			//
			OldPhone2 = rs.getString("Phone2");
			if (OldPhone2 == null)
				OldPhone2 = "";
			fPhone2.setText(OldPhone2);
			//
			OldFax = rs.getString("Fax");
			if (OldFax == null)
				OldFax = "";
			fFax.setText(OldFax);
			//
			OldEMail = rs.getString("EMail");
			if (OldEMail == null)
				OldEMail = "";
			fEMail.setText(OldEMail);
			//
			int location = rs.getInt("C_Location_ID");
			fAddress.setValue (new Integer(location));
			//
			m_C_BPartner_Contact_ID = new Integer (rs.getInt("C_BPartner_Contact_ID"));
			if (rs.wasNull())
				m_C_BPartner_Contact_ID = null;
			m_C_BPartner_Location_ID = new Integer (rs.getInt("C_BPartner_Location_ID"));
			if (rs.wasNull())
				m_C_BPartner_Location_ID = null;
			//
			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			ADialog.error(m_WindowNo, this, "BPartnerNotFound", e.getLocalizedMessage());
			return false;
		}
		return true;
	}	//	loadBPartner


	/**
	 *	Action Listener
	 * 	@param e event
	 */
	public void actionPerformed(ActionEvent e)
	{
		//	OK pressed
		if (e.getActionCommand().equals(ConfirmPanel.A_OK) && actionSave())
			dispose();
		//	Cancel pressed
		else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
			dispose();
	}	//	actionPerformed

	/**
	 *	Save.
	 *	Checks mandatory fields and saves Partner, Contact and Location
	 * 	@return true if saved
	 */
	private boolean actionSave()
	{
		Log.trace(Log.l3_Util, "VBPartner.save");

		//	Check Mandatory fields
		String value = fValue.getText();
		if (value == null)
			value = "";
		String name = fName.getText();
		if (value.equals("") || name.equals(""))
		{
			if (value.equals(""))
				fValue.setBackground(CompierePLAF.getFieldBackground_Error());
			if (name.equals(""))
				fName.setBackground(CompierePLAF.getFieldBackground_Error());
			return false;
		}

		String SQL = "";
		try
		{
			Statement stmt = DB.createStatement();
			int AD_Client_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Client_ID"));
			int AD_Org_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Org_ID"));
			int UpdatedBy = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_User_ID"));

			KeyNamePair p = (KeyNamePair)fGreetingBP.getSelectedItem();
			int greetingBP = p.getKey();
			p = (KeyNamePair)fGreetingC.getSelectedItem();
			int greetingC = p.getKey();

			//	===	Insert Business Partner	===
			if (m_C_BPartner_ID == 0)
			{
				m_C_BPartner_ID = DB.getKeyNextNo(Env.getCtx(), m_WindowNo, "C_BPartner");
				Log.trace(Log.l4_Data, "Insert BPartner " + m_C_BPartner_ID);
				String gr = "NULL";
				if (greetingBP > 0)
					gr = "" + greetingBP;
				SQL = "INSERT INTO C_BPartner"
					+ "(C_BPartner_ID,"
					+ "AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,"
					+ "Value,Name,Name2,C_Greeting_ID,IsSummary,IsOneTime,IsProspect,IsVendor,IsCustomer,IsEmployee,IsSalesRep,"
					+ "AD_Language,C_BP_Group_ID,C_InvoiceSchedule_ID,C_PaymentTerm_ID,"
					+ "M_PriceList_ID,M_DiscountSchema_ID,C_Dunning_ID,DocumentCopies,PaymentRule,"
					+ "SO_CreditLimit, SO_CreditUsed) "
					//
					+ "SELECT " + m_C_BPartner_ID + ","
					+ AD_Client_ID + "," + AD_Org_ID + ",'Y',SysDate," + UpdatedBy + ",SysDate," + UpdatedBy + ","
					+ DB.TO_STRING(value) + "," + DB.TO_STRING(name) + "," + DB.TO_STRING(fName2.getText())
					+ "," + gr + ",'N','N','N','N','Y','N','N',"
					+ "AD_Language,C_BP_Group_ID,C_InvoiceSchedule_ID,C_PaymentTerm_ID,"
					+ "p.M_PriceList_ID,M_DiscountSchema_ID,C_Dunning_ID,DocumentCopies,PaymentRule,"
					+ "0,0 "
					+ "FROM C_BPartner p, AD_ClientInfo c "
					+ "WHERE c.AD_Client_ID=" + AD_Client_ID
					+ " AND p.C_BPartner_ID(+)=c.C_BPartnerCashTrx_ID";
				int i = stmt.executeUpdate(SQL);
				if (i != 1)
					ADialog.error(m_WindowNo, this, "BPartnerNotSaved", "\nPartner I#=" + i + ", SQL=" + SQL);
			}
			//	===	Update Business Partner	===		(value/greeting/name/name2)
			else if (!(OldValue.equals(value) && OldGreetingBP==greetingBP && OldName.equals(name)
				&& OldName2.equals(fName2.getText()) ))
			{
				Log.trace(Log.l4_Data, "Update BPartner " + m_C_BPartner_ID);
				Integer gr = new Integer(greetingBP);
				SQL = "UPDATE C_BPartner SET "
					+ "Value=" + DB.TO_STRING(value) + ","
					+ "C_Greeting_ID=" + (greetingBP == -1 ? "NULL" : gr.toString()) + ","
					+ "Name=" + DB.TO_STRING(name) + ","
					+ "Name2=" + DB.TO_STRING(fName2.getText()) + ","
					+ "Updated=SysDate, UpdatedBy=" + UpdatedBy
					+ " WHERE C_BPartner_ID=" + m_C_BPartner_ID;
				int i = stmt.executeUpdate(SQL);
				if (i != 1)
					ADialog.error(m_WindowNo, this, "BPartnerNotSaved", "\nPartner U#=" + i + ", SQL=" + SQL);
			}

			//	===	Insert New BPartner_Location ===
			if (m_C_BPartner_Location_ID == null && !fAddress.getValue().equals(new Integer(0)))
			{
				m_C_BPartner_Location_ID = new Integer (DB.getKeyNextNo(Env.getCtx(), m_WindowNo, "C_BPartner_Location"));
				Log.trace(Log.l4_Data, "Insert BPartner Location " + m_C_BPartner_Location_ID + " (" + fAddress.getValue() + ")");
				SQL = "INSERT INTO C_BPartner_Location"
					+ "(C_BPartner_Location_ID, C_BPartner_ID,"
					+ "AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,"
					+ "Name, C_Location_ID, Phone, Phone2, Fax)"
					+ " VALUES "
					+ "(" + m_C_BPartner_Location_ID + "," + m_C_BPartner_ID + ","
					+ AD_Client_ID + "," + AD_Org_ID + ",'Y',SysDate," + UpdatedBy + ",SysDate," + UpdatedBy + ","
					+ DB.TO_STRING(fAddress.getName()) + "," + fAddress.getValue() + ","
					+ DB.TO_STRING(fPhone.getText()) + "," + DB.TO_STRING(fPhone2.getText()) + ","
					+ DB.TO_STRING(fFax.getText()) + ")";
				int i = stmt.executeUpdate(SQL);
				if (i != 1)
					ADialog.error(m_WindowNo, this, "BPartnerNotSaved", "\nLocation I#=" + i + ", SQL=" + SQL);
			}
			//	=== Update BPartner_Location ===
			else if (m_C_BPartner_Location_ID != null &&
				!(fAddress.getValue().equals(m_C_BPartner_Location_ID)
				&& OldPhone.equals(fPhone.getText()) && OldPhone2.equals(fPhone2.getText())
				&& OldFax.equals(fFax.getText()) 	))
			{
				Log.trace(Log.l4_Data, "Update BPartner Location " + m_C_BPartner_Location_ID);
				SQL = "UPDATE C_BPartner_Location SET "
					+ "C_Location_ID=" + fAddress.getValue() + ","
					+ "Phone=" + DB.TO_STRING(fPhone.getText()) + ","
					+ "Phone2=" + DB.TO_STRING(fPhone2.getText()) + ","
					+ "Fax=" + DB.TO_STRING(fFax.getText()) + ","
					+ "Updated=SysDate, UpdatedBy=" + UpdatedBy
					+ " WHERE C_BPartner_Location_ID=" + m_C_BPartner_Location_ID;
				int i = stmt.executeUpdate(SQL);
				if (i != 1)
					ADialog.error(m_WindowNo, this, "BPartnerNotSaved", "\nLocation U#=" + i + ", SQL=" + SQL);
			}

			//	=== Insert new BPartner_Contact === only if contact/email entered
			if (!fEMail.getText().equals("") && fContact.getText().equals(""))
				fContact.setText(fName.getText());
			if (m_C_BPartner_Contact_ID == null && !fContact.getText().equals("")
			  &&
				!(OldContact.equals(fContact.getText()) && OldTitle.equals(fTitle.getText())
				&& OldPhone.equals(fPhone.getText()) && OldPhone2.equals(fPhone2.getText())
				&& OldFax.equals(fFax.getText()) && OldEMail.equals(fEMail.getText())		))
			{
				m_C_BPartner_Contact_ID = new Integer (DB.getKeyNextNo(Env.getCtx(), m_WindowNo, "C_BPartner_Contact"));
				Log.trace(Log.l4_Data, "Insert BPartner Contact " + m_C_BPartner_Contact_ID);
				String gr = "NULL";
				if (greetingC > 0)
					gr = "" + greetingC;
				SQL = "INSERT INTO C_BPartner_Contact"
					+ "(C_BPartner_Contact_ID, C_BPartner_ID,"
					+ "AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,"
					+ "Name, C_Greeting_ID, Title, Phone, Phone2, Fax, EMail)"
					+ " VALUES "
					+ "(" + m_C_BPartner_Contact_ID + "," + m_C_BPartner_ID + ","
					+ AD_Client_ID + "," + AD_Org_ID + ",'Y',SysDate," + UpdatedBy + ",SysDate," + UpdatedBy + ","
					+ DB.TO_STRING(fContact.getText()) + "," + gr + ","
					+ DB.TO_STRING(fTitle.getText()) + "," + DB.TO_STRING(fPhone.getText()) + ","
					+ DB.TO_STRING(fPhone2.getText()) + "," + DB.TO_STRING(fFax.getText()) + ","
					+ DB.TO_STRING(fEMail.getText()) + ")";
				int i = stmt.executeUpdate(SQL);
				if (i != 1)
					ADialog.error(m_WindowNo, this, "BPartnerNotSaved", "\nContact I#=" + i + ", SQL=" + SQL);
			}
			//	===	Update BPartner_Contact ===
			else if (m_C_BPartner_Contact_ID != null &&
				!(OldContact.equals(fContact.getText()) && OldTitle.equals(fTitle.getText())
				&& OldPhone.equals(fPhone.getText()) && OldPhone2.equals(fPhone2.getText())
				&& OldFax.equals(fFax.getText()) && OldEMail.equals(fEMail.getText())
				&& OldGreetingC==greetingC		))
			{
				Log.trace(Log.l4_Data, "Update BPartner Contact " + m_C_BPartner_Contact_ID);
				//	We need to have a Name
				if (fContact.getText().equals(""))
					fContact.setText(name);
				Integer gr = new Integer(greetingC);
				SQL = "UPDATE C_BPartner_Contact SET "
					+ "Name=" + DB.TO_STRING(fContact.getText()) + ","
					+ "C_Greeting_ID=" + (greetingC == -1 ? "NULL" : gr.toString()) + ","
					+ "Title=" + DB.TO_STRING(fTitle.getText()) + ","
					+ "Phone=" + DB.TO_STRING(fPhone.getText()) + ","
					+ "Phone2=" + DB.TO_STRING(fPhone2.getText()) + ","
					+ "Fax=" + DB.TO_STRING(fFax.getText()) + ","
					+ "EMail=" + DB.TO_STRING(fEMail.getText()) + ","
					+ "Updated=SysDate, UpdatedBy=" + UpdatedBy
					+ " WHERE C_BPartner_Contact_ID=" + m_C_BPartner_Contact_ID;
				int i = stmt.executeUpdate(SQL);
				if (i != 1)
					ADialog.error(m_WindowNo, this, "BPartnerNotSaved", "\nContact U#=" + i + ", SQL=" + SQL);
			}

		}
		catch (SQLException e)
		{
			ADialog.error(m_WindowNo, this, "BPartnerNotSaved", e.getLocalizedMessage() + "\nSQL=" + SQL);
			m_C_BPartner_ID = 0;
			return false;
		}

		return true;
	}	//	acationSave


	/**
	 *	Returns BPartner ID
	 *	@return C_BPartner)ID (0 = not saved)
	 */
	public int getBPartner_ID()
	{
		return m_C_BPartner_ID;
	}	//	getBPartner_ID


	/**************************************************************************
	 *	VLabel
	 */
	class VLabel extends JLabel
	{
		public VLabel (String text)
		{
			super (text);
			this.setHorizontalAlignment(JLabel.RIGHT);
		}
	}	//	VLabel

}	//	VBPartner

⌨️ 快捷键说明

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