public void ShowAssistanceInfo(string Name, string EmployeeNO)
{
try
{
string Path = "ruta donde estan las imagenes";
string[] filePaths = Directory.GetFiles(Path, EmployeeNO + "*.jpg");
if (filePaths.Length > 0 )
{
picBox.ImageLocation = filePaths[0].ToString();
}
}
catch (Exception exc)
{
MessageBox.Show(" ERROR!!!! Form=" + this.Name + " , Method = " + System.Reflection.MethodInfo.GetCurrentMethod().Name + ", Error Message = " + exc.Message);
}
}
El codigo anterior se usa para mostrar imagenes en un picturebox de acuerdo a lo que diga en un textbox, se esta usando Active Directory para obtener información de usuarios, lo que se hace es lo siguiente:
Al digitar 1111 debera cargar la imagen del empleado 1111 asi como su info en la zona AD User Info (la imagen esta en una ruta del equipo guardada como el numero del empleado es decir 1111.jpg), al digitar pperez que es el empleado 1111 deberá de igual manera poder verse su info y foto y si se digita Pedro Perez igual!
Solo se ha logrado la parte de la foto cuando se digita el numero de empleado se quiere lograr de las otras 2 formas que se mencionan pero no se ha dado con la solución.
Además cuando se busca un usuario que ya no exista en AD o que esté disable se muestra un message box indicando que el usuario no se encontró, hasta ahi todo bien, pero si la imagen de ese usuario existe en la ruta de imágenes se carga la imagen del mismo aunque su info no se muestre y se haya mostrado el messagebox.
Como se podrían solucionar estos problemas?
PD: De ser necesario alguna otra parte del código para poder brindar algún tipo de ayuda me lo hacen saber, muchas gracias
Este código es el que se tiene para capturar la info de AD y luego mostrarla en el form:
private void ShowUserInfo() /*esto nos va a servir mostrar la info de los usuarios en base a si se busca por username o employeeID
y si no existe en AD simplemente dice que no se encontro*/
{
Cursor.Current = Cursors.Default;
pnlBlock.BringToFront();
pnlBlock.Visible = true;
SearchResult SR = null;
if (txtSearchUser.Text.Trim().IndexOf("0") >= 0)
SR = BusqPorEmployNum(GetDirectorySearcher(), txtSearchUser.Text.Trim());
else
SR = BusqPorUserName(GetDirectorySearcher(), txtSearchUser.Text.Trim());
if (SR != null)
GetUserInfo(SR);
else
MessageBox.Show("User Not Found, Try again!", "Search Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void GetUserInfo(SearchResult SR) // obtiene la info de los usuarios de AD y los carga a los label
{
Cursor.Current = Cursors.Default;
pnlBlock.Visible = false;
if (SR.GetDirectoryEntry().Properties["samaccountname"].Value != null)
lblUsername.Text = "Username : " + SR.GetDirectoryEntry().Properties["samaccountname"].Value.ToString();
if (SR.GetDirectoryEntry().Properties["givenName"].Value != null)
lblName.Text = "First Name : " + SR.GetDirectoryEntry().Properties["givenName"].Value.ToString();
if (SR.GetDirectoryEntry().Properties["initials"].Value != null)
lblMidName.Text = "Middle Name : " + SR.GetDirectoryEntry().Properties["initials"].Value.ToString();
if (SR.GetDirectoryEntry().Properties["sn"].Value != null)
lblLastName.Text = "Last Name : " + SR.GetDirectoryEntry().Properties["sn"].Value.ToString();
if (SR.GetDirectoryEntry().Properties["mail"].Value != null)
lblEmail.Text = "Email ID : " + SR.GetDirectoryEntry().Properties["mail"].Value.ToString();
if (SR.GetDirectoryEntry().Properties["title"].Value != null)
lblTitle.Text = "Title : " + SR.GetDirectoryEntry().Properties["title"].Value.ToString();
if (SR.GetDirectoryEntry().Properties["company"].Value != null)
lblCompany.Text = "Company : " + SR.GetDirectoryEntry().Properties["company"].Value.ToString();
if (SR.GetDirectoryEntry().Properties["l"].Value != null)
lblCity.Text = "City : " + SR.GetDirectoryEntry().Properties["l"].Value.ToString();
if (SR.GetDirectoryEntry().Properties["employeeNumber"].Value != null)
lblEmplNum.Text = "Employee Number : " + SR.GetDirectoryEntry().Properties["employeeNumber"].Value.ToString();
if (SR.GetDirectoryEntry().Properties["co"].Value != null)
lblCountry.Text = "Country : " + SR.GetDirectoryEntry().Properties["co"].Value.ToString();
if (SR.GetDirectoryEntry().Properties["postalCode"].Value != null)
lblPostcod.Text = "Postal Code : " + SR.GetDirectoryEntry().Properties["postalCode"].Value.ToString();
if (SR.GetDirectoryEntry().Properties["telephoneNumber"].Value != null)
lblTelef.Text = "Telephone No. : " + SR.GetDirectoryEntry().Properties["telephoneNumber"].Value.ToString();
if (SR.GetDirectoryEntry().Properties["uidNumber"].Value != null)
lblUid.Text = "Batch Number : " + SR.GetDirectoryEntry().Properties["uidNumber"].Value.ToString();
}
Además en la siguiente imagen que adjunto intento ser lo más detallado posible con respecto a mi duda:
No importa que se introduzca en el buscador (como ejemplífico en la imagen) la imagen siempre debe aparacer porque la imagen se guarda en la carpeta que mencioné al principio de mi duda por el numero de empleado, es decir que si busco a 0001, pperez o Pedro Perez siempre debe aparecer la imagen porque siempre deberé compararla con el numero de empleado de lo que se esté buscando, además me gustaría saber como puedo hacer para evitar que aparezca la imagen de un numero de empleado que no aparezca en AD esto porque ya lo hemos hecho con el código que tenemos y si la imagen existe en la ruta siempre se muestra aunque no exista en AD