Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data entry question

Status
Not open for further replies.

mellenburg

Programmer
Aug 27, 2001
77
0
0
US
I need help with an approach to the following problem.

I'm designing a travel authorization form. The use can enter 1 or more travelers. I'm assuming a datagrid is the best approach. However, I don't want to write the travel list to the database while the user is entering travelers because there is more information that is needed?

I basically want the datagrid to behave like an Access table in data entry view, where adding information for 1 record automatically shows entry boxes for the next record.

When the final form is submitted, I want to be able to retrieve all the travelers and then write them to the database.

Also, when the user enters the traveler's email address, I need to search for that user in Active Directory and prepopulate the other fields with their personal information.

Has anyone done anything similar to this?
 
Sounds like you want something like the Wizard control so you can step through various sections. You may also want to create the "travelers" controls dynamically so that you can enter x number of them.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
I have written a few Active Directory applications with the C#. I gutted out the code from a previous example, but you can basically iterate through the DirectoryEntry collection to derive the users.

Code:
using System.DirectoryServices;
using System.Runtime.InteropServices;
using System.Configuration;
using System.Diagnostics;

using(DirectoryEntry de = new DirectoryEntry())
			{
														
					de.Path = ConfigurationSettings.AppSettings["DirectoryPath"];                  
					de.Username = ConfigurationSettings.AppSettings["UserName"];
										//Decrypt the password from the config file
										de.Password = "yourpassword";					
					
					Console.WriteLine(de.Name);
					
					/* We can simply iterate through the children collection of the
					Active Directory path specified above */
					foreach(DirectoryEntry obj in de.Children)
					{
												
						userName = obj.Properties["Name"].Value.ToString();
						
						
						/* Do a test of active users, otherwise a COM Error will be thrown
						 * If the PwdLastSet <> 0 Then we can assume that this is an active
						 * user */
						if(obj.Properties["pwdLastSet"].Value != null)
						{
							z = GetInt64FromLargeInteger(obj.Properties["pwdLastSet"].Value);	
							email = obj.Properties["userPrincipalName"].Value.ToString();
							
														//These are the active users
								iuser=(ActiveDs.IADsUser)obj.NativeObject;									
								lastChangedDate = iuser.PasswordLastChanged;
								activeUser = true;

								//Write active user values to a new user collection
							}
 
IT4EVER - have you every written an application that updates Active Directory. I'm trying to write something but when I try to run CommitChanges() I get the following error message:

System.DirectoryServices.DirectoryServicesCOMException (0x80072014): The requested operation did not satisfy one or more constraints associated with the class of the object. (Exception from HRESULT: 0x80072014) at System.DirectoryServices.DirectoryEntry.CommitChanges()

I presume that this is because I'm not updating one or more mandatory fields (i'm only trying to do telephone number) but don't know what these are or how to find out. Can you help?
 
I haven't had any experience updating the Active Directory, but usually HRESULT represents a field that has a null value.

Each organization sets up their Active Directory differently. I would contact the admin of that server or domain to make sure that field is indeed being used.

In the case of date fields, you won't find the dates in Active Directory in a date format. It produces it as a 16-digit number that you have to parse to get a date.

We don't use telephone number here, so if I try to access that property then I get an HRESULT COM error. .NET uses COM to communicate with Active Directory.

You may want to try an if(field != null) comparison first.

 
However in some research I found something that might help you. If an attribute in Active Directory has not been set for a particular user, you might be able to get

Code:
if (user.Properties.Contains("exampleAttribute"))
{
    //Attribute exists update the attribute
    user.Properties["exampleAttribute"].Value = "(555)555-1212";
}
else
{
    //Attribute doesn't exist so add it properties collection
    user.Properties["exampleAttribute"].Add("(555)555-1212");
}
user.CommitChanges();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top