Пример #1
0
        protected void btnModificar_Click(object sender, EventArgs e)
        {
            try
            {
                Cls_Motos_ADO controladorMotos = new Cls_Motos_ADO(ConfigurationManager.ConnectionStrings["stringConexion"].ConnectionString);

                //path de la foto
                string urlImagen = this.Scooter1.ImageUrl;
                urlImagen = urlImagen.Replace("~", "");
                urlImagen = urlImagen.Replace("/", "\\");
                urlImagen = urlImagen.Substring(1, urlImagen.Length - 1);
                string path = Request.PhysicalApplicationPath + urlImagen;

                //se crea una instancia del cliente con los datos ingresados en el front-end
                this.varMotos = new Cls_Motos(this.txtPlaca.Text, decimal.Parse(this.txtPrecio.Text), this.cbxTipo.SelectedValue,
                                              this.txtModelo.Text, this.txtDescripcion.Text, File.ReadAllBytes(path), this.Session["nombreFoto"].ToString());

                //utilizar el controlador
                //ADO = access data object
                Cls_Motos_ADO controladorMoto = new Cls_Motos_ADO(ConfigurationManager.ConnectionStrings["stringConexion"].ConnectionString);

                //se utiliza el controlador para almacenar los datos del objeto modelo
                //en la base de datos (Db_Motos)
                controladorMoto.ModificarMotos(this.varMotos);

                //se muestra los datos de la instancia del cliente
                Response.Write("<script language='javaScript'> alert('Datos del vehiculo" + this.varMotos.placa + " " +
                               this.varMotos.Descripcion + " " + this.varMotos.precio + "'); </script>");
            }
            catch (Exception ex)
            {
                Response.Write("<script language='JavaScript'> alert('" + ex.Message + "');</script>");
            }
        }
