⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmcustomer.java~1~

📁 《JBuilder编程技术与实例》(2006 四维科技 人民邮电)赠送代码——库存管理系统(Access)
💻 JAVA~1~
📖 第 1 页 / 共 2 页
字号:
                                                if(sqlE.getMessage() != null){
                                                        System.out.println(sqlE.getMessage());
                                                }else{
                                                        JOptionPane.showMessageDialog(null,"Please select a record in the list to modify.","No Record Selected",JOptionPane.INFORMATION_MESSAGE);
                                                }

                                        }
                                }
                        //Search Record
                        }else if(srcObj=="search"){
                                JDialog JDSearchRec = new FrmSearchCustomer(JFParentFrame);
                                JDSearchRec.show(true);
                        //Print Record
                        }else if(srcObj=="print"){
                                if(total != 0){
                                        try{
                                                        if(JTCusTable.getValueAt(JTCusTable.getSelectedRow(),JTCusTable.getSelectedColumn()) != null){
                                                                clsPublicMethods PrintingClass = new clsPublicMethods();
                                                                ResultSet rsPrint = stCus.executeQuery("SELECT * FROM tblCustomer WHERE CustomerIndex = " + JTCusTable.getValueAt(JTCusTable.getSelectedRow(),0));
                                                                if(rsPrint.next()==true){
                                                                        String RecordToPrint = "";
                                                                        java.util.Date CurrentDate = new java.util.Date();
                                                                        SimpleDateFormat SDFDateFormatter = new SimpleDateFormat("MMM. dd, yyyy",Locale.getDefault());

                                                                        RecordToPrint += "                            C U S T O M E R   R E C O R D							 \n";
                                                                        RecordToPrint += "                              " + SDFDateFormatter.format(CurrentDate).toString() + "\n\n\n";


                                                                        RecordToPrint += "___________________________________________________________________________________\n\n\n";

                                                                        RecordToPrint += " Customer ID: " + rsPrint.getString("CustomerID") + "                 Company Name: " + rsPrint.getString("CompanyName") + "\n";
                                                                        RecordToPrint += "___________________________________________________________________________________\n";
                                                                        RecordToPrint += "___________________________________________________________________________________\n\n";

                                                                        RecordToPrint += " Contact Person: " + rsPrint.getString("ContactName") + "\n";
                                                                        RecordToPrint += " Contact Title: " + rsPrint.getString("ContactTitle") + "\n";
                                                                        RecordToPrint += " Address: " + rsPrint.getString("Address") + "\n";
                                                                        RecordToPrint += " City: " + rsPrint.getString("CityTown") + "\n";
                                                                        RecordToPrint += " State/Province: " + rsPrint.getString("StateProvince") + "\n";
                                                                        RecordToPrint += " Zip Code: " + rsPrint.getString("ZipCode") + "\n";
                                                                        RecordToPrint += " Country: " + rsPrint.getString("Country") + "\n";
                                                                        RecordToPrint += " Phone: " + rsPrint.getString("Phone") + "\n";
                                                                        RecordToPrint += " Fax: " + rsPrint.getString("Fax") + "\n\n";

                                                                        RecordToPrint += "___________________________________________________________________________________\n\n";

                                                                        PrintingClass.printRecord(RecordToPrint,JFParentFrame);

                                                                        CurrentDate=null;
                                                                        SDFDateFormatter=null;
                                                                        RecordToPrint=null;

                                                                }else{
                                                                        JOptionPane.showMessageDialog(null,"The selected record has been change since last modified. Please click the 'Reload' button and try again!","No record to print",JOptionPane.WARNING_MESSAGE);
                                                                }
                                                                //Dispose the variable
                                                                rsPrint=null;

                                                        }
                                        }catch(Exception sqlE){
                                                if(sqlE.getMessage() != null){
                                                        System.out.println(sqlE.getMessage());
                                                }else{
                                                        JOptionPane.showMessageDialog(null,"Please select a record in the list to print.","No Record Selected",JOptionPane.INFORMATION_MESSAGE);
                                                }
                                        }
                                }
                        //Delete Record
                        }else if(srcObj=="delete"){
                                if(total != 0){
                                        try{
                                                if(JTCusTable.getValueAt(JTCusTable.getSelectedRow(),JTCusTable.getSelectedColumn()) != null){
                                                        String ObjButtons[] = {"Yes","No"};
                                                        int PromptResult = JOptionPane.showOptionDialog(null,"Are you sure you want to delete the selected record?","Delete Record",JOptionPane.DEFAULT_OPTION,JOptionPane.ERROR_MESSAGE,null,ObjButtons,ObjButtons[1]);
                                                        if(PromptResult==0){
                                                                stCus.execute("DELETE * FROM tblCustomer WHERE CustomerIndex = " + JTCusTable.getValueAt(JTCusTable.getSelectedRow(),0));
                                                                reloadRecord();
                                                                JOptionPane.showMessageDialog(null,"Record has been successfully deleted.","Comfirm Delete",JOptionPane.INFORMATION_MESSAGE);
                                                        }
                                                }
                                        }catch(Exception sqlE){
                                                if(sqlE.getMessage()!=null){
                                                        JOptionPane.showMessageDialog(null,"You cannot delete this customer because it already have an invoice transaction.\nIn order to delete this customer, delete its invoice first.","Comfirm Delete",JOptionPane.WARNING_MESSAGE);
                                                }else{
                                                        JOptionPane.showMessageDialog(null,"Please select a record in the list to deleted.","No Record Selected",JOptionPane.INFORMATION_MESSAGE);
                                                }
                                        }
                                }
                        //Reload Record
                        }else if(srcObj=="reload"){
                                reloadRecord();
                        //Close the Form
                        }
                }
        };
        /*************************** End event handling ***************************/

        /************************** Start custom class ***************************/

        public static  JTable CreateTable(){
                String ColumnHeaderName[] = {
                        "Index","Customer ID","Company Name","Contact Name"
                };
                try{
                        rsCus = stCus.executeQuery(strSQL);
                        total = 0;
                        //Move to the last record
                        rsCus.afterLast();
                        //Get the current record position
                        if(rsCus.previous())total = rsCus.getRow();
                        //Move back to the first record;
                        rsCus.beforeFirst();
                        if(total > 0){
                                Content = new String[total][4];
                                while(rsCus.next()){
                                        Content[rowNum][0] = "" + rsCus.getString("CustomerIndex");
                                        Content[rowNum][1] = "" + rsCus.getString("CustomerID");
                                        Content[rowNum][2] = "" + rsCus.getString("CompanyName");
                                        Content[rowNum][3] = "" + rsCus.getString("ContactName");
                                        rowNum++;
                                }
                        }else{
                                Content = new String[0][4];
                                Content[0][0] = " ";
                                Content[0][1] = " ";
                                Content[0][2] = " ";
                                Content[0][3] = " ";
                        }
                }catch(Exception eE){
                }
                JTable NewTable = new JTable (Content,ColumnHeaderName){
                        public boolean isCellEditable (int iRows, int iCols) {
                                return false;
                        }
                };

                NewTable.setPreferredScrollableViewportSize(new Dimension(727, 320));
                NewTable.setBackground(Color.white);

                //Start resize the table column
                NewTable.getColumnModel().getColumn(0).setMaxWidth(0);
                NewTable.getColumnModel().getColumn(0).setMinWidth(0);
                NewTable.getColumnModel().getColumn(0).setWidth(0);
                NewTable.getColumnModel().getColumn(0).setPreferredWidth(0);
                NewTable.getColumnModel().getColumn(1).setPreferredWidth(100);
                NewTable.getColumnModel().getColumn(2).setPreferredWidth(300);
                NewTable.getColumnModel().getColumn(3).setPreferredWidth(200);
                //End resize the table column

                //Disposed variables
                ColumnHeaderName=null;
                Content=null;

                rowNum = 0;

                return NewTable;
        }

        /**************************** End custom class ****************************/

        /************************** Start Custom method ***************************/

        public static void reloadRecord(String srcSQL){
                                strSQL = srcSQL;
                                CusTableJSP.getViewport().remove(JTCusTable);
                                JTCusTable=CreateTable();
                                CusTableJSP.getViewport().add(JTCusTable);
                                JPContainer.repaint();
        }
        public static void reloadRecord(){
                                CusTableJSP.getViewport().remove(JTCusTable);
                                JTCusTable=CreateTable();
                                CusTableJSP.getViewport().add(JTCusTable);
                                JPContainer.repaint();
        }

        /*************************** End Custom method ****************************/

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -