⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tc_main.pas

📁 亚惠快餐管理信息系统 包括亚惠快餐管理的各项功能
💻 PAS
字号:
unit TC_Main;
{$P-} { <-- Delphi 1.0 compatibility }

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, ExtCtrls, TeeProcs, TeEngine, Chart, StdCtrls, Series,
  TeeShape, GanttCh, BubbleCh, ArrowCha, Buttons, ComCtrls, ToolWin,
  ImgList, DB, ADODB, DBTables, DbChart, ExtDlgs;

type

  TFrmTC_Main = class(TForm)
    Notebook1: TNotebook;
    Panel3: TPanel;
    Timer1: TTimer;
    Label4: TLabel;
    Label5: TLabel;
    ScrollBar3: TScrollBar;
    Label8: TLabel;
    CoolBar1: TCoolBar;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    ToolButton9: TToolButton;
    ToolButton10: TToolButton;
    ImageList1: TImageList;
    StatusBar1: TStatusBar;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Label2: TLabel;
    ScrollBar1: TScrollBar;
    Label3: TLabel;
    CheckBox2: TCheckBox;
    GroupBox3: TGroupBox;
    CheckBox1: TCheckBox;
    Label6: TLabel;
    ScrollBar2: TScrollBar;
    Label7: TLabel;
    Panel1: TPanel;
    ToolButton11: TToolButton;
    Splitter1: TSplitter;
    DBChart2: TDBChart;
    Series5: TBarSeries;
    DBChart4: TDBChart;
    Series11: TAreaSeries;
    Series12: TAreaSeries;
    Series34: TAreaSeries;
    Series35: TAreaSeries;
    DBChart5: TDBChart;
    Series13: TPointSeries;
    Series14: TPointSeries;
    Series15: TPointSeries;
    Series16: TPointSeries;
    DBChart6: TDBChart;
    Series17: TPieSeries;
    Series18: TPieSeries;
    Series19: TPieSeries;
    Series36: TPieSeries;
    DBChart7: TDBChart;
    Series20: TFastLineSeries;
    Series21: TFastLineSeries;
    Series22: TFastLineSeries;
    Series23: TFastLineSeries;
    DBChart11: TDBChart;
    Series37: TArrowSeries;
    Series38: TArrowSeries;
    Series39: TArrowSeries;
    Series40: TArrowSeries;
    Series6: TBarSeries;
    Series7: TBarSeries;
    Series8: TBarSeries;
    DBChart1: TDBChart;
    ComboBox1: TComboBox;
    Series1: TLineSeries;
    Series2: TLineSeries;
    Series3: TLineSeries;
    Series4: TLineSeries;
    Label1: TLabel;
    ComboBox3: TComboBox;
    ToolButton14: TToolButton;
    GroupBox8: TGroupBox;
    GroupBox4: TGroupBox;
    Label9: TLabel;
    Label10: TLabel;
    X_ComboBox2: TComboBox;
    Y_ComboBox4: TComboBox;
    GroupBox5: TGroupBox;
    Label11: TLabel;
    Label12: TLabel;
    X_ComboBox5: TComboBox;
    Y_ComboBox6: TComboBox;
    GroupBox6: TGroupBox;
    Label13: TLabel;
    Label14: TLabel;
    X_ComboBox7: TComboBox;
    Y_ComboBox8: TComboBox;
    GroupBox7: TGroupBox;
    Label15: TLabel;
    Label16: TLabel;
    X_ComboBox9: TComboBox;
    Y_ComboBox10: TComboBox;
    ToolButton16: TToolButton;
    Panel2: TPanel;
    ADOQuery1: TADOQuery;
    ToolButton12: TToolButton;
    SavePictureDialog1: TSavePictureDialog;
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure ScrollBar1Change(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure ScrollBar2Change(Sender: TObject);
    procedure Series28GetMarkText(Sender: TChartSeries;
      ValueIndex: Integer; var MarkText: string);
    procedure ScrollBar3Change(Sender: TObject);
    procedure ToolButton10Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ComboBox1Change(Sender: TObject);
    procedure ComboBox3Change(Sender: TObject);
    procedure X_ComboBox2Change(Sender: TObject);
    procedure ToolButton14Click(Sender: TObject);
    procedure ToolButton16Click(Sender: TObject);
    procedure ToolButton12Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    tmpSeries,
      tmpIndex,
      tmpRandom,
      tmpTimes: Longint;
    SqlStrings: TStrings;
    ChartName: string;
    Maximum: Double;
    FirstTime: Boolean;
    function TheChart: TDBChart;
    procedure HorizScroll(const Percent: Double);
    procedure VertScroll(const Percent: Double);
    procedure ScrollAxis(Axis: TChartAxis; const Percent: Double);
    function OpenDataSource: Boolean;
    constructor ACreate(ASqlStrings: TStrings);
  end;

procedure SetWork(ASqlStrings: TStrings);

implementation

uses PublicUnit;

{$R *.dfm}

procedure SetWork(ASqlStrings: TStrings);
var
  FrmTC_Main: TFrmTC_Main;
begin
  FrmTC_Main := TFrmTC_Main.ACreate(ASQLStrings);
  FrmTC_Main.Show;
end;

{-------------------------------------------------------------------------------}

constructor TFrmTC_Main.ACreate(ASqlStrings: TStrings);
var
  i: integer;
begin
  inherited Create(Application);
  tmpTimes := -1;
  ScrollBar1.Position := Timer1.Interval;
  SqlStrings := TStringList.Create;
  SqlStrings.Assign(ASqlStrings);
  for i := SqlStrings.Count - 1 downto 0 do
    if Trim(SqlStrings[i]) = '' then
      SqlStrings.Delete(i);
  ChartName := '统计分析图形显示';
  if not OpenDataSource then
    Exit;
  ComboBox3.ItemIndex := 0;
  ComboBox3Change(Application);
  X_ComboBox2.ItemIndex := 0;
  Y_ComboBox4.ItemIndex := 0;
  X_ComboBox5.ItemIndex := 0;
  Y_ComboBox6.ItemIndex := 0;
  X_ComboBox7.ItemIndex := 0;
  Y_ComboBox8.ItemIndex := 0;
  X_ComboBox9.ItemIndex := 0;
  Y_ComboBox10.ItemIndex := 0;
  FirstTime := True;
  Maximum := 10000000000;
end;

procedure TFrmTC_Main.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  SqlStrings.Free;
  Action := caFree;
end;

{--------------------------------------------------------------------------------}

//选择图形样式

procedure TFrmTC_Main.ComboBox3Change(Sender: TObject);
var
  i: integer;
begin
  NoteBook1.PageIndex := ComboBox3.ItemIndex;
  with TheChart do
  begin
    tmpTimes := -1;
    AnimatedZoom := True;
    AnimatedZoomSteps := 4;
    Title.Text.Text := ChartName;
    for i := 0 to SeriesCount - 1 do
    begin
      with Series[i] do
      begin
        DataSource := ADOQuery1;
        Marks.Visible := True;
        case i of
          0:
            begin
              X_ComboBox2.OnChange(X_ComboBox2);
              Y_ComboBox4.OnChange(Y_ComboBox4);
            end;
          1:
            begin
              X_ComboBox5.OnChange(X_ComboBox5);
              Y_ComboBox6.OnChange(Y_ComboBox6);
            end;
          2:
            begin
              X_ComboBox7.OnChange(X_ComboBox7);
              Y_ComboBox8.OnChange(Y_ComboBox8);
            end;
          3:
            begin
              X_ComboBox9.OnChange(X_ComboBox9);
              Y_ComboBox10.OnChange(Y_ComboBox10);
            end;
        end;
      end;
    end;
    UndoZoom;
    CheckBox1.Checked := View3D;
    ScrollBar2.Enabled := View3D;
    ScrollBar2.Position := Chart3DPercent;
    if Series[0] is TPieSeries then
      ScrollBar3.Position := View3DOptions.Elevation
    else
      ScrollBar3.Position := View3DOptions.Rotation;
    ScrollBar3.Enabled := View3D;
  end;
  ComboBox1.ItemIndex := 1;
end;

//选择显示方式

procedure TFrmTC_Main.ComboBox1Change(Sender: TObject);
var
  i: integer;
begin
  with TheChart do
  begin
    for i := 0 to SeriesCount - 1 do
      with Series[i] do
      begin
        Marks.Visible := True;
        case ComboBox1.ItemIndex of
          0: Marks.Visible := False;
          1: Marks.Style := smsValue;
          2: Marks.Style := smsLabel;
          3: Marks.Style := smsPercent;
        end;
      end;
  end;
end;

//选择坐标

procedure TFrmTC_Main.X_ComboBox2Change(Sender: TObject);
var
  s: string;
begin
  s := TComboBox(Sender).Text;
  if s = '无' then
    s := '';
  with TheChart do
    with Series[TComboBox(Sender).Tag] do
    begin
      if Pos('Y_', TComboBox(Sender).Name) <> 0 then
      begin
        Title := s;
        YValues.ValueSource := s; { <-- the Field for Bar Values }
      end
      else
        XLabelsSource := s;
    end;
  ComboBox1.OnChange(Sender);
end;

//三维显示选择

procedure TFrmTC_Main.CheckBox1Click(Sender: TObject);
begin
  TheChart.View3D := CheckBox1.Checked;
  ScrollBar2.Enabled := TheChart.View3D;
  ScrollBar3.Enabled := TheChart.View3D;
end;

//动画显示选择

procedure TFrmTC_Main.CheckBox2Click(Sender: TObject);
begin
  FirstTime := True;
  Timer1.Enabled := CheckBox2.Checked;
  ScrollBar1.Enabled := Timer1.Enabled;
end;

//动画显示速度选择

procedure TFrmTC_Main.ScrollBar1Change(Sender: TObject);
begin
  Timer1.Interval := ScrollBar1.Position;
end;

//三维显示效果选择

procedure TFrmTC_Main.ScrollBar2Change(Sender: TObject);
begin
  TheChart.Chart3DPercent := ScrollBar2.Position;
end;

//旋转角度选择

procedure TFrmTC_Main.ScrollBar3Change(Sender: TObject);
begin
  if ScrollBar3.Enabled then
    with TheChart.View3DOptions do
    begin
      Orthogonal := False;
      if TheChart[0] is TPieSeries then
        Elevation := ScrollBar3.Position
      else
        Rotation := ScrollBar3.Position;
    end;
end;

//动画显示

procedure TFrmTC_Main.Timer1Timer(Sender: TObject);
begin
  case NoteBook1.PageIndex of
    0, 1, 2, 3, 5, 6: HorizScroll(1);
    4: (TheChart[0] as TPieSeries).Rotate(358);
  end;
end;

//关闭按钮

procedure TFrmTC_Main.ToolButton10Click(Sender: TObject);
begin
  Close;
end;

//右移按钮

procedure TFrmTC_Main.ToolButton8Click(Sender: TObject);
begin
  HorizScroll(-1);
end;

//下移按钮

procedure TFrmTC_Main.ToolButton7Click(Sender: TObject);
begin
  VertScroll(1);
end;

//上移按钮

procedure TFrmTC_Main.ToolButton6Click(Sender: TObject);
begin
  VertScroll(-1);
end;

//左移按钮

procedure TFrmTC_Main.ToolButton5Click(Sender: TObject);
begin
  HorizScroll(1);
end;

//还原按钮

procedure TFrmTC_Main.ToolButton3Click(Sender: TObject);
begin
  TheChart.UndoZoom;
end;

//放大按钮

procedure TFrmTC_Main.ToolButton2Click(Sender: TObject);
begin
  TheChart.ZoomPercent(80);
end;

//缩小按钮

procedure TFrmTC_Main.ToolButton1Click(Sender: TObject);
begin
  TheChart.ZoomPercent(120);
end;

//标题设置按钮

procedure TFrmTC_Main.ToolButton14Click(Sender: TObject);
var
  s: string;
begin
  s := ChartName;
  if not InputQuery('图表配置', '请输入图表名称:', s) then
    Exit;
  ChartName := s;
  TheChart.Title.Text.Text := ChartName;
end;

//打印

procedure TFrmTC_Main.ToolButton16Click(Sender: TObject);
begin
  TheChart.Print;
end;

procedure TFrmTC_Main.ToolButton12Click(Sender: TObject);
var
  FileName: string;
begin
  if not SavePictureDialog1.Execute then
    Exit;
  FileName := SavePictureDialog1.FileName;
  try
    TheChart.SaveToBitmapFile(FileName);
    MessageDlg('当前图形被保存至文件《' + FileName + '》中!', mtInformation,
      [mbOk], 0);
  except
    MessageDlg('未能成功保存,请重试!', mtInformation, [mbOk], 0);
  end;
end;

{-------------------------------------------------------------------------------}

procedure TFrmTC_Main.VertScroll(const Percent: Double);
begin
  ScrollAxis(TheChart.LeftAxis, Percent);
  ScrollAxis(TheChart.RightAxis, Percent);
end;

procedure TFrmTC_Main.HorizScroll(const Percent: Double);
begin
  if ABS(Maximum - TheChart.BottomAxis.Minimum) <= 10 then
  begin
    TheChart.BottomAxis.Minimum := 0;
    TheChart.BottomAxis.Maximum := Maximum;
  end;
  ScrollAxis(TheChart.TopAxis, Percent);
  ScrollAxis(TheChart.BottomAxis, Percent);
  if FirstTime then
  begin
    Maximum := TheChart.BottomAxis.Maximum;
    FirstTime := False;
  end;
end;

procedure TFrmTC_Main.ScrollAxis(Axis: TChartAxis; const Percent: Double);
var
  Amount: Double;
begin
  with Axis do
  begin
    Amount := -((Maximum - Minimum) / (100.0 / Percent));
    SetMinMax(Minimum - Amount, Maximum - Amount);
  end;
end;

function TFrmTC_Main.TheChart: TDBChart;
begin
  with NoteBook1 do
    result := (Pages.Objects[PageIndex] as TPage).Controls[0] as TDBChart;
end;

procedure TFrmTC_Main.Series28GetMarkText(Sender: TChartSeries;
  ValueIndex: Integer; var MarkText: string);
begin
  if ValueIndex = 3 then
    MarkText := 'USA'
  else if ValueIndex = 5 then
    MarkText := 'UK'
  else if ValueIndex = 7 then
    MarkText := 'Germany'
  else
    MarkText := '';
end;

function TFrmTC_Main.OpenDataSource: Boolean;
var
  i: integer;
begin
  Result := False;
  with ADOQuery1 do
  begin
    Close;
    ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID='
      + PublicUnit.DbUser + ';Password=' + PublicUnit.DbPass +
      ';Initial Catalog='
      + PublicUnit.DbName + ';Data Source=' + PublicUnit.ServerName;
    Sql.Clear;
    Sql.Assign(SqlStrings);
    if not ExecuteSQLStatement(ADOQuery1) then
    begin
      ShowMessage('无法打开统计分析结果,系统不能正常工作!');
      Exit;
    end;
    X_ComboBox2.Items.Clear;
    X_ComboBox2.Items.Add('无');
    Y_ComboBox4.Items.Add('无');
    for i := 0 to FieldCount - 1 do
    begin
      X_ComboBox2.Items.Add(Fields[i].FieldName);
      case Fields[i].DataType of
        ftSmallint, ftInteger, ftWord, ftFloat, ftCurrency, ftBCD, ftBytes,
          ftVarBytes, ftAutoInc, ftLargeint:
          Y_ComboBox4.Items.Add(Fields[i].FieldName);
      end;
    end;
    X_ComboBox5.Items.Assign(X_ComboBox2.Items);
    Y_ComboBox6.Items.Assign(Y_ComboBox4.Items);
    X_ComboBox7.Items.Assign(X_ComboBox2.Items);
    Y_ComboBox8.Items.Assign(Y_ComboBox4.Items);
    X_ComboBox9.Items.Assign(X_ComboBox2.Items);
    Y_ComboBox10.Items.Assign(Y_ComboBox4.Items);
  end;
  Result := True;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -