0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
1. unit Unit1;2. 3. interface4. 5. uses6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,7. Dialogs, ExtCtrls, StdCtrls, DB, DBClient, Grids, DBGrids, ComCtrls;8. 9. type10. TForm1 = class(TForm)11. Panel1: TPanel;12. Panel2: TPanel;13. Panel3: TPanel;14. DBGrid1: TDBGrid;15. cds: TClientDataSet;16. ds: TDataSource;17. Button1: TButton;18. Button2: TButton;19. Button3: TButton;20. Label1: TLabel;21. cxDateEdit1: TcxDateEdit;22. procedure Button1Click(Sender: TObject);23. procedure Button2Click(Sender: TObject);24. procedure Button3Click(Sender: TObject);25. private26. { Private declarations }27. public28. { Public declarations }29. end;30. 31. var32. Form1: TForm1;33. 34. implementation35. 36. {$R *.dfm}37. 38. function IMin(Val1, Val2: Integer): Integer;39. begin40. Result := Val1;41. if Val2 < Val1 then42. Result := Val2;43. end;44. 45. procedure AssignRecordx(Source, Dest: TDataSet; ByName: Boolean);46. 47. var48. I: Integer;49. F, FSrc: TField;50. begin51. 52. if ByName then53. begin54. for I := 0 to Source.FieldCount - 1 do55. begin56. F := Dest.FindField(Source.Fields[I].FieldName);57. if F <> nil then58. begin59. try60. F.Value := Source.Fields[I].Value;61. except62. end;63. end;64. end;65. end66. else67. begin68. for I := 0 to iMin(Source.FieldDefs.Count - 1, Dest.FieldDefs.Count - 1) do69. begin70. F := Dest.FindField(Dest.FieldDefs[I].Name);71. FSrc := Source.FindField(Source.FieldDefs[I].Name);72. if (F <> nil) and (FSrc <> nil) then73. begin74. try75. F.Value := FSrc.Value;76. except77. end;78. end;79. end;80. end;81. end;82. 83. procedure TForm1.Button1Click(Sender: TObject);84. begin85. cds.data := hosxp_getdataset('select o.hn,o.vstdate,o.vsttime,p.pname,p.fname,p.lname ' +86. ' from ovst o ' +87. ' left outer join patient p on p.hn = o.hn ' +88. ' where o.vstdate = "' + formatdatetime('yyyy-mm-dd', cxdateedit1.date) + '"');89. end;90. 91. procedure TForm1.Button2Click(Sender: TObject);92. var dbf1: tdbf;93. i: integer;94. nf: boolean;95. begin96. dbf1 := tdbf.create(nil);97. dbf1.close;98. dbf1.tablelevel := 4;99. dbf1.fielddefs.assign(cds.fielddefs);100. repeat101. nf := false;102. for i := 0 to (dbf1.fielddefs.count - 1) do103. begin104. if not nf then105. if (dbf1.fielddefs.items[i].datatype = ftTime) then106. begin107. dbf1.fielddefs.items[i].datatype := ftstring;108. dbf1.fielddefs.items[i].size := 8;109. nf := true;110. end;111. end;112. 113. until not nf;114. 115. dbf1.tablename := 'c:\dbase.dbf';116. dbf1.createtable;117. dbf1.open;118. cds.first;119. while not cds.eof do120. begin121. 122. 123. dbf1.append;124. assignrecordx(cds, dbf1, true);125. dbf1.post;126. cds.next;127. end;128. dbf1.close;129. dbf1.free;130. 131. showmessage('Done.');132. 133. 134. end;135. 136. procedure TForm1.Button3Click(Sender: TObject);137. begin138. fcds.data := cds.data;139. CreateDatasetReport('HOSxP Report');140. 141. end;142. 143. end.