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

📄 uintercol.pas

📁 中式财务栏 表格式录入 运行时设置可显示列、列名、列宽
💻 PAS
字号:
{*******************************************************}
{                                                       }
{       操作表格功能函数接口                            }
{                                                       }
{       版权所有 (C) 2008 咏南工作室                    }
{                                                       }
{*******************************************************}

unit uInterCOL;

interface

uses
  SysUtils,db,DBGridEh,Graphics,Printers,Forms,PrnDbgeh,Windows,ADODB,Menus,
  Classes,DBCtrls,ExtCtrls,Controls,sncCurrency,sncDBCurrency,GridsEh;
  
{ 记录查找 }  
procedure FindPublicShowA(AGrid: TDBGridEh);
{ 表格编辑 }
procedure ShowGridColEditorA(Grid: TDBGridEH);
{ 导出 }
procedure ExpDbgridEhA(grid:TDBGridEh;OpenExcel:Boolean=True);
{ 导入 }
procedure ImpDbgridEhA(grid:TDBGridEh);
//--------------------------------------------------------------------------------
// 功能:设定 DbGridEh 合计行信息
// 参数: pDbGrid:TDBGridEh;
//        pcFields : string ; 字段列表,字段用逗号分隔
//        pvtType : TFooterValueType ;统计类型 TFooterValueType = (fvtNon, fvtSum, fvtAvg, fvtCount, fvtFieldValue, fvtStaticText);
// 引用:StrToStringList
// 例如:DbGridEhFoot( DbGridEh1, 'Number,Sum', fvtSum ); 设定数量和金额字段为合计统计
// AFlag=1记录数
// AFlag=2合计
// AFlag=3两者都要
//--------------------------------------------------------------------------------
Procedure SetDbGridEhFootA(pDbGrid:TDBGridEh;pcFields:string;AFlag:Integer=3;
  AValueType:TFooterValueType=fvtSum);
{ 分组统计 }
procedure ShowGroupA(AGrid:TDBGridEh);
{ 显示分组统计后结果 }
procedure ShowDisplayA(AQuery: TADOQuery);
{ 通用打印 }
procedure PrintA(ADBGridEh:TDBGridEh);
{ 设置数字或金额字段的显示格式 }
procedure SetDisplayFormatA(AField:TField;AFormat:string='###,##0.00');
{ 请稍候 }
procedure ShowWaitA(Text: string='');
{ 定时关闭各种对话框 }
procedure SetDlgAutoCloseA(nTime: Integer=1000;
  ADoHint:Boolean=False;AReturn: Boolean = false);
//==============================================================================
// MulteTitle
// EnterAsTab
// 调节COLUMN的宽度
// RestoreGridLayOut
// 过滤(dbgrideh自身的),用开关控制
//==============================================================================
procedure SetDbGridEHPropertyA(AGrid:TDBGridEh;AFilter:Boolean=false);
{ 汉化DBNavigator }
//procedure CHNDBNavigatorA(ADBNavigator:TDBNavigator);
{ 图形分析 }
procedure ShowChartA(AGrid:TDBGridEh;ATitle:string='');
{ 记录筛选 }
procedure ShowFilterFormA(AGrid:TDBGridEh);
{ 恢复表格格式 }
procedure RestoreGridLayOutA(AGrid:TDBGridEh);
{ 创建弹出菜单 }
function GetPopupMenuA(AOwner:TForm;n:TNotifyEvent):TPopupMenu;
{ 弹出菜单项点击事件 }
procedure MenuItemClickA(AMenuItem:TMenuItem;ADBGridEH:TDBGridEh);
{ 单据录入选择 }
procedure SelectMyA(HostControl: TControl;ADataSet:TDataSet;
  AFieldList:TStringList;AP,AP2:Pointer);
{ 显示DBGridEH左上角的三角形标志 }
procedure ShowIndicatorTitleA(AGrid:TDBGridEh);
{ 是否金额栏 }
function CheckCurrencyFieldA(AFieldName,AFieldList: String): Boolean;
{ SetHighLightColorA }
procedure SetHighLightColorA(ACurrency:TsncDBCurrencyEdit);
{ SetNormalColorA }
procedure SetNormalColorA(ACurrency:TsncDBCurrencyEdit;AGrid:TDBGridEh);
{ DBGridEh1DrawColumnCellA }
procedure DBGridEhDrawColumnCellA(ACurrency:TsncDBCurrencyEdit;AGrid:TDBGridEh;
  ARect:TRect;AColumn:TColumnEh;AState:TGridDrawState;AFieldList:string);
{ DBGridEhColEnterA }
procedure DBGridEhColEnterA(ACurrency:TsncDBCurrencyEdit;AGrid:TDBGridEh;AFieldList:string);
{ DBGridEhColExitA }
procedure DBGridEhColExitA(ACurrency:TsncDBCurrencyEdit;AGrid:TDBGridEh;AFieldList:string);

