-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdialogoproducto.cpp
158 lines (143 loc) · 5.76 KB
/
dialogoproducto.cpp
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
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "dialogoproducto.h"
#include "basedatos.h"
#include "itemsproductos.h"
#include "auxiliar.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormDialogoProducto *FormDialogoProducto;
static AnsiString Dialogos[DLG_PTO_N] = {"Agregar producto", "Editar producto"};
//---------------------------------------------------------------------------
__fastcall TFormDialogoProducto::TFormDialogoProducto(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
TModalResult TFormDialogoProducto::Mostrar(int tipo)
{
Caption = Dialogos[tipo];
return ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoProducto::BitBtnAceptarClick(TObject *Sender)
{
/* Se verifica que estén los datos obligatorios */
DBEditCodigo->Text = DBEditCodigo->Text.Trim();
if (DBEditCodigo->Text.IsEmpty())
{
MessageBox(Handle, "Debe especificar un código para el "
"producto.", Application->Title.c_str(),
MB_APPLMODAL | MB_OK | MB_ICONINFORMATION);
return;
}
if (DBEditDescripcion->Text.IsEmpty())
{
MessageBox(Handle, "Debe especificar una descripción para el "
"producto.", Application->Title.c_str(),
MB_APPLMODAL | MB_OK | MB_ICONINFORMATION);
return;
}
if (DBEditPrecio1->Text.IsEmpty() ||
DBEditPrecio2->Text.IsEmpty() ||
DBEditPrecio3->Text.IsEmpty())
{
MessageBox(Handle, "Debe especificar todos los precios para "
"el producto.",
Application->Title.c_str(), MB_APPLMODAL |
MB_OK | MB_ICONINFORMATION);
return;
}
if (DBEditGramos->Text.IsEmpty())
{
MessageBox(Handle, "Debe especificar los gramos para el "
"producto.", Application->Title.c_str(),
MB_APPLMODAL | MB_OK | MB_ICONINFORMATION);
return;
}
/* Se verifican que los datos sean correctos */
TDBEdit *dbedit;
for (int i = 1; i <= 3; i++)
{
dbedit = static_cast<TDBEdit *>(FindComponent("DBEditPrecio" +
IntToStr(i)));
try
{
double precio = MonedaANumero(dbedit->Text).ToDouble();
if (precio < 0) throw Exception("");
}
catch (...)
{
MessageBox(Handle, ("El valor ingresado para Precio " +
IntToStr(i) + " no es válido.").c_str(),
Application->Title.c_str(),
MB_APPLMODAL | MB_OK | MB_ICONWARNING);
return;
}
}
try
{
int gramos = DBEditGramos->Text.ToInt();
if (gramos < 0) throw Exception("");
}
catch (...)
{
MessageBox(Handle,
"El valor ingresado para Gramos no es válido.",
Application->Title.c_str(),
MB_APPLMODAL | MB_OK | MB_ICONWARNING);
Abort();
}
/* Si es un nuevo producto o se está editando uno, entonces se envían
los datos */
if (BD->TableProductos->State == dsInsert ||
BD->TableProductos->State == dsEdit)
{
BD->TableProductos->Post();
}
ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoProducto::BitBtnCancelarClick(TObject *Sender)
{
ModalResult = mrCancel;
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoProducto::FormClose(TObject *Sender,
TCloseAction &Action)
{
/* Se cancelan las modificaciones del registro actual no enviadas */
BD->TableProductos->Cancel();
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoProducto::FormShow(TObject *Sender)
{
DBEditCodigo->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoProducto::BitBtnFamiliasClick(
TObject *Sender)
{
TBitBtn *boton = static_cast< TBitBtn * >(Sender);
FormItemsProductos->Mostrar(boton->Tag);
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoProducto::DBEditPrecio1KeyPress(
TObject *Sender, char &Key)
{
TEdit *Precio = static_cast<TEdit *>(Sender);
if (Key == '+' || Key == '-')
Abort();
if (Key == '.')
if (Precio->Text.AnsiPos(".") &&
! Precio->SelText.AnsiPos(".")) Abort();
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoProducto::DBEditCodigoKeyPress(TObject *Sender,
char &Key)
{
if (! (isalnum(Key) || Key == VK_BACK)) Abort();
}
//---------------------------------------------------------------------------