0% found this document useful (0 votes)
53 views13 pages

Form1: Unit Unit1

The document describes a form (Form1) with labels, edit boxes, combo boxes, buttons, and other controls for inputting and editing student data. It includes procedures for saving, updating, and retrieving data from a database table using ADO components. A secondary form (Form2) displays the student data in a datagrid and allows double clicking a record to edit it in Form1.

Uploaded by

ReiymBo Rezpect
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views13 pages

Form1: Unit Unit1

The document describes a form (Form1) with labels, edit boxes, combo boxes, buttons, and other controls for inputting and editing student data. It includes procedures for saving, updating, and retrieving data from a database table using ADO components. A secondary form (Form2) displays the student data in a datagrid and allows double clicking a record to edit it in Form1.

Uploaded by

ReiymBo Rezpect
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Form1 unit Unit1;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ExtDlgs, ExtCtrls, jpeg, XPMan, DB, ADODB;

type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; Label9: TLabel; Label10: TLabel; Label11: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; DateTimePicker1: TDateTimePicker; ComboBox1: TComboBox; ComboBox2: TComboBox; Edit5: TEdit; Edit6: TEdit; ComboBox3: TComboBox; Edit4: TEdit; Edit7: TEdit; Button1: TButton; Button2: TButton;

Button3: TButton; Button4: TButton; Image1: TImage; OpenPictureDialog1: TOpenPictureDialog; Bevel1: TBevel; Edit8: TEdit; Label12: TLabel; XPManifest1: TXPManifest; Label13: TLabel; ADOQuery1: TADOQuery; procedure Button3Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure Edit1KeyPress(Sender: TObject; var Key: Char); procedure FormPaint(Sender: TObject); procedure Edit1Change(Sender: TObject); procedure Edit2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;

var Form1: TForm1;

implementation

uses Unit2, Math;

{$R *.dfm}

procedure TForm1.Button3Click(Sender: TObject); begin if messagedlg('Apakah Anda yakin Ingin Keluar Dari Pengimputan Ini ?'+chr (13) + 'PIlih YES Jika Ingin Keluar Atau NO kembali Ke Pengimputan',mtconfirmation,[mbyes,mbno], 0)=mryes then close; end;

procedure TForm1.Button2Click(Sender: TObject); begin FORM2.SHOW; //Form1.Close; end;

procedure TForm1.Button4Click(Sender: TObject); begin

If OpenPictureDialog1.Execute then Image1.Visible:=TRUE; Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);

end;

procedure TForm1.Button1Click(Sender: TObject); begin IF Button1.Caption='&SIMPAN' then begin FORM2.ADOQuery1.Append;

Form2.ADOQuery1.fieldbyname('nim').Value:=Edit1.Text; Form2.ADOQuery1.fieldbyname('NAMA').Value:=Edit2.Text; Form2.ADOQuery1.fieldbyname('TEMPAT_LAHIR').Value:=Edit3.Text; Form2.ADOQuery1.fieldbyname('TTL').Value:=DateTimePicker1.DateFormat; Form2.ADOQuery1.fieldbyname('JENIS_KELAMIN').Value:=ComboBox1.Text; Form2.ADOQuery1.fieldbyname('AGAMA').Value:=ComboBox2.Text; Form2.ADOQuery1.fieldbyname('STATUS').Value:=ComboBox3.Text; Form2.ADOQuery1.fieldbyname('PEKERJAAN').Value:=Edit5.Text; Form2.ADOQuery1.fieldbyname('ALAMAT').Value:= Edit6.Text; Form2.ADOQuery1.fieldbyname('jurusan').Value:= Edit8.Text; Form2.ADOQuery1.fieldbyname('TELEPON').Value:=Edit4.Text; Form2.ADOQuery1.fieldbyname('EMAIL').Value:=Edit7.Text; Form2.ADOQuery1.fieldbyname('FOTO').Value:=OpenPictureDialog1.FileName; Form2.ADOQuery1.Post; Edit1.Text:=''; Edit2.Text:=''; Edit3.Text:=''; Edit4.Text:=''; Edit5.Text:=''; Edit6.Text:=''; Edit7.Text:=''; Edit8.Text:=''; ComboBox1.Text:=''; ComboBox2.Text:=''; ComboBox3.Text:=''; DateTimePicker1.Date:=now; Image1.Visible:=false; Button1.Caption:='TAMBAH'; ShowMessage('PROSES SIMPAN TELAH DILAKSANAKAN'); Button1.Caption:='TAMBAH'; end else