implementation

uses FindPublic, FormColSelect, uExport, uFooter, uGroup,uKingFilter,
  uFormatDisplay,uPrint,FormWait,uTimerDlg,uChart,uSelect,uDisplay;

procedure DBGridEhColExitA(ACurrency:TsncDBCurrencyEdit;AGrid:TDBGridEh;AFieldList:string);
begin
  if CheckCurrencyFieldA(AGrid.SelectedField.FieldName,aFieldList) then
  begin
    ACurrency.Visible := false;
    ACurrency.Tag := 0;
  end;
end;    

procedure DBGridEhColEnterA(ACurrency:TsncDBCurrencyEdit;AGrid:TDBGridEh;AFieldList:string);
begin
  if CheckCurrencyFieldA(AGrid.SelectedField.FieldName,aFieldList) then
  begin
    ACurrency.DataField := AGrid.SelectedField.FieldName;
    ACurrency.Tag := 1;
  end;
end;  

procedure DBGridEhDrawColumnCellA(ACurrency:TsncDBCurrencyEdit;AGrid:TDBGridEh;
  ARect:TRect;AColumn:TColumnEh;AState:TGridDrawState;AFieldList:string);
var
  OldColor, OldFontColor: TColor;
begin
  if CheckCurrencyFieldA(aColumn.FieldName,AFieldList) then
  begin
    if (gdFocused in aState) then
    begin
      with ACurrency do
      begin
        Font.Assign(AGrid.Font);
        Left := aRect.Left + AGrid.Left+2;
        Top := aRect.Top + AGrid.top+2;
        Width := aRect.Right-aRect.Left;
        Height := aRect.Bottom- aRect.Top;
      end;
      SetHighLightColorA(ACurrency);
      if (ACurrency.Tag=1) and (not ACurrency.Visible) then
        ACurrency.Visible := True;
    end else
    begin
      OldColor := ACurrency.Color;
      OldFontColor := ACurrency.Font.Color;
      SetNormalColorA(ACurrency,AGrid);
      DrawCurrencyFrame(AGrid.Canvas, aRect, ACurrency, aColumn.Field.AsFloat);
      ACurrency.Color := OldColor;
      ACurrency.Font.Color := OldFontColor;
    end;
  end;      
end;  

procedure SetNormalColorA(ACurrency:TsncDBCurrencyEdit;AGrid:TDBGridEh);
begin
  ACurrency.Color:=AGrid.Color;
  ACurrency.Font.Color:=AGrid.Font.Color;
end;  

procedure SetHighLightColorA(ACurrency:TsncDBCurrencyEdit);
begin
  ACurrency.Color:=clHighlight;
  ACurrency.Font.Color:=clWhite;
end;    

function CheckCurrencyFieldA(AFieldName,AFieldList: String): Boolean;
var
  I: Integer;
  sl:TStringList;
begin
  Result := False;
  sl:=TStringList.Create;
  try
    sl.Delimiter:=',';
    sl.DelimitedText:=AFieldList;
    for I:=0 to sl.Count-1 do
    begin
      if (AFieldName=sl.Strings[i]) then
      begin
        Result := True;
        Break;
      end;
    end;
  finally
    sl.Free;
  end;
end;

procedure ShowIndicatorTitleA(AGrid:TDBGridEh);
begin
  with AGrid.IndicatorTitle do
  begin
    ShowDropDownSign:=True;
    TitleButton:=True;
  end;  
end;  

procedure SelectMyA(HostControl: TControl;ADataSet:TDataSet;
  AFieldList:TStringList;AP,AP2:Pointer);
begin
  Execute(HostControl,ADataSet,AFieldList,AP,AP2);
end;  

function GetPopupMenuA(AOwner:TForm;n:TNotifyEvent):TPopupMenu;
var
  FPopupMenu:TPopupMenu;
  FMenuItem,FMenuItem2,FMenuItem3,FMenuItem4,FMenuItem5:TMenuItem;
  FMenuItem6,FMenuItem7:TMenuItem;
  i:Integer;
begin
  FPopupMenu:=TPopupMenu.Create(AOwner);
  FPopupMenu.Items.Clear;
  FMenuItem:=TMenuItem.Create(AOwner);
  FMenuItem.Caption:='表格设置';
  FMenuItem.Tag:=101;
  FPopupMenu.Items.Add(FMenuItem);
  FMenuItem2:=TMenuItem.Create(AOwner);
  FMenuItem2.Caption:='记录查找';
  FMenuItem2.Tag:=102;
  FPopupMenu.Items.Add(FMenuItem2);
  FMenuItem3:=TMenuItem.Create(AOwner);
  FMenuItem3.Caption:='记录筛选';
  FMenuItem3.Tag:=103;
  FPopupMenu.Items.Add(FMenuItem3);
  FMenuItem4:=TMenuItem.Create(AOwner);
  FMenuItem4.Caption:='分组统计';
  FMenuItem4.Tag:=104;
  FPopupMenu.Items.Add(FMenuItem4);
  FMenuItem5:=TMenuItem.Create(AOwner);
  FMenuItem5.Caption:='导出数据';
  FMenuItem5.Tag:=105;
  FPopupMenu.Items.Add(FMenuItem5);
  FMenuItem6:=TMenuItem.Create(AOwner);
  FMenuItem6.Caption:='图形分析';
  FMenuItem6.Tag:=106;
  FPopupMenu.Items.Add(FMenuItem6);
  FMenuItem7:=TMenuItem.Create(AOwner);
  FMenuItem7.Caption:='打印表格';
  FMenuItem7.Tag:=107;
  FPopupMenu.Items.Add(FMenuItem7);
  for i := 0 to FPopupMenu.Items.Count - 1 do
    FPopupMenu.Items[i].OnClick:=n;
  Result:=FPopupMenu;
end;

procedure MenuItemClickA(AMenuItem:TMenuItem;ADBGridEH:TDBGridEh);
begin
  case AMenuItem.Tag of
    101: ShowGridColEditorA(ADBGridEH);
    102: FindPublicShowA(ADBGridEH);
    103: ShowFilterFormA(ADBGridEH);
    104: ShowGroupA(ADBGridEH);
    105: ExpDbgridEhA(ADBGridEH);
    106: ShowChartA(ADBGridEH);
    107: PrintA(ADBGridEH);
  end;
end;  

procedure ShowFilterFormA(AGrid:TDBGridEh);
begin
  ShowFilterForm(AGrid);
end;  

procedure ShowChartA(AGrid:TDBGridEh;ATitle:string='');
begin
  ShowChart(AGrid,ATitle);
