Osama Ghazal Posted August 29, 2021 Share Posted August 29, 2021 (edited) ****************************** Thanks God, I solve it. The Problem is with loading the uniDBGrid, I enable the BufferedStore, and it solve the problem ****************************** Hi All, I am trying to insert a new customer by fireDAC query and mysql database, The Problem is When I Refresh the query, it gives me no errors but the application is freezing. I put the insert query in UNIDatamodule and the CustomersQuery in the customers form and also I move it to the datamodule, but it is the same. I enabled the screen mask and disable it and it is the same problem I didn't face any problems with the other forms, only this form. Only I open the web from another pc and re open it from my pc, and it was solved directly for only 2 inserting I am working on this problem for 2 days 🥵🥵 I used this sentences: Function TdmMySQL.AddCustomer(CustomersQuery, TagsQuery: TFDQuery; CustomerTags : TStrings) : Integer; var NewID, I: Integer; c_Tag : String; begin With qryInsertCustomer Do Begin Close; if dmMainModule.recCustomer.CustomerNo = 0 then dmMainModule.recCustomer.CustomerNo := dmMainModule.CompanyConnection.ExecSQLScalar('Select IfNull(Max(CustomerNo),0) + 1 From customers'); ParamByName('CustomerNo').Value := dmMainModule.recCustomer.CustomerNo; ParamByName('CustomerName').Value := dmMainModule.recCustomer.CustomerName; ParamByName('CustomerType').Value := dmMainModule.recCustomer.CustomerTypeID; ParamByName('LinkedWithSalesMan').Value := dmMainModule.recCustomer.LinkedWithSalesMan; ParamByName('SalesManID').Value := dmMainModule.recCustomer.SalesManID; ParamByName('SalesTaxType').Value := dmMainModule.recCustomer.SalesTaxType; ParamByName('SalesTaxNumber').Value := dmMainModule.recCustomer.SalesTaxNumber; ParamByName('IsBlackListed').Value := dmMainModule.recCustomer.IsBlackListed; ParamByName('AllowCredit').Value := dmMainModule.recCustomer.AllowCredit; ParamByName('HasDebtLimit').Value := dmMainModule.recCustomer.HasDebtLimit; ParamByName('DebtLimit').Value := dmMainModule.recCustomer.DebtLimit; ParamByName('AllowCheques').Value := dmMainModule.recCustomer.AllowCheques; ParamByName('HasChequesValuesLimit').Value := dmMainModule.recCustomer.HasChequesValuesLimit; ParamByName('ChequesValuesLimit').Value := dmMainModule.recCustomer.ChequesValuesLimit; ParamByName('BankName').Value := dmMainModule.recCustomer.BankName; ParamByName('BankBranch').Value := dmMainModule.recCustomer.BankBranch; ParamByName('BankAccountNumber').Value := dmMainModule.recCustomer.BankAccountNumber; ParamByName('BankSwiftCode').Value := dmMainModule.recCustomer.BankSwiftCode; ParamByName('BankAddress').Value := dmMainModule.recCustomer.BankAddress; ParamByName('IBANNumber').Value := dmMainModule.recCustomer.IBANNumber; End; With qrySaveCustomerInfo Do Begin ParamByName('Phone1').Value := dmMainModule.recCustomer.Phone1; ParamByName('Phone2').Value := dmMainModule.recCustomer.Phone2; ParamByName('Fax').Value := dmMainModule.recCustomer.Fax; ParamByName('Section1ExtName').Value := dmMainModule.recCustomer.Section1ExtName; ParamByName('Section1Ext').Value := dmMainModule.recCustomer.Section1Ext; ParamByName('Section2ExtName').Value := dmMainModule.recCustomer.Section2ExtName; ParamByName('Section2Ext').Value := dmMainModule.recCustomer.Section2Ext; ParamByName('ContactPerson1Name').Value := dmMainModule.recCustomer.ContactPerson1Name; ParamByName('ContactPerson1Mobile').Value := dmMainModule.recCustomer.ContactPerson1Mobile; ParamByName('ContactPerson2Name').Value := dmMainModule.recCustomer.ContactPerson2Name; ParamByName('ContactPerson2Mobile').Value := dmMainModule.recCustomer.ContactPerson2Mobile; ParamByName('EMail1').Value := dmMainModule.recCustomer.EMail1; ParamByName('EMail2').Value := dmMainModule.recCustomer.EMail2; ParamByName('Website').Value := dmMainModule.recCustomer.Website; ParamByName('City').Value := dmMainModule.recCustomer.City; ParamByName('Area').Value := dmMainModule.recCustomer.Area; ParamByName('Street').Value := dmMainModule.recCustomer.Street; ParamByName('BuildingNo').Value := dmMainModule.recCustomer.BuildingNo; ParamByName('BuildingSubNo').Value := dmMainModule.recCustomer.BuildingSubNo; ParamByName('Floor').Value := dmMainModule.recCustomer.Floor; ParamByName('OfficeNo').Value := dmMainModule.recCustomer.OfficeNo; ParamByName('POBOX').Value := dmMainModule.recCustomer.POBOX; ParamByName('POBoxCity').Value := dmMainModule.recCustomer.POBoxCity; ParamByName('ZipCode').Value := dmMainModule.recCustomer.ZipCode; ParamByName('POBoxState').Value := dmMainModule.recCustomer.POBoxState; ParamByName('Remarks').Value := dmMainModule.recCustomer.Remarks; End; With qrySaveCustomerOpenBalances Do Begin ParamByName('PeriodID').Value := dmMainModule.LoginInfo.PeriodID; ParamByName('Debit').Value := dmMainModule.recCustomer.OpeningDebit; ParamByName('Credit').Value := dmMainModule.recCustomer.OpeningCredit; End; dmMainModule.CompanyConnection.StartTransaction; Try qryInsertCustomer.OpenOrExecute; // I tried this and also open to take a newid result NewID := qryInsertCustomer.FieldByName('NewID').Value; dmMainModule.recCustomer.CustomerID := NewID; qrySaveCustomerInfo.ParamByName('CustomerID').Value := NewID; qrySaveCustomerInfo.ExecSQL; qrySaveCustomerOpenBalances.ParamByName('CustomerID').Value := NewID; qrySaveCustomerOpenBalances.ExecSQL; qrySaveCustomerTags.Params.ArraySize := CustomerTags.Count; for I := 0 to CustomerTags.Count - 1 do Begin c_Tag := CustomerTags[i]; if TagsQuery.Locate('Tag',c_Tag,[]) then Begin qrySaveCustomerTags.ParamByName('CustomerID').Values[i] := NewID; qrySaveCustomerTags.ParamByName('TagID').Values[i] := TagsQuery.FieldByName('TagID').AsInteger; End; End; qrySaveCustomerTags.Execute(qrySaveCustomerTags.Params.ArraySize); dmMainModule.CompanyConnection.Commit; qryInsertCustomer.Close; CustomersQuery.Refresh; // ***** here is the problem and I tried to close it and reopen it also ********/// CustomersQuery.Locate('CustomerID', dmMainModule.recCustomer.CustomerID, []); Result := NewID; Except On E : Exception Do Begin dmMainModule.CompanyConnection.Rollback; ShowMessage(E.Message); Result := -1; raise; End; End; end; the CustomersQuery.text is : Select c.CustomerID, c.CustomerNo, c.CustomerName, Cast(c.CustomerType as signed integer) as CustomerTypeID, ct.TypeName as CustomerType, c.LinkedWithSalesMan, c.SalesManID, sm.SalesManName, c.SalesTaxType, c.SalesTaxNumber, c.IsBlackListed, c.AllowCredit, c.HasDebtLimit , c.DebtLimit, c.AllowCheques, c.HasChequesValuesLimit, c.ChequesValuesLimit , c.BankName, c.BankBranch, c.BankAccountNumber, c.BankSwiftCode , c.BankAddress, c.IBANNumber, ci.Phone1, ci.Phone2, ci.Fax, ci.Section1ExtName , ci.Section1Ext, ci.Section2ExtName, ci.Section2Ext, ci.ContactPerson1Name, ci.ContactPerson1Mobile, ci.ContactPerson2Name, ci.ContactPerson2Mobile , ci.EMail1, ci.EMail2 , ci.Website, ci.City, ci.Area , ci.Street, ci.BuildingNo, ci.BuildingSubNo, ci.Floor , ci.OfficeNo, ci.POBOX, ci.POBoxCity, ci.ZipCode , ci.POBoxState, ci.Remarks From customers c Left Outer Join customersinfo ci on c.CustomerID = ci.CustomerID Left Outer Join customertypes ct on c.CustomerType = ct.TypeID Left Outer Join SalesMen sm on sm.SalesManID = c.SalesManID Where Upper(c.CustomerName) Like Upper(:CustomerName) AND Upper(sm.SalesManName) Like Upper(:SalesManName) Edited August 30, 2021 by Osama Ghazal The problem was solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.