home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
MDBS.ZIP
/
SQLAUTHO.CLS
< prev
next >
Wrap
Text File
|
1990-02-21
|
12KB
|
390 lines
define(#SQLAUTHORS_AUTHORIDTEXT, 9009);
define(#SQLAUTHORS_AUTHORID, 9003);
define(#SQLAUTHORS_FIRSTNAMETEXT, 9011);
define(#SQLAUTHORS_FIRSTNAME, 9005);
define(#SQLAUTHORS_LASTNAMETEXT, 9010);
define(#SQLAUTHORS_LASTNAME, 9004);
define(#SQLAUTHORS_ADDRESSTEXT, 9012);
define(#SQLAUTHORS_ADDRESS, 9006);
define(#SQLAUTHORS_CITYTEXT, 9013);
define(#SQLAUTHORS_CITY, 9015);
define(#SQLAUTHORS_STATETEXT, 9014);
define(#SQLAUTHORS_STATE, 9016);
define(#SQLAUTHORS_ZIPTEXT, 9017);
define(#SQLAUTHORS_ZIPCODE, 9018);
define(#SQLAUTHORS_TELEPHONETEXT, 9019);$
define(#SQLAUTHORS_PHONE, 9020);
define(#SQLAUTHORS_NEW, 9024);
define(#SQLAUTHORS_FIND, 9021);
define(#SQLAUTHORS_NEXT, 9023);
define(#SQLAUTHORS_UPDATE, 9025);
define(#SQLAUTHORS_QUIT, 9022);$
$
subclass(SQLForms,
#SQLAuthors,
#(updateSession,
updateResultBuffer,
updateCommandBuffer),
true, true, false);
$
/* Create the form */
method SQLAuthors::initFormSQLAuthors1(self, hPS)
{
local temp;
temp = new(TextControl,
asPels(new(Rect, 295, 2657, 1225, 2879), hPS),
self, SQLAUTHORS_AUTHORIDTEXT, "Author ID",0x10000001);
addObject(self, temp);
temp = new(EntryField,
asPels(new(Rect, 1417, 2657, 6998, 2982), hPS),
self, SQLAUTHORS_AUTHORID, "",0x10010008);
addObject(self, temp);
addEventPair(self, #(SQLAUTHORS_AUTHORID, #dummyHandler));
temp = new(TextControl,
asPels(new(Rect, 3942, 2185, 5123, 2421), hPS),
self, SQLAUTHORS_FIRSTNAMETEXT, "First Name",0x10000001);
addObject(self, temp);
temp = new(EntryField,
asPels(new(Rect, 5300, 2185, 7013, 2509), hPS),
self, SQLAUTHORS_FIRSTNAME, "",0x10010008);
addObject(self, temp);
addEventPair(self, #(SQLAUTHORS_FIRSTNAME, #dummyHandler));
temp = new(TextControl,
asPels(new(Rect, 295, 2199, 1387, 2436), hPS),
self, SQLAUTHORS_LASTNAMETEXT, "Last Name",0x10000001);
addObject(self, temp);
}
/* Create the form */
method SQLAuthors::initFormSQLAuthors2(self, hPS)
{
local temp;
temp = new(EntryField,
asPels(new(Rect, 1565, 2185, 3691, 2509), hPS),
self, SQLAUTHORS_LASTNAME, "",0x10010008);
addObject(self, temp);
addEventPair(self, #(SQLAUTHORS_LASTNAME, #dummyHandler));
temp = new(TextControl,
asPels(new(Rect, 295, 1756, 1107, 1993), hPS),
self, SQLAUTHORS_ADDRESSTEXT, "Address",0x10000001);
addObject(self, temp);
temp = new(EntryField,
asPels(new(Rect, 1284, 1742, 7057, 2067), hPS),
self, SQLAUTHORS_ADDRESS, "",0x10010008);
addObject(self, temp);
addEventPair(self, #(SQLAUTHORS_ADDRESS, #dummyHandler));
temp = new(TextControl,
asPels(new(Rect, 295, 1314, 738, 1550), hPS),
self, SQLAUTHORS_CITYTEXT, "City",0x10000001);
addObject(self, temp);
temp = new(EntryField,
asPels(new(Rect, 930, 1314, 2406, 1638), hPS),
self, SQLAUTHORS_CITY, "",0x10010008);
addObject(self, temp);
addEventPair(self, #(SQLAUTHORS_CITY, #dummyHandler));
}
/* Create the form */
method SQLAuthors::initFormSQLAuthors3(self, hPS)
{
local temp;
temp = new(TextControl,
asPels(new(Rect, 2687, 1314, 3248, 1550), hPS),
self, SQLAUTHORS_STATETEXT, "State",0x10000001);
addObject(self, temp);
temp = new(EntryField,
asPels(new(Rect, 3425, 1314, 4887, 1638), hPS),
self, SQLAUTHORS_STATE, "",0x10010008);
addObject(self, temp);
addEventPair(self, #(SQLAUTHORS_STATE, #dummyHandler));
temp = new(TextControl,
asPels(new(Rect, 5138, 1314, 5448, 1550), hPS),
self, SQLAUTHORS_ZIPTEXT, "Zip",0x10000001);
addObject(self, temp);
temp = new(EntryField,
asPels(new(Rect, 5551, 1314, 7013, 1638), hPS),
self, SQLAUTHORS_ZIPCODE, "",0x10010008);
addObject(self, temp);
addEventPair(self, #(SQLAUTHORS_ZIPCODE, #dummyHandler));
temp = new(TextControl,
asPels(new(Rect, 295, 871, 1343, 1107), hPS),
self, SQLAUTHORS_TELEPHONETEXT, "Telephone",0x10000001);
addObject(self, temp);
}
/* Create the form */
method SQLAuthors::initFormSQLAuthors4(self, hPS)
{
local temp;
temp = new(EntryField,
asPels(new(Rect, 1491, 871, 4636, 1195), hPS),
self, SQLAUTHORS_PHONE, "",0x10030008);
addObject(self, temp);
addEventPair(self, #(SQLAUTHORS_PHONE, #dummyHandler));
temp = new(PushButton,
asPels(new(Rect, 324, 177, 1373, 546), hPS),
self, SQLAUTHORS_NEW, "New",0x10000000);
addObject(self, temp);
addEventPair(self, #(SQLAUTHORS_NEW, #newEntry));
temp = new(PushButton,
asPels(new(Rect, 1697, 177, 2746, 546), hPS),
self, SQLAUTHORS_FIND, "Find",0x10010400);
addObject(self, temp);
addEventPair(self, #(SQLAUTHORS_FIND, #find));
temp = new(PushButton,
asPels(new(Rect, 3070, 177, 4119, 546), hPS),
self, SQLAUTHORS_NEXT, "Next",0x10000000);
addObject(self, temp);
addEventPair(self, #(SQLAUTHORS_NEXT, #next));
temp = new(PushButton,
asPels(new(Rect, 4444, 177, 5492, 546), hPS),
self, SQLAUTHORS_UPDATE, "Update",0x10000000);
addObject(self, temp);
addEventPair(self, #(SQLAUTHORS_UPDATE, #updateDB));
}
/* Create the form */
method SQLAuthors::initFormSQLAuthors5(self, hPS)
{
local temp;
temp = new(PushButton,
asPels(new(Rect, 5817, 177, 6865, 546), hPS),
self, SQLAUTHORS_QUIT, "Quit",0x10000000);
addObject(self, temp);
addEventPair(self, #(SQLAUTHORS_QUIT, #quit));
}
/* Handle message from control. */
method SQLAuthors::dummyHandler(self, mp1, mp2)
{
return nil;
}
/* find the next author with the same last name as the last author. */
method SQLAuthors::find(self, mp1, mp2)
{
cancel(commandBuffer);
addCommand(commandBuffer, "select * from authors ");
addCommand(commandBuffer, "where au_lname like \"");
addCommand(commandBuffer, itemTextOf(self, SQLAUTHORS_LASTNAME));
addCommand(commandBuffer, "%\"");
sendCommand(commandBuffer, true);
if (nextQuery(resultBuffer) == FAIL)
destroy(self);
if (nextRow(resultBuffer) != NO_MORE_ROWS) {
enableItem(self, SQLAUTHORS_NEXT);
next(self, nil, nil);
} else
disableItem(self, SQLAUTHORS_NEXT);
return nil;
}
/* Blank the form */
method SQLAuthors::newEntry(self, mp1, mp2)
{
cancelQuery(resultBuffer);
cancel(commandBuffer);
disableItem(self, SQLAUTHORS_NEXT);
setItemText(self, SQLAUTHORS_AUTHORID, EmptyString);
setItemText(self, SQLAUTHORS_LASTNAME, EmptyString);
setItemText(self, SQLAUTHORS_FIRSTNAME, EmptyString);
setItemText(self, SQLAUTHORS_PHONE, EmptyString);
setItemText(self, SQLAUTHORS_ADDRESS, EmptyString);
setItemText(self, SQLAUTHORS_CITY, EmptyString);
setItemText(self, SQLAUTHORS_STATE, EmptyString);
setItemText(self, SQLAUTHORS_ZIPCODE, EmptyString);
return nil;
}
/* get the next row from the result buffer and display it. */
method SQLAuthors::next(self, mp1, mp2)
{
fill(self);
if (nextRow(resultBuffer) != NO_MORE_ROWS) {
enableItem(self, SQLAUTHORS_NEXT);
} else {
disableItem(self, SQLAUTHORS_NEXT);
}
return nil;
}
/* Handle message from control. */
method SQLAuthors::quit(self, mp1, mp2)
{
destroy(self);
return nil;
}
/* Handle message from control. */
method SQLAuthors::updateDB(self, mp1, mp2)
{
addCommand(updateCommandBuffer, "update authors set address = '");
addCommand(updateCommandBuffer, itemTextOf(self, SQLAUTHORS_ADDRESS));
addCommand(updateCommandBuffer, "', city = '");
addCommand(updateCommandBuffer, itemTextOf(self, SQLAUTHORS_CITY));
addCommand(updateCommandBuffer, "', state = '");
addCommand(updateCommandBuffer, itemTextOf(self, SQLAUTHORS_STATE));
addCommand(updateCommandBuffer, "', zip = '");
addCommand(updateCommandBuffer, trim(itemTextOf(self, SQLAUTHORS_ZIPCODE)));
addCommand(updateCommandBuffer, "', au_lname = '");
addCommand(updateCommandBuffer, itemTextOf(self, SQLAUTHORS_LASTNAME));
addCommand(updateCommandBuffer, "', au_fname = '");
addCommand(updateCommandBuffer, itemTextOf(self, SQLAUTHORS_FIRSTNAME));
addCommand(updateCommandBuffer, "', phone = '");
addCommand(updateCommandBuffer, itemTextOf(self, SQLAUTHORS_PHONE));
addCommand(updateCommandBuffer, "' where au_id = '");
addCommand(updateCommandBuffer, itemTextOf(self, SQLAUTHORS_AUTHORID));
addCommand(updateCommandBuffer, "'");
sendCommand(updateCommandBuffer, true);
nextQuery(updateResultBuffer);
return nil;
}
/* Initialize the form */
method SQLAuthors::init(self, parent)
{
return init(super, parent, basicNew(Rect), "SQLAuthors SQL Server Example", 0x80000080, 0x1101, 0xffffff);
}
/* Initialize the form by creating the objects on it. */
method SQLAuthors::initializeForm(self)
{
local hPS, finalShape;
hPS = getPS(self);
setPS(0@0, PU_HIENGLISH, hPS);
finalShape = asPels(new(Rect, 1247, 1882, 8511, 5484), hPS);
createFattr(fattrManager,"System Proportional",0,0,120,-1);
initFormSQLAuthors1(self, hPS);
initFormSQLAuthors2(self, hPS);
initFormSQLAuthors3(self, hPS);
initFormSQLAuthors4(self, hPS);
initFormSQLAuthors5(self, hPS);
deleteAllFattrs(fattrManager);
releasePS(self, hPS);
initializeForm(super);
return finalShape;
}
/* Answer whether the form is modal. */
method SQLAuthors::isModal(self)
{
return false;
}
/* set the default database name and user name. */
method SQLAuthors::userInit(self)
{
databaseName = "pubs";
userName = "sa";
disableItem(self, SQLAUTHORS_NEXT);
return false;
}
/* Set the fields of the form from the current row from the database. */
method SQLAuthors::fill(self)
{
setItemText(self, SQLAUTHORS_AUTHORID, getColumn(resultBuffer, "au_id"));
setItemText(self, SQLAUTHORS_LASTNAME, getColumn(resultBuffer, "au_lname"));
setItemText(self, SQLAUTHORS_FIRSTNAME, getColumn(resultBuffer, "au_fname"));
setItemText(self, SQLAUTHORS_PHONE, getColumn(resultBuffer, "phone"));
setItemText(self, SQLAUTHORS_ADDRESS, getColumn(resultBuffer, "address"));
setItemText(self, SQLAUTHORS_CITY, getColumn(resultBuffer, "city"));
setItemText(self, SQLAUTHORS_STATE, getColumn(resultBuffer, "state"));
setItemText(self, SQLAUTHORS_ZIPCODE, getColumn(resultBuffer, "zip"));
return nil;
}
/* I need two sessions, so I will override this message. */
method SQLAuthors::init2(self)
{
local sPtr;
sPtr = setPointer(systemPointer(SPTR_WAIT));
init2(super);
sPtr = setPointer(systemPointer(SPTR_WAIT));
updateSession = new(SQLSession, loginRecord, serverName);
if (isNil(updateSession)) {
messageBox(self,
"Could not login in to SQL Server.",
"Object/1",
MB_ICONHAND | MB_OK);
if (canceledLogin(self)) {
destroy(self);
return nil;
} else {
update(DeskTop);
return self;
}
}
sqlErrorMessages = new(OrderedCollection, 0);
setErrorMessageHandler(updateSession,self);
setErrorReportHandler(updateSession, self, #displayError);
if (notNil(databaseName))
use(updateSession, databaseName);
updateResultBuffer = resultBufferOf(updateSession);
updateCommandBuffer = commandBufferOf(updateSession);
setPointer(sPtr);
return self;
}
/* Make sure the database gets closed. */
method SQLAuthors::destroy(self)
{
if (notNil(updateSession)) {
close(updateSession);
}
updateCommandBuffer = nil;
updateResultBuffer = nil;
updateSession = nil;
return destroy(super);
}
/*
** Answer the name of the demo application
** to be used by the demo start list box.
*/
method SQLAuthorsClass::demoNameOf(self)
{
return "Authors (SQL Server)";
}