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

📄 frm_dbgrideh_print_set.pas

📁 一个地方税务征收管理系统
💻 PAS
字号:
unit frm_dbgrideh_print_set;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, inifiles, StdCtrls, PrnDbgeh, Buttons, ComCtrls, Grids, DBGridEh,
  ImgList, FileCtrl;

type
  Tdbgrideh_print = class(TForm)
    PrintDBGridEh1: TPrintDBGridEh;
    FontDialog1: TFontDialog;
    SaveDialog1: TSaveDialog;
    OpenDialog1: TOpenDialog;
    FileListBox1: TFileListBox;
    BitBtn2: TBitBtn;
    BitBtn6: TBitBtn;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    SpeedButton1: TSpeedButton;
    GroupBox1: TGroupBox;
    L_TITLE_LEFT: TLabel;
    SpeedButton4: TSpeedButton;
    GroupBox2: TGroupBox;
    L_TITLE_CENTER: TLabel;
    SpeedButton2: TSpeedButton;
    GroupBox3: TGroupBox;
    L_TITLE_RIGHT: TLabel;
    SpeedButton5: TSpeedButton;
    TabSheet2: TTabSheet;
    SpeedButton8: TSpeedButton;
    GroupBox4: TGroupBox;
    L_FOOTS_LEFT: TLabel;
    SpeedButton3: TSpeedButton;
    GroupBox5: TGroupBox;
    L_FOOTS_CENTER: TLabel;
    SpeedButton6: TSpeedButton;
    GroupBox6: TGroupBox;
    L_FOOTS_RIGHT: TLabel;
    SpeedButton7: TSpeedButton;
    TabSheet3: TTabSheet;
    GroupBox7: TGroupBox;
    L_GRIDE_BEFOR: TLabel;
    SpeedButton9: TSpeedButton;
    TabSheet6: TTabSheet;
    GroupBox9: TGroupBox;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label15: TLabel;
    Label14: TLabel;
    Label16: TLabel;
    E_LEFT: TEdit;
    E_RIGHT: TEdit;
    E_TOP: TEdit;
    E_BOTTOM: TEdit;
    GroupBox10: TGroupBox;
    c_usecolor: TCheckBox;
    SpeedButton12: TSpeedButton;
    Label17: TLabel;
    SpeedButton11: TSpeedButton;
    SpeedButton14: TSpeedButton;
    C_PROJECT: TComboBox;
    c_font: TCheckBox;
    GroupBox8: TGroupBox;
    l_grid_after: TLabel;
    SpeedButton10: TSpeedButton;
    procedure SpeedButton1Click(Sender: TObject);
    function Edit_string(mstr: string): string;
    procedure SpeedButton8Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton9Click(Sender: TObject);
    procedure SpeedButton10Click(Sender: TObject);
    procedure SpeedButton11Click(Sender: TObject);
    procedure SpeedButton15Click(Sender: TObject);
    procedure SpeedButton14Click(Sender: TObject);
    procedure SpeedButton16Click(Sender: TObject);

    procedure L_writetoIni(mlabel: TLabel);
    procedure E_writetoIni(medit: Tedit);
    procedure c_writeToini(mcheckbox: TCheckBox);

    procedure L_readFromIni(mlabel: TLabel);
    procedure e_readFromIni(medit: TEdit);
    procedure c_readFromini(Mcheckbox: TCheckBox);
    procedure BitBtn5Click(Sender: TObject);

    procedure APP_change;
    procedure BitBtn4Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure SpeedButton6Click(Sender: TObject);
    procedure SpeedButton7Click(Sender: TObject);
    procedure SpeedButton12Click(Sender: TObject);
    procedure SpeedButton13Click(Sender: TObject);
    procedure C_PROJECTClick(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);

    procedure load_project;
    procedure FormCreate(Sender: TObject);
    procedure C_PROJECTChange(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    FMdbgrideh: TDBGridEh;
    procedure SetMdbgrideh(const Value: TDBGridEh);
    { Private declarations }
  public
    { Public declarations }
  published
    property Mdbgrideh: TDBGridEh read FMdbgrideh write SetMdbgrideh;
  end;

var
  dbgrideh_print: Tdbgrideh_print;
  inifile: TIniFile;

implementation

{$R *.dfm}

function Tdbgrideh_print.Edit_string(mstr: string): string;
var
  s: string;
begin
  s := mstr;
  if InputQuery('文字', '输入文字:', s) then
  begin
    if s <> '' then
      Result := s
    else
      Result := '';
  end;
end;

procedure Tdbgrideh_print.SpeedButton1Click(Sender: TObject);
begin
  with FontDialog1 do
  begin
    Font.Assign(L_TITLE_LEFT.Font);
    if Execute then
    begin
      l_title_center.Font.Assign(Font);
      l_title_left.Font.Assign(Font);
      l_title_right.Font.Assign(Font);
    end;
  end;
end;

procedure Tdbgrideh_print.SpeedButton8Click(Sender: TObject);
begin
  with FontDialog1 do
  begin
    Font.Assign(L_FOOTS_LEFT.Font);
    if Execute then
    begin
      L_FOOTS_LEFT.Font.Assign(Font);
      L_FOOTS_LEFT.Font.Assign(Font);
      L_FOOTS_LEFT.Font.Assign(Font);
    end;
  end;
end;

procedure Tdbgrideh_print.SpeedButton3Click(Sender: TObject);
begin
  L_FOOTS_LEFT.Caption := Edit_string(L_FOOTS_LEFT.Caption);
end;

procedure Tdbgrideh_print.SpeedButton9Click(Sender: TObject);
begin
  L_GRIDE_BEFOR.Caption := Edit_string(L_GRIDE_BEFOR.Caption);
end;

procedure Tdbgrideh_print.SpeedButton10Click(Sender: TObject);
begin
  l_grid_after.Caption := Edit_string(l_grid_after.Caption);
end;

procedure Tdbgrideh_print.SpeedButton11Click(Sender: TObject);
var
  S: string;
  app_path: string;
begin
  app_path := ExtractFilePath(Application.ExeName);
  InputQuery('保存打印方案', '请输入要保存的方案名称:', s);
  if s = '' then exit;
  if inifile <> nil then inifile.Free;

  // MessageDlg(app_path + s + '.ps', mtWarning, [mbok], 0);
  inifile := TIniFile.Create(app_path + s + '.ps');

  L_writetoIni(l_title_center);
  L_writetoIni(l_title_left);
  L_writetoIni(l_title_right);

  L_writetoIni(L_foots_center);
  L_writetoIni(L_foots_left);
  L_writetoIni(L_foots_right);

  L_writetoIni(L_GRIDE_BEFOR);
  L_writetoIni(l_grid_after);

  E_writetoIni(E_LEFT);
  E_writetoIni(E_RIGHT);
  E_writetoIni(E_TOP);
  E_writetoIni(E_BOTTOM);

  c_writeToini(c_usecolor);
  MessageDlg('保存完成!', mtWarning, [mbOK], 0);

  load_project;
end;

procedure Tdbgrideh_print.SpeedButton15Click(Sender: TObject);
begin
  l_title_right.Caption := Edit_string(l_title_right.Caption);
end;

procedure Tdbgrideh_print.SpeedButton14Click(Sender: TObject);
var
  s: string;
begin
  if MessageDlg('你真的准备删除该方案吗?', mtWarning, mbOKCancel, 0) = idok
    then
  begin
    s := ExtractFilePath(Application.ExeName) + C_PROJECT.Text;
    DeleteFile(s);
    load_project;
  end;
end;

procedure Tdbgrideh_print.SpeedButton16Click(Sender: TObject);
begin
  with FontDialog1 do
  begin
    if Execute then
      l_title_right.Font.Assign(Font);
  end;

end;

procedure Tdbgrideh_print.L_writetoIni(mlabel: TLabel);
begin
  with inifile do
  begin
    with mlabel do
    begin
      WriteString(mlabel.Name, 'caption', mlabel.Caption);
      WriteInteger(mlabel.Name, 'fontsize', mlabel.Font.Size);
      WriteString(mlabel.Name, 'fontname', mlabel.Font.Name);
      WriteString(mlabel.Name, 'fontcolor', ColorToString(mlabel.Font.Color));
    end;
  end;
end;

procedure Tdbgrideh_print.E_writetoIni(medit: Tedit);
begin
  with inifile do
  begin
    with medit do
    begin
      WriteString(medit.Name, 'text', medit.Text);
    end;
  end;
end;

procedure Tdbgrideh_print.c_writeToini(mcheckbox: TCheckBox);
begin
  with inifile do
  begin
    with mcheckbox do
    begin
      WriteBool(mcheckbox.Name, 'checked', mcheckbox.Checked);
    end;
  end;

end;

procedure Tdbgrideh_print.L_readFromIni(mlabel: TLabel);
begin
  with inifile do
  begin
    with mlabel do
    begin
      mlabel.Caption := ReadString(mlabel.Name, 'caption', '');
      mlabel.Font.Size := ReadInteger(mlabel.Name, 'fontsize', 0);
      mlabel.Font.Name := ReadString(mlabel.Name, 'fontname', '');
      mlabel.Font.Color := StringToColor(ReadString(mlabel.Name, 'fontcolor',
        'clblack'));
    end;
  end;
end;

procedure Tdbgrideh_print.e_readFromIni(medit: TEdit);
begin
  with inifile do
  begin
    with medit do
    begin
      medit.Text := ReadString(medit.Name, 'text', '');
    end;
  end;
end;

procedure Tdbgrideh_print.c_readFromini(Mcheckbox: TCheckBox);
begin
  with inifile do
  begin
    with mcheckbox do
    begin
      Checked := ReadBool(mcheckbox.Name, 'checked', false);
    end;
  end;
end;

procedure Tdbgrideh_print.BitBtn5Click(Sender: TObject);
begin
  PrintDBGridEh1.PrinterSetupDialog;
end;

procedure Tdbgrideh_print.APP_change;
begin
  with PrintDBGridEh1 do
  begin
    PageHeader.CenterText.Text := l_title_center.Caption;
    PageHeader.Font.Assign(l_title_center.Font);
    PageHeader.LeftText.Text := l_title_left.Caption;
    PageHeader.RightText.Text := l_title_right.Caption;

    PageFooter.Font.Assign(L_foots_center.Font);
    PageFooter.CenterText.Text := L_foots_center.Caption;
    PageFooter.LeftText.Text := L_foots_left.Caption;
    PageFooter.RightText.Text := L_foots_right.Caption;

    BeforeGridText.Text := L_GRIDE_BEFOR.Caption;
    AfterGridText.Text := l_grid_after.Caption;

    Page.LeftMargin := StrToFloat(E_LEFT.Text);
    Page.RightMargin := StrToFloat(E_RIGHT.Text);
    Page.TopMargin := StrToFloat(E_TOP.Text);
    Page.BottomMargin := StrToCurr(E_BOTTOM.Text);

    if c_usecolor.Checked then
      Options := Options + [pghcolored]
    else
    begin
      if (pghcolored in Options) then
        Options := Options - [pghcolored];
    end;
  end;
end;

procedure Tdbgrideh_print.BitBtn4Click(Sender: TObject);
begin
  APP_change;
  PrintDBGridEh1.Preview;
end;

procedure Tdbgrideh_print.BitBtn3Click(Sender: TObject);
begin
  APP_change;
  Print;
end;

procedure Tdbgrideh_print.FormShow(Sender: TObject);
begin
  PrintDBGridEh1.DBGridEh.OnGetCellParams := nil;
  BitBtn2.Enabled := PrintDBGridEh1.DBGridEh <> nil;
  SaveDialog1.InitialDir := ExtractFilePath(Application.ExeName);
  OpenDialog1.InitialDir := ExtractFilePath(Application.ExeName);
end;

procedure Tdbgrideh_print.SpeedButton4Click(Sender: TObject);
begin
  L_TITLE_LEFT.Caption := Edit_string(L_TITLE_LEFT.Caption);
end;

procedure Tdbgrideh_print.SpeedButton2Click(Sender: TObject);
begin
  L_TITLE_CENTER.Caption := Edit_string(L_TITLE_CENTER.Caption);
end;

procedure Tdbgrideh_print.SpeedButton5Click(Sender: TObject);
begin
  L_TITLE_RIGHT.Caption := Edit_string(L_TITLE_RIGHT.Caption);
end;

procedure Tdbgrideh_print.SpeedButton6Click(Sender: TObject);
begin
  L_FOOTS_CENTER.Caption := Edit_string(L_FOOTS_CENTER.Caption);

end;

procedure Tdbgrideh_print.SpeedButton7Click(Sender: TObject);
begin
  L_FOOTS_RIGHT.Caption := Edit_string(L_FOOTS_RIGHT.Caption);
end;

procedure Tdbgrideh_print.SpeedButton12Click(Sender: TObject);
begin
  with FontDialog1 do
  begin
    Font.Assign(L_GRIDE_BEFOR.Font);
    if Execute then
    begin
      L_GRIDE_BEFOR.Font.Assign(Font);
      l_grid_after.Font.Assign(Font);

    end;
  end;
end;

procedure Tdbgrideh_print.SpeedButton13Click(Sender: TObject);
begin
  with FontDialog1 do
  begin
    Font.Assign(l_grid_after.Font);
    if Execute then
    begin
      l_grid_after.Font.Assign(Font);
    end;
  end;

end;

procedure Tdbgrideh_print.C_PROJECTClick(Sender: TObject);
var
  s: string;
begin
  if C_PROJECT.Text = '' then Exit;
  s := ExtractFilePath(Application.ExeName);
  s := s + C_PROJECT.Text;
  // MessageDlg(s, mtWarning, [mbok], 0);
  if inifile <> nil then inifile.Free;

  inifile := TIniFile.Create(s);

  L_readFromIni(l_title_center);
  L_readFromIni(l_title_left);
  L_readFromIni(l_title_right);

  L_readFromIni(L_foots_center);
  L_readFromIni(L_foots_left);
  L_readFromIni(L_foots_right);

  L_readFromIni(L_GRIDE_BEFOR);
  L_readFromIni(l_grid_after);

  e_readFromIni(E_LEFT);
  e_readFromIni(E_RIGHT);
  e_readFromIni(E_TOP);
  e_readFromIni(E_BOTTOM);
  c_readFromini(c_usecolor);
end;

procedure Tdbgrideh_print.BitBtn2Click(Sender: TObject);
begin
  with PrintDBGridEh1 do
  begin
    PageHeader.CenterText.Text := l_title_center.Caption;
    PageHeader.Font.Assign(l_title_center.Font);
    PageHeader.LeftText.Text := l_title_left.Caption;
    PageHeader.RightText.Text := l_title_right.Caption;

    PageFooter.Font.Assign(L_foots_center.Font);
    PageFooter.CenterText.Text := L_foots_center.Caption;
    PageFooter.LeftText.Text := L_foots_left.Caption;
    PageFooter.RightText.Text := L_foots_right.Caption;

    BeforeGridText.Text := L_GRIDE_BEFOR.Caption;
    AfterGridText.Text := l_grid_after.Caption;

    Page.LeftMargin := StrToFloat(E_LEFT.Text);
    Page.RightMargin := StrToFloat(E_RIGHT.Text);
    Page.TopMargin := StrToFloat(E_TOP.Text);
    Page.BottomMargin := StrToCurr(E_BOTTOM.Text);

    if c_usecolor.Checked then
      Options := Options + [pghcolored]
    else
    begin
      if (pghcolored in Options) then
        Options := Options - [pghcolored];
    end;

    if c_font.Checked then
    begin
      with PrintDBGridEh1.DBGridEh do
      begin
        Font.Size := 12;
        TitleFont.Size := 12;
        FooterFont.Size := 12;
      end;
    end;

  end;
  PrintDBGridEh1.Preview;
end;

procedure Tdbgrideh_print.load_project;
var
  i: integer;
begin
  C_PROJECT.Items.Clear;
  C_PROJECT.Text := '';
  with FileListBox1 do
  begin
    Mask := '*.s';
    Mask := '*.ps';
    Directory := ExtractFilePath(Application.ExeName);
    C_PROJECT.Items.Assign(Items);
  end;

end;

procedure Tdbgrideh_print.FormCreate(Sender: TObject);
begin
  load_project;
end;

procedure Tdbgrideh_print.C_PROJECTChange(Sender: TObject);
begin
  SpeedButton4.Enabled := C_PROJECT.Text <> '';
end;

procedure Tdbgrideh_print.SetMdbgrideh(const Value: TDBGridEh);
begin
  FMdbgrideh := Value;
end;

procedure Tdbgrideh_print.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  with PrintDBGridEh1.DBGridEh do
  begin
    Font.Size := 10;
    TitleFont.Size := 10;
    FooterFont.Size := 10;
  end;
end;

end.

⌨️ 快捷键说明

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