-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCurso.aspx.cs
212 lines (190 loc) · 6.17 KB
/
Curso.aspx.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Negocio;
using Entidades;
namespace UI.web
{
public partial class WebForm1 : System.Web.UI.Page
{
CursoLogic _logic;
private CursoLogic Logic
{
get
{
if (_logic == null)
{
_logic = new CursoLogic();
}
return _logic;
}
}
private void LoadGrid()
{
this.gridView.DataSource = Logic.GetAll();
this.gridView.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["tipoUsuario"].Equals(1))
{
Response.Redirect("/Error.aspx");
}
if (Session["tipoUsuario"].Equals(2))
{
Response.Redirect("/Error.aspx");
}
if (!Page.IsPostBack)
{
this.LoadGrid();
}
}
public enum FormModes
{
Alta,
Baja,
Modificacion
}
public FormModes FormMode
{
get { return (FormModes)this.ViewState["FormMode"]; }
set { this.ViewState["FormMode"] = value; }
}
private Curso Entity
{
get;
set;
}
private int SelectedID
{
get
{
if (this.ViewState["SelectedID"] != null)
return (int)ViewState["SelectedID"];
else
return 0;
}
set { this.ViewState["SelectedID"] = value; }
}
private bool IsEntitySelected
{
get { return (this.SelectedID != 0); }
}
protected void gridView_SelectedIndexChanged(object sender, EventArgs e)
{
this.SelectedID = (int)this.gridView.SelectedValue;
}
private void LoadForm(int id)
{
this.Entity = this.Logic.GetOne(id);
this.DropDownList1.Text = this.Entity.IdMateria.ToString();
this.DropDownList2.Text = this.Entity.IdComision.ToString();
this.anioCalendarioTextBox.Text = this.Entity.AnioCalendario.ToString();
this.cupoTextBox.Text = this.Entity.Cupo.ToString();
}
private void LoadEntity(Curso curso)
{
curso.IdMateria = int.Parse(this.DropDownList1.Text);
curso.IdComision = int.Parse(this.DropDownList2.Text);
curso.AnioCalendario = int.Parse(this.anioCalendarioTextBox.Text);
curso.Cupo = int.Parse(this.cupoTextBox.Text);
}
private void SaveEntity(Curso curso)
{
this.Logic.Save(curso);
}
private void EnableForm(bool enable)
{
this.DropDownList1.Enabled = enable;
this.DropDownList2.Enabled = enable;
this.anioCalendarioTextBox.Enabled = enable;
this.cupoTextBox.Enabled = enable;
this.idMateriaLabel.Visible = enable;
this.idComisionLabel.Visible = enable;
this.anioCalendarioLabel.Visible = enable;
this.cupoLabel.Visible = enable;
}
protected void editarLinkButton_Click(object sender, EventArgs e)
{
if (this.IsEntitySelected)
{
this.formPanel.Visible = true;
this.formActionsPanel.Visible = true;
this.FormMode = FormModes.Modificacion;
this.LoadForm(this.SelectedID);
this.EnableForm(true);
}
}
protected void eliminarLinkButton_Click(object sender, EventArgs e)
{
if (this.IsEntitySelected)
{
this.formPanel.Visible = true;
this.formActionsPanel.Visible = true;
this.FormMode = FormModes.Baja;
this.LoadForm(this.SelectedID);
this.EnableForm(false);
}
}
protected void nuevoLinkButton_Click(object sender, EventArgs e)
{
this.formPanel.Visible = true;
this.formActionsPanel.Visible = true;
this.ClearForm();
this.FormMode = FormModes.Alta;
this.EnableForm(true);
}
private void ClearForm()
{
this.anioCalendarioTextBox.Text = string.Empty;
this.cupoTextBox.Text = string.Empty;
}
private void DeleteEntity(int id)
{
this.Logic.Delete(id);
}
protected void aceptarLinkButton_Click(object sender, EventArgs e)
{
switch (this.FormMode)
{
case FormModes.Alta:
this.Entity = new Curso();
this.LoadEntity(this.Entity);
this.SaveEntity(this.Entity);
this.LoadGrid();
break;
case FormModes.Baja:
this.DeleteEntity(this.SelectedID);
this.LoadGrid();
break;
case FormModes.Modificacion:
this.Entity = new Curso();
this.Entity.Id = this.SelectedID;
this.Entity.State = BusinessEntity.States.Modified;
this.LoadEntity(this.Entity);
this.SaveEntity(this.Entity);
this.LoadGrid();
break;
default:
break;
}
this.formPanel.Visible = false;
this.formActionsPanel.Visible = false;
}
protected void cancelarLinkButton_Click(object sender, EventArgs e)
{
gridView.Enabled = true;
this.ClearForm();
this.formPanel.Visible = false;
this.formActionsPanel.Visible = false;
this.LoadGrid();
}
protected void gridView_SelectedIndexChanged1(object sender, EventArgs e)
{
this.SelectedID = (int)this.gridView.SelectedValue;
}
}
}