-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddProduct.cs
More file actions
234 lines (205 loc) · 8.62 KB
/
addProduct.cs
File metadata and controls
234 lines (205 loc) · 8.62 KB
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
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;
using MundoMusical.CODE_BAR;
using MundoMusical.DB;
using MundoMusical.CUSTOM_CONTROLS;
using System.Globalization;
using MundoMusical.LABELS;
namespace MundoMusical.PRODUCT
{
public partial class addProduct : XBASE.productBase
{
protected dbop db;
protected cb cbar;
protected producto prod;
protected List<Control> controls;
protected List<TextBox> tboxes;
private printCbar cbprint;
public addProduct()
{
InitializeComponent();
this.Text = "Agregar Producto";
this.cbar = new cb();
this.db = new dbop();
this.setAtribs();
}
public addProduct(midformProduct origen)
{
InitializeComponent();
this.Text = "Agregar Producto";
this.origen = origen;
this.origen.addbtn.Enabled = false;
this.FormClosed += (x, y) => { this.origen.addbtn.Enabled = true; };
this.cbar = new cb();
this.db = new dbop();
this.setAtribs();
this.stopBounds();
}
protected virtual void setAtribs()
{
this.controls = new List<Control>() { this.txt1, this.txt3, this.cb1, this.txtcosto, this.cbganancia, this.txt2, this.txt4 };
this.tboxes = new List<TextBox>() { this.txt1, this.txt2, this.txt3, this.txt4, this.txtcosto};
behaviorDefinitions.txtOnlyNumbers(ref this.txt3);
behaviorDefinitions.txtOnlyNumbers(ref this.txt4);
behaviorDefinitions.txtPrice(this.txtcosto);
behaviorDefinitions.txtPrice(this.txt2);
controls.ElementAt(0).KeyPress += (x, y) => { if (y.KeyChar == (char)Keys.Enter) controls.ElementAt(1).Focus(); };
controls.ElementAt(1).KeyPress += (x, y) => { if (y.KeyChar == (char)Keys.Enter) controls.ElementAt(2).Focus(); };
controls.ElementAt(2).KeyPress += (x, y) => { if (y.KeyChar == (char)Keys.Enter) controls.ElementAt(3).Focus(); };
controls.ElementAt(3).KeyPress += (x, y) => { if(y.KeyChar == (char)Keys.Enter)controls.ElementAt(4).Focus(); };
controls.ElementAt(4).KeyPress += (x, y) => { if (y.KeyChar == (char)Keys.Enter) controls.ElementAt(5).Focus(); };
controls.ElementAt(5).KeyPress += (x, y) => { if (y.KeyChar == (char)Keys.Enter) controls.ElementAt(6).Focus(); };
this.txt4.KeyUp += (x, y) => { if (this.txt4.Text.Trim() != "") this.picbox.Image = this.cbar.getImage(this.txt4.Text.Trim()); };
this.txt4.KeyPress += (x, y) => { if (y.KeyChar == (char)Keys.Enter && (this.txt4.Text.Trim() != "")) this.onAccept(); };
this.txt4.KeyUp += (x, y) => { if(this.txt4.Text.Trim() == "") this.generateCBAR(); };
this.baccept.Click += (x, y) =>
{
this.onAccept();
};
this.bcancel.Click += (x, y) =>
{
this.onCancel();
};
this.prod = new producto();
for(int x=0; x<101; ++x)
{
this.cbganancia.Items.Add(x.ToString() + "%");
}
this.cbganancia.SelectedIndex = 0;
this.cbganancia.SelectedIndexChanged += (sender, args) => {
if(this.txtcosto.Text.Trim() != string.Empty)
{
Double val = Double.Parse(this.txtcosto.Text, CultureInfo.InvariantCulture);
this.txt2.Text = (val + ((val / 100) * this.cbganancia.SelectedIndex)).ToString("F2");
}
};
this.cbprint = new printCbar();
}
protected virtual void onAccept()
{
this.insertProduct();
}
protected virtual void onCancel()
{
this.cleartxt();
this.generateCBAR();
this.txt1.Focus();
}
private void insertProduct()
{
string val = this.validatedata();
switch (val)
{
case ("00"):
{
genericDefinitions.error("Codigo de producto invalido", "Codigo de barras error");
this.txt1.Focus();
break;
}
case ("0"):
{
genericDefinitions.dangerInfo("Datos Invalidos, Llene todos los campos.", "Datos incorrectos");
this.txt1.Focus();
break;
}
case ("1"):
{
this.prod.idcategoria = db.getidcategoria(this.cb1.Text);
this.prod.nombre = this.txt1.Text;
this.prod.precio = double.Parse(this.txt2.Text.Trim(), CultureInfo.InvariantCulture);
this.prod.stock = int.Parse(this.txt3.Text);
this.prod.idproducto = int.Parse(this.txt4.Text);
this.prod.preciocosto = double.Parse(this.txtcosto.Text.Trim(), CultureInfo.InvariantCulture);
if(this.prod.preciocosto > this.prod.precio)
{
genericDefinitions.dangerInfo("Precio de producto menor a costo del mismo.");
this.txt2.Focus();
return;
}
if (db.insertproduct(this.prod))
{
if (this.rbcodigo.Checked)
{
this.cbprint.setParams(this.prod.idproducto);
this.cbprint.print(this.prod.stock);
}
if (this.cbnotifica.Checked)
{
genericDefinitions.ok("Se ha dado de alta articulo", "Echo");
}
this.cleartxt();
this.generateCBAR();
this.txt1.Focus();
}
else
{
this.txt1.Focus();
}
break;
}
}
}
protected void cleartxt()
{
foreach(Control c in this.controls)
{
c.Text = null;
}
this.cbganancia.SelectedIndex = 0;
}
protected string validatedata()
{
foreach(Control c in this.controls)
{
if (c.Text == ""){
return "0";
}
if(c.Name == "txt4")
{
if (!(this.db.isavailableIDproducto(int.Parse(this.txt4.Text.Trim()))))
return "00";
}
}
return "1";
}
protected void fillcategoria()
{
List<categoria> loc = db.getCategorias();
if (loc != null)
{
foreach (categoria c in loc)
this.cb1.Items.Add(c.nombre);
}
}
protected void generateCBAR()
{
this.txt4.Text = this.db.getcurrentidproductos().ToString();
this.picbox.Image = cbar.getImage(this.txt4.Text);
}
protected virtual void addProduct_Load(object sender, EventArgs e)
{
if (!DesignMode)
{
this.fillcategoria();
this.generateCBAR();
}
this.picbox.SizeMode = PictureBoxSizeMode.CenterImage;
this.ActiveControl = this.txt1;
}
private void baccept_Click(object sender, EventArgs e)
{}
private void btncat_Click(object sender, EventArgs e)
{
this.cb1.Items.Clear();
this.fillcategoria();
this.cb1.Focus();
}
}
}