Código de Visual Basic.NET - Ejemplo en WPF de un banco registrando un usuario

sin imagen de perfil
Val: 8
Ha aumentado su posición en 19 puestos en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Ejemplo en WPF de un banco registrando un usuariográfica de visualizaciones


Visual Basic.NET

Actualizado el 27 de Junio del 2018 por Bastian (4 códigos) (Publicado el 25 de Mayo del 2018)
3.429 visualizaciones desde el 25 de Mayo del 2018
Este código de ejemplo de WPF de un banco registrando un usuario que al ser ingresado dependiendo de su tipo de cuenta su saldo sufrirá un cambio el cual sera impreso en la sección de abajo del WPF.
Esta dividido en clases las cual separe en "////////////////" y el ultimo código es la función del botón "agregar" del WPF.

1.0
estrellaestrellaestrellaestrellaestrella(3)

Actualizado el 1 de Julio del 2018 (Publicado el 25 de Mayo del 2018)gráfica de visualizaciones de la versión: 1.0
3.430 visualizaciones desde el 25 de Mayo del 2018
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

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
public class Cliente
    {
        #region Campos
        private String _nombre;
        private DateTime _fechaNacimiento;
        private int _edad;
        //private DateTime _fechaMin = new DateTime(1900, 01, 01);
        #endregion
 
        #region Propiedades
        // No seteamos _edad en Edad  ya que depende de la fecha de nacimiento (nosotros debemos setearla por programa )     
        public int Edad
        {
            get { return _edad; }
 
            /*set
            {
                if ((DateTime.Now.Year - FechaNacimiento.Year) < 18 )
                {
                    throw new ArgumentOutOfRangeException("Edad", "La edad debe ser mayor o igual a 18");
                }
                else
                {
                    _edad = (DateTime.Now.Year - FechaNacimiento.Year);
                }
            }*/
 
        }
        public DateTime FechaNacimiento
        {
            get
            {
                return _fechaNacimiento;
            }
            set
            {
                if (value < new DateTime(1900, 01, 01) || value > DateTime.Today)
                {
                    throw new ArgumentOutOfRangeException("Fecha Nacimiento", "La fecha debe ser posterior al 01-01-1900");
                }
                else
                {
                    _fechaNacimiento = value;
 
                    if (DateTime.Now.Year - FechaNacimiento.Year >= 18)
                    {
                        _edad = (DateTime.Now.Year - FechaNacimiento.Year);
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("Edad", "no cumple con la edad mínima");
                    }
                }
            }
        }
 
 
        public String Nombre
        {
            get { return _nombre; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    _nombre = value;
                }
                else
                {
                    throw new ArgumentNullException(" El Nombre no puede estar vacio");
                }
 
            }
        }
 
        public Sexo Sexo
        {
            get;
            set;
        }
        #endregion
 
        #region Constructor
 
        public Cliente()
        {
            _nombre = string.Empty;
            _edad = 18;
            FechaNacimiento = new DateTime(1990,01,01);
            Sexo = Sexo.NoIngresado;
        }
 
        #endregion
    }
}
 
//////////////////////77
  public class Cuenta
    {
        #region Campos
        private static int _contadorAhorro=0, _contadorCorriente=0, _contadorVista=0;
 
        private DateTime _apertura = new DateTime(1980,01,01);
        //private DateTime _fechaMin = new DateTime(01 - 01 - 1980);
        private String _identidficador;
        private int _saldoInicial;
        private double _costoMantencion;
        #endregion
 
        #region Propiedades
 
        public DateTime Apertura
        {
            get { return _apertura;}
            set { _apertura = value; }
 
        }
 
        public String Identificador
        {
            get;
 
        }
 
        public int SaldoInicial
        {
            get { return _saldoInicial; }
            set { if (value <= 0)
                {
                throw new ArgumentOutOfRangeException("Saldo Inicial", "Debe ser mayor a 0");
            }
                else
                {
                _saldoInicial = value;
            }
        }
 
    }
 
        public int CostoMantencion
        {
            get;
            set;
        }
 
        public TipoCuenta TipoCuentas
        {
            get;
            set;
        }
        public Cliente Clientito
        {
            get;
            set;
        }
 
        #endregion
 
        #region Constructor
 
        public Cuenta()
        {
            TipoCuentas = TipoCuenta.NoIngresado;
            Apertura = _apertura;
            Identificador = string.Empty;
            SaldoInicial = 1;
            CostoMantencion = 0;
            Clientito = new Cliente();
 
        }
        #endregion
 
        #region Metodos
        public int CalcularCostoMantencion()
        {
            _costoMantencion = 0.01;
            int valor = 0;
 
            switch (TipoCuentas)
            {
                case TipoCuenta.CuentaCorriente:
                    _costoMantencion += 0.03;
                    break;
 
                case TipoCuenta.CuentaVista:
                    _costoMantencion += 0.02;
                    break;
 
                case TipoCuenta.CuentaAhorro:
                    _costoMantencion += 0.01;
                    break;
            }
 
            if (Clientito.Edad >= 18 & Clientito.Edad <= 35)
            {
                _costoMantencion += 0.03;
            }
            else if (Clientito.Edad > 35 & Clientito.Edad < 45)
            {
                _costoMantencion += 0.02;
            }
            else if (Clientito.Edad > 45)
            {
                _costoMantencion += 0.01;
            }
 
            valor = (int)(23000 * _costoMantencion);
 
            return valor;
        }
 
        public StringBuilder imprimir()
        {
            StringBuilder salida = new StringBuilder();
 
            salida.AppendFormat("*********Información Cliente*********").AppendLine()
            .AppendFormat("Nombre: {0}", Clientito.Nombre).AppendLine()
            .AppendFormat("Fecha Nacimiento: {0}", Clientito.FechaNacimiento.ToShortDateString()).AppendLine()
            .AppendFormat("Edad: {0}", Clientito.Edad).AppendLine()
            .AppendFormat("Genero: {0}", Clientito.Sexo).AppendLine()
            .AppendFormat("***************CUENTA**************").AppendLine()
            .AppendFormat("Identificador Cuenta: {0}",calcularIdentificador()).AppendLine()
            .AppendFormat("Tipo Cuenta: {0}", TipoCuentas).AppendLine()
            .AppendFormat("Fecha Apertura: {0}", Apertura.ToShortDateString()).AppendLine()
            .AppendFormat("Saldo Inicial: {0}", SaldoInicial.ToString("C0")).AppendLine()
            .AppendFormat("Costo Mantención: {0}", CalcularCostoMantencion().ToString("C0"));
 
            return salida;
        }
 
 
        public string calcularIdentificador()
        {
            if (TipoCuentas == TipoCuenta.CuentaAhorro)
            {
                _contadorAhorro++;
                _identidficador = "CTA-AHO-" +_contadorAhorro.ToString();
            }
            else if(TipoCuentas==TipoCuenta.CuentaCorriente)
            {
                _contadorCorriente++;
                _identidficador = "CTA-CTE-" +_contadorCorriente.ToString() ;
            }
            else if (TipoCuentas==TipoCuenta.CuentaVista)
            {
                _contadorVista++;
               _identidficador = "CTA-VIS-" + _contadorVista.ToString() ;
            }
            return _identidficador;
        }
 
        #endregion
 
 
    }
}
///////////////////////////////////////////////77
    public enum TipoCuenta
 
    {
        NoIngresado,
        CuentaAhorro ,
        CuentaVista,
        CuentaCorriente
    };
 
    public enum Sexo
    {
        NoIngresado,
        Masculino,
        Femenino
    };
 
