-
Notifications
You must be signed in to change notification settings - Fork 0
/
CUImpuestos.cs
166 lines (143 loc) · 5.63 KB
/
CUImpuestos.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace metaGamesInventory
{
public partial class CUImpuestos : Form
{
public CUImpuestos()
{
InitializeComponent();
}
bool closable = false;
home home = new home();
tax impuestos;
public CUImpuestos(tax obj)
{
InitializeComponent();
impuestos = obj;
assigningData();
}
private void assigningData()
{
txtnimpu.Text = impuestos.name;
numimp.Value = Int32.Parse(impuestos.percentage.ToString());
}
private void CreacionImpuesto()
{
tax obj = new tax();
obj.name = txtnimpu.Text;
obj.percentage = Int32.Parse(numimp.Value.ToString());
//Int32.Parse(txtporcen.ToString());
using (metaGamesInventoryAlterEntities BD = new metaGamesInventoryAlterEntities())
{
BD.tax.Add(obj);//Añadimos el objeto previamente establecido al contexto creado
BD.SaveChanges();//Persistimos los datos del contexto, dentro de la base de datos
MessageBox.Show("Impuesto registrado exitosamente.", "Operación exitosa", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
closable = true;
this.Close();
RDImpuestos form = new RDImpuestos();
form.MdiParent = metaGamesInventory.home.ActiveForm;
form.Text = "Impuesto registrados";
form.Show();
}
}
private void btnimpuesto_Click(object sender, EventArgs e)
{
//CreacionImpuesto();
if (Controlvali())
//Si el formulario entero cumple las validaciones
{
if (impuestos == null)
/*Si el objeto productToUpdate no cambia su estado inicial (null),
significa que no proviene del formulario RDProduct, por ende,
se ejecutara una inserción a la tabla Product*/
{
CreacionImpuesto();
}
else
{
updateProduct();
}
}
}
private void updateProduct()
{
impuestos.name = txtnimpu.Text;
impuestos.percentage = Int32.Parse(numimp.Value.ToString());
using (metaGamesInventoryAlterEntities BD = new metaGamesInventoryAlterEntities())
{
BD.Entry(impuestos).State = System.Data.Entity.EntityState.Modified;
BD.SaveChanges();//Persistimos los datos actualizados dentro de la base de datos
MessageBox.Show("Producto modificado exitosamente.", "Operación exitosa", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
closable = true;
this.Close();
RDImpuestos form = new RDImpuestos();
form.MdiParent = metaGamesInventory.home.ActiveForm;
form.Text = "Impuesto Registrado";
form.Show();
}
}
private bool Controlvali()
{
if (string.IsNullOrWhiteSpace(txtnimpu.Text))//Si no se ha ingresado información al campo indicado...
{
txtnimpu.Focus();//Enfocamos el campo
//Añadimos un mensaje descriptivo del error de validación
errorProvider1.SetError(txtnimpu, "Por favor, ingresa el nombre del producto");
return false;
}
else
{
errorProvider1.SetError(txtnimpu, null);
//Eliminamos cualquier mensaje de validación referido al campo en cuestión
}
return true;
}
private void CUImpuestos_FormClosing(object sender, FormClosingEventArgs e)
{
if (closable == false)
{
var ans = MessageBox.Show("Todos los cambios quedarán anulados si decides abandonar el formulario", "¿Seguro de salir del formulario?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (ans == DialogResult.Yes)
{
if (impuestos != null)
{
RDImpuestos form = new RDImpuestos();
form.MdiParent = metaGamesInventory.home.ActiveForm;
form.Text = "impuestos regitrados";
form.Show();
}
}
else
{
e.Cancel = true;
}
}
}
private void txtnimpu_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsLetter(e.KeyChar)) && (e.KeyChar != (char)Keys.Back) && (e.KeyChar != (char)Keys.Space))
{
MessageBox.Show("Solo se permiten letras", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
e.Handled = true;
return;
}
}
private void numimp_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
{
MessageBox.Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
e.Handled = true;
return;
}
}
}
}