Merge Edit Form into beas

Again we have to tell be.as where and when this new form will be called.

We have decided to open the edit form from out Browser form.

So let us perform the necessary steps for that.

 

 

Let us start with the "New" button"

We need to enhance the "New" button script in the Browser form.

 

Open Browser form and use Strg+N+B.

Use the "Button+Menü" tab and push the orange Arrow in front of the "new:" entry.

 

databrowseN

 

Here we go, now we are ready to insert / change our "New:" Button script.

To open the edit from we need to insert.

openwindow=mycolor_edit.psr=b_parm1:t

 

Short Description:

openwindow:                Opens a window with the given name.

mycolor_edit.psr        Name of the form. Must be in the Sub folder of BEAS.

b_parm1:t                b_parm1 is part of the Message structure. We set the parm b_parm1 to "True". So the form will automatically insert a new row.

                 

 

Now change the Script and close the Editor.

Lets try it out. Open the Browser Form and push the new button.

You should so the Edit form with an new row already inserted.

 

databrowseO

 

Again, the form has not been definied just created. We need to Design some functionality.

So user Strg+N+B and the editor will open uo.

Please use the settings below:

 

databrowseP

 

"Für dieses Fenster"        ->        Eingabefenster ok+ende+löschen template. Should be used for any Edit Form.

                         If you want to prevent the scrollbars than please activate and directly deactivate them.

mark Del Checkbox        ->        Creates a Delete Button

mark Print Button        ->        Creates a Print Button

 

 

Propagate Changes from one Form to another one.

Other Forms need to be informed if something has been changed in the Edit Form.

e.g. If we have changed the Color information than we need to inform all other Forms that are showing Data from the Color table that they need to to something ( Retrieve the new Data or so ) right now !!

We can do this by triggering the Post-Redraw event on the dependent Forms.

The internal Message Engine takes care about the sending / receiving mechanism.

The only thing we need to take care about is that we tell the Message Engine what and who to do.

So we will need to tell the Browser Form ( since this is the only one showing Data from the Color Table right now) that something need to be done.

Parameters for the Message Engine are:

dwname                ->        The name of the form ( In PowerBuilder we would say the name of the Datawindow )

Program Area                ->        The Name of the Program Area where <dwname> resides in.

 

Important: If you do not provide the dwname than the Message Engine will propagate the Event to all Forms in  this Program Area and the settings are Case-Sensitiv.

 

Settings:

Mouse Click on "Send Retrieve nach Edit" [Send Retrieve after Edit]

databrowseQ

 

and Save the settings with "Aktualisierung". Now you can close the Editor.

 

 

Modus Save Data

We need to tell the Form how the data need to be saved.

Open the editor with Strg+N+B and choose the Tab "Update"

Now insert into Command "dwupdate".

That means that we are using the Update Method of the Datawindow. Remember the discussion about how the Datawindow dynamically is creating the SQL-Statement ?? That is what will be used.

 

Modus New Data

Please select the Tab "Neu" [ New ].

Here you can define how the form behaves before any Data can be inserted. e.g you can set some initial values in here.

There is a trick if you are unsure what to enter.

Select the orange Arrow after "Alle Felder vorbelegen".

Now all Fields will be initialized with an default value.

 

Please delete all fields you don't need. like "erftstamp", "erfuser" and so on and set the initial value for the Rest

 

One more question. Imagine, that we have entered some data and now we wanted to enter a new record by pressing the "new" button.

Wouldn't it be nice if the form would than clear all input fields ??

To do this you need to enter the Command "reset=j"

 

help-achtungAgain, be.as Script is case-Sensitiv.. So please write anything lower Case.

 

Modus Delete

Use the Tab "Löschen"

Enter the following Commands into the Script Editor.

 

delete:question=<colorid>

delete:close

 

delete:question:   Will open a Messagebox which ask for permission to Delete the Data.

                         If the user selects "No" then the whole Delete transaction will be stopped.

delete:close          Form will be closed right after the Deletion Process.

 

Again, save all Data and close the Editor Form.

If there will be any Error Messages right now than please ignore them.

 

 

Ersten Datensatz eingeben

Eingabefenster über "NEU" wieder öffnen, Daten eingeben, aktualiseren und schließen.

Der erste Datensatz ist nun vorhanden.

 

Modus Modify Data

It would be nice to have if the form would react to Mouse double click, Modify and Delete Command.

Since Mouse Double Click and Modify will have the same functionality we can now create a Function which will be called from there.

 

Global Functions have a Form wide Scope. That means if the Form closes than the global Function will also be gone.

Global Functions are Form functions and can only be used within.

 

So let us write a global Function.

