tjtablemodel.java

来自「一个企业小型固定资产系统的源代码。发布出来让刚学习java的人研究。」· Java 代码 · 共 121 行

JAVA
121
字号
package project;

import java.sql.*;
import java.math.*;
import java.util.ArrayList;
public class TJtableModel {
   Connection conn;
 public  String[][] Stabledata;
 public int handnum=18;
 public  ArrayList Atabledata;



    public  TJtableModel (String rowname,String term,String table) {

    String sql="";

    String sql1="  RecodeInfo.R_NO, ProductInfo.P_ID, ProductInfo.P_Name, ProductInfo.P_TypeSize,  ";
        sql1=sql1+" ProductInfo.P_Property, ProductInfo.P_Unit, RecodeInfo.R_Num, RecodeInfo.R_BB_Price,  ";
        sql1=sql1+" RecodeInfo.R_Money, RecodeInfo.R_Type, RecodeInfo.R_Process, RecodeInfo.R_Date, CKInfo.C_ID,  ";
        sql1=sql1+" CKInfo.C_Name, UserInfo.U_ID, UserInfo.U_Name, UserInfo.U_Type, RecodeInfo.R_Note ";
        sql1=sql1+" FROM ProductInfo INNER JOIN (CKInfo INNER JOIN (UserInfo INNER JOIN RecodeInfo ON  ";
        sql1=sql1+" UserInfo.U_NO = RecodeInfo.R_U_NO) ON CKInfo.C_NO = RecodeInfo.R_C_NO)  ";
        sql1=sql1+" ON ProductInfo.P_NO = RecodeInfo.R_P_NO ";
    conn = (new DbConn()).getConnection();
     if(table.equals("RInfo")&&term.equals(" ")){

         sql="SELECT "+ sql1;
         sql=sql+" ORDER BY RecodeInfo.R_NO;";
         handnum=18;
     }
     if(table.equals("RInfow")) {
        sql="SELECT "+ sql1;
        sql=sql+" WHERE "+rowname+" LIKE '"+term+"'";
        sql=sql+" ORDER BY RecodeInfo.R_NO ;";

           handnum=18;
     }
      if(table.equals("UInfo")&&term.equals(" ")) {

           sql="SELECT UserInfo.U_ID, UserInfo.U_Name, UserInfo.U_Type, UserInfo.U_Grade, UserInfo.U_Note ";
           sql=sql+" FROM UserInfo WHERE U_Dis=true ORDER BY  U_ID;";
            handnum=5;

      }
      if(table.equals("UInfow")) {

          sql="SELECT UserInfo.U_ID, UserInfo.U_Name, UserInfo.U_Type, UserInfo.U_Grade, UserInfo.U_Note ";
           sql=sql+" FROM UserInfo WHERE "+rowname+" LIKE '"+term+"'";
            sql=sql+" AND U_Dis=true ORDER BY  U_ID;";
            handnum=5;

      }
      if(table.equals("DInfo")&&term.equals(" ")) {
          sql="SELECT CKInfo.C_ID, CKInfo.C_Name, ProductInfo.P_ID, ProductInfo.P_BigClass, ProductInfo.P_Name,   ";
          sql=sql+" ProductInfo.P_TypeSize, ProductInfo.P_Property, ProductInfo.P_Unit, Depot.D_Num,   ";
          sql=sql+" Depot.D_Price, Depot.D_Money, Depot.D_Note ";
          sql=sql+" FROM ProductInfo INNER JOIN (CKInfo INNER JOIN Depot ON CKInfo.C_NO = Depot.D_C_NO) ";
          sql=sql+" ON ProductInfo.P_NO = Depot.D_P_NO  ";
          sql=sql+" ORDER BY ProductInfo.P_ID;";
           handnum=12;

      }
      if(table.equals("DInfow")) {
          sql="SELECT CKInfo.C_ID, CKInfo.C_Name, ProductInfo.P_ID, ProductInfo.P_BigClass, ProductInfo.P_Name,   ";
         sql=sql+" ProductInfo.P_TypeSize, ProductInfo.P_Property, ProductInfo.P_Unit, Depot.D_Num,   ";
         sql=sql+" Depot.D_Price, Depot.D_Money, Depot.D_Note ";
         sql=sql+" FROM ProductInfo INNER JOIN (CKInfo INNER JOIN Depot ON CKInfo.C_NO = Depot.D_C_NO) ";
          sql=sql+" ON ProductInfo.P_NO = Depot.D_P_NO  ";
            sql=sql+"  WHERE "+rowname+" LIKE '"+term+"'";
            sql=sql+" ORDER BY ProductInfo.P_ID;";
             handnum=12;

     }
     if(table.equals("PInfo")&&term.equals(" ")) {
          sql="SELECT P_ID, P_BigClass, P_Name, P_TypeSize, P_Property, P_Unit, P_Note";
           sql=sql+" FROM ProductInfo  ORDER BY P_ID;";
          handnum=7;
     }
     if(table.equals("PInfow")) {
         sql="SELECT P_ID, P_BigClass, P_Name, P_TypeSize, P_Property, P_Unit, P_Note";
          sql=sql+" FROM ProductInfo WHERE "+rowname+" LIKE '"+term+"'";
           sql=sql+" ORDER BY P_ID;";
          handnum=7;
     }

      try {

          Atabledata = new ArrayList();
          Statement stmt1 = conn.createStatement();
          ResultSet rset1 = stmt1.executeQuery(sql);

          while (rset1.next()) {
               for (int j = 1; j <= handnum; j++) {
              Atabledata.add(rset1.getString(j));
               }
          }
         rset1.close();
          stmt1.close();
          conn.close();
      String[] business = (String[]) Atabledata.toArray(new String[Atabledata.size()]);
      Stabledata = new String[Atabledata.size() / handnum][handnum];
      int num2=0;
          for(int y=0;y<business.length/ handnum;y++){

        for (int x = 0; x <handnum; x++) {
          Stabledata[y][x] = business[num2];
          num2++;
             }
          }
      }
      catch (java.sql.SQLException s) {
        System.out.println("exception: " + s.getMessage());
      }

   }
   public String[][] alldata(){
       return  Stabledata;
   }
}

⌨️ 快捷键说明

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