TextField fIsbn = (TextField)bFieldset.getControl("isbn");
Select fPubDate = (Select)bFieldset.getControl("pubDate");
TextField fSupplier = (TextField)bFieldset.getControl("supplier");
TextField fCkey = (TextField)bFieldset.getControl("classKey");
TextField fClass = (TextField)bFieldset.getControl("classDescription");
NumberField fQtty = (NumberField)bFieldset.getControl("quantity");
ConnectionSource conn = (JdbcConnectionSource) GetConnection();
Author a = new Author();
if(fullNameArr.length > 1) {
a = a.getByFullName(conn, author, fullNameArr);
Integer author_id = a.getId();
if (author_id != 0 && author_id != null) {
if(fullNameArr.length > 2) {
if (!a.getLname().equalsIgnoreCase(fullNameArr[1]) ||
!a.getMname().equalsIgnoreCase(fullNameArr[2]) ||
!a.getName().equalsIgnoreCase(fullNameArr[0]))
author.update(a);
} else if (fullNameArr.length == 2) {
if (!a.getLname().equalsIgnoreCase(fullNameArr[1]) ||
!a.getName().equalsIgnoreCase(fullNameArr[0]))
author.update(a);
}
author.refresh(a);
} else {
a = new Author(fullNameArr);
author.create(a);
author.refresh(a);
}
}
Publisher p = new Publisher();
if(!fPublisher.getValue().trim().isEmpty()) {
p = p.getByName(conn, publisher,
fPublisher.getValue().trim());
Integer publisher_id = p.getId();
if(publisher_id != 0 && publisher_id != null) {
if(!p.getName().equalsIgnoreCase(fPublisher.getValue().trim()))
publisher.update(p);
publisher.refresh(p);
} else {
p = new Publisher(fPublisher.getValue().trim());
publisher.create(p);
publisher.refresh(p);
}
}
Supplier s = new Supplier();
if(!fSupplier.getValue().isEmpty()) {
s.getByName(conn, supplier,
fSupplier.getValue());
Integer supplier_id = s.getId();
if(supplier_id != 0 && supplier_id != null) {
if(!s.getName().equalsIgnoreCase(fSupplier.getValue())) {
supplier.update(s);
supplier.refresh(s);
}
} else {
s = new Supplier(fSupplier.getValue());
supplier.create(s);
supplier.refresh(s);
}
}
Classification c = new Classification();
if(!fCkey.getValue().isEmpty() &&
!fClass.getValue().isEmpty()) {
c.getByClassification(conn, classification,
fCkey.getValue(), fClass.getValue());
Integer class_id = c.getId();
if(class_id != 0 && class_id != null) {
if(!c.getDescription().equalsIgnoreCase(fClass.getValue())) {
classification.update(c);
}
if(!c.getCkey().equalsIgnoreCase(fCkey.getValue())) {
classification.update(c);
}
classification.refresh(c);
} else {
c = new Classification(fCkey.getValue(), fClass.getValue());
classification.create(c);
classification.refresh(c);
}
}
Book b = new Book();
form.copyTo(b);
try {
ISBN validIsbn = new ISBN(fIsbn.getValue());
b.setIsbn(validIsbn.toString());
} catch (InvalidStandardIDException e) {
// TODO Auto-generated catch block
b.setIsbn("");
e.printStackTrace();
}
DateFormat df = new SimpleDateFormat("yyyy");
Date year = df.parse(fPubDate.getSelectedValues().get(0).toString());
if(year != null)
b.setPubdate(year);
if(a != null)
b.setAuthor(a);
if(b != null)
b.setPublisher(p);
if(c != null)
b.setClassification(c);
if(fQtty.getValue().isEmpty())
b.setQuantity(1);
Integer book_id = b.getId();
if (book_id != 0 && book_id != null) {
book.update(b);