RTFormwork/public10/design/U_cxGridCustomSet.pas

506 lines
15 KiB
ObjectPascal
Raw Normal View History

2024-07-07 09:35:27 +08:00
unit U_cxGridCustomSet;
interface
uses
Windows, SysUtils, Messages, Classes, Controls, StdCtrls, ComCtrls, Forms,
ExtCtrls, ComObj, DXCORE, ActiveX, cxMemo, cxButtons, Graphics, IniFiles,
Variants, DBClient,
Dialogs, Menus, DB, ADODB, cxLabel, BtnEdit, RTComboBox, cxTextEdit,
cxMRUEdit,
cxDBData, cxGridLevel, cxButtonEdit, cxCurrencyEdit, cxGridTableView, cxGrid,
cxGridCustomTableView, cxGraphics, cxCalendar, cxCheckBox, cxGridDBTableView,
cxGridDBBandedTableView, cxStyles, cxPc, cxGroupBox, U_cxGridCustomCss,
dxLayoutContainer,
cxCustomData, cxClasses, cxTimeEdit, cxEdit, cxLookAndFeels, dxLayoutControl,
cxLookAndFeelPainters, cxGridCustomView, Buttons, cxDropDownEdit;
// procedure createFindLayout(dxLayoutControl1: TdxLayoutControl; ADOTmp: TADOQuery; mdesignCode: string);
procedure CreateCxGridColumn(application: TApplication; tv1: TcxGridDBTableView;
ADOQueryTmp: TADOQuery; mdesignCode: string);
// stdcall;external 'rtCommon.dll' Name 'CreateCxGridColumn_A';
procedure CreateCxGridColumn_A(application: TApplication;
tv1: TcxGridDBTableView; ADOQueryTmp: TADOQuery; mdesignCode: string);
stdcall; external 'rtCommon.dll';
procedure ShowCxGridDesign(application: TApplication;
mCxGridView: TcxGridDBTableView; client1: TClientDataSet; ADOCmd: TADOQuery;
mFormName: PWideChar; mGridName: PWideChar; mDllName: PWideChar;
2024-10-12 10:45:24 +08:00
mFormId: integer; mGridType: integer = 0;mProcedureName: PWideChar=nil); stdcall;
2024-07-07 09:35:27 +08:00
external 'rtCommon.dll' Name 'ShowCxGridDesign_A';
function SaveGridSetInfoToBase(mCxGridView: TcxGridDBTableView;
ADOCmd: TADOQuery; designCode: PWideChar): Boolean; stdcall;
external 'rtCommon.dll' Name 'SaveGridSetInfoToBase_A';
//
function checkColumnMustIn(app: TApplication; tv1: TcxGridDBTableView;
mFlag: integer): Boolean;
// stdcall;external 'rtCommon.dll' Name 'checkColumnMustIn_A';
function checkColumnMustIn_A(app: TApplication; tv1: TcxGridDBTableView;
client1: TClientDataSet; mFlag: integer): Boolean; stdcall;
external 'rtCommon.dll';
procedure getColumnRelation(tv1: TcxGridDBTableView; client1: TClientDataSet);
implementation
// uses
// U_globalVar, U_DataLink;
/// ////////////////////////////////////////////////////////////////
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƴ<EFBFBD><C6B4><EFBFBD>
// 0: mGridType <20><>ѯ; 1:<3A><><EFBFBD><EFBFBD>
/// /////////////////////////////////////////////////////////////////
// procedure ShowCxGridDesign(mCxGridView: TcxGridDBTableView; ADOCmd: TADOQuery;
// mFormName: string; mGridName: string; mDllName: string; mFormId: integer;
// mGridType: integer = 0);
// type
// TMyFunc = function(App: Tapplication; FormH: hwnd; FormID: integer;
// UID: String; UName: String; dataBase: string; Title: string; Def1: string;
// Def2: string): hwnd; stdcall;
// var
// Tf: TMyFunc;
// Tp: TFarProc;
// Th: Thandle;
// newh: hwnd;
// mdesignCode: string;
// begin
//
// /// ////////////////////////////////////
// // Ȩ<>޿<EFBFBD><DEBF><EFBFBD>
// with ADOCmd do
// begin
// close;
// sql.Clear;
// filtered := false;
// sql.Add('select count(*) as cnt');
// sql.Add('from sy_user A');
// sql.Add('where userid=' + quotedStr(gUserId));
// sql.Add('and valid=''Y''');
// sql.Add('and candesign=1');
// open;
// if fieldByName('cnt').AsInteger <= 0 then
// begin
// close;
// // exit;
// end;
// close;
//
// mdesignCode := mDllName +mFormName+ '|' + intTostr(mFormId) + '|' + mGridName;
//
// /// ////////////////////////////////////////
// // <20><><EFBFBD>浱ǰ<E6B5B1>ؼ<EFBFBD><D8BC><EFBFBD>Ϣ
// if not SaveGridSetInfoToBase(mCxGridView, ADOCmd, mdesignCode) then
// begin
// exit;
// end;
// end;
//
// /// ////////////////////////////////////////
// //
// Th := LoadLibrary('rtDesign.dll');
// if Th > 0 then
// begin
// try
// Tp := GetProcAddress(Th, 'GetDllForm');
// if Tp <> nil then
// begin
// Tf := TMyFunc(Tp);
// newh := Tf(Application, 0, 2, PChar(gUserId), PChar(gUserName),
// PChar(DConString), PChar('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'), PChar(mdesignCode), PChar(''));
// end
// else
// begin
// ShowMessage('<27><><EFBFBD><EFBFBD>rtDesign.dllʱ<6C><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!');
// end;
// finally
// // FreeLibrary();
// end;
// end
// else
// begin
// ShowMessage('<27>Ҳ<EFBFBD><D2B2><EFBFBD>rtDesign.dll');
// end;
// // CreateCxGridColumn(mCxGridView,ADOCmd,mwinCode,mFormName,mGridName);
//
// CreateCxGridColumn(mCxGridView, ADOCmd, mdesignCode);
//
// end;
/// ////////////////////////////////////////////////////////////////////
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
/// ///////////////////////////////////////////////////////////////////////
// function SaveGridSetInfoToBase(mCxGridView: TcxGridDBTableView;
// ADOCmd: TADOQuery; designCode: string): Boolean;
// var
// i: integer;
// mfieldName: string;
// begin
// result := false;
//
// try
// with ADOCmd do
// begin
// close;
// sql.Clear;
// sql.Add('select * from SD_FormGrid_Design');
// sql.Add('where designCode=' + quotedStr(designCode));
// open;
//
// for i := mCxGridView.ColumnCount - 1 downto 0 do
// begin
// mfieldName := TcxGridDBColumn(mCxGridView.Columns[i])
// .DataBinding.FieldName;
//
// if locate('fieldName', mfieldName, []) then
// begin
// // Edit ;
// continue;
// end
// else
// begin
//
// Append;
// fieldByName('designCode').value := designCode;
//
// fieldByName('ColumnName').value := mCxGridView.Columns[i].Name;
// fieldByName('oldCaption').value := mCxGridView.Columns[i].Caption;
// fieldByName('ColumnLock').value := 0;
// fieldByName('ColumnHide').value := mCxGridView.Columns[i].Hidden;
// fieldByName('ColumnOrder').value := mCxGridView.Columns[i].SortOrder;
// fieldByName('Visible').value := mCxGridView.Columns[i].Visible;
//
// fieldByName('Valid').value := 1;
// end;
//
// fieldByName('FieldName').value :=
// trim(TcxGridDBColumn(mCxGridView.Columns[i]).DataBinding.FieldName);
// fieldByName('Caption').value := mCxGridView.Columns[i].Caption;
// fieldByName('ColumnType').value :=
// trim(TcxGridDBColumn(mCxGridView.Columns[i]).DataBinding.ValueType);
//
// if mCxGridView.Columns[i].FixedKind = fkLeftDynamic then
// begin
// fieldByName('fixColumn').value := True;
// end
// else
// begin
// fieldByName('fixColumn').value := false;
// end;
//
// fieldByName('Width').value := mCxGridView.Columns[i].Width;
//
// if mCxGridView.Columns[i].Tag=9 then
// begin
// fieldByName('mustIn').value := true;
// end
// else
// begin
// fieldByName('mustIn').value := false;
// end;
// fieldByName('IsOrder').value := 1;
//
// Post;
// end;
//
// end;
//
// /// /////////////////////////////////////////////
// //
// for i := 0 to mCxGridView.DataController.DataSet.FieldCount - 1 do
// begin
// mfieldName := trim(mCxGridView.DataController.DataSet.Fields[i]
// .FieldName);
// if mfieldName = '' then
// continue;
// with ADOCmd do
// begin
// close;
// sql.Clear;
// sql.Add('select * from SD_FormGrid_Design');
// sql.Add('where designcode=' + quotedStr(designCode));
// sql.Add('and fieldName=' + quotedStr(mfieldName));
// open;
// if RecordCount <= 0 then
// begin
// Append;
// fieldByName('designcode').value := designCode;
// fieldByName('fieldName').value := mfieldName;
// fieldByName('Caption').value := 'δ<><CEB4><EFBFBD><EFBFBD>';
// fieldByName('ColumnName').value := mCxGridView.Name + mfieldName;
// fieldByName('Visible').value := false;
// fieldByName('AddFlag').value := True;
// fieldByName('Width').value := 60;
// fieldByName('ColumnOrder').value := 99;
//
// fieldByName('Valid').value := 0;
// Post;
//
// end;
// end;
// end;
// result := True;
// except
// Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣʱ<CFA2><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ<EFBFBD><CABE>Ϣ', 0);
// end;
// end;
//
/// ////////////////////////////////////////////////////////
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>CxGrid<69><64>
/// ////////////////////////////////////////////////////////
procedure CreateCxGridColumn(application: TApplication; tv1: TcxGridDBTableView;
ADOQueryTmp: TADOQuery; mdesignCode: string);
var
ADBColumn: TcxGridDBColumn;
strField, strCaption: string;
mColumnName: string;
mCalcWidth: integer;
mWidth: integer;
mAvgWidth, mGridWidth: integer;
HeaderStyle: TcxStyle;
2024-10-12 10:45:24 +08:00
footsumitem:tcxdatasummaryitem;
2024-07-07 09:35:27 +08:00
begin mWidth := 12;
mGridWidth := TcxGrid(TcxGridLevel(tv1.level).Control).Width;
2024-10-12 10:45:24 +08:00
with ADOQueryTmp do begin close;
sql.Clear;
sql.Add('select A.* ');
sql.Add('from SD_FormGrid_Design A');
sql.Add('where A.designCode=' + quotedStr(mdesignCode));
open;
if IsEmpty then exit;
end;
2024-07-07 09:35:27 +08:00
try
2024-10-12 10:45:24 +08:00
2024-07-07 09:35:27 +08:00
HeaderStyle := TcxStyle.Create(nil);
HeaderStyle.Font := TcxGrid(TcxGridLevel(tv1.level).Control).Font;
HeaderStyle.TextColor := clBlue;
tv1.BeginUpdate;
// CreateCxGridColumn_A(application,tv1,ADOQueryTmp,mdesignCode);
2024-10-12 10:45:24 +08:00
with ADOQueryTmp do
begin
2024-07-07 09:35:27 +08:00
First;
while not Eof do
begin
2024-10-12 10:45:24 +08:00
if trim(fieldByName('fieldName').AsString)='' then
begin
Next;
continue;
end;
2024-07-07 09:35:27 +08:00
ADBColumn := tv1.GetColumnByFieldName
2024-10-12 10:45:24 +08:00
(trim(ADOQueryTmp.fieldByName('fieldName').AsString));
2024-07-07 09:35:27 +08:00
if ADBColumn <> nil then begin
// <20><><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD>ʾ
if not fieldByName('valid').AsBoolean then
begin
ADBColumn.Visible := false;
ADBColumn.Hidden := True;
Next;
continue;
end;
2024-10-12 10:45:24 +08:00
2024-07-07 09:35:27 +08:00
ADBColumn.Name := trim(tv1.Name) +
2024-10-12 10:45:24 +08:00
trim(ADOQueryTmp.fieldByName('fieldName').AsString);
2024-07-07 09:35:27 +08:00
if fieldByName('fixColumn').AsBoolean then
begin
ADBColumn.FixedKind := fkLeftDynamic;
end
else begin ADBColumn.FixedKind := fkNone;
end;
if fieldByName('mustIn').AsBoolean then
begin
ADBColumn.Tag := 9;
end;
if ADBColumn.Tag = 9 then
ADBColumn.Styles.Header := HeaderStyle;
ADBColumn.Hidden := fieldByName('ColumnHide').AsBoolean;
if ADBColumn.Hidden then begin ADBColumn.Visible := false;
end
else begin ADBColumn.Visible := fieldByName('Visible').AsBoolean;
end;
2024-10-12 10:45:24 +08:00
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
///
if (trim(ADOQueryTmp.fieldByName('FooterType').AsString)<>'') and (ADBColumn.Summary.FooterKind=skNone) then
begin
footsumitem:=tv1.DataController.Summary.FooterSummaryItems.Add;
footsumitem.ItemLink:= ADBColumn ;
if (trim(fieldByName('FooterType').AsString)='sum') or (trim(fieldByName('FooterType').AsString)='<27>ϼ<EFBFBD>') then
begin
footsumitem.Kind:=skSum;
end;
if (trim(fieldByName('FooterType').AsString)='count')or (trim(fieldByName('FooterType').AsString)='С<><D0A1>') then
begin
footsumitem.Kind:=skCount;
end;
// footsumitem.Format:='#';
footsumitem.Position:=spFooter;
end
else
begin
// ADBColumn.Summary.FooterKind:=skNone ;
end;
2024-07-07 09:35:27 +08:00
ADBColumn.Caption := trim(fieldByName('caption').AsString);
Next;
continue;
end;
2024-10-12 10:45:24 +08:00
//
2024-07-07 09:35:27 +08:00
if not fieldByName('valid').AsBoolean then
begin
ADOQueryTmp.Next;
continue;
end;
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>Ѵ<EFBFBD><D1B4><EFBFBD>
mColumnName := trim(tv1.Name) + trim(fieldByName('fieldName').AsString);
if tv1.FindItemByName(mColumnName) <> nil then
begin
ADOQueryTmp.Next;
continue;
end;
// <20>µ<EFBFBD><C2B5><EFBFBD>
ADBColumn := tv1.CreateColumn;
ADBColumn.DataBinding.FieldName :=
trim(fieldByName('fieldName').AsString);
ADBColumn.Caption := trim(fieldByName('Caption').AsString);
// <20><><EFBFBD><EFBFBD>
ADBColumn.Width := fieldByName('width').AsInteger;
if fieldByName('fixColumn').AsBoolean then
begin
ADBColumn.FixedKind := fkLeftDynamic;
end;
//
if fieldByName('mustIn').AsBoolean then
begin
ADBColumn.Tag := 9;
end;
ADBColumn.Visible := fieldByName('visible').AsBoolean;
// ADBColumn.Hidden := fieldByName('ColumnHide').AsBoolean;
ADBColumn.HeaderAlignmentHorz := taCenter;
2024-10-12 10:45:24 +08:00
// ADBColumn.MinWidth := 50;
2024-07-07 09:35:27 +08:00
ADBColumn.Name := mColumnName;
ADBColumn.Options.Editing := not fieldByName('ReadOnly').AsBoolean;
ADBColumn.Options.Focusing := not fieldByName('ReadOnly').AsBoolean;
/// /////////////
2024-10-12 10:45:24 +08:00
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
///
if (trim(ADOQueryTmp.fieldByName('FooterType').AsString)<>'') then
begin
footsumitem:=tv1.DataController.Summary.FooterSummaryItems.Add;
footsumitem.ItemLink:= ADBColumn ;
if (trim(fieldByName('FooterType').AsString)='sum') or (trim(fieldByName('FooterType').AsString)='<27>ϼ<EFBFBD>') then
begin
footsumitem.Kind:=skSum;
end;
if (trim(fieldByName('FooterType').AsString)='count') or (trim(fieldByName('FooterType').AsString)='С<><D0A1>') then
begin
footsumitem.Kind:=skCount;
end;
// footsumitem.Format:='#';
footsumitem.Position:=spFooter;
end;
2024-07-07 09:35:27 +08:00
ADOQueryTmp.Next;
end;
close;
end;
finally
2024-10-12 10:45:24 +08:00
2024-07-07 09:35:27 +08:00
tv1.EndUpdate;
end;
end;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯloyout
// procedure createFindLayout(dxLayoutControl1: TdxLayoutControl;
// ADOTmp: TADOQuery; mdesignCode: string);
// var
// LayoutItem: TdxLayoutItem;
// cxTextEdit: TcxTextEdit;
// i: integer;
// begin
// with ADOTmp do
// begin
// close;
// sql.Clear;
// sql.Add('select A.* ');
// sql.Add('from SD_FormGrid_Design A');
// sql.Add('where A.designCode=' + quotedStr(mdesignCode));
// sql.Add('and (A.columnQuery=1 or A.ColumnFilter=1)');
// sql.Add('and A.valid=1');
// open;
//
// while not Eof do
// begin
// cxTextEdit := TcxTextEdit.Create(nil);
// cxTextEdit.Name := trim(fieldByName('fieldName').AsString);
// cxTextEdit.Text := '';
// cxTextEdit.Tag := 2;
//
// if (dxLayoutControl1.FindComponent('layitem' +
// trim(fieldByName('fieldName').AsString)) = nil) and
// (dxLayoutControl1.FindItem(cxTextEdit) = nil) then
// begin
// LayoutItem := dxLayoutControl1.CreateItemForControl(cxTextEdit, nil);
// LayoutItem.Name := 'layitem' + trim(fieldByName('fieldName').AsString);
// LayoutItem.CaptionOptions.Text := trim(fieldByName('caption').AsString);
// LayoutItem.Control := cxTextEdit;
//
// LayoutItem.SizeOptions.SizableHorz := True;
// LayoutItem.SizeOptions.SizableVert := True;
// end;
// Next;
// end;
//
// end;
// end;
//
function checkColumnMustIn(app: TApplication; tv1: TcxGridDBTableView;
mFlag: integer): Boolean;
var
i: integer;
client1: TClientDataSet;
begin client1 := TClientDataSet.Create(nil);
try
client1.FieldDefs.Add('fieldName', ftString, 100);
client1.FieldDefs.Add('caption', ftString, 100);
client1.FieldDefs.Add('ValueType', ftString, 100);
2024-10-12 10:45:24 +08:00
client1.FieldDefs.Add('fieldValue', ftString, 100);
2024-07-07 09:35:27 +08:00
client1.CreateDataSet;
getColumnRelation(tv1, client1);
Result := checkColumnMustIn_A(app, tv1, client1, mFlag);
finally
client1.Free;
end;
end;
/// //////////////////////////////////////////////////////////////
///
procedure getColumnRelation(tv1: TcxGridDBTableView; client1: TClientDataSet);
var
i: integer;
begin
client1.EmptyDataSet;
for i := 0 to tv1.ColumnCount - 1 do begin client1.Append;
client1.fieldByName('fieldName').Value := tv1.Columns[i]
.DataBinding.FieldName;
client1.fieldByName('caption').Value := tv1.Columns[i].Caption;
client1.fieldByName('ValueType').Value := tv1.Columns[i]
.DataBinding.ValueType;
end;
end;
end.