-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStockManager_u.pas
205 lines (185 loc) · 5.79 KB
/
StockManager_u.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
unit StockManager_u;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, DM_u, Data.DB, Vcl.Grids, Vcl.DBGrids,
Data.Win.ADODB, Vcl.StdCtrls, Vcl.Buttons, clsStockManagement_u, Vcl.ToolWin,
Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.Samples.Spin, clsExport;
type
TfrmStockManager = class(TForm)
dsStock: TDataSource;
dbgrdStockView: TDBGrid;
btnAddStock: TBitBtn;
btnCorrectStock: TBitBtn;
btnViewAvailableStock: TBitBtn;
qryStockFilter: TADOQuery;
seFilterByAmount: TSpinEdit;
lblFilter: TLabel;
lblShowProducts: TLabel;
btnResetFilter: TBitBtn;
btnFilter: TBitBtn;
btnExportStock: TBitBtn;
btnGenerateReport: TBitBtn;
lblFilterActive: TLabel;
procedure btnViewAvailableStockClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btnFilterClick(Sender: TObject);
procedure btnCorrectStockClick(Sender: TObject);
procedure btnResetFilterClick(Sender: TObject);
procedure btnAddStockClick(Sender: TObject);
procedure btnExportStockClick(Sender: TObject);
procedure btnGenerateReportClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
objStock: TStockManagment;
{ Private declarations }
public
{ Public declarations }
end;
var
frmStockManager: TfrmStockManager;
implementation
uses
Admin_u;
{$R *.dfm}
procedure TfrmStockManager.btnAddStockClick(Sender: TObject);
var
sBarcode: string;
iAdd: Integer;
begin
sBarcode := InputBox('Product Barcode', 'Scan Product Barcode', '');
if (sBarcode = '') or (Length(sBarcode) < 13) or (Length(sBarcode) > 17) then
begin
MessageDlg('Barcode Invalid. Please try again', mtError, [mbOK], 0);
Exit;
end;
try
iAdd := StrToInt(InputBox('Add Stock',
'How much stock must be added', '0'));
except
MessageDlg('The Value Entred can not be used. Please try again', mtError,
[mbOK], 0);
end;
objStock := TStockManagment.Create;
objStock.AddStock(sBarcode, iAdd);
MessageDlg('Stock Added Succsessfully', mtInformation, [mbOK], 0);
dsStock.Enabled := False;
qryStockFilter.Active := False;
qryStockFilter.Active := True;
dsStock.Enabled := True;
dbgrdStockView.Columns[0].Width := 230;
dbgrdStockView.Columns[1].Width := 300;
dbgrdStockView.Columns[2].Width := 275;
end;
procedure TfrmStockManager.btnCorrectStockClick(Sender: TObject);
var
sBarcode: string;
iRemove: Integer;
begin
sBarcode := InputBox('Product Barcode', 'Scan Product Barcode', '');
if (sBarcode = '') or (Length(sBarcode) < 13) or (Length(sBarcode) > 17) then
begin
MessageDlg('Barcode Invalid. Please try again', mtError, [mbOK], 0);
Exit;
end;
try
iRemove := StrToInt(InputBox('Stock Correction',
'Enter amount to correct stock by', '0'));
except
MessageDlg('The Value Entred can not be used. Please try again', mtError,
[mbOK], 0);
end;
objStock := TStockManagment.Create;
objStock.RemoveStock(sBarcode, iRemove);
MessageDlg('Stock correction done', mtInformation, [mbOK], 0);
dsStock.Enabled := False;
qryStockFilter.Active := False;
qryStockFilter.Active := True;
dsStock.Enabled := True;
dbgrdStockView.Columns[0].Width := 230;
dbgrdStockView.Columns[1].Width := 300;
dbgrdStockView.Columns[2].Width := 275;
end;
procedure TfrmStockManager.btnExportStockClick(Sender: TObject);
var
objExport: TExport;
begin
objExport := TExport.Create(dbgrdStockView, 'FiltredStockExport');
objExport.ExportToCSV;
objExport.Free;
end;
procedure TfrmStockManager.btnFilterClick(Sender: TObject);
var
iUnder: Integer;
begin
lblFilterActive.Caption := 'Filter Currently Active';
iUnder := StrToInt(seFilterByAmount.Text);
with qryStockFilter do
begin
SQL.Text :=
'SELECT Barcode,ProductName,ProductAmountAvailable FROM Stock WHERE ProductAmountAvailable <= :FilterAmount';
Parameters.ParamByName('FilterAmount').Value := iUnder;
ExecSQL;
Open;
end;
dsStock.Enabled := False;
qryStockFilter.Active := False;
qryStockFilter.Active := True;
dsStock.Enabled := True;
dbgrdStockView.Columns[0].Width := 230;
dbgrdStockView.Columns[1].Width := 300;
dbgrdStockView.Columns[2].Width := 275;
end;
procedure TfrmStockManager.btnGenerateReportClick(Sender: TObject);
var
objExport: TExport;
begin
objExport := TExport.Create(dbgrdStockView, 'Stock');
objExport.ExportToHTML('Stock');
objExport.Free;
MessageDlg('Report Generated', mtInformation, [mbOK], 0);
end;
procedure TfrmStockManager.btnResetFilterClick(Sender: TObject);
begin
lblFilterActive.Caption := 'No Filter Active';
with qryStockFilter do
begin
SQL.Text :=
'SELECT Barcode,ProductName,ProductAmountAvailable FROM Stock';
ExecSQL;
Open;
end;
dsStock.Enabled := False;
qryStockFilter.Active := False;
qryStockFilter.Active := True;
dsStock.Enabled := True;
dbgrdStockView.Columns[0].Width := 230;
dbgrdStockView.Columns[1].Width := 300;
dbgrdStockView.Columns[2].Width := 275;
end;
procedure TfrmStockManager.btnViewAvailableStockClick(Sender: TObject);
var
sBarcode: string;
begin
sBarcode := InputBox('Barcode', 'Scan Product Barcode Now', '');
objStock := TStockManagment.Create;
ShowMessage(FloatToStrF(objStock.GetStockAvalible(sBarcode), ffGeneral, 10, 2)
+ ' Is available for ' + objStock.GetProductName(sBarcode));
objStock.Free;
end;
procedure TfrmStockManager.FormClose(Sender: TObject; var Action: TCloseAction);
begin
frmAdmin.Show;
end;
procedure TfrmStockManager.FormCreate(Sender: TObject);
begin
SetWindowLong(Handle, GWL_EXSTYLE, WS_EX_APPWINDOW);
//qryStockFilter.Active:= True;
end;
procedure TfrmStockManager.FormShow(Sender: TObject);
begin
qryStockFilter.Active:= True;
end;
end.