Delphi实现ERP单据列表栏目设置

什么都不用说了,ERP你懂的。一张报表,不同的客户都可以调死你。直接上图

通过这个设置界面,直接生成参数调整报表所用的DBGridEh。对,是DBGridEh,不是DBGrid,也不是CXGrid。

然后再将这些参数生成一个JSON,保存到数据库。下次打开,直接取这个JSON就可以了。这样,客户可以根据自己的需要调整自己的报表。

unit uGridDes;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,DbGridEh, DBGridEhGrouping, ToolCtrlsEh,
  DBGridEhToolCtrls, DynVarsEh, FireDAC.Stan.Intf, FireDAC.Stan.Option,
  FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf,
  FireDAC.DApt.Intf, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client,
  EhLibVCL, GridsEh, DBAxisGridsEh,QJson, Vcl.ComCtrls, Vcl.ToolWin;

type
  RGridIndex=record
    cFileName:String;
    cTitle:String;
    cDefTitle:String;
    iWidth:Integer;
    bVisible:Boolean;
  end;
  TFrmGridDes = class(TForm)
    FDMem: TFDMemTable;
    DataSource1: TDataSource;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    StatusBar1: TStatusBar;
    DBGridEh1: TDBGridEh;
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure DBGridEh1CellClick(Column: TColumnEh);
    procedure ToolButton4Click(Sender: TObject);
  private
  //  function JsonLoadGrid: TQJson;
    { Private declarations }
  public
    FDBGridEh:TDBGridEh;
    FJson:TQJson;
    function UPDateJson:TQJson;
    function GetJsonFromGrid:TQJson;
    function UPDateGrid:Boolean;
    Function TryParsetojson(Text:String):Boolean;
  class Function SetGridasJson(FDBGrid:TDBGridEh;Ajson:TQjson):TQJson;
    { Public declarations }
  end;

var
  FrmGridDes: TFrmGridDes;

implementation

{$R *.dfm}

procedure TFrmGridDes.DBGridEh1CellClick(Column: TColumnEh);
begin
// if  then
  if DBGridEh1.ReadOnly=False  And (Column.FieldName<>‘cFieldName‘) then
    DBGridEh1.EditorMode:=True;

end;

procedure TFrmGridDes.FormCreate(Sender: TObject);
begin
  FJson:=TQJson.Create;
  FDMem.CreateDataSet;
end;

procedure TFrmGridDes.FormShow(Sender: TObject);
var
  I:integer;
begin

  Self.Left:=(Screen.Width-Self.Width) div 2;
  Self.Top:=(Screen.Height-Self.Height)div 2;
  DBGridEh1.ReadOnly:=True;
  DBGridEh1.Options:=DBGridEh1.Options-[dgEditing]+[dgRowSelect];
  FDMem.Close;
  FDMem.CreateDataSet;
//  if FJson.Count=0 then

     for I := 0 to FDBGridEh.Columns.Count-1 do
        FDMem.AppendRecord([I,FDBGridEh.Columns[i].FieldName,FDBGridEh.Columns[i].Title.Caption,
        FDBGridEh.Columns[i].Title.Caption,FDBGridEh.Columns[i].Width,FDBGridEh.Columns[i].Visible]);

   FDMem.First;

end;

function TFrmGridDes.GetJsonFromGrid: TQJson;
Var
  I:integer;
begin
  Result:=nil;
  FDMem.DisableControls;
  FDMem.Table.Clear;
   for I := 0 to FDBGridEh.Columns.Count-1 do
      FDMem.AppendRecord([I,FDBGridEh.Columns[i].FieldName,FDBGridEh.Columns[i].Title.Caption,
      FDBGridEh.Columns[i].Title.Caption,FDBGridEh.Columns[i].Width,FDBGridEh.Columns[i].Visible]);
   UPDateJson;
   FDMem.First;
   FDMem.EnableControls;
   Result:=Fjson;