if Button1.Caption='UBAH' then BEGIN FORM2.ADOQuery1.EDIT; Form2.ADOQuery1.fieldbyname('nim').Value:=Edit1.Text; Form2.ADOQuery1.fieldbyname('NAMA').Value:=Edit2.Text; Form2.ADOQuery1.fieldbyname('TEMPAT_LAHIR').Value:=Edit3.Text; Form2.ADOQuery1.fieldbyname('TTL').Value:=DateTimePicker1.DateTime; Form2.ADOQuery1.fieldbyname('JENIS_KELAMIN').Value:=ComboBox1.Text; Form2.ADOQuery1.fieldbyname('AGAMA').Value:=ComboBox2.Text; Form2.ADOQuery1.fieldbyname('STATUS').Value:=ComboBox3.Text; Form2.ADOQuery1.fieldbyname('PEKERJAAN').Value:=Edit5.Text; Form2.ADOQuery1.fieldbyname('ALAMAT').Value:= Edit6.Text; Form2.ADOQuery1.fieldbyname('TELEPON').Value:=Edit4.Text; Form2.ADOQuery1.fieldbyname('EMAIL').Value:=Edit7.Text; Form2.ADOQuery1.fieldbyname('jurusan').Value:= Edit8.Text; Form2.ADOQuery1.fieldbyname('FOTO').Value:=OpenPictureDialog1.FileName; Form2.ADOQuery1.Post; Edit1.Text:=''; Edit2.Text:=''; Edit3.Text:=''; Edit4.Text:=''; Edit5.Text:=''; Edit6.Text:=''; Edit7.Text:=''; Edit8.Text:=''; ComboBox1.Text:=''; ComboBox2.Text:=''; ComboBox3.Text:=''; DateTimePicker1.Date:=now; Image1.Visible:=false; Button1.Caption:='TAMBAH';

ShowMessage('PROSES UBAH TELAH DILAKSANAKAN');

END ELSE IF Button1.Caption='TAMBAH' THEN BEGIN Form2.ADOQuery1.Insert; Button1.Caption:='&SIMPAN'; Edit1.SetFocus; END

end;

procedure TForm1.FormShow(Sender: TObject); begin DateTimePicker1.Date:=NOW; end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); var kdj:string; begin

if Key=#13 then begin Form2.ADOQuery1.SQL.Clear; Form2.ADOQuery1.SQL.Add('select * from tbl_mahasiswa where nim='''+Edit1.Text+''''); Form2.ADOQuery1.Open; if Form2.ADOQuery1.IsEmpty then begin Edit2.SetFocus; kdj:=copy(Edit1.Text,0,2);

// Edit8.Text:=kdj; // ADOQuery1.SQL.Clear; //ADOQuery1.SQL.Add('select * from tbl_JURUSAN where KODE='''+kdj+''''); //ADOQuery1.Open; // Edit8.Text:=ADOQuery1.FieldByName('NAMA').Value; //Label12.Caption:=ADOQuery1.FieldByName('NAMA').Value; end else begin ShowMessage('data sudah ada silahkan input nim yang lain'); Edit1.Text:=''; Edit1.SetFocus; end; end; end;

procedure TForm1.FormPaint(Sender: TObject); var Row, Ht: Word; IX: Integer; begin iX :=200 ; Ht:=(ClientHeight + 900) div 100; for Row := 0 to 900 do begin with Canvas do begin Brush.Color := RGB(Ix,150,row); FillRect(Rect(0, Row * Ht, ClientWidth, (Row + 2) * Ht)); IX :=(IX-1); end; end;

END;

