Пример #1
0
 //constructor para insertar
 public clsStock(int parIdProductoInt, clsAlmacen parIdAlmacenST, clsMedida parIdMedidaST, decimal parCantidadSt)
 {
     IdProdructoInt = parIdProductoInt;
     IdAlmacenST    = parIdAlmacenST;
     IdMedidaST     = parIdMedidaST;
     CantidadST     = parCantidadSt;
 }
        private void lstvDatos_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstvDatos.SelectedItems.Count > 0)
            {
                AlmacenSeleccionado = AlmacenesEncontrados[lstvDatos.SelectedItems[0].Index];
            }

            txtId.Text          = AlmacenSeleccionado.IdAlmacen.ToString();
            txtDireccion.Text   = AlmacenSeleccionado.DireccionAlm.ToString();
            txtTelefono.Text    = AlmacenSeleccionado.TelefonoAlm.ToString();
            txtDescripcion.Text = AlmacenSeleccionado.DescripcionAlm.ToString();
            if (AlmacenSeleccionado.TipoAlm.ToString() == "PRINCIPAL")
            {
                rbnPrincipal.Checked = true;
            }
            else
            {
                rbnSecundario.Checked = true;
            }


            txtDireccion.Enabled   = false;
            txtTelefono.Enabled    = false;
            txtDescripcion.Enabled = false;
            btnGuardar.Visible     = false;
            btnActualizar.Visible  = true;
            btnLimpiar.Enabled     = true;
            rbnPrincipal.Enabled   = false;
            rbnSecundario.Enabled  = false;
        }
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                clsAlmacen nuevosDatosAlmacen;
                if (rbnPrincipal.Checked == true)
                {
                    nuevosDatosAlmacen = new clsAlmacen(txtDireccion.Text, txtTelefono.Text, "PRINCIPAL");
                }
                else
                {
                    nuevosDatosAlmacen = new clsAlmacen(txtDireccion.Text, txtTelefono.Text, "SECUNDARIO");
                }

                nuevosDatosAlmacen.DescripcionAlm = txtDescripcion.Text;
                AlmacenSeleccionado.Actualizar(nuevosDatosAlmacen);
                MessageBox.Show("Datos actualizados satisfactoriamente.");
            }
            catch (Exception ErrorRegCli)
            {
                MessageBox.Show(ErrorRegCli.Message);
            }


            txtDireccion.Enabled   = false;
            txtTelefono.Enabled    = false;
            txtDescripcion.Enabled = false;
            btnGuardar.Visible     = false;
            btnActualizar.Visible  = true;
            btnLimpiar.Enabled     = true;
            rbnPrincipal.Enabled   = false;
            rbnSecundario.Enabled  = false;
            lstvDatos.Items.Clear();
            txtTexto.Clear();
        }
        public void Actualizar(clsAlmacen NuevosDatos)
        {
            SqlConnection conexion;

            conexion = new SqlConnection(mdlVariables.CadenaDeConexion);

            SqlCommand cmd = new SqlCommand("usp_Almacen_Actualizar", conexion);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@parIdAlmacen", IdAlmacen);

            cmd.Parameters.AddWithValue("@parNUEVO_Direccion_Alm", NuevosDatos.DireccionAlm);
            cmd.Parameters.AddWithValue("@parNUEVO_Telefono_Alm", NuevosDatos.TelefonoAlm);
            cmd.Parameters.AddWithValue("@parNUEVO_Tipo_Alm", NuevosDatos.TipoAlm);

            if (string.IsNullOrEmpty(NuevosDatos.DescripcionAlm))
            {
                cmd.Parameters.AddWithValue("@parNUEVO_Descripcion_Alm", DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@parNUEVO_Descripcion_Alm", NuevosDatos.DescripcionAlm);
            }
            conexion.Open();
            cmd.ExecuteNonQuery();
            conexion.Close();
        }
        public static List <clsAlmacen> ListarAlmacenPorId(int parametroId)
        {
            List <clsAlmacen> x = new List <clsAlmacen>();

            SqlConnection conexion;

            conexion = new SqlConnection(mdlVariables.CadenaDeConexion);

            SqlCommand cmd = new SqlCommand("usp_Almacen_ListarPorId", conexion);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@parIdAlmacen", parametroId);
            conexion.Open();
            SqlDataReader contenedor;

            contenedor = cmd.ExecuteReader();
            while (contenedor.Read() == true)
            {
                clsAlmacen MiObjeto;
                MiObjeto = new clsAlmacen(Convert.ToInt32(contenedor["IdAlmacen"]), contenedor["Direccion_Alm"].ToString(),
                                          contenedor["Telefono_Alm"].ToString(), contenedor["Descripcion_Alm"].ToString(), contenedor["Tipo_Alm"].ToString());

                x.Add(MiObjeto);
            }
            conexion.Close();

            return(x);
        }
Пример #6
0
        private void btnInsertar_Click(object sender, EventArgs e)
        {
            try
            {
                clsAlmacen nuevoAlmacen;

                if (rbnPrincipal.Checked == true)
                {
                    nuevoAlmacen = new clsAlmacen(txtDireccion.Text, txtTelefono.Text, "PRINCIPAL");
                }
                else
                {
                    nuevoAlmacen = new clsAlmacen(txtDireccion.Text, txtTelefono.Text, "SECUNDARIO");
                }
                nuevoAlmacen.DescripcionAlm = txtDescripcion.Text;
                nuevoAlmacen.InsertarAlmacen();
                MessageBox.Show("Almacen Registrado");
            }
            catch (Exception ErrorRegCli)
            {
                MessageBox.Show(ErrorRegCli.Message);
            }
        }