Advertisement
rikokurniawan

Lat ke 7 penggunaan inputan data ke StringGrid

Nov 29th, 2012
886
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.22 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, Grids, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     GroupBox1: TGroupBox;
  12.     Label1: TLabel;
  13.     Label2: TLabel;
  14.     Label3: TLabel;
  15.     Label4: TLabel;
  16.     Label5: TLabel;
  17.     Label6: TLabel;
  18.     ComboBox1: TComboBox;
  19.     Edit1: TEdit;
  20.     Edit2: TEdit;
  21.     Edit3: TEdit;
  22.     Edit4: TEdit;
  23.     Edit5: TEdit;
  24.     Button1: TButton;
  25.     StringGrid1: TStringGrid;
  26.     Button2: TButton;
  27.     Button3: TButton;
  28.     Label7: TLabel;
  29.     Label8: TLabel;
  30.     Label9: TLabel;
  31.     Edit6: TEdit;
  32.     Edit7: TEdit;
  33.     Edit8: TEdit;
  34.     procedure FormCreate(Sender: TObject);
  35.     procedure ComboBox1Click(Sender: TObject);
  36.     procedure Button1Click(Sender: TObject);
  37.     procedure Button3Click(Sender: TObject);
  38.     procedure Button2Click(Sender: TObject);
  39.   private
  40.     { Private declarations }
  41.   public
  42.     { Public declarations }
  43.     procedure bersih;
  44.     procedure hitung;
  45.   end;
  46.  
  47. var
  48.   Form1: TForm1;
  49.  
  50. implementation
  51.  
  52. {$R *.dfm}
  53.  
  54. procedure TForm1.bersih;
  55. begin
  56.   Edit1.Clear;
  57.   Edit2.Clear;
  58.   Edit3.Clear;
  59.   Edit4.Clear;
  60.   Edit5.Clear;
  61.   Edit6.Clear;
  62.   Edit7.Clear;
  63.   Edit8.Clear;
  64.   ComboBox1.Text:='';
  65.   StringGrid1.RowCount:=1;
  66. end;
  67.  
  68. procedure TForm1.hitung;
  69. var i,t,D:Integer;
  70. begin
  71. With StringGrid1 Do Begin
  72.   t:=0;
  73.   D:=0;
  74.   for i := 1 to RowCount - 1 do begin
  75.     Cells[0,i]:=IntToStr(i);
  76.     t:=t + StrToInt(Cells[6,i]);
  77.     D:=D + StrToInt(Cells[7,i]);
  78.   end;
  79.   Edit6.Text:=IntToStr(t);
  80.   Edit7.Text:=IntToStr(D);
  81.   Edit8.Text:=CurrToStr(StrToCurr(Edit6.Text)-StrToCurr(Edit7.Text));
  82. End;
  83. end;
  84.  
  85. procedure TForm1.Button1Click(Sender: TObject);
  86. begin
  87.   if Length(Edit5.Text)=0 then begin
  88.     Application.MessageBox('Jumlah Belum Benar','Cek Pengisian Jumlah', MB_ICONWARNING);
  89.     Edit5.SetFocus;
  90.     EXIT;
  91.   end;
  92.   if StrToInt(Edit5.Text)<=0 then begin
  93.     Application.MessageBox('Jumlah Belum Benar','Cek Pengisian Jumlah', MB_ICONWARNING);
  94.     Edit5.SetFocus;
  95.     EXIT;
  96.   end;
  97.   With StringGrid1 Do Begin
  98.     RowCount:= RowCount+ 1;
  99.     FixedCols:=1;
  100.     FixedRows:=1;
  101.    
  102.     Cells[1,RowCount - 1]:=ComboBox1.Text;
  103.     Cells[2,RowCount - 1]:=Edit1.Text;
  104.     Cells[3,RowCount - 1]:=Edit2.Text;
  105.     Cells[4,RowCount - 1]:=Edit3.Text;
  106.     Cells[5,RowCount - 1]:=Edit5.Text;
  107.     Cells[6,RowCount - 1]:=CurrToStr(StrToCurr(Edit3.Text)*StrToCurr(Edit5.Text));
  108.     Cells[7,RowCount - 1]:=CurrToStr(((StrToCurr(Edit3.Text) * StrToCurr(Edit4.Text))/100) * StrToInt(Edit5.Text));
  109.     hitung;
  110.   End;
  111.  
  112. end;
  113.  
  114. procedure TForm1.Button2Click(Sender: TObject);
  115. begin
  116.   Bersih;
  117. end;
  118.  
  119. procedure TForm1.Button3Click(Sender: TObject);
  120. begin
  121. Close;
  122. end;
  123.  
  124. procedure TForm1.ComboBox1Click(Sender: TObject);
  125. begin
  126. if ComboBox1.Text='BRG01' then begin
  127.   Edit1.Text:='Nasi Goreng';
  128.   Edit2.Text:='Porsi';
  129.   Edit3.Text:='6000';
  130.   Edit4.Text:='5';
  131.   Edit5.SetFocus;
  132. end
  133. else if ComboBox1.Text='BRG02' then begin
  134.   Edit1.Text:='Mie Goreng';
  135.   Edit2.Text:='Porsi';
  136.   Edit3.Text:='6000';
  137.   Edit4.Text:='10';
  138.   Edit5.SetFocus;
  139. end
  140. else if ComboBox1.Text='BRG03' then begin
  141.   Edit1.Text:='Bakso';
  142.   Edit2.Text:='Porsi';
  143.   Edit3.Text:='8000';
  144.   Edit4.Text:='2';
  145.   Edit5.SetFocus;
  146. end
  147. else if ComboBox1.Text='BRG04' then begin
  148.   Edit1.Text:='Pangsit';
  149.   Edit2.Text:='Porsi';
  150.   Edit3.Text:='8000';
  151.   Edit4.Text:='0';
  152.   Edit5.SetFocus;
  153. end
  154. else if ComboBox1.Text='BRG05' then begin
  155.   Edit1.Text:='Soto';
  156.   Edit2.Text:='Porsi';
  157.   Edit3.Text:='9000';
  158.   Edit4.Text:='3';
  159.   Edit5.SetFocus;
  160. end;
  161. end;
  162.  
  163. procedure TForm1.FormCreate(Sender: TObject);
  164. begin
  165. bersih;
  166. ComboBox1.Clear;
  167. ComboBox1.Items.Add('BRG01');
  168. ComboBox1.Items.Add('BRG02');
  169. ComboBox1.Items.Add('BRG03');
  170. ComboBox1.Items.Add('BRG04');
  171. ComboBox1.Items.Add('BRG05');
  172.  
  173. With StringGrid1 Do Begin
  174.   RowCount:=1;
  175.   ColCount:=8;
  176.   Cells[0,0]:='NO';
  177.   Cells[1,0]:='KODE';
  178.   Cells[2,0]:='BARANG';
  179.   Cells[3,0]:='SATUAN';
  180.   Cells[4,0]:='HARGA';
  181.   Cells[5,0]:='JUMLAH';
  182.   Cells[6,0]:='TOTAL';
  183.   Cells[7,0]:='DISKON';
  184.  
  185.   ColWidths[0]:=30;
  186.   ColWidths[1]:=80;
  187.   ColWidths[2]:=100;
  188.   ColWidths[3]:=80;
  189.   ColWidths[4]:=80;
  190.   ColWidths[5]:=80;
  191.   ColWidths[6]:=80;
  192.   ColWidths[7]:=80;
  193. End;
  194. end;
  195.  
  196. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement