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

📄 hangkong.java~1~

📁 这个代码是一本关于JAVA书籍的源代码 这本书叫做JAVA+SQLSERVER项目开发实践,希望对大家有帮助
💻 JAVA~1~
📖 第 1 页 / 共 2 页
字号:
        else if (jbrmultiple.isSelected()) {
          isFull = seatinformation.isFull(string[11], string[10]);
          mflight = multipleflight();
          if (sflight == 1) {
            JOptionPane.showMessageDialog(this, "第一航班号不能为空!", "错误信息",
                                          JOptionPane.ERROR_MESSAGE);
          }
          else if (sflight == 2) {
            JOptionPane.showMessageDialog(this,
                                          "你要预定的第一航班号已经满座!\n您可以改定同一天的航班:\n" +
                                          otherchoice, "客户信息",
                                          JOptionPane.INFORMATION_MESSAGE);
            jbtflight.setText("");
          }
          else if (sflight == 3) {
            JOptionPane.showMessageDialog(this,
                "您要预定的第一航班已经满座了!\n而且当天其他航班也已无票售!\n建议您重新选择第一航班日期", "错误信息",
                                          JOptionPane.ERROR_MESSAGE);
            jbtflight.setText("");

          }
          else if (sflight == 4) {
            JOptionPane.showMessageDialog(this, "没有第一航班号,请您重新查阅!",
                                          "错误信息", JOptionPane.ERROR_MESSAGE);
            jbtflight.setText("");
          }
          else {
            if (mflight == 1) {
              JOptionPane.showMessageDialog(this, "第二航班号不能为空!",
                                            "错误信息", JOptionPane.ERROR_MESSAGE);

            }
            else if (mflight == 2) {
              JOptionPane.showMessageDialog(this,
                                            "你要预定的第二航班号已经满座!\n您可以改定同一天的航班:\n" +
                                            otherchoice,
                                            "客户信息",
                                            JOptionPane.INFORMATION_MESSAGE);
              jbtflight1.setText("");
            }
            else if (mflight == 3) {
              JOptionPane.showMessageDialog(this,
                  "您要预定的第二航班号已经满座了!\n而且当天其他航班也已无票售!\n建议您重新选择第二航班日期",
                                            "错误信息", JOptionPane.ERROR_MESSAGE);
              jbtflight1.setText("");
            }
            else if (mflight == 4) {
              JOptionPane.showMessageDialog(this, "不存在您要预定的第二航班号,请您重新查阅!",
                                            "错误信息", JOptionPane.ERROR_MESSAGE);
              jbtflight1.setText("");
            }
            else if (mflight == 5) {
              JOptionPane.showMessageDialog(this, "第二航班号与第一航班号不匹配\n请重新输入返回航班号!",
                                            "错误信息", JOptionPane.ERROR_MESSAGE);
              jbtflight1.setText("");
            }
            else {
              clientFrame.getContentPane().add(client.panel(string));
              clientFrame.setTitle("客户资料");
              clientFrame.setSize(450, 460);
              clientFrame.setVisible(true);
              this.setVisible(false);
            }
          }
        }
      }
      else {
        JOptionPane.showMessageDialog(null, "对不起,不能预定以前的票了",
                                      "客户信息", JOptionPane.ERROR_MESSAGE);
      }
    }
    if (e.getSource() == jbtreturn) {
      this.setVisible(false);
      this.dispose();
    }
    if (e.getSource() == jbrsingle) {
      string[11] = jbtflight1.getText().trim();
      //	string[12]="single";
      string[5] = "单程";
      s1.setVisible(false);
      s2.setVisible(false);
      jblsecondflight.setVisible(false);
      jbtflight1.setVisible(false);
      jblreturnflight.setVisible(false);
      jbtflight2.setVisible(false);
    }
    if (e.getSource() == jbrdouble) {
      //	string[12]="double";
      string[5] = "往返";
      s2.setVisible(false);
      s1.setVisible(true);
      jblreturnflight.setVisible(true);
      jbtflight1.setVisible(true);
      jblsecondflight.setVisible(false);
      jbtflight2.setVisible(false);
    }
    if (e.getSource() == jbrmultiple) {
      //	string[12]="multiple";
      string[5] = "联程";
      s1.setVisible(false);
      jblreturnflight.setVisible(false);
      jbtflight1.setVisible(false);
      s2.setVisible(true);
      jblsecondflight.setVisible(true);
      jbtflight2.setVisible(true);
    }
  }

  String startplace = new String();
  String endplace = new String();
  public int singleflight() {
    if (jbtflight.getText().trim().length() == 0)return 1;
    else {
      try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:flight",
            "sa", "");
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("select * from flight");
        while (rs.next())
          if (rs.getString(1).trim().equals(string[4]))
            flag = 1;
        if (flag == 1) {

          String airfirm1 = new String();
          String sql =
              "select start,destination,airFirm from flight where flight='" +
              string[4] + "'";
          ResultSet rs1 = stmt.executeQuery(sql);
          while (rs1.next()) {
            startplace = rs1.getString(1).trim();
            endplace = rs1.getString(2).trim();
            airfirm1 = rs1.getString(3).trim();
          }

          if (!isFull) {
            string[0] = startplace;
            string[1] = endplace;
            string[6] = airfirm1;
            //		string[7]=boxadult.getSelectedItem().toString().trim();
            string[8] = string[5] + "票";
          }
          else {
            String[] flightcode = new String[50];
            int i = 0;
            for (i = 0; i < 50; i++)
              flightcode[i] = new String("null");
            i = 0;

            sql = "select flight from flight where start='" + startplace +
                "' AND destination='" + endplace + "'";
            ResultSet rs2 = stmt.executeQuery(sql);
            while (rs2.next()) {
              flightcode[i] = rs2.getString(1);
              i++;
            }
            stmt.close();
            con.close();
            i = 0;

            while (! (flightcode[i].equals("null"))) {
              if (! (flightcode[i].equals(string[4])));
              {
                isFull = seatinformation.isFull(flightcode[i], string[3]);
                if (!isFull) {
                  otherchoice = otherchoice + flightcode[i];
                }
              }
              i++;
            }

            if (! (otherchoice.equals(" ")))return 2;

            else return 3;

          }
        }
        if (flag == 0)return 4;

      }
      catch (Exception ex) {
        ex.printStackTrace();
      }

    }
    return 0;
  }

  //********************************************************************************************

   public int doubleflight() {
     if (jbtflight1.getText().trim().length() == 0)return 1;
     else {
       try {
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection con = DriverManager.getConnection("jdbc:odbc:flight",
             "sa", "");
         Statement stmt = con.createStatement();
         //ResultSet rs = stmt.executeQuery("select * from flight");
         ResultSet drs = stmt.executeQuery("select * from flight");
         //flag=1 exists the flight
         while (drs.next()) {
           if (drs.getString(1).trim().equals(string[11])) {
             flag = 1;
           }
         }
         if (flag == 1) {
           String dstartplace = new String();
           String dendplace = new String();
           String sql = "select start,destination from flight where flight='" +
               string[11] + "'";
           ResultSet drs1 = stmt.executeQuery(sql);
           while (drs1.next()) {
             dstartplace = drs1.getString(1).trim();
             dendplace = drs1.getString(2).trim();
           }
           if (dstartplace.equals(endplace) && dendplace.equals(startplace)) {
             if (isFull) {
               String[] dflightcode = new String[50];
               int i = 0;
               for (i = 0; i < 50; i++)
                 dflightcode[i] = new String("null");
               i = 0;
               sql = "select flight from flight where start='" + startplace +
                   "' AND destination='" + endplace + "'";
               ResultSet drs2 = stmt.executeQuery(sql);
               while (drs2.next()) {
                 dflightcode[i] = drs2.getString(1);
                 i++;
               }
               stmt.close();
               con.close();
               i = 0;
               while (! (dflightcode[i].equals("null"))) {
                 if (! (dflightcode[i].equals(string[11])));
                 {
                   isFull = seatinformation.isFull(dflightcode[i], string[3]);
                   if (!isFull) {
                     dotherchoice = dotherchoice + dflightcode[i];
                   }
                 }
                 i++;
               }
               if (! (dotherchoice.equals(" ")))return 2;
               else return 3;
             }
           }
           else return 5;
         }
         if (flag == 0)return 4;
       }
       catch (Exception ex) {
         ex.printStackTrace();
       }
     }
     return 0;
   }

  //***************************************************************************
   public int multipleflight() {
     if (jbtflight2.getText().trim().length() == 0)return 1;
     else {
       try {
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection con = DriverManager.getConnection("jdbc:odbc:flight",
             "sa", "");
         Statement stmt = con.createStatement();
         //ResultSet rs = stmt.executeQuery("select * from flight");
         ResultSet mrs = stmt.executeQuery("select * from flight");
         //flag=1 exists the flight
         while (mrs.next()) {
           if (mrs.getString(1).trim().equals(string[16])) {
             flag = 1;
           }
         }
         string[11] = string[16];
         if (flag == 1) {
           String mstartplace = new String();
           String mendplace = new String();
           String sql = "select start,destination from flight where flight='" +
               string[16] + "'";
           ResultSet mrs1 = stmt.executeQuery(sql);
           while (mrs1.next()) {
             mstartplace = mrs1.getString(1).trim();
             mendplace = mrs1.getString(2).trim();
           }
           if (mstartplace.equals(endplace)) {
             if (isFull) {
               String[] mflightcode = new String[50];
               int i = 0;
               for (i = 0; i < 50; i++)
                 mflightcode[i] = new String("null");
               i = 0;
               sql = "select flight from flight where start='" + startplace +
                   "' AND destination='" + endplace + "'";
               ResultSet mrs2 = stmt.executeQuery(sql);
               while (mrs2.next()) {
                 mflightcode[i] = mrs2.getString(1);
                 i++;
               }
               stmt.close();
               con.close();
               i = 0;
               while (! (mflightcode[i].equals("null"))) {
                 if (! (mflightcode[i].equals(string[16])));
                 {
                   isFull = seatinformation.isFull(mflightcode[i], string[17]);
                   if (!isFull) {
                     motherchoice = motherchoice + mflightcode[i];
                   }
                 }
                 i++;
               }
               if (! (motherchoice.equals(" ")))return 2;
               else return 3;
             }
           }
           else return 5;
         }
         if (flag == 0)return 4;
       }
       catch (Exception ex) {
         ex.printStackTrace();
       }
     }
     return 0;
   }

  //*************************************************************
   private boolean isTimeValid(String year, String month, String day) {
     int y = Integer.parseInt(year);
     int m = Integer.parseInt(month);
     int d = Integer.parseInt(day);

     //Get the present time
     Calendar cal = Calendar.getInstance();

     cal.setTime(new java.util.Date());

     int py = cal.get(Calendar.YEAR);
     int pm = cal.get(Calendar.MONTH) + 1;
     int pd = cal.get(Calendar.DAY_OF_MONTH);

     if (y == py) {
       if (m < pm)
         return false;
       else if (d < pd)
         return false;
     }

     return true;
   }
}

⌨️ 快捷键说明

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