Jump to content

taariq

Members
  • Content Count

    29
  • Joined

  • Last visited

Posts posted by taariq


  1. Good day
    Plz note I am a newbie to Delphi and still learning but enjoying it...

     

    I need help with calculations please...

     

    I got total sum via database by using the following code that is working...

     

    dmuse.dmDBuse.FDQueryMaterialTotal.Open('SELECT SUM(COST) AS TC FROM MATERIAL WHERE ORDERNO=:d',[dbOrderNo.Text]);
    Showmessage(format( 'Total for Material OrderNo %s is %m',[dbOrderNo.text,dmuse.dmDBuse.FDQueryMaterialTotal.FieldbyName('TC').asCurrency]));
    tMaterial.text:=Format('%m',[dmuse.dmDBuse.FDQueryMaterialTotal.fieldbyName('TC').asCurrency]);

     

    dmuse.dmDBuse.fdQueryTraveling.Open('SELECT SUM(COST) AS TC FROM TRAVELING WHERE ORDERNO=:d',[dbOrderNo.Text]);
    Showmessage(format( 'Total for Traveling OrderNo %s is %m',[dbOrderNo.text,dmuse.dmDBuse.fdQueryTraveling.FieldbyName('TC').asCurrency]));
    tTraveling.text:=Format('%m',[dmuse.dmDBuse.fdQueryTraveling.fieldbyName('TC').asCurrency]);

     

    But here is my issue - trying to add the two values together

     

    Code I tried but get error -
    image.png.122147abf0241d124163876c65845104.png

     

    Code I am using...

    procedure TForm1.Button2Click(Sender: TObject);
    var  tMaterial, tTraveling, tTotalCost: Currency ;
     usSet : TFormatSettings;
    begin
      usSet:=TFormatSettings.Create('EN_US');

      tMaterial :=  StrToCurr (lbMaterial.Caption,usSet) ;
      tTraveling :=  StrToCurr (lbTraveling.Caption,usSet) ;


      tTotalCost := tMaterial + tTraveling;

      tProjectCosting.text := CurrToStrF(tTotalCost, ffCurrency, 2);

    end;

     

    Please help

    Thank you


  2. Good day
    Thank you - getting closer now....

    I updated the code to include amountex - hope I did it correct - it runs and then I get this error...

     

    image.png.3889f1e98388a967d1bc0bc2a25f8092.png

     

    My current records

    image.png.641f15d0fff578faf8c3dd2f7d5d9e01.png

    The updated code

     

    procedure TMainForm.Button1Click(Sender: TObject);
    //declare var to enter new job card
    var sOrderNo, sJobName , sStartDate, sCompletionDate, sAmountEx: string ;
    begin
    sOrderNo := Inputbox ( 'OrderNo' ,  'Enter OrderNo'  , 'QU000' ) ;
    sJobName := Inputbox ( 'JobName' ,   'Enter JobName'  , 'Company Name' ) ;
    sStartDate := Inputbox ( 'StartDate' ,   'Enter Start Date'  , 'YYYY/MM/DD' ) ;
    sCompletionDate := Inputbox ( 'CompletionDate' ,   'Enter Completion Date'  , 'YYYY/MM/DD' ) ;
    sAmountEx := Inputbox ( 'AmountEx' ,   'Enter Amount Ex'  , 'R '  ) ;
    dmTas.tblJobCard.Connection.ExecSQL('INSERT INTO jobCard (orderno,jobname,StartDate,Completiondate,AmountEx) values (?,?,?,?,?)', [sOrderNo,sJobName,sStartDate,sCompletionDate,sAmountEx]);

    //
    // if you want to retrieve last id you can use ExecSQLScalar
    //LID:=dmTas.tblJobCard.Connection.ExeSQL('INSERT INTO jobCard (orderno,jobname,StartDate,Completiondate,AmountEx) values (?,?,?,?,?) RETRUNING ID into :id',  [sOrderNo,sJobName,sStartDate,sCompletionDate,sAmountEx]);
    // put LID as private or public of the form
    // do refresh Grid

    end;

     

     


  3. 9 minutes ago, Serge_G said:

    Why don't you use this in your code ?

    
     procedure TMainForm.Button1Click(Sender: TObject);
    //declare my var to enter new job card
    var sOrderNo, sJobName , sStartDate, sCompletionDate, sAmountEx: string ;
    begin
    sOrderNo := Inputbox ( 'OrderNo' ,   'Enter OrderNo'  , 'QU000'  ) ;
    sJobName := Inputbox ( 'JobName' ,   'Enter JobName'  , 'Company Name'  ) ;
    sStartDate := Inputbox ( 'StartDate' ,   'Enter Start Date'  , 'YYYY/MM/DD'  ) ;
    sCompletionDate := Inputbox ( 'CompletionDate' ,   'Enter Completion Date'  , 'YYYY/MM/DD'  ) ;
    dmTas.tblJobCard.Connection.ExeSQL('INSERT INTO jobCard (orderno,jobname,StartDate,Completiondate,amount) values (?,?,?,?,?)', [sOrderNo,sJobName,sStartDate,sCompletionDate,sAmountEx]);
    // if you want to retrieve last id you can use ExecSQLScalar
    //LID:=dmTas.tblJobCard.Connection.ExeSQL('INSERT INTO jobCard (orderno,jobname,StartDate,Completiondate,amount) values (?,?,?,?,?) RETRUNING ID into :id',  [sOrderNo,sJobName,sStartDate,sCompletionDate,sAmountEx]);
    // put LID as private or public of the form
    // do refresh Grid 
    end;

    Thank you - let me do this one will get back to you asap
    Thank you so much for your time....

     


  4. 14 minutes ago, Stano said:

    PrimaryKeys are an internal DB issue. You have nothing to do with them. The user must not suspect that such a thing exists.
    I repeat: you must use the Generator to insert new PrimaryKeys.

     

    Good day


    I did create Generator BUT for some reason Only works in Flamerobin and not in Delphi...

    image.thumb.png.1cf7d16545a2f204d5a66fe861047ee0.png


  5. Good day

    Thank you so much I will have a look - this is my first FlameRobin and Firecad database - I had it all working 100% with a Access database...
    So now just trying to understand Flamerobin and Firecad ......

    But for now if I want to take the ID as I got it in DBText2 and + 1 their how will I set the following to get the value from a label or the dbtext

    iID:= StrToInt ( Inputbox ( 'ID' ,   'ID'  , '002'  ) ) ;


  6. 31 minutes ago, joaodanet2018 said:

    if "ID" is auto-increment by default on table, then, dont inform it on inserts --> you dont need know what next id, your database will know it! 

    That is the issue I got ?
    In Flamerobin I can add a record and it generates the id for the next record...
    But in Delphi it asks for ID?

    My code that I currently got where it asks for id...
    I get error > Field 'ID' must have a value.

     

    procedure TMainForm.Button1Click(Sender: TObject);
    //declare my var to enter new job card
    var sOrderNo, sJobName , sStartDate, sCompletionDate, sAmountEx: string ;
    //iID : integer;
    begin
    //asign values to input box
    //iID:= StrToInt ( Inputbox ( 'ID' ,   'ID'  , '002'  ) ) ;

    sOrderNo := Inputbox ( 'OrderNo' ,   'Enter OrderNo'  , 'QU000'  ) ;
    sJobName := Inputbox ( 'JobName' ,   'Enter JobName'  , 'Company Name'  ) ;
    sStartDate := Inputbox ( 'StartDate' ,   'Enter Start Date'  , 'YYYY/MM/DD'  ) ;
    sCompletionDate := Inputbox ( 'CompletionDate' ,   'Enter Completion Date'  , 'YYYY/MM/DD'  ) ;
    sAmountEx := Inputbox ( 'AmountEx' ,   'Enter Amount Ex'  , 'R '  ) ;
    //insert values to DBgrid
    dmTaS.tblJobCard.Insert ;
    //dmTaS.tblJobCard['ID' ] := iID ;
    dmTaS.tblJobCard['OrderNo' ] := sOrderNo ;
    dmTaS.tblJobCard['JobName' ] := sJobName ;
    dmTaS.tblJobCard['StartDate' ] := sStartDate ;
    dmTaS.tblJobCard['CompletionDate' ] := sCompletionDate ;
    dmTaS.tblJobCard['AmountEx' ] := sAmountEx ;
    dmTaS.tblJobCard.Post ;
    //refresh db grid
    DBGrid1.DataSource.DataSet.Refresh;
    //show mesagges


    end;

     

    But if I do it like the following and add the ID manually it works - so I sorted the query via sql to get the last ID - I have the last ID in DBText2 - so now trying to figure out how to + 1 and give the value to iID

    procedure TMainForm.Button1Click(Sender: TObject);
    //declare my var to enter new job card
    var sOrderNo, sJobName , sStartDate, sCompletionDate, sAmountEx: string ;
    iID : integer;
    begin
    //asign values to input box
    iID:= StrToInt ( Inputbox ( 'ID' ,   'ID'  , '002'  ) ) ;
    sOrderNo := Inputbox ( 'OrderNo' ,   'Enter OrderNo'  , 'QU000'  ) ;
    sJobName := Inputbox ( 'JobName' ,   'Enter JobName'  , 'Company Name'  ) ;
    sStartDate := Inputbox ( 'StartDate' ,   'Enter Start Date'  , 'YYYY/MM/DD'  ) ;
    sCompletionDate := Inputbox ( 'CompletionDate' ,   'Enter Completion Date'  , 'YYYY/MM/DD'  ) ;
    sAmountEx := Inputbox ( 'AmountEx' ,   'Enter Amount Ex'  , 'R '  ) ;
    //insert values to DBgrid
    dmTaS.tblJobCard.Insert ;
    dmTaS.tblJobCard['ID' ] := iID ;
    dmTaS.tblJobCard['OrderNo' ] := sOrderNo ;
    dmTaS.tblJobCard['JobName' ] := sJobName ;
    dmTaS.tblJobCard['StartDate' ] := sStartDate ;
    dmTaS.tblJobCard['CompletionDate' ] := sCompletionDate ;
    dmTaS.tblJobCard['AmountEx' ] := sAmountEx ;
    dmTaS.tblJobCard.Post ;
    //refresh db grid
    DBGrid1.DataSource.DataSet.Refresh;
    //show mesagges

    end;

     

     

     


  7. Good day

    I am VCL

    I got my table ordered correctly now via SQL
    It is ordering DESC
    I got the last ID now in a DBText2
     

    So all I have to figure out now is how to add +1 to the value and I assume update the following...

     

    iID:= StrToInt ( Inputbox ( 'ID' ,   'ID'  , '002'  ) ) ;

    or

    dmTaS.tblJobCard['ID' ] := iID ;

     

     

    So the Delphi passes the next id on ....
    I think...

     

     

     


  8. Good day

    I got it to work now from Delphi side when I manual add the id...

    Now I see that the sort by does not work and I have to do it by SQL..
    So now I am trying to figure out how to sort the db grid to get last ID record to get the next ID - is this correct ?

    please point me in the right direction....

     

    Thank you
     


  9. thanks for the quick reply - I don't understand that - sorry newbie - first time working with Firebird and flamerobin...
    Maybe I created the table wrong - here is the code I used to created the table..

     

    create table JobCard (id integer generated by default as identity primary key,
      orderno varchar(12),
      jobname varchar(100),
      startdate varchar(24),
      completiondate varchar(24),
      amountex varchar(12),
      desc varchar (50)
      );


  10. Thank for all the help - really learning a lot now - thank you so much for your time and effort...

     

    So now I did the following...
    1. Create my Firbird databse
    2. Used FlameRobin

    3. I added a record via Delphi to the database - so happy
    4. Now I am trying to generate the ID next number so I don't have to manually add it...
    My code works all fine adding record, but not once I add the code to sort field to get ID vale...
    I get error under //get next ID

     

    procedure TMainForm.Button1Click(Sender: TObject);
    //declare my var to enter new job card
    var sOrderNo, sJobName , sStartDate, sCompletionDate, sAmountEx: string ;
    iID : integer;
    begin
    //assign values to input box
    //iID:= StrToInt ( Inputbox ( 'ID' ,   'ID'  , '002'  ) ) ;
    sOrderNo := Inputbox ( 'OrderNo' ,   'Enter OrderNo'  , 'QU000'  ) ;
    sJobName := Inputbox ( 'JobName' ,   'Enter JobName'  , 'Company Name'  ) ;
    sStartDate := Inputbox ( 'StartDate' ,   'Enter Start Date'  , 'YYYY/MM/DD'  ) ;
    sCompletionDate := Inputbox ( 'CompletionDate' ,   'Enter Completion Date'  , 'YYYY/MM/DD'  ) ;
    sAmountEx := Inputbox ( 'AmountEx' ,   'Enter Amount Ex'  , 'R '  ) ;
    //get next ID
    dmTaS.tblJobCard.Sort := 'ID ASC'  ;
    dmTaS.tblJobCard.Last;
    iID : = dmTaS.tblJobCard['ID'] + 1 ;

    //insert values to DBgrid
    dmTaS.tblJobCard.Insert ;
    dmTaS.tblJobCard['ID' ] := iID ;
    dmTaS.tblJobCard['OrderNo' ] := sOrderNo ;
    dmTaS.tblJobCard['JobName' ] := sJobName ;
    dmTaS.tblJobCard['StartDate' ] := sStartDate ;
    dmTaS.tblJobCard['CompletionDate' ] := sCompletionDate ;
    dmTaS.tblJobCard['AmountEx' ] := sAmountEx ;
    dmTaS.tblJobCard.Post ;
    //refresh db grid
    DBGrid1.DataSource.DataSet.Refresh;
    //show messages

     

    Thank you


  11. Thanks will have a look...
    Just a question if I have a field  > ORDERNO , can I use that as my id as all tables will use the >orderno< to identify the records related to that order number...
    Or is it a must that I must have an id field....

     

    Thank you

     

     


  12. Thank you so much

    Playing with Firebird and Flamerobin
    How would I setup an id field that is an auto number for ID as access db

    My SQL

    create table JobCard ( id varchar(10) not null primary key,
      orderno varchar(12),
      jobname varchar(100),
      startdate varchar(24),
      completiondate varchar(24),
      amountex varchar(12),
      desc varchar (50)
      );

     

    Thank you

×