| | |
C# ASP.NET Project Idea
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
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.
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.
You can check it against the Database, if it already exists then call the same routine to generate next randomn no.
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>
"<br> <a href='<link>/'> VDAS </a> <br> Your Verification code is : <b>";
String footer = "</b><br> 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 ...
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>
"<br> <a href='<link>/'> VDAS </a> <br> Your Verification code is : <b>";
String footer = "</b><br> 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 ...
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.
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.
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.
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.
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.
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.
Hi, I'm working on Switch right now.
I saw switch statements online.
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...
I saw switch statements online.
C# Syntax (Toggle Plain Text)
Switch (variable) { case 1: //do something case 2: //do something else break; }
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)
if (!txtEmail1.Text.Equals("")) { msgMail1.From = new MailAddress(txtPCEmail.Text); if (!txtBackupEmail.Text.Equals("")) { msgMail1.CC.Add(new MailAddress(txtBackupEmail.Text)); } msgMail1.Subject = "TEST EMAIL for VR Documents (EndPack) - " + projectID; msgMail1.IsBodyHtml = true; String v_code = generateVCode(); vc = new VerCode(v_code,"1",projectID); VerCodeDAO.addVCode(vc); msgMail1.Body = body + v_code + footer; MailAddress to1 = new MailAddress(txtEmail1.Text); if (!txtWatcherEmail1.Text.Equals("")) { MailAddress cc1 = new MailAddress(txtWatcherEmail1.Text); msgMail1.CC.Add(cc1); } msgMail1.To.Add(to1); } if (!txtEmail2.Text.Equals("")) { msgMail2.From = new MailAddress(txtPCEmail.Text); if (!txtBackupEmail.Text.Equals("")) { msgMail2.CC.Add(new MailAddress(txtBackupEmail.Text)); } msgMail2.Subject = "TEST EMAIL for VR Documents (EndPack) - " + projectID; msgMail2.IsBodyHtml = true; 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); msgMail2.CC.Add(cc2); } msgMail2.To.Add(to2); msgMail2.Body = body + v_code + footer; }
Serene Joey
![]() |
Similar Threads
- ??? ASP.NET vs. Outlook Calendar ??? (ASP.NET)
- ASP.NET project (ASP.NET)
- how can I copy asp.net project from one system and work on it in a different system (ASP.NET)
- i ned asp.net project (ASP.NET)
- I need a ASP.net project (ASP.NET)
- Error creating new ASP.Net project (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: i have a project in my hand please help me to complete that project
- Next Thread: Drawing circles and connecting them
| Thread Tools | Search this Thread |
.net access ado.net algorithm array backup barchart bitmap box broadcast buttons c# check checkbox client clock color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing dynamiccreation encryption enum event excel file form format forms function game gdi+ httpwebrequest image index input install interface java label list listbox mandelbrot math microsystems mouseclick mysql operator password path photoshop picturebox pixelinversion post programming property radians regex remote remoting richtextbox running... serialization server sleep soap socket sql sqlserver stack statistics stream string table text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf write xml





