Exemple #1
0
        protected void btnBorrar_Click(object sender, EventArgs e)
        {
            lblMensajes.Text = "";
            string   StrIdProducto = TablaMedico.SelectedRow.Cells[1].Text;
            string   strCodMedico, strNombre, strDateFecNac, strNif, strDireccion, strTelefono, strCP, strCheck, strCodEsp, strCodAse;
            DateTime dateFecNac;

            strCodMedico = txtCodMedico.Text;
            strNombre    = txtNombre.Text;
            strNif       = txtNif.Text;
            strDireccion = txtDireccion.Text;
            strTelefono  = txtTelefono.Text;
            strCP        = txtCP.Text;
            if (chkActivo.Checked == true)
            {
                strCheck = "S";
            }
            else
            {
                strCheck = "N";
            }
            strCodEsp     = ddlCodEsp.SelectedItem.Value;
            strCodAse     = ddlCodAseg.SelectedItem.Value;
            dateFecNac    = DateTime.Parse(txtFecNac.Text);
            strDateFecNac = String.Format("{0:yyyy-MM-dd}", dateFecNac);

            string strCadenaConexion = "Data Source=(localdb)\\MSSQLLocalDB;AttachDbFilename=" +
                                       Server.MapPath("~/App_Data/Medicos.mdf") +
                                       ";Integrated Security=True;Connect Timeout=30";
            string strComandoSql = "UPDATE MEDICO SET CodMed = '" + strCodMedico.Trim() + "', Nif = '" + strNif.Trim() +
                                   "', Nombre = '" + strNombre.Trim() + "', Direccion='" + strDireccion.Trim() + "', Telefono = '" + strTelefono.Trim() +
                                   "', CodPostal = '" + strCP.Trim() + "', FechaNac = '" + strDateFecNac.Trim() + "', Activo='" + "N" +
                                   "', CodEsp='" + strCodEsp.Trim() + "', CodAseg = '" + strCodAse.Trim() + "'" +
                                   "WHERE CodMed = '" + StrIdProducto + "'";

            if (!(txtCodMedico.Text.Length == 0) && !(txtFecNac.Text.Length == 0) && !(txtNombre.Text.Length == 0))
            {
                using (SqlConnection conexion = new SqlConnection(strCadenaConexion))
                {
                    try
                    {
                        conexion.Open();
                        SqlCommand comando = conexion.CreateCommand();
                        comando.CommandText = strComandoSql;
                        int inRegistrosAfectados = comando.ExecuteNonQuery();
                        if (inRegistrosAfectados == 1)
                        {
                            lblMensajes.Text = "<p class='alert alert-success'>Registro Eliminado correctamente</p>";
                        }
                        else
                        {
                            lblMensajes.Text = "<p class='alert alert-alert'>Error al Eliminar el registro<p>";
                        }
                        reInicioBtn();
                    }
                    catch (SqlException ex)
                    {
                        lblMensajes.Text = error(ex);
                        return;
                    }
                }
                TablaMedico.DataBind();
                TablaMedico.SelectedIndex = -1;
                FnDeshabilitarControles();
            }
            else
            {
                string StrErrorCamposVacios = "<p class='alert alert-danger'> Hay Campos Necesarios para poder eliminar el registro, reviselo </p>";
                lblMensajes.Text = StrErrorCamposVacios;
            }
        }
Exemple #2
0
 protected void btnInsertar_Click(object sender, EventArgs e)
 {
     if (!(txtCodMedico.Text.Length == 0) && !(txtFecNac.Text.Length == 0) && !(txtNombre.Text.Length == 0))
     {
         lblMensajes.Text = "";
         string   strCodMedico, strNombre, strDateFecNac, strNif, strDireccion, strTelefono, strCP, strCheck, strCodEsp, strCodAse;
         DateTime dateFecNac;
         strCodMedico = txtCodMedico.Text;
         strNombre    = txtNombre.Text;
         strNif       = txtNif.Text;
         strDireccion = txtDireccion.Text;
         strTelefono  = txtTelefono.Text;
         strCP        = txtCP.Text;
         if (chkActivo.Enabled)
         {
             strCheck = "S";
         }
         else
         {
             strCheck = "N";
         }
         strCodEsp     = ddlCodEsp.SelectedItem.Value;
         strCodAse     = ddlCodAseg.SelectedItem.Value;
         dateFecNac    = DateTime.Parse(txtFecNac.Text);
         strDateFecNac = String.Format("{0:yyyy-MM-dd}", dateFecNac);
         string strCadenaConexion = "Data Source=(localdb)\\MSSQLLocalDB;AttachDbFilename=" +
                                    Server.MapPath("~/App_Data/Medicos.mdf") +
                                    ";Integrated Security=True;Connect Timeout=30";
         string strComandoSql = "INSERT MEDICO (CodMed, Nif, Nombre, Direccion, Telefono, CodPostal, FechaNac, Activo, CodEsp, CodAseg) " +
                                "VALUES('" + strCodMedico + "', '" + strNif + "', '" + strNombre + "', '" + strDireccion +
                                "', '" + strTelefono + "', '" + strCP + "', '" + strDateFecNac + "', '" + strCheck +
                                "', '" + strCodEsp + "', '" + strCodAse + "')";
         using (SqlConnection conexion = new SqlConnection(strCadenaConexion))
         {
             try
             {
                 conexion.Open();
                 SqlCommand comando = conexion.CreateCommand();
                 comando.CommandText = strComandoSql;
                 int inRegistrosAfectados = comando.ExecuteNonQuery();
                 if (inRegistrosAfectados == 1)
                 {
                     lblMensajes.Text = "<p class='alert alert-success'>Registro insertado correctamente</p>";
                 }
                 else
                 {
                     lblMensajes.Text = "<p class='alert alert-danger'>Error al insertar el registro</p>";
                 }
                 reInicioBtn();;
             }
             catch (SqlException ex)
             {
                 lblMensajes.Text = error(ex);
                 return;
             }
         }
         TablaMedico.DataBind();
         TablaMedico.SelectedIndex = -1;
         FnDeshabilitarControles();
     }
     else
     {
         string StrErrorCamposVacios = "<p class='alert alert-danger'> Hay Campos Necesarios para poder insertar nuevo registro reviselo </p>";
         lblMensajes.Text = StrErrorCamposVacios;
     }
 }