-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocentesCursos.aspx.cs
211 lines (176 loc) · 5.68 KB
/
DocentesCursos.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
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 DocentesCursos : System.Web.UI.Page
{
DocenteCursoLogic _logic;
private DocenteCursoLogic Logic
{
get
{
if (_logic == null)
{
_logic = new DocenteCursoLogic();
}
return _logic;
}
}
private void LoadGrid()
{
this.gridView1.DataSource = Logic.GetAll();
this.gridView1.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 Entidades.DocenteCurso 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.gridView1.SelectedValue;
}
private void LoadForm(int id)
{
this.Entity = this.Logic.GetOne(id);
this.nombreTextBox.Text = this.Entity.Id.ToString();
this.DropDownList1.Text = this.Entity.IdCurso.ToString();
this.DropDownList2.Text = this.Entity.IdDocente.ToString();
this.DropDownList3.Text = this.Entity.Cargo;
}
private void LoadEntity(DocenteCurso dc)
{
dc.IdCurso = int.Parse(this.DropDownList1.SelectedValue);
dc.IdDocente = int.Parse(this.DropDownList2.SelectedValue);
dc.Cargo = this.DropDownList3.Text;
}
private void SaveEntity(DocenteCurso dc)
{
this.Logic.Save(dc);
}
private void EnableForm(bool enable)
{
this.nombreTextBox.Enabled = false;
this.DropDownList1.Enabled = enable;
this.DropDownList2.Enabled = enable;
this.DropDownList3.Enabled = enable;
}
private void DeleteEntity(int id)
{
this.Logic.Delete(id);
}
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 aceptarLinkButton_Click(object sender, EventArgs e)
{
switch (this.FormMode)
{
case FormModes.Alta:
this.Entity = new DocenteCurso();
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 DocenteCurso();
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 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);
}
}
private void ClearForm()
{
}
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);
}
protected void cancelarLinkButton_Click(object sender, EventArgs e)
{
gridView1.Enabled = true;
this.ClearForm();
this.formPanel.Visible = false;
this.formActionsPanel.Visible = false;
}
}
}