end;

function TFrmGridDes.UPDateGrid:Boolean;
Var
  ItemJson:TQJson;
  I:integer;
begin
  Result:=False;
  if Fjson.Count=0 then Exit;

  Try

  for I := 0 to FJson.Count-1 do
      begin
       ItemJson:=FJson.ItemByName(IntToStr(I));
       With FDBGridEh.Columns[i] do// else
         begin
           if  FieldName<>ItemJson.ValueByName(‘cFieldName‘,‘‘) then
             FieldName:=ItemJson.ValueByName(‘cFieldName‘,‘‘);
           if Width<>StrTOInt(ItemJson.ValueByName(‘iWidth‘,‘64‘)) then
             Width:=StrTOInt(ItemJson.ValueByName(‘iWidth‘,‘64‘));
           if Title.Caption<>ItemJson.ValueByName(‘cDefTitle‘,‘1‘) then
             Title.Caption:=ItemJson.ValueByName(‘cDefTitle‘,‘1‘);
           if Visible<>StrToBool(ItemJson.ValueByName(‘bVisible‘,‘2‘)) then
             Visible:=StrToBool(ItemJson.ValueByName(‘bVisible‘,‘2‘));
         end;
//         ItemJson.Free;
      end;
  except
    Exit(False);
  End;

   Result:=True;

end;

function TFrmGridDes.UPDateJson: TQJson;
Var
  ItemJson:TQJson;
  str:string;
begin
 FJson.Clear;
 FDMem.DisableControls;
 FDMem.First;
 while Not FDMem.Eof do
   begin
     ItemJson:=TQJson.Create;
     for Str in FDMem.FieldList do
       ItemJson.Add(Str,FDMem.FieldByName(Str).AsString);
     FJson.Add(IntToStr(FDMem.FieldByName(‘iRow‘).AsInteger),ItemJson);
     FDMem.Next;
   end;
 FDMem.First;
 FDMem.EnableControls;
 Result:=FJson;
end;

class function TFrmGridDes.SetGridasJson(FDBGrid: TDBGridEh;
  Ajson: TQjson): TQJson;
begin
  if FrmGridDes=nil then
   FrmGridDes:=TFrmGridDes.Create(nil);
   FrmGridDes.FDBGridEh:=FDBGrid;

     FrmGridDes.UPDateGrid;
   FrmGridDes.ShowModal;
   FrmGridDes.UPDateGrid;
   Result:=TQJson.Create;
   Result.Assign(FrmGridDes.fJson);

end;

procedure TFrmGridDes.ToolButton1Click(Sender: TObject);
begin

 DBGridEh1.ReadOnly:=False;
 DBGridEh1.Options:=DBGridEh1.Options+[dgediting]-[dgRowSelect];
 ToolButton2.Enabled:=True;
 ToolButton1.Enabled:=False;
 ToolButton5.Enabled:=True;
 ToolButton6.Enabled:=True;
 ToolButton4.Enabled:=True;
end;

procedure TFrmGridDes.ToolButton2Click(Sender: TObject);
begin
 FDMem.Edit;
 FDMem.Post;
 DBGridEh1.ReadOnly:=True;
 UPDateJson;
 DBGridEh1.Options:=DBGridEh1.Options-[dgediting]+[dgRowSelect];
 ToolButton1.Enabled:=True;
 ToolButton2.Enabled:=False;
  ToolButton4.Enabled:=False;
  ToolButton5.Enabled:=False;
 ToolButton6.Enabled:=False;
end;

procedure TFrmGridDes.ToolButton3Click(Sender: TObject);
begin
 if ToolButton2.Enabled then
    begin
      ShowMessage(‘栏目设置未保存,不能退出‘);
      Exit;
    end;

 Close;
end;

