public bool Create(Accidente a)
 {
     try
     {
         comando.Connection  = conn.AbrirConexion();
         comando.CommandText = "insert into accidente values(@nombre,@apellido,@edad,@sexo,@accidente,@estado,@foto,@lesion,@direccion,@detalle)";
         comando.CommandType = CommandType.Text;
         comando.Parameters.AddWithValue("@nombre", a.nombre);
         comando.Parameters.AddWithValue("@apellido", a.apellido);
         comando.Parameters.AddWithValue("@edad", a.edad);
         comando.Parameters.AddWithValue("@sexo", a.sexo);
         comando.Parameters.AddWithValue("@accidente", a.accidente);
         comando.Parameters.AddWithValue("@estado", a.estado);
         comando.Parameters.AddWithValue("@foto", a.foto);
         comando.Parameters.AddWithValue("@lesion", a.lesion);
         comando.Parameters.AddWithValue("@direccion", a.direccion);
         comando.Parameters.AddWithValue("@detalle", a.detalle);
         comando.ExecuteNonQuery();
         comando.Parameters.Clear();
         conn.CerrarConexion();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool Update(Accidente a)
 {
     try
     {
         comando.Connection  = conn.AbrirConexion();
         comando.CommandText = "update accidente set nombre=@nombre,apellido=@apellido,edad=@edad,sexo=@sexo,accidente=@accidente,estado=@estado,foto=@foto,lesion=@lesion,direccion=@direccion,detalle=@detalle where id=" + a.id;
         comando.CommandType = CommandType.Text;
         comando.Parameters.AddWithValue("@nombre", a.nombre);
         comando.Parameters.AddWithValue("@apellido", a.apellido);
         comando.Parameters.AddWithValue("@edad", a.edad);
         comando.Parameters.AddWithValue("@sexo", a.sexo);
         comando.Parameters.AddWithValue("@accidente", a.accidente);
         comando.Parameters.AddWithValue("@estado", a.estado);
         comando.Parameters.AddWithValue("@foto", a.foto);
         comando.Parameters.AddWithValue("@lesion", a.lesion);
         comando.Parameters.AddWithValue("@direccion", a.direccion);
         comando.Parameters.AddWithValue("@detalle", a.detalle);
         comando.ExecuteNonQuery();
         comando.Parameters.Clear();
         conn.CerrarConexion();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #3
0
        protected void sendForm(object sender, EventArgs e)
        {
            #region SubmitActualizarRegistro
            if (!string.IsNullOrEmpty(Request.QueryString["id"]) && !string.IsNullOrEmpty(Request["id"]))
            {
                if (Request.QueryString["id"].ToString() == Request["id"].ToString())
                {
                    Accidente accidente = new Accidente();
                    if (foto.HasFile)
                    {
                        string date = DateTime.Now.ToString("yyyyMMddTHHmmss");
                        Debug.WriteLine(date);
                        string direccionruta = Server.MapPath("Imagenes\\");
                        Debug.WriteLine(date);
                        Debug.WriteLine(direccionruta + date + foto.FileName);
                        foto.SaveAs(direccionruta + date + foto.FileName);
                        accidente.foto = date + foto.FileName;
                    }
                    else if (!foto.HasFile)
                    {
                        DatabaseOPS databaseOPSX = new DatabaseOPS(new Conexion());
                        var         accidentex   = databaseOPSX.Read(int.Parse(Request["ctl00$MainContent$id"].ToString()));
                        accidente.foto = accidentex.foto;
                    }

                    #region TipoLesion
                    string quemadura1, fractura1, cortadura1, armafuego1;
                    quemadura1 = (!string.IsNullOrEmpty(Request["ctl00$MainContent$quemadura"])) ? "1" : "0";
                    fractura1  = (!string.IsNullOrEmpty(Request["ctl00$MainContent$fractura"])) ? "1" : "0";
                    cortadura1 = (!string.IsNullOrEmpty(Request["ctl00$MainContent$cortadura"])) ? "1" : "0";
                    armafuego1 = (!string.IsNullOrEmpty(Request["ctl00$MainContent$armafuego"])) ? "1" : "0";
                    #endregion

                    accidente.id        = int.Parse(Request["ctl00$MainContent$id"].ToString());
                    accidente.nombre    = Request["ctl00$MainContent$nombre"].ToString();
                    accidente.apellido  = Request["ctl00$MainContent$apellido"].ToString();
                    accidente.edad      = int.Parse(Request["ctl00$MainContent$edad"].ToString());
                    accidente.sexo      = int.Parse(Request["ctl00$MainContent$sexo"].ToString());
                    accidente.accidente = Request["ctl00$MainContent$fecha"].ToString();
                    accidente.estado    = int.Parse(Request["ctl00$MainContent$estado"].ToString());

                    accidente.lesion    = quemadura1 + fractura1 + cortadura1 + armafuego1;
                    accidente.direccion = Request["ctl00$MainContent$direccion"].ToString();
                    accidente.detalle   = Request["ctl00$MainContent$detalle"].ToString();


                    DatabaseOPS databaseOPS = new DatabaseOPS(new Conexion());
                    databaseOPS.Update(accidente);
                    Response.Redirect("/CRUDAccidentes");
                }
                else
                {
                    Response.StatusCode = 400;
                    Response.Write("Ha ocurrido un error");
                    Response.Redirect("/CRUDAccidentes");
                }
            }
            #endregion

            #region SubmitAgregarRegistro
            else if (string.IsNullOrEmpty(Request.QueryString["id"]) && string.IsNullOrEmpty(Request["id"]))
            {
                string date = DateTime.Now.ToString("yyyyMMddTHHmmss");
                Debug.WriteLine(date);
                string direccionruta = Server.MapPath("Imagenes\\");
                Debug.WriteLine(date);
                Debug.WriteLine(direccionruta + date + foto.FileName);
                foto.SaveAs(direccionruta + date + foto.FileName);

                #region TipoLesion
                string quemadura1, fractura1, cortadura1, armafuego1;
                quemadura1 = (quemadura.Checked) ? "1" : "0";
                fractura1  = (fractura.Checked) ? "1" : "0";
                cortadura1 = (cortadura.Checked) ? "1" : "0";
                armafuego1 = (armafuego.Checked) ? "1" : "0";
                #endregion
                Accidente accidente = new Accidente();

                accidente.nombre    = nombre.Value.ToString();
                accidente.apellido  = apellido.Value.ToString();
                accidente.edad      = int.Parse(edad.Value.ToString());
                accidente.sexo      = (sexo1.Checked) ? 1 : 0;
                accidente.accidente = fecha.Value.ToString();
                accidente.estado    = (estado.Value == "1") ? 1 : 0;
                accidente.foto      = date + foto.FileName;
                accidente.lesion    = quemadura1 + fractura1 + cortadura1 + armafuego1;
                accidente.direccion = direccion.Value.ToString();
                accidente.detalle   = detalle.Value.ToString();


                DatabaseOPS databaseOPS = new DatabaseOPS(new Conexion());
                databaseOPS.Create(accidente);
                Response.Redirect("/CRUDAccidentes");
            }
            #endregion
            else
            {
                Response.StatusCode = 400;
                Response.Write("Ha ocurrido un error");
                Response.Redirect("/CRUDAccidentes");
            }
        }