1 14 package org.compiere.apps.form; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import javax.swing.*; 19 import java.sql.*; 20 import java.io.*; 21 22 import org.compiere.util.*; 23 import org.compiere.apps.*; 24 import org.compiere.apps.*; 25 import org.compiere.model.*; 26 import org.compiere.plaf.*; 27 import org.compiere.print.*; 28 import org.compiere.swing.*; 29 30 36 public class VSetup extends CPanel 37 implements FormPanel, ActionListener 38 { 39 42 public VSetup() 43 { 44 } 46 51 public void init (int WindowNo, FormFrame frame) 52 { 53 Log.trace(Log.l1_User, "VSetup.init"); 54 m_WindowNo = WindowNo; 55 m_frame = frame; 56 try 57 { 58 jbInit(); 59 dynInit(); 60 frame.getContentPane().add(centerPane, BorderLayout.CENTER); 61 frame.getContentPane().add(confirmPanel, BorderLayout.SOUTH); 62 } 63 catch(Exception e) 64 { 65 Log.error("VSetup.init", e); 66 } 67 } 69 70 private int m_WindowNo = 0; 71 72 private FormFrame m_frame; 73 74 75 private File m_file = null; 76 77 private JScrollPane centerPane = new JScrollPane(); 79 private ConfirmPanel confirmPanel = new ConfirmPanel(true); 80 private CPanel centerPanel = new CPanel(); 81 private GridBagLayout centerLayout = new GridBagLayout(); 82 private JLabel lClientName = new JLabel(); 83 private JTextField fClientName = new JTextField(); 84 private JLabel lOrgName = new JLabel(); 85 private JTextField fOrgName = new JTextField(); 86 private JLabel lCurrency = new JLabel(); 87 private JComboBox fCurrency = new JComboBox(); 88 private JLabel lUserClient = new JLabel(); 89 private JTextField fUserClient = new JTextField(); 90 private JLabel lUserOrg = new JLabel(); 91 private JTextField fUserOrg = new JTextField(); 92 private JCheckBox fProject = new JCheckBox(); 93 private JCheckBox fProduct = new JCheckBox(); 94 private JCheckBox fBPartner = new JCheckBox(); 95 private JLabel lAccountSeg = new JLabel(); 96 private JCheckBox fMCampaign = new JCheckBox(); 97 private JCheckBox fSRegion = new JCheckBox(); 98 private JButton buttonLoadAcct = new JButton(); 99 private JLabel lCountry = new JLabel(); 100 private JLabel lCity = new JLabel(); 101 private JComboBox fCountry = new JComboBox(); 102 private JTextField fCity = new JTextField(); 103 private JLabel lRegion = new JLabel(); 104 private JComboBox fRegion = new JComboBox(); 105 106 110 private void jbInit() throws Exception 111 { 112 CompiereColor.setBackground(this); 113 centerPanel.setLayout(centerLayout); 114 String optional = Msg.translate(Env.getCtx(), "Optional"); 115 lClientName.setLabelFor(fClientName); 117 lClientName.setText(Msg.translate(Env.getCtx(), "AD_Client_ID")); 118 fClientName.setText("client"); 120 fClientName.setColumns(20); 121 lOrgName.setLabelFor(fOrgName); 123 lOrgName.setText(Msg.translate(Env.getCtx(), "AD_Org_ID")); 124 fOrgName.setText("org"); 125 fOrgName.setColumns(20); 126 lCurrency.setLabelFor(fCurrency); 128 lCurrency.setText(Msg.translate(Env.getCtx(), "C_Currency_ID")); 129 lUserClient.setLabelFor(fUserClient); 132 lUserClient.setText(Msg.parseTranslation(Env.getCtx(), "@AD_User_ID@ @AD_Client_ID@")); 133 fUserClient.setText("clientAdmin"); 135 fUserClient.setColumns(20); 136 lUserOrg.setLabelFor(fUserOrg); 138 lUserOrg.setText(Msg.parseTranslation(Env.getCtx(), "@AD_User_ID@ @AD_Org_ID@")); 139 fUserOrg.setText("clientUser"); 141 fUserOrg.setColumns(20); 142 lCountry.setLabelFor(fCountry); 144 lCountry.setText(Msg.translate(Env.getCtx(), "C_Country_ID")); 145 lCity.setLabelFor(fCity); 146 lCity.setText(Msg.translate(Env.getCtx(), "C_City_ID")); 147 fCity.setText("city"); 148 fCity.setColumns(20); 149 lRegion.setLabelFor(fRegion); 150 lRegion.setText(Msg.translate(Env.getCtx(), "C_Region_ID")); 151 lRegion.setToolTipText(optional); 152 lAccountSeg.setText(optional); 154 fBPartner.setSelected(true); 155 fBPartner.setText(Msg.translate(Env.getCtx(), "C_BPartner_ID")); 156 fProduct.setSelected(true); 157 fProduct.setText(Msg.translate(Env.getCtx(), "M_Product_ID")); 158 fProject.setText(Msg.translate(Env.getCtx(), "C_Project_ID")); 159 fMCampaign.setText(Msg.translate(Env.getCtx(), "C_Campaign_ID")); 160 fSRegion.setText(Msg.translate(Env.getCtx(), "C_SalesRegion_ID")); 161 buttonLoadAcct.setText(Msg.getMsg(Env.getCtx(), "LoadAccountingValues")); 163 164 centerPane.getViewport().add(centerPanel, null); 165 centerPanel.add(lClientName, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 166 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 167 centerPanel.add(fClientName, new GridBagConstraints(1, 0, 4, 1, 0.0, 0.0 168 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); 169 centerPanel.add(lOrgName, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 170 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); 171 centerPanel.add(fOrgName, new GridBagConstraints(1, 1, 4, 1, 0.0, 0.0 172 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); 173 centerPanel.add(lUserClient, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 174 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); 175 centerPanel.add(fUserClient, new GridBagConstraints(1, 2, 4, 1, 0.0, 0.0 176 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); 177 centerPanel.add(lUserOrg, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 178 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); 179 centerPanel.add(fUserOrg, new GridBagConstraints(1, 3, 2, 1, 0.0, 0.0 180 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); 181 centerPanel.add(lAccountSeg, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0 182 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); 183 centerPanel.add(fProject, new GridBagConstraints(1, 9, 3, 1, 0.0, 0.0 184 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); 185 centerPanel.add(fBPartner, new GridBagConstraints(1, 8, 1, 1, 0.0, 0.0 186 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); 187 centerPanel.add(fMCampaign, new GridBagConstraints(1, 10, 1, 1, 0.0, 0.0 188 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); 189 centerPanel.add(fCurrency, new GridBagConstraints(1, 4, 2, 1, 0.0, 0.0 190 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); 191 centerPanel.add(lCurrency, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0 192 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); 193 centerPanel.add(buttonLoadAcct, new GridBagConstraints(1, 11, 2, 1, 0.0, 0.0 194 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); 195 centerPanel.add(lCountry, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0 196 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); 197 centerPanel.add(lCity, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0 198 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); 199 centerPanel.add(fCountry, new GridBagConstraints(1, 5, 3, 1, 0.0, 0.0 200 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); 201 centerPanel.add(fCity, new GridBagConstraints(1, 6, 3, 1, 0.0, 0.0 202 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); 203 centerPanel.add(fProduct, new GridBagConstraints(2, 8, 1, 1, 0.0, 0.0 204 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 0), 0, 0)); 205 centerPanel.add(fSRegion, new GridBagConstraints(2, 10, 1, 1, 0.0, 0.0 206 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); 207 centerPanel.add(lRegion, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0 208 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); 209 centerPanel.add(fRegion, new GridBagConstraints(1, 7, 2, 1, 0.0, 0.0 210 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); 211 } 213 216 private void dynInit() 217 { 218 String sql = "SELECT C_Currency_ID, Description FROM C_Currency ORDER BY 1"; try 221 { 222 Statement stmt = DB.createStatement(); 223 ResultSet rs = stmt.executeQuery(sql); 224 while (rs.next()) 225 fCurrency.addItem(new KeyNamePair(rs.getInt(1) , rs.getString(2))); 226 rs.close(); 227 stmt.close(); 228 } 229 catch (SQLException e1) 230 { 231 Log.error ("VSetup.dynInit -currency", e1); 232 } 233 fCurrency.setSelectedIndex(0); 234 235 sql = "SELECT C_Country_ID, Name FROM C_Country ORDER BY 1"; try 238 { 239 Statement stmt = DB.createStatement(); 240 ResultSet rs = stmt.executeQuery(sql); 241 while (rs.next()) 242 fCountry.addItem(new KeyNamePair(rs.getInt(1) , rs.getString(2))); 243 rs.close(); 244 stmt.close(); 245 } 246 catch (SQLException e1) 247 { 248 Log.error ("VSetup.dynInit -country", e1); 249 } 250 fCountry.setSelectedIndex(0); 251 252 sql = "SELECT C_Region_ID, Name FROM C_Region ORDER BY C_Country_ID, Name"; 254 try 255 { 256 fRegion.addItem(new KeyNamePair(0, " ")); 257 Statement stmt = DB.createStatement(); 258 ResultSet rs = stmt.executeQuery(sql); 259 while (rs.next()) 260 fRegion.addItem(new KeyNamePair(rs.getInt(1) , rs.getString(2))); 261 rs.close(); 262 stmt.close(); 263 } 264 catch (SQLException e1) 265 { 266 Log.error ("VSetup.dynInit -region", e1); 267 } 268 fRegion.setSelectedIndex(0); 269 270 confirmPanel.addActionListener(this); 272 buttonLoadAcct.addActionListener(this); 273 confirmPanel.getOKButton().setEnabled(false); 274 } 276 279 public void dispose() 280 { 281 m_frame.dispose(); 282 } 284 288 public void actionPerformed (ActionEvent e) 289 { 290 if (e.getSource().equals(buttonLoadAcct)) 292 m_file = getFile(); 293 else if (e.getActionCommand().equals(ConfirmPanel.A_OK) && m_file != null) 295 { 296 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 297 confirmPanel.getCancelButton().setEnabled(false); 298 confirmPanel.getOKButton().setEnabled(false); 299 if (createSetup()) 300 dispose(); 301 setCursor(Cursor.getDefaultCursor()); 302 confirmPanel.getCancelButton().setEnabled(true); 303 confirmPanel.getOKButton().setEnabled(true); 304 } 305 else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) 307 dispose(); 308 } 310 314 private File getFile() 315 { 316 File file = null; 317 String dirName = org.compiere.Compiere.getCompiereHome() + File.separator + "data" + File.separator + "import"; 318 Log.trace(Log.l4_Data, "VSetup.getFile", dirName); 319 JFileChooser chooser = new JFileChooser(dirName); 320 chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); 321 chooser.setMultiSelectionEnabled(false); 322 chooser.setDialogTitle(Msg.translate(Env.getCtx(), "LoadAccountingValues")); 323 chooser.addChoosableFileFilter(new ExtensionFileFilter("csv", "Comma Separated Values (*.csv)")); 324 file = new File(dirName + File.pathSeparator + "AccountingUS.csv"); 326 if (file.exists()) 327 chooser.setSelectedFile(file); 328 329 if (chooser.showOpenDialog(this.getParent()) == JFileChooser.APPROVE_OPTION) 331 file = chooser.getSelectedFile(); 332 else 333 file = null; 334 chooser = null; 335 336 if (file == null) 337 buttonLoadAcct.setText(Msg.translate(Env.getCtx(), "LoadAccountingValues")); 338 else 339 buttonLoadAcct.setText(file.getAbsolutePath()); 340 confirmPanel.getOKButton().setEnabled(file != null); 341 m_frame.pack(); 342 return file; 343 } 345 346 347 351 private boolean createSetup() 352 { 353 fClientName.setText(fClientName.getText().replace('\'','"')); 355 fClientName.setText(fClientName.getText().replace('\\','/')); 356 fOrgName.setText(fOrgName.getText().replace('\'','"')); 357 fOrgName.setText(fOrgName.getText().replace('\\','/')); 358 fUserClient.setText(fUserClient.getText().replace('\'','"')); 359 fUserClient.setText(fUserClient.getText().replace('\\','/')); 360 fUserOrg.setText(fUserOrg.getText().replace('\'','"')); 361 fUserOrg.setText(fUserOrg.getText().replace('\\','/')); 362 363 String SQL = "UPDATE AD_CLient SET CreatedBy=0 WHERE Name='" + fClientName.getText() + "'"; 365 if (DB.executeUpdate(SQL) != 0) 366 { 367 fClientName.setBackground(CompierePLAF.getFieldBackground_Error()); 368 ADialog.error(m_WindowNo, this, "NotUnique", lClientName.getText()); 369 return false; 370 } 371 fClientName.setBackground(CompierePLAF.getFieldBackground_Normal()); 372 373 384 385 SQL = "UPDATE AD_User SET CreatedBy=0 WHERE Name='" + fUserClient.getText() + "'"; 387 if (DB.executeUpdate(SQL) != 0) 388 { 389 fUserClient.setBackground(CompierePLAF.getFieldBackground_Error()); 390 ADialog.error(m_WindowNo, this, "NotUnique", lUserClient.getText()); 391 return false; 392 } 393 fUserClient.setBackground(CompierePLAF.getFieldBackground_Normal()); 394 SQL = "UPDATE AD_User SET CreatedBy=0 WHERE Name='" + fUserOrg.getText() + "'"; 395 if (DB.executeUpdate(SQL) != 0 || fUserClient.getText().equals(fUserOrg.getText())) 396 { 397 fUserOrg.setBackground(CompierePLAF.getFieldBackground_Error()); 398 ADialog.error(m_WindowNo, this, "NotUnique", lUserOrg.getText()); 399 return false; 400 } 401 fUserOrg.setBackground(CompierePLAF.getFieldBackground_Normal()); 402 403 406 MSetup ms = new MSetup(Env.getCtx(), m_WindowNo); 407 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 408 boolean ok = ms.createClient(fClientName.getText(), fOrgName.getText(), 410 fUserClient.getText(), fUserOrg.getText()); 411 String info = ms.getInfo(); 412 413 if (ok) 414 { 415 KeyNamePair p = (KeyNamePair)fCurrency.getSelectedItem(); 417 ms.createAccounting(p.getKey(), p.getName(), 418 fProduct.isSelected(), fBPartner.isSelected(), fProject.isSelected(), 419 fMCampaign.isSelected(), fSRegion.isSelected(), 420 m_file); 421 p = (KeyNamePair)fCountry.getSelectedItem(); 423 int C_Country_ID = p.getKey(); 424 p = (KeyNamePair)fRegion.getSelectedItem(); 425 int C_Region_ID = p.getKey(); 426 ms.createEntities(C_Country_ID, fCity.getText(), C_Region_ID); 427 info += ms.getInfo(); 428 PrintUtil.setupPrintForm(ms.getAD_Client_ID()); 430 } 431 432 setCursor(Cursor.getDefaultCursor()); 433 ADialog.info(m_WindowNo, this, "VSetup", info.toString()); 434 return ok; 435 } 437 } | Popular Tags |