procedure TFrmGridDes.ToolButton4Click(Sender: TObject);
begin
 FDMem.Edit;
 FDMem.Post;
 DBGridEh1.ReadOnly:=True;
 GetJsonFromGrid;
 DBGridEh1.Options:=DBGridEh1.Options-[dgediting]+[dgRowSelect];
 ToolButton1.Enabled:=True;
 ToolButton2.Enabled:=False;
 ToolButton4.Enabled:=False;
 ToolButton5.Enabled:=False;
 ToolButton6.Enabled:=False;
end;

procedure TFrmGridDes.ToolButton5Click(Sender: TObject);

Var
  R1,R2:RGridIndex;
begin
  if FDMem.Bof then exit;

  FDMem.DisableControls;
  R1.cFileName:=FDMem.FieldByName(‘cFieldName‘).AsString;
  R1.cTitle:=FDMem.FieldByName(‘cTitle‘).AsString;
  R1.cDefTitle:=FDMem.FieldByName(‘cDefTitle‘).AsString;
  R1.iWidth:=FDMem.FieldByName(‘iWidth‘).AsInteger;
  R1.bVisible:=FDMem.FieldByName(‘bVisible‘).AsBoolean;

  FDMem.Prior;

  R2.cFileName:=FDMem.FieldByName(‘cFieldName‘).AsString;
  R2.cTitle:=FDMem.FieldByName(‘cTitle‘).AsString;
  R2.cDefTitle:=FDMem.FieldByName(‘cDefTitle‘).AsString;
  R2.iWidth:=FDMem.FieldByName(‘iWidth‘).AsInteger;
  R2.bVisible:=FDMem.FieldByName(‘bVisible‘).AsBoolean;
  FDMem.Edit;
  FDMem.FieldByName(‘cFieldName‘).AsString:=R1.cFileName;
  FDMem.FieldByName(‘ctitle‘).AsString:=R1.cTitle;
  FDMem.FieldByName(‘cDeftitle‘).AsString:=R1.cDefTitle;
  FDMem.FieldByName(‘iWidth‘).AsInteger:=r1.iWidth;
  FDMem.FieldByName(‘bVisible‘).AsBoolean:=R1.bVisible;
  FDMem.Next;
  FDMem.Edit;
  FDMem.FieldByName(‘cFieldName‘).AsString:=R2.cFileName;
  FDMem.FieldByName(‘ctitle‘).AsString:=R2.cTitle;
  FDMem.FieldByName(‘cDeftitle‘).AsString:=R2.cDefTitle;
  FDMem.FieldByName(‘iWidth‘).AsInteger:=r2.iWidth;
  FDMem.FieldByName(‘bVisible‘).AsBoolean:=R2.bVisible;
  FDMem.Prior;
  FDMem.EnableControls;

end;

procedure TFrmGridDes.ToolButton6Click(Sender: TObject);
Var
  R1,R2:RGridIndex;
begin
 if FDMem.Eof then Exit;

  FDMem.DisableControls;
  R1.cFileName:=FDMem.FieldByName(‘cFieldName‘).AsString;
  R1.cTitle:=FDMem.FieldByName(‘cTitle‘).AsString;
  R1.cDefTitle:=FDMem.FieldByName(‘cDefTitle‘).AsString;
  R1.iWidth:=FDMem.FieldByName(‘iWidth‘).AsInteger;
  R1.bVisible:=FDMem.FieldByName(‘bVisible‘).AsBoolean;

  FDMem.Next;

  R2.cFileName:=FDMem.FieldByName(‘cFieldName‘).AsString;
  R2.cTitle:=FDMem.FieldByName(‘cTitle‘).AsString;
  R2.cDefTitle:=FDMem.FieldByName(‘cDefTitle‘).AsString;
  R2.iWidth:=FDMem.FieldByName(‘iWidth‘).AsInteger;
  R2.bVisible:=FDMem.FieldByName(‘bVisible‘).AsBoolean;
  FDMem.Edit;
  FDMem.FieldByName(‘cFieldName‘).AsString:=R1.cFileName;
  FDMem.FieldByName(‘ctitle‘).AsString:=R1.cTitle;
  FDMem.FieldByName(‘cDeftitle‘).AsString:=R1.cDefTitle;
  FDMem.FieldByName(‘iWidth‘).AsInteger:=r1.iWidth;
  FDMem.FieldByName(‘bVisible‘).AsBoolean:=R1.bVisible;
  FDMem.Prior;
  FDMem.Edit;
  FDMem.FieldByName(‘cFieldName‘).AsString:=R2.cFileName;
  FDMem.FieldByName(‘ctitle‘).AsString:=R2.cTitle;
  FDMem.FieldByName(‘cDeftitle‘).AsString:=R2.cDefTitle;
  FDMem.FieldByName(‘iWidth‘).AsInteger:=r2.iWidth;
  FDMem.FieldByName(‘bVisible‘).AsBoolean:=R2.bVisible;
  FDMem.Next;
  FDMem.EnableControls;

