コード例 #1
0
        protected void asignarVariable_Click(object sender, EventArgs e)
        {
            try {
                if (listaVariablesAsignadas.Enabled == false)
                {
                    Response.Write("<script> alert('Error, Hay muestras registradas'); </script>");
                    return;
                }
                VariableController obj = new VariableController();
                dtVariables = (DataTable)Session["dtVariables"];
                int con = 0, activos = 0;
                mapa = (Dictionary <string, int>)Session["mapa"];
                msj  = "Se cambian ";
                DataRow dr;

                for (int i = 0; i < listaVariablesAsignadas.Items.Count; i++)
                {
                    dr = dtVariables.Rows[mapa[listaVariablesAsignadas.Items[i].ToString()]];
                    if (!dr["EXISTE"].ToString().Equals("Si"))
                    {
                        activos++;
                        if (!obj.asignarVariable(Session["pk_pro"].ToString(), dr["idVARIABLE"].ToString()))
                        {
                            con++;
                        }
                        else
                        {
                            dtVariables.Rows[mapa[listaVariablesAsignadas.Items[i].ToString()]]["EXISTE"] = "Si";
                        }
                    }
                }

                for (int i = 0; i < listaVariablesDisponibles.Items.Count; i++)
                {
                    dr = dtVariables.Rows[mapa[listaVariablesDisponibles.Items[i].ToString()]];
                    if (dr["EXISTE"].ToString().Equals("Si"))
                    {
                        activos++;
                        if (!obj.eliminarVariable(Session["pk_pro"].ToString(), dr["idVARIABLE"].ToString()))
                        {
                            con++;
                        }
                        else
                        {
                            dtVariables.Rows[mapa[listaVariablesDisponibles.Items[i].ToString()]]["EXISTE"] = "No";
                        }
                    }
                }

                if (activos == 0)
                {
                    msj = "Sin cambios";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "Confirm();", true);
                    return;
                }
                if (con == 0)
                {
                    msj += " " + activos;
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "Confirm();", true);
                }
                else
                {
                    msj = "Error al actualizar alguno(s)";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "Confirm();", true);
                }
            } catch (Exception) {
                Response.Write("<script> alert('Error inesperado'); </script>");
            }
            cargarVariables(Session["pk_pro"].ToString());
        }