/// <summary> /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ItemCommand_lvGeneric(object sender, ListViewCommandEventArgs e) { try { String[] arguments = e.CommandArgument.ToString().Split('|'); Int32 alimentoId = int.Parse("0" + arguments[0]); string alimento = arguments[1]; if (e.CommandName.ToString().ToUpper() == "ELIMINAR") { //-- Si existe la realcion de al menos un registro, //-- NO SE PUEDE ELIMINAR EL ALIMENTO //-------------------------------------------------- AlimentoNutrienteBus busAliNutriente = new AlimentoNutrienteBus(); AlimentoNutrienteEntityFilter filterAliNutriente = new AlimentoNutrienteEntityFilter(); filterAliNutriente.OpeAlimentoId = Helpers.Operators.Operadores_Int.Igual; filterAliNutriente.AlimentoId = alimentoId; DataTable dtControl = busAliNutriente.Search(filterAliNutriente); if (dtControl != null && dtControl.Rows.Count > 0) { ltrMessage.Text = string.Format("<span style='color:red;'>No es posible eliminar el Alimento [<b>{0}</b>] ya que tiene Nutrientes asignados!</span>", alimento); ltrMessage.Visible = true; return; } EncuestaAlimentoBus busEncuestaAli = new EncuestaAlimentoBus(); EncuestaAlimentoEntityFilter filterEncuestaAli = new EncuestaAlimentoEntityFilter(); filterEncuestaAli.OpeAlimentoId = Helpers.Operators.Operadores_Int.Igual; filterEncuestaAli.AlimentoId = alimentoId; dtControl = busEncuestaAli.Search(filterEncuestaAli); if (dtControl != null && dtControl.Rows.Count > 0) { ltrMessage.Text = string.Format("<span style='color:red;'>No es posible eliminar el Alimento [<b>{0}</b>] ya existe en ciertas Encuestas!</span>", alimento); ltrMessage.Visible = true; return; } //-------------------------------------------------- //-- ELIMINO el ALIMENTO //-------------------------------------------------- keyAlimento.AlimentoId = alimentoId; busAlimento.Delete(keyAlimento); lvGeneric.DataBind(); ltrMessage.Text = string.Format("<span style='color:red;'>El alimento {0} fue Eliminado!</span>", alimento); ltrMessage.Visible = true; } } catch (Exception ex) { Logger.LogExceptionStatic(ex); } }
/// <summary> /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ItemCommand_lvGeneric(object sender, ListViewCommandEventArgs e) { try { String[] arguments = e.CommandArgument.ToString().Split('|'); Int32 nutrienteId = int.Parse("0" + arguments[0]); string nutriente = arguments[1]; if (e.CommandName.ToString().ToUpper() == "ELIMINAR") { //-- Si existe la relacion de al menos un registro, //-- NO SE PUEDE ELIMINAR EL NUTRIENTE //-------------------------------------------------- AlimentoNutrienteBus busAliNutriente = new AlimentoNutrienteBus(); AlimentoNutrienteEntityFilter filterAliNutriente = new AlimentoNutrienteEntityFilter(); filterAliNutriente.OpeNutrienteId = Helpers.Operators.Operadores_Int.Igual; filterAliNutriente.NutrienteId = nutrienteId; DataTable dtControl = busAliNutriente.Search(filterAliNutriente); if (dtControl != null && dtControl.Rows.Count > 0) { ltrMessage.Text = string.Format("<span style='color:red;'>No es posible eliminar el Nutriente [<b>{0}</b>] ya que tiene Alimentos asignados!</span>", nutriente); ltrMessage.Visible = true; return; } //-- Elimino el nutriente //-------------------------------------------------- keyNutriente.NutrienteId = nutrienteId; busNutriente.Delete(keyNutriente); lvGeneric.DataBind(); ltrMessage.Text = string.Format("<span style='color:red;'>El nutriente [<b>{0}</b>] fue Eliminado!</span>", nutriente); ltrMessage.Visible = true; } } catch (Exception ex) { Logger.LogExceptionStatic(ex); } }