943,845 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 6453
  • C# RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Nov 13th, 2007
0

Re: C# ASP.NET Project Idea

Hi and thanks for your reply,

I found the method of generating numbers. It's working... But how can I improve it so that the code are not repeated as v_code is my primary key in my database.

the method is as follows:

//Generate v_code
private String generateVCode()
{
char[] normalChars = "qwertyuiopasdfghjklzxcvbnm1234567890".ToCharArray();

string code = string.Empty;

for (int i = 0; i < 20; i++)
{
char n = ' ';

n = normalChars[GetRandomNumber(normalChars.Length - 1)];

if (i % 2 == 0)
code += n.ToString().ToUpper();

else
code += n;
}
return code;
}

//Get Random Number
public static int GetRandomNumber(int maxvalue)
{
System.Security.Cryptography.RandomNumberGenerator random =

System.Security.Cryptography.RandomNumberGenerator.Create();

byte[] r = new byte[1];

random.GetBytes(r);

double val = (double)r[0] / byte.MaxValue;

int i = (int)Math.Round(val * maxvalue, 0);

return i;
}


Thank you in advance.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
dotNetDummi is offline Offline
53 posts
since Nov 2007
Nov 13th, 2007
0

Re: C# ASP.NET Project Idea

You can check it against the Database, if it already exists then call the same routine to generate next randomn no.
Reputation Points: 25
Solved Threads: 18
Practically a Master Poster
binoj_daniel is offline Offline
645 posts
since Dec 2006
Nov 13th, 2007
0

Re: C# ASP.NET Project Idea

Cool, I understand already. Thanks..
Erm, Now I have an error with my email.

I have 2 recipents, both vercode and apid in the database are different.

however, both the recipents receive the same vercode. the first recipents receive the second recipent's ver_code(different from database).

String body = "<html><body>Hi, <br><br>&nbsp;&nbsp;&nbsp;
"<br>&nbsp;&nbsp;&nbsp;<a href='<link>/'> VDAS </a> <br>&nbsp;&nbsp;&nbsp;Your Verification code is : <b>";

String footer = "</b><br>&nbsp;&nbsp;&nbsp;Thank You!" +
"<br><br>Regards, <br>Team</body></html>";

VerCode vc = new VerCode();

if (!txtEmail1.Text.Equals(""))
{
String v_code = generateVCode();
vc = new VerCode(v_code,"1",projectID);
VerCodeDAO.addVCode(vc);

msgMail.Body = body + v_code + footer;

MailAddress to1 = new MailAddress(txtEmail1.Text);

if (!txtWatcherEmail1.Text.Equals(""))
{
MailAddress cc1 = new MailAddress(txtWatcherEmail1.Text);
msgMail.CC.Add(cc1);
}
msgMail.To.Add(to1);


}

if (!txtEmail2.Text.Equals(""))
{
String v_code = generateVCode();
vc = new VerCode(v_code, "2", projectID);
VerCodeDAO.addVCode(vc);

MailAddress to2 = new MailAddress(txtEmail2.Text);

if (!txtWatcherEmail2.Text.Equals(""))
{
MailAddress cc2 = new MailAddress(txtWatcherEmail2.Text);
msgMail.CC.Add(cc2);
}
msgMail.To.Add(to2);
msgMail.Body = body + v_code + footer;

}

smtp.Send(msgMail);

I tried and put smtp.Send(msgMail); into each if statement but it's worst.

I apologise for troubling you but please advice. Thanks a Million. By the way, I find that it's not good to use if statements for checking of each txtbox (null or not) because I've 5 textboxes.

Other than using switch is there any methods for me to use? I thought of using for loop. is it possible. if so, can you please give me some hints/tips on the coding ...
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
dotNetDummi is offline Offline
53 posts
since Nov 2007
Nov 14th, 2007
0

Re: C# ASP.NET Project Idea

First debug and see what values are you getting for String v_code = generateVCode(); for each each call.
Then try using diff. mail objects to send mails to diff. people. In the above example you are trying to send the same mail to diff. user.
Reputation Points: 25
Solved Threads: 18
Practically a Master Poster
binoj_daniel is offline Offline
645 posts
since Dec 2006
Nov 14th, 2007
0

Re: C# ASP.NET Project Idea

