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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A simple question

Status
Not open for further replies.

tsisher

Programmer
Sep 14, 2004
36
GB

Hi,

I have a win form where users get registered and can update/modify details as well.
On this form I have certain fields (like email, country, etc.). The important field is email.
Why important? This gets checked against database whether this email address already exists or not.

1) New User : When a new user gets registered, I have a routine which checks back to the database whether email address exists in the user table and if yes I prompt user saying this email address belongs to someother user-
provide some other email address, which is fine for new registration.

2) Existing User: I pull their details from database and show them. Lets assume user has not modify any field and presses the 'Update' Button. And if I call the same routine - this will definitely prompt user even though the user hasn't modify the email address.
That means I am forcing user every time to change their email address.

I want this routine not to check this password if not modified.

Please let me know how to implement this. For existing user what logic I need so that current email of the user should not be checked if not modified . or some other logic

Thanks,
 
You really should split these two sections up. Create a login form and a User Details form.

Remember to take your data and functionality out of your forms and into a separate class. This way multiple forms can use the same information/functionality.

 
Yes- I have already split this functionality. I also have a login form.
Okay- let me explain--
Some one logs in - lets say admin- He can create new users and modify existing users-
For new user - my routine is fine which checks whether new email is already existing in the database- if yes informs user - provide different email address to register since this belong to some other user.

For updating user- I still need to check whether new email address exists(if provided one- lets say admin gets called that user wants to change the email address) in the table or not so I use this routine.
Now the problem is - lets say the admin brought up the details of the user and has not changed anything at all and simply pressed the 'update button' - so this routine gets called and will promp the user that this email address already belongs to the user but its the same user.
So this routine is not smart enough that the email address belongs to the same user so that it should ignore checking.
That's the logic I am looking for.
Hope I made it clear.
Thanks
 
perhaps you could?
Code:
string newEmail = GetNewEmailFromForm();
string oldEmail = GetUsersOldEmail(user);
bool emailHasChanged = (oldEmail.Trim() == newEmail.Trim());
   if (emailHasChanged)
   {
      //do email check 
   }

Age is a consequence of experience
 
sry this line:
Code:
bool emailHasChanged = (oldEmail.Trim() == newEmail.Trim());

should read:
Code:
bool emailHasChanged = (oldEmail.Trim() != newEmail.Trim());

:~/

Age is a consequence of experience
 
When loading the form, keep a copy of the original email address in a private variable. When saving, check for equality of the input (eg. from textbox) and the original email ad. If they are different, do the validation routine for new email ad.

hth [wink]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top