unit lcxQxsz; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, bsSkinData, BusinessSkinForm, bsSkinCtrls, DB, ADODB,inifiles; type TfrmLcxQxsz = class(TForm) db_load: TADOConnection; btnqxrestore: TbsSkinButton; bsSkinButton4: TbsSkinButton; btnqxBack: TbsSkinButton; bsBusinessSkinForm1: TbsBusinessSkinForm; bsStoredSkin1: TbsStoredSkin; bsSkinData1: TbsSkinData; bsSkinGroupBox1: TbsSkinGroupBox; chkseae: TbsSkinCheckRadioBox; chkseaei: TbsSkinCheckRadioBox; chkair: TbsSkinCheckRadioBox; chkairi: TbsSkinCheckRadioBox; qrytmp: TADOQuery; qryUpdate: TADOQuery; bsSkinCheckRadioBox1: TbsSkinCheckRadioBox; procedure FormShow(Sender: TObject); procedure db_loadBeforeConnect(Sender: TObject); procedure bsSkinButton4Click(Sender: TObject); procedure btnqxBackClick(Sender: TObject); procedure btnqxrestoreClick(Sender: TObject); private function connect_string(file_name:string):string; { Private declarations } public { Public declarations } end; var frmLcxQxsz: TfrmLcxQxsz; implementation uses u_sys_login; {$R *.dfm} procedure TfrmLcxQxsz.FormShow(Sender: TObject); begin db_load.Connected:=true ; frm_sys_login:=Tfrm_sys_login.create(self); if frm_sys_login.showmodal=mrok then begin with qrytmp,sql do //检查上次还原情况 begin close ;clear ; add('select count(*)as cnt from t_sys_code_emp_back '); open ; btnqxrestore.Enabled:= fieldbyname('cnt').AsInteger>0 ; btnqxBack.Enabled:= not btnqxrestore.Enabled ; end; end ; frm_sys_login.free ; end; procedure TfrmLcxQxsz.db_loadBeforeConnect(Sender: TObject); begin db_load.ConnectionString:=connect_string('main.ini'); end; function TfrmLcxQxsz.connect_string(file_name:string):string; var str:string; inifile1:Tinifile; begin inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+file_name); str:=''; str:='Provider='+inifile1.ReadString('database','Provider',''); str:=str+'Password='+inifile1.ReadString('database','Password',''); str:=str+'Persist Security Info='+inifile1.ReadString('database','Persist Security Info',''); str:=str+'User ID='+inifile1.ReadString('database','User ID',''); str:=str+'Initial Catalog='+inifile1.ReadString('database','Initial Catalog',''); str:=str+'Data Source='+inifile1.ReadString('database','Data Source',''); result:=str; inifile1.Free; end; procedure TfrmLcxQxsz.bsSkinButton4Click(Sender: TObject); begin close ; end; procedure TfrmLcxQxsz.btnqxBackClick(Sender: TObject); var str :string ; begin with qrytmp,sql do //检查上次还原情况 begin close ;clear ; add('select count(*)as cnt from t_sys_code_emp_back '); open ; if fieldbyname('cnt').AsInteger>0 then begin if Application.MessageBox('上次取消权限未还原,是否覆盖?', '提示', MB_ICONQUESTION + MB_YESNO + MB_DEFBUTTON2) <> IDYES then Abort; end ; end ; with qrytmp,sql do // 删除备份权限 begin close ;clear ; add('delete from t_sys_code_emp_back '); execsql ; end ; with qrytmp,sql do ///备份权限 begin close ; clear ; add('insert into t_sys_code_emp_back(权限代码, 一级模块, 二级模块,权限名称,人员,是否可操作,授权人, 授权日期,取消日期) '); add('select 权限代码, 一级模块, 二级模块,权限名称,人员,是否可操作,授权人, 授权日期,'''+datetostr(date)+''''); add('from t_sys_code_emp where (1=1)'); if chkseae.Checked then str:='(权限代码='''+'023'''+')or(权限代码='''+'022'''+')' ; if chkseaei.Checked then begin if str<>'' then str:=str+ 'or (权限代码='''+'055'''+')'+'or(权限代码='''+'056'''+')' else str:='(权限代码='''+'022'''+')'+'or(权限代码='''+'056'''+')' ; end ; if chkair.Checked then begin if str<>'' then str:=str+ 'or (权限代码='''+'073'''+')'+'or(权限代码='''+'074'''+')' else str:='(权限代码='''+'073'''+')'+'or(权限代码='''+'074'''+')' ; end ; if chkairi.Checked then begin if str<>'' then str:=str+ 'or (权限代码='''+'081'''+')'+'or(权限代码='''+'082'''+')' else str:='(权限代码='''+'081'''+')'+'or(权限代码='''+'082'''+')' ; end ; if str='' then exit else add('and ('+str+')'); execsql ; end ; with qrytmp,sql do // 权限库清零 begin close ;clear ; add('update t_sys_code_emp set 是否可操作=0 where (1=1) '); if str='' then exit else add('and ('+str+')'); execsql ; end ; with qrytmp,sql do begin close ; clear ; add('update t_sys_parameters_value set 参数值='+''''+'TRUE'+''''); add(' where VL_ID=109 '); execsql ; end ; showmessage('成功取消权限!'); btnqxrestore.Enabled:= true ; btnqxBack.Enabled:= not btnqxrestore.Enabled ; end; procedure TfrmLcxQxsz.btnqxrestoreClick(Sender: TObject); begin with qrytmp,sql do //检查还原备份 begin close ;clear ; add('select count(*)as cnt from t_sys_code_emp_back '); open ; if fieldbyname('cnt').AsInteger<=0 then begin showmessage('没有找到备份权限,不能还原!'); exit; end ; end ; with qrytmp,sql do //修改权限表 begin close ;clear ; add('select * from t_sys_code_emp_back'); open ; first ; while not eof do begin qryUpdate.Close ; qryUpdate.Parameters.ParamByName('mypermiss').Value:=fieldbyname('是否可操作').Value ; qryUpdate.Parameters.ParamByName('myqxdm').Value:=fieldbyname('权限代码').Value ; qryUpdate.Parameters.ParamByName('myuser').Value:=fieldbyname('人员').Value ; qryUpdate.ExecSQL ; next ; end ; end ; // 删除备份权限库 with qrytmp,sql do // 删除备份权限 begin close ;clear ; add('delete from t_sys_code_emp_back '); execsql ; end ; with qrytmp,sql do begin close ; clear ; add('update t_sys_parameters_value set 参数值='+''''+'FALSE'+''''); add(' where VL_ID=109 '); execsql ; end ; showmessage('还原成功!'); btnqxBack.Enabled:= true ; btnqxrestore.Enabled:= not btnqxrestore.Enabled ; end; end.