unit U_EmployeeList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, cxButtonEdit,
  cxDropDownEdit, cxPC, cxTL, cxMaskEdit, cxInplaceContainer, cxDBTL, cxTLData,
  cxLookAndFeels, cxLookAndFeelPainters, cxTLdxBarBuiltInMenu, dxBarBuiltInMenu,
  cxNavigator, U_BaseList, dxDateRanges, cxContainer, cxTextEdit,
  dxScrollbarAnnotations, cxProgressBar, dxSkinsCore, dxSkinsDefaultPainters,
  dxSkinOffice2013White, dxSkinSharpPlus, dxSkinWXI;

type
  TfrmEmployeeList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    TBView: TToolButton;
    Panel1: TPanel;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N1: TMenuItem;
    Label1: TLabel;
    EEName: TEdit;
    Label2: TLabel;
    Sex: TComboBox;
    Label5: TLabel;
    Post: TEdit;
    cxDBTreeList1: TcxDBTreeList;
    cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
    DataSource2: TDataSource;
    CDS_Tree: TClientDataSet;
    ADOQueryTree: TADOQuery;
    cxSplitter1: TcxSplitter;
    cxTabControl1: TcxTabControl;
    TLZ: TToolButton;
    ADOQuery1: TADOQuery;
    TCXLZ: TToolButton;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1RuZhiDate: TcxGridDBColumn;
    v1YGName: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column29: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label4: TLabel;
    Dept: TEdit;
    v1SFZNo: TcxGridDBColumn;
    Panel2: TPanel;
    Label6: TLabel;
    SJLiZhiDate: TDateTimePicker;
    Label7: TLabel;
    EECode: TEdit;
    ToolButton2: TToolButton;
    v1Column4: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Label3: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column14: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    Tv1Column16: TcxGridDBColumn;
    Tv1Column17: TcxGridDBColumn;
    Tv1Column18: TcxGridDBColumn;
    Tv1Column19: TcxGridDBColumn;
    Tv1Column20: TcxGridDBColumn;
    Tv1Column21: TcxGridDBColumn;
    Tv1Column22: TcxGridDBColumn;
    Tv1Column23: TcxGridDBColumn;
    Tv1Column24: TcxGridDBColumn;
    Tv1Column25: TcxGridDBColumn;
    Tv1Column26: TcxGridDBColumn;
    Tv1Column27: TcxGridDBColumn;
    Tv1Column28: TcxGridDBColumn;
    Tv1Column29: TcxGridDBColumn;
    Tv1Column30: TcxGridDBColumn;
    Tv1Column31: TcxGridDBColumn;
    Tv1Column32: TcxGridDBColumn;
    Tv1Column33: TcxGridDBColumn;
    Tv1Column34: TcxGridDBColumn;
    Tv1Column35: TcxGridDBColumn;
    Tv1Column36: TcxGridDBColumn;
    Tv1Column37: TcxGridDBColumn;
    Tv1Column38: TcxGridDBColumn;
    Tv1Column39: TcxGridDBColumn;
    Tv1Column40: TcxGridDBColumn;
    Tv1Column41: TcxGridDBColumn;
    Tv1Column42: TcxGridDBColumn;
    Tv1Column43: TcxGridDBColumn;
    Tv1Column44: TcxGridDBColumn;
    Tv1Column45: TcxGridDBColumn;
    Tv1Column46: TcxGridDBColumn;
    Tv1Column47: TcxGridDBColumn;
    Tv1Column48: TcxGridDBColumn;
    Tv1Column49: TcxGridDBColumn;
    Tv1Column50: TcxGridDBColumn;
    Tv1Column51: TcxGridDBColumn;
    Tv1Column52: TcxGridDBColumn;
    Tv1Column53: TcxGridDBColumn;
    Tv1Column54: TcxGridDBColumn;
    Tv1Column55: TcxGridDBColumn;
    Tv1Column56: TcxGridDBColumn;
    Tv1Column57: TcxGridDBColumn;
    ToolButton3: TToolButton;
    cxgrdbclmnTv1Column58: TcxGridDBColumn;
    btn1: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure TBViewClick(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure EENameChange(Sender: TObject);
    procedure cxDBTreeList1DblClick(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure TLZClick(Sender: TObject);
    procedure TCXLZClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure btn1Click(Sender: TObject);
  private
    canshu1: string;
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    procedure InitTree();
    procedure GLAge();
    { Private declarations }
  public
    FFInt, FCloth: Integer;

    { Public declarations }
  end;

var
  frmEmployeeList: TfrmEmployeeList;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_EmployeeInPut, U_DeptTypeHelp; // U_FjList_RZ,

{$R *.dfm}

procedure TfrmEmployeeList.FormDestroy(Sender: TObject);
begin
  inherited;
  frmEmployeeList := nil;
end;

procedure TfrmEmployeeList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
end;

procedure TfrmEmployeeList.FormCreate(Sender: TObject);
begin
  inherited;
  canshu1 := Trim(DParameters1);
  SJLiZhiDate.Date := SGetServerDate(ADOQueryTemp);
  cxgrid1.Align := alClient;
end;

procedure TfrmEmployeeList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('员工档案列表2', Tv1, 'OA管理');
end;

procedure TfrmEmployeeList.InitGrid();
var
  SqlStr, FilterStr: string;
begin

  if cxTabControl1.TabIndex = 0 then
  begin
    Tv1Column1.Visible := False;
    Tv1Column1.Hidden := true;
  end
  else
  begin
    Tv1Column1.Visible := true;
    Tv1Column1.Hidden := False;
  end;

  FilterStr := SGetFilters(Panel1, 1, 2);
  SqlStr := ' exec P_EE_Get_All @DPID=' + quotedstr(Trim(CDS_Tree.fieldbyname('DPID').AsString));
  SqlStr := SqlStr + ' ,@LiZhiFlag=' + quotedstr(Trim(inttostr(cxTabControl1.TabIndex)));
  //showmessage(SqlStr);
  InitCDSData(ADOQueryMain, Order_Main, Tv1, SqlStr, FilterStr, '');

  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select count(*) AS YGGS from SY_Employee where EEType =''正式'' ');
    open;
  end;
  Label3.Caption := '员工人数：' + Trim(ADOQueryCmd.fieldbyname('YGGS').AsString) + '个';

  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select count(*) AS LZGS from SY_Employee where EEType =''离职'' ');
    open;
  end;
  Label8.Caption := '离职人数：' + Trim(ADOQueryCmd.fieldbyname('LZGS').AsString) + '个';

  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select count(*) AS CBGS from SY_Employee where SocialSecurity =''是'' and EEType =''正式''  ');
    open;
  end;
  Label9.Caption := '参保人数：' + Trim(ADOQueryCmd.fieldbyname('CBGS').AsString) + '个';

  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select count(*) AS SYGS from SY_Employee where AccidentInsurance =''是'' and EEType =''正式'' ');
    open;
  end;
  Label10.Caption := '商业保险人数：' + Trim(ADOQueryCmd.fieldbyname('SYGS').AsString) + '个';

end;
//  try
//    ADOQueryMain.DisableControls;
//    with ADOQueryMain do
//    begin
//      Filtered := False;
//      Close;
//      sql.Clear;
//      sql.Add(' exec P_EE_Get_All :DPID,:LiZhiFlag');
//      Parameters.ParamByName('DPID').Value := ;
//      Parameters.ParamByName('LiZhiFlag').Value := cxTabControl1.TabIndex;
//      Open;
//    end;
//    SCreateCDS(ADOQueryMain, Order_Main);
//    SInitCDSData(ADOQueryMain, Order_Main);
//  finally
//    ADOQueryMain.EnableControls;
//  end;
//end;

procedure TfrmEmployeeList.GLAge();
var
  FXTGLNF, FYGGLNF, FGLYF: Double;
begin
  FXTGLNF := strtofloat(uppercase(formatdateTime('yyyy', SGetServerDate(ADOQueryTemp))));
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select RuZhiDate,YGYearGL from SY_Employee where YGType=''正式'' ');
    open;
  end;
  with ADOQueryCmd do
  begin
    first;
    while not eof do
    begin
      edit;
      if ADOQueryCmd.fieldbyname('RuZhiDate').asstring = '' then
      begin
        fieldbyname('YGYearGL').AsFloat := 0;
      end
      else
      begin
        FYGGLNF := strtofloat(uppercase(formatdateTime('yyyy', ADOQueryCmd.fieldbyname('RuZhiDate').AsDateTime)));
        FGLYF := strtofloat(uppercase(formatdateTime('MM', ADOQueryCmd.fieldbyname('RuZhiDate').AsDateTime)));
        if (FGLYF >= 1) and (FGLYF <= 3) then
          fieldbyname('YGYearGL').AsFloat := FXTGLNF - FYGGLNF + 1;
        if (FGLYF > 3) and (FGLYF <= 9) then
          fieldbyname('YGYearGL').AsFloat := FXTGLNF - FYGGLNF + 0.5;
        if (FGLYF > 9) and (FGLYF <= 12) then
          fieldbyname('YGYearGL').AsFloat := FXTGLNF - FYGGLNF;
      end;
      next;
    end;
  end;
end;

procedure TfrmEmployeeList.InitTree();
var
  i: Integer;
begin
  try
    ADOQueryTree.DisableControls;
    with ADOQueryTree do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from SY_Dept order by DPlevel,DPOrder,DPName');
      Open;
    end;
    SCreateCDS(ADOQueryTree, CDS_Tree);
    SInitCDSData(ADOQueryTree, CDS_Tree);
    cxDBTreeList1.Items[0].Expand(True);
  finally
    ADOQueryTree.EnableControls;
  end;
end;

procedure TfrmEmployeeList.InitForm();
begin
  ReadCxGrid('员工档案列表2', Tv1, 'OA管理');
  InitTree();
//  GLAge();
  InitGrid();
end;

procedure TfrmEmployeeList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, Order_Main);
  SInitCDSData(ADOQueryMain, Order_Main);
end;

procedure TfrmEmployeeList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmYGInPut := TfrmYGInPut.Create(Application);
    with frmYGInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('EEID').AsString);
      FDPID := Trim(CDS_Tree.fieldbyname('DPID').AsString);
      FDPName := trim(CDS_Tree.fieldbyname('DPName').AsString);
      frmYGInPut.canshu1 := Trim(Self.canshu1);
      ToolButton1.Visible := false;

      if ShowModal = 1 then
      begin
        initgrid();
      end;
    end;
  finally
    frmYGInPut.Free;
  end;
