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 / JDPLayout22.java < prev    next >
Encoding:
Text File  |  1999-04-09  |  11.3 KB  |  381 lines

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