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

📄 udbchart.pas

📁 说明: 比较简单的人事档案管理程序,包含了人事档案的大部分功能,做人事档案的兄弟可以看看. 本程序类型:delphi7 + Access2000 桌面数据库 初始用户名/密码:admin
💻 PAS
字号:
//========================================================
//
//
//
//========================================================
unit UDbchart;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, TeEngine, Series, ExtCtrls, TeeProcs, Chart, DbChart,
  StdCtrls, Buttons, ExtDlgs, ComCtrls;

type
  TForm_DBChart = class(TForm)
    ADOQChart: TADOQuery;
    CountListBox: TListBox;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    modifetitle: TSpeedButton;
    SavePicture: TSpeedButton;
    SavePictureDialog1: TSavePictureDialog;
    Label3: TLabel;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    DBChart1: TDBChart;
    Series1: TPieSeries;
    DBChart2: TDBChart;
    Series2: TBarSeries;
    procedure DBChart1GetLegendText(Sender: TCustomAxisPanel;
      LegendStyle: TLegendStyle; Index: Integer; var LegendText: string);
    procedure CountListBoxClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure modifetitleClick(Sender: TObject);
    procedure SavePictureClick(Sender: TObject);
    procedure DBChart2GetLegendText(Sender: TCustomAxisPanel;
      LegendStyle: TLegendStyle; Index: Integer; var LegendText: String);
  private
    { Private declarations }
    SelectList: Integer; //当前选择的统计项,默认为0(第一项)
    sqlstring: string; // SQL查询语句
    colName: string; // 选中统计项的字段名称
    procedure LoadDBChart(var ColName: string; SqlString: string);
  public
    { Public declarations }
  end;

var
  Form_DBChart: TForm_DBChart;

implementation
uses Umain, Ueditform;
{$R *.dfm}

//========================================
//根据设置的条件进行图形显示
//========================================
procedure TForm_DBChart.LoadDBChart(var ColName: string; SqlString: string);
begin
  try
    with ADOQChart do
    begin
      close;
      SQL.Clear;
      sql.Add(SqlString);
      open;
    end;
  except
    showmessage('打开图型查询出错');
  end;
end;

//========================================
//设置饼状图DBCHART右边的标签显示
//========================================
procedure TForm_DBChart.DBChart1GetLegendText(Sender: TCustomAxisPanel;
  LegendStyle: TLegendStyle; Index: Integer; var LegendText: string);
var titlestring: string;
begin
  ADOQChart.First;
  ADOQChart.MoveBy(index);
  titlestring := LegendText;
  if ColName = 'JoinInYear' then
  begin
    LegendText := inttostr(ADOQChart.FieldValues['TJoinInYear']) + '年入本单位  ' + LegendText;
    exit;
  end;
  if ColName = 'JoinInMonth' then
  begin
    LegendText := inttostr(ADOQChart.FieldValues['TJoinInMonth']) + '月  ' + LegendText;
    exit;
  end;
  if ColName = 'WorkAge' then
  begin
    LegendText := inttostr(ADOQChart.FieldValues['TheWorkAge']) + '年出生  ' + LegendText;
    exit;
  end;
  LegendText := ADOQChart.FieldByName(ColName).AsString + '  ' + LegendText
end;

