📄 worker.pas
字号:
begin //while
if strtoint(fieldbyname('ID').AsString)=i then
begin
Break;
end
else
if i<10 then
result := '000'+inttostr(i)
else
if i<100 then
result:='00'+inttostr(i)
else
if i<1000 then
result:='0'+inttostr(i)
else
if i<10000 then
result:=inttostr(i);
next;
end; //while
end; //for
end;
end;
procedure TWorkerForm.SpeedButton3Click(Sender: TObject);
var
i:integer;
begin
if not speedbutton1.Enabled then
begin
myshowmessage('对不起!正在执行修改操作!');
exit;
end;
speedbutton4.Caption:='&X取消';
speedbutton3.Enabled:=false;
//speedbutton1.Enabled:=false;
speedbutton5.Enabled:=false;
combobox1.Clear;
combobox2.Clear;
edit1.Clear;
edit2.Clear;
edit3.Clear;
edit4.Clear;
edit1.Enabled:=true;
edit2.Enabled:=true;
edit3.Enabled:=true;
edit4.Enabled:=true;
edit1.Visible:=true;
edit2.Visible:=true;
label1.Visible:=true;
label6.Visible:=true;
combobox2.Text:= IDcreate;
combobox2.Enabled:=false;
groupbox1.Enabled:=true;
for i:=0 to groupbox1.ControlCount -1 do
begin
Tcheckbox(groupbox1.Controls[i]).Checked:=false;
end;
end;
procedure TWorkerForm.SpeedButton1Click(Sender: TObject);
begin
if not speedbutton3.Enabled then
begin
myshowmessage('对不起!正在执行添加操作!');
exit;
end;
if data.PublicQuery.Active then
begin
if data.PublicQuery.RecordCount> 0 then
begin
speedbutton4.Caption:='&X取消';
speedbutton1.Enabled:=false;
combobox2.Enabled:=false;
combobox1.clear;
combobox1.Text:=username;
edit3.Enabled:=true;
edit4.Enabled:=true;
edit1.Visible:=true;
edit2.Visible:=true;
label1.Visible:=true;
label6.Visible:=true;
groupbox1.Enabled:=true;
end;
end;
end;
procedure TWorkerForm.SpeedButton2Click(Sender: TObject);
begin
if not speedbutton3.Enabled then // insert
begin
if (Trim(combobox1.Text) <> '') and(Trim(edit3.Text) <> '')and (Trim(edit1.Text) <> '')and (Trim(edit2.Text) <> '')and(Trim(edit4.Text) <> '') then
begin
with data.PublicQuery do
begin
close;
sql.Clear;
sql.Add('select * from worker where username = :username');
parameters.ParamByName('username').Value:=combobox1.Text;
open;
if recordcount < 1 then
begin
if strcomp(pchar(edit1.Text),pchar(edit2.Text))<>0 then
begin
myshowmessage('确认密码不匹配!!');
exit;
end;
close;
sql.Clear;
sql.Add('insert into Worker values(:ID,:Username,:PassWord,:UserGroup,:Name,:PersonID)');
parameters.ParamByName('id').Value:=combobox2.Text;
parameters.ParamByName('Username').Value:=combobox1.Text;
parameters.ParamByName('PassWord').Value:=edit1.Text;
parameters.ParamByName('UserGroup').Value:='';
parameters.ParamByName('Name').Value:=edit3.Text;
parameters.ParamByName('PersonID').Value:=edit4.Text;
execsql;
close;
sql.Clear;
sql.Add('insert into userpower values(:UserName,:Base,:InManage,:Lendandsell,:analyze,:system,:supervisor)');
parameters.ParamByName('UserName').Value:=combobox1.Text;
if checkbox6.Checked then
parameters.ParamByName('supervisor').Value:=1
else
parameters.ParamByName('supervisor').Value:=0;
if checkbox1.Checked then
parameters.ParamByName('Base').Value:=1
else
parameters.ParamByName('Base').Value:=0;
if checkbox2.Checked then
parameters.ParamByName('InManage').Value:=1
else
parameters.ParamByName('InManage').Value:=0;
if checkbox3.Checked then
parameters.ParamByName('Lendandsell').Value:=1
else
parameters.ParamByName('Lendandsell').Value:=0;
if checkbox4.Checked then
parameters.ParamByName('analyze').Value:=1
else
parameters.ParamByName('analyze').Value:=0;
if checkbox5.Checked then
parameters.ParamByName('system').Value:=1
else
parameters.ParamByName('system').Value:=0;
execsql;
end
else
begin
myshowmessage('对不起!该用户已经存在');
exit;
end;
end;
end;
end;
if not speedbutton1.Enabled then //change
begin // if not enabled
if (Trim(combobox1.Text) <> '') and (Trim(edit3.Text) <> '')and (Trim(edit4.Text) <> '') then
begin
with data.PublicQuery do
begin
close;
sql.Clear;
sql.Add('select * from worker where username = :username');
parameters.ParamByName('username').Value:=combobox1.Text;
open;
if recordcount <1 then
begin
myshowmessage('对不起!修改的用户名已经存在!');
exit;
end
else
begin
if strcomp(pchar(edit1.Text),pchar(edit2.Text))=0 then
begin
if (edit1.Text='') and (edit2.Text='') then
begin
close;
sql.Clear;
sql.Add('update Worker set Username=:Username,UserGroup=:UserGroup,Name=:Name,PersonID=:PersonID where ID=:id');
parameters.ParamByName('id').Value:=combobox2.Text;
parameters.ParamByName('Username').Value:=combobox1.Text;
parameters.ParamByName('UserGroup').Value:='';
parameters.ParamByName('Name').Value:=edit3.Text;
parameters.ParamByName('PersonID').Value:=edit4.Text;
execsql;
end
else
begin
close;
sql.Clear;
sql.Add('update Worker set Username=:Username,PassWord=:PassWord,UserGroup=:UserGroup,Name=:Name,PersonID=:PersonID where ID=:id');
parameters.ParamByName('id').Value:=combobox2.Text;
parameters.ParamByName('Username').Value:=combobox1.Text;
parameters.ParamByName('PassWord').Value:=edit1.Text;
parameters.ParamByName('UserGroup').Value:='';
parameters.ParamByName('Name').Value:=edit3.Text;
parameters.ParamByName('PersonID').Value:=edit4.Text;
execsql;
end;
close;
sql.Clear;
sql.Add('update userpower set UserName=:UserName,Base=:Base,InManage=:InManage,Lendandsell=:Lendandsell,analyze=:analyze,system=:system,supervisor=:supervisor where username=:usernameOLD');
parameters.ParamByName('usernameold').Value:=username;
parameters.ParamByName('UserName').Value:=combobox1.Text;
if checkbox6.Checked then
parameters.ParamByName('supervisor').Value:=1
else
parameters.ParamByName('supervisor').Value:=0;
if checkbox1.Checked then
parameters.ParamByName('Base').Value:=1
else
parameters.ParamByName('Base').Value:=0;
if checkbox2.Checked then
parameters.ParamByName('InManage').Value:=1
else
parameters.ParamByName('InManage').Value:=0;
if checkbox3.Checked then
parameters.ParamByName('Lendandsell').Value:=1
else
parameters.ParamByName('Lendandsell').Value:=0;
if checkbox4.Checked then
parameters.ParamByName('analyze').Value:=1
else
parameters.ParamByName('analyze').Value:=0;
if checkbox5.Checked then
parameters.ParamByName('system').Value:=1
else
parameters.ParamByName('system').Value:=0;
execsql;
end
else
begin
myshowmessage('请确认密码?');
exit;
end;
end;
end;
end
else
begin
myshowmessage('输入不完全!');
exit;
end;
end; //if not e
formshow(self);
end;
procedure TWorkerForm.SpeedButton5Click(Sender: TObject);
begin
if speedbutton3.Enabled or speedbutton4.Enabled then
if combobox2.Text<>'' then
if myshowmessage('确定要删除此用户吗?') then
//if messagebox(self.Handle,'确定要删除此用户吗?','提示',MB_YESNO)= ID_YES then
begin
with data.PublicQuery do
begin
close;
sql.Clear;
sql.Add('delete from worker where username=:username');
parameters.ParamByName('username').value:=username;
execsql;
close;
sql.Clear;
sql.Add('delete from userpower where username=:username');
parameters.ParamByName('username').Value:=username;
execsql;
end;
formshow(self);
end;
end;
procedure TWorkerForm.CheckBox6Click(Sender: TObject);
var
i:integer;
begin
if checkbox6.Checked then
for i:=0 to groupbox1.ControlCount -1 do
begin
Tcheckbox(groupbox1.Controls[i]).Checked:=true;
end;
end;
procedure TWorkerForm.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
edit4.SetFocus;
end;
procedure TWorkerForm.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
edit1.SetFocus;
end;
procedure TWorkerForm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
edit2.SetFocus;
end;
procedure TWorkerForm.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
checkbox1.SetFocus;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -