Esempio n. 1
0
 public void addRec() {
   try {
     setFields();
     db.write();
     goTo(db.getRecordCount());
     delCB.setState(false);
     trl.setText(" of " + db.getRecordCount());
   } // try
   catch (Exception e1) {
     System.out.println(e1);
     System.exit(1);
   }
   Update.setEnabled(true);
   updateRecord.setEnabled(true);
 }
Esempio n. 2
0
  public void updateRec() {

    try {
      setFields();
      db.update();
      boolean b = delCB.getState();
      if (db.deleted() && !b) {
        db.undelete();
      } else if (!db.deleted() && b) {
        db.delete();
      }
    } // try
    catch (Exception e1) {
      System.out.println(e1);
      System.exit(1);
    }
  }
Esempio n. 3
0
  public void setFields() {
    Field f;
    LogicalField lf;
    Checkbox c;
    TextField t;

    int i;
    try {
      for (i = 1; i <= db.getFieldCount(); i++) {
        f = db.getField(i);
        if (f.isMemoField() || f.isPictureField()) {
        } else if (f.isLogicalField()) {
          lf = (LogicalField) f;
          c = (Checkbox) fldObjects.elementAt(i - 1);
          lf.put(c.getState());
        } else {
          t = (TextField) fldObjects.elementAt(i - 1);
          f.put(t.getText());
        }
      }
    } catch (Exception e1) {
      System.out.println(e1);
    }
  }
Esempio n. 4
0
  public void actionPerformed(ActionEvent event) {
    if (event.getSource() == firstRecord) {
      goTo(1);
      return;
    }
    if (event.getSource() == lastRecord) {
      goTo(db.getRecordCount());
      return;
    }
    if (event.getSource() == Next || event.getSource() == nextRecord) {
      if (db.getCurrentRecordNumber() < db.getRecordCount()) {
        goTo(db.getCurrentRecordNumber() + 1);
      }
      return;
    }

    if (event.getSource() == Prev || event.getSource() == prevRecord) {
      if (db.getCurrentRecordNumber() > 1) {
        goTo(db.getCurrentRecordNumber() - 1);
      }
      return;
    }

    if (event.getSource() == Add || event.getSource() == addRecord) {
      addRec();
      return;
    }
    if (event.getSource() == Update || event.getSource() == updateRecord) {
      updateRec();
      return;
    }
    if (event.getSource() == Clear || event.getSource() == clearRecord) {
      clearFields();
      return;
    }

    if (event.getSource() == opener) {
      FileDialog fd = new FileDialog(this, "dbfShow", FileDialog.LOAD);
      fd.setFile("*.DBF");
      fd.pack();
      fd.setVisible(true);
      String DBFname = fd.getFile();
      String dirname = fd.getDirectory();
      if (DBFname == null) {
        return;
      }
      if (DBFname.length() < 1) {
        return;
      }
      String dbname = new String(dirname + DBFname);
      try {
        setupDBFields(dbname);
      } catch (Exception e1) {
        System.out.println(e1);
        System.exit(4);
      }
      pack();
      setVisible(true);
      return;
    }

    if (event.getSource() == packer) {
      packer.setEnabled(false);
      try {
        db.pack();
        trl.setText(" of " + db.getRecordCount());
      } catch (Exception e1) {
        e1.printStackTrace();
      }
      if (db.getRecordCount() == 0) {
        Update.setEnabled(false);
        Next.setEnabled(false);
        updateRecord.setEnabled(false);
        nextRecord.setEnabled(false);
        SBrecpos.setValues(0, 1, 0, 0);
      } else {
        goTo(1);
      }
      packer.setEnabled(true);
      return;
    }

    if (event.getSource() == quiter) {
      System.exit(0);
      return;
    }

    if (event.getSource() instanceof Button) {
      int i;
      Field f;
      for (i = 1; i <= db.getFieldCount(); i++) {
        try {
          f = db.getField(i);
          if (f.isMemoField()) {
            if (event.getActionCommand().equals(f.getName())) {
              md = new memoDialog(this, f);
              md.setVisible(true);
              return;
            }
          }
        } catch (Exception e1) {
          System.out.println(e1);
        }
      }
    }
  }
Esempio n. 5
0
  public void goTo(int where) {
    try {
      if (where < 1) {
        return;
      }
      if (where > db.getRecordCount()) {
        return;
      }
      db.gotoRecord(where);
      crl.setText("Record " + db.getCurrentRecordNumber());
      delCB.setState(db.deleted());

      Field f;
      LogicalField lf;
      Checkbox c;
      TextField t;

      int i;

      for (i = 1; i <= db.getFieldCount(); i++) {
        f = db.getField(i);
        if (f.isMemoField()) {
        } else if (f.getType() == 'L') {
          lf = (LogicalField) f;
          c = (Checkbox) fldObjects.elementAt(i - 1);
          c.setState(lf.getBoolean());
        } else {
          t = (TextField) fldObjects.elementAt(i - 1);
          t.setText(f.get().trim());
        }
      }

      Next.setEnabled(!(db.getCurrentRecordNumber() == db.getRecordCount()));
      nextRecord.setEnabled(!(db.getCurrentRecordNumber() == db.getRecordCount()));

      Prev.setEnabled(!(db.getCurrentRecordNumber() == 1));
      prevRecord.setEnabled(!(db.getCurrentRecordNumber() == 1));

      firstRecord.setEnabled(db.getRecordCount() > 0);
      lastRecord.setEnabled(db.getRecordCount() > 0);

      SBrecpos.setValues(db.getCurrentRecordNumber(), 1, 0, db.getRecordCount());
    } // try
    catch (Exception e1) {
      System.out.println(e1);
      System.exit(2);
    }
  }
