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

📄 backteldialog.java

📁 用java编写的人事管理系统,很好的 学习下吧
💻 JAVA
字号:
/**
 * 源文件:BackTelDialog.java
 * 作用:退货信息窗体
 */
package mypro;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;

public class BackTelDialog extends JDialog implements ActionListener,MouseListener
{
	BackTelData bd=new BackTelData();
	Check check=new Check();
	private JLabel labBackInvoice,labImei,labBackDate,labUserCode,labReason;
	private JTextField txtBackInvoice,txtImei,txtBackDate,txtUserCode;
	private JButton btnInsert,btnDelete;
	private JTextArea teaReason;
	private JScrollPane scop,scop1;
	private JTable tabShow;
	private DefaultTableModel dtm;//定义表模型
	private int row=0;
	
	static 
	{
   	 	//设置窗体为豪华框架
   		JDialog.setDefaultLookAndFeelDecorated(true);		
	}
	
	public BackTelDialog(MainFrame owner,boolean bo)
	{
		super(owner,bo);
	  	labBackInvoice = new JLabel("*退货单号");
  		txtBackInvoice = new JTextField();
  		labImei = new JLabel("*手机串号");
  		txtImei = new JTextField();
  		labBackDate = new JLabel("*退货日期");
  		txtBackDate = new JTextField();
  		labUserCode = new JLabel("*工号");
  		txtUserCode = new JTextField();
  		labReason = new JLabel("*退机原因");
  		teaReason = new JTextArea("");
  		btnInsert = new JButton("插入");
  		btnDelete = new JButton("删除");
  		scop = new JScrollPane();
  		scop1 = new JScrollPane();
  		tabShow = new JTable();
  		
        labBackInvoice.setBounds(new Rectangle(12, 16, 73, 14));
    	txtBackInvoice.setBounds(new Rectangle(82, 16, 121, 23));
    	labImei.setBounds(new Rectangle(12, 49, 73, 14));
    	txtImei.setBounds(new Rectangle(82, 49, 121, 23));
    	labBackDate.setBounds(new Rectangle(12, 82, 73, 14));
    	txtBackDate.setBounds(new Rectangle(82, 82, 121, 23));
    	labUserCode.setBounds(new Rectangle(254, 18, 73, 14));
    	txtUserCode.setBounds(new Rectangle(330, 18, 121, 23));
    	labReason.setBounds(new Rectangle(254, 49, 73, 14));
        scop1.setBounds(new Rectangle(330, 49, 121, 55));
        
        btnInsert.setBounds(new Rectangle(100, 148, 89, 28));
    	btnInsert.setActionCommand("Insert");
        btnInsert.setToolTipText("插入新的退货信息");
    	btnDelete.setBounds(new Rectangle(270, 148, 89, 28));
    	btnDelete.setActionCommand("Delete");
    	btnDelete.setToolTipText("删除退货信息");
    	scop.setBounds(new Rectangle(12, 190, 439, 98));
    	/*注册监听器*/
    	btnInsert.addActionListener(this); 
    	btnDelete.addActionListener(this);
    	tabShow.addMouseListener(this);
        
        Container me=this.getContentPane();
  		me.setLayout(null);
     	me.add(labBackInvoice);
        me.add(txtBackInvoice);
        me.add(labImei);
        me.add(txtImei);
        me.add(labBackDate);
        me.add(txtBackDate);
        me.add(labUserCode);
   	 	me.add(txtUserCode);
   	 	me.add(labReason);
    	me.add(btnInsert);
    	me.add(btnDelete);
    	me.add(scop);
        me.add(scop1);
        scop1.getViewport().add(teaReason);
        scop.getViewport().add(tabShow);
        DatabaseOperate datao = new DatabaseOperate();
  		dtm = new DefaultTableModel(datao.getDataByTabname("backTel"),datao.getColumnNamesByTabname("backTel"));
        tabShow.setModel(dtm);//通过dtm模型构造表
        tabShow.setAutoResizeMode(tabShow.AUTO_RESIZE_OFF);//当调整表的大小时,设置表的自动调整模式为不自动调整列的宽度;使用滚动条
    	
		this.setTitle("退货信息");
	  	this.setSize(480,380);
	  	this.setLocationRelativeTo(this);
	  	this.setResizable(false);
	  	this.setVisible(true);
	  }
	  public void actionPerformed(ActionEvent bae)
	  {
	  	String strbtn=bae.getActionCommand();
	  	
	  	if(strbtn.equals("Insert"))
	  	{
	  		int strbi=0;
			try
			{
			  	strbi=Integer.parseInt(txtBackInvoice.getText().trim());
			}
			catch(NumberFormatException ne)
			{
			  	JOptionPane.showMessageDialog(null,"请输入4位以内整数","提示",JOptionPane.INFORMATION_MESSAGE);
			}
			if(check.checkPrimary("backTel","退货单号",strbi))
			{
			  	JOptionPane.showMessageDialog(null,"该退货单号已存在","提示",JOptionPane.INFORMATION_MESSAGE);
			  	txtBackInvoice.setText("");
		 		txtBackInvoice.requestFocus();			
			}
			else if(operationBeforeCheck())
			{
				InsertData ind =new InsertData();
				Vector vid = new Vector();
				vid.add(bd.getBackInvoice());
				vid.add(bd.getImei());
				vid.add(bd.getBackDate());
				vid.add(bd.getUserCode());
				vid.add(bd.getReason());
				if(ind.BackTelInsert(bd))
			  	{
			  		JOptionPane.showMessageDialog(null,"成功插入一行数据","提示",JOptionPane.INFORMATION_MESSAGE);
			  		dtm.addRow(vid);//添加一行到模型的结尾
			  		new SellTelDialog(null,true);	
			  	}
			  	else
			  	{
			  		JOptionPane.showMessageDialog(null,"数据插入失败","提示",JOptionPane.INFORMATION_MESSAGE);	
			  	}	
			}
	  	}
	  	else if(strbtn.equals("Delete"))
		{
			Integer n=(Integer)tabShow.getValueAt(row,0);
			int strbi=n.intValue();
			DeleteData ded=new DeleteData();
			if(ded.deleteDate("backTel","退货单号",strbi))
			{
				JOptionPane.showMessageDialog(null,"成功删除一行数据","提示",JOptionPane.INFORMATION_MESSAGE);
				dtm.removeRow(row);//移除模型中 row 位置的行。
			}
			else
			{
				JOptionPane.showMessageDialog(null,"数据删除失败","提示",JOptionPane.INFORMATION_MESSAGE);
			}		
		}
		txtBackInvoice.setText("");
		txtImei.setText("");
		txtBackDate.setText("");
		txtUserCode.setText("");
		teaReason.setText("");
	  }
	  /*单击表中的一行将数据返回到组件中*/
	  public void mouseEntered(MouseEvent me){}
	  public void mouseExited(MouseEvent me){}
	  public void mousePressed(MouseEvent me){}
	  public void mouseReleased(MouseEvent me){}
	  public void mouseClicked(MouseEvent me)
	  {
	  	row=tabShow.getSelectedRow();
	  	String strbi=String.valueOf(tabShow.getValueAt(row,0));
	  	String strimei=(String)tabShow.getValueAt(row,1);
	  	String strbackd=(String)tabShow.getValueAt(row,2);
	  	String strcode=(String)tabShow.getValueAt(row,3);
	  	String strrea=(String)tabShow.getValueAt(row,4);

	  	txtBackInvoice.setText(strbi.trim());
	  	txtImei.setText(strimei.trim());
	  	txtBackDate.setText(strbackd.trim());
	  	txtUserCode.setText(strcode.trim());
	  	teaReason.setText(strrea.trim());
	  	
	  }
	  /* 执行操作前对数据进行验证*/
	  public boolean operationBeforeCheck()
	  {
			int strbi=0;
			try
			{
			  	strbi=Integer.parseInt(txtBackInvoice.getText().trim());
			}
			catch(NumberFormatException ne)
			{
			  	JOptionPane.showMessageDialog(null,"请输入4位以内整数","提示",JOptionPane.INFORMATION_MESSAGE);
			  	return false;
			}
			String strimei=txtImei.getText().trim();
			String strbackd=txtBackDate.getText().trim();
			String strcode=txtUserCode.getText().trim();
			String strrea=teaReason.getText().trim();
			
			bd.setBackInvoice(strbi);
			bd.setImei(strimei);
			bd.setBackDate(strbackd);
			bd.setUserCode(strcode);
			bd.setReason(strrea);
			
			if(strbi==0||strimei.length()==0||strbackd.length()==0||strcode.length()==0||strrea.length()==0)
			{
				JOptionPane.showMessageDialog(null,"带*号的必填,请填写完整","提示",JOptionPane.INFORMATION_MESSAGE);
				return false;
			}
			else if(strbi>9999&&strbi<0)
			{
			  	JOptionPane.showMessageDialog(null,"请输入4位以内整数","提示",JOptionPane.INFORMATION_MESSAGE);
			  	txtBackInvoice.setText("");
		 		txtBackInvoice.requestFocus();
		 		return false;
			}
			else if(!(check.checkPrimary("sellTel","手机串号",strimei)))
			{
				JOptionPane.showMessageDialog(null,"手机未售出","提示",JOptionPane.INFORMATION_MESSAGE);
			  	txtImei.setText("");
		 		txtImei.requestFocus();
		 		return false;
			}
			else if(!check.checkDate(strbackd))
			{
			  	JOptionPane.showMessageDialog(null,"请输入准确的,如1996-02-03格式的日期","提示",JOptionPane.INFORMATION_MESSAGE);
			  	txtBackDate.setText("");
		 		txtBackDate.requestFocus();
		 		return false;
			}
			else if(!(check.checkPrimary("users","工号",strcode)))
			{
				JOptionPane.showMessageDialog(null,"无此员工信息","提示",JOptionPane.INFORMATION_MESSAGE);
			  	txtUserCode.setText("");
		 		txtUserCode.requestFocus();
		 		return false;
			}
			else if(strrea.length()>25)
			{
				JOptionPane.showMessageDialog(null,"字数过长","提示",JOptionPane.INFORMATION_MESSAGE);
		  		teaReason.setText("");
	 			teaReason.requestFocus();
	 			return false;
			}
			else
			{
				return true;
			}
	  }

}

⌨️ 快捷键说明

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