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 / JDPLayout4.java < prev    next >
Encoding:
Text File  |  1999-04-09  |  12.8 KB  |  409 lines

  1. >XXX0384  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.     JDPTextGrid tableContents;
  19.     JDPWhereClause jdpWhereClause;
  20.     JDPMaskEdit JDPMaskEditMain;
  21.  
  22.     String[] psortChoice;
  23.     String[] pdisplayChoice;
  24.     int itemIndex;
  25.     boolean insertRequested = false;
  26.     boolean deleteRequested = false;
  27.     String pfromWhereClause;
  28.     String[][] rowKey;
  29.     int keyCount;
  30.     int prevColumnCount;
  31. >119    int columnCount = <columnCount>;
  32.  
  33.     Vector pmatchUsing;
  34.     Vector pactualmatchUsing;
  35.  
  36.     public void InitClass(JDPUser user, Panel targetPanel, String moduleParameter) {
  37.  
  38.         this.user = user;
  39.         //
  40.         //  Set JAGG settings for this class
  41.         //
  42.         jaggSQL = new JDPJagg(user.jaggPath);
  43.         jaggSQL.setNULL("space");
  44. >995        jaggSQL.setMRW("<maxRows>");
  45. >998        jaggSQL.setDSN("<datasource>");
  46. >984        jaggSQL.setUID("<>");
  47. >985        jaggSQL.setPWD("<>");
  48.  
  49.         setLayout(new BorderLayout());
  50.         setFont(user.plainFont);
  51.  
  52.         JDPMaskEditMain = new JDPMaskEdit();
  53.         Panel mainPanel = new Panel();
  54.         mainPanel.setLayout(new BorderLayout());
  55.         Panel centerMainPanel = new Panel();
  56.         centerMainPanel.setLayout(new BorderLayout());
  57.  
  58.         //
  59.         //  Create a new instance of a Grid
  60.         //
  61.         tableContents = new JDPTextGrid(user);
  62.         mainPanel.add("Center",tableContents);
  63.         centerMainPanel.add("Center",mainPanel);
  64.         
  65.         //
  66.         //  Define parameters for JDPWhereClause
  67.         //
  68. >016        String[] pchooseFrom = new String[<7>];
  69. >017        pchooseFrom[<0>] = "<Account Name>";
  70.  
  71. >018        String[] pactualchooseFrom = new String[<7>];
  72. >019        pactualchooseFrom[<0>] = "<username>";
  73.  
  74.         loadMatchUsing();
  75.  
  76. >024        boolean[] constantIsString = new boolean[<7>];
  77. >025        constantIsString[<0>] = <true>;
  78.  
  79. >026        int[] constantLength = new int[<7>];
  80. >027        constantLength[<0>] = <20>;
  81.  
  82.         //
  83.         //  Add JDPWhereClause search panel
  84.         //
  85.         if (pchooseFrom.length > 0) {
  86. >028            jdpWhereClause = new JDPWhereClause(user, targetPanel, "<UserBill>", false, "<pinitChoice>", pchooseFrom, pactualchooseFrom,
  87.                                                 pmatchUsing, pactualmatchUsing, null, null,
  88.                                                 constantLength, constantIsString);
  89.             centerMainPanel.add("North",jdpWhereClause);
  90.         }
  91.  
  92. >030        add("Center",new JDPChiselFramePanel(user,"<User Billing Details>",centerMainPanel,"North"));
  93.         loadGrid();
  94.  
  95.         //
  96.         //  Add the handle to this panel to the global vector so other panels can
  97.         //  access this one
  98.         //
  99.         user.gParm.addElement(this);
  100.     }
  101.  
  102.     //
  103.     //  Handle screen events
  104.     //
  105.     public boolean handleEvent(Event e) {
  106.  
  107.         switch (e.id) {
  108.         case Event.ACTION_EVENT:
  109.             if (e.target instanceof Button) {
  110.                 String choice = (String)e.arg;
  111.                 if (choice.trim().compareTo("Search") == 0) {
  112.                     newSearch();
  113.                     return true;
  114.                 }
  115.                 return false;
  116.             }
  117.             if (e.target instanceof Choice) {
  118.                 return true;
  119.             }
  120.             if (e.target instanceof TextField) {
  121.                 if ((jdpWhereClause != null) && (e.target.equals(jdpWhereClause.matchConstant))) {
  122.                     newSearch();
  123.                     return true;
  124.                 }
  125.                 return true;
  126.             }
  127.             return false;
  128.  
  129.         case Event.WINDOW_EXPOSE:
  130.             if (e.target instanceof JDPTabSelectPanel) {
  131.                 //
  132.                 //  This is where you place code to get executed when this panel is
  133.                 //  reactivated from the tab menu
  134.                 //
  135.                 return true;
  136.             }
  137.             return false;
  138.  
  139.         default:
  140.             return false;
  141.  
  142.         }
  143.     }
  144.  
  145.     //
  146.     //  Retrieve the handle to another panel so as to be able to interact with it
  147.     //
  148.     public void retrieveHandle() {
  149.  
  150.         for (int ix=0; ix<user.gParm.size(); ix++) {
  151.             //
  152.             //  Activate the next four lines of code to retrieve the handle to another 
  153.             //  Panel within your JDP system. Of course you should declare the variable 
  154.             //  at the top of this source instead of within this method so you can 
  155.             //  access it from all the methods within this class. You only need to 
  156.             //  substitute DemoClass with the name ouf your class. You should call this 
  157.             //  method from somewhere else in this class. To access a variable from 
  158.             //  your resulting class use:
  159.             //     if (DemoClassHandle != null) mynewvar = demoClassHandle.variable;
  160.             //
  161. //            if (user.gParm.elementAt(ix) instanceof DemoClass19) {
  162. //                DemoClass19 DemoClassHandle = (DemoClass19)user.gParm.elementAt(ix);
  163. //                return;
  164. //            }
  165.         }
  166.     }
  167.  
  168.     //
  169.     //  The search button was pressed so rerun the query with the new search criteria
  170.     //
  171.     public void newSearch() {
  172.  
  173.         loadGrid();
  174.     }
  175.  
  176.     //
  177.     //  Load the grid with the specified parameters and selected data
  178.     //
  179.     public void loadGrid() {
  180.  
  181.         StringTokenizer stok;
  182.         int recCount = 0;
  183.         Vector results = new Vector();
  184.         String sep = jaggSQL.getSEP();
  185.         int actualRows = 0;
  186.         String row;
  187.         float[][] worksubTotal;
  188.         float[][] workgrandTotal;
  189.  
  190.         Vector columns = new Vector();
  191.         Vector indexes = new Vector();
  192.  
  193. >100        String SQL = <SELECT>;
  194.  
  195.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  196.  
  197.         recCount = jaggSQL.execSQL(SQL, results);
  198.  
  199.         if(recCount == -1) {
  200.             user.u.setSqlMessage(jaggSQL,SQL);
  201.             return;
  202.         }
  203.  
  204.         //
  205.         //  Initialise result arrays
  206.         //
  207.         actualRows = jaggSQL.getRowCount();
  208.         tableContents.currentText = new String[columnCount][actualRows+30];
  209.         tableContents.cellFont = new Font[columnCount][actualRows+30];
  210.         tableContents.gridColor = Color.white;
  211.         boolean[] totalThisColumn = new boolean[columnCount];
  212.         //
  213.         //  If we haven't already initialise the grid settings
  214.         //
  215.         if (columnCount != prevColumnCount) {
  216.             prevColumnCount = columnCount;
  217.             setGridSettings();
  218.         }
  219.         String[] lastItem = new String[columnCount];
  220. >125        boolean[] subTotal = new boolean[<>];
  221. >125        boolean[] grandTotal = new boolean[<>];
  222. >126        int orderBy = <>;
  223. >127        subTotal[<>] = <>;
  224. >128        grandTotal[<>] = <>;
  225. >129        totalThisColumn[<>] = <>;
  226.         //
  227.         //  Load arrays and result List
  228.         //
  229.         worksubTotal = new float[1][1];
  230.         workgrandTotal = new float[1][1];
  231.         int xOffset = 0;
  232.         int    xIncrement = 0;
  233.         int titlePos = (int)(columnCount/2)-1;
  234.         if (titlePos < 0) titlePos = 0;
  235. >124        tableContents.currentText[titlePos][1] = "<>";
  236.         tableContents.cellFont[titlePos][1] = new Font(user.plainFont.getName(),Font.BOLD,user.plainFont.getSize()+4);
  237.         for (int iy=0; iy<columnCount; iy++) {
  238.             tableContents.cellFont[iy][3] = user.boldFont;
  239.         }
  240. >101        tableContents.currentText[<ix>][3] = "<>";
  241.         xOffset = 4;
  242.         worksubTotal = new float[orderBy][columnCount];
  243.         workgrandTotal = new float[orderBy][columnCount];
  244.         int ix;
  245.         String tempText;
  246.         for (ix=0; ix<actualRows; ix++) {
  247.             row = (String)results.elementAt(ix);
  248.             if ((row != null) && (row.trim().compareTo("") != 0)) {
  249.                 stok = new StringTokenizer(row,sep);
  250.                 for (int iy=0; iy<columnCount; iy++) {
  251.                     tempText = stok.nextToken().trim();
  252.                     tableContents.currentText[iy][ix+xOffset] = tempText;
  253. >053                    <tableContents.currentText[iy][ix+xOffset] = stok.nextToken().trim();>
  254.                     if (tableContents.maskEdit[iy] != null) {
  255.                         if (tableContents.maskType[iy] == "Float") {
  256.                             tableContents.currentText[iy][ix+xOffset] = JDPMaskEditMain.formatFloat(tableContents.currentText[iy][ix+xOffset],tableContents.maskEdit[iy]);
  257.                         } else {
  258.                             tableContents.currentText[iy][ix+xOffset] = JDPMaskEditMain.formatString(tableContents.currentText[iy][ix+xOffset],tableContents.maskEdit[iy]);
  259.                         }
  260.                     }
  261.                 }
  262.                 for (int iy=columnCount-1; iy>=0; iy--) {
  263.                     String thisItem = tableContents.currentText[iy][ix+xOffset];
  264.                     if ((orderBy > iy) && (ix > 0)) {
  265.                         if (thisItem.equals(lastItem[iy])) {
  266.                             tableContents.currentText[iy][ix+xOffset] = "";
  267.                         } else {
  268.                             if (subTotal[iy]) {
  269.                                 for (int iz=0; iz<columnCount; iz++) {
  270.                                     tableContents.currentText[iz][ix+xOffset+1] = tableContents.currentText[iz][ix+xOffset];
  271.                                     tableContents.currentText[iz][ix+xOffset] = "";
  272.                                     tableContents.cellFont[iz][ix+xOffset+1] = tableContents.cellFont[iz][ix+xOffset];
  273.                                     tableContents.cellFont[iz][ix+xOffset] = null;
  274.                                 }
  275.                                 tableContents.currentText[iy][ix+xOffset] = "Subtotal";
  276.                                 tableContents.cellFont[iy][ix+xOffset] = user.boldFont;
  277.                                 for (int iw=iy+1; iw<columnCount; iw++) {
  278.                                     if (totalThisColumn[iw]) {
  279.                                         tableContents.currentText[iw][ix+xOffset] = JDPMaskEditMain.formatFloat(worksubTotal[iy][iw],tableContents.maskEdit[iy]);
  280.                                         tableContents.cellFont[iw][ix+xOffset] = user.boldFont;
  281.                                     }
  282.                                     worksubTotal[iy][iw] = 0;
  283.                                 }
  284.                                 xOffset += 1;
  285.                             }
  286.                             tableContents.currentText[iy][ix+xOffset] = thisItem;
  287.                         }
  288.                     }
  289.                     if ((orderBy > 0) && (ix > 0)) {
  290.                         try {
  291.                             float tempfloat = Float.valueOf(JDPMaskEditMain.stripFloat(lastItem[iy])).floatValue();
  292.                             for (int iz=0; iz<orderBy; iz++) {
  293.                                 worksubTotal[iz][iy] += tempfloat;
  294.                                 workgrandTotal[iz][iy] += tempfloat;
  295.                             }
  296.                         } catch(Exception e) { 
  297.                         }
  298.                     }
  299.                     lastItem[iy] = thisItem;
  300.                 }
  301.             }
  302.         }
  303.  
  304.         for (int iy=0; iy<columnCount; iy++) {
  305.             try {
  306.                 float tempfloat = Float.valueOf(JDPMaskEditMain.stripFloat(lastItem[iy])).floatValue();
  307.                 for (int iz=0; iz<orderBy; iz++) {
  308.                     worksubTotal[iz][iy] += tempfloat;
  309.                     workgrandTotal[iz][iy] += tempfloat;
  310.                 }
  311.             } catch(Exception e) { 
  312.             }
  313.         }
  314.         for (int iy=columnCount-1; iy>=0; iy--) {
  315.             if (orderBy > iy) {
  316.                 if (subTotal[iy]) {
  317.                     tableContents.currentText[iy][ix+xOffset] = "Subtotal";
  318.                     tableContents.cellFont[iy][ix+xOffset] = user.boldFont;
  319.                     for (int iw=iy+1; iw<columnCount; iw++) {
  320.                         if (totalThisColumn[iw]) {
  321.                             tableContents.currentText[iw][ix+xOffset] = JDPMaskEditMain.formatFloat(worksubTotal[iy][iw],tableContents.maskEdit[iw]);
  322.                             tableContents.cellFont[iw][ix+xOffset] = user.boldFont;
  323.                         }
  324.                     }
  325.                     xOffset += 1;
  326.                 }
  327.             }
  328.         }
  329.         for (int iy=columnCount-1; iy>=0; iy--) {
  330.             if (orderBy > iy) {
  331.                 if (grandTotal[iy]) {
  332.                     tableContents.currentText[iy][ix+xOffset] = "Total";
  333.                     tableContents.cellFont[iy][ix+xOffset] = user.boldFont;
  334.                     for (int iw=iy+1; iw<columnCount; iw++) {
  335.                         if (totalThisColumn[iw]) {
  336.                             tableContents.currentText[iw][ix+xOffset] = JDPMaskEditMain.formatFloat(workgrandTotal[iy][iw],tableContents.maskEdit[iw]);
  337.                             tableContents.cellFont[iw][ix+xOffset] = user.boldFont;
  338.                         }
  339.                     }
  340.                     xOffset++;
  341.                 }
  342.             }
  343.         }
  344.  
  345.         tableContents.newTable();
  346.  
  347.         //
  348.         //  Clear status message
  349.         //
  350.         user.mainmsg.clearStatusMsg();
  351.     }
  352.  
  353.     //
  354.     //  Set up the parameters for this grid
  355.     //
  356.     void setGridSettings() {
  357.  
  358.         tableContents.columnHeader = null;
  359.         tableContents.columnHeaderStyle = new int[columnCount];
  360.         tableContents.columnStyle = new int[columnCount];
  361.         tableContents.columnHeaderColor = new Color[columnCount];
  362.         tableContents.columnColor = new Color[columnCount];
  363.         tableContents.columnBGColor = new Color[columnCount];
  364.         tableContents.columnProtected = new boolean[columnCount];
  365.         tableContents.columnWidth = new int[columnCount];
  366.         tableContents.rightJustify = new boolean[columnCount];
  367.         tableContents.rowHeader = null;
  368.         tableContents.columnHeight = null;
  369.         tableContents.maskEdit = new String[columnCount];
  370.         tableContents.maskType = new String[columnCount];
  371.         for (int ix=0; ix<columnCount; ix++) {
  372.             tableContents.columnHeaderStyle[ix] = Font.BOLD;
  373.             tableContents.columnStyle[ix] = Font.PLAIN;
  374.             tableContents.columnHeaderColor[ix] = Color.black;
  375.             tableContents.columnColor[ix] = Color.black;
  376.             tableContents.columnBGColor[ix] = Color.white;
  377.             tableContents.columnStyle[ix] = Font.PLAIN;
  378.         }
  379. >102        tableContents.columnHeaderStyle[<ix>] = <>;
  380. >103        tableContents.columnStyle[<ix>] = <>;
  381. >104        tableContents.columnHeaderColor[<ix>] = user.u._cvtcolor("<>");
  382. >105        tableContents.columnColor[<ix>] = user.u._cvtcolor("<>");
  383. >106        tableContents.columnBGColor[<ix>] = user.u._cvtcolor("<>");
  384. >107        tableContents.columnProtected[<ix>] = <>;
  385. >108        tableContents.columnWidth[<ix>] = <>;
  386. >109        tableContents.rightJustify[<ix>] = <>;
  387. >170        tableContents.maskEdit[<ix>] = "<>";
  388. >171        tableContents.maskType[<ix>] = "<>";
  389.  
  390.     }
  391.  
  392.     //
  393.     //  Load the Search Layout pulldown choices
  394.     //
  395.     void loadMatchUsing() {
  396.  
  397.         pmatchUsing = new Vector();
  398.         pactualmatchUsing = new Vector();
  399. >020        pmatchUsing.addElement(new Vector());
  400. >022        pactualmatchUsing.addElement(new Vector());
  401. >021        ((Vector)pmatchUsing.elementAt(<0>)).addElement("<Begins with>");
  402. >023        ((Vector)pactualmatchUsing.elementAt(<0>)).addElement("< like >");
  403.  
  404.     }
  405.  
  406.  
  407. }
  408.  
  409.