Maaf masih nuebie, jadi jangan diketawain ya.. hehehe
Inilah Hasilnya :
Dan waktu di Jalankan hasilnya :
Kalau ada yg berminat ini source codenya:
unit PB;interfaceusesWinapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.DBCtrls, Vcl.ExtCtrls,Data.DB, Data.Win.ADODB, Vcl.DBLookup, Vcl.ComCtrls, Data.FMTBcd, Vcl.Grids,Data.SqlExpr, Vcl.DBGrids;typeTForm2 = class(TForm)Panel1: TPanel;Label1: TLabel;Label2: TLabel;Edit2: TEdit;Label3: TLabel;ADODataSet1: TADODataSet;DataSource1: TDataSource;DBLookupComboBox1: TDBLookupComboBox;ADODataSet2: TADODataSet;DateTimePicker1: TDateTimePicker;Label4: TLabel;Edit1: TEdit;DBText1: TDBText;Edit3: TEdit;Button1: TButton;ADODataSet3: TADODataSet;SG: TStringGrid;Edit4: TEdit;Edit5: TEdit;Edit6: TEdit;Edit7: TEdit;Button2: TButton;Button3: TButton;procedure FormClose(Sender: TObject; var Action: TCloseAction);procedure FormActivate(Sender: TObject);procedure Edit3KeyPress(Sender: TObject; var Key: Char);procedure Edit2KeyPress(Sender: TObject; var Key: Char);procedure FormCreate(Sender: TObject);procedure aturkolom;procedure tampil;procedure SGKeyPress(Sender: TObject; var Key: Char);procedure SGSelectCell(Sender: TObject; ACol, ARow: Integer;var CanSelect: Boolean);procedure Edit1KeyPress(Sender: TObject; var Key: Char);procedure SGDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;State: TGridDrawState);private{ Private declarations }public{ Public declarations }end;varFPB: TForm2;y,sel : integer;sum : real;vSQL1, vsql2, vsql3,a,b: string;implementation{$R *.dfm}uses Utama;procedure TForm2.tampil;Var i : Integer;beginif ADODataSet3.RecordCount<>0 thenbeginSG.RowCount:= ADODataSet3.RecordCount+1;for i:= 0 to ADODataSet3.RecordCount-1 dobegininc(y);SG.Cells[0,i+1]:=IntToStr(i+1)+'.';SG.Cells[1,i+1]:=ADODataSet3.FieldByName('ItemCode').AsString;SG.Cells[2,i+1]:=ADODataSet3.FieldByName('namaitem').AsString;SG.Cells[3,i+1]:=ADODataSet3.FieldByName('satuan').AsString;SG.Cells[4,i+1]:=ADODataSet3.FieldByName('qty').AsString;SG.Cells[5,i+1]:=ADODataSet3.FieldByName('harga').AsString;SG.Cells[6,i+1]:=ADODataSet3.FieldByName('total').AsString;{SG.Cells[6,i+1]:=ADODataSet3.FieldByName('suplier').AsString;}ADODataSet3.Next;end;end;end;procedure TForm2.aturkolom;beginwith SG dobeginColCount:=9;RowCount:=2;FixedCols:=1;DefaultROwHeight:=18;{Options := [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSelect];}Options := options+[goediting];Cells[0,0]:='No.';Cells[1,0]:='Kode Barang';Cells[2,0]:='Nama Barang';Cells[3,0]:='Satuan';Cells[4,0]:='Qty';Cells[5,0]:='Harga';Cells[6,0]:='Total';Cells[4,1] := '0';Cells[5,1] := '0';Cells[6,1] := '0';//lebar kolomColWidths[0]:=25;ColWidths[1]:=90;ColWidths[2]:=300;ColWidths[3]:=50;ColWidths[4]:=60;ColWidths[5]:=100;ColWidths[6]:=100;ColWidths[7]:=0;ColWidths[8]:=0;end;end;procedure TForm2.Edit1KeyPress(Sender: TObject; var Key: Char);beginif key = chr(13) thenbeginSG.Row:=1;SG.Col:=1;sg.setfocus;end;end;procedure TForm2.Edit2KeyPress(Sender: TObject; var Key: Char);beginif key = chr(13) thenedit3.SetFocus;end;procedure TForm2.Edit3KeyPress(Sender: TObject; var Key: Char);var sql : string;beginif key = chr(13) thenBeginsql := 'Select Supplier, NamaSup From apsuppl Where Supplier = '+quotedstr(edit3.Text);adodataset1.Active := false;AdoDataSet1.CommandText := Sql;adodataset1.Active := true;edit1.SetFocus;if adodataset1.Eof thenshowmessage('Data Tidak Terdaftar')End;end;procedure TForm2.FormActivate(Sender: TObject);var Yr, Mn, Dy : Word;awal : integer;ID,Kd : string;beginy := 1;sel := 1;aturkolom;DecodeDate(Now, Yr, Mn, Dy);adodataset2.CommandText := 'select * from no_beli where bulan = '+inttostr(mn)+' and tahun = '+inttostr(yr);adodataset2.Active:=true;awal := adodataset2.FieldByName('Urut').Asinteger+1;kd := inttostr(awal);ID := Copy('0000'+kd,length('0000'+kd)-3,4);edit2.Text := 'PB'+FormatDateTime('YYMM',Now)+ID;{inttostr(Yr);}datetimepicker1.Date:=now;edit1.Text:='';edit3.Text:='';edit7.Text:=FloatToStrF(0, ffNumber, 12, 2);end;procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);beginrelease;end;procedure TForm2.FormCreate(Sender: TObject);beginDBLookupCombobox1.Visible:=False;end;procedure TForm2.SGDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;State: TGridDrawState);const _Padding = 2;var _sg : TStringGrid;_text : string;_textwidth : integer;_cellwidth : integer;_xpos, _ypos : integer;begin_sg := Sender as TStringGrid;_text := _sg.cells[ACol, ARow];_textwidth := _sg.Canvas.TextWidth(_text);_cellwidth := rect.Right - rect.Left + 1;//if ACol = 3 then begin//Centered_xpos := rect.left + ((_cellwidth - _textwidth) div 2) + _padding;end else if (ACol = 4) or (ACol = 5) or (ACol = 6) then begin//Right Justify_xpos := rect.left + (_cellwidth - _textwidth) - _padding;end else begin//Left Justify_xpos := rect.left + _padding;end;_ypos := rect.top + _padding;_sg.Canvas.TextRect(rect, _xpos, _ypos, _text);end;procedure TForm2.SGKeyPress(Sender: TObject; var Key: Char);var ttl : real;i : integer;beginif Key = chr(13) thenbeginadodataset3.Active := false;ttl := 0;if sel > 1 thenbeginif sel = 5 thenbeginsel := 0;edit6.Text:=inttostr(y+1);if sg.Cells[1,sg.RowCount-1] <> '' thenbeginsg.RowCount:=sg.RowCount+1;SG.Cells[4,SG.RowCount-1] := '0';SG.Cells[5,SG.RowCount-1] := '0';SG.Cells[6,SG.RowCount-1] := '0';end;inc(y);end;inc(sel);endelsebeginif sg.Cells[sel,y] <> '' thenAdoDataSet3.CommandText := '';a := sg.Cells[1,y];vSQL1:= 'Select ItemCode, NamaItem, Satuan, Harga From IcAlt Where ItemCode = '+QuotedStr(a);AdoDataSet3.CommandText := VSql1;AdoDataSet3.Active := true;if adodataset3.Eof thenshowmessage('Data Tidak Terdaftar')elsebeginsg.Cells[0,y] := inttostr(y);sg.Cells[2,y] := adodataset3.FieldByName('NamaItem').AsString;sg.Cells[3,y] := adodataset3.FieldByName('Satuan').AsString;sg.Cells[7,y] := adodataset3.FieldByName('Harga').AsString;SG.Cells[5,y] := FloatToStrF(adodataset3.FieldByName('Harga').AsFloat, ffNumber, 12, 2);inc(sel);end;end;if (SG.Cells[7,y] <> '') and (SG.Cells[4,y] <> '') thenbeginttl := Strtofloat(SG.Cells[7,y]) * strtofloat(SG.Cells[4,y]);SG.Cells[6,y] := FloatToStrF(ttl, ffNumber, 12, 2);SG.Cells[8,y] := floattostr(ttl);Sum := 0;for i := 1 to SG.RowCount-1 DoSum := Sum + strtofloat(SG.Cells[8, i]);Edit7.Text:=FloatToStrF(SUM, ffNumber, 12, 2);end;edit4.Text:=inttostr(sel);edit5.Text:=inttostr(y);SG.Row:=strtoint(edit5.Text);SG.Col:=strtoint(edit4.Text);SG.SetFocus;end;end;procedure TForm2.SGSelectCell(Sender: TObject; ACol, ARow: Integer;var CanSelect: Boolean);beginsel:=Acol;y:=Arow;end;end.
Semoga Bermanfaat..
Tidak ada komentar:
Posting Komentar