end;  
{
procedure CHNDBNavigatorA(ADBNavigator:TDBNavigator);
var
  i:Integer;
begin
  with ADBNavigator do
  begin
    for I:=0 to ComponentCount-1   do
    begin
      if Components[I] is TNavButton then
      begin
        case TNavButton(Components[I]).Index of
            nbFirst:   TNavButton(Components[I]).Caption   :=   '首笔';
            nbPrior:   TNavButton(Components[I]).Caption   :=   '上笔';
            nbNext:    TNavButton(Components[I]).Caption   :=   '下笔';
            nbLast:    TNavButton(Components[I]).Caption   :=   '末笔';
            nbInsert:  TNavButton(Components[I]).Caption   :=   '新增';
            nbDelete:  TNavButton(Components[I]).Caption   :=   '删除';
            nbEdit:    TNavButton(Components[I]).Caption   :=   '修改';
            nbPost:    TNavButton(Components[I]).Caption   :=   '保存';
            nbCancel:  TNavButton(Components[I]).Caption   :=   '取消';
            nbRefresh: TNavButton(Components[I]).Caption   :=   '刷新';
        end;
      end;
    end;
  end;
  ADBNavigator.ShowHint:=False;
end; }

{ AFilter=true 打开dbgrideh自带的过滤 }
procedure SetDbGridEHPropertyA(AGrid:TDBGridEh;AFilter:Boolean=false);
var
  i:Integer;
begin
  with AGrid do
  begin
    OptionsEh:=OptionsEh+[dghAutoSortMarking];        //多列排序
    ColumnDefValues.Title.TitleButton := True;
    OptionsEh :=OptionsEh + [dghMultiSortMarking];
    SortLocal:=True;

    UseMultiTitle:=True;                              //多行表头

//    OptionsEh:=OptionsEh+[dghEnterAsTab];
//    ShowSerialNo:=True;
    
    for i:=0 to Columns.Count-1 do                    //限制太宽的列
      if Columns[i].Width>=180 then
        Columns[i].Width:=100;

    RestoreGridLayOutA(AGrid);                        //恢复表格格式

    if AFilter then
    begin                                             //是否使用DBGRIDEH自带的过滤
      STFilter.Local:=True;
      STFilter.Visible:=True;
    end;

    ShowIndicatorTitleA(AGrid);
  end;
end;

procedure RestoreGridLayOutA(AGrid:TDBGridEh);
var
  RestoreParams:TDBGridEhRestoreParams;
begin
  RestoreParams:=[grpColIndexEh,grpColWidthsEh,grpSortMarkerEh,
    grpColVisibleEh,grpRowHeightEh,grpDropDownRowsEh,grpDropDownWidthEh];
  with AGrid do
    RestoreGridLayoutIni(ExtractFilePath(Application.ExeName) + '\Grid.ini',
      Owner.ClassName + '$' + Name,RestoreParams);
end;

procedure SetDlgAutoCloseA(nTime: Integer=1000;
  ADoHint:Boolean=False;AReturn: Boolean = false);
begin
  SetDlgAutoClose(nTime,ADoHint,AReturn);
end;  

procedure ShowWaitA(Text: string='');
begin
  ShowWaitText(Text);
end;  

procedure PrintA(ADBGridEh:TDBGridEh);
begin
  PrintMy(ADBGridEh);
end;  

procedure ShowDisplayA(AQuery: TADOQuery);
begin
  ShowDisplay(aquery);
end;  

procedure SetDisplayFormatA(AField:TField;AFormat:string='###,##0.00');
begin
  SetDisplayFormat(AField,AFormat);
end; 

procedure ShowGroupA(AGrid:TDBGridEh);
begin
  ShowGroup(AGrid);
end;  

Procedure SetDbGridEhFootA(pDbGrid:TDBGridEh;pcFields:string;AFlag:Integer=3;
  AValueType:TFooterValueType=fvtSum);
begin
  SetDbGridEhFoot(pDbGrid,pcFields,AFlag,AValueType);
end;

procedure ExpDbgridEhA(grid:TDBGridEh;OpenExcel:Boolean=True);
begin
  ExpDbgridEh(grid,OpenExcel);
end;

procedure ImpDbgridEhA(grid:TDBGridEh);
begin
  ImpDbgridEh(grid);
end;  

procedure FindPublicShowA(AGrid: TDBGridEh);
begin
  FindPublicShow(AGrid);
end;

procedure ShowGridColEditorA(Grid: TDBGridEH);
begin
  ShowGridColEditor(Grid);
end;

end.

⌨️ 快捷键说明

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