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, Menus; 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; dxDBGrid1: TdxDBGrid; dxDBGrid1Column1: TdxDBGridMaskColumn; 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; bsSkinButton8: TbsSkinButton; dxDBGrid3Column12: TdxDBGridCheckColumn; bsSkinButton13: TbsSkinButton; ADOQuery1: TADOQuery; dxDBGrid3Column13: TdxDBGridDateColumn; dxDBGrid3Column14: TdxDBGridDateColumn; PopupMenu1: TPopupMenu; N1: TMenuItem; N2: TMenuItem; N3: TMenuItem; dxDBGrid1Column2: TdxDBGridCheckColumn; dxDBGrid1Column3: TdxDBGridColumn; dxDBGrid3Column15: 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 bsSkinButton8Click(Sender: TObject); procedure t_sys_employeeAfterInsert(DataSet: TDataSet); procedure N3Click(Sender: TObject); procedure N1Click(Sender: TObject); procedure bsSkinButton13Click(Sender: TObject); private function isopvisible(emp,otemp,quan:string):Integer; { 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; 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['是否可视']:=isopvisible(t_sys_employee.fieldbyname('部门名称').AsString,frm_data_share.t_sys_employee['姓名'],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['是否可视']:=0; t_sys_code_data['是否操作']:=0; 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; t_sys_code_data.insert; t_sys_code_data['人员']:=t_sys_employee['姓名']; t_sys_code_data['属性']:='3006'; t_sys_code_data['是否可视']:=0; t_sys_code_data['是否操作']:=0; t_sys_code_data['职员']:='底价构成'; t_sys_code_data.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; t_sys_code_data.insert; t_sys_code_data['人员']:=t_sys_employee['姓名']; t_sys_code_data['属性']:='3006'; t_sys_code_data['是否可视']:=0; t_sys_code_data['是否操作']:=0; t_sys_code_data['职员']:='二级售价'; t_sys_code_data.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; t_sys_code_data.insert; t_sys_code_data['人员']:=t_sys_employee['姓名']; t_sys_code_data['属性']:='3006'; t_sys_code_data['是否可视']:=0; t_sys_code_data['是否操作']:=0; t_sys_code_data['职员']:='全包底价'; t_sys_code_data.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; t_sys_code_data.insert; t_sys_code_data['人员']:=t_sys_employee['姓名']; t_sys_code_data['属性']:='3006'; t_sys_code_data['是否可视']:=0; t_sys_code_data['是否操作']:=0; t_sys_code_data['职员']:='三级售价'; t_sys_code_data.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; t_sys_code_data.insert; t_sys_code_data['人员']:=t_sys_employee['姓名']; t_sys_code_data['属性']:='3006'; t_sys_code_data['是否可视']:=0; t_sys_code_data['是否操作']:=0; t_sys_code_data['职员']:='一级售价'; t_sys_code_data.post; 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.bsSkinButton8Click(Sender: TObject); begin if t_sys_employee.IsEmpty then exit; if t_sys_employee['停用']=0 then begin t_sys_employee.Edit; t_sys_employee['停用']:=1; t_sys_employee.Post; end else begin t_sys_employee.Edit; t_sys_employee['停用']:=0; t_sys_employee.Post; end; end; procedure Tfrm_sys_dep_emp.t_sys_employeeAfterInsert(DataSet: TDataSet); begin t_sys_employee['停用']:=0; end; procedure Tfrm_sys_dep_emp.N3Click(Sender: TObject); var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select * from t_op_seae where 揽货人='''+t_sys_employee.fieldByName('姓名').AsString+''' and 销售部门<>'''+t_sys_employee.fieldByName('部门名称').AsString+''' and (开船日期 between '''+t_sys_employee.fieldByName('启用日期').AsString+''' and '''+t_sys_employee.fieldByName('停用日期').AsString+''')'); Open; First; while not eof do begin Edit; FieldByName('销售部门').AsString:=t_sys_employee.fieldByName('部门名称').AsString; Post; Next; end; end; finally FreeAndNil(aQuery); end; end; procedure Tfrm_sys_dep_emp.N1Click(Sender: TObject); 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 IF NOT t_sys_code_emp.Locate('权限代码;人员',VarArrayOf([t_sys_code['权限代码'],t_sys_employee['姓名']]),[]) then 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; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; t_sys_code.next; end; ADOQuery1.Open; 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 if not ADOQuery1.Locate('人员;属性;职员',VarArrayOf([frm_data_share.t_sys_employee.FieldByName('姓名').asstring,t_sys_code_data_all.FieldByName('属性').asstring,t_sys_employee.FieldByName('姓名').asstring]),[]) then 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['是否可视']:=isopvisible(t_sys_employee.fieldbyname('部门名称').AsString,frm_data_share.t_sys_employee['姓名'],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; END; 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; ADOQuery1.Close; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; frm_sys_progress.close; frm_sys_progress:=nil; end; procedure Tfrm_sys_dep_emp.bsSkinButton13Click(Sender: TObject); var Pnt:Tpoint; begin Pnt:=bsSkinButton13.ClientToScreen(Point(0,bsSkinButton13.Height)); PopupMenu1.Popup(Pnt.x,Pnt.y); end; function Tfrm_sys_dep_emp.isopvisible(emp, otemp, quan: string):Integer; var aQuery:TADOQuery; begin result:=0; aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Text:='select 可视范围 from t_sys_code_sql where 属性='''+quan+''' and 人员='''+otemp+''' ' +' and 人员 in (select 姓名 from t_sys_employee where 部门名称='''+emp+''')'; Open; if not IsEmpty then begin if FieldByName('可视范围').AsString='部门' then begin result:=1; end; end; end; finally FreeAndNil(aQuery); end; end; end.