601

(3 replies, posted in General)

Selected customer focused then it displays customer inv and if invoice has any inv items via use of search buttons.


Issue I wanted solve when newly added customer selected without any invoice to display. Inv Items tGrid was displaying all inv items of all customers.


The following sorted on cell click (when browsing customers tGrid with mouse)

procedure tgMainCustCellClick2; 
begin
  if Form1.tgMainCustomersTrans.rowcount = 0 then
  begin
  Form1.tgMainCustomersTransItems.clearrows;
  end;
end;

However, when browsing customer records with keyboard up and down keys following didn't work?

procedure tgMainCustKeyUp2;
begin
  if Form1.tgMainCustomersTrans.rowcount = 0 then
  begin
  Form1.tgMainCustomersTransItems.clearrows;
  end;
end;

Please see the attached sample project

602

(14 replies, posted in General)

ehwagner wrote:

Thought I would take a stab at it.


Hi EHW,


Thank you very much..........................
Nice start.


Here is what I'm trying to do (please see the attachment) but unable to do so - beyond my current knowledge. Perhaps Dmitry can give us hand too.

603

(14 replies, posted in General)

I found some Delphi code on the Net.. Perhaps somebody can translate MVD or do something with it.


From: https://delphindo.wordpress.com/2009/04 … generator/

Tricks generate random passwords of a certain length
To generate random text, you need to specify the length of text to be generated. With SetLength () you can adjust the length of a string dynamically. If the password length you specify, the next step of each character in the password is determined randomly by using the Random () function. The output of the Random () function is used to perform a look-up to a list of allowed characters to become password characters. The function parameter Random () we fill with the number of characters allowed as password characters.

The following is the full source code of the TPasswordGenerator class that wraps the random password generation functionality of a certain length.

unit paswgen;

interface
uses classes;

const
  CHAR_ALPHANUM='ABCDEFGHIJKLMNOPQRSTUVWXYZ'+
                           'abcdefghijklmnopqrstuvwxyz'+
                           '0123456789';
  CHAR_ALPHA='ABCDEFGHIJKLMNOPQRSTUVWXYZ'+
                     'abcdefghijklmnopqrstuvwxyz';
  CHAR_NUMERIC='0123456789';

type
  TPasswordGenerator=class(TObject)
  private
    FMaxChar: word;
    FPassword: string;
    FCharacter: string;
    procedure SetMaxChar(const Value: word);
    procedure SetCharacter(const Value: string);
  public
    constructor Create;
    procedure Generate;

    //password
    property Password:string read FPassword;
    //karakter yang diijinkan
    property Character:string read FCharacter write SetCharacter;
    //panjang password
    property MaxChar:word read FMaxChar write SetMaxChar;
  end;

implementation


{ TPasswordGenerator }

constructor TPasswordGenerator.Create;
begin
  FMaxChar:=8;
  SetLength(FPassword,FMaxChar);
  FCharacter:=CHAR_ALPHANUM;
end;

procedure TPasswordGenerator.Generate;
var i,indx:word;
begin
  SetLength(FPassword,FMaxChar);
  for i:=1 to FMaxChar do
  begin
    indx:=random(length(FCharacter))+1;
    FPassword[i]:=FCharacter[indx];
  end;
end;

procedure TPasswordGenerator.SetCharacter(const Value: string);
begin
  FCharacter := Value;
end;

procedure TPasswordGenerator.SetMaxChar(const Value: word);
begin
  FMaxChar := Value;
end;

initialization
Randomize;
end.

604

(48 replies, posted in General)

Hi EHW,


Thank you very much...........
Truly appreciated........


I had to take out  Report word from ReportMemo1 to get it working. I guess it was because memo1 wasn't db field, just a label in Fast reports. The following worked for me thanks to your kind help:

if trim(ReportDbCrdbcr.text) = 'Sale' then
  begin              
    ReportDbCrdbcr.font.Color := clBlue;
    Memo1.font.color := clBlue;
  end else    
    begin
     ReportDbCrdbcr.font.Color := clRed;
     Memo1.font.color := clRed;
    end;

605

(48 replies, posted in General)

I have an Invoice report. I like to change color of two fields in Fast Reorts depending on field 1 value.


Field 1. DbCr with 2 values (ReportDbCrdbcr)
Sale
Refund


Field 2. Fast reports text field (Memo1)


In Fast reports script editor I need the following script please.
----------------------------------------------------------------------------------
If Field 1 value is  'Sale' then Field 1 and Field 2 text color =clBlue

If Field 1 value is  'Refund' then Field 1 and Field 2 text color =clRed


The following didn't work?

procedure ReportDbCrdbcrOnAfterData(Sender: TfrxComponent);
begin
  if DbCrdbcr.text := 'Sale' then
  begin              
  DbCrdbcr.textColor := clBlue;
  Memo1.text := clBlue
  else
  if DbCrdbcr.text := 'Refund' then      
    begin
    DbCrdbcr.textColor := clRede;
    Memo1.text := clRede
    end;              
end;

606

(15 replies, posted in General)

Thank you very much EHW..........................
Truly appreciated.............................

607

(15 replies, posted in General)

I wanted to color all rows text to red on tgMainCustomersTransItems,  if  tgMainCustomersTrans column[1] contained 'Refund' as follow:

procedure tgCustInvItemChange2; // ********* Coloring refund Inv Items rows
var
   iRow1 ,c2: integer;
   q1, iCol1: integer;
begin
     c2 := Form1.tgMainCustomersTransItems.RowCount - 1;
     q1 := Form1.tgMainCustomersTransItems.Columns.Count-1;
     for iRow1 := 0 to c2 do
        if Form1.tgMainCustomersTrans.Cells[1,iRow1] = 'Refund' then
            for iCol1 := 0 to q1 do Form1.tgMainCustomersTransItems.Cell[iCol1,iRow1].textColor := clRed;
end;

but it didn't work? Tried to add Form1.btnCustTransItemSearch.click; to above which caused app crash on run.


--------------------------------------------------------------------------------------------------------------------------------------------------------------


Also tried to get tGrid focused on newly added record row with the following but didn't work too:

procedure frmSalesInv_Button1_OnAfterClick (Sender: string);
begin
      Form1.tgMainCustomersTrans.dbItemID:= Last_Insert_id;
      Form1_tgMainCustomersTrans_OnCellClick('',0,0);
end;

608

(15 replies, posted in General)

Hi EHW,


Great Stuff!!!
Thank you very much................................


...I'm not sure I understand your tax issue though.