Esempio n. 6
0
  public void setupDBFields(String dbname) throws Exception {

    viewPane.setLayout(null);
    Dimension dimView = sp.getSize();
    int height = 0, width = 50;
    viewPane.removeAll();
    db = new DBF(dbname);
    setTitle(dbname);

    gb = new GridBagLayout();
    gbc = new GridBagConstraints();
    viewPane.setLayout(gb);

    int i, j;
    fldObjects = new Vector(db.getFieldCount());
    for (i = 1; i <= db.getFieldCount(); i++) {
      j = i - 1;
      f = db.getField(i);
      if (f.isMemoField() || f.isPictureField()) {
        b = new Button(db.getField(i).getName());
        b.addActionListener(this);
        addComponent(
            viewPane, b, 1, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
        fldObjects.addElement(b);
      } else if (f.getType() == 'L') {
        c = new Checkbox(db.getField(i).getName(), true);
        addComponent(
            viewPane, c, 1, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
        fldObjects.addElement(c);
      } else {
        l = new Label(db.getField(i).getName(), Label.RIGHT);
        addComponent(
            viewPane, l, 0, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
        int ln = f.getLength();
        if (ln > 100) {
          ln = 100;
        }
        t = new TextField(db.getField(i).getName(), ln);
        if (width < ln * 10) {
          width = ln * 10;
        }
        addComponent(
            viewPane, t, 1, j, ln, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
        fldObjects.addElement(t);
        t.setEditable(true);
      }
      height += 10;
    }

    crl.setText("Record " + db.getCurrentRecordNumber());
    trl.setText(" of " + db.getRecordCount());
    SBrecpos.setMaximum(db.getRecordCount());
    addComponent(viewPane, crl, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    addComponent(viewPane, trl, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    i++;
    addComponent(
        viewPane, SBrecpos, 0, i, 2, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    addComponent(
        viewPane, delCB, 2, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    i++;
    addComponent(
        viewPane, Prev, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    addComponent(
        viewPane, Next, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    i++;
    addComponent(viewPane, Add, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    addComponent(
        viewPane, Update, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    addComponent(
        viewPane, Clear, 2, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    Prev.setEnabled(false);
    prevRecord.setEnabled(false);
    if (db.getRecordCount() == 0) {
      Update.setEnabled(false);
      updateRecord.setEnabled(false);
      Next.setEnabled(false);
      nextRecord.setEnabled(false);
    }

    dimView.setSize(width + 150, height + 150);
    sp.setSize(dimView);

    goTo(1);
  }
Esempio n. 7
0
  public static void main(String args[]) {

    try {
      // Create a new dbf file
      DBF aDB = new DBF("class.dbf", true);

      // Create the fields

      CharField classId = new CharField("classId", 9);
      CharField className = new CharField("className", 25);
      CharField teacherId = new CharField("teacherId", 9);
      CharField daysMeet = new CharField("daysMeet", 7);
      CharField timeMeet = new CharField("timeMeet", 4);
      NumField credits = new NumField("credits", 2, 0);
      LogicalField UnderGrad = new LogicalField("UnderGrad");

      // Add field definitions to database
      aDB.addField(classId);
      aDB.addField(className);
      aDB.addField(teacherId);
      aDB.addField(daysMeet);
      aDB.addField(timeMeet);
      aDB.addField(credits);
      aDB.addField(UnderGrad);

      aDB.createIndex(
          "classId.ndx", "classId", true, true); //  true - delete ndx, true - unique index,
      aDB.createIndex(
          "TchrClass.ndx",
          "teacherID+classId",
          true,
          false); // true - delete NDX,  false - unique index,
      System.out.println("index created");

      classId.put("JAVA10100");
      className.put("Introduction to JAVA");
      teacherId.put("120120120");
      daysMeet.put("NYNYNYN");
      timeMeet.put("0800");
      credits.put(3);
      UnderGrad.put(true);

      aDB.write();

      classId.put("JAVA10200");
      className.put("Intermediate JAVA");
      teacherId.put("300020000");
      daysMeet.put("NYNYNYN");
      timeMeet.put("0930");
      credits.put(3);
      UnderGrad.put(true);

      aDB.write();

      classId.put("JAVA501");
      className.put("JAVA And Abstract Algebra");
      teacherId.put("120120120");
      daysMeet.put("NNYNYNN");
      timeMeet.put("0930");
      credits.put(6);
      UnderGrad.put(false);

      aDB.write();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 8
-1
  public void clearFields() {
    Field f;

    Checkbox c;
    TextField t;

    int i;

    for (i = 1; i <= db.getFieldCount(); i++) {
      try {
        f = db.getField(i);
        if (f.isMemoField()) {
          f.put("");
        } else if (f.getType() == 'L') {
          c = (Checkbox) fldObjects.elementAt(i - 1);
          c.setState(false);
        } else {
          t = (TextField) fldObjects.elementAt(i - 1);
          t.setText("");
        }
      } catch (Exception e1) {
        System.out.println(e1);
        System.exit(3);
      }
    }
  }