//========================================
//设置选择列表的响应事件
//========================================
procedure TForm_DBChart.CountListBoxClick(Sender: TObject);
begin
  SelectList := CountListBox.ItemIndex;
  case SelectList of
    0: begin //按部门统计
        SqlString := 'select Employee_FirstDept,count(Employee_FirstDept)  From Employee group by Employee_FirstDept';
        ColName := 'Employee_FirstDept';
        DBChart1.Title.Text.Clear;
        DBChart1.Title.Text.Add('部门职工数量对比图');
        DBChart2.Title.Text.Clear;
        DBChart2.Title.Text.Add('部门职工数量对比图');
      end;
    1: begin //按性别统计
        SqlString := 'select Employee_Sex,count(Employee_Sex)  From Employee group by Employee_Sex';
        ColName := 'Employee_Sex';
        DBChart1.Title.Text.Clear;
        DBChart1.Title.Text.Add('职工性别对比图');
        DBChart2.Title.Text.Clear;
        DBChart2.Title.Text.Add('职工性别对比图');
      end;
    2: begin //按民族统计
        SqlString := 'select Employee_Folk,count(Employee_Folk)  From Employee group by Employee_Folk';
        ColName := 'Employee_Folk';
        DBChart1.Title.Text.Clear;
        DBChart1.Title.Text.Add('职工民族对比图');
        DBChart2.Title.Text.Clear;
        DBChart2.Title.Text.Add('职工民族对比图');
      end;
    3: begin //按政治面貌统计
        SqlString := 'select Employee_Polity,count(Employee_Polity)  From Employee group by Employee_Polity';
        ColName := 'Employee_Polity';
        DBChart1.Title.Text.Clear;
        DBChart1.Title.Text.Add('职工政治面貌对比图');
        DBChart2.Title.Text.Clear;
        DBChart2.Title.Text.Add('职工政治面貌对比图');
      end;
    4: begin //按婚姻状况统计
        SqlString := 'select Employee_Marriage,count(Employee_Marriage)  From Employee group by Employee_Marriage';
        ColName := 'Employee_Marriage';
        DBChart1.Title.Text.Clear;
        DBChart1.Title.Text.Add('职工婚姻状况对比图');
        DBChart2.Title.Text.Clear;
        DBChart2.Title.Text.Add('职工婚姻状况对比图');
      end;
    5: begin //按教育程度统计
        SqlString := 'select Employee_Educate,count(Employee_Educate)  From Employee group by Employee_Educate';
        ColName := 'Employee_Educate';
        DBChart1.Title.Text.Clear;
        DBChart1.Title.Text.Add('职工教育程度对比图');
        DBChart2.Title.Text.Clear;
        DBChart2.Title.Text.Add('职工教育程度对比图');
      end;
    6: begin //按职工类型统计
        SqlString := 'select Employee_Type,count(Employee_Type)  From Employee group by Employee_Type';
        ColName := 'Employee_Type';
        DBChart1.Title.Text.Clear;
        DBChart1.Title.Text.Add('职工类型对比图');
        DBChart2.Title.Text.Clear;
        DBChart2.Title.Text.Add('职工类型对比图');
      end;
    7: begin //按职称统计
        SqlString := 'select Employee_Post,count(Employee_Post)  From Employee group by Employee_Post';
        ColName := 'Employee_Post';
        DBChart1.Title.Text.Clear;
        DBChart1.Title.Text.Add('职工职称对比图');
        DBChart2.Title.Text.Clear;
        DBChart2.Title.Text.Add('职工职称对比图');
      end;
    8: begin //按职务统计
        SqlString := 'select Employee_Duty,count(Employee_Duty)  From Employee group by Employee_Duty';
        ColName := 'Employee_Duty';
        DBChart1.Title.Text.Clear;
        DBChart1.Title.Text.Add('职工职务对比图');
        DBChart2.Title.Text.Clear;
        DBChart2.Title.Text.Add('职工职务对比图');
      end;
    9: begin //按工资类别统计
        SqlString := 'select Employee_PayType,count(Employee_PayType)  From Employee group by Employee_PayType';
        ColName := 'Employee_PayType';
        DBChart1.Title.Text.Clear;
        DBChart1.Title.Text.Add('职工工资类别对比图');
        DBChart2.Title.Text.Clear;
        DBChart2.Title.Text.Add('职工工资类别对比图');
      end;
    10: begin //按毕业院校统计
        SqlString := 'select Employee_School,count(Employee_School)  From Employee group by Employee_School';
        ColName := 'Employee_School';
        DBChart1.Title.Text.Clear;
        DBChart1.Title.Text.Add('职工毕业院校对比图');
        DBChart2.Title.Text.Clear;
        DBChart2.Title.Text.Add('职工毕业院校对比图');
      end;
    11: begin //按年度新增员工统计
        SqlString := 'select year(Employee_JoinDate) as TJoinInYear,count(year(Employee_JoinDate))  From Employee group by year(Employee_JoinDate)';
        ColName := 'JoinInYear';
        DBChart1.Title.Text.Clear;
        DBChart1.Title.Text.Add('年度新增职工对比图');
        DBChart2.Title.Text.Clear;
        DBChart2.Title.Text.Add('年度新增职工对比图');
      end;
    12: begin //按月度新增员工统计
        SqlString := 'select month(Employee_JoinDate)as TJoinInMonth,count(month(Employee_JoinDate))  From Employee group by month(Employee_JoinDate)';
        ColName := 'JoinInMonth';
        DBChart1.Title.Text.Clear;
        DBChart1.Title.Text.Add('月度新增员工对比图');
        DBChart2.Title.Text.Clear;
        DBChart2.Title.Text.Add('月度新增员工对比图');
      end;
    13: begin //按职工年龄统计
        SqlString := 'select year(Employee_Birthday) as TheWorkAge,count(year(now())-year(Employee_Birthday))   From Employee group by year(Employee_Birthday)';
        ColName := 'WorkAge';
        DBChart1.Title.Text.Clear;
        DBChart1.Title.Text.Add('职工年龄对比图');
        DBChart2.Title.Text.Clear;
        DBChart2.Title.Text.Add('职工年龄对比图');
      end;
  end;
  LoadDBChart(ColName, SqlString); //重新载入DBCHART