procedure TForm1.Edit1Change(Sender: TObject); var kdj: String; begin kdj:=copy(Edit1.Text,0,2); ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add('select * from tbl_JURUSAN where KODE='''+kdj+''''); ADOQuery1.Open; Edit8.Text:=ADOQuery1.FieldByName('NAMA').AsString; end;

procedure TForm1.Edit2Click(Sender: TObject); begin Form2.ADOQuery1.SQL.Clear; Form2.ADOQuery1.SQL.Add('select * from tbl_mahasiswa where nim='''+Edit1.Text+''''); Form2.ADOQuery1.Open; if Form2.ADOQuery1.IsEmpty then // begin // Edit2.SetFocus; // kdj:=copy(Edit1.Text,0,2); // Edit8.Text:=kdj; // ADOQuery1.SQL.Clear; //ADOQuery1.SQL.Add('select * from tbl_JURUSAN where KODE='''+kdj+''''); //ADOQuery1.Open; // Edit8.Text:=ADOQuery1.FieldByName('NAMA').Value; //Label12.Caption:=ADOQuery1.FieldByName('NAMA').Value; // end else begin ShowMessage('data sudah ada silahkan input nim yang lain');

Edit1.Text:=''; Edit1.SetFocus; end; end;

end.

Form 2 unit Unit2;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB, XPMan;

type TForm2 = class(TForm) DBGrid1: TDBGrid; Label1: TLabel; Edit1: TEdit; Button1: TButton; ADOConnection1: TADOConnection; ADOQuery1: TADOQuery; DataSource1: TDataSource; XPManifest1: TXPManifest; procedure Button1Click(Sender: TObject); procedure DBGrid1DblClick(Sender: TObject); procedure Edit1Change(Sender: TObject); procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);

private { Private declarations } public { Public declarations } end;

var Form2: TForm2;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject); begin CLOSE; end;

procedure TForm2.DBGrid1DblClick(Sender: TObject); begin IF ADOQuery1.FieldByName('FOTO').AsString<>'' THEN BEGIN Form1.Image1.Visible:=TRUE; Form1.Edit1.Text:=ADOQuery1.fieldbyname('NIM').AsString; Form1.Edit2.Text:=ADOQuery1.fieldbyname('NAMA').AsString; Form1.Edit3.Text:=ADOQuery1.fieldbyname('TEMPAT_LAHIR').AsString; Form1.DateTimePicker1.DateTime:=ADOQuery1.fieldbyname('TTL').AsDateTime; Form1.ComboBox1.Text:=ADOQuery1.fieldbyname('JENIS_KELAMIN').AsString; Form1.ComboBox2.Text:=ADOQuery1.fieldbyname('AGAMA').AsString;

Form1.ComboBox3.Text:=ADOQuery1.fieldbyname('STATUS').Value; Form1.Edit5.Text:=ADOQuery1.fieldbyname('PEKERJAAN').Value; Form1.Edit6.Text:=ADOQuery1.fieldbyname('ALAMAT').AsString; Form1.Edit4.Text:=ADOQuery1.fieldbyname('TELEPON').AsString; Form1.Edit7.Text:=ADOQuery1.fieldbyname('EMAIL').AsString; Form1.Image1.Picture.LoadFromFile(ADOQuery1.fieldbyname('FOTO').Value); Form1.Button1.Caption:='UBAH'; form1.show; Form2.Hide; END ELSE BEGIN Form1.Edit1.Text:=ADOQuery1.fieldbyname('NIM').AsString; Form1.Edit2.Text:=ADOQuery1.fieldbyname('NAMA').AsString; Form1.Edit3.Text:=ADOQuery1.fieldbyname('TEMPAT_LAHIR').AsString; Form1.DateTimePicker1.DateTime:=ADOQuery1.fieldbyname('TTL').AsDateTime; Form1.ComboBox1.Text:=ADOQuery1.fieldbyname('JENIS_KELAMIN').AsString; Form1.ComboBox2.Text:=ADOQuery1.fieldbyname('AGAMA').AsString; Form1.ComboBox3.Text:=ADOQuery1.fieldbyname('STATUS').Value; Form1.Edit5.Text:=ADOQuery1.fieldbyname('PEKERJAAN').Value; Form1.Edit6.Text:=ADOQuery1.fieldbyname('ALAMAT').AsString; Form1.Edit4.Text:=ADOQuery1.fieldbyname('TELEPON').AsString; Form1.Edit7.Text:=ADOQuery1.fieldbyname('EMAIL').AsString; Form1.Image1.Visible:=FALSE; Form1.Button1.Caption:='UBAH'; form1.show; Form2.Hide; END end;

procedure TForm2.Edit1Change(Sender: TObject);

begin ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add('select * from tbl_mahasiswa where nama like ''%'+edit1.Text+'%'''); ADOQuery1.Open; end;

procedure TForm2.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if DBGrid1.DataSource.DataSet.RecNo mod 2 =0 then DBGrid1.Canvas.Brush.Color := clskyBlue; //pilih warnanya DBGrid1.DefaultDrawColumnCell(rect, datacol, column, state); end;

end.

You might also like