|
Home Up Database Steps Objects & Tools PB Window Steps Event Scripts
| |
 |
These scripts should work fine if they
are copied & pasted into the appropriate scripts in a Window
with controls named as in the schematic which follows on the
next page.
A Window built like this should work fine if
it references a table that has at least one row of data in it.
|
 | When you've seen where the Scripts below fit
in it's time to take PB Window
Steps ... |
[ Up ] [ Database Steps ] [ Objects & Tools ] [ PB Window Steps ] [ Event Scripts ]
|
 | @open of the application object: |
Get your Database Connection Syntax from the Properties of your
connected Database as described elsewhere & copy it into the
open event script for Open of the Application Object, followed by:
open(w_main_panel)
 | Global Variables of the application object: //to be read at open of main_panel
string ThisEnterpriseId, ThisEnterpriseName, ThisEnterpriseEmail, ThisEnterpriseActivity
//to support main_panel:parseline function & MAPI psX12 processing
integer Attempts, F, P, L, FieldCount, EditErrors, psX12File
string Fields[100], CleanFields[100], psX12Line, AChar, Delimiter = "*", EditMessage
string CrLf = char(13) + char(10)
string SubjectLine, NoteText, psX12FileName, psX12FileNames[100], CleanpsX12FileNames[100]
string EmailEnterpriseId, EnterpriseId, EnterpriseName, EmailDate, EmailTime, EmailAddress
long InBoxCount, InBoxLoc, psX12Loc[1000], psX12Count, RecLength
boolean TransactionOK, Connected, LoggedOn
string slug, ResponseType
mailSession MS
mailMessage Msg
mailRecipient Recipient
|
 | Function parseline (you need to:
Open the Application Object; Choose the Create button, Object tab,
choose Function as type; name it; copy script to it; & complete the
Prototype, or Header, Section for the Function.) //The function is passed an argument in aline that should be an asterisk delimited string
//Clear the array Fields by assigning CleanFields to it
//F is for field count, P is for Position in aline, L gets Length of aline
Fields = CleanFields
F = 1
P = 1
L = len(aline)
//Examine each character in aline, increment F when it is a Delimiter (*), otherwise
//cat it to the Fields[F]
for P = 1 to L
AChar = mid(aline,P,1)
if AChar = Delimiter then
F += 1
else
Fields[F] += AChar
end if
next
//Return F, field count, fields are in Global variable Fields[]
return (F)
|
 | @open: w_main_panel: |
integer EnterpriseDefFile, EnterpriseFields
string EnterpriseString
//Read the Enterprise Control Record and edit it
EnterpriseDefFile = fileopen("Enterprise.def",StreamMode!,Read!)
if EnterpriseDefFile <= 0 then
messagebox("While reading Enterprise Definition Record","No Enterprise.def was found in the default directory")
halt
end if
fileread(EnterpriseDefFile, EnterpriseString)
fileclose(EnterpriseDefFile)
EnterpriseFields = parseline(EnterpriseString)
if EnterpriseFields <> 4 then
messagebox("Enterprise Control Record","The Enterprise Control Record is corrupt. Please advise the Systems Administrator." + CrLf + EnterpriseString)
halt
end if
ThisEnterpriseId = Fields[1]
if not match(ThisEnterpriseId , "^[0-9][0-9][0-9][0-9]$") then
messagebox("Enterprise Control Record","'" + ThisEnterpriseId + "' is not a valid Enterprise Id." + CrLf + EnterpriseString)
halt
end if
ThisEnterpriseName = Fields[2]
if len(ThisEnterpriseName) = 0 then
messagebox("Enterprise Control Record", "The Control Record appears to have nothing for Enterprise Name." + CrLf + EnterpriseString)
halt
end if
ThisEnterpriseEmail = Fields[3]
if len(ThisEnterpriseEmail) = 0 then
messagebox("Enterprise Control Record", "The Control Record appears to have nothing for Enterprise Email." + CrLf + EnterpriseString)
halt
end if
ThisEnterpriseActivity = Fields[4]
if len(ThisEnterpriseActivity) = 0 then
messagebox("Enterprise Control Record", "The Control Record appears to have nothing for Enterprise Core Activity." + CrLf + EnterpriseString)
halt
end if
//Supply text for This window's title
this.title = ThisEnterpriseId + " " + ThisEnterpriseName
 | @click for each button on the Main Panel to launch the appropriate window:
cb_ledacc, cb_activity, cb_entity, cb_gs open(w_ledacc_maint) similar for other buttons: _activity_, _entity_, or _gs_
|
 | @getfocus: of each button on the Main Panel so it can be 'clicked' by
hitting the Enter key this.default = TRUE
|
 | The rest of these scripts are for the first Table Maintenance Window,
from which the others will be inherited: |
 | Instance Variables
boolean FirstPass = TRUE
integer TheId
long TheRow
|
 | @open: w_table_maint
