示例#1
0
        // metodo para filtrar gridview
        private void TxtFiltrar_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                dgvEmpresas.Rows.Clear();
                dgvEmpresas.Refresh();
                //instansear web service con seguridad
                ServiceProcess_Empresa.Process_EmpresaSoapClient auxServiceEmpresa = new ServiceProcess_Empresa.Process_EmpresaSoapClient();
                auxServiceEmpresa.ClientCredentials.UserName.UserName = Cuenta.Usuario_iis;
                auxServiceEmpresa.ClientCredentials.UserName.Password = Cuenta.Clave_iis;
                ServiceProcess_Empresa.Empresa auxEmpresa = new ServiceProcess_Empresa.Empresa();
                //capturar dataset
                DataSet ds = auxServiceEmpresa.TraerEmpresaConClaveSinEntidad_Escritorio(txtFiltrar.Text.ToUpper());
                if ((ds.Tables.Count != 0) && (ds.Tables[0].Rows.Count > 0))
                {
                    //Capturar Tabla
                    DataTable dt = ds.Tables[0];
                    //contar cantidad de empresas
                    int _cantidad_empresas = dt.Rows.Count;
                    //crear array bidimencional
                    string[,] ListaEmpresa = new string[_cantidad_empresas, 2];
                    //Recorrer data table
                    int _fila = 0;
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        //Capturar datos de la fila recorridad en objeto empresa
                        auxEmpresa.Rut_empresa = (String)dt.Rows[i]["Rut_empresa"];
                        auxEmpresa.Nombre      = (String)dt.Rows[i]["Nombre"];
                        auxEmpresa.Giro        = (String)dt.Rows[i]["Giro"];
                        auxEmpresa.Direccion   = (String)dt.Rows[i]["Direccion"];
                        auxEmpresa.Estado      = Convert.ToInt32(dt.Rows[i]["Estado"]);
                        auxEmpresa.Id_comuna   = Convert.ToInt32(dt.Rows[i]["Id_comuna"]);

                        if (auxEmpresa.Estado == 1) // si la empresa esta activa se carga en la lista
                        {
                            // cargar array con datos de fila
                            ListaEmpresa[_fila, 0] = auxEmpresa.Rut_empresa;
                            ListaEmpresa[_fila, 1] = auxEmpresa.Nombre;
                            //agregar lista a gridview
                            dgvEmpresas.Rows.Add(ListaEmpresa[_fila, 0], ListaEmpresa[_fila, 1]);
                            _fila++;
                        }
                    }
                    txtEmpresa.Clear();
                    pbSeleccion.Visible = false;
                }
                else
                {
                    //Mostrar GridView Vacio
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error en metodo de accion TxtFiltrar_KeyUp, Contactese con el Administrador Detalle de Error: " + ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void TxtFiltrarEmpresa_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                dgvEmpresas.Rows.Clear();
                dgvEmpresas.Refresh();
                //instansear web service con seguridad
                ServiceProcess_Empresa.Process_EmpresaSoapClient auxServiceEmpresa = new ServiceProcess_Empresa.Process_EmpresaSoapClient();
                auxServiceEmpresa.ClientCredentials.UserName.UserName = Cuenta.Usuario_iis;
                auxServiceEmpresa.ClientCredentials.UserName.Password = Cuenta.Clave_iis;

                ServiceProcess_Usuario.Process_UsuarioSoapClient auxServiceUsuario = new ServiceProcess_Usuario.Process_UsuarioSoapClient();
                auxServiceUsuario.ClientCredentials.UserName.UserName = Cuenta.Usuario_iis;
                auxServiceUsuario.ClientCredentials.UserName.Password = Cuenta.Clave_iis;

                ServiceProcess_Usuario.Usuario auxUsuario = new ServiceProcess_Usuario.Usuario();
                ServiceProcess_Empresa.Empresa auxEmpresa = new ServiceProcess_Empresa.Empresa();
                //capturar dataset
                DataSet ds = auxServiceEmpresa.TraerEmpresaConClaveSinEntidad_Escritorio(txtFiltrarEmpresa.Text.ToUpper());
                if ((ds.Tables.Count != 0) && (ds.Tables[0].Rows.Count > 0))
                {
                    //Capturar Tabla
                    DataTable dt = ds.Tables[0];
                    //contar cantidad de empresas
                    int _cantidad_empresas = dt.Rows.Count;
                    //crear array bidimencional
                    string[,] ListaEmpresas = new string[_cantidad_empresas, 2];
                    //Recorrer data table
                    int _fila = 0;
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        //Capturar datos de la fila recorridad en objeto empresa
                        auxEmpresa.Rut_empresa = (String)dt.Rows[i]["Rut_empresa"];
                        auxEmpresa.Nombre      = (String)dt.Rows[i]["Nombre"];
                        auxEmpresa.Giro        = (String)dt.Rows[i]["Giro"];
                        auxEmpresa.Direccion   = (String)dt.Rows[i]["Direccion"];
                        auxEmpresa.Estado      = Convert.ToInt32(dt.Rows[i]["Estado"]);
                        auxEmpresa.Id_comuna   = Convert.ToInt32(dt.Rows[i]["Id_comuna"]);

                        //CAPTURAR DATASET
                        DataSet dsU = auxServiceUsuario.TraerUsuarioPorRutPorEmpresaSinEntidad_Escritorio(_rut_usuario, auxEmpresa.Rut_empresa);
                        if ((dsU.Tables.Count != 0) && (dsU.Tables[0].Rows.Count > 0))
                        {
                            //no carga nada al gridview por que ya es usuario  de la empresa
                        }
                        else
                        {
                            //cargar array con datos de fila
                            ListaEmpresas[_fila, 0] = auxEmpresa.Rut_empresa;
                            ListaEmpresas[_fila, 1] = auxEmpresa.Nombre;
                            //agregar lista a gridview
                            dgvEmpresas.Rows.Add(ListaEmpresas[_fila, 0], ListaEmpresas[_fila, 1]);
                            _fila++;
                        }
                    }
                    lblPaso1.Font        = new System.Drawing.Font(lblPaso1.Font, FontStyle.Regular);
                    lblPaso2.Font        = new System.Drawing.Font(lblPaso1.Font, FontStyle.Bold);
                    lblPaso3.Font        = new System.Drawing.Font(lblPaso1.Font, FontStyle.Regular);
                    pbSeleccion1.Visible = true;
                    pbSeleccion2.Visible = false;
                    pbSeleccion3.Visible = false;
                    pbFlecha1.Visible    = true;
                    pbFlecha2.Visible    = false;
                    dgvCargo.Rows.Clear();
                    dgvCargo.Refresh();
                    _rut_empresa = null;
                    _id_cargo    = null;
                }
                else
                {
                    lblPaso1.Font        = new System.Drawing.Font(lblPaso1.Font, FontStyle.Regular);
                    lblPaso2.Font        = new System.Drawing.Font(lblPaso1.Font, FontStyle.Bold);
                    lblPaso3.Font        = new System.Drawing.Font(lblPaso1.Font, FontStyle.Regular);
                    pbSeleccion1.Visible = true;
                    pbSeleccion2.Visible = false;
                    pbSeleccion3.Visible = false;
                    pbFlecha1.Visible    = true;
                    pbFlecha2.Visible    = false;
                    dgvCargo.Rows.Clear();
                    dgvCargo.Refresh();
                    _rut_empresa = null;
                    _id_cargo    = null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error en metodo de accion TxtFiltrarEmpresa_KeyUp, Contactese con el Administrador Detalle de Error: " + ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }