home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 May
/
Pcwk0597.iso
/
borland
/
ib
/
setups
/
intrabld
/
data.z
/
KBLOOKUP.JFM
< prev
next >
Wrap
Text File
|
1996-12-11
|
14KB
|
460 lines
/****************************************************************************\
* *
* KbLookup.jfm -- Knowledge Base Lookup Table Update Form *
* *
* KbLookup.jfm is part of the Knowledge Base prebuilt business solution. It *
* is used to update the two lookup tables, products and categories. It uses *
* the kblogin form to provide password security. See the header code right *
* after this comment block to see how the login form is called. *
* *
* Dependencies: knowbs31.gif *
* homepg31.gif *
* paper_22.gif *
* database.cc *
* apps\shared\controls.cc *
* *
* Updated 11/13/96 by IntraBuilder Samples Group *
* $Revision: 1.11 $ *
* *
* Copyright (c) 1996, Borland International, Inc. All rights reserved. *
* *
\****************************************************************************/
#include "security.h"
//
// The code loads the security login form instead of the update form.
// An object reference to the update form is stored as a property of
// the login form. If the login is successful, the login form opens
// this update form.
//
// First create the update form, but don't open it.
var f = new kblookupForm();
// then create a security object
_sys.scripts.load(SM_CLASS_LOCATION + "security.js");
f.security = new SecurityManager();
// then create the login form
_sys.scripts.load("kblogin.jfm");
var login = new kbloginForm();
// the login form requires two custom properties be set
login.security = f.security;
login.nextForm = f;
// finally, open the login form
login.open();
return;
// {End Header} Do not remove this comment//
// Generated on 11/13/96
//
var f = new kblookupForm();
f.open();
class kblookupForm extends Form {
_sys.scripts.load(_sys.env.home() + "APPS\\SHARED\\CONTROLS.CC");
_sys.scripts.load("DATABASE.CC");
with (this) {
preRender = class::Form_preRender;
onServerLoad = class::Form_onServerLoad;
color = "ffffc4";
height = 14;
left = 0;
top = 0;
width = 72;
title = "Edit Lookup Tables";
background = "filename paper_22.gif";
}
with (this.ibapps1 = new KbaseDatabase()){
left = 15;
top = 2.4583;
active = true;
}
with (this.category1 = new Query()){
left = 22;
top = 2.4583;
database = parent.ibapps1;
sql = "SELECT * FROM kbcat";
active = true;
}
with (this.category1.rowset) {
}
with (this.product1 = new Query()){
left = 28;
top = 2.4583;
database = parent.ibapps1;
sql = "SELECT * FROM kbprod";
active = true;
}
with (this.product1.rowset) {
}
with (this.rule1 = new Rule(this)){
top = 4;
size = 2;
right = 70;
pageno = 0;
}
with (this.rule2 = new Rule(this)){
top = 12.5;
size = 2;
right = 70;
}
with (this.rule3 = new Rule(this)){
top = 20.5;
size = 2;
right = 70;
pageno = 0;
}
with (this.rule4 = new Rule(this)){
top = 25;
size = 2;
right = 70;
pageno = 0;
}
with (this.kbaseLogoImage = new Image(this)){
height = 3.4167;
width = 10.25;
dataSource = "filename KNOWBS31.GIF";
alignment = 4;
pageno = 0;
}
with (this.titleHTML = new HTML(this)){
height = 2;
left = 12;
width = 58;
color = "navy";
text = {||'<H1><FONT SIZE="+4"><FONT COLOR="maroon">U</FONT></FONT>pdate <FONT SIZE="+4"><FONT COLOR="maroon">L</FONT></FONT>ookup <FONT SIZE="+4"><FONT COLOR="maroon">T</FONT></FONT>ables</H1>'};
pageno = 0;
}
with (this.prodHTML = new HTML(this)){
height = 1;
left = 24;
top = 5;
width = 28;
color = "black";
fontBold = true;
text = "Current products";
}
with (this.prodSelect = new ListBox(this)){
height = 6;
left = 24;
top = 6;
width = 22;
}
with (this.prodAddButton = new Button(this)){
onServerClick = class::prodAddButton_onServerClick;
top = 7.5;
width = 20;
text = "Add Product";
}
with (this.prodText = new Text(this)){
top = 6;
width = 20;
value = "";
}
with (this.prodDeleteButton = new Button(this)){
onServerClick = class::prodDeleteButton_onServerClick;
top = 9;
width = 20;
text = "Delete Product";
}
with (this.catHTML = new HTML(this)){
height = 1;
left = 24;
top = 13;
width = 28;
color = "black";
fontBold = true;
text = "Current categories";
}
with (this.catSelect = new ListBox(this)){
height = 6;
left = 24;
top = 14;
width = 22;
}
with (this.catAddButton = new Button(this)){
onServerClick = class::catAddButton_onServerClick;
top = 15.5;
width = 20;
text = "Add Category";
}
with (this.catText = new Text(this)){
top = 14;
width = 20;
value = "";
}
with (this.catDeleteButton = new Button(this)){
onServerClick = class::catDeleteButton_onServerClick;
top = 17;
width = 20;
text = "Delete Category";
}
with (this.HomePageLinkImage = new Image(this)){
onImageClick = class::link_to_home_page;
height = 3.4167;
top = 21;
width = 10.25;
dataSource = "filename HOMEPG31.GIF";
alignment = 4;
pageno = 0;
}
with (this.HomePageLinkHTML = new HTML(this)){
height = 1;
left = 12;
top = 21;
width = 58;
color = "black";
text = "<A HREF='/ibapps/index.htm'>Return to Home Page</A>";
pageno = 0;
}
with (this.GeneratedHTML1 = new GeneratedHTML(this)){
height = 1;
top = 25.5;
width = 70;
pageno = 0;
}
with (this.errorHTML = new HTML(this)){
height = 4;
top = 5;
width = 70;
color = "black";
text = "HTML1";
pageno = 2;
}
with (this.html1 = new HTML(this)){
height = 1;
top = 5;
width = 20;
color = "black";
fontBold = true;
text = "New product";
}
with (this.html2 = new HTML(this)){
height = 1;
top = 13;
width = 20;
color = "black";
fontBold = true;
text = "New category";
}
function Form_onServerLoad()
{
try{
if (!this.security.hasAccessTo("kbupdate")) {
this.errorHTML.text = "Insufficient rights to update lookup tables";
this.backButton.visible = false;
this.pageno = 2;
}
}
catch (Exception e) {
this.errorHTML.text = "Error opening lookup form. " +
e.message + " (" + e.code + ")";
this.backButton.visible = false;
this.pageno = 2;
}
class::Form_preRender();
}
function Form_preRender(notForm, formRef)
{
//
// generate array from KbProd for the listbox
//
form = notForm ? formRef : this;
form.prodArray = new Array();
form.product1.rowset.first();
while(!form.product1.rowset.endOfSet) {
form.prodArray.add(form.product1.rowset.fields["ProdDescript"].value);
form.product1.rowset.next();
}
form.prodArray.sort();
form.prodSelect.options = 'array form.prodArray';
//
// generate array from KbCat for the listbox
//
form = notForm ? formRef : this;
form.catArray = new Array();
form.category1.rowset.first();
while(!form.category1.rowset.endOfSet) {
form.catArray.add(form.category1.rowset.fields["CatDescript"].value);
form.category1.rowset.next();
}
form.catArray.sort();
form.catSelect.options = 'array form.catArray';
}
function prodAddButton_onServerClick()
{
var prod = new StringEx(this.form.prodText.value);
prod = new StringEx(prod.rightTrim());
prod = prod.leftTrim();
if (prod.length > 0) {
var s = new StoredProc();
s.database = this.form.product1.database;
s.procedureName = "GET_PRODUCT";
s.active=true;
this.form.product1.rowset.beginAppend();
this.form.product1.rowset.fields["Product"].value = s.params["NEW_ID"].value;
this.form.product1.rowset.fields["ProdDescript"].value = prod;
this.form.product1.rowset.save();
// blank out the text
this.form.prodText.value = "";
// re-render the form
this.form.Form_preRender(true, this.form);
}
}
function prodDeleteButton_onServerClick()
{
var prod = new StringEx(this.form.prodSelect.value);
prod = new StringEx(prod.rightTrim());
prod = prod.leftTrim();
if (prod.length > 0) {
this.form.product1.active = false;
this.form.product1.sql = "SELECT * FROM kbprod WHERE ProdDescript = :PROD";
this form.product1.params["PROD"] = prod;
this.form.product1.active = true;
try {
if (!this.form.product1.rowset.endOfSet)
this.form.product1.rowset.delete();
}
catch (DbException e) {
if (e.message.indexOf("FOREIGN KEY") > 0)
this.form.errorHTML.text = "You can not delete a product if there are " +
"any documents in the Knowledge Base for this product.<p>" +
e.message + " (" + e.code + ")<p>";
else
this.form.errorHTML.text = e.message + " (" + e.code + ")<p>";
this.form.errorHTML.text += "<u>Server Errors:</u><p>";
for (var i = 0; i<e.errors.length; i++)
this.form.errorHTML.text += e.errors[i].message + " (" + e.errors[i].context + ")<br>";
this.form.pageno = 2;
}
catch (Exception e) {
this.form.errorHTML.text = e.message + " (" + e.code + ")";
this.form.pageno = 2;
}
finally {
this.form.product1.sql = "SELECT * FROM kbprod";
this.form.Form_preRender(true, this.form);
}
}
}
function catAddButton_onServerClick()
{
var cat = new StringEx(this.form.catText.value);
cat = new StringEx(cat.rightTrim());
cat = cat.leftTrim();
if (cat.length > 0) {
var s = new StoredProc();
s.database = this.form.category1.database;
s.procedureName = "GET_CATEGORY";
s.active=true;
this.form.category1.rowset.beginAppend();
this.form.category1.rowset.fields["Category"].value = s.params["NEW_ID"].value;
this.form.category1.rowset.fields["CatDescript"].value = cat;
this.form.category1.rowset.save();
// blank out the text
this.form.catText.value = "";
// re-render the form
this.form.Form_preRender(true, this.form);
}
}
function catDeleteButton_onServerClick()
{
var cat = new StringEx(this.form.catSelect.value);
cat = new StringEx(cat.rightTrim());
cat = cat.leftTrim();
if (cat.length > 0) {
this.form.category1.active = false;
this.form.category1.sql = "SELECT * FROM kbcat WHERE CatDescript = :CAT";
this form.category1.params["CAT"] = cat;
this.form.category1.active = true;
try {
if (!this.form.category1.rowset.endOfSet)
this.form.category1.rowset.delete();
}
catch (DbException e) {
if (e.message.indexOf("FOREIGN KEY") > 0)
this.form.errorHTML.text = "You can not delete a category if there are " +
"any documents in the Knowledge Base for this category.<p>" +
e.message + " (" + e.code + ")<p>";
else
this.form.errorHTML.text = e.message + " (" + e.code + ")<p>";
this.form.errorHTML.text += "<u>Server Errors:</u><p>";
for (var i = 0; i<e.errors.length; i++)
this.form.errorHTML.text += i + ") " + e.errors[i].message + " (" + e.errors[i].context + ")<br>";
this.form.pageno = 2;
}
catch (Exception e) {
this.form.errorHTML.text = e.message + " (" + e.code + ")";
this.form.pageno = 2;
}
finally {
this.form.category1.sql = "SELECT * FROM kbcat";
this.form.Form_preRender(true, this.form);
}
}
}
function link_to_home_page()
{
location.href="/ibapps/index.htm";
}
}