////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Bancaria;
 
namespace Ventana
{
    /// <summary>
    /// Lógica de interacción para MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
 
    {
        public Cuenta[] cuentas = new Cuenta[0];
 
        public MainWindow()
        {
            InitializeComponent();
 
            // Asignar los valores del Enum al comboBox
            cmbTipoCuenta.ItemsSource = Enum.GetValues(typeof(TipoCuenta));
            // Inicializar el valor por default
            cmbTipoCuenta.SelectedIndex = 0;
            datosDePueba();
 
        }
 
        #region BotonAgregar
        private void button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Cuenta cta = new Cuenta();
                cta.Clientito.Nombre = txtNombre.Text.Trim();
                cta.Clientito.FechaNacimiento = dpFechaNacimiento.SelectedDate.Value;
                // Para el  genero !
                #region IngresarGenero
                if (!(bool)rbtnFemenino.IsChecked && !(bool)rbtnMasculino.IsChecked)
                {
 
                    cta.Clientito.Sexo = Sexo.NoIngresado;
                }
 
                else
                {
                    cta.Clientito.Sexo = (bool)rbtnFemenino.IsChecked ? Sexo.Femenino : Sexo.Masculino;
                }
                #endregion
                cta.SaldoInicial = int.Parse(txtSaldoInicial.Text.Trim());
                cta.TipoCuentas = (TipoCuenta)cmbTipoCuenta.SelectedValue;
                cta.Apertura = dpFechaApertura.SelectedDate.Value;
 
 
                Array.Resize(ref cuentas, cuentas.Length + 1);
 
                cuentas[cuentas.Length - 1] = cta;
 
                txtSalida.Items.Add(cta.imprimir().ToString());
 
                limpiar();
 
                MessageBox.Show(string.Format("Se ha guardado el Visitante {0}", cta.Clientito.Nombre));
            }
            catch (ArgumentOutOfRangeException ex)
            {
 
                MessageBox.Show(ex.Message);
            }
            catch(ArgumentNullException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
 
 
        }
 
        #endregion
 
        private void datosDePueba()
        {
            txtNombre.Text = "Juan";
            dpFechaNacimiento.SelectedDate = DateTime.Today;
            rbtnFemenino.IsChecked = false;
            rbtnMasculino.IsChecked = true;
            txtSaldoInicial.Text = "1000";
            cmbTipoCuenta.SelectedIndex = 2;
            dpFechaApertura.SelectedDate = DateTime.Today;
        }
 
        private void limpiar()
        {
            txtNombre.Clear();
            dpFechaNacimiento.SelectedDate = DateTime.Today;
            rbtnFemenino.IsChecked = false;
            rbtnMasculino.IsChecked = false;
            txtSaldoInicial.Clear();
            cmbTipoCuenta.SelectedIndex = 0;
            dpFechaApertura.SelectedDate = DateTime.Today;
 
        }
 
    }
}



Comentarios sobre la versión: 1.0 (3)

Imágen de perfil
28 de Junio del 2018
estrellaestrellaestrellaestrellaestrella
Esto no es VB.Net
Responder
Javi
2 de Julio del 2018
estrellaestrellaestrellaestrellaestrella
gilman tiene razón
No es vb
Responder
2 de Julio del 2018
estrellaestrellaestrellaestrellaestrella
y vb net, donde esta? me quede con las ganas de verlo, no hay que confundir el cebo con la manteca

vb net una cosa y c# es otra
Responder

Comentar la versión: 1.0

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s4615