TableBcpInDialogOfMSSQL

public class TableBcpInDialogOfMSSQL extends AbstractProcessDialog
{

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    private DebugPrn dMsg = new DebugPrn(TableBcpInDialogOfMSSQL.class.getName());
    //private static Logger dMsg = Logger.getLogger(DBResourceDialog.class.getName());

    private I18n I18N = null;
    private String STR_ESCAPE_RELEASED = "ESCAPE_RELEASED";
    private KeyStroke ESCAPE_STROKE = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
    private KeyStroke ENTER_STROKE = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);

    private DatabaseInfo dbInfo = null;

    private JTextField jvalueTextArea = new JTextField("");

    private JCheckBox jcIsTruncateFirst = new JCheckBox();

    /**用户(ora) 或者 数据库名 的列表*/
    // private ZJList jcmbDBName = new ZJList();
    private ZXComboBox jcmbDBName = new ZXComboBox();

    /**显示DB信息的JTable控件列名*/
    private Vector vecColumnStrDBInfo = null;
    /**显示table信息的JTable控件列名*/
    private Vector vecColumnStrTableInfo = null;

    private NonEditableTableModel jtbModelTableInfo = null;

    // 各种 监控器 和 动作事件 处理类
    private KeyAdapter keyAdpJcmbEnter = null;
    private KeyAdapter keyAdpEscape = null;
    private ActionListener actionLsrJbutOk = null;
    private ActionListener actionLsrJbutEXECUTE = null;
    private ActionListener actionLsrJbutUpdateDBMSOwnerSystemTables = null;

    private ActionListener actionLsrCommon = null;

    private ActionListener actionFile = null;

    private ActionListener itemLsrJcmbDBName = null;
    private Action actionEscape = null;
    private JFrame jfmMain = null;
    private AbstractProcessJFrame main = null;

    private JTable jtblTableInfo = null;

    private String dbName = null;
    private String path = null;
    private String tableName = null;
    private AbstractProcessDialog thisDialog = null;

    //private final static ImageIcon ICON_DBSVR_RESVIEW_DESC = UIToolKit
    //       .getIcon("uep-dev-d-dbres-browse");

    /**
     * 构造函数
     * @param frame
     * @param title
     * @param modal
     * @param inDbInfo
     */
    public TableBcpInDialogOfMSSQL(AbstractProcessJFrame main, String title, DatabaseInfo inDBInfo)
    {
        super(main, title, true);
        thisDialog = this;
        I18N = STMConsts.getI18N();
        jfmMain = main;
        this.main = main;
        this.dbInfo = inDBInfo;
        boolean bOk = false;
        this.setCursor(new Cursor(Cursor.WAIT_CURSOR));

        try
        {
            defineActions();
            bOk = initialize();

        }
        catch(Exception ignore)
        {
            dMsg.error("", ignore);
            return;
        }
        this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

        if(bOk)
        {
            ToolBox.setDlgCenterDisplayLocation(this);
            setVisible(true);
        }

    }

    /**
     *
     *各种事件处理函数
     */
    private void defineActions()
    {
        // Enter键 处理
        keyAdpJcmbEnter = new KeyAdapter()
        {

            public void keyPressed(KeyEvent e)
            {
                if(e.getSource() instanceof JComboBox)
                {
                    if(!(((JComboBox) (e.getSource())).isPopupVisible()))
                    {
                        if(e.getKeyCode() == KeyEvent.VK_ENTER)
                        {
                            importTable();
                        }
                    }
                }
            }
        };
        //
        keyAdpEscape = new KeyAdapter()
        {

            public void keyPressed(KeyEvent e)
            {
                if(e.getKeyCode() == KeyEvent.VK_ESCAPE)
                {
                    close();
                }
            }
        };
        //
        actionEscape = new AbstractAction()
        {

            /**
             *
             */
            private static final long serialVersionUID = 1L;

            public void actionPerformed(ActionEvent e)
            {
                close();
            }
        };
        //
        itemLsrJcmbDBName = new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {
                jcmbDBName_itemStateChanged(e);
            }
        };

        //
        actionLsrJbutOk = new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {
                jbutOk_actionPerformed(e);
            }
        };

        //
        actionLsrJbutEXECUTE = new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {
                jbutEXECUTE_actionPerformed(e);
            }
        };

        //
        actionLsrJbutUpdateDBMSOwnerSystemTables = new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {
                jbutUpdateDBMSOwnerSystemTables_actionPerformed(e);
            }
        };

        actionLsrCommon = new ActionListener()
        {

            public void actionPerformed(ActionEvent ae)
            {
                //调度事件
                jbRefreshClicked(ae);
            }
        };

        actionFile = new ActionListener()
        {

            public void actionPerformed(ActionEvent ae)
            {
                //调度事件
                selectPath(jvalueTextArea);
            }
        };
    }

    /**
     * 更新
     * @param ae ActionEvent
     */
    private void jbRefreshClicked(ActionEvent ae)
    {

        actionLsrJbutUpdateDBMSOwnerSystemTables.actionPerformed(ae);

    }

    /**
     * 消息回调方法
     * @param msg String 系统表信息更新完成
     */
    public void addProcessMsg(String msg)
    {
        SwingUtilities.invokeLater(new UpdateHandler(this));
    }

    /**
     * 初使化操作
     *
     */
    private boolean initialize()
    {
        this.setSize(new Dimension(780, 500));
        UIToolKit.setMinimumSize(this, 780, 500);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.registerEscapeAction(this.getRootPane(), actionEscape);
        this.setupColumnStrVector();

        //-------------数据表信息-----------
        jtbModelTableInfo = new NonEditableTableModel(new Vector(), this.vecColumnStrTableInfo);

        if(addAllDBNamesToJcmbDBName() == false)
        {
            return false;
        }

        jcmbDBName.addActionListener(null);
        jcmbDBName.addActionListener(itemLsrJcmbDBName);
        jcmbDBName.setEditable(false);
        jcmbDBName.setSelectedIndex(0);
        jcmbDBName.addKeyListener(keyAdpJcmbEnter);

        //加载当前库所有表行数信息
        jtblTableInfo = TableHelper.createSortableTable(jtbModelTableInfo);
        jtblTableInfo.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        jtblTableInfo.addKeyListener(keyAdpEscape);
        setCellRender(jtblTableInfo);
        jtblTableInfo.setDefaultRenderer(String.class, new CellRender());
        jtblTableInfo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JScrollPane jscrPaneTableInfo = new JScrollPane();
        jscrPaneTableInfo.getViewport().add(jtblTableInfo);
        if(loadTableInfoofCurrUser() == false)
        {
            return false;
        }
        JPanel panelTableInfo = new JPanel();
        panelTableInfo.setLayout(new BorderLayout(6, 6));

        JPanel jscrDBNamesInfo = new JPanel();
        jscrDBNamesInfo.setLayout(new BorderLayout(6, 6));

        JPanel p1 = new JPanel();
        p1.setLayout(new GridBagLayout());
        p1.setPreferredSize(new Dimension(160, 30));

        p1.add(new JLabel(STMConsts.getI18N().getLabelValue("info_dataclear_database")),
                new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST,
                        GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

        p1.add(jcmbDBName,
                new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST,
                        GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        jscrDBNamesInfo.add(p1, BorderLayout.WEST);

        JPanel p2 = new JPanel();
        p2.setLayout(new BorderLayout(6, 6));
        p2.setPreferredSize(new Dimension(400, 30));

        JButton fileButton = new JButton(STMConsts.getI18N().getLabelValue("info_imp_filebutton"));
        fileButton.setMnemonic('F');
        fileButton.addActionListener(actionFile);

        JPanel p3 = new JPanel();
        p3.setLayout(new BorderLayout(6, 6));
        p3.setPreferredSize(new Dimension(200, 30));

        p3.add(fileButton, BorderLayout.CENTER);

        p2.add(jvalueTextArea, BorderLayout.CENTER);
        p2.add(p3, BorderLayout.EAST);

        jscrDBNamesInfo.add(p2, BorderLayout.CENTER);

        panelTableInfo.add(jscrDBNamesInfo, BorderLayout.NORTH);
        jscrPaneTableInfo.setBorder(BorderFactory.createTitledBorder(""));
        panelTableInfo.add(jscrPaneTableInfo, BorderLayout.CENTER);
        JPanel jpTabRoot = new JPanel();
        jpTabRoot.setLayout(new GridBagLayout());
        jpTabRoot.add(panelTableInfo, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 6, 6, 6), 0, 0));

        //进程信息panelProcessInfo------------------------

        //----this.getContentPane()
        JButton jbutRefresh = new JButton(I18N.getLabelValue("I18N_REFRESH_R"));
        jbutRefresh.setMnemonic('R');
        jbutRefresh.addActionListener(actionLsrCommon);

        JButton jbutClose = new JButton(I18N.getLabelValue("I18N_CANCEL"));
        jbutClose.setMnemonic('C');

        jbutClose.addActionListener(actionLsrJbutOk);

        JButton jbutEXECUTE = new JButton(I18N.getLabelValue("info_imp_button"));
        jbutEXECUTE.setMnemonic('E');
        jbutEXECUTE.registerKeyboardAction(actionLsrJbutEXECUTE, ENTER_STROKE,
                JComponent.WHEN_IN_FOCUSED_WINDOW);
        jbutEXECUTE.addActionListener(actionLsrJbutEXECUTE);

        JPanel jpButtonPanel = new JPanel();
        jpButtonPanel.setLayout(new GridBagLayout());
        jcIsTruncateFirst.setText(I18N.getLabelValue("info_imp_checkbox_truncate"));
        jpButtonPanel.add(jcIsTruncateFirst, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
                GridBagConstraints.NORTHWEST, GridBagConstraints.WEST, new Insets(0, 0, 0, 295),
                10, 0));
        jpButtonPanel.add(jbutEXECUTE, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
                GridBagConstraints.NORTHWEST, GridBagConstraints.EAST, new Insets(0, 0, 0, 3), 10,
                0));
        jpButtonPanel.add(jbutRefresh, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 3), 0, 0));

        jpButtonPanel.add(jbutClose,
                new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST,
                        GridBagConstraints.NONE, new Insets(0, 3, 0, 0), 0, 0));
        this.getContentPane().setLayout(new GridBagLayout());

        /*
         JPanel jpDesc = UIToolKit.createDialogDescPanel(I18N
         .getLabelValue("DIALOG_DESC_DBRES_VIEW_TITLE"), I18N
         .getLabelValue("DIALOG_DESC_DBRES_VIEW_DESC"), ICON_DBSVR_RESVIEW_DESC);
         this.getContentPane().add(
         jpDesc,
         new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,
         GridBagConstraints.HORIZONTAL, new Insets(0, 0, 3, 0), 0, 0));
         */
        this.getContentPane().add(
                jpTabRoot,
                new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
                        GridBagConstraints.BOTH, new Insets(3, 12, 6, 12), 385, 242));
        this.getContentPane().add(
                jpButtonPanel,
                new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
                        GridBagConstraints.NONE, new Insets(6, 0, 12, 12), 0, 0));
        jbutClose.requestFocus();
        return true;
    }

    /**
     * 加载当前库的所有表的信息
     * @return boolean 失败返回false
     */
    private boolean loadTableInfoofCurrUser()
    {
        String dbName = (String) jcmbDBName.getSelectedItem();
        Vector vecTableInfo2D = null;
        try
        {
            vecTableInfo2D = DBAction.getAllTableInfoOfOwner(this.jfmMain, dbName, this.dbInfo);
            for(int i = 0; i < vecTableInfo2D.size(); i++)
            {
                Vector vecRowData = (Vector) vecTableInfo2D.get(i);
                Vector vecParsed = parseData(vecRowData);
                vecTableInfo2D.setElementAt(vecParsed, i);
            }
            jtbModelTableInfo.setDataVector(vecTableInfo2D, this.vecColumnStrTableInfo);
            int iWidth = this.dbInfo.getDBType() == DatabaseInfo.DBTYPE_ORACLE ? 220 : 150;
            for(int iIndex = 0; iIndex < vecColumnStrTableInfo.size(); iIndex++)
            {
                jtblTableInfo.getColumnModel().getColumn(iIndex).setPreferredWidth(iWidth);
            }
        }
        catch(FIException fiEx)
        {
            ZJShowMsgPane.showDetailMessage(this, fiEx);
            return false;
        }
        return true;
    }

    /**
     *
     *设置显示DB和Table信息的JTable列名称
     */
    private void setupColumnStrVector()
    {
        vecColumnStrDBInfo = new Vector();
        vecColumnStrTableInfo = new Vector();

        int iDBType = this.dbInfo.getDBType();
        switch(iDBType)
        {
            case DatabaseInfo.DBTYPE_ORACLE:
                //显示DB信息的JTable控件列名
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("dbSpaceName"));
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("assignSize") + "(KB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("usedSize") + "(KB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("leftSize") + "(KB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("leftPercent") + "(%)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("autoextensible"));
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("datafile"));
                //显示table信息的JTable控件列名
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("tabName"));
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("inDbSpace"));
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("recNum"));

                break;
            case DatabaseInfo.DBTYPE_MSSQL:
                //显示DB信息的JTable控件列名
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("dbName"));
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("dbSize") + "(MB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("UnassignSize") + "(MB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("reserveSize") + "(KB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("dataSize") + "(KB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("indexSize") + "(KB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("unusedSize") + "(KB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("I18N_MDF_FREE_PERCENT") + "(%)");
                //显示table信息的JTable控件列名
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("tabName"));
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("recNum"));
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("reserveSize") + "(KB)");
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("dataSize") + "(KB)");
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("indexSize") + "(KB)");
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("unusedSize") + "(KB)");
                //显示 process info 的JTable控件列名

                break;

            default:
                dMsg.error("Wrong database got! iDBType=" + iDBType);
                break;
        }
    }

    /**
     * 将数据库/用户名 添加到 jcmbDBName 中
     */
    private boolean addAllDBNamesToJcmbDBName()
    {
        String[] dbName = new String[3];
        if(this.dbInfo.getDBType() == DatabaseInfo.DBTYPE_ORACLE)
        {
            dbName[0] = DatabaseInfo.EMS_ORACLE_UEP;
            dbName[1] = DatabaseInfo.EMS_ORACLE_UEPPM;
            dbName[2] = DatabaseInfo.EMS_ORACLE_CAFFM;

        }
        else
        {
            dbName[0] = DatabaseInfo.EMS_MSSQL_UEP;
            dbName[1] = DatabaseInfo.EMS_MSSQL_UEPPM;
            dbName[2] = DatabaseInfo.EMS_MSSQL_CAFFM;

        }
        String[] arrStrDBNames = null;
        try
        {
            arrStrDBNames = DBAction.getDBSOwners(this.jfmMain, this.dbInfo);
            if(arrStrDBNames != null)
            {
                for(int i = 0; i < arrStrDBNames.length; i++)
                {
                    for(int j = 0; j < dbName.length; j++)
                    {
                        if(dbName[j].equalsIgnoreCase(arrStrDBNames[i]))
                        {
                            jcmbDBName.addItem((arrStrDBNames[i]));
                        }
                    }
                }
                jcmbDBName.setSelectedIndex(0);
            }
        }
        catch(FIException fiEx)
        {
            ZJShowMsgPane.showDetailMessage(this, fiEx);
            return false;
        }
        return true;
    }

    /**
     *
     * @param itemEvent
     */
    private void jcmbDBName_itemStateChanged(ActionEvent itemEvent)
    {
        String dbName = (String) jcmbDBName.getSelectedItem();
        Vector vecTableInfo2D = null;
        this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
        try
        {
            vecTableInfo2D = DBAction.getAllTableInfoOfOwner(this.jfmMain, dbName, this.dbInfo);
            jtbModelTableInfo.removeAllRow();
            for(int i = 0; i < vecTableInfo2D.size(); i++)
            {
                Vector vecRawData = (Vector) vecTableInfo2D.get(i);
                Vector vecParsed = parseData(vecRawData);
                jtbModelTableInfo.addRow(vecParsed);
            }
        }
        catch(FIException fiEx)
        {
            jtbModelTableInfo.setDataVector(vecTableInfo2D, this.vecColumnStrTableInfo);
            ZJShowMsgPane.showDetailMessage(this, fiEx);
        }
        this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }

    /**
     *
     * @param vec
     * @return
     */
    private Vector parseData(Vector vec)
    {
        Vector vecFolat = new Vector();
        int iVecSize = vec.size();
        float fvalue = (float) 0.0;
        int iDBType = this.dbInfo.getDBType();
        for(int i = 0; i < iVecSize; i++)
        {
            String tempstr = vec.get(i).toString();
            // TODO 单号610000056089
            if(i == 0)
            {
                vecFolat.addElement(tempstr);
                continue;
            }
            tempstr = tempstr.trim();
            String oldtemp = tempstr;
            int iUnit = tempstr.indexOf("MB");
            if(iUnit == -1)
            {
                iUnit = tempstr.indexOf("KB");
            }
            if(iUnit == -1)
            {
                iUnit = tempstr.indexOf("%");
            }
            if(iUnit == -1)
            {
                try
                {
                    //格式化显示剩余空间数据,都显示两位小数
                    switch(iDBType)
                    {
                        case DatabaseInfo.DBTYPE_MSSQL:
                            if(i == iVecSize - 1)
                            {
                                DecimalFormat df1 = new DecimalFormat("0.00");
                                vecFolat.addElement(df1.format(Float.valueOf(tempstr)));
                            }
                            else
                            {
                                vecFolat.addElement(Float.valueOf(tempstr));
                            }
                            break;
                        case DatabaseInfo.DBTYPE_ORACLE:
                            if(i == 4)
                            {
                                DecimalFormat df1 = new DecimalFormat("0.00");
                                vecFolat.addElement(df1.format(Float.valueOf(tempstr)));
                            }
                            else
                            {
                                vecFolat.addElement(Float.valueOf(tempstr));
                            }
                            break;
                    }
                    continue;
                }
                catch(NumberFormatException ex)
                {
                    vecFolat.addElement(tempstr);
                    continue;
                }
            }
            try
            {
                tempstr = tempstr.substring(0, iUnit);
                fvalue = Float.parseFloat(tempstr);
                vecFolat.addElement(new Float(fvalue));
            }
            catch(NumberFormatException ex)
            {
                vecFolat.addElement(oldtemp);
                continue;
            }
        }
        return vecFolat;
    }

    /**
     *
     * @param e
     * @JTIUP
     */
    private void jbutUpdateDBMSOwnerSystemTables_actionPerformed(ActionEvent e)
    {

        //        int iOption = ZJShowMsgPane.showConfirmDialog(STMClientView.getSTMMainFrame(),
        //                I18N.getLabelValue("I18N_UPDATE_STAT_TIP"),
        //                I18N.getLabelValue("dialogQuestion"),
        //                ZJShowMsgPane.OK_CANCEL_OPTION,
        //                ZJShowMsgPane.QUESTION_MESSAGE);
        //       if(iOption != ZJShowMsgPane.OK_OPTION) {
        //        return;
        //       }
        // begin updating...
        String strOwner = (String) jcmbDBName.getSelectedItem();
        this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
        try
        {
            this.dbInfo.setOwner(strOwner);
            DBAction.updateDBMSSystemTables(this, this.dbInfo, strOwner);
        }
        catch(FIException fiEx)
        {
            ZJShowMsgPane.showDetailMessage(this, fiEx);
        }
        this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        ZJShowMsgPane.showMessageDialog(this, I18N.getLabelValue("I18N_UPDATING_TIP"),
                ZJShowMsgPane.INFORMATION_MESSAGE);
    }

    /**
     * 关闭操作
     * 也就是唯一按钮ok按钮的action响应方法
     * @param e
     * @JTIUP
     */
    private void jbutOk_actionPerformed(ActionEvent e)
    {
        this.close();
    }

    /**
     * 关闭操作
     * 也就是唯一按钮ok按钮的action响应方法
     * @param e
     * @JTIUP
     */
    private void jbutEXECUTE_actionPerformed(ActionEvent e)
    {
        dMsg.error("按下导入按钮");
        importTable();
        //this.close();
    }

    /**
     * 注册escape按键事件到指定组件 当指定组件在当前窗口时,action动作会注册到escape按键响应上
     *
     * @param component
     * @param action
     */
    private void registerEscapeAction(JComponent component, Action action)
    {
        component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_STROKE,
                STR_ESCAPE_RELEASED);
        component.getActionMap().put(STR_ESCAPE_RELEASED, action);
    }

    /**
     * 撤销指定组件的escape事件
     * 将escape响应从指定组件上撤销
     * @param component
     */
    private void unregisterEscapeAction(JComponent component)
    {
        component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(ESCAPE_STROKE);
        component.getActionMap().remove(STR_ESCAPE_RELEASED);
    }

    private void importTable()
    {

        try
        {
            if(jtblTableInfo.getSelectedRow() == -1)
            {
                throw new STMRuntimeException(STMConsts.getI18N().getLabelValue(
                        "info_dataclear_chooseTable"));
            }

            this.path = jvalueTextArea.getText().trim();

            if(path.equals(""))
            {
                throw new STMRuntimeException(STMConsts.getI18N().getLabelValue(
                        "info_imp_inputfile"));
            }

            File file = new File(path);
            if(file.exists() && file.isFile())
            {

            }
            else
            {
                throw new STMRuntimeException(STMConsts.getI18N().getLabelValue(
                        "info_imp_inputfile_ag"));
            }
            this.dbName = (String) jcmbDBName.getSelectedItem();
            this.tableName = (String) jtblTableInfo.getModel().getValueAt(
                    jtblTableInfo.getSelectedRow(), 0);

            //checkData(dbName,tableName);
            close();
//            MainFrame.waitThread = new WaitThread(main, STMConsts.getI18N().getLabelValue(
//                    "info_imp_waitng"), STMConsts.getI18N().getLabelValue("info_imp_waitng"));
//            MainFrame.waitThread.start();
            main.paintStatus(STMConsts.getI18N().getLabelValue("info_imp_waitng"));
            main.guiChange(false);
            new Thread()
            {

                public void run()
                {
                    try
                    {
                        if(jcIsTruncateFirst.isSelected())
                        {
                            String sql = "truncate table " + dbName + ".dbo." + tableName;
                            DBAction.executeUpdateSql(jfmMain, dbInfo, dbName, sql);
                        }

                        String fileName = path;

                        String[] tableNames = new String[1];
                        String[] fileNames = new String[1];
                        tableNames[0] = tableName;
                        fileNames[0] = fileName;
                        DBAction.runTableBcpProcessor(main, dbInfo, dbName, tableNames, path,
                                fileNames, 0);
                    }

                    catch(FIException e)
                    {
                        //MainFrame.closeWaitDialog();
                        main.clearStatus();
                        main.guiChange(true);
                        ZJShowMsgPane.showMessageDialog(thisDialog, e.toString(), STMConsts
                                .getI18N().getLabelValue("ZJShowMsgPane_QuestionMessage"),
                                ZJShowMsgPane.WARNING_MESSAGE);
                    }
                }
            }.start();

        }
        catch(STMRuntimeException e)
        {
            ZJShowMsgPane.showMessageDialog(this, e.toString(), STMConsts.getI18N().getLabelValue(
                    "ZJShowMsgPane_QuestionMessage"), ZJShowMsgPane.WARNING_MESSAGE);

        }

    }

    private void selectPath(JTextField path)
    {
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new File("./"));
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        chooser.setFileFilter(new FileFilterBase("txt"));

        int returnVal = chooser.showOpenDialog(this);

        if(returnVal == JFileChooser.APPROVE_OPTION)
        {
            path.setText(chooser.getSelectedFile().getPath());
        }
    }

    /**
     * 退出对话框
     */
    private void close()
    {
        unregisterEscapeAction(this.getRootPane());

        dispose();
    }

    private void setCellRender(JTable table)
    {
        int size = table.getColumnCount();
        for(int i = 0; i < size; i++)
        {
            Class cla = table.getColumnClass(i);
            table.setDefaultRenderer(cla, new CellRender());
        }
    }

    /**
     * <p>Title: </p>
     *
     * <p>Description: </p>
     *
     * <p>Copyright: Copyright (c) 2007</p>
     *
     * <p>Company: 中兴通讯股分有限公司</p>
     * @author wanghong
     * @version 3.0
     */
    private class CellRender extends DefaultTableCellRenderer
    {

        /**
         *
         */
        private static final long serialVersionUID = 1L;

        CellRender()
        {
        }

        /**
         * Returns the component used for drawing the cell.
         *
         * @param table the <code>JTable</code> that is asking the renderer to draw; can be <code>null</code>
         * @param value the value of the cell to be rendered. It is up to the specific renderer to interpret and draw
         *   the value. For example, if <code>value</code> is the string "true", it could be rendered as a string or it
         *   could be rendered as a check box that is checked. <code>null</code> is a valid value
         * @param isSelected true if the cell is to be rendered with the selection highlighted; otherwise false
         * @param hasFocus if true, render cell appropriately. For example, put a special border on the cell, if the
         *   cell can be edited, render in the color used to indicate editing
         * @param row the row index of the cell being drawn. When drawing the header, the value of <code>row</code> is -1
         * @param column the column index of the cell being drawn
         * @return Component
         * @todo Implement this javax.swing.table.TableCellRenderer method
         */
        public Component getTableCellRendererComponent(JTable table, Object value,
                boolean isSelected, boolean hasFocus, int row, int column)
        {
            Object disPlay = value;
            if(value instanceof Float)
            {
                //去掉小数点
                if(value.toString().endsWith(".0"))
                {
                    disPlay = String.valueOf(((Float) value).longValue());
                }
            }
            return super.getTableCellRendererComponent(table, disPlay, isSelected, hasFocus, row,
                    column);
        }
    }

    /**
     *
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2007</p>
     * <p>Company: 中兴通讯股分有限公司</p>
     * @author not attributable
     * @version 3.0
     */
    private class UpdateHandler implements Runnable
    {

        private TableBcpInDialogOfMSSQL dbResDialog = null;

        /**
         * 更新界面
         * @param dialog DBResourceDialog
         */
        public UpdateHandler(TableBcpInDialogOfMSSQL dialog)
        {
            dbResDialog = dialog;
        }

        /**
         * 更新界面
         */
        public void run()
        {
            dbResDialog.setCursor(new Cursor(Cursor.WAIT_CURSOR));
            try
            {
                dbResDialog.loadTableInfoofCurrUser();
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
            catch(Throwable ex)
            {
                ex.printStackTrace();
            }
            dbResDialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

        }
    }

    public AbstractProcessJFrame getMain()
    {
        return main;
    }

    public void setMain(AbstractProcessJFrame main)
    {
        this.main = main;
    }
}

资源下载链接为: https://pan.quark.cn/s/0c983733fad2 本文主要回顾了2021年之前及2021年中国科学技术大学软件学院(简称“中科大软院”)高级软件工程(MN)专业的考试情况,重点聚焦于编程题。编程题在考试中的占比不断提高,因此考生需要深入理解这些题目及其解题方法。 中科大软院的高级软件工程专业致力于培养具备深厚理论基础和强大实践能力的高级软件人才。课程设计注重理论与实践相结合,以满足软件行业对高素质工程师的需求。考试内容通常涵盖计算机基础知识、软件工程理论、编程语言、数据结构与算法、操作系统、数据库系统等多个领域。2021年的考试中,编程题的比重进一步提升,这体现了学院对学生实际编程能力和问题解决能力的重视。 编程题通常涉及常见的编程问题,例如字符串处理、数组操作、递归算法、图论问题等,也可能包括网络编程、数据库查询或系统设计等特定领域的应用。考生需要熟练掌握至少一种编程语言,如C++、Java、Python等,并具备较强的算法分析和实现能力。在解题过程中,考生需要注意以下几点:一是准确理解题目要求,避免因误解而导致错误;二是合理选择并设计算法,考虑时间复杂度和空间复杂度,追求高效性;三是遵循良好的编程规范,注重代码的可读性和可维护性;四是考虑边界条件和异常情况,编写健壮的代码;五是编写测试用例,对代码进行充分测试,及时发现并修复问题。 对于备考的同学,建议多做历年试题,尤其是编程题,以熟悉题型和解题思路。同时,可以参加编程竞赛或在在线编程平台(如LeetCode、HackerRank)进行实战训练,提升编程和问题解决能力。此外,关注PPT中的编程代码也很关键,因为这些代码可能是老师给出的示例或解题思路,能够帮助学生更好地理解和掌握编程题的解法。因此,考生需要深入学习PPT内容,理解代码逻辑,并学会将其应用到实际编程题目中。 总之,对于
资源下载链接为: https://pan.quark.cn/s/5c50e6120579 在Android移动应用开发中,定位功能扮演着极为关键的角色,尤其是在提供导航、本地搜索等服务时,它能够帮助应用获取用户的位置信息。以“baiduGPS.rar”为例,这是一个基于百度地图API实现定位功能的示例项目,旨在展示如何在Android应用中集成百度地图的GPS定位服务。以下是对该技术的详细阐述。 百度地图API简介 百度地图API是由百度提供的一系列开放接口,开发者可以利用这些接口将百度地图的功能集成到自己的应用中,涵盖地图展示、定位、路径规划等多个方面。借助它,开发者能够开发出满足不同业务需求的定制化地图应用。 Android定位方式 Android系统支持多种定位方式,包括GPS(全球定位系统)和网络定位(通过Wi-Fi及移动网络)。开发者可以根据应用的具体需求选择合适的定位方法。在本示例中,主要采用GPS实现高精度定位。 权限声明 在Android应用中使用定位功能前,必须在Manifest.xml文件中声明相关权限。例如,添加<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />,以获取用户的精确位置信息。 百度地图SDK初始化 集成百度地图API时,需要在应用启动时初始化地图SDK。通常在Application类或Activity的onCreate()方法中调用BMapManager.init(),并设置回调监听器以处理初始化结果。 MapView的创建 在布局文件中添加MapView组件,它是地图显示的基础。通过设置其属性(如mapType、zoomLevel等),可以控制地图的显示效果。 定位服务的管理 使用百度地图API的LocationClient类来管理定位服务
资源下载链接为: https://pan.quark.cn/s/9ce3e35e0f39 在当今的微服务架构中,定时任务是不可或缺的,它广泛应用于数据同步、报表生成、缓存更新等场景。xxl-job是一款功能强大的分布式任务调度平台,具备易用的可视化界面、高效稳定的分布式调度能力以及丰富的调度策略。与SpringBoot的集成,使得定时任务的管理和执行变得更加高效便捷。本文将详细介绍如何将xxl-job与SpringBoot进行集成,实现高效的定时任务管理。 xxl-job包含两个核心组件: 调度中心(xxl-job-admin):负责任务的注册、管理和调度。 执行器(xxl-job-executor):负责任务的实际执行,可以部署在多个节点上,实现分布式运行。 添加依赖:在SpringBoot项目中,通过pom.xml文件引入xxl-job-admin和xxl-job-executor的依赖,确保版本匹配。 配置调度中心:在xxl-job-admin中配置数据库连接信息,创建表结构,并在application.properties中设置调度中心的访问地址。 配置执行器:在xxl-job-executor-sample-springboot模块中,配置执行器的属性,如ID、名称、IP等,并指定调度中心的地址。 编写Job Handler:在xxl-job-executor-sample-springboot中创建一个实现com.xxl.job.core.handler.IJobHandler接口的类,定义任务逻辑,并通过@Component注解进行自动扫描。 注册Job Handler:在启动类中,通过@Autowired注入XxlJobAdminConfig,并调用registerJobHandler方法将Job Handler注册到执行器中。 创建任务:在xxl-job-
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值