CONNECT USING SQLCA;
IF SQLCA.SQLCODE <> 0 and SQLCA.SQLCODE <> -1 THEN
MessageBox("SQLCODE ->" + STRING(SQLCA.SQLCODE) + "<-",SQLCA.SQLERRTEXT)
HALT
END IF
dwc_lookup.SetTransObject(SQLCA)
dwc_lookup.Retrieve()
dwc_lookup.SetRow(1)
dwc_maint.Enabled = false
cb_delete.Enabled = false
cb_save.Enabled = false
cb_update.Enabled = true
cb_new.Enabled = true
cb_cancel.Enabled = false
|
 | @close: w_table_maint
DISCONNECT USING SQLCA;
|
 | @clicked: cb_save
Long RetCode
RetCode = dwc_maint.Update()
If RetCode = 1 then
COMMIT USING SQLCA;
cb_New.Enabled = true
cb_Save.Enabled = false
cb_Update.Enabled = true
cb_Cancel.enabled = false
cb_Delete.Enabled = false
dwc_maint.Reset()
dwc_maint.Enabled = false
dwc_lookup.enabled = true
dwc_lookup.Reset()
dwc_lookup.retrieve()
dwc_lookup.setfocus()
st_helper.text = "Click on another record to update, or the Close button if you're through."
else
MessageBox("Update", "Update Failed! Code is ->" + string(RetCode) + ",--", Exclamation!)
ROLLBACK USING SQLCA;
close(parent)
end if
|
 | @getfocus: cb_save, with similar at getfocus on the other Command Buttons
so that the Enter key will Click them when they get focus via the tab key
and to make prompts continuously helpful
this.default = true
st_helper.Text = "Press Enter or choose Update to save this record, or use tab or the mouse to move where you need to be."
|
 | @losefocus: cb_save, with similar at losefocus on the other Command Buttons
wherever needed to make prompts continuously helpful
st_helper.Text = "Use tab to move to another control or click where you need to be."
this.Default = false
|
 | @clicked: cb_new
long RetCode
dwc_maint.Reset()
dwc_maint.InsertRow(0)
dwc_maint.Enabled = true
dwc_maint.SetRow(1)
dwc_maint.SetFocus()
cb_cancel.Enabled = true
cb_save.Enabled = true
cb_new.Enabled = false
dwc_lookup.Enabled = false
cb_update.Enabled = false
st_helper.text = "Enter each field, moving to the next with the tab key or the mouse. Click the Save button when you're done."
|
 | @getfocus: dwc_maint
cb_update.Default = true
|
 | @click: cb_cancel
dwc_maint.Reset()
ROLLBACK USING SQLCA;
cb_New.Enabled = true
cb_Save.Enabled = false
cb_Update.Enabled = true
cb_Cancel.enabled = false
cb_Delete.Enabled = false
dwc_maint.Reset()
dwc_maint.Enabled = false
dwc_lookup.enabled = true
dwc_lookup.Reset()
dwc_lookup.retrieve()
dwc_lookup.setfocus()
|
 | @click: cb_update
//Set controls appropriate for updating
dwc_lookup.Enabled = false
dwc_maint.Enabled = true
dwc_maint.SetFocus()
dwc_maint.SetRow(1)
cb_save.Enabled = true
cb_delete.Enabled = true
cb_cancel.Enabled = true
cb_new.Enabled = false
cb_update.Enabled = false
st_helper.Text = "Click on the first field to change, then others as needed. Choose Save Changes, or Cancel to leave this record alone."
|
 | @doubleclick: dwc_lookup
TheRow = dwc_lookup.GetRow()
if TheRow <= 0 then
messagebox("Click Error","Please click on one of the Rows. You have either clicked in a border or between rows", Exclamation!)
return
end if
TheId = dwc_lookup.GetItemNumber(TheRow,"id")
dwc_maint.Retrieve(TheId)
dwc_maint.Enabled = false
cb_update.TriggerEvent(Clicked!)
//cb_update.Enabled = true
//cb_delete.Enabled = true
st_helper.Text = "Highlight the record you want to update or choose New button to add a new record. Choose Update when you've highlighted a record you'd like to update."
|
 | @rowfocuschanged: dwc_lookup
st_helper.Text = "Click on a record in the upper window to update it in the window below, or highlight it and [Enter] or choose Update. Choose New Record to enter a new record."
If FirstPass then
FirstPass = FALSE
dwc_maint.SetTransObject(SQLCA)
dwc_maint.Retrieve(dwc_lookup.GetItemNumber(1,"id"))
return
end if
TheRow = dwc_lookup.GetRow()
if TheRow <= 0 then
return
end if
TheId = dwc_lookup.GetItemNumber(TheRow,"id")
dwc_maint.Retrieve(TheId)
|
 | @getfocus: dwc_lookup
cb_update.Default = true
|
 | @click: cb_delete
long RetCode
st_helper.text = "Answer Yes or No, please... It's not too late to backup and leave this record in the database."
if messagebox("Confirm Deletion","Do you really want to delete this Ledger Detail?", Question!, YesNo!) = 1 then
RetCode = dwc_maint.DeleteRow(0)
if RetCode = -1 then
messagebox("Problem in delete","Unable to delete this record")
close(parent)
else
cb_update.TriggerEvent(Clicked!)
cb_save.TriggerEvent(Clicked!)
end if
else
cb_cancel.TriggerEvent(Clicked!)
end if
|
 | @click: cb_close
close(parent) |
|