Пример #2
0
        protected void btnConsultar_Click(object sender, EventArgs e)
        {
            try
            {
                Cls_Motos_ADO controladorMotos = new Cls_Motos_ADO(ConfigurationManager.ConnectionStrings["stringConexion"].ConnectionString);
                Cls_Motos     varMoto          = null;
                varMoto                    = controladorMotos.ConsultarMotos(this.txtPlaca.Text.Trim());
                this.txtPrecio.Text        = varMoto.precio.ToString();
                this.cbxTipo.SelectedValue = varMoto.tipo.ToString();
                this.txtModelo.Text        = varMoto.Modelo.ToString();
                this.txtDescripcion.Text   = varMoto.Descripcion.ToString();

                string path = Request.PhysicalApplicationPath + "Imagenes\\" + varMoto.nombreFoto;
                using (FileStream foto = new FileStream(path, FileMode.Create, FileAccess.Write))
                {
                    foto.Flush();
                    foto.Close();
                }
                File.WriteAllBytes(path, varMoto.foto);
                this.Scooter1.ImageUrl = "~/Imagenes/" + varMoto.nombreFoto;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        public void ModificarMotos(Cls_Motos pPlaca)
        {
            try
            {
                this.conexion = new SqlConnection(this.stringConexion);
                this.conexion.Open();


                this.comando             = new SqlCommand();
                this.comando.Connection  = this.conexion;
                this.comando.CommandText = "[Sp_Upd_Motos]";
                this.comando.CommandType = System.Data.CommandType.StoredProcedure;
                this.comando.Parameters.AddWithValue("@Placa", pPlaca.placa);
                this.comando.Parameters.AddWithValue("@Precio", pPlaca.precio);
                this.comando.Parameters.AddWithValue("@tipo", pPlaca.tipo);
                this.comando.Parameters.AddWithValue("@modelo", pPlaca.Modelo);
                this.comando.Parameters.AddWithValue("@descripcion", pPlaca.Descripcion);
                this.comando.Parameters.AddWithValue("@foto", pPlaca.foto);
                this.comando.Parameters.AddWithValue("@NombreFoto", pPlaca.nombreFoto);


                this.comando.ExecuteNonQuery();


                this.conexion.Close();
                this.conexion.Dispose();
                this.comando.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #4
0
        public void RegistrarMotos(Cls_Motos pPlaca)
        {
            try
            {
                //Se requiere una conexion
                this.conexion = new SqlConnection(this.stringConexion);
                this.conexion.Open();

                //Se crea el comando que llama al procedimiento almacenado para insertar datos.
                this.comando             = new SqlCommand();
                this.comando.Connection  = this.conexion;
                this.comando.CommandText = "[Sp_Ins_Motos]";
                this.comando.CommandType = System.Data.CommandType.StoredProcedure;
                this.comando.Parameters.AddWithValue("@Placa", pPlaca.placa);
                this.comando.Parameters.AddWithValue("@Precio", pPlaca.precio);
                this.comando.Parameters.AddWithValue("@tipo", pPlaca.tipo);
                this.comando.Parameters.AddWithValue("@modelo", pPlaca.Modelo);
                this.comando.Parameters.AddWithValue("@descripcion", pPlaca.Descripcion);
                this.comando.Parameters.AddWithValue("@foto", pPlaca.foto);
                this.comando.Parameters.AddWithValue("@NombreFoto", pPlaca.nombreFoto);

                this.comando.ExecuteNonQuery();

                this.conexion.Close();
                this.conexion.Dispose();
                this.comando.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #5
0
        protected void btnRegistrar_Click(object sender, EventArgs e)
        {
            try
            {
                //path de la foto
                string urlImagen = this.Scooter1.ImageUrl;
                urlImagen = urlImagen.Replace("~", "");
                urlImagen = urlImagen.Replace("/", "\\");
                urlImagen = urlImagen.Substring(1, urlImagen.Length - 1);
                string path = Request.PhysicalApplicationPath + urlImagen;
                //se crea una instancia de la moto con los datos ingresados en el front-end
                this.varMotos = new Cls_Motos(this.txtPlaca.Text, decimal.Parse(this.txtPrecio.Text), this.cbxTipo.SelectedValue,
                                              this.txtModelo.Text, this.txtDescripcion.Text, File.ReadAllBytes(path), this.Session["nombreFoto"].ToString());


                Cls_Motos_ADO controladorMoto = new Cls_Motos_ADO(ConfigurationManager.ConnectionStrings["stringConexion"].ConnectionString);
                controladorMoto.RegistrarMotos(varMotos);

                Cls_Motos_ADO controladorMotos = new Cls_Motos_ADO(ConfigurationManager.ConnectionStrings["stringConexion"].ConnectionString);
                Cls_Motos     varMoto          = null;
                varMoto                    = controladorMotos.ConsultarMotos(this.txtPlaca.Text.Trim());
                this.txtPrecio.Text        = varMoto.precio.ToString();
                this.cbxTipo.SelectedValue = varMoto.tipo.ToString();
                this.txtModelo.Text        = varMoto.Modelo.ToString();
                this.txtDescripcion.Text   = varMoto.Descripcion.ToString();

                string path2 = Request.PhysicalApplicationPath + "Imagenes\\" + varMoto.nombreFoto;
                using (FileStream foto = new FileStream(path2, FileMode.Create, FileAccess.Write))
                {
                    foto.Flush();
                    foto.Close();
                }
                File.WriteAllBytes(path2, varMoto.foto);
                this.Scooter1.ImageUrl = "~/Imagenes/" + varMoto.nombreFoto;



                this.txtPlaca.Text         = "";
                this.txtPrecio.Text        = "";
                this.cbxTipo.SelectedIndex = 0;
                this.txtModelo.Text        = "";
                this.txtDescripcion.Text   = "";
                this.Scooter1.ImageUrl     = "~/Imagenes/índice.png";

                Response.Write("<script language='JavaScript'>" + "alert('Moto Registrada Correctamente');</script>");

                //se borra la foto despues de registrar
            }
            catch (Exception ex)
            {
                Response.Write("<script language='JavaScript'> alert('" + ex.Message + "');</script>");
            }
        }
Пример #6
0
        public Cls_Motos ConsultarMotos(string pPlaca)
        {
            try
            {
                Cls_Motos varMotos = null;

                this.conexion = new SqlConnection(this.stringConexion);

                this.comando = new SqlCommand();

                this.conexion.Open();
                this.comando.Connection  = this.conexion;
                this.comando.CommandText = "[Sp_Cns_Motos]";
                this.comando.CommandType = System.Data.CommandType.StoredProcedure;
                this.comando.Parameters.AddWithValue("@placa", pPlaca);

                SqlDataReader lector = null;

                lector = this.comando.ExecuteReader();

                if (lector.Read())
                {
                    varMotos = new Cls_Motos(lector.GetValue(0).ToString(),
                                             decimal.Parse(lector.GetValue(1).ToString()),
                                             lector.GetValue(2).ToString(),
                                             lector.GetValue(3).ToString(),
                                             lector.GetValue(4).ToString(),
                                             (byte[])(lector.GetValue(5)),
                                             lector.GetValue(6).ToString());

                    lector.Close();
                }
                else
                {
                    throw new Exception("no existe ninguna moto con la placa # " + pPlaca);
                }

                lector = null;
                conexion.Close();
                conexion.Dispose();

                //este metodo retorna la instancia del objeto
                return(varMotos);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }