📄 usermanage.pas
字号:
begin
str := '';
try
if not DataModule1.ADOConnection1.Connected then
DataModule1.ADOConnection1.Connected := true;
DataModule1.ADOCommand1.CommandText := '';
DataModule1.ADOCommand1.CommandText := 'select groupId,groupName from t_group';
DataModule1.ADOCommand1.Prepared := true;
DataModule1.ADODataSet1.Recordset := DataModule1.ADOCommand1.Execute;
if DataModule1.ADODataSet1.Recordset.RecordCount < 1 then exit
else
begin
DataModule1.ADODataSet1.Recordset.MoveFirst;
for I := 0 to DataModule1.ADODataSet1.Recordset.RecordCount - 1 do // Iterate
begin
str := Trim(DataModule1.ADODataSet1.Recordset.Fields.Item[0].Value);
str := str + ' ' + trim(DataModule1.ADODataSet1.Recordset.Fields.Item[1].Value);
ComboBox.Items.Add(str);
DataModule1.ADODataSet1.Recordset.MoveNext;
end;
end;
except on e: Exception do
showmessage(e.Message);
end;
end;
procedure TfrmUserManage.ShowGroupPrivilege(sName:string);
var
str,sTemp :string;
iPos ,i: integer;
begin
for I := 0 to GridGroupPri.RowCount - 1 do // Iterate
begin
GridGrouppri.RowCount := GridGroupPri.RowCount - 1;
end; // for
GridGroupPri.Cells[0,0] := '';
GridGroupPri.Cells[1,0] := '';
try
if not DataModule1.ADOConnection1.Connected then
DataModule1.ADOConnection1.Connected := true;
DataModule1.ADOCommand1.CommandText := '';
DataModule1.ADOCommand1.CommandText := Format('select gDesc from t_group where groupName = ''%s''',[sName]);
DataModule1.ADOCommand1.Prepared := true;
DataModule1.ADODataSet1.Recordset := DataModule1.ADOCommand1.Execute;
if DataModule1.ADODataSet1.Recordset.RecordCount < 1 then exit
else
begin
str := DataModule1.ADODataSet1.Recordset.Fields.Item[0].Value;
while pos(',',str) > 0 do
begin
iPos := pos(',',str);
sTemp := Copy(str,1,iPos - 1);
GridGroupPri.RowCount := GridGroupPri.RowCount + 1;
case Length(sTemp) of
1:
begin
GridGroupPri.Cells[0,GridGroupPri.RowCount - 2] := frmShow.MainMenu1.Items[strtoint(sTemp)].Caption;
end;
2:
begin
GridGroupPri.Cells[0,GridGroupPri.RowCount - 2] := ' '+frmShow.MainMenu1.Items[strtoint(copy(sTemp,1,1))].Items[strtoint(copy(sTemp,2,1))].Caption;
end;
3:
begin
GridGroupPri.Cells[0,GridGroupPri.RowCount - 2] := ' '+frmShow.MainMenu1.Items[strtoint(copy(sTemp,1,1))].Items[strtoint(copy(sTemp,2,1))].Items[strtoint(copy(sTemp,3,1))].Caption;
end;
end; // case
GridGroupPri.Cells[1,GridGroupPri.RowCount - 2] := sTemp;
str := Copy(str,iPos + 1,Length(str));
end;
end;
except on e: Exception do
showmessage(e.Message);
end;
GridGroupPri.RowCount := GridGroupPri.RowCount - 1;
end;
procedure TfrmUserManage.ComboBox1Change(Sender: TObject);
var
str:string;
begin
str := trim(ComboBox1.Text);
str := copy(str,5,Length(str)-4);
//ShowSysPrivilege;
ShowGroupPrivilege(str);
end;
procedure TfrmUserManage.AddPriClick(Sender: TObject);
var
lId,lName:string;
i,j,RowPos:integer;
MaxId:string;
iCount :integer;
begin
iCount := 0;
MaxId := '';
RowPos := -1;
lId := trim(GridSysPri.Cells[1,row2]);
lName := trim(GridSysPri.Cells[0,row2]);
if Length(lId) = 1 then exit;
if Length(lId) = 2 then
begin
if Length(trim(GridSysPri.Cells[1,row2+1])) > 2 then
exit;
end;
for I := 0 to GridGroupPri.RowCount - 1 do
begin
if trim(GridGroupPri.Cells[1,i]) = lId then
Exit;
end;
case Length(lId) of
// 1:
// begin
// for I := 0 to GridGroupPri.RowCount - 1 do
// begin
// if Length(GridGroupPri.Cells[1,i]) = 1 then
// MaxId := Max();
// end;
// end;
2:
begin
for I := 0 to GridGroupPri.RowCount - 2 do
begin
if trim(GridGroupPri.Cells[1,i]) = copy(lId,1,1) then
begin
//for j := i to GridGroupPri.RowCount - 2 do
// begin
// if (Length(trim(GridGroupPri.Cells[1,j])) = 2) then
// begin
// if Copy(trim(GridGroupPri.Cells[1,j]),1,1)=copy(lId,1,1) then
// iCount := iCount + 1;
// end;
// end;
// for j := i + 1 to i + iCount do // Iterate
// begin
// if strtoint(Copy(trim(GridGroupPri.Cells[1,j]),2,1)) > strtoint(copy(lId,2,1)) then
// RowPos := i - 1
// else
// RowPos := i + 1;
// end;
RowPos := i;
GridGroupPri.RowCount := GridGroupPri.RowCount + 1;
GridGroupPri.Cells[0,GridGroupPri.RowCount - 2] := ' '+frmShow.MainMenu1.Items[strtoint(copy(lId,1,1))].Items[strtoint(copy(lId,2,1))].Caption;
GridGroupPri.Cells[1,GridGroupPri.RowCount - 2] := lId;
if RowPos >= 0 then
GridGroupPri.RowMoved(GridGroupPri.RowCount-2,RowPos+1);
Exit;
end;
end;
GridGroupPri.RowCount := GridGroupPri.RowCount + 1;
GridGroupPri.Cells[0,GridGroupPri.RowCount - 2] := frmShow.MainMenu1.Items[strtoint(copy(lId,1,1))].Caption;
GridGroupPri.Cells[1,GridGroupPri.RowCount - 2] := copy(lId,1,1);
GridGroupPri.RowCount := GridGroupPri.RowCount + 1;
GridGroupPri.Cells[0,GridGroupPri.RowCount - 2] := ' '+frmShow.MainMenu1.Items[strtoint(copy(lId,1,1))].Items[strtoint(copy(lId,2,1))].Caption;
GridGroupPri.Cells[1,GridGroupPri.RowCount - 2] := lId;
end;
3:
begin
for I := 0 to GridGroupPri.RowCount - 1 do
begin
if trim(GridGroupPri.Cells[1,i]) = copy(lId,1,2) then
begin
RowPos := i;
GridGroupPri.RowCount := GridGroupPri.RowCount + 1;
GridGroupPri.Cells[0,GridGroupPri.RowCount - 2] := ' '+frmShow.MainMenu1.Items[strtoint(copy(lId,1,1))].Items[strtoint(copy(lId,2,1))].Items[strtoint(copy(lId,3,1))].Caption;
GridGroupPri.Cells[1,GridGroupPri.RowCount - 2] := lId;
if RowPos >= 0 then
GridGroupPri.RowMoved(GridGroupPri.RowCount-2,RowPos+1);
exit;
end;
end;
for I := 0 to GridGroupPri.RowCount - 1 do
begin
if trim(GridGroupPri.Cells[1,i]) = copy(lId,1,1) then
begin
RowPos := i;
GridGroupPri.RowCount := GridGroupPri.RowCount + 1;
GridGroupPri.Cells[0,GridGroupPri.RowCount - 2] := ' '+frmShow.MainMenu1.Items[strtoint(copy(lId,1,1))].Items[strtoint(copy(lId,2,1))].Caption;
GridGroupPri.Cells[1,GridGroupPri.RowCount - 2] := copy(lId,1,2);
if RowPos >= 0 then
GridGroupPri.RowMoved(GridGroupPri.RowCount-2,RowPos+1);
GridGroupPri.RowCount := GridGroupPri.RowCount + 1;
GridGroupPri.Cells[0,GridGroupPri.RowCount - 2] := ' '+frmShow.MainMenu1.Items[strtoint(copy(lId,1,1))].Items[strtoint(copy(lId,2,1))].Items[strtoint(copy(lId,3,1))].Caption;
GridGroupPri.Cells[1,GridGroupPri.RowCount - 2] := lId;
if RowPos >= 0 then
GridGroupPri.RowMoved(GridGroupPri.RowCount-2,RowPos+2);
exit;
end;
end;
GridGroupPri.RowCount := GridGroupPri.RowCount + 1;
GridGroupPri.Cells[0,GridGroupPri.RowCount - 2] := frmShow.MainMenu1.Items[strtoint(copy(lId,1,1))].Caption;
GridGroupPri.Cells[1,GridGroupPri.RowCount - 2] := copy(lId,1,1);
GridGroupPri.RowCount := GridGroupPri.RowCount + 1;
GridGroupPri.Cells[0,GridGroupPri.RowCount - 2] := ' '+frmShow.MainMenu1.Items[strtoint(copy(lId,1,1))].Items[strtoint(copy(lId,2,1))].Caption;
GridGroupPri.Cells[1,GridGroupPri.RowCount - 2] := copy(lId,1,2);
GridGroupPri.RowCount := GridGroupPri.RowCount + 1;
GridGroupPri.Cells[0,GridGroupPri.RowCount - 2] := ' '+frmShow.MainMenu1.Items[strtoint(copy(lId,1,1))].Items[strtoint(copy(lId,2,1))].Items[strtoint(copy(lId,3,1))].Caption;
GridGroupPri.Cells[1,GridGroupPri.RowCount - 2] := lId;
end;
end;
//GridGroupPri.RowCount := GridGroupPri.RowCount - 1;
end;
procedure TfrmUserManage.DelPriClick(Sender: TObject);
begin
if GridGroupPri.RowCount > 1 then
begin
GridGroupPri.DeleteRow(row3);
end
else
begin
GridGroupPri.Cells[0,0] := '';
GridGroupPri.Cells[1,0] := '';
end;
end;
procedure TfrmUserManage.FormShow(Sender: TObject);
begin
UserUnregister;
CheckBox1.Checked := false;
CheckBox2.Checked := false;
CheckBox3.Checked := false;
with GridGroup do
begin
parent := self.GroupBox2;
Left := 6;
Top := 42;
Width := 217;
Height := 271;
ColCount := 2;
DefaultColWidth := 210 ;
Enabled := False ;
FixedCols := 0;
RowCount := 1 ;
FixedRows := 0;
GridLineWidth := 2 ;
Options := [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSelect];//
PopupMenu := PopupMenu1;
ScrollBars := ssVertical;
TabOrder := 0;
OnSelectCell := frmUserManage.GridGroupSelectCell ;
show;
end;
with GridSysPri do
begin
parent := self.GroupBox3;
Left := 6 ;
Top := 18 ;
Width := 217 ;
Height := 487 ;
ColCount := 2 ;
DefaultColWidth := 210 ;
Enabled := False ;
FixedCols := 0 ;
RowCount := 1 ;
FixedRows := 0 ;
GridLineWidth := 2 ;
Options := [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSelect] ;
//ScrollBars := ssVertical;
TabOrder := 0 ;
OnClick := frmUserManage.GridSysPriClick ;
OnSelectCell := frmUserManage.GridSysPriSelectCell ;
show;
end; // with
with GridGroupPri do
begin
parent := self.GroupBox4;
Left := 6 ;
Top := 48 ;
Width := 217 ;
Height := 487 ;
ColCount := 2 ;
DefaultColWidth := 210 ;
Enabled := False ;
FixedCols := 0 ;
RowCount := 1 ;
FixedRows := 0 ;
GridLineWidth := 2 ;
Options := [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSelect];
//ScrollBars := ssVertical;
TabOrder := 1 ;
OnClick := frmUserManage.GridGroupPriClick ;
OnSelectCell := frmUserManage.GridGroupPriSelectCell ;
show;
end; // with
end;
procedure TfrmUserManage.FormCreate(Sender: TObject);
begin
GridGroupPri := TStringGridEx.Create(self);
GridGroup := TStringGridEx.Create(self);
GridSysPri := TStringGridEx.Create(self);
end;
Procedure TfrmUserManage.GridSort(StrGrid: TStringGrid; NoColumn: Integer);
Var
Line, PosActual: Integer;
Row: TStrings;
//Renglon :TStringList;
begin
//Renglon := TStringList.Create;
For Line := 1 to StrGrid.RowCount-2 do
Begin
Row := nil;
PosActual := Line;
Row := StrGrid.Rows[PosActual]; //TStringlist
While True do
Begin
If (PosActual = 0) Or (StrToInt(Row.Strings[NoColumn-1]) >= StrToInt(StrGrid.Cells[NoColumn-1,PosActual-1])) then
Break;
StrGrid.Rows[PosActual] := StrGrid.Rows[PosActual-1];
Dec(PosActual);
End;
If StrToInt(Row.Strings[NoColumn-1]) < StrToInt(StrGrid.Cells[NoColumn-1,PosActual]) then
StrGrid.Rows[PosActual] := Row;
End;
//Renglon.Free;
end;
procedure TfrmUserManage.UserUnregister;
begin
Edit1.Enabled := false;
Edit2.Enabled := false;
Edit3.Enabled := false;
ComboBox2.Enabled := false;
Button1.Enabled := false;
Button2.Enabled := false;
Edit1.Text := '';
Edit2.Text := '';
Edit3.Text := '';
ComboBox2.Items.Clear;
ComboBox2.Text := '';
end;
procedure TfrmUserManage.UserRegister;
begin
Edit1.Enabled := true;
Edit2.Enabled := true;
Edit3.Enabled := true;
ComboBox2.Enabled := true;
Button1.Enabled := true;
Button2.Enabled := true;
Edit1.Text := '';
Edit2.Text := '';
Edit3.Text := '';
ComboBox2.Items.Clear;
ComboBox2.Text := '';
end;
procedure TfrmUserManage.CheckBox3Click(Sender: TObject);
begin
if CheckBox3.Checked then
UserRegister
else
UserUnregister;
end;
procedure TfrmUserManage.ComboBox2DropDown(Sender: TObject);
begin
ComboBox2.Items.Clear;
ShowGroupName(ComboBox2);
end;
procedure TfrmUserManage.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
GridGroupPri.Free;
GridGroup.Free;
GridSysPri.Free;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -