-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdialogocliente.cpp
163 lines (145 loc) · 5.9 KB
/
dialogocliente.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
159
160
161
162
163
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "dialogocliente.h"
#include "basedatos.h"
#include "itemsclientes.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormDialogoCliente *FormDialogoCliente;
static AnsiString Dialogos[DLG_CTE_N] = {"Agregar cliente", "Editar cliente"};
//---------------------------------------------------------------------------
__fastcall TFormDialogoCliente::TFormDialogoCliente(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
TModalResult TFormDialogoCliente::Mostrar(int tipo)
{
Caption = Dialogos[tipo];
return ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoCliente::BitBtnAceptarClick(TObject *Sender)
{
/* Se verifica que estén los datos obligatorios */
if (DBEditNombreCliente->Text.IsEmpty())
{
MessageBox(Handle, "Debe especificar un nombre para el "
"cliente.", Application->Title.c_str(),
MB_APPLMODAL | MB_OK | MB_ICONINFORMATION);
return;
}
if (DBComboBoxNombreFactura->Text.IsEmpty())
{
MessageBox(Handle, "Debe especificar un nombre para "
"hacer la facturación.", Application->Title.c_str(),
MB_APPLMODAL | MB_OK | MB_ICONINFORMATION);
return;
}
if (DBComboBoxPosicionIVA->Text.IsEmpty())
{
MessageBox(Handle, "Debe especificar una posición ante el IVA.",
Application->Title.c_str(), MB_APPLMODAL |
MB_OK | MB_ICONINFORMATION);
return;
}
if (DBEditDescuento->Text.IsEmpty())
{
MessageBox(Handle, "Debe especificar un descuento para el "
"cliente.",
Application->Title.c_str(), MB_APPLMODAL |
MB_OK | MB_ICONINFORMATION);
return;
}
/* Se verifican que los datos sean correctos */
try
{
double descuento = DBEditDescuento->Text.ToDouble();
if (descuento < 0 || descuento > 100) throw EConvertError("");
}
catch (EConvertError &converterror)
{
MessageBox(Handle,
"El valor ingresado para Descuento no es válido.",
Application->Title.c_str(),
MB_APPLMODAL | MB_OK | MB_ICONWARNING);
return;
}
/* Si es un nuevo cliente o se está editando uno, entonces se envían
los datos */
/* El post lo hacemos acá porque cuando se cierra el dialogo se
sale del modo insert */
if (BD->TableClientes->State == dsInsert ||
BD->TableClientes->State == dsEdit)
{
BD->TableClientes->Post();
}
ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoCliente::BitBtnCancelarClick(TObject *Sender)
{
ModalResult = mrCancel;
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoCliente::FormClose(TObject *Sender,
TCloseAction &Action)
{
/* Se cancelan las modificaciones del registro actual no enviadas */
BD->TableClientes->Cancel();
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoCliente::FormShow(TObject *Sender)
{
ActualizarNombresFactura();
PageControl->ActivePageIndex = 0;
DBEditNombreCliente->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoCliente::BitBtnLocalidadesClick(
TObject *Sender)
{
TBitBtn *boton = static_cast< TBitBtn * >(Sender);
FormItemsClientes->Mostrar(boton->Tag);
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoCliente::DBEditDescuentoKeyPress(
TObject *Sender, char &Key)
{
if (Key == '+' || Key == '-')
Abort();
if (Key == '.')
if (DBEditDescuento->Text.AnsiPos(".") &&
! DBEditDescuento->SelText.AnsiPos(".")) Abort();
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoCliente::DBEditNombreNegocioExit(
TObject *Sender)
{
ActualizarNombresFactura();
}
//---------------------------------------------------------------------------
void __fastcall TFormDialogoCliente::DBEditNombreClienteExit(
TObject *Sender)
{
ActualizarNombresFactura();
}
//---------------------------------------------------------------------------
void TFormDialogoCliente::ActualizarNombresFactura()
{
AnsiString nombrefactura = BD->TableClientes->FieldByName("NombreFactura")->AsString;
DBComboBoxNombreFactura->Items->Clear();
DBComboBoxNombreFactura->Items->Add(DBEditNombreCliente->Text);
DBComboBoxNombreFactura->Items->Add(DBEditNombreNegocio->Text);
if (DBComboBoxNombreFactura->Items->Strings[0] == nombrefactura)
{
DBComboBoxNombreFactura->ItemIndex = 0;
}
else if (DBComboBoxNombreFactura->Items->Strings[1] == nombrefactura)
{
DBComboBoxNombreFactura->ItemIndex = 1;
}
}
//---------------------------------------------------------------------------