-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFallos_Settings_Form.cs
139 lines (123 loc) · 4.72 KB
/
Fallos_Settings_Form.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
using RugFactory.Db;
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 RugFactory
{
public partial class Fallos_Settings_Form : Form
{
DbAccess dbAccess;
private Int32? currentFalloId;
public Fallos_Settings_Form()
{
InitializeComponent();
dbAccess = new DbAccess();
}
private void Fallos_Settings_Form_Load(object sender, EventArgs e)
{
loadDataToFallosGridView();
}
private void loadDataToFallosGridView()
{
dataGridView_Fallos.DataSource = dbAccess.GetAllFallos();
}
private void button_Submit_Click(object sender, EventArgs e)
{
if (ValidateChildren(ValidationConstraints.Enabled))
{
FalloAlfombra fallo = getFalloObjextFromUserInputs();
switch (button_Submit.Text)
{
case "Actualizar":
fallo.FalloId =(int)currentFalloId;
dbAccess.UpdateFallo(fallo);
break;
case "Agregar":
dbAccess.AddFallo(fallo);
break;
}
cleanErrosMessages();
cleanTextBoxes();
currentFalloId = null;
loadDataToFallosGridView();
textBox_FalloName.CausesValidation = false;
}
}
private FalloAlfombra getFalloObjextFromUserInputs()
{
FalloAlfombra fallo = new FalloAlfombra();
string fallo_Nombre = textBox_FalloName.Text.Trim();
string fallo_Description = textBox_Description.Text.Trim();
fallo.Nombre = fallo_Nombre;
fallo.Descripcion = fallo_Description;
return fallo;
}
private void dataGridView_Fallos_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
dataGridView_Fallos.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
}
private void PopulateFalloToTexBoxes(FalloAlfombra falloToPublish)
{
textBox_FalloName.Text = falloToPublish.Nombre.ToString();
textBox_Description.Text = falloToPublish.Descripcion.ToString();
currentFalloId = falloToPublish.FalloId;
}
private void cleanTextBoxes()
{
FormUtilities.CleanAllTextBoxes(this);
}
private void textBox_FalloName_Validating(object sender, CancelEventArgs e)
{
if(string.IsNullOrEmpty(textBox_FalloName.Text))
{
e.Cancel = true;
errorProviderFallo.SetError(textBox_FalloName, "Porfavor, Indique el Nombre de Fallo");
}
else
{
errorProviderFallo.SetError(textBox_FalloName, null);
}
}
private void cleanErrosMessages()
{
FormUtilities.CleanErrorProviderMessage(errorProviderFallo, this);
}
private void button_Cancel_Click(object sender, EventArgs e)
{
cleanTextBoxes();
cleanErrosMessages();
currentFalloId = null;
button_Submit.Text = "Agregar";
}
private void button_Delete_Click(object sender, EventArgs e)
{
if (currentFalloId != null)
{
dbAccess.RemoveFallo(dbAccess.GetFalloById((int)currentFalloId));
loadDataToFallosGridView();
}
}
private void dataGridView_Fallos_RowEnter(object sender, DataGridViewCellEventArgs e)
{
publishToEditBoxes();
}
private void publishToEditBoxes()
{
if (dataGridView_Fallos.Rows.Count.Equals(0)) return;
if (dataGridView_Fallos.CurrentRow == null) return;
int falloId = (int)dataGridView_Fallos.CurrentRow.Cells[0].Value;
FalloAlfombra CurrentFallo = new FalloAlfombra();
CurrentFallo.FalloId = falloId;
CurrentFallo.Nombre = dataGridView_Fallos.CurrentRow.Cells[1].Value.ToString();
CurrentFallo.Descripcion = dataGridView_Fallos.CurrentRow.Cells[2].Value.ToString();
PopulateFalloToTexBoxes(CurrentFallo);
FormUtilities.TuggleButtonText(button_Submit, "Actualizar");
}
}
}