Deber03-UserManagement-Nicolás Toscano
Deber03-UserManagement-Nicolás Toscano
Deber03-UserManagement-Nicolás Toscano
Deber03-UserManagement
Nombre: Nicolás Toscano
Fecha: 5 de febrero de 2024
1. DESARROLLO
− Código
UserManagement.aspx
<ItemTemplate>
<asp:Label ID="lblBirthday" runat="server" Text='<%#
Eval("BIRTHDAY", "{0:dd/MM/yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Type" HeaderStyle-
HorizontalAlign="Left">
<EditItemTemplate>
<asp:DropDownList ID="ddlType" runat="server">
<asp:ListItem Value="0">Normal</asp:ListItem>
<asp:ListItem Value="1">Administrator</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlNewType" runat="server">
<asp:ListItem Value="0">Normal</asp:ListItem>
<asp:ListItem Value="1">Administrator</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
<ItemTemplate>
<asp:DropDownList ID="ddlType" Enabled="false"
runat="server">
<asp:ListItem>User Type</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<EditItemTemplate>
<asp:LinkButton ID="lbkUpdate" runat="server"
CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="lnkCancel" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lnkAdd" runat="server"
CausesValidation="False" CommandName="Insert"
Text="Insert"></asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server"
CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</div>
<div>
<asp:Panel ID="frmConfirmation" Visible="true" Runat="server">
<asp:Label id="lblMessage" ForeColor="Red" Font-Bold="true"
Runat="server"></asp:Label>
</asp:Panel>
</div>
</asp:Content>
UserManagement.aspx.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebAppPoliMusicV2.ServiceReferenceUser;
FACULTAD DE INGENIERÍA EN SISTEMAS
ISWD813 Aplicaciones Web Avanzadas
using WebAppPoliMusicV2.Util;
namespace WebAppPoliMusicV2.Admin
{
public partial class UserManagement : System.Web.UI.Page
{
int userId;
User user;
}
protected void gridViewUser_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType
== DataControlRowType.Footer)
{
DropDownList ddlType = e.Row.FindControl(e.Row.RowState ==
DataControlRowState.Edit ? "ddlType" : "ddlNewType") as DropDownList;
if (ddlType != null)
{
// Assuming that you have a DataTable as the DataSource
for the GridView
DataRowView drv = e.Row.DataItem as DataRowView;
if (drv != null)
{
// Assuming that "USER_TYPE" is the column name in
your DataTable
if (drv.Row.Table.Columns.Contains("USER_TYPE"))
{
int userTypeValue =
Convert.ToInt32(drv["USER_TYPE"]);
}
protected void gridViewUser_RowEditing(object sender,
GridViewEditEventArgs e)
{
gridViewUser.EditIndex = e.NewEditIndex;
BindData();
}
protected void gridViewUser_RowCancelingEdit(object sender,
GridViewCancelEditEventArgs e)
FACULTAD DE INGENIERÍA EN SISTEMAS
ISWD813 Aplicaciones Web Avanzadas
{
gridViewUser.EditIndex = -1;
BindData();
}
string strImageFolder =
ConfigurationManager.AppSettings["userPhotoPath"];
string strFileNameExtension =
Path.GetExtension(fileUploadNewUserPhoto.FileName);
string newFileNameWithExtension = strImageFolder +
newImageName + strFileNameExtension;
messageValidations = UserFieldsRequiredValidations(user);
if (messageValidations != string.Empty)
{
lblMessage.Text = messageValidations;
return;
}
messageValidations = new
ServiceReferenceUser.WebServiceUserSoapClient().ValidationsDuplicated(user);
if (messageValidations != string.Empty)
{
lblMessage.Text = messageValidations;
return;
}
if (fileUploadNewUserPhoto.HasFile)
{
messageValidations = new
FileManagement().SaveImageOnServer(fileUploadNewUserPhoto, strImageFolder,
newImageName);
}
else
{
messageValidations = new
FileManagement().SaveDefaultImageOnServer(strImageFolder, newImageName);
user.Photo += ".jpg";
}
if (messageValidations != string.Empty)
{
lblMessage.Text = messageValidations;
return;
}
user.Password = Util.Hash.GeneratePasswordHash(password);
new
ServiceReferenceUser.WebServiceUserSoapClient().AddUser(user);
FACULTAD DE INGENIERÍA EN SISTEMAS
ISWD813 Aplicaciones Web Avanzadas
lblMessage.Text = string.Empty;
BindData();
gridViewUser.SelectedIndex = -1;
}
}
System.Web.UI.WebControls.Image imageEditPlaylistPhoto =
(System.Web.UI.WebControls.Image)gridViewUser.Rows[e.RowIndex].FindControl("
imageEditUserPhoto");
string strImageFolder =
ConfigurationManager.AppSettings["playlistFolderPath"];
string strFileNameExtension =
Path.GetExtension(fileUploadUserPhoto.FileName);
string newFileNameWithExtension = strImageFolder + newImageName
+ strFileNameExtension;
if (fileUploadUserPhoto.HasFile)
{
user.Photo = newFileNameWithExtension;
}
else
{
user.Photo = imageEditPlaylistPhoto.ImageUrl;
}
messageValidations = UserValidations(user);
if (messageValidations != string.Empty)
{
lblMessage.Text = messageValidations;
return;
}
int returnValue = new
ServiceReferenceUser.WebServiceUserSoapClient().CheckExistUser(user.Name);
if (returnValue != 0)
{
FACULTAD DE INGENIERÍA EN SISTEMAS
ISWD813 Aplicaciones Web Avanzadas
new
ServiceReferenceUser.WebServiceUserSoapClient().UpdateUser(user.Id,
user.Name, user.Password, user.Email, user.Birthday, user.Photo ,user.Type);
lblMessage.Text = string.Empty;
gridViewUser.EditIndex = -1;
BindData();
}
}
FACULTAD DE INGENIERÍA EN SISTEMAS
ISWD813 Aplicaciones Web Avanzadas
2. Operaciones CRUD
− READ
FACULTAD DE INGENIERÍA EN SISTEMAS
ISWD813 Aplicaciones Web Avanzadas
− CREATE
− UPDATE
FACULTAD DE INGENIERÍA EN SISTEMAS
ISWD813 Aplicaciones Web Avanzadas
− DELETE