unit u_sys_dep_emp; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, BusinessSkinForm, bsSkinCtrls, dxExEdtr, dxCntner, dxTL, dxDBCtrl, dxDBGrid, dxDBTLCl, dxGrClms, Grids, DBGridEh; type Tfrm_sys_dep_emp = class(TForm) t_sys_department: TADOQuery; t_sys_department1: TDataSource; t_sys_employee1: TDataSource; t_sys_employee: TADOQuery; bsBusinessSkinForm1: TbsBusinessSkinForm; bsSkinPanel2: TbsSkinPanel; dxDBGrid3: TdxDBGrid; dxDBGrid3Column1: TdxDBGridMaskColumn; dxDBGrid3Column2: TdxDBGridMaskColumn; dxDBGrid3Column3: TdxDBGridMaskColumn; dxDBGrid3Column4: TdxDBGridMaskColumn; dxDBGrid3Column5: TdxDBGridMaskColumn; dxDBGrid3Column6: TdxDBGridMaskColumn; dxDBGrid3Column7: TdxDBGridDateColumn; dxDBGrid3Column8: TdxDBGridMaskColumn; dxDBGrid3Column9: TdxDBGridMaskColumn; dxDBGrid3Column10: TdxDBGridMaskColumn; bsSkinPanel4: TbsSkinPanel; v_all_employee: TADOQuery; bsSkinPanel1: TbsSkinPanel; bsSkinButton1: TbsSkinButton; bsSkinButton2: TbsSkinButton; bsSkinButton4: TbsSkinButton; bsSkinButton3: TbsSkinButton; bsSkinPanel3: TbsSkinPanel; bsSkinButton9: TbsSkinButton; bsSkinButton10: TbsSkinButton; bsSkinButton11: TbsSkinButton; bsSkinButton12: TbsSkinButton; bsSkinButton5: TbsSkinButton; bsSkinButton6: TbsSkinButton; p_employee_change: TADOStoredProc; p_employee_delete: TADOStoredProc; t_sys_code_data: TADOQuery; t_sys_code: TADOQuery; t_sys_code_emp: TADOQuery; t_sys_code_data_all: TADOQuery; p_employee_change_no: TADOStoredProc; p_employee_delete_no: TADOStoredProc; bsSkinButton7: TbsSkinButton; dxDBGrid3Column11: TdxDBGridColumn; DBGridEh1: TDBGridEh; t_sys_departmentDSDesigner: TStringField; t_sys_departmentDSDesigner2: TStringField; t_sys_departmentDSDesigner3: TStringField; t_sys_departmentdept: TStringField; dxDBGrid3Column12: TdxDBGridPickColumn; dxDBGrid3Column13: TdxDBGridPickColumn; dxDBGrid3Column14: TdxDBGridPickColumn; dxDBGrid3Column15: TdxDBGridCheckColumn; dxDBGrid3Column16: TdxDBGridCheckColumn; t_sys_departmentDSDesigner4: TStringField; t_sys_departmentDSDesigner5: TStringField; dxDBGrid1: TdxDBGrid; t_sys_employee_link: TADOQuery; t_sys_employee_link1: TDataSource; dxDBGrid1Column1: TdxDBGridColumn; dxDBGrid3Column17: TdxDBGridPickColumn; dxDBGrid3Column18: TdxDBGridColumn; t_sys_departmentDSDesigner6: TStringField; dxDBGrid3Column19: TdxDBGridPickColumn; dxDBGrid3Column20: TdxDBGridColumn; dxDBGrid3Column21: TdxDBGridColumn; procedure t_sys_departmentBeforePost(DataSet: TDataSet); procedure t_sys_employeeBeforePost(DataSet: TDataSet); procedure FormShow(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); procedure bsSkinButton4Click(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); procedure bsSkinButton9Click(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); procedure bsSkinButton11Click(Sender: TObject); procedure bsSkinButton12Click(Sender: TObject); procedure t_sys_department_twoBeforeInsert(DataSet: TDataSet); procedure t_sys_employeeBeforeInsert(DataSet: TDataSet); procedure t_sys_departmentDeleteError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure bsSkinButton5Click(Sender: TObject); procedure v_all_employeeAfterScroll(DataSet: TDataSet); procedure bsSkinButton6Click(Sender: TObject); procedure t_sys_employeeAfterPost(DataSet: TDataSet); procedure t_sys_employeeBeforeEdit(DataSet: TDataSet); procedure bsSkinButton7Click(Sender: TObject); procedure t_sys_departmentBeforeEdit(DataSet: TDataSet); private { Private declarations } public { Public declarations } end; var frm_sys_dep_emp: Tfrm_sys_dep_emp; dep_emp_insert:boolean; dep_emp_name:string; implementation uses u_main, my_sys_function, u_data_share, u_sys_dep_emp_delete, u_sys_progress, u_sys_dep_emp_department; {$R *.dfm} procedure Tfrm_sys_dep_emp.t_sys_departmentBeforePost( DataSet: TDataSet); begin table_before_post(t_sys_department,'部门名称'); end; procedure Tfrm_sys_dep_emp.t_sys_employeeBeforePost(DataSet: TDataSet); begin table_before_post(t_sys_employee,'姓名'); if t_sys_employee.State=dsinsert then dep_emp_insert:=true else dep_emp_insert:=false; end; procedure Tfrm_sys_dep_emp.FormShow(Sender: TObject); begin t_sys_department.open; t_sys_employee.open; v_all_employee.Open; if not frm_data_share.t_code_subcomp.Active then frm_data_share.t_code_subcomp.Open; t_sys_employee_link.Open; end; procedure Tfrm_sys_dep_emp.FormClose(Sender: TObject; var Action: TCloseAction); begin frm_data_share.t_sys_employee.requery; frm_data_share.t_sys_department.requery; end; procedure Tfrm_sys_dep_emp.bsSkinButton1Click(Sender: TObject); begin t_sys_department.insert; end; procedure Tfrm_sys_dep_emp.bsSkinButton2Click(Sender: TObject); begin table_post(t_sys_department); end; procedure Tfrm_sys_dep_emp.bsSkinButton4Click(Sender: TObject); begin table_delete(t_sys_department); end; procedure Tfrm_sys_dep_emp.bsSkinButton3Click(Sender: TObject); begin table_cancel(t_sys_department); end; procedure Tfrm_sys_dep_emp.bsSkinButton9Click(Sender: TObject); begin t_sys_employee.insert; end; procedure Tfrm_sys_dep_emp.bsSkinButton10Click(Sender: TObject); begin table_post(t_sys_employee); end; procedure Tfrm_sys_dep_emp.bsSkinButton11Click(Sender: TObject); begin if t_sys_employee.IsEmpty then exit; if v_all_employee.IsEmpty then begin if t_sys_employee.State=dsinsert then begin t_sys_employee.cancel; end else begin t_sys_employee.cancel; p_employee_delete_no.Parameters.ParamByName('name').Value:=t_sys_employee['姓名']; p_employee_delete_no.ExecProc; t_sys_employee.delete; end; end else begin try frm_sys_dep_emp_delete:=Tfrm_sys_dep_emp_delete.Create(self); frm_sys_dep_emp_delete.ShowModal; finally frm_sys_dep_emp_delete.Free; frm_sys_dep_emp_delete:=nil; end; end; end; procedure Tfrm_sys_dep_emp.bsSkinButton12Click(Sender: TObject); begin table_cancel(t_sys_employee); end; procedure Tfrm_sys_dep_emp.t_sys_department_twoBeforeInsert( DataSet: TDataSet); begin table_before_insert(t_sys_department); end; procedure Tfrm_sys_dep_emp.t_sys_employeeBeforeInsert(DataSet: TDataSet); begin table_before_insert(t_sys_department); end; procedure Tfrm_sys_dep_emp.t_sys_departmentDeleteError( DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); begin showmessage('存在职员信息,不能删除!'); abort; end; procedure Tfrm_sys_dep_emp.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin CanClose:=frm_close_query(t_sys_department); CanClose:=frm_close_query(t_sys_employee); end; procedure Tfrm_sys_dep_emp.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_sys_dep_emp.v_all_employeeAfterScroll(DataSet: TDataSet); begin if v_all_employee.IsEmpty then dxDBGrid3Column1.ReadOnly:=false else dxDBGrid3Column1.ReadOnly:=true; end; procedure Tfrm_sys_dep_emp.bsSkinButton6Click(Sender: TObject); var old_str,str:string; begin if t_sys_employee.IsEmpty then exit; if v_all_employee.IsEmpty then begin showmessage('此职员姓名在业务中还没有使用,你可以直接更改!'); exit; end; str:=trim(InputBox('请输入职员新的名字', '新的名字:', '')); if str=''then begin exit; end; try old_str:=t_sys_employee['姓名']; t_sys_employee.Edit; t_sys_employee['姓名']:=str; t_sys_employee.post; p_employee_change.Parameters.ParamByName('old_name').Value:=old_str; p_employee_change.Parameters.ParamByName('new_name').Value:=str; p_employee_change.ExecProc; v_all_employee.requery; except showmessage('更改姓名失败'); end; end; procedure Tfrm_sys_dep_emp.t_sys_employeeAfterPost(DataSet: TDataSet); begin if dep_emp_insert then begin if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(self); frm_sys_progress.bsSkinGauge1.ProgressText:='正在创建权限代码。。。'; frm_sys_progress.Show; frm_sys_progress.bsSkinGauge1.MaxValue:=20000; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; t_sys_code.close; t_sys_code.open; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; t_sys_code_data_all.close; t_sys_code_data_all.open; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; t_sys_code_data.close; t_sys_code_data.open; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; t_sys_code_emp.Close; t_sys_code_emp.open; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; frm_data_share.t_sys_employee.requery; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; frm_sys_progress.bsSkinGauge1.MaxValue:=10+t_sys_code.RecordCount +frm_data_share.t_sys_employee.RecordCount*(t_sys_code_data_all.RecordCount*2-1); t_sys_code.first; while not t_sys_code.eof do begin t_sys_code_emp.insert; t_sys_code_emp['权限代码']:=t_sys_code['权限代码']; t_sys_code_emp['一级模块']:=t_sys_code['一级模块']; t_sys_code_emp['二级模块']:=t_sys_code['二级模块']; t_sys_code_emp['权限名称']:=t_sys_code['权限名称']; t_sys_code_emp['人员']:=t_sys_employee['姓名']; t_sys_code_emp['是否可操作']:=0; t_sys_code_emp.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; t_sys_code.next; end; frm_data_share.t_sys_employee.first; while not frm_data_share.t_sys_employee.eof do begin if frm_data_share.t_sys_employee['姓名']<>t_sys_employee['姓名'] then begin t_sys_code_data_all.first; while not t_sys_code_data_all.eof do begin t_sys_code_data.insert; t_sys_code_data['人员']:=frm_data_share.t_sys_employee['姓名']; t_sys_code_data['属性']:=t_sys_code_data_all['属性']; t_sys_code_data['是否可视']:=0; t_sys_code_data['是否操作']:=0; t_sys_code_data['职员']:=t_sys_employee['姓名']; t_sys_code_data.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; t_sys_code_data_all.next; end; end; frm_data_share.t_sys_employee.next; end; frm_data_share.t_sys_employee.first; while not frm_data_share.t_sys_employee.eof do begin t_sys_code_data_all.first; while not t_sys_code_data_all.eof do begin t_sys_code_data.insert; t_sys_code_data['人员']:=t_sys_employee['姓名']; t_sys_code_data['属性']:=t_sys_code_data_all['属性']; t_sys_code_data['是否可视']:=1; t_sys_code_data['是否操作']:=1; t_sys_code_data['职员']:=frm_data_share.t_sys_employee['姓名']; t_sys_code_data.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; t_sys_code_data_all.next; end; frm_data_share.t_sys_employee.next; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; frm_sys_progress.close; frm_sys_progress:=nil; end; if dep_emp_name<>t_sys_employee['姓名'] then begin p_employee_change_no.Parameters.ParamByName('old_name').Value:=dep_emp_name; p_employee_change_no.Parameters.ParamByName('new_name').Value:=t_sys_employee['姓名']; p_employee_change_no.ExecProc; end; end; procedure Tfrm_sys_dep_emp.t_sys_employeeBeforeEdit(DataSet: TDataSet); begin dep_emp_name:=t_sys_employee['姓名']; end; procedure Tfrm_sys_dep_emp.bsSkinButton7Click(Sender: TObject); begin if t_sys_employee.isempty then exit; try frm_sys_dep_emp_department:=Tfrm_sys_dep_emp_department.Create(self); frm_sys_dep_emp_department.ShowModal; finally frm_sys_dep_emp_department.Free; frm_sys_dep_emp_department:=nil; end; end; procedure Tfrm_sys_dep_emp.t_sys_departmentBeforeEdit(DataSet: TDataSet); begin if not t_sys_employee.IsEmpty then begin MessageDlg('本部门存在人员,不能修改部门资料',mtWarning,[mbOk],0); Abort; end; end; end.