⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ustadetail.pas

📁 一个很好的员工档案管理系统源码 有无限制树
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      if aqStaDetail.State in [dsEdit, dsInsert] then aqStaDetail.CancelBatch;
    end;
  end;
end;

procedure TfraStaDetail.btnDeliClick(Sender: TObject);
var
  aqImg: TADOQuery;
begin
  if MessageBox(Handle, '真的要删除此员工照片吗?', '提示', mb_IconQuestion + mb_YesNo) = idYes then
  begin
    aqImg := TADOQuery.Create(Self);
    DM.OpenQuery(aqImg, 'select image from stainfo where id=' + IntToStr(ID));
    if FileExists(MyApp.Path + 'images\' + aqImg.Fieldbyname('image').AsString) then
    begin
      DeleteFile(MyApp.Path + 'images\' + aqImg.Fieldbyname('image').AsString);
      imgi.Picture.LoadFromFile(MyApp.Path + 'images\nophoto_f.jpg');
    end
    else MessageBox(Handle, '没有此员工照片!', '提示', mb_IconInformation + mb_Ok);
    aqImg.Free;
  end;
end;

procedure TfraStaDetail.Append;
begin
  if pcSta.ActivePageIndex = 5 then pcSta.ActivePageIndex := 0;
  aqStaDetail.Append;
  SetState(pcSta.ActivePageIndex, otAdd);
end;

function TfraStaDetail.Delete: Boolean;
begin
  Result := False;
  if pcSta.ActivePageIndex = 5 then pcSta.ActivePageIndex := 0;
  if not aqStaDetail.Active then Exit;
  try
    if pcSta.ActivePageIndex = 0 then
    begin
      if MessageBox(handle, '真的要删除此员工记录么?', '提示', mb_IconQuestion + mb_YesNo) = idYes then
      begin
        if FileExists(MyApp.Path + 'images\' + aqStaDetail.Fieldbyname('image').AsString) then
          DeleteFile(MyApp.Path + 'images\' + aqStaDetail.Fieldbyname('image').AsString);
        aqStaDetail.Delete;
        aqStaDetail.UpdateBatch();
        Result := True;
      end
    end
    else if MessageBox(Handle, '真的要删除此记录么?', '提示', mb_IconQuestion + mb_YesNo) = idYes then
    begin
      aqStaDetail.Delete;
      aqStaDetail.UpdateBatch();
    end;
  except
    on E: Exception do
    begin
      MessageBox(Handle, PAnsiChar('删除失败,信息为:' + E.Message), '提示', mb_Ok + mb_IconInformation);
      if pcSta.ActivePageIndex = 0 then Result := False;
    end;
   end;
end;

procedure TfraStaDetail.Edit;
begin
  if pcSta.ActivePageIndex = 2 then pcSta.ActivePageIndex := 0;
  aqStaDetail.Edit;
  SetState(pcSta.ActivePageIndex, otEdit);
end;

procedure TfraStaDetail.UpdateData;
  procedure UpdateRecord;
    function RecordExists(const AStaNo: string): Boolean;
    var
      aqCheck: TADOQuery;
    begin
      aqCheck := TADOQuery.Create(Self);
      DM.OpenQuery(aqCheck, 'select * from stainfo where stano=' + QuotedStr(AStaNo));
      Result := aqCheck.RecordCount <> 0;
      aqCheck.Free;
    end;

  var
    sStaNo: string;
  begin
    if pcSta.ActivePageIndex <> 0 then
      aqStaDetail.FieldByName('sid').AsInteger := ID
    else if pcSta.ActivePageIndex = 0 then
    begin
      sStaNo := Trim(deStano.Text);
      if aqStaDetail.State = dsInsert then
      begin
        if RecordExists(sStaNo) then
        begin
          MessageBox(Handle, PAnsiChar('已存在工号为[' + sStaNo + ']的记录!'), '提示', mb_Ok + mb_IconInformation);
          deStano.SetFocus;
          Abort;
        end;
      end;
      aqStaDetail.FieldByName('ename').AsString := GetEnStr(deName.Text);
    end;

    if pcSta.ActivePageIndex = 0 then
    begin
      if aqStaDetail.State = dsInsert then
        Log.Write('添加员工信息[' + deName.Text + ']')
      else
        Log.Write('更新员工信息[' + deName.Text + ']');
    end;

    aqStaDetail.UpdateBatch();
    SetState(pcSta.ActivePageIndex, otView);
  end;

begin
  case pcSta.ActivePageIndex of
    0:
    begin
      if deStano.Text = '' then
      begin
        MessageBox(Handle, '请输入工号!', '提示', mb_IconInformation + mb_Ok);
        deStano.SetFocus;
        Abort;
      end
      else if deName.Text = '' then
      begin
        MessageBox(Handle, '请输入员工姓名!', '提示', mb_IconInformation + mb_Ok);
        deName.SetFocus;
        Abort;
      end;
      if dcbSex.Text = '' then
      begin
        MessageBox(Handle, '请选择员工性别!', '提示', mb_IconInformation + mb_Ok);
        dcbSex.SetFocus;
        Abort;
      end
      else if deBirth.Text = '    -  -  ' then
      begin
        MessageBox(Handle, '请输入员工生日,用以统计年龄段!', '提示', mb_IconInformation + mb_Ok);
        deBirth.SetFocus;
        Abort;
      end
      else if dcbDep.Text = '' then
      begin
        MessageBox(Handle, '请选择员工部门!', '提示', mb_IconInformation + mb_Ok);
        dcbDep.SetFocus;
        Abort;
      end
      else if deInDate.Text = '    -  -  ' then
      begin
        MessageBox(Handle, '请输入入司时间!', '提示', mb_IconInformation + mb_Ok);
        deInDate.SetFocus;
        Abort;
      end;
    end;
    1:
    begin
      if deSDate.Text = '    -  -  ' then
      begin
        MessageBox(Handle, '请输入开始时间!', '提示', mb_IconInformation + mb_Ok);
        deSDate.SetFocus;
        Abort;
      end
      else if deEdate.Text = '    -  -  ' then
      begin
        MessageBox(Handle, '请输入结束时间!', '提示', mb_IconInformation + mb_Ok);
        deEdate.SetFocus;
        Abort;
      end
      else if deCom.Text = '' then
      begin
        MessageBox(Handle, '请输入公司名!', '提示', mb_IconInformation + mb_Ok);
        deCom.SetFocus;
        Abort;
      end;
    end;


    2:
    begin
      if deCourse.Text = '' then
      begin
        MessageBox(Handle, '请输入培训课程!', '提示', mb_IconInformation + mb_Ok);
        deCourse.SetFocus;
        Abort;
      end;
      if deDLimit.Text = '' then
      begin
        MessageBox(Handle, '请输入培训期限!', '提示', mb_IconInformation + mb_Ok);
        deDLimit.SetFocus;
        Abort;
      end;
    end;
  end;

  UpdateRecord;
end;

procedure TfraStaDetail.Cancel;
begin
  if aqStaDetail.State in [dsEdit, dsInsert] then aqStaDetail.CancelBatch;
  SetState(pcSta.ActivePageIndex, otView);
end;

procedure TfraStaDetail.Print(AIds: string);
begin
  if AIds = '' then
    MessageBox(Handle, PAnsiChar('当前没有要打印的员工信息!'), '提示', MB_OK + MB_ICONINFORMATION)
  else
  begin
    AIds := Copy(AIds, 3, Length(AIds) - 2);
    frmPrint := TfrmPrint.Create(Self, AIds);
    frmPrint.ShowModal;
    FreeAndNil(frmPrint);
  end;
end;

procedure TfraStaDetail.BeforeShow;
begin
  if aqStaDetail.State in [dsEdit, dsInsert] then aqStaDetail.CancelBatch;
end;

procedure TfraStaDetail.AfterShow(AIndex: Integer);
begin
  if not Assigned(frmStaInfo) then Exit;
  if (AIndex <> 0) and (AIndex < 3) then FilterData(aqStaDetail, 'sid=' + IntToStr(ID));
  if frmStaInfo.actOk.Visible then
  begin
    if (frmStaInfo.actOk.Caption = '提 交') and (aqStaDetail.State <> dsInsert) then
    begin
      aqStaDetail.Append;
      SetState(AIndex, False);
      Exit;
    end
    else if (frmStaInfo.actOk.Caption = '确 定') and (aqStaDetail.State <> dsEdit) then
    begin
      aqStaDetail.Edit;
      SetState(AIndex, False);
      Exit;
    end;
  end;

  SetState(AIndex, True);
  with frmStaInfo do
  begin
    actAdd.Enabled := pcSta.ActivePageIndex <> 3;
    actEdit.Enabled := actAdd.Enabled;
    actSearch.Enabled := actAdd.Enabled;
    actDel.Enabled := actAdd.Enabled;
    actPrior.Enabled := actAdd.Enabled;
    actNext.Enabled := actAdd.Enabled;

    if pcSta.ActivePageIndex <> 3 then
    begin
      actEdit.Enabled := aqStaDetail.RecordCount <> 0;
      actDel.Enabled := frmStaInfo.btnEdit.Enabled;
    end;
  end;
end;

procedure TfraStaDetail.pcStaChange(Sender: TObject);
begin
  BeforeShow;
  case pcSta.ActivePageIndex of
    0:
    begin
      if not DM.aqSta.Active then DM.OpenSta;
      aqStaDetail := DM.aqSta;
      aqStaDetail.FieldByName('depid').OnGetText := DM.GetDeptText;
      aqStaDetail.FieldByName('depid').OnSetText := DM.SetDeptText;
      aqStaDetail.FieldByName('sorts').OnGetText := DM.GetOtherText;
      aqStaDetail.FieldByName('sorts').OnSetText := DM.SetOtherText;
      aqStaDetail.FieldByName('duty').OnGetText := DM.GetOtherText;
      aqStaDetail.FieldByName('duty').OnSetText := DM.SetOtherText;
      aqStaDetail.FieldByName('folk').OnGetText := DM.GetOtherText;
      aqStaDetail.FieldByName('folk').OnSetText := DM.SetOtherText;
      aqStaDetail.FieldByName('level').OnGetText := DM.GetOtherText;
      aqStaDetail.FieldByName('level').OnSetText := DM.SetOtherText;
      aqStaDetail.FieldByName('special').OnGetText := DM.GetOtherText;
      aqStaDetail.FieldByName('special').OnSetText := DM.SetOtherText;

      if not aqStaDetail.Locate('id', IntToStr(ID), []) then Exit;
      if FileExists(MyApp.Path + 'images\' + aqStaDetail.FieldByName('image').AsString) then
        imgi.Picture.LoadFromFile(MyApp.Path + 'images\' + aqStaDetail.FieldByName('image').AsString)
      else imgi.Picture.LoadFromFile(MyApp.Path + 'images\nophoto_f.jpg');
    end;
    1:
    begin
      if not DM.aqExper.Active then DM.OpenExper;
      aqStaDetail := DM.aqExper;
    end;

    2:
    begin
      if not DM.aqTrain.Active then DM.OpenTrain;
      aqStaDetail := DM.aqTrain;
    end;
   
  end;
  AfterShow(pcSta.ActivePageIndex);
end;

procedure TfraStaDetail.btnEditiClick(Sender: TObject);
var
  aqImg: TADOQuery;
  sImgStr: string;
begin
  if odImg.Execute then
  begin
    sImgStr := ExtractFileName(odImg.FileName);
    if not FileExists(MyApp.Path + 'images\' + sImgStr) then
    begin
      aqImg := TADOQuery.Create(Self);
      DM.OpenQuery(aqImg, 'select image from stainfo where id=' + IntToStr(ID));
      if FileExists(MyApp.Path + 'images\' + aqImg.Fieldbyname('image').AsString) then
        DeleteFile(MyApp.Path + 'images\' + aqImg.Fieldbyname('image').AsString);
      CopyFile(PAnsiChar(odImg.FileName), PAnsiChar(MyApp.Path + 'images\' + sImgStr), False);
      aqImg.Free;
      DM.ExecSQL('update stainfo set [image]=' + QuotedStr(sImgStr) + ' where id=' + IntToStr(id));
      imgi.Picture.LoadFromFile(MyApp.Path + 'images\' + sImgStr);
      aqStaDetail.Requery();
      MessageBox(Handle, '照片更新成功!', '提示', mb_IconInformation + mb_Ok);
    end
    else MessageBox(Handle, '此照片文件名已存在,请改名先!', '提示', mb_IconInformation + mb_Ok);
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -