-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCadValorKwh.pas
153 lines (132 loc) · 4.65 KB
/
CadValorKwh.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
unit CadValorKwh;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Connection, Data.DB, Vcl.ExtCtrls,
Vcl.DBCtrls, Vcl.Grids, Vcl.DBGrids, Vcl.StdCtrls, Vcl.Mask, Vcl.Buttons;
type
TValorKWH = class(TForm)
Label1: TLabel;
Label3: TLabel;
DBGridValorKWH: TDBGrid;
Memo1: TMemo;
SpeedButton1: TSpeedButton;
EditCidade: TEdit;
EditVKwh: TEdit;
EditOBS: TEdit;
Label2: TLabel;
CBVP: TCheckBox;
btnSalvar: TBitBtn;
DBNavigator1: TDBNavigator;
DataSource1: TDataSource;
btnNew: TBitBtn;
DBNavigator2: TDBNavigator;
BtnEditar: TBitBtn;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure btnSalvarClick(Sender: TObject);
procedure CBVPClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
procedure btnNewClick(Sender: TObject);
procedure BtnEditarClick(Sender: TObject);
procedure EditVKwhKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
ValorKWH: TValorKWH;
implementation
{$R *.dfm}
procedure TValorKWH.btnSalvarClick(Sender: TObject);
begin
if EditCidade.Text <> DT_connection.qryvalorKWHcity.FieldByName('Cidade').AsString then
Begin
DT_connection.qryvalorKWHcity.Close;
DT_connection.qryvalorKWHcity.SQL.Clear;
DT_connection.qryvalorKWHcity.SQL.Add('Insert into valorKWHcity (Cidade ,ValorKWH ,Obs )'
+'Values('+QuotedStr(EditCidade.Text)+','+ QuotedStr(EditVKwh.Text)+','+ QuotedStr(EditOBS.Text)+')');
DT_connection.qryvalorKWHcity.ExecSQL;
DT_connection.qryvalorKWHcity.Close;
DT_connection.qryvalorKWHcity.SQL.Clear;
DT_connection.qryvalorKWHcity.SQL.Add('Select * from valorKWHcity');
DT_connection.qryvalorKWHcity.Open;
btnSalvar.Visible := false;
end else
begin
DT_connection.qryvalorKWHcity.Close;
DT_connection.qryvalorKWHcity.SQL.Clear;
DT_connection.qryvalorKWHcity.SQL.Add('update valorKWHcity set ValorKWH=' + QuotedStr(EditVKwh.Text)+','+'Obs='+QuotedStr(EditOBS.Text)+'Where Cidade='+QuotedStr(EditCidade.Text));
DT_connection.qryvalorKWHcity.ExecSQL;
DT_connection.qryvalorKWHcity.Close;
DT_connection.qryvalorKWHcity.SQL.Clear;
DT_connection.qryvalorKWHcity.SQL.Add('Select * from valorKWHcity');
DT_connection.qryvalorKWHcity.Open;
btnSalvar.Visible := false;
end;
end;
procedure TValorKWH.BtnEditarClick(Sender: TObject);
begin
btnSalvar.Visible := true;
end;
procedure TValorKWH.btnNewClick(Sender: TObject);
begin
EditCidade.Text := '';
EditVKwh.Text := '';
EditOBS.Text := '';
btnSalvar.Visible := true;
end;
procedure TValorKWH.CBVPClick(Sender: TObject);
var
temp: string;
begin
temp := EditVKwh.Text;
if CBVP.Checked then
begin
DT_connection.qryvalorKWHcity.Close;
DT_connection.qryvalorKWHcity.SQL.Clear;
DT_connection.qryvalorKWHcity.SQL.Add('update BaseCalcReal_temp set Valor='
+ QuotedStr(temp) + '');
DT_connection.qryvalorKWHcity.ExecSQL;
DT_connection.qryvalorKWHcity.Close;
DT_connection.qryvalorKWHcity.SQL.Clear;
DT_connection.qryvalorKWHcity.SQL.Add('select * from valorKWHcity ');
DT_connection.qryvalorKWHcity.Open;
ShowMessage('O Valor de:'+temp+' KWh foi definido como base de calculo!');
end;
end;
procedure TValorKWH.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
begin
EditCidade.Text := DT_connection.qryvalorKWHcity.FieldByName('Cidade').AsString;
EditVKwh.Text := DT_connection.qryvalorKWHcity.FieldByName('ValorKWH').AsString;
EditOBS.Text := DT_connection.qryvalorKWHcity.FieldByName('Obs').AsString;
btnSalvar.Visible := false;
end;
procedure TValorKWH.EditVKwhKeyPress(Sender: TObject; var Key: Char);
begin
If not( key in['0'..'9','.',#08] ) then
key:=#0;
end;
procedure TValorKWH.FormActivate(Sender: TObject);
begin
EditCidade.Text := DT_connection.qryvalorKWHcity.FieldByName('Cidade').AsString;
EditVKwh.Text := DT_connection.qryvalorKWHcity.FieldByName('ValorKWH').AsString;
EditOBS.Text := DT_connection.qryvalorKWHcity.FieldByName('Obs').AsString;
btnSalvar.Visible := false;
end;
procedure TValorKWH.FormClose(Sender: TObject; var Action: TCloseAction);
begin
// Fecha a conexão ao fechar o form
DT_connection.FDcon.Connected := false;
DT_connection.qryvalorKWHcity.active := false;
end;
procedure TValorKWH.FormCreate(Sender: TObject);
begin
DT_connection.FDcon.Connected := true;
DT_connection.qryvalorKWHcity.active := true;
ValorKWH.Free;
end;
end.