home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / JDesignerPro / Jdp3_0.exe / data1.cab / Program_Files / Applications / Layouts / JDPLayout1.java < prev    next >
Encoding:
Text File  |  1999-04-09  |  13.5 KB  |  501 lines

  1. >XXX0455  Total lines for the build status message calculation
  2. //--------------------------------------------------------------------
  3. //                                                                    
  4. >001//  Module:       <JDPModule>                                       
  5. >002//  Description:  <Class Description>
  6. //                                                                    
  7. //--------------------------------------------------------------------
  8.  
  9. import java.awt.*;
  10. import java.applet.*;
  11. import java.util.*;
  12.  
  13.  
  14. >003public class <JDPUserBill> extends JDPClassLayout {
  15.  
  16.     JDPUser user;
  17.     JDPJagg jaggSQL;
  18.     JDPWhereClause jdpWhereClause;
  19.     JDPSearchResults searchResults;
  20.     JDPPopupMessage popuppanel;
  21.     JDPTabSelectPanel tabPanel;
  22.     JDPMaskEdit JDPMaskEditMain;
  23.  
  24.     String[] psortChoice;
  25.     String[] pdisplayChoice;
  26.     int itemIndex;
  27.     boolean insertRequested = false;
  28.     boolean deleteRequested = false;
  29.     String pfromWhereClause;
  30.  
  31.     Vector pmatchUsing;
  32.     Vector pactualmatchUsing;
  33.     //
  34.     //  Declare screen components
  35.     //
  36. >004    <TextField username>;
  37.  
  38.  
  39.     public void InitClass(JDPUser user, Panel targetPanel, String moduleParameter) {
  40.  
  41.         this.user = user;
  42.         //
  43.         //  Set JAGG settings for this class
  44.         //
  45.         jaggSQL = new JDPJagg(user.jaggPath);
  46.         jaggSQL.setNULL("space");
  47. >997        jaggSQL.setMRW("<maxRows>");
  48. >998        jaggSQL.setDSN("<datasource>");
  49. >984        jaggSQL.setUID("<>");
  50. >985        jaggSQL.setPWD("<>");
  51.  
  52.         setLayout(new BorderLayout());
  53.         setFont(user.plainFont);
  54.          popuppanel = new JDPPopupMessage(user,targetPanel);
  55.         targetPanel.add(popuppanel);
  56.  
  57.         Panel mainPanel = new Panel();
  58.         mainPanel.setLayout(new BorderLayout());
  59.         Panel centerPanel = new Panel();
  60.         centerPanel.setLayout(new BorderLayout());
  61.         Panel centerMainPanel = new Panel();
  62.         centerMainPanel.setLayout(new BorderLayout());
  63.         Panel leftPanel = new Panel();
  64.         leftPanel.setLayout(new BorderLayout());
  65.         
  66.         //
  67.         //  Define parameters for JDPSearchResults
  68.         //
  69. >005        String pselectFields = "<>"; String[] psdisplayFields = {<>};
  70. >006        pfromWhereClause = "<FROM JDPUser WHERE >";
  71.  
  72. >007        psortChoice = new String[<5>];
  73. >008        psortChoice[<0>] = "<username>";
  74.  
  75. >009        String[] psortChoiceText = {<"Sort by User Name","Sort by Card Number">};
  76.         pdisplayChoice = psortChoice;
  77.  
  78. >010        boolean pdisplayCount = <true>;
  79. >011        String pcountText = "<Total Entries:>";
  80.     
  81.         //
  82.         //  Create an instance of screen components
  83.         //
  84. >012        <username> = new <TextField("",20)>;
  85.  
  86.         //
  87.         //  Initialise any choice components
  88.         //
  89.         loadChoices();
  90.  
  91.         //
  92.         //  Add components to the screen
  93.         //
  94. >058        JDPScrollPanel[] centerTopPanel = new JDPScrollPanel[<>];
  95. >059        centerTopPanel[<>] = new JDPScrollPanel();
  96. >013        centerTopPanel[<>].add("Left",new JDPWrapLabel(user,"<User Name:>",Color.<labelColor>));
  97. >014        centerTopPanel[<>].add("Right",centerR<0>);
  98.  
  99.         if (centerTopPanel.length == 1) {
  100.             centerMainPanel.add("Center",centerTopPanel[0]);
  101.         } else {
  102. >060            String[] titles = {<>};
  103.             tabPanel = new JDPTabSelectPanel(user,titles,centerTopPanel,"North");
  104.             centerMainPanel.add("Center",tabPanel);
  105.         }
  106.         
  107.         // 
  108.         //  Set screen component attributes
  109.         //
  110. >039        <username>.setForeground(Color.<fcolor>);
  111. >040        <username>.setBackground(Color.<bcolor>);
  112. >048        popuppanel.addComponent(<>,"<>","<>");
  113.         
  114.         //
  115.         //  Add buttons to the bottom of the panel
  116.         //
  117.         if (moduleParameter.compareTo("Inquiry") == 0) {
  118. >041            <username>.setEditable(false);
  119.         } else {
  120. >042            <username>.setEditable(<editable>);
  121. >015            String buttons[] = {<"   Apply   ","Reset","New","Copy","Remove">};
  122. >047            int icons[] = {<>};
  123.             JDPButtons btns = new JDPButtons(user, buttons, icons, JDPButtons.HORIZONTAL);
  124.             centerMainPanel.add("South",btns);
  125. >046            popuppanel.addComponent(btns.button[<0>],"<>","<>");
  126.         }
  127.         mainPanel.add("Center",centerMainPanel);
  128.         
  129.         //
  130.         //  Define parameters for JDPWhereClause
  131.         //
  132. >016        String[] pchooseFrom = new String[<7>];
  133. >017        pchooseFrom[<0>] = "<Account Name>";
  134.  
  135. >018        String[] pactualchooseFrom = new String[<7>];
  136. >019        pactualchooseFrom[<0>] = "<username>";
  137.  
  138. >024        boolean[] constantIsString = new boolean[<7>];
  139. >025        constantIsString[<0>] = <true>;
  140.  
  141. >026        int[] constantLength = new int[<7>];
  142. >027        constantLength[<0>] = <20>;
  143.  
  144.         //
  145.         //  Add JDPWhereClause search panel
  146.         //
  147.         if (pchooseFrom.length > 0) {
  148. >028            jdpWhereClause = new JDPWhereClause(user, targetPanel, "<UserBill>", true, "<pinitChoice>", pchooseFrom, pactualchooseFrom,
  149.                                                 pmatchUsing, pactualmatchUsing, null, null,
  150.                                                 constantLength, constantIsString);
  151.             leftPanel.add("North",jdpWhereClause);
  152.         }
  153.         //
  154.         //  Add JDPSearchResults result list
  155.         //
  156.         if (psortChoice.length > 0) {
  157. >029            searchResults = new JDPSearchResults(user, targetPanel, <false>, jaggSQL, <false>, pselectFields, psdisplayFields, pfromWhereClause, psortChoiceText, psortChoice, pdisplayChoice, "<pinitChoice>", pdisplayCount, pcountText);
  158. >055            int icons[] = {<>};
  159. >056            searchResults.setMinWidth(<>);
  160.             searchResults.setIcons(icons);
  161.             leftPanel.add("Center",searchResults);
  162.             mainPanel.add("West",leftPanel);
  163.         }
  164.  
  165. >030        add("Center",new JDPChiselFramePanel(user,"<User Billing Details>",mainPanel,"North"));
  166.  
  167.         JDPMaskEditMain = new JDPMaskEdit();
  168.         if (psortChoice.length > 0) {
  169.             newSearch();
  170.         }
  171.  
  172.         //
  173.         //  Add the handle to this panel to the global vector so other panels can
  174.         //  access this one
  175.         //
  176.         user.gParm.addElement(this);
  177.         clearFields();
  178.     }
  179.  
  180.     //
  181.     //  Handle screen events
  182.     //
  183.     public boolean handleEvent(Event e) {
  184.  
  185.         switch (e.id) {
  186.         case Event.ACTION_EVENT:
  187.             if (e.target instanceof List) {
  188.                 if (e.target.equals(searchResults.resultList)) {
  189.                     loadData();
  190.                     return true;
  191.                 }
  192.             }
  193.             if (e.target instanceof JDPTreePicker) {
  194.                 if (e.target.equals(searchResults.tree)) {
  195.                     loadData();
  196.                     return true;
  197.                 }
  198.             }
  199.             if (e.target instanceof Button) {
  200.                 String choice = (String)e.arg;
  201.                 if (choice.trim().compareTo("Apply") == 0) {
  202.                     if (checkFields()) {
  203.                         if (insertRequested) {
  204.                             saveData();
  205.                             newSearch();
  206.                         } else {
  207.                             saveData();
  208.                         }
  209.                     }
  210.                     return true;
  211.                 }
  212.                 if (choice.trim().compareTo("Reset") == 0) {
  213.                     loadData();
  214.                     return true;
  215.                 }
  216.                 if (choice.trim().compareTo("New") == 0) {
  217.                     insertRequested = true;
  218.                     clearFields();
  219.                     return true;
  220.                 }
  221.                 if (choice.trim().compareTo("Submit") == 0) {
  222.                     insertRequested = true;
  223.                     if (checkFields()) {
  224.                         saveData();
  225.                     }
  226.                     return true;
  227.                 }
  228.                 if (choice.trim().compareTo("Copy") == 0) {
  229.                     insertRequested = true;
  230.                     return true;
  231.                 }
  232.                 if (choice.trim().compareTo("Remove") == 0) {
  233. >054                    String removeMsg = "<>";
  234.                     if (removeMsg.equals("") || user.mainmsg.getStatusMsg().equals(removeMsg)) {
  235.                         insertRequested = false;
  236.                         deleteRequested = true;
  237.                         saveData();
  238.                         newSearch();
  239.                     } else {
  240.                         user.mainmsg.setStatusMsg(removeMsg,15);
  241.                     }
  242.                     return true;
  243.                 }
  244.                 if (choice.trim().compareTo("Search") == 0) {
  245.                     insertRequested = false;
  246.                     deleteRequested = false;
  247.                     newSearch();
  248.                     return true;
  249.                 }
  250.                 return true;
  251.             }
  252.             if (e.target instanceof Choice) {
  253.                 return true;
  254.             }
  255.             if (e.target instanceof TextField) {
  256.                 if ((jdpWhereClause != null) && (e.target.equals(jdpWhereClause.matchConstant))) {
  257.                     insertRequested = false;
  258.                     deleteRequested = false;
  259.                     newSearch();
  260.                     return true;
  261.                 }
  262.                 checkFields();
  263.                 return true;
  264.             }
  265.             return false;
  266.  
  267.         case Event.KEY_RELEASE:
  268. >068            if (e.target.equals(<fieldname>)) JDPMaskEditMain.format<String>(<fieldname>,"<mask>");
  269.             return true;
  270.  
  271.         case Event.KEY_PRESS:
  272.             if (e.key == '\t') {
  273.                 //  handle tabbing between components
  274.                 if (e.modifiers != Event.SHIFT_MASK) {
  275. >031                    if (e.target.equals(<username>)) { user.u.cursor(<username>); return true; }
  276.                 } else {
  277. >038                    if (e.target.equals(<username>)) { user.u.cursor(<username>); return true; }
  278.                 }
  279.                 return true;
  280.             }
  281.             return false;
  282.  
  283.         case Event.WINDOW_EXPOSE:
  284.             if (e.target instanceof JDPTabSelectPanel) {
  285.                 if (e.target.equals(user.jdpMenuPanel)) {
  286.                     //
  287.                     //  This is where you place code to get executed when this panel is
  288.                     //  reactivated from the tab menu
  289.                     //
  290.                     return true;
  291.                 }
  292.             }
  293.             return false;
  294.  
  295.           case Event.MOUSE_MOVE:
  296.          case Event.MOUSE_ENTER:
  297.          case Event.MOUSE_EXIT:
  298.             popuppanel.postEvent(e);
  299.             return false;
  300.  
  301.         default:
  302.             return false;
  303.  
  304.         }
  305.     }
  306.  
  307.     //
  308.     //  Retrieve the handle to another panel so as to be able to interact with it
  309.     //
  310.     public void retrieveHandle() {
  311.  
  312.         for (int ix=0; ix<user.gParm.size(); ix++) {
  313.             //
  314.             //  Activate the next four lines of code to retrieve the handle to another 
  315.             //  Panel within your JDP system. Of course you should declare the variable 
  316.             //  at the top of this source instead of within this method so you can 
  317.             //  access it from all the methods within this class. You only need to 
  318.             //  substitute DemoClass with the name of your class. You should call this 
  319.             //  method from somewhere else in this class. To access a variable from 
  320.             //  your resulting class use:
  321.             //     if (DemoClassHandle != null) mynewvar = demoClassHandle.variable;
  322.             //
  323. //            if (user.gParm.elementAt(ix) instanceof DemoClass19) {
  324. //                DemoClass19 DemoClassHandle = (DemoClass19)user.gParm.elementAt(ix);
  325. //                return;
  326. //            }
  327.         }
  328.     }
  329.  
  330.     //
  331.     //  The search button was pressed so rerun the query with the new search criteria
  332.     //
  333.     public void newSearch() {
  334.  
  335.         String whereClause;
  336.  
  337.         whereClause = pfromWhereClause;
  338.         if (jdpWhereClause != null) {
  339.             whereClause = whereClause + " AND " + jdpWhereClause.whereClause;
  340.         }
  341.         searchResults.setFromWhereClause(whereClause);
  342. >057        searchResults.clearList(<>);
  343.         searchResults.loadList();
  344.     }
  345.  
  346.     //
  347.     //  Load the selected item
  348.     //
  349.     public void loadData() {
  350.  
  351.         StringTokenizer stok;
  352.  
  353.         int recCount = 0;
  354.         Vector results = new Vector();
  355.         String sep = jaggSQL.getSEP();
  356.         int actualRows = 0;
  357.         String row;
  358.         String tempText;
  359.  
  360.         if ((itemIndex = searchResults.getSelectedIndex()) < 0) {
  361.             clearFields();
  362.             return;
  363.         }
  364.  
  365. >032        String SQL = <SELECT username,firstname,lastname,status,cardnum,cardexpiry,cardname FROM JDPUser (NOLOCK) WHERE userid = " + thisuserid>;
  366.  
  367.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  368.         recCount = jaggSQL.execSQL(SQL, results);
  369.  
  370.         if(recCount == -1) {
  371.             user.u.setSqlMessage(jaggSQL,SQL);
  372.             return;
  373.         }
  374.         if(recCount >= 1) {
  375.             row = (String)results.elementAt(0);
  376.             if ((row != null) && (row.trim().compareTo("") != 0)) {
  377.                 stok = new StringTokenizer(row,sep);
  378.  
  379. >033                <username>.setText(stok.nextToken().trim());
  380. >067                JDPMaskEditMain.format<String>(<fieldname>,"<mask>");
  381.             }
  382.             if(recCount > 1) {
  383.                 user.mainmsg.setStatusMsg("Multiple records found - first match only displayed.", 10);
  384.             } else {
  385.                 user.mainmsg.clearStatusMsg();
  386.             }
  387.         } else {
  388.             user.mainmsg.setStatusMsg("Requested entry does not exist.", 10);
  389.             clearFields();
  390.         }
  391.  
  392.     }
  393.  
  394.     //
  395.     //  Save the selected item
  396.     //
  397.     public boolean saveData() {
  398.  
  399.         int recCount = 0;
  400.         Vector results = new Vector();
  401.         String sep = jaggSQL.getSEP();
  402.         String SQL = "";
  403.         String prevSQL = null;
  404.  
  405.         if (insertRequested) {
  406. >034            SQL = <INSERT INTO >;
  407.         } else {
  408.             itemIndex = searchResults.getSelectedIndex();
  409.             if (itemIndex < 0) {
  410.                 user.mainmsg.setStatusMsg("You must first make a selection",5);
  411.                 return false;
  412.             }
  413.             if (deleteRequested) {
  414. >035                SQL = <DELETE FROM >;
  415.             } else {
  416. >036                SQL = <UPDATE >;
  417.             }
  418.         }
  419.  
  420.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  421.         recCount = jaggSQL.execSQL(SQL, results);
  422.  
  423.         if (recCount == 0 && prevSQL != null) {
  424.             String[] buttons = {"Reload","Update"};
  425.             int[] icons = {JDPButton.UNDO,JDPButton.SAVE};
  426.             JDPMessageDialog d = new JDPMessageDialog(user, user.jdpMainWindow, "Update failed...", "The record has been changed by another user...",buttons, icons);
  427.             d.display();
  428.             if (d.getPressedButton() == 1) {
  429.                 results = new Vector();
  430.                 recCount = jaggSQL.execSQL(prevSQL, results);
  431.             } else {
  432.                 loadData();
  433.                 return true;
  434.             }
  435.         }
  436.  
  437.         if(recCount == -1) {
  438.             user.u.setSqlMessage(jaggSQL,SQL);
  439.             return false;
  440.         }
  441.         if(recCount == 1) {
  442.             if (insertRequested) {
  443.                 user.mainmsg.setStatusMsg("Record successfully added.",3);
  444.             } else 
  445.             if (deleteRequested) {
  446.                 user.mainmsg.setStatusMsg("Record successfully removed.",3);
  447.             } else {
  448.                 user.mainmsg.setStatusMsg("Record successfully updated.",3);
  449.             }
  450.         } else {
  451.             user.u.setSqlMessage(jaggSQL,SQL);
  452.         }
  453.         if (prevSQL != null) {
  454.             loadData();
  455.         }
  456.         insertRequested = false;
  457.         deleteRequested = false;
  458.         return true;
  459.  
  460.     }
  461.  
  462.     //
  463.     //  Clear the screen fields for a new option
  464.     //
  465.     public void clearFields() {
  466.  
  467. >037        <username>.setText("<>");
  468.  
  469.     }
  470.  
  471.     //
  472.     //  Load all of the Screen Choices
  473.     //
  474.     void loadChoices() {
  475.  
  476.         pmatchUsing = new Vector();
  477.         pactualmatchUsing = new Vector();
  478. >020        pmatchUsing.addElement(new Vector());
  479. >022        pactualmatchUsing.addElement(new Vector());
  480. >021        ((Vector)pmatchUsing.elementAt(<0>)).addElement("<Begins with>");
  481. >023        ((Vector)pactualmatchUsing.elementAt(<0>)).addElement("< like >");
  482.  
  483. >043
  484. >044        new JDPLoadChoice(user,jaggSQL,<choicename>,"<choicecolumnname>","<actualcolumnname>","<tablename>","<whereclause>",value<columnname>);
  485.     }
  486.  
  487.     //
  488.     //  Perform component validations
  489.     //
  490.     public boolean checkFields() {
  491.  
  492. >045        if (!user.u.<isnumeric>(<field>,user.mainmsg,"<>")) return false;
  493.  
  494.         return true;
  495.  
  496.     }
  497.  
  498.  
  499. }
  500.  
  501.