end;

procedure TfrmEmployeeList.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  //if cxTabControl1.TabIndex<>0 then Exit;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        if fieldbyname('ssel').AsBoolean then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Delete SY_Employee where EEID=''' + Trim(Order_Main.fieldbyname('EEID').AsString) + '''');
            sql.Add('Delete SY_User where UserID=''' + Trim(Order_Main.fieldbyname('EECode').AsString) + '''');
            sql.Add('Delete TP_File where TFType=''YG'' and WBId=''' + Trim(Order_Main.fieldbyname('EEID').AsString) + '''');
            ExecSQL;
          end;
        end;
        next;
      end;
      EnableControls;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    InitGrid();
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Order_Main.EnableControls;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;

end;

procedure TfrmEmployeeList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel('员工档案列表', cxGrid1);
end;

procedure TfrmEmployeeList.TBRafreshClick(Sender: TObject);
begin
  InitTree();
  InitGrid();
end;

procedure TfrmEmployeeList.TBAddClick(Sender: TObject);
var
  maxno: string;
begin
  try
    frmYGInPut := TfrmYGInPut.Create(Application);
    with frmYGInPut do
    begin
      PState := 0;
      FMainId := '';
      FDPID := Trim(CDS_Tree.fieldbyname('DPID').AsString);
      FDPName := trim(CDS_Tree.fieldbyname('DPName').AsString);
      if ShowModal = 1 then
      begin
        initgrid();
      end;
    end;
  finally
    frmYGInPut.Free;
  end;
end;

procedure TfrmEmployeeList.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(trim(self.caption) + 'Tv1', Tv1, '员工管理');
  InitForm();
end;

procedure TfrmEmployeeList.btn1Click(Sender: TObject);
begin
  WriteCxGrid(trim(self.caption) + 'Tv1', Tv1, '员工管理');
end;

procedure TfrmEmployeeList.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmEmployeeList.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmEmployeeList.TBViewClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmYGInPut := TfrmYGInPut.Create(Application);
    with frmYGInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('EEID').AsString);
      FDPID := Trim(CDS_Tree.fieldbyname('DPID').AsString);
      TBSave.Visible := False;
      ToolButton1.Visible := False;
      ToolButton2.Visible := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmYGInPut.Free;
  end;
end;

procedure TfrmEmployeeList.CustomerNoNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, Order_Main);
  SInitCDSData(ADOQueryMain, Order_Main);
end;

procedure TfrmEmployeeList.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main, True);
end;

procedure TfrmEmployeeList.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main, False);
end;

procedure TfrmEmployeeList.cxTabControl1Change(Sender: TObject);
begin

  InitGrid();
end;

procedure TfrmEmployeeList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  TBView.Click;
end;

procedure TfrmEmployeeList.EENameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmEmployeeList.cxDBTreeList1DblClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmEmployeeList.Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if Order_Main.IsEmpty then
    Exit;
  CDS_Tree.Locate('DPID', Trim(Order_Main.fieldbyname('DPID').AsString), []);
end;

procedure TfrmEmployeeList.TLZClick(Sender: TObject);
begin

  if order_Main.IsEmpty then
    exit;
  if CxTabConTrol1.TabIndex <> 0 then
    exit;
  if application.MessageBox('确定要执行此操作', '提示', 1) = 2 then
    exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        if fieldbyname('ssel').AsBoolean then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('update SY_Employee set  EEType=''离职'',DepartureDate=' + Quotedstr(trim(FormatDateTime('yyyy-MM-dd', SJLiZhiDate.Date))));
            sql.Add(' where EEID=''' + trim(Order_Main.fieldbyname('EEID').AsString) + '''');
            ExecSQL;
          end;
          with ADOQueryCmd do
          begin
            Close;
            SQL.Clear;
            sql.Add('exec P_EE_in_Account @DataID=''' + Trim(Order_Main.fieldbyname('EEID').AsString) + '''');
            Open;
          end;
          if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
            raise Exception.Create(PChar(ADOQueryCmd.fieldbyname('ShowMsg').AsString));
        end;
        next;
      end;
      EnableControls;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    InitGrid();
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Order_Main.EnableControls;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;

end;

procedure TfrmEmployeeList.TCXLZClick(Sender: TObject);
begin
  if order_Main.IsEmpty then
    exit;
  if cxTabControl1.TabIndex <> 1 then
    exit;
  if application.MessageBox('确定要撤销离职吗', '提示', 1) = 2 then
    exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        if fieldbyname('ssel').AsBoolean then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update SY_Employee set  EEType=''正式'',DepartureDate=NULL');
            sql.Add(' where EEID=''' + trim(Order_Main.fieldbyname('EEID').AsString) + '''');
            execsql;
          end;
          with ADOQueryCmd do
          begin
            Close;
            SQL.Clear;
            sql.Add('exec P_EE_in_Account @DataID=''' + Trim(Order_Main.fieldbyname('EEID').AsString) + '''');
            Open;
          end;
          if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
            raise Exception.Create(PChar(ADOQueryCmd.fieldbyname('ShowMsg').AsString));
        end;
        next;
      end;
      EnableControls;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    InitGrid();
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Order_Main.EnableControls;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;

end;

procedure TfrmEmployeeList.ToolButton1Click(Sender: TObject);
begin
  if order_Main.IsEmpty then
    exit;
  if CxTabConTrol1.TabIndex <> 0 then
    exit;
  if application.MessageBox('确定要执行此操作', '提示', 1) = 2 then
    exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        if fieldbyname('ssel').AsBoolean then
        begin

          with ADOQueryCmd do
          begin
            Close;
            SQL.Clear;
            sql.Add('exec P_EE_in_Account @DataID=''' + Trim(Order_Main.fieldbyname('EEID').AsString) + '''');
            Open;
          end;
          if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
            raise Exception.Create(PChar(ADOQueryCmd.fieldbyname('ShowMsg').AsString));
        end;
        next;
      end;
      EnableControls;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    InitGrid();
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Order_Main.EnableControls;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

procedure TfrmEmployeeList.ToolButton2Click(Sender: TObject);
var
  FDPID, FName: string;
begin
  if Order_Main.IsEmpty then
    exit;
  if Order_Main.Locate('ssel', true, []) = false then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  FDPID := '';
  FName := '';
  frmDeptTypeHelp := TfrmDeptTypeHelp.create(self);
  with frmDeptTypeHelp do
  begin
    if showmodal = 1 then
    begin
      FDPID := Trim(ADOQueryHelp.fieldbyname('DPID').AsString);
      FName := Trim(ADOQueryHelp.fieldbyname('DPName').AsString);
    end;
    free;
  end;

  if trim(FDPID) = '' then
    exit;

  try
    with Order_Main do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        if fieldbyname('ssel').AsBoolean then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update  SY_Employee SET Dept=''' + trim(FName) + ''' ');
            sql.Add(',DPID=''' + trim(FDPID) + ''' ');
            sql.Add('where EEID=' + quotedstr(trim(Order_Main.fieldbyname('EEID').AsString)));
            execsql;
          end;
        end;
        next;
      end;
      First;
      EnableControls;
    end;
    application.MessageBox('操作成功！', '提示信息');
    initgrid();
  except
    Order_Main.EnableControls;
    application.MessageBox('操作失败！', '提示信息', 0);
  end;
end;

procedure TfrmEmployeeList.ToolButton3Click(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec UpdateEmployeeDetails ');
    ExecSQL;
  end;
  InitGrid();
end;

end.

