Exemple #1
0
 private void TxtFiltrar_KeyUp(object sender, KeyEventArgs e)
 {
     try
     {
         dgvUnidad.Rows.Clear();
         dgvUnidad.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_Unidad.Process_UnidadSoapClient auxServiceUnidad = new ServiceProcess_Unidad.Process_UnidadSoapClient();
         auxServiceUnidad.ClientCredentials.UserName.UserName = Cuenta.Usuario_iis;
         auxServiceUnidad.ClientCredentials.UserName.Password = Cuenta.Clave_iis;
         ServiceProcess_Empresa.Empresa auxEmpresa = new ServiceProcess_Empresa.Empresa();
         ServiceProcess_Unidad.Unidad   auxUnidad  = new ServiceProcess_Unidad.Unidad();
         //capturar dataset
         DataSet ds = auxServiceUnidad.TraerUnidadConClaveSinEntidad_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_unidades = dt.Rows.Count;
             //crear array bidimencional
             string[,] ListaUnidad = new string[_cantidad_unidades, 6];
             //Recorrer data table
             int _fila = 0;
             for (int i = 0; i < dt.Rows.Count; i++)
             {
                 //Capturar datos de la fila recorridad en objeto empresa
                 auxUnidad.Id_unidad   = Convert.ToInt32(dt.Rows[i]["Id_unidad"]);
                 auxUnidad.Nombre      = (String)dt.Rows[i]["Nombre"];
                 auxUnidad.Descripcion = (String)dt.Rows[i]["Descripcion"];
                 auxUnidad.Estado      = Convert.ToInt32(dt.Rows[i]["Estado"]);
                 auxUnidad.Rut_empresa = (String)dt.Rows[i]["Rut_empresa"];
                 //variables temporales de apoyo
                 string _estado         = string.Empty;
                 string _nombre_empresa = string.Empty;
                 //cargar array con datos de fila
                 ListaUnidad[_fila, 0] = auxUnidad.Id_unidad.ToString();
                 ListaUnidad[_fila, 1] = auxUnidad.Nombre;
                 auxEmpresa            = auxServiceEmpresa.TraerEmpresaConEntidad_Escritorio(auxUnidad.Rut_empresa);
                 ListaUnidad[_fila, 2] = auxEmpresa.Nombre;
                 ListaUnidad[_fila, 3] = auxEmpresa.Rut_empresa;
                 if (auxUnidad.Estado == 0)
                 {
                     _estado = "DESACTIVADO";
                 }
                 else
                 {
                     _estado = "ACTIVADO";
                 }
                 ListaUnidad[_fila, 4] = _estado;
                 ListaUnidad[_fila, 5] = auxUnidad.Descripcion;
                 //agregar lista a gridview
                 dgvUnidad.Rows.Add(ListaUnidad[_fila, 0], ListaUnidad[_fila, 1], ListaUnidad[_fila, 2], ListaUnidad[_fila, 3], ListaUnidad[_fila, 4], ListaUnidad[_fila, 5]);
                 _fila++;
             }
             //vACIAR VARIABLES
             _id_unidad            = null;
             _nombre               = string.Empty;
             _descripcion          = string.Empty;
             _estado               = string.Empty;
             _rut_empresa          = string.Empty;
             pbSeleccion.Visible   = false;
             btnActivar.Visible    = false;
             btnDesactivar.Visible = false;
         }
         else
         {
             //Mostrar GridView Vacio
             //vACIAR VARIABLES
             _id_unidad            = null;
             _nombre               = string.Empty;
             _descripcion          = string.Empty;
             _estado               = string.Empty;
             _rut_empresa          = string.Empty;
             pbSeleccion.Visible   = false;
             btnActivar.Visible    = false;
             btnDesactivar.Visible = false;
         }
     }
     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);
     }
 }