home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 March / Chip_1999-03_cd.bin / zkuste / delphi / INFO / DI9901CJ.ZIP / EDITDEMU.PAS < prev   
Pascal/Delphi Source File  |  1998-10-23  |  4KB  |  169 lines

  1. unit editdemu;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ExtCtrls, Grids, DBGrids, DBCtrls, Db, DBTables;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Table1: TTable;
  12.     DBNavigator1: TDBNavigator;
  13.     DBGrid1: TDBGrid;
  14.     Panel1: TPanel;
  15.     Button1: TButton;
  16.     Button2: TButton;
  17.     Button3: TButton;
  18.     Button4: TButton;
  19.     DataSource1: TDataSource;
  20.     LabelStart1: TLabel;
  21.     LabelEnd1: TLabel;
  22.     LabelStart2: TLabel;
  23.     LabelEnd2: TLabel;
  24.     LabelTotal1: TLabel;
  25.     LabelTotal2: TLabel;
  26.     LabelStart3: TLabel;
  27.     LabelEnd3: TLabel;
  28.     LabelTotal3: TLabel;
  29.     LabelStart4: TLabel;
  30.     LabelEnd4: TLabel;
  31.     LabelTotal4: TLabel;
  32.     Table1OrderNo: TFloatField;
  33.     Table1CustNo: TFloatField;
  34.     Table1SaleDate: TDateTimeField;
  35.     Table1ShipDate: TDateTimeField;
  36.     Table1EmpNo: TIntegerField;
  37.     Table1ShipToContact: TStringField;
  38.     Table1ShipToAddr1: TStringField;
  39.     Table1ShipToAddr2: TStringField;
  40.     Table1ShipToCity: TStringField;
  41.     Table1ShipToState: TStringField;
  42.     Table1ShipToZip: TStringField;
  43.     Table1ShipToCountry: TStringField;
  44.     Table1ShipToPhone: TStringField;
  45.     Table1ShipVIA: TStringField;
  46.     Table1PO: TStringField;
  47.     Table1Terms: TStringField;
  48.     Table1PaymentMethod: TStringField;
  49.     Table1ItemsTotal: TCurrencyField;
  50.     Table1TaxRate: TFloatField;
  51.     Table1Freight: TCurrencyField;
  52.     Table1AmountPaid: TCurrencyField;
  53.     procedure Button1Click(Sender: TObject);
  54.     procedure Button2Click(Sender: TObject);
  55.     procedure Button3Click(Sender: TObject);
  56.     procedure Button4Click(Sender: TObject);
  57.   private
  58.     { Private declarations }
  59.   public
  60.     { Public declarations }
  61.   end;
  62.  
  63. var
  64.   Form1: TForm1;
  65.  
  66. implementation
  67.  
  68. {$R *.DFM}
  69.  
  70. procedure TForm1.Button1Click(Sender: TObject);
  71. begin
  72. Button1.Enabled := False;
  73. LabelStart1.Caption := IntToStr(GetTickCount);
  74. Table1.First;
  75. while not Table1.EOF do
  76. begin
  77.   Table1.Next;
  78. end;
  79. LabelEnd1.Caption := IntToStr(GetTickCount);
  80. LabelTotal1.Caption := 'Milliseconds: '+ IntToStr(StrToInt(LabelEnd1.Caption) - StrToInt(LabelStart1.Caption));
  81. Button1.Enabled := True;
  82. end;
  83.  
  84. procedure TForm1.Button2Click(Sender: TObject);
  85. begin
  86. Button2.Enabled := False;
  87. LabelStart2.Caption := IntToStr(GetTickCount);
  88. Table1.DisableControls;
  89. try
  90.   Table1.First;
  91.   while not Table1.EOF do
  92.   begin
  93.     Table1.Next;
  94.   end;
  95.   LabelEnd2.Caption := IntToStr(GetTickCount);
  96.   LabelTotal2.Caption := 'Milliseconds: '+ IntToStr(StrToInt(LabelEnd2.Caption) - StrToInt(LabelStart2.Caption));
  97. finally
  98.   Table1.EnableControls;
  99.   Button2.Enabled := True;
  100. end;
  101. end;
  102.  
  103. procedure TForm1.Button3Click(Sender: TObject);
  104. var
  105.   SumofSales: Currency;
  106. begin
  107. SumOfSales := 0;
  108. Button3.Enabled := False;
  109. LabelStart3.Caption := IntToStr(GetTickCount);
  110. Table1.DisableControls;
  111. try
  112.   Table1.First;
  113.   while not Table1.EOF do
  114.   begin
  115.     SumOfSales := SumOfSales + Table1.FieldByName('ItemsTotal').AsCurrency;
  116.     Table1.Next;
  117.   end;
  118.   LabelEnd3.Caption := IntToStr(GetTickCount);
  119.   LabelTotal3.Caption := 'Milliseconds: '+ IntToStr(StrToInt(LabelEnd3.Caption) - StrToInt(LabelStart3.Caption));
  120. finally
  121.   Table1.EnableControls;
  122.   Button3.Enabled := True;
  123.   ShowMessage(FormatCurr('$ #,###.##',SumOfSales));
  124. end;
  125. end;
  126.  
  127. procedure TForm1.Button4Click(Sender: TObject);
  128. var
  129.   Undo: Boolean;
  130. begin
  131. Table1.First;
  132. if Table1.FieldByName('ShipToState').AsString = '' then
  133.   Undo := False
  134. else
  135.   Undo := True;
  136. Button4.Enabled := False;
  137. LabelStart4.Caption := IntToStr(GetTickCount);
  138. Table1.DisableControls;
  139. try
  140.   Table1.First;
  141.   while not Table1.EOF do
  142.   begin
  143.     try
  144.       Table1.Edit;
  145.       if Undo then
  146.         Table1.FieldByName('ShipToState').Value := ''
  147.       else
  148.         Table1.FieldByName('ShipToState').Value :=
  149.           Table1.FieldByName('PaymentMethod').Value +
  150.             ' ' + Table1.FieldByName('OrderNo').AsString;
  151.       Table1.Post;
  152.       Table1.Next;
  153.     except
  154.       //Handle a failure to edit or post here.
  155.       //In this example, ignore records that
  156.       //cannot be edited or posted.
  157.     end; //try-except
  158.   end; //begin
  159.   LabelEnd4.Caption := IntToStr(GetTickCount);
  160.   LabelTotal4.Caption := 'Milliseconds: '+
  161.     IntToStr(StrToInt(LabelEnd4.Caption) - StrToInt(LabelStart4.Caption));
  162. finally
  163.   Table1.EnableControls;
  164.   Button4.Enabled := True;
  165. end; //try-finally
  166. end;
  167.  
  168. end.
  169.