tes1

mail@pastecode.io avatar
unknown
pascal
3 years ago
4.7 kB
1
Indexable
Never
uses
  SysUtils,
  StdCtrls,
  Controls,
  ComCtrls,
  ZDataSet,
  Dialogs,
  Classes;

{$R *.res}

procedure simpanPegawai(edNip, edNama, edTmp, edTelp, edAlamat : TEdit; cbGol, cbJabatan: TComboBox; zPegawai:TZQuery);stdcall;
  begin
    try
      if(Trim(edNip.Text)= '') Then
      begin
        MessageDlg('Nip Pegawai Belum diisi', mtWarning, [mbOK],0);
        edNip.SetFocus;
      end else
      if(Trim(edNama.Text)= '') Then
      begin
        MessageDlg('Nama Belum diisi', mtWarning, [mbOK],0);
        edNama.SetFocus;
      end else
      if(Trim(edTmp.Text) = '') Then
      begin
        MessageDlg('Tempat Lahir Belum diisi', mtWarning, [mbOK],0);
        edTmp.SetFocus;
      end else
      if(Trim(edAlamat.Text) = '') Then
      begin
        MessageDlg('Alamat Belum diisi', mtWarning, [mbOK],0);
        edAlamat.SetFocus;
      end else
      if(Trim(edTelp.Text) = '') Then
      begin
        MessageDlg('No Telpon/HP Belum diisi', mtWarning, [mbOK],0);
        edTelp.SetFocus;
      end else
      if(Trim(cbGol.Text) = '-- PILIH DATA --') Then
      begin
        MessageDlg('Golongan Belum dipilih', mtWarning, [mbOK],0);
      end else
      if(Trim(cbJabatan.Text) = '-- PILIH DATA --') Then
      begin
        MessageDlg('Jabatan Belum dipilih', mtWarning, [mbOK],0);
      end else
      if(zPegawai.Locate('Nip', edNip.Text, [])) then
      begin
        MessageDlg('Pegawai dengan Nip tersebut sudah terdaftar sebelumnya', mtInformation, [mbOK],0);
        edNip.Text:=zPegawai.FieldByName('Nip').AsString;
        edNama.Text:=zPegawai.FieldByName('nama').AsString;
        edTmp.Text:=zPegawai.FieldByName('tmp_lahir').AsString;
        edTelp.Text:=zPegawai.FieldByName('telp').AsString;
        edAlamat.Text:=zPegawai.FieldByName('alamat').AsString;
        cbGol.Text:=zPegawai.FieldByName('golongan_id').AsString;
        cbJabatan.Text:=zPegawai.FieldByName('jabatan_id').AsString;
      end else
      begin
        zPegawai.Append;
        zPegawai.FieldByName('Nip').AsString:=edNip.Text;
        zPegawai.FieldByName('nama').AsString:=edNama.Text;
        zPegawai.FieldByName('tmp_lahir').AsString:=edTmp.Text;
        zPegawai.FieldByName('telp').AsString:=edTelp.Text;
        zPegawai.FieldByName('alamat').AsString:=edAlamat.Text;
        zPegawai.FieldByName('jabatan_id').AsString:=cbJabatan.Text;
        zPegawai.FieldByName('golongan_id').AsString:=cbGol.Text;
        zPegawai.Post;
        MessageDlg('Data Berhasil disimpan',mtInformation, [mbOK], 0);
      end;
      except
        on err:Exception do
        MessageDlg(err.Message, mtError, [mbOK],0);
    end;
  end;

  procedure ubahPegawai(edNip, edNama, edTmp, edTelp, edAlamat : TEdit; cbGol, cbJabatan : TComboBox; zPegawai:TZQuery);stdcall;
  begin
    try
      if ( (Trim(edNip.Text)= '') and (Trim(edNama.Text)= '')) THEN
      begin
        Beep;
        MessageDlg('Silahkan pilih data terlebih dahulu untuk melakukan proses ubah', mtWarning, [mbOK],0);
      end else
      begin
        if MessageDlg('Anda Yakin Ingin Mengubah Data ?',mtConfirmation,[mbOK,mbCancel],0)=mrOk then
        begin
          with zPegawai do
          begin
            Edit;
            FieldByName('Nip').AsString:=edNip.Text;
            FieldByName('nama').AsString:=edNama.Text;
            FieldByName('tmp_lahir').AsString:=edTmp.Text;
            FieldByName('telp').AsString:=edTelp.Text;
            FieldByName('alamat').AsString:=edAlamat.Text;
            FieldByName('jabatan_id').AsString:=cbJabatan.Text;
            FieldByName('golongan_id').AsString:=cbGol.Text;
            Post;
          end;
          MessageDlg('Data Berhasil di Update', mtInformation, [mbOK],0);
        end;
      end;
    except
      on err:Exception do
      MessageDlg(err.Message, mtError, [mbOK],0);
    end;
  end;

  procedure hapusPegawai(edNip, edNama,edTmp, edAlamat, edTelp : TEdit; cbJabatan, cbGol : TComboBox; zPegawai:TZQuery);stdcall;
  begin
    try
      if((Trim(edNip.Text) = '') and (Trim(edNama.Text) = '')) Then
      begin
        Beep;
        MessageDlg('Silahkan pilih data terlebih dahulu untuk melakukan proses ubah', mtWarning, [mbOK],0);
      end else
      begin
        if not zPegawai.IsEmpty then
        begin
          if MessageDlg('Anda Yakin Ingin Menghapus Data ?',mtConfirmation,[mbOK,mbCancel],0)=mrOk then
          begin
            zPegawai.Delete;
            MessageDlg('Data Berhasil di Hapus', mtInformation, [mbOK], 0);
          end else
          Exit;
        end else Exit;
      end;
    except
      on err:Exception do
      MessageDlg(err.Message, mtWarning, [mbOK],0);
    end;
  end;