I was trying to display inv tax amounts on inv tGrid on a different form with some calcs. On inv tGrid credit (refund) tax amounts displayed with minus (-125) and sale ones normal (125). I wanted to display them in inv  register form to have a clearer picture about sales and refund with some calcs as there are discounts and deliv charges. Then I noticed that I need to add, sub etc some minus values from plus ones ((150 + (-125)) etc. and realized that I was making things difficult for myself. So I decided to take out all those minus items to simplify things in such a way that I could perhaps make something out of it.. Working on it currently.........

609

(15 replies, posted in General)

I tried to hide refund reason column [0] on tgMainCustomersTransItems, when column [1] cell value is 'Sale' on tgMainCustomersTrans with the script below but couldn't get it right:


procedure Form1_tgMainCustomersTrans_OnChange (Sender: string);
begin
if Form1.tgMainCustomersTrans.Cells[1,Form1.tgMainCustomersTrans.SelectedRow] = 'Sale' then
   begin
     Form1.tgMainCustomersTransItems.Columns[0].Visible := False;
   end;
end;

Another issue I have no idea how to solve. tGrid tax column contains + and - values. How can I pick only minus values from the tGrid tax column cells and show the total on edit field? Kind of creating virtual tGrid tax footer column without changing the current structure of the tGrid.

610

(15 replies, posted in General)

Great Stuff EHW.......................
Thank you very much.......................


What was the issue with adding and showing records on inv items? Your sample project works perfectly but with my work project I couldn't solve showing records correctly on inv items tGrid.


edit:
I think I sorted it out. I forgot to include combobox1 on inv items save.

611

(15 replies, posted in General)

Thanks a lot for the quick info EHW..........


I noticed an issue on adding inv item. It would come up with not null error since id_customer was marked as required.  I checked off nut null. However, this time saved invoice item is not displayed tgMainCustomersTransItems tGrid.


Also, I'm not clear how to get customer details (address) on sale inv form as combo changed to label. I couldn't see onChange event for labels.


Once again I'm grateful for your kind help.........

612

(15 replies, posted in General)

Hi EHW,


Thank you very much for the fix and the info......................
There are some great stuff for me to learn and use in future projects... truly appreciated............


Your fixed sample project runs perfectly. No problem on there.
However, my work project not when I remove dbcr field from the sales items table I get an error.
https://s30.postimg.org/3vmi30f35/zzzzz_Temp29.png
I checked tgMainCustomersTrans grid, even taken out additional columns to make it same as the test project but no luck. When I put back dbcr field to sales items table it works without error but causes invoice items table refresh failure on browsing customers.

613

(15 replies, posted in General)

I'm still playing with Derek's approach on refunds. It was all fine until I start testing inv report/print. I realized that it's not practical to have sale and return items on same invoice when printing; as sale and refunds usually happens at different times. If already sale invoice issued/sent later on adding refund items to same invoice and issuing it again would be incorrect. Granted, one can issue sale and refund inv headers and items separately but this would require extra attention on user part so that user doesn't add refund items to sale inv header etc.


In order to avoid all those inconveniences, I thought moving sale or refund (DbCr) combo to sale invoice header and referencing combo value on sale inv items so that user can only add sale inv items to sale inv header and vice versa. With additional coloring (Thanks to EHW) to highlight it's whether sale or refund + hiding refund reason combo and it's label if it's a sale on sale inv items form.


In attached sample project I have tried to apply coloring and getting sale/ refund (DbCr) value on sale inv item form in order to apply same coloring + show / hide refund reason combo and it's label but failed again?


EHW, I used onAfterClick for coloring on form1 add and edit buttons beside combo on change events. Thinking it'd be used with add and edit actions beside combo change on inv header. When existing record displayed with edit action it'd keep the original status (coloring) whether it's a sale or refund.

614

(15 replies, posted in General)

Hi EHW,


Thank you very much for the fix......... truly appreciated........

615

(15 replies, posted in General)

I was trying to color label and panel depending on combobox content on same form with the following but couldn't get the script constructed correctly:

procedure Form1_OnShow (Sender: string; Action: string);  // for combo def index 0 which is Sale. However, combo doesn't show it somehow?
begin
  begin
   if Form1.cbSaleInvDBCR.text = 'Sale' then
      begin
      Form1.Label1.Caption := 'Sales Invoice'.color := clWhite;                            
      Form1.Panel1.color :=  clBlue;
      end
end;

procedure Form1_cbSaleInvDBCR_OnChange (Sender: string);
begin
   if Form1.cbSaleInvDBCR.text = 'Sale' then
      begin
      Form1.Label1.Caption := 'Sales Invoice'.color := clWhite;
      Form1.Panel1.color :=  clBlue;
      end else
      begin
      Form1.Label1.Caption := 'Sales Credit Note'.color := clWhite
      Form1.Panel.color :=  clRed;
      end;
end;

Combo has two items in total.
Sale
Refund.
First empty item set to false
Default index set to zero


If needed please see the sample project attached:

616

(9 replies, posted in General)

Hi EHW,


Thank you so much.................................

617

(9 replies, posted in General)

I couldn't apply foreign key constraint script to multiple delete buttons on same form.


I have lookups form contains about 15 tables with 15 delete buttons on tab pages. How can I apply one  foreign key constraint script to multiple delete buttons on a same form rather than repeating the script 15 times?


function OnSQLException(Sender: TObject; Msg: string; SQL: string): boolean;
begin
    if Sender = frmLookups.btnGenTaxRateDelete + frmLookups.btnGenCountryDelete + frmLookups.btnGenRetReasonDelete then
    begin
    if Pos('FOREIGN KEY constraint failed', Msg)=1 then
        begin
            result := True; // to prevent system message
            MessageBox('Record cannot be deleted....',
            'Error', MB_OK+MB_ICONWARNING);
        end;
    end;
end;

618

(3 replies, posted in General)

Thank you very much Dmitry....................
Great support....... Truly appreciated...

619

(3 replies, posted in General)

AD1408 wrote:

Hi Dmitry,


I have posted this issue in another topic, perhaps you missed it:

Most pressing issue on previous post is horizontal scroll bar flash. I have been trying to find the issue causing this strange behavior but so far no luck.
1. Click on a record from customer tgrid
2. Horizontal scroll bar briefly appears and disappears (flashes) over tGrid transactions and transaction items tGrids if transactions and transaction items tGrids contain records.

Is it a tGrid bug or I'm doing something wrong?

Tried on MVD 3.3 and 3.4b.


Any solution?

620

(3 replies, posted in General)

Hi Dmitry,


I have posted this issue in another topic, perhaps you missed it:

Most pressing issue on previous post is horizontal scroll bar flash. I have been trying to find the issue causing this strange behavior but so far no luck.
1. Click on a record from customer tgrid
2. Horizontal scroll bar briefly appears and disappears (flashes) over tGrid transactions and transaction items tGrids if transactions and transaction items tGrids contain records.

Is it a tGrid bug or I'm doing something wrong?

Tried on MVD 3.3 and 3.4b.

ehwagner wrote:

Adam, See attached for customer and product label fix. You do not need to fetch the names from the database. Since the names are already in the main tablegrids, I just pulled them from the grids instead. It eliminates an extra read to the database.


Hi EHW,
Thank you very much......................
Nice and clean solution!!!

Most pressing issue on previous post is horizontal scroll bar flash. I have been trying to find the issue causing this strange behavior but so far no luck.

1. Click on a record from customer tgrid
2. Horizontal scroll bar briefly appears and disappears (flashes) over tGrid transactions and transaction items tGrids if transactions and transaction items tGrids contain records.


Is it a tGrid bug or I'm doing something wrong?
please see the sample project  InvRefund 3.zip on my previous post #3

623

(13 replies, posted in General)

Thank you very much EHW................................

624

(13 replies, posted in General)

Thanks a lot EHW..............


I don't if it's possible to display checked field/s values is/are displayed in error message?
For instance if we are checking for name and surname fields for dup record, instead of 'Duplicate Record is not allowed - Cannot Save'; having  'Peter White exist in the database. Duplicate record is not allowed - Cannot Save'

625

(13 replies, posted in General)

Hi EHW,


Nice example for my single cell brain...
What about when checking more than 1 field. Tried the following for two fields dup check but didn't work:

procedure Form2_Button_Save_OnClick (Sender: string; var Cancel: boolean);
begin
    If (SqlExecute('Select Count(Id) From MyTable Where Col1 = "' + Form2.Edit_Col1.Text + '"') > 0) and
       (SqlExecute('Select Count(Id) From MyTable Where Col2 = "' + Form2.Edit_Col2.Text + '"') > 0) then

      Begin
         MessageBox('Duplicate Record Exists - Cannot Save','Error',MB_OK+MB_ICONERROR);
         Cancel := True;
         Form2.Edit_Col1.SetFocus;
         Form2.Edit_Col2.SetFocus;
         Exit;
      End;
end;