📄 gridrowedit.pas
字号:
unit GridRowEdit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, EditForm, KsSkinForms, KsSkinButtons, dxCntner, dxEditor, dxEdLib,
KsSkinLabels, KsSkinPanels, dxTL, SysPublic, dxDBGrid, dxExEdtr,
se_controls, DB, ADODB, KsSkinSpeedButtons;
type
TfrmGridRowEdit = class(TfrmEditForm)
Panel1: TSeSkinPanel;
bbOk: TSeSkinButton;
bbNo: TSeSkinButton;
lbl1: TSeSkinLabel;
lbl3: TSeSkinLabel;
lbl4: TSeSkinLabel;
lbl5: TSeSkinLabel;
lbl6: TSeSkinLabel;
lbl2: TSeSkinLabel;
edt1: TdxEdit;
edt2: TdxEdit;
edt3: TdxEdit;
edt4: TdxEdit;
edt5: TdxEdit;
edt6: TdxEdit;
MainGrid: TdxTreeList;
MainGridColumn1: TdxTreeListColumn;
MainGridColumn2: TdxTreeListMaskColumn;
MainGridColumn3: TdxTreeListColumn;
edtType1: TdxEdit;
edtType2: TdxEdit;
edtType3: TdxEdit;
edtType4: TdxEdit;
edtType5: TdxEdit;
edtType6: TdxEdit;
procedure bbNoClick(Sender: TObject);
procedure bbOkClick(Sender: TObject);
private
{ Private declarations }
bReturn: Boolean;
sWrite: string;
dxGrid: TdxDBGrid;
procedure LoadGrid;
function LoadData: Boolean;
procedure SaveData;
procedure MainShow;
public
{ Public declarations }
end;
function GridRowEditShow(dxGrid1: TdxDBGrid): Boolean;
implementation
uses DBData;
{$R *.dfm}
function GridRowEditShow(dxGrid1: TdxDBGrid): Boolean;
var
frmGridRowEdit: TfrmGridRowEdit;
begin
frmGridRowEdit := TfrmGridRowEdit.Create(Application);
with frmGridRowEdit do
begin
dxGrid := dxGrid1;
MainShow;
Result := bReturn;
Free;
end;
end;
procedure TfrmGridRowEdit.LoadGrid;
begin
bReturn := False;
MainGrid.Columns[0].ReadOnly := True;
MainGrid.Columns[0].Color := clBtnFace;
MainGrid.Columns[1].ReadOnly := False;
MainGrid.Columns[1].Color := clHighlightText;
MainGrid.Columns[2].Visible := False;
end;
function TfrmGridRowEdit.LoadData: Boolean;
var
i, lCount: Integer;
dxNode: TdxTreeListNode;
begin
Result := False;
sWrite := '';
for i := 0 to dxGrid.ColumnCount - 1 do
begin
if dxGrid.Columns[i].Visible and not dxGrid.Columns[i].ReadOnly then
sWrite := sWrite + ',' + dxGrid.Columns[i].FieldName;
end;
sWrite := TrimCommaStr(sWrite);
lCount := GetCommaStrCount(sWrite);
if sWrite = '' then
Exit;
if lCount <= 6 then
begin
Panel1.Visible := True;
for i := 1 to lCount do
begin
if FindComponent('lbl' + IntToStr(i)) is TSeSkinLabel then
begin
TSeSkinLabel(FindComponent('lbl' + IntToStr(i))).Caption :=
dxGrid.ColumnByFieldName(GetCommaStr(sWrite, i)).Caption;
TSeSkinLabel(FindComponent('lbl' + IntToStr(i))).Visible := True;
end;
if FindComponent('edt' + IntToStr(i)) is TdxInplaceTextEdit then
begin
TdxInplaceTextEdit(FindComponent('edt' + IntToStr(i))).Text :=
GetCells(dxGrid,
dxGrid.ColumnByFieldName(GetCommaStr(sWrite, i)).Index,
dxGrid.FocusedNode.Index);
TdxInplaceTextEdit(FindComponent('edt' + IntToStr(i))).Visible := True;
end;
if FindComponent('edtType' + IntToStr(i)) is TdxInplaceTextEdit then
begin
TdxInplaceTextEdit(FindComponent('edttype' + IntToStr(i))).Text :=
GetFieldType(dxGrid.ColumnByFieldName(GetCommaStr(sWrite, i)).Field);
end;
end;
end
else
begin
MainGrid.Visible := True;
for i := 1 to lCount do
begin
dxNode := MainGrid.Add;
dxNode.Strings[0] := dxGrid.ColumnByFieldName(GetCommaStr(sWrite,
i)).Caption;
dxNode.Strings[1] := GetCells(dxGrid,
dxGrid.ColumnByFieldName(GetCommaStr(sWrite, i)).Index,
dxGrid.FocusedNode.Index);
dxNode.Strings[2] :=
GetFieldType(dxGrid.ColumnByFieldName(GetCommaStr(sWrite, i)).Field);
end;
end;
Result := True;
end;
procedure TfrmGridRowEdit.SaveData;
var
i, lCount: Integer;
V: Variant;
begin
if sWrite = '' then
Exit;
lCount := GetCommaStrCount(sWrite);
dxGrid.DataLink.DataSet.Edit;
if lCount <= 6 then
for i := 1 to lCount do
begin
if Trim(TdxInplaceTextEdit(FindComponent('edttype' + IntToStr(i))).Text) =
'Int' then
V := StrToFloat2(TdxInplaceTextEdit(FindComponent('edt' +
IntToStr(i))).Text)
else
V := TdxInplaceTextEdit(FindComponent('edt' + IntToStr(i))).Text;
dxGrid.DataLink.DataSet.FieldByName(GetCommaStr(sWrite, i)).AsVariant :=
V;
end
else
for i := 1 to lCount do
begin
if Trim(MainGrid.Items[i - 1].Strings[2]) = 'Int' then
V := StrToFloat2(MainGrid.Items[i - 1].Strings[1])
else
V := MainGrid.Items[i - 1].Strings[1];
dxGrid.DataLink.DataSet.FieldByName(GetCommaStr(sWrite, i)).AsVariant :=
V;
end;
end;
procedure TfrmGridRowEdit.MainShow;
begin
bOperateLog := False;
LoadGrid;
if LoadData then ShowModal;
end;
procedure TfrmGridRowEdit.bbNoClick(Sender: TObject);
begin
inherited;
Close;
end;
procedure TfrmGridRowEdit.bbOkClick(Sender: TObject);
begin
inherited;
SaveData;
bReturn := True;
Close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -