-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUBarang.pas
419 lines (391 loc) · 11.6 KB
/
UBarang.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
unit UBarang;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, ExtCtrls;
type
TForm4 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Shape1: TShape;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Edit1: TEdit;
DBGrid1: TDBGrid;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
Edit5: TEdit;
ComboBox1: TComboBox;
Panel6: TPanel;
Panel7: TPanel;
Label8: TLabel;
Edit6: TEdit;
Edit7: TEdit;
Label9: TLabel;
Label10: TLabel;
ComboBox2: TComboBox;
Label11: TLabel;
Label12: TLabel;
Panel8: TPanel;
procedure Panel7Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Panel5Click(Sender: TObject);
procedure Panel4Click(Sender: TObject);
procedure Panel3Click(Sender: TObject);
procedure Panel2Click(Sender: TObject);
procedure DBGrid1CellClick(Column: TColumn);
procedure Edit7Change(Sender: TObject);
procedure Edit2Change(Sender: TObject);
procedure Panel6Click(Sender: TObject);
procedure Panel8Click(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure cekkey;
procedure Edit7KeyPress(Sender: TObject; var Key: Char);
procedure Edit4KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
uses
UDataModule, UKategori;
{$R *.dfm}
procedure TForm4.Panel7Click(Sender: TObject);
var
id : string;
begin
// coding untuk memilih kode dengan nomor yg paling terbesar :
DM.ADOQIdBarang.Close;
DM.ADOQIdBarang.SQL.Clear;
DM.ADOQIdBarang.SQL.Add('SELECT TOP 1 DataBarang.kodeBarang FROM DataBarang');
DM.ADOQIdBarang.SQL.Add('ORDER BY DataBarang.kodeBarang DESC');
DM.ADOQIdBarang.Open;
// coding untuk mengcopy nilai yang di seleksi :
id := Copy(DM.ADOQIdBarang.Fields[0].AsString, 4, 6);
// coding jika seleksi = 0 maka id = 00001 jika tdk maka tambah 1 :
if id <> '' then id := FormatFLoat('000000', StrtoInt(id) + 1)
else id := '000001';
// coding melakukan pengabungan kode string dan integer :
Form4.Edit6.Text := 'BA-' + id;
Panel5.Enabled := True;
Panel4.Enabled := False;
Panel3.Enabled := False;
Edit1.Clear;
Edit2.Clear;
Edit3.Clear;
Edit4.Clear;
Edit7.Clear;
ComboBox2.Text := '';
DM.ADOQDataBarang.Filtered := False;
end;
procedure TForm4.FormActivate(Sender: TObject);
begin
combobox2.Clear;
DM.ADOQKategori.Close;
Dm.ADOQKategori.Open;
While not Dm.ADOQKategori.Eof do
begin
combobox2.Items.Add(DM.ADOQKategori['kategori']);
Dm.ADOQKategori.Next;
end;
Edit6.Clear;
Edit1.Clear;
ComboBox2.Text := '';
Edit2.Clear;
Edit7.Clear;
Edit3.Clear;
Edit4.Clear;
Panel5.Enabled := False;
Panel4.Enabled := False;
Panel3.Enabled := False;
ComboBox1.Text := '';
Edit5.Clear;
Label11.Caption := '1';
Label12.Caption := '0';
end;
procedure TForm4.Panel5Click(Sender: TObject);
begin
if Edit6.Text = '' then MessageDlg('Kode Barang Kosong',mtinformation,[mbok],0) else
if Edit1.Text = '' then MessageDlg('Nama Barang Kosong',mtinformation,[mbok],0) else
if ComboBox2.Text = '' then MessageDlg('Kategori Kosong',mtinformation,[mbok],0) else
if Edit7.Text = '' then MessageDlg('Harga Jual Kosong',mtinformation,[mbok],0) else
if Edit2.Text = '' then MessageDlg('Harga Beli Kosong',mtinformation,[mbok],0) else
if Edit3.Text = '' then MessageDlg('Keuntungan Kosong',mtinformation,[mbok],0) else
if Edit4.Text = '' then MessageDlg('Stok Kosong',mtinformation,[mbok],0) else
begin
DM.ADOQDataBarang.Append;
DM.ADOQDataBarang['kodeBarang'] := Edit6.Text;
DM.ADOQDataBarang['namaBarang'] := Edit1.Text;
DM.ADOQDataBarang['kategori'] := ComboBox2.Text;
DM.ADOQDataBarang['hargaBeli'] := Edit2.Text;
DM.ADOQDataBarang['hargaJual'] := Edit7.Text;
DM.ADOQDataBarang['Laba'] := Edit3.Text;
DM.ADOQDataBarang['stok'] := Edit4.Text;
DM.ADOQDataBarang.Post;
Edit6.Clear;
Edit1.Clear;
ComboBox2.Text := '';
Edit2.Clear;
Edit7.Clear;
Edit3.Clear;
Edit4.Clear;
Panel5.Enabled := False;
end;
end;
procedure TForm4.Panel4Click(Sender: TObject);
begin
if Edit6.Text = '' then MessageDlg('Kode Barang Kosong',mtinformation,[mbok],0) else
if Edit1.Text = '' then MessageDlg('Nama Barang Kosong',mtinformation,[mbok],0) else
if ComboBox2.Text = '' then MessageDlg('Kategori Kosong',mtinformation,[mbok],0) else
if Edit7.Text = '' then MessageDlg('Harga Jual Kosong',mtinformation,[mbok],0) else
if Edit2.Text = '' then MessageDlg('Harga Beli Kosong',mtinformation,[mbok],0) else
if Edit3.Text = '' then MessageDlg('Keuntungan Kosong',mtinformation,[mbok],0) else
if Edit4.Text = '' then MessageDlg('Stok Kosong',mtinformation,[mbok],0) else
begin
DM.ADOQDataBarang.Edit;
DM.ADOQDataBarang['kodeBarang'] := Edit6.Text;
DM.ADOQDataBarang['namaBarang'] := Edit1.Text;
DM.ADOQDataBarang['kategori'] := ComboBox2.Text;
DM.ADOQDataBarang['hargaBeli'] := Edit2.Text;
DM.ADOQDataBarang['hargaJual'] := Edit7.Text;
DM.ADOQDataBarang['Laba'] := Edit3.Text;
DM.ADOQDataBarang['stok'] := Edit4.Text;
DM.ADOQDataBarang.Post;
Edit6.Clear;
Edit1.Clear;
ComboBox2.Text := '';
Edit2.Clear;
Edit7.Clear;
Edit3.Clear;
Edit4.Clear;
Panel4.Enabled := False;
Panel3.Enabled := False;
end;
Label11.Caption := '1';
Label12.Caption := '0';
end;
procedure TForm4.Panel3Click(Sender: TObject);
begin
if Dm.ADOQDataBarang.IsEmpty then MessageDlg('Data Kosong',mtInformation,[mbok],0) else
if Application.MessageBox('Yakin Hapus Data ??','Pesan',Mb_YesNo or Mb_IconQuestion)=MrYes then
Begin
Dm.ADOQDataBarang.Delete;
Edit6.Clear;
Edit1.Clear;
ComboBox2.Text := '';
Edit2.Clear;
Edit7.Clear;
Edit3.Clear;
Edit4.Clear;
Panel4.Enabled := False;
Panel3.Enabled := False;
End;
Label11.Caption := '1';
Label12.Caption := '0';
end;
procedure TForm4.Panel2Click(Sender: TObject);
begin
Edit6.Clear;
Edit1.Clear;
ComboBox2.Text := '';
Edit2.Clear;
Edit7.Clear;
Edit3.Clear;
Edit4.Clear;
Panel5.Enabled := False;
Panel4.Enabled := False;
Panel3.Enabled := False;
ComboBox1.Text := '';
Edit5.Clear;
Label11.Caption := '1';
Label12.Caption := '0';
DM.ADOQDataBarang.Filtered := False;
end;
procedure TForm4.DBGrid1CellClick(Column: TColumn);
begin
if Dm.ADOQDataBarang.IsEmpty then MessageDlg('Data Barang Kosong',mtInformation,[mbok],0) else
begin
Label11.Caption := '0';
Label12.Caption := '1';
Edit6.Text := DM.ADOQDataBarang['kodeBarang'] ;
Edit1.Text := DM.ADOQDataBarang['namaBarang'] ;
ComboBox2.Text := DM.ADOQDataBarang['kategori'] ;
Edit2.Text := DM.ADOQDataBarang['hargaBeli'] ;
Edit7.Text := DM.ADOQDataBarang['hargaJual'] ;
Edit3.Text := DM.ADOQDataBarang['Laba'] ;
Edit4.Text := DM.ADOQDataBarang['stok'] ;
Panel5.Enabled := False;
Panel4.Enabled := True;
Panel3.Enabled := True;
end;
end;
procedure TForm4.Edit7Change(Sender: TObject);
begin
if Label11.Caption = '1' then
begin
if (Edit2.Text <> '') and (Edit7.Text <> '') then
begin
Edit3.Text := FloatToStr(StrToFloat(Edit7.Text) - StrToFloat(Edit2.Text));
end
else
if (Edit2.Text = '') and (Edit7.Text <> '') then
begin
Edit3.Text := FloatToStr(StrToFloat(Edit7.Text) - 0);
end
else
if (Edit2.Text <> '') and (Edit7.Text = '') then
begin
Edit3.Text := FloatToStr(0 - StrToFloat(Edit2.Text));
end
else
if (Edit2.Text = '') and (Edit7.Text = '') then
begin
Edit3.Text := FloatToStr(0 - 0);
end;
end;
if Label12.Caption = '1' then
begin
if (Edit2.Text <> '') and (Edit7.Text <> '') then
begin
Edit3.Text := FloatToStr(StrToFloat(Edit7.Text) - StrToFloat(Edit2.Text));
end
else
if (Edit2.Text = '') and (Edit7.Text <> '') then
begin
Edit3.Text := FloatToStr(StrToFloat(Edit7.Text) - 0);
end
else
if (Edit2.Text <> '') and (Edit7.Text = '') then
begin
Edit3.Text := FloatToStr(0 - StrToFloat(Edit2.Text));
end
else
if (Edit2.Text = '') and (Edit7.Text = '') then
begin
Edit3.Text := FloatToStr(0 - 0);
end;
end;
end;
procedure TForm4.Edit2Change(Sender: TObject);
begin
if Label11.Caption = '1' then
begin
if (Edit2.Text <> '') and (Edit7.Text <> '') then
begin
Edit3.Text := FloatToStr(StrToFloat(Edit7.Text) - StrToFloat(Edit2.Text));
end
else
if (Edit2.Text = '') and (Edit7.Text <> '') then
begin
Edit3.Text := FloatToStr(StrToFloat(Edit7.Text) - 0);
end
else
if (Edit2.Text <> '') and (Edit7.Text = '') then
begin
Edit3.Text := FloatToStr(0 - StrToFloat(Edit2.Text));
end
else
if (Edit2.Text = '') and (Edit7.Text = '') then
begin
Edit3.Text := FloatToStr(0 - 0);
end;
end;
if Label12.Caption = '1' then
begin
if (Edit2.Text <> '') and (Edit7.Text <> '') then
begin
Edit3.Text := FloatToStr(StrToFloat(Edit7.Text) - StrToFloat(Edit2.Text));
end
else
if (Edit2.Text = '') and (Edit7.Text <> '') then
begin
Edit3.Text := FloatToStr(StrToFloat(Edit7.Text) - 0);
end
else
if (Edit2.Text <> '') and (Edit7.Text = '') then
begin
Edit3.Text := FloatToStr(0 - StrToFloat(Edit2.Text));
end
else
if (Edit2.Text = '') and (Edit7.Text = '') then
begin
Edit3.Text := FloatToStr(0 - 0);
end;
end;
end;
procedure TForm4.Panel6Click(Sender: TObject);
begin
if (ComboBox1.Text = '') and (Edit5.Text = '') then
begin
DM.ADOQDataBarang.Filtered := False;
end
else
if (ComboBox1.Text = 'KODE BARANG') and (Edit5.Text <> '') then
begin
Dm.ADOQDataBarang.Close;
Dm.ADOQDataBarang.Open;
Dm.ADOQDataBarang.Filtered := False;
DM.ADOQDataBarang.Filter :='kodeBarang LIKE '+Quotedstr('%'+Edit5.Text+'%');
Dm.ADOQDataBarang.Filtered := True;
end
else
if (ComboBox1.Text = 'NAMA BARANG') and (Edit5.Text <> '') then
begin
Dm.ADOQDataBarang.Close;
Dm.ADOQDataBarang.Open;
Dm.ADOQDataBarang.Filtered := False;
DM.ADOQDataBarang.Filter :='namaBarang LIKE '+Quotedstr('%'+Edit5.Text+'%');
Dm.ADOQDataBarang.Filtered := True;
end
else
if (ComboBox1.Text = 'KATEGORI') and (Edit5.Text <> '') then
begin
Dm.ADOQDataBarang.Close;
Dm.ADOQDataBarang.Open;
Dm.ADOQDataBarang.Filtered := False;
DM.ADOQDataBarang.Filter :='kategori LIKE '+Quotedstr('%'+Edit5.Text+'%');
Dm.ADOQDataBarang.Filtered := True;
end
else
if (ComboBox1.Text <> '') and (Edit5.Text = '') then
begin
DM.ADOQDataBarang.Filtered := False;
end;
end;
procedure TForm4.Panel8Click(Sender: TObject);
begin
FKategori.Show;
end;
procedure TForm4.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
cekkey;
end;
procedure TForm4.cekkey;
begin
if not(key in['0'..'9', #8, #13, #32]) then
begin
key :=#0;
MessageDlg('Nilai yang diinput harus angka !!!',mtError,[mbOK],0);
end
end;
procedure TForm4.Edit7KeyPress(Sender: TObject; var Key: Char);
begin
cekkey;
end;
procedure TForm4.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
cekkey;
end;
end.