end;

function TFrmGridDes.TryParsetojson(Text: String): Boolean;
begin
  Result:=FJson.TryParse(Text);
end;

end.
object FrmGridDes: TFrmGridDes
  Left = 0
  Top = 0
  BorderIcons = []
  BorderStyle = bsDialog
  Caption = #35774#32622
  ClientHeight = 416
  ClientWidth = 425
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = ‘Tahoma‘
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object ToolBar1: TToolBar
    Left = 0
    Top = 0
    Width = 425
    Height = 26
    ButtonWidth = 31
    Caption = ‘ToolBar1‘
    DrawingStyle = dsGradient
    EdgeBorders = [ebLeft, ebTop, ebRight]
    EdgeInner = esNone
    EdgeOuter = esNone
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -12
    Font.Name = ‘Tahoma‘
    Font.Style = []
    ParentFont = False
    ShowCaptions = True
    TabOrder = 0
    object ToolButton1: TToolButton
      Left = 0
      Top = 0
      Caption = #20462#25913
      ImageIndex = 0
      OnClick = ToolButton1Click
    end
    object ToolButton5: TToolButton
      Left = 31
      Top = 0
      Caption = #21521#19978
      Enabled = False
      ImageIndex = 3
      OnClick = ToolButton5Click
    end
    object ToolButton6: TToolButton
      Left = 62
      Top = 0
      Caption = #21521#19979
      Enabled = False
      ImageIndex = 3
      OnClick = ToolButton6Click
    end
    object ToolButton2: TToolButton
      Left = 93
      Top = 0
      Caption = #20445#23384
      Enabled = False
      ImageIndex = 1
      OnClick = ToolButton2Click
    end
    object ToolButton4: TToolButton
      Left = 124
      Top = 0
      Caption = #25918#24323
      Enabled = False
      ImageIndex = 3
      OnClick = ToolButton4Click
    end
    object ToolButton3: TToolButton
      Left = 155
      Top = 0
      Caption = #36864#20986
      ImageIndex = 2
      OnClick = ToolButton3Click
    end
  end
  object StatusBar1: TStatusBar
    Left = 0
    Top = 397
    Width = 425
    Height = 19
    Panels = <
      item
        Text = #26639#30446#33258#23450#20041#35774#32622
        Width = 50
      end>
  end
  object DBGridEh1: TDBGridEh
    Left = 0
    Top = 26
    Width = 425
    Height = 371
    Align = alClient
    Color = 13816530
    ColumnDefValues.Title.Alignment = taCenter
    ColumnDefValues.Title.Color = clBtnShadow
    DataGrouping.Color = clWindow
    DataGrouping.ParentColor = False
    DataSource = DataSource1
    DynProps = <>
    EvenRowColor = clScrollBar
    GridLineParams.DataHorzLines = True
    GridLineParams.DataVertLines = False
    IndicatorOptions = [gioShowRowIndicatorEh]
    BackgroundData.Visible = True
    OddRowColor = clGradientActiveCaption
    RowHeight = 23
    RowPanel.Active = True
    STFilter.Color = clActiveBorder
    TabOrder = 2
    TitleParams.Font.Charset = DEFAULT_CHARSET
    TitleParams.Font.Color = clWindowText
    TitleParams.Font.Height = 15
    TitleParams.Font.Name = ‘Tahoma‘
    TitleParams.Font.Style = [fsBold]
    TitleParams.ParentFont = False
    OnCellClick = DBGridEh1CellClick
    Columns = <
      item
        Color = 11776947
        DynProps = <>
        EditButtons = <>
        FieldName = ‘cFieldName‘
        Footers = <>
        ReadOnly = True
        TextEditing = False
        Title.Caption = #23383#27573
        Title.Color = clGradientInactiveCaption
        Width = 113
      end
      item
        DynProps = <>
        EditButtons = <>
        FieldName = ‘cTitle‘
        Footers = <>
        ReadOnly = True
        Title.Caption = #26631#39064
        Visible = False
        Width = 126
      end
      item
        DynProps = <>
        EditButtons = <>
        FieldName = ‘cDefTitle‘
        Footers = <>
        Title.Caption = #33258#23450#20041#26631#39064
        Width = 143
      end
      item
        DynProps = <>
        EditButtons = <>
        FieldName = ‘iWidth‘
        Footers = <>
        Title.Caption = #23485#24230
      end
      item
        DynProps = <>
        EditButtons = <>
        FieldName = ‘bVisible‘
        Footers = <>
        Title.Caption = #26174#31034
        Width = 53
      end
      item
        DynProps = <>
        EditButtons = <>
        FieldName = ‘iRow‘
        Footers = <>
        Visible = False
      end>
    object RowDetailData: TRowDetailPanelControlEh
    end
  end
  object FDMem: TFDMemTable
    FieldDefs = <
      item
        Name = ‘iRow‘
        DataType = ftInteger
      end
      item
        Name = ‘cFieldName‘
        DataType = ftString
        Size = 20
      end
      item
        Name = ‘cTitle‘
        DataType = ftString
        Size = 50
      end
      item
        Name = ‘cDefTitle‘
        DataType = ftString
        Size = 50
      end
      item
        Name = ‘iWidth‘
        DataType = ftFloat
      end
      item
        Name = ‘bVisible‘
        DataType = ftBoolean
      end>
    IndexDefs = <>
    FetchOptions.AssignedValues = [evMode]
    FetchOptions.Mode = fmAll
    ResourceOptions.AssignedValues = [rvSilentMode]
    ResourceOptions.SilentMode = True
    UpdateOptions.AssignedValues = [uvCheckRequired, uvAutoCommitUpdates]
    UpdateOptions.CheckRequired = False
    UpdateOptions.AutoCommitUpdates = True
    StoreDefs = True
    Left = 152
    Top = 144
  end
  object DataSource1: TDataSource
    DataSet = FDMem
    Left = 288
    Top = 176
  end
end
时间: 2024-10-06 00:39:54

Delphi实现ERP单据列表栏目设置的相关文章

Delphi XE7 Update1修正列表

Delphi XE7 Update1修正列表 官方下载地址:http://altd.embarcadero.com/download/radstudio/xe7/delphicbuilder_xe7_upd1_win.isobug修正列表:http://edn.embarcadero.com/article/44156更新内容:http://docwiki.embarcadero.com/RADStudio/XE7/en/Release_Notes_for_XE7_Update_1 Keygen

delphi开发实例:保存字体设置的方法

http://blog.csdn.net/delphi308/article/details/9906147 delphi开发实例:保存字体设置的方法 2013-08-11 22:37 446人阅读 评论(0) 收藏 举报  分类: Delphi(59)  记得一年前软件里面用到字体设置时,想把字体信息保存到配置文件里面都是把相应的属性分开来保存一下,这样一直使用,最近想delphi自己的dfm文件也同样会保存这些信息,它又是怎样保存的呢.. 用记事本打开dfm文件会看到类似这样的文本: obj

如何在dede栏目设置中添加自定义字段(dede二次开发-纯抄贴)

如何在dede栏目设置中添加自定义字段 这个说法以前没有见到到,很少有客户会提出这样的二次要求,今天织梦者在网上转了一下看到了这样的一篇文章转过来与大家分享 鉴于这个教程没人发过,网上搜索的人也比较多.所以就做了个. 比如我要添加:栏目图片,和栏目关键字等.随便你吧.好.我们现在开始做. 第一我们要进去mysql 数据库里添加字段,自己命名好!比如我下面添加了一个栏目搜索关键字字段,当然你字段可以自己新建,找到表dede_arctype (这个是栏目模型的数据库表,前面是你安装的表名,新手要注意

单据列表

新建查询项目-- 1.新建查询项目 2.保存项目路径设置 3.查询数据选择,这步可以任意设置 4.删除生成查询定义和列表,并修改ListBP,查询项目.List项目命名空间 5.重新建查询定义 6.修改查询定义属性 7.选择实体数据源 8.设置查询方案定义 9.构造ListUI,查询方案本身并不能构造 10.编辑跳转及选定的代码,编辑代码包括列表单据中点击“新增”跳转至单据中,以及单据中点击“列表”按钮时跳转至列表单据中 /// <summary> /// 列表行选定事件 /// </s

获取URL列表,设置代理请求URL,https的加密方式处理

做了一个测试的一个小工具,需求如下: 1.有一批URL列表,需要知道哪个URL请求响应内容中包含http:关键字的. 2.url请求包括http和https 2种协议 3.要部署在linux服务器上,且linux服务器只能通过代理来连接外网 帖一下我的核心代码吧: package com.cn.util; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader;

网页设计入门--列表格式设置

昨天在学习列表,试着做案例时,出现了列表无法居中显示的问题,代码如下: 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <h

IOS 特定于设备的开发:Info.plist属性列表的设置

应用程序的Info.plist属性列表使你能够在向iTunes提交应用程序时指定应用程序的要求.这些限制允许告诉iTunes应用程序需要哪些设备特性. 每个IOS单元都会提供一个独特的特性集.一些设备回提供照相机和GPS能力,另外一些则不会.一些设备具有机载陀螺仪.自动聚焦,以及其他强大的选项.你可以指定在设备上运行应用程序时需要哪些特性. 在Info.plist文件中包括UIRequiredDeviceCapabilities键时,iTunes将限制把应用程序安装到提供必须能力的设备.把这个列

delphi中获得进程列表或想要的进程(枚举进程、遍历进程)

一个常见的编程任务是枚举所有运行的"应用程序".Windows 任务管理器就是一个很好的例子.它用两种方式列出"应用程序".任务管理器的第一个选项卡列出桌面上的所有"应用程序窗口".第二个选项卡列出系统中的所有"进程".本文提供了如何执行这些任务的详细信息. 枚举顶层窗口如果将枚举进程与枚举桌面上的顶层窗口进行比较,那么枚举顶层窗口可能更容易一些.要枚举顶层窗口,请使用 EnumWindows() 函数.不要使用 GetWin

价格列表如何设置计量单位转换

在Sage X3中,我们可能会遇到这样的场景:我们直接从价格表中获取总价格,而不需要在价格表屏幕中为销售单位以外的单位定义产品价格.这个功能可以通过以下步骤实现:Navigate to: Setup → Sales → Price Lists → setup 在该屏幕,销售价格列表里的转换单位,我们将是否转换设置为"yes" 在此屏幕中,将单位转换设置为Yes.销售价格参数:价格/免费:单位转换现在拿一个产品,检查它的库存单位,销售单位和包装单位.Navigate to: Common