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

📄 ustainfo.pas

📁 这是一个门禁系统的应用程序,用 delphi编写,希望与大家交流.
💻 PAS
📖 第 1 页 / 共 4 页
字号:
procedure TfrmStainfo.SetState(aCon: TSetState; aState: Boolean);
var
  i: Integer;
  tsCur: TTabSheet;
begin
  tsCur := nil;
  case aCon of
    ssSta:
    begin
      tsCur := tsStainfo;
      if aState then
      begin
        btnEditi.Enabled := true;
        btnDeli.Enabled := true;
      end
      else
      begin
        if aqStaInfo.State = dsInsert then
        begin
          edtStano.SetFocus;
          deBirth.Value := IncYear(Date(), -20);
          deInDate.Value := Date();
          deBarstart.Value := Date();
          deBarend.Value := IncYear(Date(), 1);
        end
        else
        begin
          edtStano.ReadOnly := true;
          edtName.SetFocus;
        end;
      end;
    end;

    ssExper:
    begin
      tsCur := tsExper;
      if aState then
        dgExper.Enabled := true
      else
      begin
        dgExper.Enabled := false;
        if aqStaInfo.State = dsInsert then
        begin
          deSDate.Value := IncYear(Date(), -1);
          deEdate.Value := Date();
        end; 
      end;
    end;

    ssFami:
    begin
      tsCur := tsFami;
      if aState then
        dgFami.Enabled := true
      else
      begin
        dgFami.Enabled := false;
        dbeName.SetFocus
      end;
    end;

    ssAP:
    begin
      tsCur := tsAP;
      if aState = true then
        dgap.Enabled := true
      else
      begin
        dgap.Enabled := false;
        dbSort.SetFocus;
        if aqStaInfo.State = dsInsert then
          deDate.Value := Date();
      end;
    end;

    ssTrain:
    begin
      tsCur := tsTrain;
      if aState = true then
        dgTrain.Enabled := true
      else
      begin
        dgTrain.Enabled := false;
        deCourse.SetFocus;
        if aqStaInfo.State = dsInsert then
        begin
          dteSDate.Value := IncYear(Date(), -1);
          dteEDate.Value := IncYear(Date(), -1);
        end;
      end;
    end;
  end;

  if aState then
  begin
    for i := 0 to tsCur.ControlCount - 1 do
      if tsCur.Controls[i] is TDBEdit then
      begin
        TDBEdit(tsCur.Controls[i]).ReadOnly := true;
        TDBEdit(tsCur.Controls[i]).Color := clSkyBlue;
      end
      else if tsCur.Controls[i] is TDBComboBox then
      begin
        TDBComboBox(tsCur.Controls[i]).ReadOnly := true;
        TDBComboBox(tsCur.Controls[i]).Color := clSkyBlue;
      end
      else if tsCur.Controls[i] is TDBDateTimeEditEh then
      begin
        TDBDateTimeEditEh(tsCur.Controls[i]).ReadOnly := true;
        TDBDateTimeEditEh(tsCur.Controls[i]).Color := clSkyBlue;
      end
      else if tsCur.Controls[i] is TDBMemo then
      begin
        TDBMemo(tsCur.Controls[i]).ReadOnly := true;
        TDBMemo(tsCur.Controls[i]).Color := clSkyBlue;
      end;
  end
  else
    for i := 0 to tsCur.ControlCount - 1 do
      if tsCur.Controls[i] is TDBEdit then
      begin
        TDBEdit(tsCur.Controls[i]).ReadOnly := false;
        TDBEdit(tsCur.Controls[i]).Color := clWindow;
      end
      else if tsCur.Controls[i] is TDBComboBox then
      begin
        TDBComboBox(tsCur.Controls[i]).ReadOnly := false;
        TDBComboBox(tsCur.Controls[i]).Color := clWindow;
      end
      else if tsCur.Controls[i] is TDBDateTimeEditEh then
      begin
        TDBDateTimeEditEh(tsCur.Controls[i]).ReadOnly := false;
        TDBDateTimeEditEh(tsCur.Controls[i]).Color := clWindow;
      end
      else if tsCur.Controls[i] is TDBMemo then
      begin
        TDBMemo(tsCur.Controls[i]).ReadOnly := false;
        TDBMemo(tsCur.Controls[i]).Color := clWindow;
      end;
end;

