DIY Script

From eStream Software
Revision as of 02:17, 19 October 2015 by Twfaung (talk | contribs) (Created page with "''Menu: Tools | DIY | SQL Control Center...'' ==Introduction== This Additional Module where user can self * Create new field (DIY Fields Module) * Modified the SQL Accountin...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Menu: Tools | DIY | SQL Control Center...

Introduction

This Additional Module where user can self

  • Create new field (DIY Fields Module)
  • Modified the SQL Accounting (DIY Script Module)

DIY Script

This is additional Module which allow user to override or customise the SQL System.
The Language use is Pascal
Available Action/Event

Action/Event Description
OnOpen The script trigger On Open the Form (eg On Open the Sales Invoice Form)
OnClose The script trigger On Close/Exit the Form (eg on Exit Sales Invoice Form)
OnBeforeNew The script trigger before the build in New Button action execute.
OnAfterNew The script trigger after the build in New Button action Execute.
OnBeforeEdit The script trigger before the build in Edit Button action execute.
OnAfterEdit The script trigger after the build in Edit Button action Execute.
OnBeforeDelete The script trigger before the build in Delete Button action execute.
OnAfterDelete The script trigger after the build in Delete Button action Execute.
OnBeforeSave The script trigger before the build in Save Button action execute.
OnAfterSave The script trigger after the build in Save Button action Execute.
OnBeforeCancel The script trigger before the build in Cancel Button action execute.
OnAfterCancel The script trigger after the build in Cancel Button action Execute.
OnBeforePrint The script trigger before the build in Print or Preview Button action Execute.
OnGridBeforeInsert The script trigger before the build in + Button action Execute.
OnGridAfterInsert The script trigger after the build in + Button action Execute.
OnGridBeforePost The script trigger before post the current row record.
OnGridAfterPost The script trigger after post the current row record.
OnGridBeforeDelete The script trigger before the build in - Button action Execute.
OnGridAfteDelete The script trigger after the build in - Button action Execute.
OnGridBeforeCancel The script trigger before cancel the current row record.
OnGridAfterCancel The script trigger after cancel the current row record.
OnGridColumnValueChanged The script trigger on changes value in the current record.
----------------------------------------------------------------------------------------------------------------------------------------------------
Template.Tips-01.jpg
Commonly we only OnOpen, OnBeforeSave & OnGridColumnValueChanged Event
----------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------
Template.Warning-01.jpg
Avoid use 2 same Event/Action in 1 Business Object (eg 2 OnOpen in Sales Invoice is NOT allow)
----------------------------------------------------------------------------------------------------------------------------------------------------

Script Example 1

Below is Example are doing following actions

  • Get UDF_Length & UDF_Width from Maintain Item UDF Fields
  • Do Calculation Qty := UDF_Length * UDF_Width * UDF_Rate


01. Right Click the Sales Invoice
DIYField-03.jpg
02. Select New Event
DIYScript-01.jpg
03. Enter any name (eg Calc) in the Name field (Only Alphanumeric & no spacing)
04. Select OnGridColumnValueChanged for Event field
05. Click OK
06. Click the Calc (name create at Step 3 above) on the left panel
DIYScript-02.jpg
07. Copy below script & paste to the Right Panel (Script Section)
var FComServer, lBizObj : Variant;
    cdsData : TClientDataSet;

function ComServer: Variant;
begin
  if FComServer = Null then begin
    FComServer := CreateOleObject('SQLAcc.BizApp');
  end;
  Result := FComServer;
end;

procedure GetStockInfo;
var lSQL, lCode  : String;
begin
  FComServer := null;
  cdsData    := TClientDataSet.Create(nil); // Create & preparing Component
  try
    lCode := Dataset.FindField('ItemCode').AsString;     
    lSQL  := Format('SELECT UDF_Length, UDF_Width FROM ST_ITEM WHERE Code=%s',[QuotedStr(lCode)]);

    cdsData.Data := ComServer.DBManager.Execute(lSQL);
  finally
    lBizObj    := null;
    FComServer := null;
  end;
end;

begin
  if SameText(EditingField, 'ItemCode') OR // when selecting or change itemcode field
     SameText(EditingField, 'UDF_Rate') then begin // when change UDF_Rate field
    try
      GetStockInfo; // Get UDF_Length & UDF_Width from Maintain Item

      // Below is Set the Invoice detial UDF Fields from Maintain Item UDF Fields
      DataSet.FindField('UDF_Length').AsFloat := cdsData.FindField('UDF_Length').AsFloat;
      DataSet.FindField('UDF_Width').AsFloat  := cdsData.FindField('UDF_Width').AsFloat;

      // Below is doing calculation for Qty := UDF_Length * UDF_Width * UDF_Rate
      DataSet.FindField('Qty').AsFloat        := DataSet.FindField('UDF_Length').AsFloat *
                                                 DataSet.FindField('UDF_Width').AsFloat *
                                                 DataSet.FindField('UDF_Rate').AsFloat;
    finally
      cdsData.Free; // Free the Component after used
    end;
  end;
end.
08. Click Save button
----------------------------------------------------------------------------------------------------------------------------------------------------
Template.Warning-01.jpg
  • Avoid update below field in same time as will cause unlimited looping updating each other
- Qty
- UnitPrice
- TaxAmt
- Amount
----------------------------------------------------------------------------------------------------------------------------------------------------

Script Example 2

  • More Coming Soon....

See also