Please open the Script Editor with Strg+N+B and select the Tab "Funktionen", "Neu"

"Funktionsname" ="openmywindow"        ->        The name of the Global Function

Now mouse click "bearbeiten" and the Script Help Editor will open.

 

 

This window will help you writing Scripts. It shows information about the current state of Variables and so much more.

Variables with <> will be replaced with the current values when the Script will be interpreted.

 

Now enter the following Script:

if <rowcount> n= 0 then

 return failure

end if

openwindow=mycolor_edit.psr=s_parm1:<colorid>

return success

 

Description:

if <rowcount> n= 0 then        -> If then Syntax

 

<rowcount>        The actual RowCount of the form (Datawindow. Please take a look into the PowerBuilder Help... Search for "rowcount")

n=                Operator: be.as-Script doesn't know how to declare any Data types.

         To tell be.as that we except a numeric value we use the "n" command.

         So if we have 2 rows loaded into the form than <rowcount> n will be replaced by 2. We need to tell the script what Data type the value will be

         because we need to somehow equal that value against another Data type.

         So the Script would look like If 2 = 0 then

 

return        Exit the Function

         Approved Return values are:

         failure, false, -1  = Abort, Error

         success, true, 1  = No Errors everything is fine !!

         no_action, no action, 0 = Nothing has been done.

 

openwindow        Will open a form. Remember that this window need to be in / under the Program Folder !!!

         Search order will be

         a:) in the Current Program Folder

         b.) under the Current Program Folders

         Syntax:

         openwindow=<filename.psr>=parameter:value,parameter:value=command

         Following Types, Syntaxes exists:

         openwindow (or edit)                ->        Child Form will be opened modal. The Parent Form will be saved before the Client Form will be opened.

                                                 The Command "Update" will be triggered at the Parent Form.

         opennewwindow (oder newedit)        ->        Child Form will be opened non modal. The Parent Form will not be saved.

         openchild                        ->        Child Form will be opened modal But the Parent Form will not be saved.

 

s_parm1:<colorid>        This value is part for the Structure Variable str_parm.

                 s_parm will be filled with the current Colorid. Do you Remember the the Edit Form has an Retrieval Argument called s_parm1 ??

                 So what happens is that the s_parm1:<colorid> will be filled with the current colorid value (e.g. s_parm1 = 12212212) and this will be used

                 for retrieving the Data into the Edit Form. So the Sql Statement for the Edit Form will look like Select yyy from yyy where

                 colorid = 12212212.

                 So we ensure that only the current value will be edited.

 

PLEASE Save the Script right now!!

 

 

Go back to the tab "Button+Menu" and mouse click the orange Arrow at "edit:"

We will now tell the System what will executed when Edit has been chosen.

The Global Function should be called... So please enter:

openmywindow()

 

We also need to tell the System what to do if a mouse double click has raised.

Select the Tab "Grundeinstellung" and for the Command "Befehl Doppelclick" enter:

openmywindow()

Now we can modify the Color Data.

 

 

Disable the Edit of Certain Fields

By Default all Edit Fields are enabled. That means if you show the primary key as an Edit field than the user can change the value of it.

To permit this we need to tell the system what fields need to be disabled.

[Remember, there is one way within the Form ( Datawindow) creation, Set the Tab Step to 0!!)

To do this please open the Editor with Strg+N+B und select the Tab "Grundeinstellung"

After "Nach Retrieve (nicht bei Neuanlage)" enter:

protect=colorid=1

This command tells the System that the field colorid will be protected.. 1 stands for True.

BUT command will not be triggert if the a new Record will be inserted...

To ensure that we have a non protected ColorID field when we insert a new Record we need to enter a command.

Select Tab "Neu" and insert:

protect=colorid=0

 

help-hinweisIf you can't remember all the Field Names than you can use the Script Help Editor by mouse click the Orange Arrow. Here you can see all the Field Names, Variables, Database Table fields, Column Names and so much more.

 

Activate the Delete Button

Now only the Delete Button needs to be scripted.

Use Strg+N+B inside the Browser Form and mouse click the orange arrow in front of "DEL:"

Insert the following Script:

if <rowcount> n= 0 then

 return failure

end if

openwindow=mycolor_edit.psr=s_parm1:<colorid>=post=del

return success

 

specific feature:

If you take a look at the openwindow command you will see the parameter "post" which says : post=del;

Let us see what that means.

del        Command Delete: The Script what we have entered under the tab "Löschen" (Strg+N+B) will be called.

post        stands for "PostEvent":

 We need to Post trigger the Event beacuse the window need to be initialized and loaded before the Delete Command can / should be processed.

 If not than there an Exception might been thrown. e.g. There is now row at the time the delete command will be fulfilled.