1 14 package org.compiere.grid.ed; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import java.sql.*; 19 import java.util.ArrayList ; 20 21 import javax.swing.*; 22 import javax.swing.border.TitledBorder ; 23 24 import org.compiere.apps.*; 25 import org.compiere.grid.GridController; 26 import org.compiere.model.*; 27 import org.compiere.plaf.CompiereColor; 28 import org.compiere.swing.CButton; 29 import org.compiere.swing.CPanel; 30 import org.compiere.util.*; 31 32 38 public final class VAccountDialog extends JDialog 39 implements ActionListener, DataStatusListener 40 { 41 47 public VAccountDialog (Frame frame, String title, MAccount mAccount) 48 { 49 super (frame, title, true); 50 Log.trace(Log.l2_Sub, "VAccountDialog"); 51 m_mAccount = mAccount; 52 m_WindowNo = Env.createWindowNo (this); 53 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 54 try 55 { 56 jbInit(); 57 } 58 catch(Exception ex) 59 { 60 Log.error ("VAccountDialog" + ex); 61 } 62 initAccount(); 63 AEnv.showCenterWindow(frame, this); 64 } 66 private int m_WindowNo; 67 protected boolean m_changed = false; 68 69 70 private static AcctSchema s_AcctSchema = null; 71 72 private MWindow m_mWindow = null; 73 74 private MTab m_mTab = null; 75 76 private GridController m_gridController = null; 77 78 79 private MAccount m_mAccount = null; 80 81 private int m_C_ValidCombination_ID; 82 83 private int m_AD_Client_ID; 84 85 private MQuery m_query; 86 87 private VEditor f_Alias, f_Combination, 89 f_AD_Org_ID, f_Account_ID, 90 f_M_Product_ID, f_C_BPartner_ID, f_C_Campaign_ID, f_C_LocFrom_ID, f_C_LocTo_ID, 91 f_C_Project_ID, f_C_SalesRegion_ID, f_AD_OrgTrx_ID, f_C_Activity_ID, 92 f_User1_ID, f_User2_ID; 93 private JLabel f_Description = new JLabel ("", JLabel.CENTER); 95 96 private GridBagConstraints m_gbc = new GridBagConstraints(); 97 private Insets m_labelInsets = new Insets(2,15,2,0); private Insets m_fieldInsets = new Insets(2,5,2,10); 99 private int m_line = 0; 100 private boolean m_newRow = true; 101 private CPanel panel = new CPanel(); 103 private BorderLayout panelLayout = new BorderLayout(); 104 private ConfirmPanel confirmPanel = new ConfirmPanel(true); 105 private TitledBorder titledBorder; 106 private StatusBar statusBar = new StatusBar(); 107 private CPanel northPanel = new CPanel(); 108 private CPanel parameterPanel = new CPanel(); 109 private GridBagLayout parameterLayout = new GridBagLayout(); 110 private BorderLayout northLayout = new BorderLayout(); 111 private JToolBar toolBar = new JToolBar(); 112 private CButton bRefresh = new CButton(); 113 private CButton bSave = new CButton(); 114 private CButton bIgnore = new CButton(); 115 116 129 void jbInit() throws Exception 130 { 131 CompiereColor.setBackground(this); 132 titledBorder = new TitledBorder (BorderFactory.createEtchedBorder(Color.white,new Color(134, 134, 134)), "Parameter"); 133 panelLayout.setHgap(5); 135 panelLayout.setVgap(5); 136 northLayout.setHgap(5); 137 northLayout.setVgap(5); 138 parameterPanel.setLayout(parameterLayout); 140 parameterPanel.setBorder(titledBorder); 141 northPanel.setLayout(northLayout); 142 toolBar.setOrientation(JToolBar.VERTICAL); 143 toolBar.setBorder(null); 144 toolBar.setRequestFocusEnabled(false); 145 toolBar.setBorderPainted(false); 146 toolBar.setMargin(new Insets(5, 5, 5, 5)); 147 bSave.setIcon(new ImageIcon(org.compiere.Compiere.class.getResource("images/Save24.gif"))); 148 bSave.setMargin(new Insets(2, 2, 2, 2)); 149 bSave.setToolTipText(Msg.getMsg(Env.getCtx(),"AccountNewUpdate")); 150 bSave.addActionListener(this); 151 bRefresh.setIcon(new ImageIcon(org.compiere.Compiere.class.getResource("images/Refresh24.gif"))); 152 bRefresh.setMargin(new Insets(2, 2, 2, 2)); 153 bRefresh.setToolTipText(Msg.getMsg(Env.getCtx(),"Refresh")); 154 bRefresh.addActionListener(this); 155 bIgnore.setIcon(new ImageIcon(org.compiere.Compiere.class.getResource("images/Ignore24.gif"))); 156 bIgnore.setMargin(new Insets(2, 2, 2, 2)); 157 bIgnore.setToolTipText(Msg.getMsg(Env.getCtx(),"Ignore")); 158 bIgnore.addActionListener(this); 159 toolBar.addSeparator(); 161 toolBar.add(bRefresh, null); 162 toolBar.add(bIgnore, null); 163 toolBar.add(bSave, null); 164 getContentPane().add(panel); 166 panel.setLayout(panelLayout); 167 panel.add(confirmPanel, BorderLayout.SOUTH); 168 panel.add(northPanel, BorderLayout.NORTH); 169 northPanel.add(parameterPanel, BorderLayout.CENTER); 170 northPanel.add(toolBar, BorderLayout.EAST); 171 this.getContentPane().add(statusBar, BorderLayout.SOUTH); 173 confirmPanel.addActionListener(this); 174 } 176 182 private boolean initAccount() 183 { 184 m_AD_Client_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_Client_ID"); 185 int C_AcctSchema_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_AcctSchema_ID"); 187 if (C_AcctSchema_ID == 0) 188 C_AcctSchema_ID = Env.getContextAsInt(Env.getCtx(), "$C_AcctSchema_ID"); 189 if (s_AcctSchema == null || s_AcctSchema.getC_AcctSchema_ID() != C_AcctSchema_ID) 190 s_AcctSchema = new AcctSchema(C_AcctSchema_ID); 191 Log.trace(Log.l3_Util, "VAccountDialog.initAccount - " + s_AcctSchema.toString() 192 + ", #" + s_AcctSchema.getAcctSchemaElementList().size()); 193 Env.setContext(Env.getCtx(), m_WindowNo, "C_AcctSchema_ID", C_AcctSchema_ID); 194 195 MWindowVO wVO = AEnv.getMWindowVO (m_WindowNo, 153, 0); if (wVO == null) 198 return false; 199 m_mWindow = new MWindow (wVO); 200 m_mTab = m_mWindow.getTab(0); 201 m_mTab.getField("Alias").setDisplayLength(15); 203 m_mTab.getField("Combination").setDisplayLength(15); 204 m_mTab.getField("AD_Client_ID").setDisplayed(false); 206 m_mTab.getField("C_AcctSchema_ID").setDisplayed(false); 207 m_mTab.getField("IsActive").setDisplayed(false); 208 m_mTab.getField("IsFullyQualified").setDisplayed(false); 209 for (int i = 0; i < m_mTab.getFieldCount(); i++) 211 { 212 MField field = m_mTab.getField(i); 213 if (!field.isDisplayed (true)) field.setDisplayed (false); 215 } 216 217 m_gridController = new GridController(); 219 m_gridController.initGrid(m_mTab, true, m_WindowNo, null, null); 220 m_gridController.setPreferredSize(new Dimension(300,100)); 221 panel.add(m_gridController, BorderLayout.CENTER); 222 223 m_gbc.anchor = GridBagConstraints.NORTHWEST; 225 m_gbc.gridy = 0; m_gbc.gridx = 0; 227 m_gbc.gridwidth = 1; 228 m_gbc.insets = m_fieldInsets; 229 m_gbc.fill = GridBagConstraints.HORIZONTAL; 230 m_gbc.weightx = 0; 231 m_gbc.weighty = 0; 232 233 int TabNo = 0; 234 Env.setContext(Env.getCtx(), m_WindowNo, "C_AcctSchema_ID", C_AcctSchema_ID); 235 236 if (s_AcctSchema.hasAlias()) 238 { 239 MField alias = m_mTab.getField("Alias"); 240 f_Alias = VEditorFactory.getEditor(m_mTab, alias, false); 241 addLine(alias, f_Alias, false); 242 } 244 MField combination = m_mTab.getField("Combination"); 246 f_Combination = VEditorFactory.getEditor(m_mTab, combination, false); 247 addLine(combination, f_Combination, false); 248 m_newRow = true; 249 250 253 ArrayList ase_list = s_AcctSchema.getAcctSchemaElementList(); 254 for (int i = 0; i < ase_list.size(); i++) 255 { 256 AcctSchemaElement ase = (AcctSchemaElement)ase_list.get(i); 257 String type = ase.getSegmentType(); 258 boolean isMandatory = ase.isMandatory(); 259 if (type.equals(AcctSchemaElement.SEGMENT_Org)) 261 { 262 MField field = m_mTab.getField("AD_Org_ID"); 263 f_AD_Org_ID = VEditorFactory.getEditor(m_mTab, field, false); 264 addLine(field, f_AD_Org_ID, isMandatory); 265 } 266 else if (type.equals(AcctSchemaElement.SEGMENT_Account)) 267 { 268 MField field = m_mTab.getField("Account_ID"); 269 f_Account_ID = VEditorFactory.getEditor(m_mTab, field, false); 270 addLine(field, f_Account_ID, isMandatory); 271 } 272 else if (type.equals(AcctSchemaElement.SEGMENT_Product)) 273 { 274 MField field = m_mTab.getField("M_Product_ID"); 275 f_M_Product_ID = VEditorFactory.getEditor(m_mTab, field, false); 276 addLine(field, f_M_Product_ID, isMandatory); 277 } 278 else if (type.equals(AcctSchemaElement.SEGMENT_BPartner)) 279 { 280 MField field = m_mTab.getField("C_BPartner_ID"); 281 f_C_BPartner_ID = VEditorFactory.getEditor(m_mTab, field, false); 282 addLine(field, f_C_BPartner_ID, isMandatory); 283 } 284 else if (type.equals(AcctSchemaElement.SEGMENT_Campaign)) 285 { 286 MField field = m_mTab.getField("C_Campaign_ID"); 287 f_C_Campaign_ID = VEditorFactory.getEditor(m_mTab, field, false); 288 addLine(field, f_C_Campaign_ID, isMandatory); 289 } 290 else if (type.equals(AcctSchemaElement.SEGMENT_LocationFrom)) 291 { 292 MField field = m_mTab.getField("C_LocFrom_ID"); 293 f_C_LocFrom_ID = VEditorFactory.getEditor(m_mTab, field, false); 294 addLine(field, f_C_LocFrom_ID, isMandatory); 295 } 296 else if (type.equals(AcctSchemaElement.SEGMENT_LocationTo)) 297 { 298 MField field = m_mTab.getField("C_LocTo_ID"); 299 f_C_LocTo_ID = VEditorFactory.getEditor(m_mTab, field, false); 300 addLine(field, f_C_LocTo_ID, isMandatory); 301 } 302 else if (type.equals(AcctSchemaElement.SEGMENT_Project)) 303 { 304 MField field = m_mTab.getField("C_Project_ID"); 305 f_C_Project_ID = VEditorFactory.getEditor(m_mTab, field, false); 306 addLine(field, f_C_Project_ID, isMandatory); 307 } 308 else if (type.equals(AcctSchemaElement.SEGMENT_SalesRegion)) 309 { 310 MField field = m_mTab.getField("C_SalesRegion_ID"); 311 f_C_SalesRegion_ID = VEditorFactory.getEditor(m_mTab, field, false); 312 addLine(field, f_C_SalesRegion_ID, isMandatory); 313 } 314 else if (type.equals(AcctSchemaElement.SEGMENT_OrgTrx)) 315 { 316 MField field = m_mTab.getField("AD_OrgTrx_ID"); 317 f_AD_OrgTrx_ID = VEditorFactory.getEditor(m_mTab, field, false); 318 addLine(field, f_AD_OrgTrx_ID, isMandatory); 319 } 320 else if (type.equals(AcctSchemaElement.SEGMENT_Activity)) 321 { 322 MField field = m_mTab.getField("C_Activity_ID"); 323 f_C_Activity_ID = VEditorFactory.getEditor(m_mTab, field, false); 324 addLine(field, f_C_Activity_ID, isMandatory); 325 } 326 else if (type.equals(AcctSchemaElement.SEGMENT_User1)) 328 { 329 MField field = m_mTab.getField("User1_ID"); 330 f_User1_ID = VEditorFactory.getEditor(m_mTab, field, false); 331 addLine(field, f_User1_ID, isMandatory); 332 } 333 else if (type.equals(AcctSchemaElement.SEGMENT_User2)) 334 { 335 MField field = m_mTab.getField("User2_ID"); 336 f_User2_ID = VEditorFactory.getEditor(m_mTab, field, false); 337 addLine(field, f_User2_ID, isMandatory); 338 } 339 } 341 m_newRow = true; 343 m_gbc.gridy = m_line++; 344 m_gbc.gridx = 0; 345 m_gbc.gridwidth = 4; 346 m_gbc.insets = new Insets(5,15,2,0); m_gbc.fill = GridBagConstraints.HORIZONTAL; 348 f_Description.setFont(f_Description.getFont().deriveFont(Font.ITALIC)); 349 parameterPanel.add(f_Description, m_gbc); 350 351 m_query = new MQuery(); 353 m_query.addRestriction("C_AcctSchema_ID", MQuery.EQUAL, C_AcctSchema_ID); 354 m_query.addRestriction("IsFullyQualified", MQuery.EQUAL, "Y"); 355 if (m_mAccount.C_ValidCombination_ID == 0) 356 m_mTab.setQuery(MQuery.getEqualQuery("1", "2")); 357 else 358 m_mTab.setQuery(MQuery.getEqualQuery("C_ValidCombination_ID", m_mAccount.C_ValidCombination_ID)); 359 m_mTab.query(false); 360 m_gridController.getTable().addMouseListener(new VAccountDialog_mouseAdapter(this)); 361 m_gridController.addDataStatusListener(this); 362 363 statusBar.setStatusLine(s_AcctSchema.toString()); 364 statusBar.setStatusDB("?"); 365 366 if (m_mAccount.C_ValidCombination_ID != 0) 368 m_mTab.navigate(0); 369 370 Log.trace(Log.l4_Data, "VAccountDialog.initAccount - fini"); 371 return true; 372 } 374 381 private void addLine (MField field, VEditor editor, boolean mandatory) 382 { 383 Log.trace(Log.l6_Database, "VAccountDialog.addLine", "Field=" + field); 384 JLabel label = VEditorFactory.getLabel(field); 385 label.setLabelFor((Component)editor); 386 editor.setReadWrite(true); 387 editor.setMandatory(mandatory); 388 field.addPropertyChangeListener(editor); 390 391 if (m_newRow) 393 { 394 m_gbc.gridy = m_line++; 395 m_gbc.gridx = 0; 396 } 397 else 398 m_gbc.gridx = 2; 399 m_gbc.insets = m_labelInsets; 400 m_gbc.fill = GridBagConstraints.HORIZONTAL; 401 parameterPanel.add(label, m_gbc); 402 403 if (m_newRow) 405 m_gbc.gridx = 1; 406 else 407 m_gbc.gridx = 3; 408 m_gbc.insets = m_fieldInsets; 409 m_gbc.fill = GridBagConstraints.NONE; 410 parameterPanel.add((Component)editor, m_gbc); 411 m_newRow = !m_newRow; 413 } 415 419 private void loadInfo (int C_ValidCombination_ID) 420 { 421 Log.trace(Log.l5_DData, "VAccountDialog.loadInfo - " + C_ValidCombination_ID); 422 String SQL = "SELECT * FROM C_ValidCombination WHERE C_ValidCombination_ID=?"; 423 try 424 { 425 PreparedStatement pstmt = DB.prepareStatement(SQL); 426 pstmt.setInt(1, C_ValidCombination_ID); 427 ResultSet rs = pstmt.executeQuery(); 428 if (rs.next()) 429 { 430 if (f_Alias != null) 431 f_Alias.setValue(rs.getString("Alias")); 432 f_Combination.setValue(rs.getString("Combination")); 433 loadInfoOf (rs, f_AD_Org_ID, "AD_Org_ID"); 435 loadInfoOf (rs, f_Account_ID, "Account_ID"); 436 loadInfoOf (rs, f_M_Product_ID, "M_Product_ID"); 438 loadInfoOf (rs, f_C_BPartner_ID, "C_BPartner_ID"); 439 loadInfoOf (rs, f_C_Campaign_ID, "C_Campaign_ID"); 440 loadInfoOf (rs, f_C_LocFrom_ID, "C_LocFrom_ID"); 441 loadInfoOf (rs, f_C_LocTo_ID, "C_LocTo_ID"); 442 loadInfoOf (rs, f_C_Project_ID, "C_Project_ID"); 443 loadInfoOf (rs, f_C_SalesRegion_ID, "C_SalesRegion_ID"); 444 loadInfoOf (rs, f_AD_OrgTrx_ID, "AD_OrgTrx_ID"); 445 loadInfoOf (rs, f_C_Activity_ID, "C_Activity_ID"); 446 loadInfoOf (rs, f_User1_ID, "User1_ID"); 447 loadInfoOf (rs, f_User2_ID, "User2_ID"); 448 f_Description.setText (rs.getString("Description")); 450 } 451 rs.close(); 452 pstmt.close(); 453 } 454 catch (SQLException e) 455 { 456 Log.error ("VAccountDialog.loadInfo", e); 457 } 458 } 460 467 private void loadInfoOf (ResultSet rs, VEditor editor, String name) throws SQLException 468 { 469 if (editor == null) 470 return; 471 int intValue = rs.getInt(name); 472 if (rs.wasNull()) 473 editor.setValue(null); 474 else 475 editor.setValue(new Integer (intValue)); 476 } 478 479 482 public void dispose() 483 { 484 saveSelection(); 485 if (m_gridController != null) 487 m_gridController.dispose(); 488 m_gridController = null; 489 m_mTab = null; 491 if (m_mWindow != null) 492 m_mWindow.dispose(); 493 m_mWindow = null; 494 495 removeAll(); 496 Env.clearWinContext(m_WindowNo); 497 super.dispose(); 498 } 500 503 private void saveSelection() 504 { 505 if (m_changed && m_gridController != null) 506 { 507 int row = m_gridController.getTable().getSelectedRow(); 508 if (row >= 0) 509 m_C_ValidCombination_ID = ((Integer )m_mTab.getValue(row, "C_ValidCombination_ID")).intValue(); 510 Log.trace(Log.l4_Data, "VAccountDialog.saveSelection (" + row + ") - " + m_C_ValidCombination_ID); 511 } 512 } 514 518 public void actionPerformed(ActionEvent e) 519 { 520 if (e.getActionCommand().equals(ConfirmPanel.A_OK)) 521 { 522 m_changed = true; 523 dispose(); 524 } 525 else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) 526 { 527 m_changed = false; 528 dispose(); 529 } 530 else if (e.getSource() == bSave) 532 action_Save(); 533 else if (e.getSource() == bIgnore) 534 action_Ignore(); 535 else 537 action_Find (true); 538 539 } 541 542 546 public void dataStatusChanged (DataStatusEvent e) 547 { 548 Log.trace(Log.l4_Data, "VAccountDialog.dataStatusChanged", e.toString()); 549 String info = (String )m_mTab.getValue("Description"); 550 f_Description.setText (info); 551 } 558 559 565 private void action_Find (boolean includeAliasCombination) 566 { 567 Log.trace(Log.l1_User, "VAccountDialog.action_Find"); 568 setCursor (Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 569 570 MQuery query = null; 572 if (m_query != null) 573 query = m_query.deepCopy(); 574 else 575 query = new MQuery(); 576 if (includeAliasCombination && f_Alias != null && f_Alias.getValue().toString().length() > 0) 578 { 579 String value = f_Alias.getValue().toString().toUpperCase(); 580 if (!value.endsWith("%")) 581 value += "%"; 582 query.addRestriction("UPPER(Alias)", MQuery.LIKE, value); 583 } 584 if (includeAliasCombination && f_Combination.getValue().toString().length() > 0) 586 { 587 String value = f_Combination.getValue().toString().toUpperCase(); 588 if (!value.endsWith("%")) 589 value += "%"; 590 query.addRestriction("UPPER(Combination)", MQuery.LIKE, value); 591 } 592 if (f_AD_Org_ID.getValue() != null) 594 query.addRestriction("AD_Org_ID", MQuery.EQUAL, f_AD_Org_ID.getValue()); 595 if (f_Account_ID.getValue() != null) 597 query.addRestriction("Account_ID", MQuery.EQUAL, f_Account_ID.getValue()); 598 599 if (f_M_Product_ID != null && f_M_Product_ID.getValue() != null) 601 query.addRestriction("M_Product_ID", MQuery.EQUAL, f_M_Product_ID.getValue()); 602 if (f_C_BPartner_ID != null && f_C_BPartner_ID.getValue() != null) 604 query.addRestriction("C_BPartner_ID", MQuery.EQUAL, f_C_BPartner_ID.getValue()); 605 if (f_C_Campaign_ID != null && f_C_Campaign_ID.getValue() != null) 607 query.addRestriction("C_Campaign_ID", MQuery.EQUAL, f_C_Campaign_ID.getValue()); 608 if (f_C_LocFrom_ID != null && f_C_LocFrom_ID.getValue() != null) 610 query.addRestriction("C_LocFrom_ID", MQuery.EQUAL, f_C_LocFrom_ID.getValue()); 611 if (f_C_LocTo_ID != null && f_C_LocTo_ID.getValue() != null) 613 query.addRestriction("C_LocTo_ID", MQuery.EQUAL, f_C_LocTo_ID.getValue()); 614 if (f_C_Project_ID != null && f_C_Project_ID.getValue() != null) 616 query.addRestriction("C_Project_ID", MQuery.EQUAL, f_C_Project_ID.getValue()); 617 if (f_C_SalesRegion_ID != null && f_C_SalesRegion_ID.getValue() != null) 619 query.addRestriction("C_SalesRegion_ID", MQuery.EQUAL, f_C_SalesRegion_ID.getValue()); 620 if (f_AD_OrgTrx_ID != null && f_AD_OrgTrx_ID.getValue() != null) 622 query.addRestriction("AD_OrgTrx_ID", MQuery.EQUAL, f_AD_OrgTrx_ID.getValue()); 623 if (f_C_Activity_ID != null && f_C_Activity_ID.getValue() != null) 625 query.addRestriction("C_Activity_ID", MQuery.EQUAL, f_C_Activity_ID.getValue()); 626 if (f_User1_ID != null && f_User1_ID.getValue() != null) 628 query.addRestriction("User1_ID", MQuery.EQUAL, f_User1_ID.getValue()); 629 if (f_User2_ID != null && f_User2_ID.getValue() != null) 631 query.addRestriction("User2_ID", MQuery.EQUAL, f_User2_ID.getValue()); 632 633 m_mTab.setQuery(query); 635 m_mTab.query(false); 636 statusBar.setStatusDB(String.valueOf(m_mTab.getRowCount())); 637 setCursor (Cursor.getDefaultCursor()); 638 } 640 641 644 private void action_Save() 645 { 646 Log.trace(Log.l1_User, "VAccountDialog.action_Save"); 647 650 StringBuffer sb = new StringBuffer (); 651 StringBuffer sql = new StringBuffer ("SELECT C_ValidCombination_ID, Alias FROM C_ValidCombination WHERE "); 652 Object value = null; 653 if (s_AcctSchema.hasAlias()) 654 { 655 value = f_Alias.getValue().toString(); 656 if (value == null) 657 sb.append(Msg.translate(Env.getCtx(), "Alias")).append(", "); 658 } 659 ArrayList ase_list = s_AcctSchema.getAcctSchemaElementList(); 660 for (int i = 0; i < ase_list.size(); i++) 661 { 662 AcctSchemaElement ase = (AcctSchemaElement)ase_list.get(i); 663 String type = ase.getSegmentType(); 664 if (type.equals(AcctSchemaElement.SEGMENT_Org)) 666 { 667 value = f_AD_Org_ID.getValue(); 668 sql.append("AD_Org_ID"); 669 if (value == null) 670 sql.append(" IS NULL AND "); 671 else 672 sql.append("=").append(value).append(" AND "); 673 } 674 else if (type.equals(AcctSchemaElement.SEGMENT_Account)) 675 { 676 value = f_Account_ID.getValue(); 677 sql.append("Account_ID"); 678 if (value == null) 679 sql.append(" IS NULL AND "); 680 else 681 sql.append("=").append(value).append(" AND "); 682 } 683 else if (type.equals(AcctSchemaElement.SEGMENT_Product)) 684 { 685 value = f_M_Product_ID.getValue(); 686 sql.append("M_Product_ID"); 687 if (value == null) 688 sql.append(" IS NULL AND "); 689 else 690 sql.append("=").append(value).append(" AND "); 691 } 692 else if (type.equals(AcctSchemaElement.SEGMENT_BPartner)) 693 { 694 value = f_C_BPartner_ID.getValue(); 695 sql.append("C_BPartner_ID"); 696 if (value == null) 697 sql.append(" IS NULL AND "); 698 else 699 sql.append("=").append(value).append(" AND "); 700 } 701 else if (type.equals(AcctSchemaElement.SEGMENT_Campaign)) 702 { 703 value = f_C_Campaign_ID.getValue(); 704 sql.append("C_Campaign_ID"); 705 if (value == null) 706 sql.append(" IS NULL AND "); 707 else 708 sql.append("=").append(value).append(" AND "); 709 } 710 else if (type.equals(AcctSchemaElement.SEGMENT_LocationFrom)) 711 { 712 value = f_C_LocFrom_ID.getValue(); 713 sql.append("C_LocFrom_ID"); 714 if (value == null) 715 sql.append(" IS NULL AND "); 716 else 717 sql.append("=").append(value).append(" AND "); 718 } 719 else if (type.equals(AcctSchemaElement.SEGMENT_LocationTo)) 720 { 721 value = f_C_LocTo_ID.getValue(); 722 sql.append("C_LocTo_ID"); 723 if (value == null) 724 sql.append(" IS NULL AND "); 725 else 726 sql.append("=").append(value).append(" AND "); 727 } 728 else if (type.equals(AcctSchemaElement.SEGMENT_Project)) 729 { 730 value = f_C_Project_ID.getValue(); 731 sql.append("C_Project_ID"); 732 if (value == null) 733 sql.append(" IS NULL AND "); 734 else 735 sql.append("=").append(value).append(" AND "); 736 } 737 else if (type.equals(AcctSchemaElement.SEGMENT_SalesRegion)) 738 { 739 value = f_C_SalesRegion_ID.getValue(); 740 sql.append("C_SalesRegion_ID"); 741 if (value == null) 742 sql.append(" IS NULL AND "); 743 else 744 sql.append("=").append(value).append(" AND "); 745 } 746 else if (type.equals(AcctSchemaElement.SEGMENT_OrgTrx)) 747 { 748 value = f_AD_OrgTrx_ID.getValue(); 749 sql.append("AD_OrgTrx_ID"); 750 if (value == null) 751 sql.append(" IS NULL AND "); 752 else 753 sql.append("=").append(value).append(" AND "); 754 } 755 else if (type.equals(AcctSchemaElement.SEGMENT_Activity)) 756 { 757 value = f_C_Activity_ID.getValue(); 758 sql.append("C_Activity_ID"); 759 if (value == null) 760 sql.append(" IS NULL AND "); 761 else 762 sql.append("=").append(value).append(" AND "); 763 } 764 else if (type.equals(AcctSchemaElement.SEGMENT_User1)) 765 { 766 value = f_User1_ID.getValue(); 767 sql.append("User1_ID"); 768 if (value == null) 769 sql.append(" IS NULL AND "); 770 else 771 sql.append("=").append(value).append(" AND "); 772 } 773 else if (type.equals(AcctSchemaElement.SEGMENT_User2)) 774 { 775 value = f_User2_ID.getValue(); 776 sql.append("User2_ID"); 777 if (value == null) 778 sql.append(" IS NULL AND "); 779 else 780 sql.append("=").append(value).append(" AND "); 781 } 782 if (ase.isMandatory() && value == null) 784 sb.append(ase.getName()).append(", "); 785 } 787 if (sb.length() != 0) 788 { 789 ADialog.error(m_WindowNo, this, "FillMandatory", sb.substring(0, sb.length()-2)); 790 return; 791 } 792 793 796 sql.append("AD_Client_ID=").append(m_AD_Client_ID); 797 Log.trace(Log.l6_Database, "VAccountDialog.action_Save check = " + sql.toString()); 798 int IDvalue = 0; 799 String Alias = null; 800 try 801 { 802 Statement stmt = DB.createStatement(); 803 ResultSet rs = stmt.executeQuery(sql.toString()); 804 if (rs.next()) 805 { 806 IDvalue = rs.getInt(1); 807 Alias = rs.getString(2); 808 } 809 rs.close(); 810 stmt.close(); 811 } 812 catch (SQLException e) 813 { 814 Log.error ("VAccountDialog.action_Save SQL=" + sql.toString(), e); 815 IDvalue = 0; 816 } 817 Log.trace(Log.l6_Database, "VAccountDialog.action_Save ID=" + IDvalue + ", Alias=" + Alias); 818 819 if (Alias == null) 820 Alias = ""; 821 822 if (IDvalue != 0 && s_AcctSchema.hasAlias() 824 && !f_Alias.getValue().toString().equals(Alias)) 825 { 826 sql = new StringBuffer ("UPDATE C_ValidCombination SET Alias="); 827 if (f_Alias.getValue().toString().length() == 0) 828 sql.append("NULL"); 829 else 830 sql.append("'").append(f_Alias.getValue()).append("'"); 831 sql.append(" WHERE C_ValidCombination_ID=").append(IDvalue); 832 int i = 0; 833 try 834 { 835 Statement stmt = DB.createStatement(); 836 i = stmt.executeUpdate(sql.toString()); 837 stmt.close(); 838 } 839 catch (SQLException e) 840 { 841 Log.error ("VAccountDialog.action_Save SQL=" + sql.toString(), e); 842 } 843 if (i == 0) 844 ADialog.error(m_WindowNo, this, "AccountNotUpdated"); 845 } 846 847 if (IDvalue != 0) 849 { 850 loadInfo (IDvalue); 851 action_Find (false); 852 return; 853 } 854 855 Log.trace(Log.l3_Util, "VAccountDialog.action_Save - create new"); 856 Alias = null; 857 if (f_Alias != null) 858 Alias = f_Alias.getValue().toString(); 859 int M_Product_ID = 0; 860 if (f_M_Product_ID != null && f_M_Product_ID.getValue() != null) 861 M_Product_ID = ((Integer )f_M_Product_ID.getValue()).intValue(); 862 int C_BPartner_ID = 0; 863 if (f_C_BPartner_ID != null && f_C_BPartner_ID.getValue() != null) 864 C_BPartner_ID = ((Integer )f_C_BPartner_ID.getValue()).intValue(); 865 int AD_OrgTrx_ID = 0; 866 if (f_AD_OrgTrx_ID != null && f_AD_OrgTrx_ID.getValue() != null) 867 AD_OrgTrx_ID = ((Integer )f_AD_OrgTrx_ID.getValue()).intValue(); 868 int C_LocFrom_ID = 0; 869 if (f_C_LocFrom_ID != null && f_C_LocFrom_ID.getValue() != null) 870 C_LocFrom_ID = ((Integer )f_C_LocFrom_ID.getValue()).intValue(); 871 int C_LocTo_ID = 0; 872 if (f_C_LocTo_ID != null && f_C_LocTo_ID.getValue() != null) 873 C_LocTo_ID = ((Integer )f_C_LocTo_ID.getValue()).intValue(); 874 int C_SRegion_ID = 0; 875 if (f_C_SalesRegion_ID != null && f_C_SalesRegion_ID.getValue() != null) 876 C_SRegion_ID = ((Integer )f_C_SalesRegion_ID.getValue()).intValue(); 877 int C_Project_ID = 0; 878 if (f_C_Project_ID != null && f_C_Project_ID.getValue() != null) 879 C_Project_ID= ((Integer )f_C_Project_ID.getValue()).intValue(); 880 int C_Campaign_ID = 0; 881 if (f_C_Campaign_ID != null && f_C_Campaign_ID.getValue() != null) 882 C_Campaign_ID = ((Integer )f_C_Campaign_ID.getValue()).intValue(); 883 int C_Activity_ID = 0; 884 if (f_C_Activity_ID != null && f_C_Activity_ID.getValue() != null) 885 C_Activity_ID = ((Integer )f_C_Activity_ID.getValue()).intValue(); 886 int User1_ID = 0; 887 if (f_User1_ID != null && f_User1_ID.getValue() != null) 888 User1_ID = ((Integer )f_User1_ID.getValue()).intValue(); 889 int User2_ID = 0; 890 if (f_User2_ID != null && f_User2_ID.getValue() != null) 891 User2_ID = ((Integer )f_User2_ID.getValue()).intValue(); 892 893 int retValue = DB.getValidCombination(m_AD_Client_ID, ((Integer )f_AD_Org_ID.getValue()).intValue(), 894 s_AcctSchema.getC_AcctSchema_ID(), ((Integer )f_Account_ID.getValue()).intValue(), 0, 895 Alias, Env.getContextAsInt(Env.getCtx(), "#AD_User_ID"), M_Product_ID, C_BPartner_ID, AD_OrgTrx_ID, 896 C_LocFrom_ID, C_LocTo_ID, C_SRegion_ID, C_Project_ID, 897 C_Campaign_ID, C_Activity_ID, User1_ID, User2_ID); 898 899 loadInfo (retValue); 901 action_Find (false); 902 } 904 905 908 private void action_Ignore() 909 { 910 if (f_Alias != null) 911 f_Alias.setValue(""); 912 f_Combination.setValue(""); 913 f_Description.setText(""); 914 f_AD_Org_ID.setValue(null); 917 f_Account_ID.setValue(null); 919 920 if (f_M_Product_ID != null) 922 f_M_Product_ID.setValue(null); 923 if (f_C_BPartner_ID != null) 925 f_C_BPartner_ID.setValue(null); 926 if (f_C_Campaign_ID != null) 928 f_C_Campaign_ID.setValue(null); 929 if (f_C_LocFrom_ID != null) 931 f_C_LocFrom_ID.setValue(null); 932 if (f_C_LocTo_ID != null) 934 f_C_LocTo_ID.setValue(null); 935 if (f_C_Project_ID != null) 937 f_C_Project_ID.setValue(null); 938 if (f_C_SalesRegion_ID != null) 940 f_C_SalesRegion_ID.setValue(null); 941 if (f_AD_OrgTrx_ID != null) 943 f_AD_OrgTrx_ID.setValue(null); 944 if (f_C_Activity_ID != null) 946 f_C_Activity_ID.setValue(null); 947 if (f_User1_ID != null) 949 f_User1_ID.setValue(null); 950 if (f_User2_ID != null) 952 f_User2_ID.setValue(null); 953 } 955 959 public Integer getValue() 960 { 961 Log.trace(Log.l3_Util, "VAccountDialog.getValue", "C_ValidCombination_ID=" + m_C_ValidCombination_ID + ", Changed=" + m_changed); 962 if (!m_changed || m_C_ValidCombination_ID == 0) 963 return null; 964 return new Integer (m_C_ValidCombination_ID); 965 } 966 967 } 969 972 class VAccountDialog_mouseAdapter extends java.awt.event.MouseAdapter 973 { 974 VAccountDialog_mouseAdapter(VAccountDialog adaptee) 975 { 976 this.adaptee = adaptee; 977 } 978 979 VAccountDialog adaptee; 980 981 public void mouseClicked(MouseEvent e) 982 { 983 if (e.getSource() instanceof JTable && e.getClickCount() > 1) 985 { 986 adaptee.m_changed = true; 987 adaptee.dispose(); 988 } 989 } 990 } | Popular Tags |