Ejemplo n.º 1
0
    public void btn_editGrabar_Click(object sender, EventArgs e)
    {
        UsuarioRemolcadorBC u = new UsuarioRemolcadorBC();

        u.REMO_ID = int.Parse(this.ddl_remoEdit.SelectedValue);
        u.SITE_ID = int.Parse(this.ddl_siteEdit.SelectedValue);
        DataTable dt    = (DataTable)this.ViewState["edit"];
        bool      exito = true;

        if (!string.IsNullOrEmpty(this.hf_eliminados.Value))
        {
            if (!u.Eliminar(this.hf_eliminados.Value))
            {
                exito = false;
            }
        }
        foreach (DataRow dr in dt.Rows)
        {
            if (dr["REPR_ID"].ToString() == "0")
            {
                u.FECHA   = DateTime.Parse(dr["FECHA"].ToString());
                u.USUA_ID = int.Parse(dr["USUA_ID"].ToString());
                u.JORN_ID = int.Parse(dr["JORN_ID"].ToString());
                u.REPD_ID = int.Parse(dr["REPD_ID"].ToString());
                if (!u.Guardar(u))
                {
                    exito = false;
                }
            }
        }
        if (exito)
        {
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "msj", "showAlert('Asociación usuario remolcador guardada exitosamente!');", true);
            if (string.IsNullOrEmpty(this.hf_idremo.Value))
            {
                this.limpiarForm();
            }
            this.ObtenerUsuarioRemolcador(true);
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "cerrar", "$('#modalUsuarioRemolcador').modal('hide');", true);
        }
        else
        {
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "msj", "alert('Error. No se guardaron/eliminaron todos los registros correctamente. Revise los datos.');", true);
        }
    }