home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / OTHER / MONTHLY / BYMONTH.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  3.6 KB  |  132 lines

  1. unit bymonth;
  2.  
  3. interface
  4.  
  5. { This unit shows an example of use of the TEEMONTH.PAS unit.
  6.  
  7.   It performs a "GROUP BY MONTH" or "GROUP BY WEEK" query against
  8.   the DBDEMOS ORDERS.DB example table.
  9.  
  10.   (note: the "Year" combobox in this demo is not available in Delphi 1.0 16bit)
  11. }
  12. uses
  13.   WinTypes,WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  14.   StdCtrls, Buttons, TeEngine, Series, ExtCtrls, TeeProcs, Chart, Grids,
  15.   DBGrids, Db, DBTables;
  16.  
  17. type
  18.   TFormMonthly = class(TForm)
  19.     DataSource1: TDataSource;
  20.     Table1: TTable;
  21.     Chart1: TChart;
  22.     Series1: TBarSeries;
  23.     Panel1: TPanel;
  24.     RadioGroup2: TRadioGroup;
  25.     RadioGroup1: TRadioGroup;
  26.     ComboBox1: TComboBox;
  27.     Label1: TLabel;
  28.     Button1: TButton;
  29.     CheckBox1: TCheckBox;
  30.     LabelRemind: TLabel;
  31.     procedure RadioGroup1Click(Sender: TObject);
  32.     procedure RadioGroup2Click(Sender: TObject);
  33.     procedure CheckBox1Click(Sender: TObject);
  34.     procedure Button1Click(Sender: TObject);
  35.     procedure ComboBox1Change(Sender: TObject);
  36.     procedure FormCreate(Sender: TObject);
  37.   private
  38.     { Private declarations }
  39.   public
  40.     { Public declarations }
  41.     procedure Refresh;
  42.   end;
  43.  
  44. var
  45.   FormMonthly: TFormMonthly;
  46.  
  47. implementation
  48.  
  49. {$R *.DFM}
  50.  
  51. Uses EditChar,   { <-- necessary to edit the chart }
  52.      TeeMonth;   { <-- necessary to do the calculation }
  53.  
  54. procedure TFormMonthly.Refresh;
  55. Var DatePeriod:TDateTimeStep;
  56.     YearSt:String;
  57. begin
  58.   {$IFDEF WIN32}
  59.   { only for Delphi 2 and 3... }
  60.   { Set a YEAR filter on the table for this example... }
  61.   if ComboBox1.ItemIndex=0 then Table1.Filtered:=False
  62.   else
  63.   begin
  64.     YearSt:=ComboBox1.Text;
  65.     Table1.Filter:='SaleDate>'+#39+'1/1/'+YearSt+#39+' and SaleDate<='+#39+'31/12/'+YearSt+#39;
  66.     Table1.Filtered:=True;
  67.   end;
  68.   {$ENDIF}
  69.  
  70.   { choose a period (Month or Week) }
  71.   if RadioGroup2.ItemIndex=0 then DatePeriod:=dtOneMonth
  72.                              else DatePeriod:=dtOneWeek;
  73.  
  74.   { HERE IS THE IMPORTANT THING: Call the routine !!! }
  75.   DBMonthlySeries( Series1,                   { <-- the destination Series }
  76.                    Table1,                    { <-- the origin Table (or Query) }
  77.                    'SaleDate',                { <-- the DATE field }
  78.                    'AmountPaid',              { <-- the CHART field }
  79.                    DatePeriod,                { <-- it can be dtOneMonth or dtOneWeek }
  80.                    RadioGroup1.ItemIndex=0);  { <-- choose Sum or Count }
  81.  
  82.  
  83.   { To make this demo nicer, set the Chart Titles accordingly.... }
  84.   if DatePeriod=dtOneMonth then
  85.      Chart1.BottomAxis.Title.Caption:='Sale Date Month'
  86.   else
  87.      Chart1.BottomAxis.Title.Caption:='Sale Date Week';
  88.   if RadioGroup1.ItemIndex=0 then
  89.      Chart1.LeftAxis.Title.Caption:='Count of Orders'
  90.   else
  91.      Chart1.LeftAxis.Title.Caption:='Sum of Amount Paid';
  92. end;
  93.  
  94. procedure TFormMonthly.RadioGroup1Click(Sender: TObject);
  95. begin
  96.   Refresh;
  97. end;
  98.  
  99. procedure TFormMonthly.RadioGroup2Click(Sender: TObject);
  100. begin
  101.   Refresh;
  102. end;
  103.  
  104. procedure TFormMonthly.CheckBox1Click(Sender: TObject);
  105. begin
  106.   Series1.Marks.Visible:=CheckBox1.Checked;
  107. end;
  108.  
  109. procedure TFormMonthly.Button1Click(Sender: TObject);
  110. begin
  111.   EditChart(Self,Chart1);
  112. end;
  113.  
  114. procedure TFormMonthly.ComboBox1Change(Sender: TObject);
  115. begin
  116.   Refresh;
  117. end;
  118.  
  119. procedure TFormMonthly.FormCreate(Sender: TObject);
  120. begin
  121.   {$IFNDEF WIN32}
  122.   ComboBox1.Enabled:=False;
  123.   LabelRemind.Visible:=True;
  124.   {$ELSE}
  125.   LabelRemind.Visible:=False;
  126.   {$ENDIF}
  127.   ComboBox1.ItemIndex:=4;
  128.   Refresh;
  129. end;
  130.  
  131. end.
  132.