Guest User

Untitled

a guest
Nov 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. select ec.*
  2. from tt_emp e, tt_emp_contract ec
  3. where (coalesce(e.tt_nonactive,0)=0)
  4. and e.tt_emp_id = ec.tt_emp_id
  5.  
  6. with EmployeeContracts do
  7. begin
  8. // Retrieve contracts of all active employees
  9. if (not Active) then
  10. begin
  11. Open;
  12. end;
  13.  
  14. // Is record already correctly positioned?
  15. if (FieldByName(SEmpID).Asinteger=AEmpID) and
  16. (FieldByName(SFromDate).AsDateTime<=APeilDatum) and
  17. (FieldByName(SToDate).AsDateTime>=APeilDatum) then
  18. begin
  19. Result := True;
  20. Exit;
  21. end;
  22.  
  23. if not FindKey([AEmpID]) then // Make sure the data are up to date. Refresh from the server.
  24. begin
  25. Refresh; // ERROR HERE
  26. end;
  27.  
  28. if FindKey([AEmpID]) then
  29. begin
  30. while (FieldByName(SempID).Asinteger=AEmpID) and (not EOF) do
  31. begin
  32. if (FieldByName(SFromDate).AsDateTime<=APeilDatum) and
  33. (FieldByName(SToDate).AsDateTime>=APeilDatum) then
  34. begin
  35. Result := True;
  36. Exit;
  37. end;
  38.  
  39. Next;
  40. end;
  41. end;
  42. end;
  43.  
  44. unit uClientDatasetRefresh;
  45.  
  46. interface
  47.  
  48. uses
  49. Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  50. Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option,
  51. FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf,
  52. FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt, FireDAC.UI.Intf,
  53. FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Phys, FireDAC.Phys.FB,
  54. FireDAC.Phys.FBDef, FireDAC.VCLUI.Wait, Data.DB, Vcl.StdCtrls, Vcl.Grids,
  55. Vcl.DBGrids, Vcl.ExtCtrls, FireDAC.Comp.Client, FireDAC.Comp.DataSet,
  56. Datasnap.Provider, Datasnap.DBClient;
  57.  
  58. type
  59. TFrmClientDatasetRefresh = class(TForm)
  60. ClientDataSet1: TClientDataSet;
  61. DataSetProvider1: TDataSetProvider;
  62. FDQuery1: TFDQuery;
  63. FDConnection1: TFDConnection;
  64. Panel1: TPanel;
  65. DataSource1: TDataSource;
  66. DBGrid1: TDBGrid;
  67. Button1: TButton;
  68. procedure Button1Click(Sender: TObject);
  69. private
  70. function PositionOnEmployeeContractRecord(AEmpID: integer; ADate: TDateTime = 0): Boolean;
  71. public
  72. end;
  73.  
  74. var
  75. FrmClientDatasetRefresh: TFrmClientDatasetRefresh;
  76.  
  77. implementation
  78.  
  79. {$R *.dfm}
  80.  
  81. procedure TFrmClientDatasetRefresh.Button1Click(Sender: TObject);
  82. begin
  83. PositionOnEmployeeContractRecord(20652); // Has records in tt_emp_contract
  84. PositionOnEmployeeContractRecord(1024); // Has no records in tt_emp_contract
  85. end;
  86.  
  87. const
  88. SEmpID = 'tt_emp_id';
  89. SFromDate = 'tt_fromdate';
  90. SToDate = 'tt_todate';
  91.  
  92. function TFrmClientDatasetRefresh.PositionOnEmployeeContractRecord(AEmpID: integer; ADate: TDateTime = 0): Boolean;
  93. begin
  94. Result := False;
  95.  
  96. if (AEmpID=0) then Exit;
  97. if ADate=0 then ADate := Date;
  98.  
  99. with ClientDataSet1 do
  100. begin
  101. if (not Active) then
  102. begin
  103. Open;
  104. end;
  105.  
  106. if (FieldByName(SEmpID).Asinteger=AEmpID) and
  107. (FieldByName(SFromDate).AsDateTime<=ADate) and
  108. (FieldByName(SToDate).AsDateTime>=ADate) then
  109. begin
  110. Result := True;
  111. Exit;
  112. end;
  113.  
  114. if not FindKey([AEmpID]) then
  115. begin
  116. Refresh;
  117. end;
  118.  
  119. if FindKey([AEmpID]) then
  120. begin
  121. while (FieldByName(SempID).Asinteger=AEmpID) and (not EOF) do
  122. begin
  123. if (FieldByName(SFromDate).AsDateTime<=ADate) and
  124. (FieldByName(SToDate).AsDateTime>=ADate) then
  125. begin
  126. Result := True;
  127. Exit;
  128. end;
  129.  
  130. Next;
  131. end;
  132. end;
  133. end;
  134. end;
  135.  
  136. end.
  137.  
  138. object FrmClientDatasetRefresh: TFrmClientDatasetRefresh
  139. Left = 0
  140. Top = 0
  141. Caption = 'ClientDataset Refresh'
  142. ClientHeight = 276
  143. ClientWidth = 560
  144. Color = clBtnFace
  145. Font.Charset = DEFAULT_CHARSET
  146. Font.Color = clWindowText
  147. Font.Height = -11
  148. Font.Name = 'Tahoma'
  149. Font.Style = []
  150. OldCreateOrder = False
  151. Position = poScreenCenter
  152. PixelsPerInch = 96
  153. TextHeight = 13
  154. object Panel1: TPanel
  155. Left = 0
  156. Top = 0
  157. Width = 560
  158. Height = 41
  159. Align = alTop
  160. BevelOuter = bvNone
  161. TabOrder = 0
  162. ExplicitLeft = 16
  163. ExplicitTop = 8
  164. ExplicitWidth = 185
  165. object Button1: TButton
  166. Left = 32
  167. Top = 8
  168. Width = 75
  169. Height = 25
  170. Caption = 'Test'
  171. TabOrder = 0
  172. OnClick = Button1Click
  173. end
  174. end
  175. object DBGrid1: TDBGrid
  176. Left = 0
  177. Top = 41
  178. Width = 560
  179. Height = 235
  180. Align = alClient
  181. DataSource = DataSource1
  182. TabOrder = 1
  183. TitleFont.Charset = DEFAULT_CHARSET
  184. TitleFont.Color = clWindowText
  185. TitleFont.Height = -11
  186. TitleFont.Name = 'Tahoma'
  187. TitleFont.Style = []
  188. end
  189. object ClientDataSet1: TClientDataSet
  190. Aggregates = <>
  191. IndexFieldNames = 'tt_emp_id;tt_fromdate'
  192. Params = <>
  193. ProviderName = 'DataSetProvider1'
  194. Left = 288
  195. Top = 8
  196. end
  197. object DataSetProvider1: TDataSetProvider
  198. DataSet = FDQuery1
  199. Left = 376
  200. Top = 8
  201. end
  202. object FDQuery1: TFDQuery
  203. Connection = FDConnection1
  204. SQL.Strings = (
  205. 'select ec.*'
  206. 'from tt_emp e, tt_emp_contract ec'
  207. 'where (coalesce(e.tt_nonactive,0)=0)'
  208. 'and e.tt_emp_id = ec.tt_emp_id')
  209. Left = 448
  210. Top = 8
  211. end
  212. object FDConnection1: TFDConnection
  213. Params.Strings = (
  214. 'DriverID=FB'
  215. 'Database=*****.GDB'
  216. 'Password=masterkey'
  217. 'User_Name=SYSDBA')
  218. LoginPrompt = False
  219. Left = 528
  220. Top = 8
  221. end
  222. object DataSource1: TDataSource
  223. DataSet = ClientDataSet1
  224. Left = 216
  225. Top = 8
  226. end
  227. end
  228.  
  229. TT_EMP_ID Integer
  230. TT_FROMDATE DateTime
  231. TT_TODATE DateTime
  232. TT_HOURS Float
  233. ... more
  234.  
  235. Index TT_I0_EMP_CONTRACT on TT_EMP_ID, TT_FROMDATE Primary, Unique
Add Comment
Please, Sign In to add comment