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

📄 getoutquery.java

📁 企业物资管理系统 为了使物资管理部门的责、权、利得到落实, 以提高总体的经济效益,采用J2EE 技术体系, 设计与实现了B/S 模式下的企业物资管理系统, 依据开发实例,分析了企业物资管理系统的
💻 JAVA
字号:
//QueryDB.java
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

 
public class GetoutQuery extends JFrame implements ActionListener
{
 private Connection con=null;
 private Statement stmt =null;
 private ResultSet rs =null;
 private JLabel conditionlabel=new JLabel("请填写下列查询条件", SwingConstants.CENTER);
 private JLabel outidlabel=new JLabel("出库编号", SwingConstants.RIGHT);
 private JTextField outid =new JTextField(10);
 private JLabel idlabel=new JLabel("出库物资编号", SwingConstants.RIGHT);
 private JTextField id =new JTextField(10);
 private JLabel namelabel=new JLabel("物资名称", SwingConstants.RIGHT);
 private JTextField name =new JTextField(10);
 private JLabel timelabel=new JLabel("出库时间", SwingConstants.RIGHT);
 private JTextField time =new JTextField(10);
 private JButton commit=new JButton("递交");
 private JLabel resultlabel=new JLabel("查询结果", SwingConstants.RIGHT);
 private JTextArea resultarea=new JTextArea(10,28);
 private  String command=null;
 public GetoutQuery(){
   setTitle("出库信息查询");
   setSize(500,200);
 addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e)
       {System.exit(0);}
   });
 getContentPane().setLayout(new GridBagLayout());
 //以下代码功能是使用girdbaglayout布局编排swing组件
 GridBagConstraints gbc=new GridBagConstraints();
 gbc.fill=GridBagConstraints.NONE;
 gbc.anchor=GridBagConstraints.CENTER;
 gbc.weightx=100;
 gbc.weighty=100;
 add(conditionlabel,gbc,3,0,5,1);
 add(outid,gbc,1,1,2,1);
 add(id,gbc,4,1,1,1); 
 add(name,gbc,6,1,1,1);
 gbc.anchor=GridBagConstraints.WEST;
 add(time,gbc,8,1,3,1);
 gbc.anchor=GridBagConstraints.CENTER;
 add(commit,gbc,5,2,1,1);
 add(resultlabel,gbc,4,3,3,1);
 JScrollPane scrollpane=new JScrollPane(resultarea);
 add(scrollpane,gbc,3,4,5,3);
 resultarea.setEditable(false);
 resultarea.setLineWrap(true);
 gbc.anchor=GridBagConstraints.EAST;
 add(outidlabel,gbc,0,1,1,1);
 add(idlabel,gbc,3,1,1,1);
 add(namelabel,gbc,5,1,1,1);
 gbc.anchor=GridBagConstraints.CENTER;
 add(timelabel,gbc,7,1,1,1);
 commit.addActionListener(this);
 commit.setNextFocusableComponent(id);
 try{
     String url ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=BasicInfo";
     String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
     Class.forName(driverName).newInstance(); 
      con=DriverManager.getConnection(url,"SA","");
     stmt=con.createStatement();
    }catch(Exception ex)
      {
        resultarea.append(ex.getMessage()+"\n");
        return;
       }
   setSize(800,600);
   show();
}

 public void add(Component c,GridBagConstraints gbc,int x,int y, int w,int h)
 {
   gbc.gridx=x; gbc.gridy=y; gbc.gridwidth=w; gbc.gridheight=h;
   getContentPane().add(c,gbc);
  }
 
 public void actionPerformed(ActionEvent evt)
 {
   try{
        String outidvalue=outid.getText().trim();
        String idvalue=id.getText().trim();
        String namevalue=name.getText().trim();
        String timevalue=time.getText().trim();
        String soutid ,sid,sname,stime;
          //支持模糊搜索,并且当查询条件中出现某项输入为空时,认为此项取值不受限制
        soutid=" LIKE '%"+outidvalue+"%' ";
        sid=" LIKE '%"+idvalue+"%' ";
        sname=" LIKE '%"+namevalue+"%' ";
        stime=" LIKE '%"+timevalue+"%' ";
command="use basicinfo SELECT * FROM  GetoutInformation where 出库编号"+soutid+" and 出库物资编号"+sid+" and 物资名称"+sname+" and 出库时间"+stime;
   rs=stmt.executeQuery(command);
   resultarea.setText("");
   if(!rs.next())
      resultarea.setText("找不到符合此条件的记录");
   else{
     do{
        String reoutid=rs.getString("出库编号").trim();
        String reid=rs.getString("出库物资编号").trim();
        String retime=rs.getString("出库时间").trim(); 
    String rename=rs.getString("物资名称").trim();
      resultarea.append(reoutid);
      //计算入库物资编号的长度,在编号后输出相应的空格,以使后面的名称等列对齐
     int length=reoutid.length();
     for(int i=1;i<=(16-2*length);i++)
         resultarea.append(" ");
         resultarea.append(reid+"         ");
         resultarea.append(rename+"            ");
         resultarea.append(retime+"\n");
        }while(rs.next());
     }

   }catch(Exception  ex)
     {
       resultarea.append(ex.getMessage()+"\n");
      }
   }
 }






⌨️ 快捷键说明

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