コード例 #1
0
        private void btnGenerar_Click(object sender, EventArgs e)
        {
            try
            {
                var random = new Random();

                for (int i = 0; i < 10; i++)
                {
                    var      value = random.Next(1, 200);
                    var      opc   = random.Next(1, 4);
                    ClaseVar Aux   = new ClaseVar();//genera para la clase b
                    Aux.Nombre = RandomString(4);
                    Aux.ID     = value;
                    Aux.Sueldo = value;



                    Aux.Direccion = PathDireccion;
                    arbol.AgregarNodo(Aux);
                    AgregarTabla("");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error {ex}");
            }
        }
コード例 #2
0
        private ClaseVar ObtenerObjeto(string Tipo, string x)
        {
            ClaseVar empresa = new ClaseVar();

            if (Tipo == "Agregar")
            {
                try
                {
                    empresa.Nombre = txtCampo1.Text;
                    empresa.ID     = int.Parse(txtCampo2.Text);
                    empresa.Sueldo = int.Parse(txtCampo3.Text);

                    empresa.Direccion = PathDireccion;
                    return(empresa);
                }
                catch (Exception ex)
                {
                    throw new Exception("" + ex);
                }
            }
            DataGridViewRow row = Tabla.CurrentRow;

            if (Tipo == "Tabla" && row != null)//Para cuando hago click en la tabla
            {
                try
                {
                    empresa.Nombre = Tabla.CurrentRow.Cells[0].Value.ToString();
                    empresa.ID     = int.Parse(Tabla.CurrentRow.Cells[1].Value.ToString());
                    empresa.Sueldo = int.Parse(Tabla.CurrentRow.Cells[2].Value.ToString());

                    empresa.Direccion = Tabla.CurrentRow.Cells[3].Value.ToString();
                    return(empresa);
                }
                catch (NullReferenceException exx)
                {
                    throw new Exception("" + exx);
                }
                catch (Exception ex)
                {
                    throw new Exception("" + ex);
                }
            }
            if (Tipo == "Buscar" && row != null)//Para el boton buscar
            {
                try
                {
                    ClaseVar Aux = new ClaseVar();
                    txtCampo1.Text = Tabla.CurrentRow.Cells[0].Value.ToString();
                    txtCampo2.Text = Tabla.CurrentRow.Cells[1].Value.ToString();
                    txtCampo3.Text = Tabla.CurrentRow.Cells[2].Value.ToString();

                    MostrarImagenPerfil(Tabla.CurrentRow.Cells[3].Value.ToString());
                    return(ObtenerObjeto("Agregar", ""));
                }
                catch (Exception)
                {
                    throw new Exception("Error");
                }
            }

            if (row == null)
            {
                throw new Exception("Seleccione un renglon de la tabla");
            }
            throw new Exception("El metodo no encontro la palabra " + Tipo);
        }