fittingqueryAction.java
上传用户:flow_meter
上传日期:2022-03-21
资源大小:40k
文件大小:4k
- package sql_lab;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.eclipse.jface.action.Action;
- import org.eclipse.jface.dialogs.IInputValidator;
- import org.eclipse.jface.dialogs.InputDialog;
- import org.eclipse.jface.window.Window;
- import org.eclipse.swt.widgets.Display;
- import org.eclipse.swt.widgets.Text;
- import sql_lab.salequeryAction.saleValidator;
- public class fittingqueryAction extends Action {
- public fittingqueryAction(){
- super();
- this.setText("配件信息查询(&P)");
- this.setToolTipText("配件信息查询");
- }
- public void run(){
- if(MainWindow.log==false){
- Text content=MainWindow.getApp().getContent();
- content.append("请您先登陆n");
- return ;
- }
- InputDialog inputDialog=new InputDialog(Display.getCurrent().getActiveShell(),"请输入配件代号",
- "配件代号","",new fittingValidator() );//这个是自定义验证有效性的对象
- int result=inputDialog.open();
-
- if(result==Window.OK){//对数据库进行查询
- int saleNumber=Integer.parseInt(inputDialog.getValue());//得到售货单号
- String str1="call proc_1("+saleNumber+")";
- sqlManager sql=sqlManager.getSqlManager();
- sql.executeQuery(str1);
- String str2="select "+
- sqlManager.tb_produce+"."+sqlManager.row_produce_id+", "+// 选择配件id
- sqlManager.tb_produce+"."+sqlManager.row_produce_name+", "+//配件名称
- sqlManager.tb_produce+"."+sqlManager.row_produce_funtion+", "+//配件介绍
- sqlManager.tb_produce+"."+sqlManager.row_produce_price+", "+//配件价格
- sqlManager.tb_produce+"."+sqlManager.row_produce_sort+", "+//配件类别
- sqlManager.tb_producer+"."+sqlManager.row_producer_name+", "+//厂家名称
- sqlManager.tb_producer+"."+sqlManager.row_producer_address+", "+//厂家地址
- sqlManager.tb_producer+"."+sqlManager.row_producer_call+", "+//厂家电话
- sqlManager.tb_producer+"."+sqlManager.row_producer_describe+" "+//厂家介绍
- "from "+sqlManager.tb_fitting_result+" , "+sqlManager.tb_produce+", "+sqlManager.tb_producer+" "+
- "where "+sqlManager.tb_fitting_result+"."+sqlManager.row_result_id+"="+sqlManager.tb_produce+"."+
- sqlManager.row_produce_id+" and "+sqlManager.tb_produce+"."+sqlManager.row_produce_producer_id+"="+
- sqlManager.tb_producer+"."+sqlManager.row_producer_id+
- " ";
-
- ResultSet set=sql.executeQuery(str2);
- Text content=MainWindow.getApp().getContent();
- boolean flag=false;
- String s="***********************************配件信息查询查询结果**********************************n";
- content.append(s);
- try{
- while(set.next()){
- flag=true;
- //content.append(s);
- if(saleNumber==set.getInt(1))
- content.append("您要查的产品ID为:"+saleNumber+"n");
- else content.append("配件ID:"+set.getInt(1)+"n");
- content.append("名称: "+set.getString(2)+"n");
- content.append("介绍: "+set.getString(3)+"n");
- content.append("价格: "+set.getDouble(4)+"n");
- content.append("类别: "+set.getString(5)+"n");
- content.append("厂家信息n");
- content.append("生产厂家: "+set.getString(6)+"n");
- content.append("厂家地址: "+set.getString(7)+"n");
- content.append("厂家电话: "+set.getString(8)+"n");
- content.append("厂家介绍: "+set.getString(9)+"n");
- }
- }
- catch(SQLException e){
- e.printStackTrace();
- }
- content.append(s);
- if(flag==false)content.append("查询结果为空n");
- }
- else{
- System.out.println("input cancel");
- }
-
- }
- public class fittingValidator implements IInputValidator{
- public String isValid(String newText){
- try{
- Integer.parseInt(newText);
- }
- catch(NumberFormatException ne){
- return "输入错误,请输入有效的配件代号";
- }
- return null;
- }
- }
- }