home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 May
/
Pcwk0597.iso
/
borland
/
ib
/
setups
/
intrabld
/
data.z
/
MSSQLPUB.JFM
< prev
next >
Wrap
Text File
|
1996-11-13
|
18KB
|
592 lines
/****************************************************************************\
* *
* MSSqlPub.jfm -- Sample MS SQL Server Form *
* *
* MSSqlPub demonstrates the use of IntraBuilder with MS SQL Server data. *
* Before running this form, you need to have access to a MS SQL Server with *
* the sample database, pubs. You must use a user account that has write *
* access to the pubs database. When the form runs, you are asked to provide *
* a user name and password. If you want to automatically login to the server *
* you can add a loginString value to the Database object in the class *
* definition below. It should look something like this: *
* *
* with (this.pubs1 = new Database()){ *
* left = 49; *
* top = 0; *
* databaseName = "PUBS"; *
* loginString = "username/password"; *
* active = true; *
* } *
* *
* For more information about setting up the Borland Database Engine to *
* a remote server database, see the Samples.txt file in this directory. *
* *
* Dependencies: PUBS database on MS SQL Server *
* expinavh.gif *
* expirowh.gif *
* *
* Updated 11/13/96 by IntraBuilder Samples Group *
* $Revision: 1.6 $ *
* *
* Copyright (c) 1996, Borland International, Inc. All rights reserved. *
* *
\****************************************************************************/
#include "intra.h"
// {End Header} Do not remove this comment//
// Generated on 11/13/96
//
var f = new mssqlpubForm();
f.open();
class mssqlpubForm extends Form {
with (this) {
preRender = class::form_preRender;
onServerLoad = class::form_onServerLoad;
height = 14;
left = 0;
top = 0;
width = 64;
title = "Publications from MS SQL Server";
}
with (this.pubs1 = new Database()){
left = 50;
top = 0;
databaseName = "PUBS";
active = true;
}
with (this.dbo_publishers = new Query()){
left = 56;
top = 2;
database = parent.pubs1;
sql = "SELECT * FROM dbo.publishers";
requestLive = false;
}
with (this.dbo_publishers.rowset) {
}
with (this.dbo_authorsAll = new Query()){
left = 56;
top = 1;
database = parent.pubs1;
sql = "SELECT * FROM dbo.authors";
requestLive = false;
}
with (this.dbo_authorsAll.rowset) {
}
with (this.dbo_titles = new Query()){
left = 56;
top = 0;
database = parent.pubs1;
sql = "SELECT * FROM dbo.titles";
active = true;
}
with (this.dbo_titles.rowset) {
}
with (this.dbo_titleauthor = new Query()){
left = 50;
top = 1;
database = parent.pubs1;
sql = "SELECT * FROM dbo.titleauthor where title_id = :title_id";
params["title_id"] = "";
masterSource = parent.dbo_titles.rowset;
active = true;
onOpen = class::titleAuthor_onOpen;
}
with (this.dbo_titleauthor.rowset) {
}
with (this.dbo_authors = new Query()){
left = 50;
top = 2;
database = parent.pubs1;
sql = "SELECT * FROM dbo.authors where au_id = :au_id";
requestLive = false;
params["au_id"] = "";
masterSource = parent.dbo_titleauthor.rowset;
active = true;
}
with (this.dbo_authors.rowset) {
}
with (this.image1 = new Image(this)){
onImageServerClick = {|nLeft, nTop|;if (nLeft >= 26*0 && nLeft < 26*1){form.rowset.first()}else if (nLeft >= 26*1 && nLeft < 26*2){if (!form.rowset.next(-1)) form.rowset.next();}else if (nLeft >= 26*2 && nLeft < 26*3){if (!form.rowset.next()) form.rowset.next(-1);}else{form.rowset.last()}};
height = 0.9583;
top = 1.5;
width = 13;
dataSource = "filename EXPINAVH.GIF";
alignment = 4;
}
with (this.image2 = new Image(this)){
onImageServerClick = class::image2_onImageServerClick;
height = 0.9583;
left = 16;
top = 1.5;
width = 22.75;
dataSource = "filename EXPIROWH.GIF";
alignment = 4;
}
with (this.html1 = new HTML(this)){
height = 1;
top = 3;
width = 10;
color = "black";
alignVertical = 1;
text = "Title id";
}
with (this.titleIDTest = new Text(this)){
left = 10;
top = 3;
width = 8;
dataLink = parent.dbo_titles.rowset.fields["title_id"];
}
with (this.html2 = new HTML(this)){
height = 1;
top = 4;
width = 10;
color = "black";
alignVertical = 1;
text = "Title";
}
with (this.titleText = new Text(this)){
left = 10;
top = 4;
width = 36;
dataLink = parent.dbo_titles.rowset.fields["title"];
}
with (this.html3 = new HTML(this)){
height = 1;
top = 5;
width = 10;
color = "black";
alignVertical = 1;
text = "Type";
}
with (this.html4 = new HTML(this)){
height = 1;
top = 6;
width = 10;
color = "black";
alignVertical = 1;
text = "Pub id";
}
with (this.html5 = new HTML(this)){
height = 1;
top = 7;
width = 10;
color = "black";
alignVertical = 1;
text = "Notes";
}
with (this.TITLE = new HTML(this)){
height = 1.5;
width = 60;
color = "black";
text = "<H1>Publication Titles</H1>";
pageno = 0;
}
with (this.notesTextArea = new TextArea(this)){
height = 4;
left = 10;
top = 7;
width = 48;
dataLink = parent.dbo_titles.rowset.fields["notes"];
}
with (this.pubIDSelect = new Select(this)){
onServerLoad = class::pubIDSelect_onServerLoad;
left = 10;
top = 6;
width = 15;
dataLink = parent.dbo_titles.rowset.fields["pub_id"];
}
with (this.authorHTML = new HTML(this)){
height = 1;
top = 11;
width = 10;
color = "black";
alignVertical = 1;
text = "Author(s)";
}
with (this.authorListBox = new ListBox(this)){
height = 4;
left = 10;
top = 11;
width = 28;
}
with (this.addButton = new Button(this)){
onServerClick = {;this.form.pageno = 2};
left = 44;
top = 11.5;
width = 15;
text = "Add Author";
}
with (this.deleteAuthorButton = new Button(this)){
onServerClick = class::deleteAuthorButton_onServerClick;
left = 44;
top = 13;
width = 15;
text = "Delete Author";
}
with (this.typeSelect = new Select(this)){
left = 10;
top = 5;
width = 22;
dataLink = parent.dbo_titles.rowset.fields["type"];
options = 'array {"business","mod_cook","popular_comp","psychology","trad_cook","UNDECIDED"}';
}
with (this.allAuthorsListBox = new ListBox(this)){
onServerLoad = class::allAuthorsListBox_onServerLoad;
height = 6;
left = 14;
top = 4;
width = 22;
pageno = 2;
}
with (this.html7 = new HTML(this)){
height = 1.2083;
top = 2;
width = 64;
color = "black";
text = "Available Authors";
pageno = 2;
}
with (this.addAuthorButton = new Button(this)){
onServerClick = class::addAuthorButton_onServerClick;
left = 2;
top = 4;
width = 10.5;
text = "Add";
pageno = 2;
}
with (this.abandonButton = new Button(this)){
onServerClick = {;this.form.pageno = 1};
left = 2;
top = 6;
width = 10;
text = "Abandon";
pageno = 2;
}
with (this.html8 = new HTML(this)){
height = 1.2083;
top = 2;
width = 60;
color = "black";
text = "<h2>An Error Has Occured:<h2>";
pageno = 3;
}
with (this.errorHTML = new HTML(this)){
height = 4;
top = 4;
width = 60;
color = "black";
text = "error";
pageno = 3;
}
with (this.errorBackButton = new Button(this)){
onServerClick = {;this.form.pageno = 1};
top = 8;
width = 10.5;
text = "Back";
pageno = 3;
}
this.rowset = this.dbo_titles.rowset;
function form_onServerLoad()
{
this.rowset.first();
}
function form_preRender()
{
var state = this.rowset.state;
var vis = !(state == STATE_APPEND || state == STATE_FILTER || state == STATE_LOCATE);
this.authorHTML.visible = this.authorListBox.visible =
this.addButton.visible = this.deleteAuthorButton.visible = vis;
}
function pubIDSelect_onServerLoad()
{
this.pubIDArray = new Array();
this.form.dbo_publishers.active = true;
while (!this.form.dbo_publishers.rowset.endOfSet) {
this.pubIDArray.add(this.form.dbo_publishers.rowset.fields["pub_id"].value);
this.form.dbo_publishers.rowset.next();
}
this.form.dbo_publishers.active = false;
this.options = "array this.pubIDArray";
}
function allAuthorsListBox_onServerLoad()
{
this.authorsArray = new Array();
this.form.dbo_authorsAll.active = true;
while (!this.form.dbo_authorsAll.rowset.endOfSet) {
this.authorsArray.add(this.form.dbo_authorsAll.rowset.fields["au_lname"].value + ", " +
this.form.dbo_authorsAll.rowset.fields["au_fname"].value);
this.form.dbo_authorsAll.rowset.next();
}
this.authorsArray.sort();
this.options = "array this.authorsArray";
}
function titleAuthor_onOpen()
{
var fields = this.parent.dbo_authors.rowset.fields;
this.authorArray = new Array();
this.max_au_ord = -1;
while (!this.rowset.endOfSet) {
this.authorArray.add(fields["au_lname"].value + ", " + fields["au_fname"].value);
this.max_au_ord = (this.rowset.fields["au_ord"].value > this.max_au_ord) ? this.rowset.fields["au_ord"].value : this.max_au_ord;
this.rowset.next();
}
try {
this.authorArray.sort();
this.parent.authorListBox.options = "array this.authorArray";
}
catch (Exception e) {}
}
function addAuthorButton_onServerClick()
{
var value = this.form.allAuthorsListBox.value;
var authorsAll = this.form.dbo_authorsAll;
var titleauthor = this.form.dbo_titleauthor;
var titles = this.form.dbo_titles;
var error = "";
if (value.length == 0) {
error = "Error: no author was selected.";
}
else {
// look for match in dbo_authorsAll
authorsAll.active = false;
authorsAll.sql = "SELECT * FROM dbo.authors where au_fname = :fname and au_lname = :lname";
authorsAll.params["lname"] = value.substring(0,value.indexOf(", "));
authorsAll.params["fname"] = value.substring(value.indexOf(", ") + 2, value.length);
authorsAll.active = true;
// add to dbo_titleauthor
if (authorsAll.rowset.endOfSet) {
error = "Error: author was not added.";
}
else {
titleauthor.rowset.beginAppend();
titleauthor.rowset.fields["au_id"].value = authorsAll.rowset.fields["au_id"].value;
titleauthor.rowset.fields["title_id"].value = titles.rowset.fields["title_id"].value;
titleauthor.rowset.fields["au_ord"].value = titleauthor.max_au_ord + 1;
titleauthor.rowset.fields["royaltyper"].value = 0;
try {
titleauthor.rowset.save();
titleauthor.requery();
}
catch (DbException e) {
if (e.message.indexOf("PRIMARY") > 0) {
error = "Error: duplicate author was not added.";
}
else {
error = "Error: Server Error<p>";
for (var i = 0; i<e.errors.length; i++)
error += e.errors[i].message + "<br>";
}
titleauthor.rowset.abandon();
}
catch (Exception e) {
error = "Error: IntraBuilder Error<p>" +
e.message + " (" + e.code + ")";
titleauthor.rowset.abandon();
}
}
}
if (error.length > 0) {
this.form.errorHTML.text = error;
this.form.pageno = 3;
}
else {
this.form.pageno = 1;
}
}
function deleteAuthorButton_onServerClick()
{
var value = this.form.authorListBox.value;
var authorsAll = this.form.dbo_authorsAll;
var titleauthor = this.form.dbo_titleauthor;
var error = "";
if (value.length == 0) {
error = "Error: no author was selected.";
}
else {
// look for match in dbo_authorsAll
authorsAll.active = false;
authorsAll.sql = "SELECT * FROM dbo.authors where au_fname = :fname and au_lname = :lname";
authorsAll.params["lname"] = value.substring(0,value.indexOf(", "));
authorsAll.params["fname"] = value.substring(value.indexOf(", ") + 2, value.length);
authorsAll.active = true;
// delete from dbo_titleauthor
if (authorsAll.rowset.endOfSet) {
error = "Error: author was not deleted.";
}
else {
if (titleauthor.rowset.applyLocate("au_id='" + authorsAll.rowset.fields["au_id"].value + "'")) {
titleauthor.rowset.delete();
titleauthor.requery();
}
}
}
if (error.length > 0) {
this.form.errorHTML.text = error;
this.form.pageno = 3;
}
else {
this.form.pageno = 1;
}
}
function image2_onImageServerClick(nLeft, nTop) {
var error = "";
if (nLeft >= 26*0 && nLeft < 26*1) {
form.rowset.beginAppend();
}
else if (nLeft >= 26*1 && nLeft < 26*2) {
if (!form.rowset.endOfSet) {
try {
form.rowset.delete();
if (form.rowset.endOfSet)
form.rowset.last();
}
catch (DbException e) {
if (e.message.indexOf("COLUMN REFERENCE constraint") > 0) {
error = "Error: There are referencial integrity rules in place that prevent the deletion of this record. " +
"This may be caused by deleting a title that still has authors attached. " +
"This simple sample program does not account for these server constraints.";
}
else {
error = "Error: Server Error<p>";
for (var i = 0; i<e.errors.length; i++)
error += e.errors[i].message + "<br>";
}
}
catch (Exception e) {
error = "Error: IntraBuilder Error<p>" +
e.message + " (" + e.code + ")";
}
}
}
else if (nLeft >= 26*2 && nLeft < 26*3) {
try {
form.rowset.save();
}
catch (DbException e) {
if (e.message.indexOf("PRIMARY KEY") > 0) {
error = "Error: There is already a title with this ID. Enter a different Title ID. The title was not saved.";
}
else {
error = "Error: Server Error<p>";
for (var i = 0; i<e.errors.length; i++)
error += e.errors[i].message + "<br>";
}
}
catch (Exception e) {
error = "Error: IntraBuilder Error<p>" +
e.message + " (" + e.code + ")";
}
}
else if (nLeft >= 26*3 && nLeft < 26*4) {
form.rowset.abandon();
}
else if (nLeft >= 26*4 && nLeft < 26*5) {
form.rowset.beginEdit();
}
else if (nLeft >= 26*5 && nLeft < 26*6) {
if (form.rowset.state==5)
form.rowset.applyLocate();
else
form.rowset.beginLocate();
}
else {
if (form.rowset.state==4)
form.rowset.applyFilter();
else
form.rowset.beginFilter();
}
if (error.length > 0) {
this.form.errorHTML.text = error;
this.form.pageno = 3;
}
else {
this.form.pageno = 1;
}
}
}