Exemplo n.º 1
0
        private void btnGuardar_Click_1(object sender, EventArgs e)
        {
            Huesped pHuesped = new Huesped();

            pHuesped.PrimerNombre    = txtPrimerNombre.Text.Trim();
            pHuesped.SegundoNombre   = txtSegundoNombre.Text.Trim();
            pHuesped.PrimerApellido  = txtPrimerApellido.Text.Trim();
            pHuesped.SegundoApellido = txtSegundoApellido.Text.Trim();
            pHuesped.Compania        = Compania.Trim();
            pHuesped.NombreCompania  = txtNombreCompania.Text.Trim();
            pHuesped.TipoDocumento   = cbxTipoIdentificacion.Text.Trim();
            pHuesped.NumDocumento    = txtIdentificacion.Text.Trim();
            pHuesped.Sexo            = Sexo.Trim();
            pHuesped.Telefono        = txtTelefono.Text.Trim();
            pHuesped.Direccion       = txtDireccion.Text.Trim();
            pHuesped.Ciudad          = txtCiudad.Text.Trim();
            pHuesped.Provincia       = txtProvincia.Text.Trim();
            pHuesped.Pais            = txtPaisNatal.Text.Trim();
            pHuesped.Correo          = txtCorreo.Text.Trim();

            int resultado = HuespedD.Agregar(pHuesped);

            if (resultado > 0)
            {
                MessageBox.Show("Huesped guardado con exito!!", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dgvHuespedes.DataSource = null;
                dgvHuespedes.DataSource = obj.VistaTabla();
                Huesped limpiar = new Huesped();
                limpiar.BorrarCampos(this, groupBox1);
                //cbxTipoIdentificacion.Items.Clear();
                //cbxTipoIdentificacion.SelectedIndex = 0;
                rbtnSexoFemenino.Checked  = false;
                rbtnSexoMasculino.Checked = false;
                rbtnEsCompania.Checked    = false;
                rbtnNoCompania.Checked    = false;
            }
            else
            {
                MessageBox.Show("No se pudo guardar el huesped", "Fallo!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void BtnGuardar_Click(object sender, EventArgs e)
        {
            if (editar == false)
            {
                if (this.txtPrimerNombre.Text == string.Empty || this.txtPrimerApellido.Text == string.Empty)
                {
                    ErrorDatosFaltantes.confirmacionForm("ERROR");
                }
                else
                {
                    Huesped pHuesped = new Huesped();
                    pHuesped.PrimerNombre    = txtPrimerNombre.Text.Trim();
                    pHuesped.SegundoNombre   = txtSegundoNombre.Text.Trim();
                    pHuesped.PrimerApellido  = txtPrimerApellido.Text.Trim();
                    pHuesped.SegundoApellido = txtSegundoApellido.Text.Trim();
                    pHuesped.Compania        = cbxCompania.Text.Trim();
                    pHuesped.NombreCompania  = txtNombreCompania.Text.Trim();
                    pHuesped.TipoDocumento   = cbxTipoIdentificacion.Text.Trim();
                    pHuesped.NumDocumento    = txtIdentificacion.Text.Trim();
                    pHuesped.Sexo            = cbxSexo.Text.Trim();
                    pHuesped.Telefono        = txtTelefono.Text.Trim();
                    pHuesped.Direccion       = txtDireccion.Text.Trim();
                    pHuesped.Ciudad          = txtCiudad.Text.Trim();
                    pHuesped.Provincia       = txtProvincia.Text.Trim();
                    pHuesped.Pais            = txtPaisNatal.Text.Trim();
                    pHuesped.Correo          = txtCorreo.Text.Trim();

                    int resultado = HuespedD.Agregar(pHuesped);
                    if (resultado > 0)
                    {
                        FrmCorrecto.confirmacionForm("AGREGADO");
                        txtPrimerNombre.Text                = "";
                        txtSegundoNombre.Text               = "";
                        txtPrimerApellido.Text              = "";
                        txtSegundoApellido.Text             = "";
                        txtNombreCompania.Text              = "";
                        cbxCompania.SelectedIndex           = -1;
                        cbxTipoIdentificacion.SelectedIndex = -1;
                        cbxSexo.SelectedIndex               = -1;
                        txtTelefono.Text  = "";
                        txtDireccion.Text = "";
                        txtCiudad.Text    = "";
                        txtProvincia.Text = "";
                        txtPaisNatal.Text = "";
                        txtCorreo.Text    = "";
                        //dgvclie.DataSource = null;
                        //dgvHuespedes.DataSource = obj.VistaTabla();
                        Huesped limpiar = new Huesped();
                        //limpiar.BorrarCampos(this, groupBox1);
                        //cbxTipoIdentificacion.Items.Clear();
                        //cbxTipoIdentificacion.SelectedIndex = 0;
                    }
                    else
                    {
                        FrmSeguroCerrar.confirmacionForm("ERROR");
                    }
                }
            }

            if (editar == true)
            {
                try
                {
                    string          MyConnection2 = "server=localhost; database=hostal; Uid=root; pwd=root";
                    string          Query         = "update hostal.huesped set PrimerNombre='" + this.txtPrimerNombre.Text + "',SegundoNombre='" + this.txtSegundoNombre.Text + "',PrimerApellido='" + this.txtPrimerApellido.Text + "',SegundoApellido='" + this.txtSegundoApellido.Text + "' where IdHuesped='" + this.txtIdHuesped.Text + "';";
                    MySqlConnection MyConn2       = new MySqlConnection(MyConnection2);
                    MySqlCommand    MyCommand2    = new MySqlCommand(Query, MyConn2);
                    MySqlDataReader MyReader2;
                    MyConn2.Open();
                    MyReader2 = MyCommand2.ExecuteReader();
                    MessageBox.Show("El cliente ha sido modificado.");
                    Huesped limpiar = new Huesped();
                    //limpiar.BorrarCampos(this, groupbox1);
                    //cbxTipoIdentificacion.Items.Clear();
                    //cbxTipoIdentificacion.SelectedIndex = 0;
                    while (MyReader2.Read())
                    {
                    }
                    MyConn2.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }