C# ASP.NET Project Idea

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2007
Posts: 53
Reputation: dotNetDummi is an unknown quantity at this point 
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: C# ASP.NET Project Idea

 
0
  #11
Nov 13th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 645
Reputation: binoj_daniel is an unknown quantity at this point 
Solved Threads: 17
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: C# ASP.NET Project Idea

 
0
  #12
Nov 13th, 2007
You can check it against the Database, if it already exists then call the same routine to generate next randomn no.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 53
Reputation: dotNetDummi is an unknown quantity at this point 
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: C# ASP.NET Project Idea

 
0
  #13
Nov 13th, 2007
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 ...
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 645
Reputation: binoj_daniel is an unknown quantity at this point 
Solved Threads: 17
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: C# ASP.NET Project Idea

 
0
  #14
Nov 14th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 645
Reputation: binoj_daniel is an unknown quantity at this point 
Solved Threads: 17
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: C# ASP.NET Project Idea

 
0
  #15
Nov 14th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 53
Reputation: dotNetDummi is an unknown quantity at this point 
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: C# ASP.NET Project Idea

 
0
  #16
Nov 14th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 645
Reputation: binoj_daniel is an unknown quantity at this point 
Solved Threads: 17
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: C# ASP.NET Project Idea

 
0
  #17
Nov 14th, 2007
Switch is faster than using "if". Also i think you are in the right direction with the login.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 645
Reputation: binoj_daniel is an unknown quantity at this point 
Solved Threads: 17
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: C# ASP.NET Project Idea

 
0
  #18
Nov 14th, 2007
Let me know how it goes.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 53
Reputation: dotNetDummi is an unknown quantity at this point 
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: C# ASP.NET Project Idea

 
0
  #19
Nov 14th, 2007
Thanks for your help... =)
I will keep you update... Hopefully, I don't need to trouble you so much anymore... =)
Serene Joey
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 53
Reputation: dotNetDummi is an unknown quantity at this point 
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: C# ASP.NET Project Idea

 
0
  #20
Nov 15th, 2007
Hi, I'm working on Switch right now.
I saw switch statements online.
  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...

  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. }
Serene Joey
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC