unit U_SXPrice;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, DB, ADODB, VclTee.TeeGDIPlus, VCLTee.TeEngine,
  VCLTee.Series, VCLTee.TeeProcs, VCLTee.Chart, VCLTee.DBChart;

type
  TfrmSXPrice = class(TForm)
    Panel1: TPanel;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DBChart1: TDBChart;
    Series1: TFastLineSeries;
    ADOQueryBaseTemp: TADOQuery;
    ADOQueryBaseCmd: TADOQuery;
    procedure Button2Click(Sender: TObject);
    procedure initDbChart();
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    FY_Code, FYarn_Name: string;
    { Public declarations }
  end;

var
  frmSXPrice: TfrmSXPrice;

implementation

{$R *.dfm}

procedure TfrmSXPrice.Button2Click(Sender: TObject);
begin
  Close;
end;

procedure TfrmSXPrice.FormShow(Sender: TObject);
begin
  initDbChart();
end;

procedure TfrmSXPrice.initDbChart();
var
  i, j: integer;
begin
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select A.NewPrice,SJ= CONVERT(varchar(100), Filltime, 23)  from  Bs_Yarn_Info_Price A  where A.Y_Code=' + quotedstr(FY_Code));
    SQL.Add(' order by A.Filltime ');
//    ShowMessage(sql.text);
    Open;
  end;
  if ADOQueryTemp.isempty then
    exit;
//------------------------------------------
  //图表加载数据前清理数据
  with DbChart1 do
  begin
    j := SeriesCount;
    if j <= 0 then
      exit;
    for i := 0 to j - 1 do
    begin
      dbchart1.Series[i].Active := false;
      dbchart1.Series[i].DataSource := nil;
      dbchart1.Series[i].Clear;
      dbchart1.Series[i].XLabelsSource := '';
      dbchart1.Series[i].YValues.ValueSource := '';
    end;
  end;
  //加载图表
  if ADOQueryTemp.Active = false then
    exit;
  with DBChart1 do
  begin
    j := SeriesCount;
    if j <= 0 then
      exit;
    for i := 0 to j - 1 do
    begin        {清除series数据源}
      dbchart1.Series[i].Active := false;
      dbchart1.Series[i].DataSource := nil;
      dbchart1.Series[i].Clear;
      dbchart1.Series[i].XLabelsSource := '';
      dbchart1.Series[i].YValues.ValueSource := '';
    end;

    DBChart1.Title.Text.Text := FYarn_Name + '  价格走势图';
    Series[0].DataSource := ADOQueryTemp;
    Series[0].Active := true;
    Series[0].XLabelsSource := ADOQueryTemp.fieldbyname('SJ').FieldName;
    Series[0].YValues.ValueSource := ADOQueryTemp.fieldbyname('NewPrice').FieldName;
    Series[0].CheckDatasource;
  end;
end;

end.