end;

//================================
// 在显示窗口时初始化窗口控件
//================================
procedure TForm_DBChart.FormShow(Sender: TObject);
begin
  try
    with ADOQChart do
    begin
      SQL.Clear;
      SQL.Add('select Employee_FirstDept,count(Employee_FirstDept)  From Employee group by Employee_FirstDept');
      open;
    end;
  except
    beep;
    Showmessage('打开职工表失败,请检查数据库文件是否存在');
    CLose;
  end;
  ColName := 'Employee_FirstDept';
  CountListBox.ItemHeight := 20;
  CountListBoxClick(Sender);
end;

//========================================
//设置柱状图DBCHART右边的标签显示
//========================================
procedure TForm_DBChart.modifetitleClick(Sender: TObject);
begin
  Form_Edit := TForm_Edit.Create(self);
  Form_Edit.Edit1.Text := DBChart1.Title.Text.Text;
  Form_Edit.ShowModal;
  DBChart1.Title.Text.Clear;
  DBChart1.Title.Text.Add(Form_Edit.Edit1.Text);
  DBChart2.Title.Text.Clear;
  DBChart2.Title.Text.Add(Form_Edit.Edit1.Text);
  Form_Edit.Free;
end;

//========================================
//保存图象为图片
//========================================
procedure TForm_DBChart.SavePictureClick(Sender: TObject);
begin
//showmessage(DBChart1.Title.Text.Text);
   //SavePictureDialog1.FileName:=DBChart1.Title.Text.Text;
  if SavePictureDialog1.Execute then
  begin
    if PageControl1.ActivePageIndex = 0 then
      DBChart1.SaveToBitmapFile(SavePictureDialog1.FileName)
    else
      DBChart2.SaveToBitmapFile(SavePictureDialog1.FileName);
  end;

end;

//========================================
//设置DBCHART右边的标签显示
//========================================
procedure TForm_DBChart.DBChart2GetLegendText(Sender: TCustomAxisPanel;
  LegendStyle: TLegendStyle; Index: Integer; var LegendText: String);
begin
  ADOQChart.First;
  ADOQChart.MoveBy(index);
  if ColName = 'JoinInYear' then
  begin
    LegendText := inttostr(ADOQChart.FieldValues['TJoinInYear']) + '年入本单位  ' + LegendText;
    exit;
  end;
  if ColName = 'JoinInMonth' then
  begin
    LegendText := inttostr(ADOQChart.FieldValues['TJoinInMonth']) + '月  ' + LegendText;
    exit;
  end;
  if ColName = 'WorkAge' then
  begin
    LegendText := inttostr(ADOQChart.FieldValues['TheWorkAge']) + '年出生  ' + LegendText;
    exit;
  end;
  LegendText := ADOQChart.FieldByName(ColName).AsString + '  ' + LegendText
end;

end.

⌨️ 快捷键说明

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