procedure TfrmStainfo.SetState(aCon: TSetState; aOtype: TOpeType);
begin
  case aOtype of
    otAdd, otEdit:
    begin
      tvPer.Enabled := false;
      btnEdit.Visible := false;
      btnInqu.Visible := false;
      btnPrior.Visible := false;
      btnNext.Visible := false;
      btnDel.Visible := false;
      btnPrint.Caption := '取  消';
      btnClose.Visible := false;
      SetState(aCon, false);
      if aOtype = otAdd then
      begin
        btnAdd.Caption := '提  交';
        btnEditi.Enabled := false;
        btnDeli.Enabled := false;
      end
      else
        btnAdd.Caption := '确  定';
    end;
    otCancel:
    begin
      tvPer.Enabled := true;
      btnEdit.Visible := true;
      btnAdd.Caption := '添  加';
      btnInqu.Visible := true;
      btnPrior.Visible := true;
      btnNext.Visible := true;
      btnDel.Visible := true;
      btnPrint.Caption := '打  印';
      btnClose.Visible := true;
      SetState(aCon, true);
      if aqStaInfo.State in [dsEdit, dsInsert] then
      begin
        aqStaInfo.Cancel;
        aqStaInfo.CancelBatch;
      end;
    end;
  end;
end;

procedure TfrmStainfo.AddData(aCon: TSetState);
  procedure UpdateRecord;
    procedure FindTree(aNo: string);
    var
      i: Integer;
    begin
      for i := 0 to tvPer.Items.Count - 1 do
      begin
        if tvPer.Items[i].Data <> nil then
          if Psid(tvPer.Items[i].Data)^.sNo = aNo then
          begin
            tvPer.Items[i].Selected := true;
            tvPer.Setfocus;
            Break;
          end;
      end;
    end;
  var
    sNo: string;
  begin
    try
      if pcSta.ActivePageIndex <> 0 then
        aqStaInfo.FieldByName('sid').AsInteger := id
      else
      begin
        sNo := edtStano.Text;
        aqStaInfo.FieldByName('ename').AsString := GetEn(edtName.Text);
        if dcbSDep.Text = '[不  限]' then
          aqStaInfo.FieldByName('sdep').AsString := ''
        else
          aqStaInfo.FieldByName('sdep').AsString := dcbSDep.Text;
      end;

      aqStaInfo.Post;
      aqStaInfo.UpdateBatch();
      if aqStaInfo.RecordCount = 0 then
        btnEdit.Enabled := false
      else
        btnEdit.Enabled := true;
      btnDel.Enabled := btnEdit.Enabled;
      SetState(aCon, otCancel);
      if pcSta.ActivePageIndex = 0 then
      begin
        DrawTree;
        FindTree(sNo);
      end;
    except
      MessageBox(self.Handle, '记录添加失败!', '提示', mb_IconInformation + mb_Ok);
    end;
  end;
begin
  case aCon of
    ssSta:
    begin
      if edtStano.Text = '' then
      begin
        MessageBox(self.Handle, '请输入工号!', '提示', mb_IconInformation + mb_Ok);
        edtStano.SetFocus;
        Abort;
      end;
      if edtName.Text = '' then
      begin
        MessageBox(self.Handle, '请输入员工姓名!', '提示', mb_IconInformation + mb_Ok);
        edtName.SetFocus;
        Abort;
      end;
      if dcbSex.Text = '' then
      begin
        MessageBox(self.Handle, '请选择员工性别!', '提示', mb_IconInformation + mb_Ok);
        dcbSex.SetFocus;
        Abort;
      end;
      if deBirth.Text = '    -  -  ' then
      begin
        MessageBox(self.Handle, '请输入员工生日,用以统计年龄段!', '提示', mb_IconInformation + mb_Ok);
        deBirth.SetFocus;
        Abort;
      end;
      if dcbDep.Text = '' then
      begin
        MessageBox(self.Handle, '请选择员工部门!', '提示', mb_IconInformation + mb_Ok);
        dcbDep.SetFocus;
        Abort;
      end;
      if deInDate.Text = '    -  -  ' then
      begin
        MessageBox(self.Handle, '请输入入司时间!', '提示', mb_IconInformation + mb_Ok);
        deInDate.SetFocus;
        Abort;
      end;

      UpDateRecord;
    end;
    ssExper:
    begin
      if deSDate.Text = '    -  -  ' then
      begin
        MessageBox(self.Handle, '请输入开始时间!', '提示', mb_IconInformation + mb_Ok);
        deSDate.SetFocus;
        Abort;
      end;
      if deEdate.Text = '    -  -  ' then
      begin
        MessageBox(self.Handle, '请输入结束时间!', '提示', mb_IconInformation + mb_Ok);
        deEdate.SetFocus;
        Abort;
      end;
      if deCom.Text = '' then
      begin
        MessageBox(self.Handle, '请输入公司名!', '提示', mb_IconInformation + mb_Ok);
        deCom.SetFocus;
        Abort;
      end;

      UpdateRecord;
    end;        
    ssFami:
    begin
      if dbeName.Text = '' then
      begin
        MessageBox(self.Handle, '请输入家人姓名!', '提示', mb_IconInformation + mb_Ok);
        dbeName.SetFocus;
        Abort;
      end;

      UpdateRecord;
    end;
    ssAP:
    begin
      if dbSort.Text = '' then
      begin
        MessageBox(self.Handle, '请选择类别!', '提示', mb_IconInformation + mb_Ok);
        dbSort.SetFocus;
        Abort;
      end;
      if deTopic.Text = '' then
      begin
        MessageBox(self.Handle, '请输入事件!', '提示', mb_IconInformation + mb_Ok);
        deTopic.SetFocus;
        Abort;
      end;

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

      UpdateRecord;
    end;
  end;
