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

📄 ustadetail.pas

📁 人事档案管理
💻 PAS
📖 第 1 页 / 共 2 页
字号:
procedure TfraStaDetail.UpdateData;
  procedure UpdateRecord;
    function RecordExists(const AStaNo: string): Boolean;
    var
      aqCheck: TADOQuery;
    begin
      aqCheck := TADOQuery.Create(Self);
      dmPer.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 dbeName.Text = '' then
      begin
        MessageBox(Handle, '请输入家人姓名!', '提示', mb_IconInformation + mb_Ok);
        dbeName.SetFocus;
        Abort;
      end;
    end;
    3:
    begin
      if dbSort.Text = '' then
      begin
        MessageBox(Handle, '请选择类别!', '提示', mb_IconInformation + mb_Ok);
        dbSort.SetFocus;
        Abort;
      end;
      if deTopic.Text = '' then
      begin
        MessageBox(Handle, '请输入事件!', '提示', mb_IconInformation + mb_Ok);
        deTopic.SetFocus;
        Abort;
      end;
    end;
    4:
    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 < 5) 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 <> 5;
    actEdit.Enabled := actAdd.Enabled;
    actSearch.Enabled := actAdd.Enabled;
    actDel.Enabled := actAdd.Enabled;
    actPrior.Enabled := actAdd.Enabled;
    actNext.Enabled := actAdd.Enabled;

    if pcSta.ActivePageIndex <> 5 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 dmPer.aqSta.Active then dmPer.OpenSta;
      aqStaDetail := dmPer.aqSta;
      aqStaDetail.FieldByName('depid').OnGetText := dmPer.GetDeptText;
      aqStaDetail.FieldByName('depid').OnSetText := dmPer.SetDeptText;
      aqStaDetail.FieldByName('sorts').OnGetText := dmPer.GetOtherText;
      aqStaDetail.FieldByName('sorts').OnSetText := dmPer.SetOtherText;
      aqStaDetail.FieldByName('duty').OnGetText := dmPer.GetOtherText;
      aqStaDetail.FieldByName('duty').OnSetText := dmPer.SetOtherText;
      aqStaDetail.FieldByName('folk').OnGetText := dmPer.GetOtherText;
      aqStaDetail.FieldByName('folk').OnSetText := dmPer.SetOtherText;
      aqStaDetail.FieldByName('level').OnGetText := dmPer.GetOtherText;
      aqStaDetail.FieldByName('level').OnSetText := dmPer.SetOtherText;
      aqStaDetail.FieldByName('special').OnGetText := dmPer.GetOtherText;
      aqStaDetail.FieldByName('special').OnSetText := dmPer.SetOtherText;

      if not aqStaDetail.Locate('id', IntToStr(ID), []) then Exit;
      if FileExists(App.Path + 'images\' + aqStaDetail.FieldByName('image').AsString) then
        imgi.Picture.LoadFromFile(App.Path + 'images\' + aqStaDetail.FieldByName('image').AsString)
      else imgi.Picture.LoadFromFile(App.Path + 'images\imgd.jpg');
    end;
    1:
    begin
      if not dmPer.aqExper.Active then dmPer.OpenExper;
      aqStaDetail := dmPer.aqExper;
    end;
    2:
    begin
      if not dmPer.aqFami.Active then dmPer.OpenFami;
      aqStaDetail := dmPer.aqFami;
    end;
    3:
    begin
      if not dmPer.aqAP.Active then dmPer.OpenAP;
      aqStaDetail := dmPer.aqAP;
      aqStaDetail.FieldByName('dep').OnGetText := dmPer.GetDeptText;
      aqStaDetail.FieldByName('dep').OnSetText := dmPer.SetDeptText;
    end;
    4:
    begin
      if not dmPer.aqTrain.Active then dmPer.OpenTrain;
      aqStaDetail := dmPer.aqTrain;
    end;
    5:
    begin
      aqStaDetail := dmPer.aqStat;
      sbDepClick(Sender);
    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(App.Path + 'images\' + sImgStr) then
    begin
      aqImg := TADOQuery.Create(Self);
      dmPer.OpenQuery(aqImg, 'select image from stainfo where id=' + IntToStr(ID));
      if FileExists(App.Path + 'images\' + aqImg.Fieldbyname('image').AsString) then
        DeleteFile(App.Path + 'images\' + aqImg.Fieldbyname('image').AsString);
      CopyFile(PAnsiChar(odImg.FileName), PAnsiChar(App.Path + 'images\' + sImgStr), False);
      aqImg.Free;
      dmPer.ExecSQL('update stainfo set [image]=' + QuotedStr(sImgStr) + ' where id=' + IntToStr(id));
      imgi.Picture.LoadFromFile(App.Path + 'images\' + sImgStr);
      aqStaDetail.Requery();
      MessageBox(Handle, '照片更新成功!', '提示', mb_IconInformation + mb_Ok);
    end
    else MessageBox(Handle, '此照片文件名已存在,请改名先!', '提示', mb_IconInformation + mb_Ok);
  end;
end;

{显示图表开始}
procedure TfraStaDetail.AddStatData(AStatType: TStatType);
  procedure DrawChart;
  var
    i: Integer;
    sXvalue: string;
  begin
    aqStaDetail.First;

    chrStaInfo.Series[0].Clear;
    for i := 0 to aqStaDetail.RecordCount - 1 do
    begin
      sXvalue := aqStaDetail.Fields[0].Text;
      if aStatType = stAge then
        sXvalue := sXvalue + '岁'
      else if aStatType = stYear then
        sXvalue := sXvalue + '年';
      if sXvalue = '' then sXvalue := '未指定';
      chrStaInfo.Series[0].Add(aqStaDetail.Fields[1].AsFloat, sXvalue);
      aqStaDetail.Next;
    end;
    aqStaDetail.First;
  end;
  
begin
  if aqStaDetail.Active then aqStaDetail.Close;
  case aStatType of
    stDep:
    begin
      dmPer.OpenStat(sWhr, 'depid');
      aqStaDetail := dmPer.aqStat;
      aqStaDetail.Fields[0].DisplayLabel := '部 门';
      aqStaDetail.Fields[0].DisplayWidth := 11;
      aqStaDetail.Fields[1].DisplayLabel := '人 数';
      aqStaDetail.Fields[1].DisplayWidth := 4;
      aqStaDetail.Fields[0].OnGetText := dmPer.GetDeptText;
      dsStat.DataSet := aqStaDetail;
      chrStaInfo.Title.Text.Text := '公司统计信息-部 门';
    end;
    stSex:
    begin
      dmPer.OpenStat(sWhr, 'sex');
      aqStaDetail := dmPer.aqStat;
      aqStaDetail.Fields[0].DisplayLabel := '性 别';
      aqStaDetail.Fields[0].DisplayWidth := 11;
      aqStaDetail.Fields[1].DisplayLabel := '人 数';
      aqStaDetail.Fields[1].DisplayWidth := 4;
      dsStat.DataSet := aqStaDetail;
      chrStaInfo.Title.Text.Text := '公司统计信息-性 别';
    end;
    stLevel:
    begin
      dmPer.OpenStat(sWhr, '[level]');
      aqStaDetail := dmPer.aqStat;
      aqStaDetail.Fields[0].DisplayLabel := '学 历';
      aqStaDetail.Fields[0].DisplayWidth := 11;
      aqStaDetail.Fields[1].DisplayLabel := '人 数';
      aqStaDetail.Fields[1].DisplayWidth := 4;
      aqStaDetail.Fields[0].OnGetText := dmPer.GetOtherText;
      dsStat.DataSet := aqStaDetail;
      chrStaInfo.Title.Text.Text := '公司统计信息-学 历';
    end;
    stCap:
    begin
      dmPer.OpenStat(sWhr, '[duty]');
      aqStaDetail := dmPer.aqStat;
      aqStaDetail.Fields[0].DisplayLabel := '职 称';
      aqStaDetail.Fields[0].DisplayWidth := 11;
      aqStaDetail.Fields[1].DisplayLabel := '人 数';
      aqStaDetail.Fields[1].DisplayWidth := 4;
      aqStaDetail.Fields[0].OnGetText := dmPer.GetOtherText;
      dsStat.DataSet := aqStaDetail;
      chrStaInfo.Title.Text.Text := '公司统计信息-职 称';
    end;
    stAge:
    begin
      dmPer.OpenStat(sWhr, 'DateDiff(''yyyy'', birth, Date())');
      aqStaDetail := dmPer.aqStat;
      aqStaDetail.Fields[0].DisplayLabel := '年 龄';
      aqStaDetail.Fields[0].DisplayWidth := 11;
      aqStaDetail.Fields[1].DisplayLabel := '人 数';
      aqStaDetail.Fields[1].DisplayWidth := 4;
      dsStat.DataSet := aqStaDetail;
      chrStaInfo.Title.Text.Text := '公司统计信息-年 龄';
    end;
    stYear:
    begin
      dmPer.OpenStat(sWhr, 'year(indate)');
      aqStaDetail := dmPer.aqStat;
      aqStaDetail.Fields[0].DisplayLabel := '年 份';
      aqStaDetail.Fields[0].DisplayWidth := 11;
      aqStaDetail.Fields[1].DisplayLabel := '人 数';
      aqStaDetail.Fields[1].DisplayWidth := 4;
      dsStat.DataSet := aqStaDetail;
      chrStaInfo.Title.Text.Text := '公司统计信息-入司年份';
    end;
    stMonth:
    begin
      dmPer.OpenStat(sWhr, 'year(indate)&''-''&month(indate)');
      aqStaDetail := dmPer.aqStat;
      aqStaDetail.Fields[0].DisplayLabel := '月 份';
      aqStaDetail.Fields[0].DisplayWidth := 11;
      aqStaDetail.Fields[1].DisplayLabel := '人 数';
      aqStaDetail.Fields[1].DisplayWidth := 4;
      dsStat.DataSet := aqStaDetail;
      chrStaInfo.Title.Text.Text := '公司统计信息-入司年份';
    end;
  end;

  DrawChart;
end;
{显示图表结束}

procedure TfraStaDetail.sbDepClick(Sender: TObject);
begin
  AddStatData(stDep);
end;

procedure TfraStaDetail.sbSexClick(Sender: TObject);
begin
  AddStatData(stSex);
end;

procedure TfraStaDetail.sbElevelClick(Sender: TObject);
begin
  AddStatData(stLevel);
end;

procedure TfraStaDetail.sbAgeClick(Sender: TObject);
begin
  AddStatData(stAge);
end;

procedure TfraStaDetail.sbCapClick(Sender: TObject);
begin
  AddStatData(stCap);
end;

procedure TfraStaDetail.sbYearClick(Sender: TObject);
begin
  AddStatData(stYear);
end;

procedure TfraStaDetail.sbMonthClick(Sender: TObject);
begin
  AddStatData(stMonth);
end;

procedure TfraStaDetail.sbSaveAsClick(Sender: TObject);
begin
  if spdChart.Execute then
  begin
    if FileExists(spdChart.FileName) then
    begin
      if MessageBox(Handle, PAnsiChar('文件' + spdChart.FileName + '已存在,要覆盖吗?'), '提示', mb_IconQuestion + mb_YesNo) = idYes then
      begin
        chrStaInfo.SaveToBitmapFile(spdChart.FileName);
        MessageBox(Handle, PAnsiChar('图表已成功导出为' + spdChart.FileName), '提示', mb_IconInformation + mb_Ok);
      end
      else sbSaveAsClick(Sender);
    end
    else
    begin
      chrStaInfo.SaveToBitmapFile(spdChart.FileName);
      MessageBox(Handle, PAnsiChar('图表已成功导出为' + spdChart.FileName), '提示', mb_IconInformation + mb_Ok);
    end;
  end;
end;

end.

⌨️ 快捷键说明

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