salequeryAction.java
上传用户:flow_meter
上传日期:2022-03-21
资源大小:40k
文件大小:4k
源码类别:

MySQL数据库

开发平台:

SQL

  1. package sql_lab;
  2. /*
  3.  * 售货单信息查询
  4.  */
  5. import java.sql.*;
  6. import org.eclipse.jface.action.Action;
  7. import org.eclipse.jface.dialogs.IInputValidator;
  8. import org.eclipse.jface.dialogs.InputDialog;
  9. import org.eclipse.jface.window.Window;
  10. import org.eclipse.swt.widgets.Display;
  11. import org.eclipse.jface.action.*;
  12. import org.eclipse.jface.window.ApplicationWindow;
  13. import org.eclipse.swt.widgets.*;
  14. public class salequeryAction extends Action {
  15. public salequeryAction(){
  16. super();
  17. this.setText("售货单查询(&S)");
  18. this.setToolTipText("售货单查询");
  19. }
  20. public void run(){
  21. if(MainWindow.log==false){
  22. Text content=MainWindow.getApp().getContent();
  23. content.append("请您先登陆n");
  24. return ;
  25. }
  26. InputDialog inputDialog=new InputDialog(Display.getCurrent().getActiveShell(),"请输入售货单号",
  27.  "售货单号","",new saleValidator() );//这个是自定义验证有效性的对象
  28. int result=inputDialog.open();
  29. if(result==Window.OK){//对数据库进行查询
  30. int saleNumber=Integer.parseInt(inputDialog.getValue());//得到售货单号
  31. String str="select "+
  32. sqlManager.tb_sell+"."+sqlManager.row_sell_id+","+//得到售货单号
  33. sqlManager.tb_sell+"."+sqlManager.row_sell_amount+","+ //得到数量
  34. sqlManager.tb_sell+"."+sqlManager.row_sell_time+","+ //出售时间
  35. sqlManager.tb_customer+"."+sqlManager.row_customer_name+","+ //客户姓名
  36. sqlManager.tb_customer+"."+sqlManager.row_customer_address+","+//客户地址
  37. sqlManager.tb_customer+"."+sqlManager.row_customer_call+","+//客户电话
  38. sqlManager.tb_customer+"."+sqlManager.row_customer_mail+","+//得到客户邮箱
  39. sqlManager.tb_produce+"."+sqlManager.row_produce_name+","+//产品名称
  40. sqlManager.tb_produce+"."+sqlManager.row_produce_price+","+//价格
  41. sqlManager.tb_produce+"."+sqlManager.row_produce_funtion+","+//描述
  42. sqlManager.tb_produce+"."+sqlManager.row_produce_sort+","+//类别
  43. sqlManager.tb_producer+"."+sqlManager.row_producer_name+","+ //生产商名称
  44. sqlManager.tb_producer+"."+sqlManager.row_producer_address+","+ //地址
  45. sqlManager.tb_producer+"."+sqlManager.row_producer_call+","+ //电话
  46. sqlManager.tb_producer+"."+sqlManager.row_producer_describe+"  "+ //简介
  47. "from "+sqlManager.tb_sell+","+sqlManager.tb_produce+","+sqlManager.tb_customer+","+
  48. sqlManager.tb_producer+","+sqlManager.tb_store+" "+
  49. "where "+sqlManager.tb_sell+"."+sqlManager.row_sell_id+"="+saleNumber+" and "+
  50. sqlManager.tb_sell+"."+sqlManager.row_sell_produce_id+"="+sqlManager.tb_produce+"."+sqlManager.row_produce_id+" and "+
  51. sqlManager.tb_sell+"."+sqlManager.row_sell_customer_id+"="+sqlManager.tb_customer+"."+sqlManager.row_customer_id+" and "+
  52. sqlManager.tb_sell+"."+sqlManager.row_sell_store_id+"="+sqlManager.tb_store+"."+sqlManager.row_store_id+
  53. "";
  54. sqlManager sql=sqlManager.getSqlManager();
  55. ResultSet set=sql.executeQuery(str);
  56. Text content=MainWindow.getApp().getContent();
  57. boolean flag=false;
  58. String s="***********************************售货单查询查询结果**********************************n";
  59. try{
  60. while(set.next()){
  61. flag=true;
  62. content.append(s);
  63. content.append("客户姓名:"+set.getString(4)+"n");
  64. content.append("售货单号:"+set.getInt(1)+"n");
  65. content.append("商品数量"+set.getInt(2)+" n");
  66. content.append("出售时间:"+set.getString(3)+"n");
  67. content.append("收货地址: "+set.getString(5)+"n");
  68. content.append("联系电话: "+set.getString(6)+"n");
  69. content.append("客户邮箱:"+set.getString(7)+"n");
  70. content.append("产品名称: "+set.getString(8)+"n");
  71. content.append("产品价格: "+set.getDouble(9)+"n");
  72. content.append("产品描述: "+set.getString(10)+"n");
  73. content.append("产品类别: "+set.getString(11)+"n");
  74. content.append("生产商名称: "+set.getString(12)+" n");
  75. content.append("生产商地址: "+set.getString(13)+"n");
  76. content.append("生产商电话: "+set.getString(14)+" n");
  77. content.append("生产商简介: "+set.getString(15)+"n");
  78. }
  79. }
  80. catch(SQLException e){
  81. e.printStackTrace();
  82. }
  83. content.append(s);
  84. if(flag==false)content.append("查询结果为空n");
  85. }
  86. else{
  87. System.out.println("input cancel");
  88. }
  89. }
  90. public class saleValidator implements IInputValidator{
  91. public String isValid(String newText){
  92. try{
  93. Integer.parseInt(newText);
  94. }
  95. catch(NumberFormatException ne){
  96. return "输入错误,请输入有效的售货单";
  97. }
  98. return null;
  99. }
  100. }
  101. }