380 lines
12 KiB
ObjectPascal
380 lines
12 KiB
ObjectPascal
|
unit Dbpanel;
|
|||
|
|
|||
|
interface
|
|||
|
uses
|
|||
|
Windows, Messages, SysUtils, Classes,Graphics, Controls, Forms, Dialogs,
|
|||
|
ExtCtrls, dbctrls, stdctrls, db, ADODB, ComCtrls;
|
|||
|
|
|||
|
type
|
|||
|
TEditorstyle = (TsDbMemo,TsDBcombox,Tsdbedit);
|
|||
|
|
|||
|
type
|
|||
|
TDBPanel = class(TPanel)
|
|||
|
private
|
|||
|
{ Private declarations }
|
|||
|
FEditorstyle:Teditorstyle;
|
|||
|
FLeft: Integer;
|
|||
|
FTop: Integer;
|
|||
|
maxTextLen: Integer;
|
|||
|
maxLabelLen: Integer;
|
|||
|
FTitleVisible :Boolean;
|
|||
|
FScrollBox: TScrollBox; {<7B><><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD>}
|
|||
|
FLineHeight: Integer;
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
|
|||
|
MemoEditors: array of TDBMemo;
|
|||
|
comEditors: array of TDBCombobox;
|
|||
|
edEditors: array of TDBedit;
|
|||
|
ProgressEditor :array of TDBedit;
|
|||
|
Labels: array of TDBText; //<2F>ֶα<D6B6><CEB1>⣬<EFBFBD><E2A3AC>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
|
|||
|
ProgressBars: array of TProgressBar;
|
|||
|
|
|||
|
FDataSource: TDataSource; // <20><><EFBFBD><EFBFBD>Դ
|
|||
|
FDataField_A: String; // DataField
|
|||
|
FDataField_B: String; // DataField
|
|||
|
FDataField_C: String; // DataField
|
|||
|
FColumns: Integer; //<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
|||
|
procedure FreeEditors; //<2F>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
|||
|
procedure AKeyDown(Sender:TObject; var Key: Word; Shift:TShiftState);
|
|||
|
procedure AKeyPress(Sender:TObject; var Key: Char);
|
|||
|
procedure AProgressEditorChange(Sender: TObject);
|
|||
|
function comEditor(Index: Integer):TDBComboBox;
|
|||
|
function edEditor(Index: Integer):TDBedit;
|
|||
|
function MemoEditor(Index: Integer): TDBMemo;
|
|||
|
protected
|
|||
|
{ Protected declarations }
|
|||
|
|
|||
|
public
|
|||
|
constructor Create(AOwner:TComponent); override;
|
|||
|
destructor Destroy; override;
|
|||
|
function Get_TitleVisible() :Boolean;
|
|||
|
procedure Set_TitleVisible(Value : Boolean);
|
|||
|
procedure Setedit(Value : TEditorstyle);
|
|||
|
procedure CreateEditors(DS: TDataSource; ColCount: Integer); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶε<D6B6><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD>
|
|||
|
procedure ClearHits(ItemIndex: Integer);
|
|||
|
procedure AddHits(ItemIndex:Integer; Hits: array of string);
|
|||
|
|
|||
|
{ Public declarations }
|
|||
|
published
|
|||
|
|
|||
|
property LimitLeft: Integer read FLeft write FLeft default 10;
|
|||
|
property LimitTop: Integer read FTop write FTop default 10;
|
|||
|
property Editorstyle : TEditorstyle read FEditorstyle write Setedit default tsdbMemo;
|
|||
|
property EditorWidth: Integer read maxTextLen write maxTextLen default 100;
|
|||
|
property TitleWidth: Integer read maxLabelLen write maxLabelLen default 100;
|
|||
|
property TitleVisible : Boolean read Get_TitleVisible write Set_TitleVisible default True;
|
|||
|
property LineHeight: Integer read FLineHeight write FLineHeight default 15;
|
|||
|
//property OnOkClick: TNotifyEvent read FClick write FClick;
|
|||
|
property DataSource: TDataSource read FDataSource write FDataSource; //<2F><><EFBFBD><EFBFBD>Դ
|
|||
|
property DataField_Editor: String read FDataField_A write FDataField_A;
|
|||
|
property DataField_Title: String read FDataField_B write FDataField_B;
|
|||
|
property DataField_Progress: String read FDataField_C write FDataField_C;
|
|||
|
property Columns: Integer read FColumns write FColumns default 4;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
{ Published declarations }
|
|||
|
end;
|
|||
|
|
|||
|
procedure Register;
|
|||
|
|
|||
|
implementation
|
|||
|
|
|||
|
procedure Register;
|
|||
|
begin
|
|||
|
RegisterComponents('Data Controls', [TDBPanel]);
|
|||
|
end;
|
|||
|
|
|||
|
function TDBPanel.Get_TitleVisible() :Boolean;
|
|||
|
begin
|
|||
|
Result := FTitleVisible;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TDBPanel.Set_TitleVisible(Value : Boolean);
|
|||
|
begin
|
|||
|
FTitleVisible := Value;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TDBPanel.Setedit(Value : TEditorstyle);
|
|||
|
begin
|
|||
|
if FEditorstyle <> Value then
|
|||
|
begin
|
|||
|
FEditorstyle := Value;
|
|||
|
Invalidate;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
{ Ϊ<><CEAA>I<EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>Ϣ<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>}
|
|||
|
procedure TDBPanel.AddHits(ItemIndex:
|
|||
|
Integer; Hits: array of string);
|
|||
|
var
|
|||
|
m,n,i: Integer;
|
|||
|
begin
|
|||
|
if FEditorstyle = TsDBcombox then
|
|||
|
begin
|
|||
|
n := Length(comEditors);
|
|||
|
m := Length(Hits);
|
|||
|
if ItemIndex< n then
|
|||
|
for i:=0 to m-1 do
|
|||
|
comEditors[ItemIndex].Items.Add(Hits[i]);
|
|||
|
end
|
|||
|
else if FEditorstyle = TsDBEdit then
|
|||
|
begin
|
|||
|
n := Length(edEditors);
|
|||
|
m := Length(Hits);
|
|||
|
if ItemIndex< n then
|
|||
|
for i:=0 to m-1 do
|
|||
|
edEditors[ItemIndex].Hint:= Hits[i];
|
|||
|
end
|
|||
|
else if FEditorstyle = TsDBMemo then
|
|||
|
begin
|
|||
|
n := Length(memoEditors);
|
|||
|
m := Length(Hits);
|
|||
|
if ItemIndex< n then
|
|||
|
for i:=0 to m-1 do
|
|||
|
memoEditors[ItemIndex].Hint:= Hits[i];
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TDBPanel.AKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
|||
|
begin
|
|||
|
if (Sender is TDBComboBox) then
|
|||
|
begin
|
|||
|
case Key of
|
|||
|
VK_Next: (Sender as TDBComboBox).DataSource.DataSet.Next;
|
|||
|
VK_PRIOR: (Sender as TDBComboBox).DataSource.DataSet.Prior;
|
|||
|
end;
|
|||
|
end
|
|||
|
else if (Sender is TDBedit) then
|
|||
|
begin
|
|||
|
case Key of
|
|||
|
VK_Next: (Sender as TDBedit).DataSource.DataSet.Next;
|
|||
|
VK_PRIOR: (Sender as TDBedit).DataSource.DataSet.Prior;
|
|||
|
end;
|
|||
|
end
|
|||
|
else if (Sender is TDBMemo) then
|
|||
|
begin
|
|||
|
case Key of
|
|||
|
VK_Next: (Sender as TDBMemo).DataSource.DataSet.Next;
|
|||
|
VK_PRIOR: (Sender as TDBMemo).DataSource.DataSet.Prior;
|
|||
|
end;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TDBPanel.AProgressEditorChange(Sender: TObject);
|
|||
|
begin
|
|||
|
//
|
|||
|
end;
|
|||
|
|
|||
|
procedure TDBPanel.AKeyPress(Sender: TObject; var Key: Char);
|
|||
|
begin
|
|||
|
if (Sender is TDBComboBox) or (Sender is TDBedit) or (Sender is TDBMemo) then
|
|||
|
if Key=#13 then
|
|||
|
(Owner as TForm).Perform(WM_NEXTDLGCTL, 0, 0);
|
|||
|
end;
|
|||
|
|
|||
|
procedure TDBPanel.ClearHits(ItemIndex: Integer);
|
|||
|
var
|
|||
|
n: Integer;
|
|||
|
begin
|
|||
|
if FEditorstyle = TsDBcombox then
|
|||
|
begin
|
|||
|
n := Length(comEditors);
|
|||
|
if ItemIndex< n then comEditors[ItemIndex].Items.Clear;
|
|||
|
end
|
|||
|
else if FEditorstyle = TsDBEdit then
|
|||
|
begin
|
|||
|
n := Length(edEditors);
|
|||
|
if ItemIndex< n then edEditors[ItemIndex].Hint:='';;
|
|||
|
end
|
|||
|
else if FEditorstyle = TsDBMemo then
|
|||
|
begin
|
|||
|
n := Length(MemoEditors);
|
|||
|
if ItemIndex< n then MemoEditors[ItemIndex].Hint:='';;
|
|||
|
end;
|
|||
|
|
|||
|
end;
|
|||
|
|
|||
|
constructor TDBPanel.Create(AOwner: TComponent);
|
|||
|
begin
|
|||
|
Inherited Create(AOWner);
|
|||
|
FLeft :=10;
|
|||
|
FTop := 10;
|
|||
|
maxTextLen := 100;
|
|||
|
maxLabelLen := 100;
|
|||
|
FLineHeight := 15;
|
|||
|
end;
|
|||
|
|
|||
|
{ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶε<D6B6><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC>ķ<EFBFBD><C4B7><EFBFBD>}
|
|||
|
procedure TDBPanel.CreateEditors(DS: TDataSource; ColCount: Integer);
|
|||
|
var
|
|||
|
i, n, RowCount: Integer;
|
|||
|
TextHeight: Integer;
|
|||
|
begin
|
|||
|
if DataSource = nil then exit;
|
|||
|
if not DataSource.DataSet.Active then exit;
|
|||
|
n := DataSource.DataSet.RecordCount;
|
|||
|
if n > 0 then
|
|||
|
begin
|
|||
|
DataSource.DataSet.DisableControls;
|
|||
|
if maxLabelLen < maxTextLen then
|
|||
|
maxTextLen := maxLabelLen;
|
|||
|
|
|||
|
{ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1>ⳤ<EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>}
|
|||
|
DataSource.DataSet.First;
|
|||
|
{ <20><><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>}
|
|||
|
TextHeight := Canvas.TextHeight(DataSource.DataSet.Fields[0].DisplayLabel) + FLineHeight; //10;
|
|||
|
{ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>}
|
|||
|
if (FColumns = 0) or (FColumns <> ColCount) then FColumns := ColCount;
|
|||
|
RowCount := n div Columns;
|
|||
|
if n mod Columns <> 0 then inc(RowCount);
|
|||
|
{ <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>}
|
|||
|
FreeEditors;
|
|||
|
SetLength(Labels,n);
|
|||
|
SetLength(ProgressBars,n);
|
|||
|
SetLength(ProgressEditor,n);
|
|||
|
if FEditorstyle = TsDBcombox then
|
|||
|
SetLength(comEditors,n)
|
|||
|
else if FEditorstyle = TsDBEdit then
|
|||
|
SetLength(edEditors,n)
|
|||
|
else
|
|||
|
SetLength(MemoEditors,n);
|
|||
|
|
|||
|
{ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>}
|
|||
|
FScrollBox := TScrollBox.Create(Owner);
|
|||
|
FScrollBox.Visible := False;
|
|||
|
FScrollBox.Parent := Self;
|
|||
|
FScrollBox.Align := alClient;
|
|||
|
{ <20><><EFBFBD><EFBFBD><EFBFBD>༭}
|
|||
|
for i := 0 to n - 1 do
|
|||
|
begin
|
|||
|
{ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>}
|
|||
|
Labels[i] := TDBText.Create(Owner);
|
|||
|
Labels[i].visible := FTitleVisible;
|
|||
|
Labels[i].Parent := FScrollBox;
|
|||
|
Labels[i].DataField := DataField_Title;
|
|||
|
Labels[i].DataSource := DataSource;
|
|||
|
Labels[i].Left := FLeft + (maxLabelLen + 36) * (i div RowCount)+16; //+maxTextLen
|
|||
|
if FEditorstyle = TsDBMemo then
|
|||
|
begin
|
|||
|
Labels[i].Width := maxLabelLen;
|
|||
|
Labels[i].Top := FTop + (i mod RowCount) * (TextHeight*4+10) + 2;
|
|||
|
end
|
|||
|
else
|
|||
|
begin
|
|||
|
Labels[i].Top := FTop + (i mod RowCount) * (TextHeight*2+10) + 2;
|
|||
|
Labels[i].Width := maxLabelLen;
|
|||
|
end;
|
|||
|
{ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>}
|
|||
|
ProgressEditor[i] := TDBedit.Create(Owner);
|
|||
|
ProgressEditor[i].visible := False;
|
|||
|
ProgressEditor[i].Parent := FScrollBox;
|
|||
|
ProgressEditor[i].DataField := DataField_Progress;
|
|||
|
ProgressEditor[i].DataSource := DataSource;
|
|||
|
ProgressEditor[i].OnChange := AProgressEditorChange;
|
|||
|
|
|||
|
{ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ʾ<EFBFBD><CABE><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>}
|
|||
|
if FEditorstyle = TsDBcombox then
|
|||
|
begin
|
|||
|
comEditors[i] := TDBComboBox.Create(Owner);
|
|||
|
comEditors[i].Parent := FScrollBox; //Self;
|
|||
|
comEditors[i].Left := Labels[i].Left; //+ Labels[i].Width;
|
|||
|
comEditors[i].Width := maxTextLen;
|
|||
|
comEditors[i].Top := Labels[i].Top+20;
|
|||
|
comEditors[i].DataSource := DataSource;
|
|||
|
comEditors[i].DataField := DataField_Editor;
|
|||
|
comEditors[i].OnKeyPress := AKeyPress;
|
|||
|
comEditors[i].OnKeyDown := AKeyDown;
|
|||
|
ProgressBars[i] := TProgressBar.Create(Owner);
|
|||
|
ProgressBars[i].Parent := FScrollBox;
|
|||
|
ProgressBars[i].Orientation := pbHorizontal;
|
|||
|
ProgressBars[i].Left := comEditors[i].Left;
|
|||
|
ProgressBars[i].Width := comEditors[i].Width;
|
|||
|
ProgressBars[i].Height := 10;
|
|||
|
ProgressBars[i].Top := comEditors[i].Top+comEditors[i].height+2;
|
|||
|
ProgressBars[i].Position := i*4
|
|||
|
end
|
|||
|
else if FEditorstyle = TsDBEdit then
|
|||
|
begin
|
|||
|
edEditors[i] := TDBedit.Create(Owner);
|
|||
|
edEditors[i].Parent := FScrollBox;
|
|||
|
edEditors[i].Left := Labels[i].Left; //+ Labels[i].Width;
|
|||
|
edEditors[i].Width := maxTextLen;
|
|||
|
edEditors[i].Top := Labels[i].Top+20;
|
|||
|
edEditors[i].DataSource := DataSource;
|
|||
|
edEditors[i].DataField := DataField_Editor;
|
|||
|
edEditors[i].OnKeyPress := AKeyPress;
|
|||
|
edEditors[i].OnKeyDown := AKeyDown;
|
|||
|
ProgressBars[i] := TProgressBar.Create(Owner);
|
|||
|
ProgressBars[i].Parent := FScrollBox;
|
|||
|
ProgressBars[i].Orientation := pbHorizontal;
|
|||
|
ProgressBars[i].Left := edEditors[i].Left;
|
|||
|
ProgressBars[i].Width := edEditors[i].Width;
|
|||
|
ProgressBars[i].Height := 10;
|
|||
|
ProgressBars[i].Top := edEditors[i].Top+edEditors[i].height+2;;
|
|||
|
ProgressBars[i].Position := i*4
|
|||
|
end
|
|||
|
else
|
|||
|
begin
|
|||
|
MemoEditors[i] := TDBmemo.Create(Owner);
|
|||
|
MemoEditors[i].Parent := FScrollBox;
|
|||
|
MemoEditors[i].Left := Labels[i].Left;
|
|||
|
MemoEditors[i].Width := maxTextLen;
|
|||
|
MemoEditors[i].Top := Labels[i].Top+20;
|
|||
|
MemoEditors[i].DataSource := DataSource;
|
|||
|
MemoEditors[i].DataField := DataField_Editor;
|
|||
|
MemoEditors[i].OnKeyPress := AKeyPress;
|
|||
|
MemoEditors[i].OnKeyDown := AKeyDown;
|
|||
|
ProgressBars[i] := TProgressBar.Create(Owner);
|
|||
|
ProgressBars[i].Parent := FScrollBox;
|
|||
|
ProgressBars[i].Orientation := pbVertical;
|
|||
|
ProgressBars[i].Left := MemoEditors[i].Left + MemoEditors[i].Width +1;
|
|||
|
ProgressBars[i].Width := 10;
|
|||
|
ProgressBars[i].Height := MemoEditors[i].Height;
|
|||
|
ProgressBars[i].Top := MemoEditors[i].Top;
|
|||
|
ProgressBars[i].Position := i*4
|
|||
|
end;
|
|||
|
if not DataSource.DataSet.Eof then
|
|||
|
DataSource.DataSet.next;
|
|||
|
end;
|
|||
|
DataSource.DataSet.EnableControls;
|
|||
|
FScrollBox.Visible := True;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
destructor TDBPanel.Destroy;
|
|||
|
begin
|
|||
|
FreeEditors;
|
|||
|
Inherited Destroy;
|
|||
|
end;
|
|||
|
|
|||
|
function TDBPanel.comEditor(Index: Integer): TDBComboBox;
|
|||
|
begin
|
|||
|
if Index< Length(comEditors) then Result := comEditors[Index]
|
|||
|
else Result := nil;
|
|||
|
end;
|
|||
|
|
|||
|
function TDBPanel.edEditor(Index: Integer): TDBedit;
|
|||
|
begin
|
|||
|
if Index < Length(edEditors) then Result := edEditors[Index]
|
|||
|
else Result := nil;
|
|||
|
end;
|
|||
|
function TDBPanel.MemoEditor(Index: Integer): TDBMemo;
|
|||
|
begin
|
|||
|
if Index< Length(MemoEditors) then Result := MemoEditors[Index]
|
|||
|
else Result := nil;
|
|||
|
end;
|
|||
|
|
|||
|
// <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>Ҫ<EFBFBD><D2AA>˳<EFBFBD><CBB3><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>෴<EFBFBD><E0B7B4>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD>и<EFBFBD><D0B8>ӹ<EFBFBD>ϵʱ
|
|||
|
procedure TDBPanel.FreeEditors;
|
|||
|
begin
|
|||
|
if FScrollBox <> nil then
|
|||
|
begin
|
|||
|
comEditors := nil;
|
|||
|
edEditors := nil;
|
|||
|
MemoEditors := nil;
|
|||
|
FScrollBox.Free;
|
|||
|
FScrollBox := nil;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
end.
|
|||
|
|