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

📄 deptmanagerframe.java

📁 Athena酒店小组_Athena酒店管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            }
        )
        {
            Class[] types = new Class []
            {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean []
            {
                false, false
            };

            public Class getColumnClass(int columnIndex)
            {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex)
            {
                return canEdit [columnIndex];
            }
        });
        deptTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        deptTable.addMouseListener(new java.awt.event.MouseAdapter()
        {
            public void mouseClicked(java.awt.event.MouseEvent evt)
            {
                deptTableMouseClicked(evt);
            }
        });

        deptTableScrollPane.setViewportView(deptTable);

        deleteButton.setFont(new java.awt.Font("新宋体", 0, 12));
        deleteButton.setMnemonic('D');
        deleteButton.setText("\u5220\u9664(D)");
        deleteButton.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                deleteButtonActionPerformed(evt);
            }
        });

        insertButton.setFont(new java.awt.Font("新宋体", 0, 12));
        insertButton.setMnemonic('A');
        insertButton.setText("\u65b0\u589e(A)");
        insertButton.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                insertButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(insertButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(deleteButton))
                    .addComponent(deptTableScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(deptInfoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(deptTableScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(deleteButton)
                            .addComponent(insertButton)))
                    .addComponent(deptInfoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formComponentShown(java.awt.event.ComponentEvent evt)//GEN-FIRST:event_formComponentShown
    {//GEN-HEADEREND:event_formComponentShown
	userInit();
    }//GEN-LAST:event_formComponentShown
    
    private void updateButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_updateButtonActionPerformed
    {//GEN-HEADEREND:event_updateButtonActionPerformed
	//获取部门信息
	String deptId = deptIdText.getText();
	String deptName = deptNameText.getText();
	String desc = descText.getText();
	DeptInfo dept = new DeptInfo(deptId, deptName);
	dept.setDescription(desc);
	
	DeptAccess da = new DeptAccess(Resource.getDBResource());
	if (evt.getActionCommand().equals("insert"))
	{
	    //新增
	    if (da.insert(dept) == 1)
	    {
		JOptionPane.showMessageDialog(null, "部门添加成功", "提示", JOptionPane.INFORMATION_MESSAGE);
		//更新Table
		userInit();
	    }
	    else
	    {
		JOptionPane.showMessageDialog(null, "部门添加失败!", "错误", JOptionPane.ERROR_MESSAGE);
	    }
	}
	else
	{
	    //更新
	    if (da.update(dept) == 1)
	    {
		JOptionPane.showMessageDialog(null, "部门信息修改成功", "提示", JOptionPane.INFORMATION_MESSAGE);
	    }
	    else
	    {
		JOptionPane.showMessageDialog(null, "部门信息修改失败!", "错误", JOptionPane.ERROR_MESSAGE);
	    }
	}
    }//GEN-LAST:event_updateButtonActionPerformed
    
    private void insertButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_insertButtonActionPerformed
    {//GEN-HEADEREND:event_insertButtonActionPerformed
	setInsertMode();
    }//GEN-LAST:event_insertButtonActionPerformed
    
    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_deleteButtonActionPerformed
    {//GEN-HEADEREND:event_deleteButtonActionPerformed
	int rs = JOptionPane.showConfirmDialog(null, "是否删除部门?", "问题", JOptionPane.YES_NO_OPTION);
	if (rs == JOptionPane.YES_OPTION)
	{
	    int index = deptTable.getSelectedRow();
	    if (index != -1)
	    {
		DeptInfo dept = (DeptInfo)deptTable.getValueAt(index, 1);
		DeptAccess da = new DeptAccess(Resource.getDBResource());
		if (da.delete(dept) == 1)
		{
		    JOptionPane.showMessageDialog(null, "部门删除成功", "提示", JOptionPane.INFORMATION_MESSAGE);
		}
		else
		{
		    JOptionPane.showMessageDialog(null, "部门删除失败!", "错误", JOptionPane.ERROR_MESSAGE);
		}
	    }
	}
    }//GEN-LAST:event_deleteButtonActionPerformed
    
    private void deptTableMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_deptTableMouseClicked
    {//GEN-HEADEREND:event_deptTableMouseClicked
	int index = deptTable.getSelectedRow();
	if (index != -1)
	{
	    DeptInfo dept = (DeptInfo)deptTable.getValueAt(index, 1);
	    deptIdText.setText(dept.getDeptId());
	    deptNameText.setText(dept.getDeptName());
	    descText.setText(dept.getDescription());
	    
	    setUpdateMode();
	}
    }//GEN-LAST:event_deptTableMouseClicked
        
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JButton deleteButton;
    private javax.swing.JLabel deptIdLabel;
    private javax.swing.JTextField deptIdText;
    private javax.swing.JPanel deptInfoPanel;
    private javax.swing.JLabel deptNameLabel;
    private javax.swing.JTextField deptNameText;
    private javax.swing.JTable deptTable;
    private javax.swing.JScrollPane deptTableScrollPane;
    private javax.swing.JLabel descLabel;
    private javax.swing.JScrollPane descScrollPane;
    private javax.swing.JTextArea descText;
    private javax.swing.JButton insertButton;
    private javax.swing.JButton updateButton;
    // 变量声明结束//GEN-END:variables
    
}

⌨️ 快捷键说明

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