U_QXGL_GNSZ.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:4k
- unit U_QXGL_GNSZ;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Forms, Dialogs, Controls, StdCtrls,
- Buttons, ExtCtrls, ComCtrls;
- type
- TfrmQXGL_GNB = class(TForm)
- Panel1: TPanel;
- StatusBar1: TStatusBar;
- SrcLabel: TLabel;
- DstLabel: TLabel;
- IncludeBtn: TSpeedButton;
- IncAllBtn: TSpeedButton;
- ExcludeBtn: TSpeedButton;
- ExAllBtn: TSpeedButton;
- SrcList: TListBox;
- Dstlist: TListBox;
- Panel2: TPanel;
- btnOK: TSpeedButton;
- btnCancel: TSpeedButton;
- procedure IncludeBtnClick(Sender: TObject);
- procedure ExcludeBtnClick(Sender: TObject);
- procedure IncAllBtnClick(Sender: TObject);
- procedure ExcAllBtnClick(Sender: TObject);
- procedure SrcListDblClick(Sender: TObject);
- procedure DstlistDblClick(Sender: TObject);
- procedure btnOKClick(Sender: TObject);
- procedure btnCancelClick(Sender: TObject);
- procedure FormActivate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- {移动两个列表框的函数}
- procedure MoveSelected(List: TCustomListBox; Items: TStrings);
- procedure SetItem(List: TListBox; Index: Integer);
- function GetFirstSelection(List: TCustomListBox): Integer;
- procedure SetButtons;
- end;
- var
- frmQXGL_GNB: TfrmQXGL_GNB;
- implementation
- uses U_qxgl_zhsz, WzglDB;
- {$R *.DFM}
- procedure TfrmQXGL_GNB.IncludeBtnClick(Sender: TObject);
- var
- Index: Integer;
- begin
- Index := GetFirstSelection(SrcList);
- MoveSelected(SrcList, DstList.Items);
- SetItem(SrcList, Index);
- end;
- procedure TfrmQXGL_GNB.ExcludeBtnClick(Sender: TObject);
- var
- Index: Integer;
- begin
- Index := GetFirstSelection(DstList);
- MoveSelected(DstList, SrcList.Items);
- SetItem(DstList, Index);
- end;
- procedure TfrmQXGL_GNB.IncAllBtnClick(Sender: TObject);
- var
- I: Integer;
- begin
- for I := 0 to SrcList.Items.Count - 1 do
- DstList.Items.AddObject(SrcList.Items[I],
- SrcList.Items.Objects[I]);
- SrcList.Items.Clear;
- SetItem(SrcList, 0);
- end;
- procedure TfrmQXGL_GNB.ExcAllBtnClick(Sender: TObject);
- var
- I: Integer;
- begin
- for I := 0 to DstList.Items.Count - 1 do
- SrcList.Items.AddObject(DstList.Items[I], DstList.Items.Objects[I]);
- DstList.Items.Clear;
- SetItem(DstList, 0);
- end;
- procedure TfrmQXGL_GNB.MoveSelected(List: TCustomListBox; Items: TStrings);
- var
- I: Integer;
- begin
- for I := List.Items.Count - 1 downto 0 do
- if List.Selected[I] then
- begin
- Items.AddObject(List.Items[I], List.Items.Objects[I]);
- List.Items.Delete(I);
- end;
- end;
- procedure TfrmQXGL_GNB.SetButtons;
- var
- SrcEmpty, DstEmpty: Boolean;
- begin
- SrcEmpty := SrcList.Items.Count = 0;
- DstEmpty := DstList.Items.Count = 0;
- IncludeBtn.Enabled := not SrcEmpty;
- IncAllBtn.Enabled := not SrcEmpty;
- ExcludeBtn.Enabled := not DstEmpty;
- ExAllBtn.Enabled := not DstEmpty;
- end;
- function TfrmQXGL_GNB.GetFirstSelection(List: TCustomListBox): Integer;
- begin
- for Result := 0 to List.Items.Count - 1 do
- if List.Selected[Result] then Exit;
- Result := LB_ERR;
- end;
- procedure TfrmQXGL_GNB.SetItem(List: TListBox; Index: Integer);
- var
- MaxIndex: Integer;
- begin
- with List do
- begin
- SetFocus;
- MaxIndex := List.Items.Count - 1;
- if Index = LB_ERR then Index := 0
- else if Index > MaxIndex then Index := MaxIndex;
- Selected[Index] := True;
- end;
- SetButtons;
- end;
- procedure TfrmQXGL_GNB.SrcListDblClick(Sender: TObject);
- begin
- includebtn.Click;
- end;
- procedure TfrmQXGL_GNB.DstlistDblClick(Sender: TObject);
- begin
- excludebtn.Click;
- end;
- //更新具体组号的权限
- procedure TfrmQXGL_GNB.btnOKClick(Sender: TObject);
- var
- i: integer;
- begin
- with DM do
- begin
- CDS_QXGL_ZHNR.First;
- while not CDS_QXGL_ZHNR.Eof do
- begin
- CDS_QXGL_ZHNR.Delete;
- end;
- CDS_QXGL_ZHSZ.ApplyUpdates(0);
- for i := 0 to dstlist.items.count - 1 do
- begin
- CDS_QXGL_ZHNR.insert;
- CDS_QXGL_ZHNR.FieldByName('功能项').asstring := dstlist.Items.Strings[i];
- CDS_QXGL_ZHNR.post;
- end;
- CDS_QXGL_ZHSZ.applyupdates(0);
- end;
- close;
- end;
- procedure TfrmQXGL_GNB.btnCancelClick(Sender: TObject);
- begin
- close;
- end;
- procedure TfrmQXGL_GNB.FormActivate(Sender: TObject);
- begin
- if srclist.Items.Count > 0 then
- begin
- Includebtn.Enabled := true;
- IncAllbtn.Enabled := True;
- end;
- if Dstlist.Items.Count > 0 then
- begin
- ExcludeBtn.Enabled := true;
- ExAllbtn.Enabled := True;
- end;
- end;
- end.