end;

procedure TfrmStainfo.UpdateData(aCon: TSetState);
  procedure UpdateRecord;
    procedure FindTree(aNo: string);
    var
      i: Integer;
    begin
      for i := 0 to tvPer.Items.Count - 1 do
      begin
        if tvPer.Items[i].Data <> nil then
          if Psid(tvPer.Items[i].Data)^.sNo = aNo then
          begin
            tvPer.Items[i].Selected := true;
            tvPer.Setfocus;
            Break;
          end;
      end;
    end;
  var
    sNo, sDep, sSDep, sName: string;
  begin
    sDep := '';
    sSDep := '';
    if tvPer.Selected.Data <> nil then
    begin
      sNo := Psid(tvPer.Selected.Data)^.sNo;
      if tvPer.Selected.Level = 2 then sDep := tvPer.Selected.Parent.Text;
      if tvPer.Selected.Level = 3 then sSdep := tvPer.Selected.Parent.Text;
      sName := tvPer.Selected.Text;
    end;
    try
      if pcSta.ActivePageIndex = 0 then
      begin
        aqStaInfo.FieldByName('ename').AsString := GetEn(edtName.Text);
        if dcbSDep.Text = '[不  限]' then
          aqStaInfo.FieldByName('sdep').AsString := ''
        else
          aqStaInfo.FieldByName('sdep').AsString := dcbSDep.Text;
      end;
      aqStaInfo.Post;
      aqStaInfo.UpdateBatch();
      SetState(aCon, otCancel);
      if ((sDep <> dcbDep.Text) or (sName <> edtName.Text) or (sSDep <> dcbSDep.Text)) and (pcSta.ActivePageIndex = 0) then
      begin
        DrawTree;
        FindTree(sNo);
      end;
    except
      MessageBox(self.Handle, '记录更新失败!', '提示', mb_IconInformation + mb_Ok);
    end;
  end;
begin
  case aCon of
    ssSta:
    begin
      if edtName.Text = '' then
      begin
        MessageBox(self.Handle, '请输入员工姓名!', '提示', mb_IconInformation + mb_Ok);
        edtName.SetFocus;
        Abort;
      end;
      if dcbSex.Text = '' then
      begin
        MessageBox(self.Handle, '请选择员工性别!', '提示', mb_IconInformation + mb_Ok);
        dcbSex.SetFocus;
        Abort;
      end;
      if deBirth.Text = '    -  -  ' then
      begin
        MessageBox(self.Handle, '请输入员工生日,用以统计年龄段!', '提示', mb_IconInformation + mb_Ok);
        deBirth.SetFocus;
        Abort;
      end;
      if dcbDep.Text = '' then
      begin
        MessageBox(self.Handle, '请选择员工部门!', '提示', mb_IconInformation + mb_Ok);
        dcbDep.SetFocus;
        Abort;
      end;
      if deInDate.Text = '    -  -  ' then
      begin
        MessageBox(self.Handle, '请输入入司时间!', '提示', mb_IconInformation + mb_Ok);
        deInDate.SetFocus;
        Abort;
      end;

      UpDateRecord;
    end;
    ssExper:
    begin
      if deSDate.Text = '    -  -  ' then
      begin
        MessageBox(self.Handle, '请输入开始时间!', '提示', mb_IconInformation + mb_Ok);
        deSDate.SetFocus;
        Abort;
      end;
      if deEdate.Text = '    -  -  ' then
      begin
        MessageBox(self.Handle, '请输入结束时间!', '提示', mb_IconInformation + mb_Ok);
        deEdate.SetFocus;
        Abort;
      end;
      if deCom.Text = '' then
      begin
        MessageBox(self.Handle, '请输入公司名!', '提示', mb_IconInformation + mb_Ok);
        deCom.SetFocus;
        Abort;
      end;

      UpdateRecord;
    end;
    ssFami:
    begin
      if dbeName.Text = '' then
      begin
        MessageBox(self.Handle, '请输入家人姓名!', '提示', mb_IconInformation + mb_Ok);

⌨️ 快捷键说明

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