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

  1. \*    //
  2.     //  Main initialization method
  3.     //
  4.     public void <compName>Main() {
  5.  
  6.         <compName>ClearFields();
  7.         <compName>SetGridSettings();
  8.         <compName>LoadChoices();
  9.         <compName>WhereClauseMain();
  10.         <compName>SearchResultsMain();
  11.  
  12.     }
  13.  
  14. \*R    //
  15.     //  Load the selected item
  16.     //
  17.     public void <compName>Load(String[] keys) {
  18.  
  19.         StringTokenizer stok;
  20.  
  21.         int recCount = 0;
  22.         Vector results = new Vector();
  23.         String sep = jaggSQL.getSEP();
  24.         int actualRows = 0;
  25.         String row;
  26.         String tempText;
  27.  
  28.         if (keys == null || keys.length < 0) {
  29.             <compName>ClearFields();
  30.             return;
  31.         }
  32.  
  33. >032        String SQL = <SELECT>;
  34.  
  35. <jaggPrefs>
  36.         user.mainmsg.setStatusMsg(JDPLang.get("Message0"), 0);
  37.         recCount = jaggSQL.execSQL(SQL, results);
  38.  
  39.         if(recCount == -1) {
  40.             user.u.setSqlMessage(jaggSQL,SQL);
  41.             return;
  42.         }
  43.         if(recCount >= 1) {
  44.             row = (String)results.elementAt(0);
  45.             if ((row != null) && (row.trim().compareTo("") != 0)) {
  46.                 stok = new StringTokenizer(row,sep);
  47. >033                <username>.setText(stok.nextToken().trim());
  48. >067                JDPMaskEditMain.format<String>(<fieldname>,"<mask>");
  49.             }
  50.             if(recCount > 1) {
  51.                 user.mainmsg.setStatusMsg(JDPLang.get("Message1"), 10);
  52.             } else {
  53.                 user.mainmsg.clearStatusMsg();
  54.             }
  55.         } else {
  56.             user.mainmsg.setStatusMsg(JDPLang.get("Message2"), 10);
  57.             <compName>ClearFields();
  58.         }
  59.  
  60.     }
  61.  
  62. \*R    //
  63.     //  Clear the screen fields for a new option
  64.     //
  65.     public void <compName>ClearFields() {
  66.  
  67. >037        <username>.setText("<>");
  68.  
  69.     }
  70.  
  71. \*R    //
  72.     //  Perform component validations
  73.     //
  74.     public boolean <compName>CheckFields() {
  75.  
  76. >063        if (!user.u.<isnumeric>(<field>,user.mainmsg,"<>")) return false;
  77.  
  78.         return true;
  79.  
  80.     }
  81.  
  82.  
  83. \*    //
  84.     //  Load the grid with the specified parameters and selected data
  85.     //
  86.     public void <compName>LoadGridFromWhereClause(String whereClause) {
  87.  
  88.         int fPos = whereClause.indexOf("WHERE ");
  89.         whereClause = " AND" + whereClause.substring(fPos+5);
  90.         String[] keys = new String[0];
  91.  
  92.         <compName>LoadGridMain(keys, whereClause);
  93.     }
  94.  
  95. \*    //
  96.     //  Load the grid with the specified parameters and selected data
  97.     //
  98.     public void <compName>LoadGrid(String[] keys) {
  99.  
  100.         <compName>LoadGridMain(keys, null);
  101.     }
  102.  
  103. \*R    //
  104.     //  Load the grid with the specified parameters and selected data
  105.     //
  106.     void <compName>LoadGridMain(String[] keys, String whereClause) {
  107.  
  108.         JDPTextGrid tableContents = <compName>GL1;
  109.  
  110.         StringTokenizer stok;
  111.         int recCount = 0;
  112.         Vector results = new Vector();
  113.         String sep = jaggSQL.getSEP();
  114.         int actualRows = 0;
  115.         String row;
  116. >119        int columnCount = <columnCount>;
  117.  
  118.         Vector columns = new Vector();
  119.         Vector indexes = new Vector();
  120.  
  121. >100        String SQL = <SELECT>;
  122.         if (whereClause != null) {
  123.             SQL += whereClause;
  124.         }
  125.  
  126.         user.mainmsg.setStatusMsg(JDPLang.get("Message0"), 0);
  127.  
  128. <jaggPrefs>
  129.         recCount = jaggSQL.execSQL(SQL, results);
  130.  
  131.         if(recCount == -1) {
  132.             user.u.setSqlMessage(jaggSQL,SQL);
  133.             return;
  134.         }
  135.  
  136.         //
  137.         //  Initialise result arrays
  138.         //
  139.         tableContents.totalDataRows = jaggSQL.getRowCount();
  140.         actualRows = jaggSQL.getRowCount()+20;
  141.         tableContents.currentText = new String[columnCount][actualRows];
  142.  
  143.         tableContents.cellChanged = null;
  144.         tableContents.rowChanged = null;
  145.         tableContents.columnSelected = null;
  146. >120        int keyCount = <keycount>;
  147.         tableContents.rowKey = new String[actualRows][keyCount];
  148.         tableContents.recordLockValue = new String[actualRows];
  149.         
  150.         //
  151.         //  Load key array and grid array
  152.         //
  153.         String tempText;
  154.         for (int ix=0; ix<actualRows-20; ix++) {
  155.             row = (String)results.elementAt(ix);
  156.             if ((row != null) && (row.trim().compareTo("") != 0)) {
  157.                 stok = new StringTokenizer(row,sep);
  158. >162                tableContents.recordLockValue[ix] = stok.nextToken().trim();
  159.                 for (int iy=0; iy<keyCount; iy++) {
  160.                     tableContents.rowKey[ix][iy] = stok.nextToken().trim();
  161.                 }
  162.                 for (int iy=0; iy<columnCount; iy++) {
  163.                     tempText = stok.nextToken().trim();
  164.                     tableContents.currentText[iy][ix] = tempText;
  165. >053                    if ((iy == <1>) && (tableContents.pullDownValue[<1>][0].indexOf(tempText) >= 0)) tableContents.currentText[iy][ix] = tableContents.pullDownList[<1>][0].getItem(tableContents.pullDownValue[<1>][0].indexOf(tempText));
  166. >071                    if (iy == <1>) tableContents.currentText[iy][ix] = (tableContents.currentText[iy][ix].equals("<checkedValue>"))?"Y":"N";
  167. >069                    if (iy == <1>) JDPMaskEditMain.format<String>(tableContents,iy,ix,"<mask>");
  168. >069                    if (iy == <1>) tableContents.setEditMask("<String>",iy,"<mask>");
  169.                 }
  170.             }
  171.         }
  172.         for (int ix=actualRows-20; ix<actualRows; ix++) {
  173.             for (int iy=0; iy<keys.length; iy++) {
  174.                 tableContents.rowKey[ix][iy] = keys[iy];
  175.             }
  176.         }
  177.  
  178.         tableContents.newTable();
  179.  
  180.         //
  181.         //  Clear status message
  182.         //
  183.         user.mainmsg.clearStatusMsg();
  184.     }
  185.  
  186. \*    //
  187.     //  Check each row that has changed and issue an update to the database
  188.     //
  189.     public void <compName>UpdateRowsFromWhereClause(String whereClause) {
  190.  
  191.         int fPos = whereClause.indexOf("WHERE ");
  192.         whereClause = " AND" + whereClause.substring(fPos+5);
  193.         String[] keys = new String[0];
  194.  
  195.         <compName>UpdateRowsMain(keys, whereClause);
  196.     }
  197.  
  198. \*    //
  199.     //  Check each row that has changed and issue an update to the database
  200.     //
  201.     public void <compName>UpdateRows(String[] keys) {
  202.  
  203.         <compName>UpdateRowsMain(keys, null);
  204.     }
  205.  
  206. \*    //
  207.     //  Check each row that has changed and issue an update to the database
  208.     //
  209.     void <compName>UpdateRowsMain(String[] keys, String whereClause) {
  210.  
  211.         JDPTextGrid tableContents = <compName>GL1;
  212.  
  213.         int changedCount = 0;
  214.         int insertedCount = 0;
  215.         int cCount = 1;
  216.         int iCount = 1;
  217.         boolean reload = false;
  218.         
  219.         for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  220.             if (tableContents.rowChanged[ix]) {
  221.                 if (ix >= tableContents.totalDataRows) {
  222.                     insertedCount++;
  223.                 } else {
  224.                     changedCount++;
  225.                 }
  226.             }
  227.         }
  228.         for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  229.             if (tableContents.rowChanged[ix]) {
  230.                 if (ix >= tableContents.totalDataRows) {
  231.                     user.mainmsg.setStatusMsg(JDPLang.get("Message7",iCount++,insertedCount), 0);
  232.                     <compName>SaveData(ix,"I");
  233.                 } else {
  234.                     user.mainmsg.setStatusMsg(JDPLang.get("Message8",cCount++,changedCount), 0);
  235.                     if (<compName>SaveData(ix,"U")) {
  236.                         reload = true;
  237.                     }
  238.                 }
  239.                 tableContents.rowChanged[ix] = false;
  240.             }
  241.         }
  242.         if (insertedCount > 0 || reload) {
  243.             <compName>LoadGridMain(keys, whereClause);
  244.         }
  245.     }
  246.  
  247. \*    //
  248.     //  Delete any of the selected rows
  249.     //
  250.     public void <compName>DeleteRowsFromWhereClause(String whereClause) {
  251.  
  252.     int fPos = whereClause.indexOf("WHERE ");
  253.         whereClause = " AND" + whereClause.substring(fPos+5);
  254.         String[] keys = new String[0];
  255.  
  256.         <compName>DeleteRowsMain(keys, whereClause);
  257.     }
  258.  
  259. \*    //
  260.     //  Check each row that has changed and issue an update to the database
  261.     //
  262.     public void <compName>DeleteRows(String[] keys) {
  263.  
  264.         <compName>DeleteRowsMain(keys, null);
  265.     }
  266.  
  267. \*    //
  268.     //  Check each row that has changed and issue an update to the database
  269.     //
  270.     void <compName>DeleteRowsMain(String[] keys, String whereClause) {
  271.  
  272.         JDPTextGrid tableContents = <compName>GL1;
  273.  
  274.         int deletedCount = 0;
  275.         int cCount = 1;
  276.         int iCount = 1;
  277.         
  278.         for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  279.             if (tableContents.rowSelected[ix]) {
  280.                 deletedCount++;
  281.             } 
  282.         }
  283.         for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  284.             if (tableContents.rowSelected[ix]) {
  285.                 user.mainmsg.setStatusMsg(JDPLang.get("Message9",iCount++,deletedCount), 0);
  286.                 <compName>SaveData(ix,"D");
  287.             }
  288.         }
  289.         if (deletedCount > 0) {
  290.             <compName>LoadGridMain(keys, whereClause);
  291.         }
  292.     }
  293.  
  294. \*R    //
  295.     //  Save the selected item
  296.     //
  297.     boolean <compName>SaveData(int tableRow, String action) {
  298.  
  299.         JDPTextGrid tableContents = <compName>GL1;
  300.         int recCount = 0;
  301.         Vector results = new Vector();
  302.         String sep = jaggSQL.getSEP();
  303.         String SQL = "";
  304.         String prevSQL = null;
  305.  
  306. <jaggPrefs>
  307.         if (action.equals("I")) {
  308. >121            SQL = <INSERT INTO >;
  309.         } else {
  310.             if (action.equals("D")) {
  311. >122                SQL = <DELETE FROM >;
  312.                 if (tableContents.recordLockValue[tableRow] != null) {
  313.                     prevSQL = SQL;
  314. >163                    SQL += " AND <colname> = " + tableContents.recordLockValue[tableRow];
  315.                 }
  316.             } else {
  317. >123                SQL = <UPDATE >;
  318.                 if (tableContents.recordLockValue[tableRow] != null) {
  319.                     prevSQL = SQL;
  320. >163                    SQL += " AND <colname> = " + tableContents.recordLockValue[tableRow];
  321.                 }
  322.             }
  323.         }
  324.  
  325.         recCount = jaggSQL.execSQL(SQL, results);
  326.  
  327.         if (user.DEBUG) System.out.println("saveData CNT: "+Integer.toString(recCount));
  328.  
  329.         if (recCount == 0 && prevSQL != null) {
  330.             String[] buttons = {"Reload","Update"};
  331.             int[] icons = {JDPButton.UNDO,JDPButton.SAVE};
  332.             JDPMessageDialog d = new JDPMessageDialog(user, user.jdpMainWindow, JDPLang.get("Dialog0"), JDPLang.get("Dialog1"), buttons, icons);
  333.             d.display();
  334.             if (d.getPressedButton() == 1) {
  335.                 results = new Vector();
  336.                 recCount = jaggSQL.execSQL(prevSQL, results);
  337.             } else {
  338.                 return true;
  339.             }
  340.         }
  341.  
  342.         if(recCount == -1) {
  343.             user.u.setSqlMessage(jaggSQL,SQL);
  344.             return false;
  345.         }
  346.         if(recCount == 1) {
  347.             if (action.equals("I")) {
  348.                 user.mainmsg.setStatusMsg(JDPLang.get("Message4"),3);
  349.             } else 
  350.             if (action.equals("D")) {
  351.                 user.mainmsg.setStatusMsg(JDPLang.get("Message5"),3);
  352.             } else {
  353.                 user.mainmsg.setStatusMsg(JDPLang.get("Message6"),3);
  354.             }
  355.         } else {
  356.             user.u.setSqlMessage(jaggSQL,SQL);
  357.         }
  358.         if (prevSQL != null) {
  359.             return true;
  360.         }
  361.         return false;
  362.  
  363.     }
  364.  
  365. \*R    //
  366.     //  Load the grid with the blank rows to allow data entry
  367.     //
  368.     public void <compName>LoadEmptyGrid() {
  369.  
  370.         JDPTextGrid tableContents = <compName>GL1;
  371. >119        int columnCount = <columnCount>;
  372.  
  373.         tableContents.currentText = new String[columnCount][50];
  374.         tableContents.cellChanged = null;
  375.         tableContents.rowChanged = null;
  376.         tableContents.columnSelected = null;
  377.         tableContents.rowKey = new String[50][1];
  378.         tableContents.newTable();
  379.         tableContents.totalDataRows = 0;
  380.         tableContents.setSortingEnabled(true);
  381.     }
  382.  
  383. \*R    //
  384.     //  Set up the parameters for this grid
  385.     //
  386.     void <compName>SetGridSettings() {
  387.  
  388.         if (<compName> == null) {
  389.             <compName> = new JDPTextGrid(user);
  390.         } 
  391.         JDPTextGrid tableContents = <compName>GL1;
  392. >119        int columnCount = <columnCount>;
  393.  
  394.         tableContents.fieldTypeCol = new int[columnCount];
  395.         tableContents.columnHeader = new String[columnCount];
  396.         tableContents.columnHeaderStyle = new int[columnCount];
  397.         tableContents.columnStyle = new int[columnCount];
  398.         tableContents.columnHeaderColor = new Color[columnCount];
  399.         tableContents.columnColor = new Color[columnCount];
  400.         tableContents.columnBGColor = new Color[columnCount];
  401.         tableContents.columnProtected = new boolean[columnCount];
  402.         tableContents.columnDisabled = new boolean[columnCount];
  403.         tableContents.columnWidth = new int[columnCount];
  404.         tableContents.rightJustify = new boolean[columnCount];
  405.         tableContents.rowHeader = null;
  406.         tableContents.columnHeight = null;
  407.         for (int ix=0; ix<columnCount; ix++) {
  408.             tableContents.columnHeaderStyle[ix] = Font.BOLD;
  409.             tableContents.columnStyle[ix] = Font.PLAIN;
  410.             tableContents.columnHeaderColor[ix] = Color.black;
  411.             tableContents.columnColor[ix] = Color.black;
  412.             tableContents.columnBGColor[ix] = Color.white;
  413.             tableContents.columnStyle[ix] = Font.PLAIN;
  414.         }
  415. >110        tableContents.setFieldTypeCol(<ix>,JDPTextGrid.<TEXTFIELD>);
  416. >107        tableContents.columnProtected[<ix>] = <>;
  417. >107        tableContents.columnDisabled[<ix>] = <>;
  418. >108        tableContents.columnWidth[<ix>] = <>;
  419. >109        tableContents.rightJustify[<ix>] = <>;
  420. >101        tableContents.columnHeader[<ix>] = "<>";
  421. >102        tableContents.columnHeaderStyle[<ix>] = <>;
  422. >103        tableContents.columnStyle[<ix>] = <>;
  423. >104        tableContents.columnHeaderColor[<ix>] = user.u._cvtcolor("<>");
  424. >105        tableContents.columnColor[<ix>] = user.u._cvtcolor("<>");
  425. >106        tableContents.columnBGColor[<ix>] = user.u._cvtcolor("<>");
  426.  
  427.         <compName>LoadEmptyGrid();
  428.     }
  429.  
  430. \*R    //
  431.     //  Load all of the Screen Choices
  432.     //
  433.     void <compName>LoadChoices() {
  434.  
  435.         JDPTextGrid tableContents = <compName>GL1;
  436. >119        int columnCount = <columnCount>;
  437.  
  438. <jaggPrefs>
  439.         tableContents.isPullDownCol = new boolean[columnCount];
  440.         tableContents.pullDownColType = new int[columnCount];
  441.         tableContents.pullDownList = new List[columnCount][1];
  442. >049        tableContents.isPullDownCol[<1>] = true;
  443. >049        tableContents.pullDownColType[<1>] = JDPTextGrid.REGULAR;
  444. >049        tableContents.pullDownList[<1>][0] = new List();
  445. >070        tableContents.isPullDownCol[<1>] = true;
  446. >070        tableContents.pullDownColType[<1>] = JDPTextGrid.DATE;
  447. >050
  448. >051        new JDPLoadChoice(user,jaggSQL,tableContents.pullDownList[<1>][0],"<choicecolumnname>","<actualcolumnname>","<tablename>","<whereclause>",tableContents.pullDownValue[<1>][0]);
  449.  
  450. >061
  451. >062        new JDPLoadChoice(user,jaggSQL,<choicename>,"<choicecolumnname>","<actualcolumnname>","<tablename>","<whereclause>",null);
  452.     }
  453.  
  454.