ok, I got the problem,
In the database you might be getting diff. verification code but when you send in email it is coming same, right?
And the reason is because you are using the same mail object and same v_code variable. You have to use diff. mailobject instances for diff. values.
Reputation Points: 25
Solved Threads: 18
Practically a Master Poster
binoj_daniel is offline Offline
645 posts
since Dec 2006
Nov 14th, 2007
0

Re: C# ASP.NET Project Idea

Cool. I got it already. It's working perfectly. Thanks man~
So now I can use the v_code, from here it's similar with login right?

get the v_code from the textbox, check who is the user or valid v_code then show the output?
am i right?

by the way, erm, there's no other options then if-else statements/switch??

sorry.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
dotNetDummi is offline Offline
53 posts
since Nov 2007
Nov 14th, 2007
0

Re: C# ASP.NET Project Idea

Switch is faster than using "if". Also i think you are in the right direction with the login.
Reputation Points: 25
Solved Threads: 18
Practically a Master Poster
binoj_daniel is offline Offline
645 posts
since Dec 2006
Nov 14th, 2007
0

Re: C# ASP.NET Project Idea

Let me know how it goes.
Reputation Points: 25
Solved Threads: 18
Practically a Master Poster
binoj_daniel is offline Offline
645 posts
since Dec 2006
Nov 14th, 2007
0

Re: C# ASP.NET Project Idea

Thanks for your help... =)
I will keep you update... Hopefully, I don't need to trouble you so much anymore... =)
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
dotNetDummi is offline Offline
53 posts
since Nov 2007
Nov 15th, 2007
0

Re: C# ASP.NET Project Idea

Hi, I'm working on Switch right now.
I saw switch statements online.
C# Syntax (Toggle Plain Text)
  1. Switch (variable)
  2. {
  3. case 1: //do something
  4. case 2: //do something else
  5. break;
  6. }

but I don't know what variable I need for my case. Er can you please help?
I'm trying to use switch instead of if-else...

C# Syntax (Toggle Plain Text)
  1. if (!txtEmail1.Text.Equals(""))
  2. {
  3. msgMail1.From = new MailAddress(txtPCEmail.Text);
  4. if (!txtBackupEmail.Text.Equals(""))
  5. {
  6. msgMail1.CC.Add(new MailAddress(txtBackupEmail.Text));
  7. }
  8.  
  9. msgMail1.Subject = "TEST EMAIL for VR Documents (EndPack) - " + projectID;
  10.  
  11. msgMail1.IsBodyHtml = true;
  12.  
  13. String v_code = generateVCode();
  14. vc = new VerCode(v_code,"1",projectID);
  15. VerCodeDAO.addVCode(vc);
  16.  
  17. msgMail1.Body = body + v_code + footer;
  18.  
  19. MailAddress to1 = new MailAddress(txtEmail1.Text);
  20.  
  21. if (!txtWatcherEmail1.Text.Equals(""))
  22. {
  23. MailAddress cc1 = new MailAddress(txtWatcherEmail1.Text);
  24. msgMail1.CC.Add(cc1);
  25. }
  26. msgMail1.To.Add(to1);
  27.  
  28.  
  29. }
  30.  
  31. if (!txtEmail2.Text.Equals(""))
  32. {
  33. msgMail2.From = new MailAddress(txtPCEmail.Text);
  34. if (!txtBackupEmail.Text.Equals(""))
  35. {
  36. msgMail2.CC.Add(new MailAddress(txtBackupEmail.Text));
  37. }
  38.  
  39. msgMail2.Subject = "TEST EMAIL for VR Documents (EndPack) - " + projectID;
  40.  
  41. msgMail2.IsBodyHtml = true;
  42.  
  43. String v_code = generateVCode();
  44. vc = new VerCode(v_code, "2", projectID);
  45. VerCodeDAO.addVCode(vc);
  46.  
  47. MailAddress to2 = new MailAddress(txtEmail2.Text);
  48.  
  49. if (!txtWatcherEmail2.Text.Equals(""))
  50. {
  51. MailAddress cc2 = new MailAddress(txtWatcherEmail2.Text);
  52. msgMail2.CC.Add(cc2);
  53. }
  54. msgMail2.To.Add(to2);
  55. msgMail2.Body = body + v_code + footer;
  56.  
  57. }
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
dotNetDummi is offline Offline
53 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: i have a project in my hand please help me to complete that project
Next Thread in C# Forum Timeline: Drawing circles and connecting them





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC