Load DropdownList
<asp:DropDownList ID="ddlState" runat="server" CssClass="dropdown"/>
if (!Page.IsPostBack)
{
this.LoadState();
}
private void LoadState()
{
UserBO userBO = new UserBO();
ddlState.DataSource = userBO.GetStateName();
ddlState.DataValueField = "State1";
ddlState.DataTextField = "State1";
ddlState.DataBind();
}
public List<State> GetStateName()
{
using (dbcntx = new FiduciaryKEntities())
{
return dbcntx.States.ToList();
}
}
Load Form Data
if (Request.QueryString["userId"] != null)
{
UserBO userBO = new UserBO();
int userId = int.Parse(Request.QueryString["userId"]);
this.LoadUser(userId);
}
private void LoadUser(int uId)
{
UserBO userBO = new UserBO();
FiduciaryK_User objUser = userBO.GetUserById(uId);
if (objUser != null)
{
ddlTitle.Text = objUser.Title;
txtFirstName.Value = objUser.FirstName;
txtLastName.Value = objUser.LastName;
ddlState.SelectedValue= objUser.State;
}
}
Form
<input type="text" class="validate[required]" value="" id="txtFirstName" runat="server" /><strong>*</strong></li>
<asp:DropDownList ID="ddlState" runat="server" CssClass="dropdown"/>
Load DropDownList
<li class="clearfix">
<label>Title:</label>
<asp:DropDownList ID="ddlTitle" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Mr.</asp:ListItem>
<asp:ListItem>Miss</asp:ListItem>
<asp:ListItem>Mrs.</asp:ListItem>
<asp:ListItem>Ms.</asp:ListItem>
</asp:DropDownList>
</li>
Save
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
userBO = new UserBO();
user.Title = ddlTitle.SelectedItem.Text;
user.FirstName = txtFirstName.Value.Trim();
user.LastName = txtLastName.Value.Trim();
user.State = ddlState.SelectedItem.Text;
user.Email = txtEmail.Value.Trim();
if (!string.IsNullOrEmpty(txtEmail.Value))
{
if (userBO.CheckEmailExist(txtEmail.Value.Trim()) == true)
{
this.lblerror.Text = "Account already exists for this email!";
return;
};
}
if (!string.IsNullOrEmpty(txtReferralCode.Value))
{
user.ReferralId = SaveReferral(txtReferralCode.Value);
}
Guid registercode = Guid.NewGuid();
user.VerificationCode = registercode;
user.IsActive = true;
userBO.SaveUserInfo(user);
this.SendMail(user.ReferralId == null ? 0 : user.ReferralId.Value, registercode, txtUserName.Value.Trim(), txtFirstName.Value.Trim(), txtEmail.Value.Trim());
Response.Redirect("../Account/Login.aspx");
}
catch (Exception ex)
{ }
finally
{ }
}
Edit
protected void btnSubmit_Click(object sender, EventArgs e)
{
UserBO userBO = new UserBO();
try
{
if (Request.QueryString["userId"] !=null)
{
int userId = Convert.ToInt32(Request.QueryString["userId"]);
objUser = new FiduciaryK_User();
objUser = userBO.GetUserById(userId);
objUser.Title = ddlTitle.SelectedValue;
objUser.FirstName = txtFirstName.Value.Trim();
objUser.LastName = txtLastName.Value.Trim();
objUser.Address1 = txtAdd.Value;
objUser.City = txtCity.Value.Trim();
objUser.State = ddlState.SelectedValue;
userBO.SaveUserInfo(objUser);
Session["FirstName"] = txtFirstName.Value.Trim();
}
}
catch (Exception ex)
{
}
public void SaveUserInfo(FiduciaryK_User user)
{
try
{
if (user.Id == 0)
{
dbcntx.FiduciaryK_User.Add(user);
}
dbcntx.SaveChanges();
}
catch (Exception ex)
{ }
finally
{
}
}
public FiduciaryK_User GetUserById(int userid)
{
return dbcntx.FiduciaryK_User.Where(u => u.Id == userid).FirstOrDefault();
}
public Boolean CheckEmailExist(string email)
{
try
{
if (dbcntx.FiduciaryK_User.Count(x => x.Email.Trim() == email) > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}
private void SendMail(int refId, Guid registercode, string userName,string firstName, string emailto)
{
this.SendInternalEmail();
}
private void SendInternalEmail()
{
string to = "adrienne@redhawkwa.com,rick@redhawkwa.com,internalsales@julyservices.com";
string cc = "gsnyder@julyservices.com,mahfuz@julyservices.com";
string subject = "Fiduciaryk – Registration Request";
string name = txtFirstName.Value.Trim() + " " + txtLastName.Value.Trim();
string body = "<style>img{border: none; display:block;}</style><table style='background:#FAFAFA; border: 1px solid #990000; border-top: 30px solid #990000; border-bottom: 30px solid #990000;'><tr><td colspan='3' style='height:20px;'></td></tr><tr><td width='20'> </td><td><img src='https://fiduciaryk.com/Content/images/logo.png' width='387' height='100' alt='FiduciaryK Logo' /></td></tr><tr><td colspan='3' style='height:20px;'></td></tr><tr><td width='20'> </td><td style='font-family:Arial; font-size:14px; line-height:20px; color:#333333;'>Registration Request:</BR>Name: " + name + "</BR>Email: " + txtEmail.Value.Trim() + "</BR>Phone: " + txtPhone.Value.Trim() + "</td><td width='20'> </td></td><tr><td colspan='3' style='height:30px;'></td></tr></table>";
email.SendEmailAsyn(ContactEmails, to, cc, subject, body);
}
Send Mail
public void SendEmailAsyn(string mailFrom, string mailTo,string mailCC, string subject, string body)
{
try
{
if (mailTo.Trim() != "" && mailTo.Trim() != " ")
{
if (isEmail(mailTo))
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.From = new MailAddress(mailFrom);
var mailTos = mailTo.Split(new Char[] { ',', ';' });
foreach (var to in mailTos)
{
if (!String.IsNullOrEmpty(to))
message.To.Add(new MailAddress(to));
}
var mailCCs = mailCC.Split(',');
foreach (var cc in mailCCs)
{
if (!String.IsNullOrEmpty(cc))
message.CC.Add(new MailAddress(cc));
}
message.Subject = subject;
message.Body = body;
message.Priority = System.Net.Mail.MailPriority.Normal;
message.IsBodyHtml = true;
System.Net.Mail.SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = "mail.julyservices.com";
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("dp_smtp", "Dp$123456", "julyservices");
smtpClient.Credentials = SMTPUserInfo;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Send(message);
}
}
}
catch (Exception ex)
{
}
}
public bool isEmail(string inputEmail)
{
var mails = inputEmail.Split(new Char[] { ',', ';' });
//inputEmail = NulltoString(inputEmail);
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex re = new Regex(strRegex);
Boolean isValidMail = false;
foreach (var mail in mails)
{
if (!String.IsNullOrEmpty(mail))
{
if (re.IsMatch(mail))
{
isValidMail = true;
}
else
{
isValidMail = false;
break;
}
}
}
return isValidMail;
}
Download Excel Template
<div class="dwnld-excel">
<asp:LinkButton CssClass="downloadlink" ID="censusFileDlLink" runat="server" OnClick="downloadSampleCensusFile">Download Excel Template</asp:LinkButton>
</div>
protected void downloadSampleCensusFile(object sender, EventArgs e)
{
string fileName = "Census-Spreadsheet.xls";
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
filePath = Server.MapPath("/Documents/" + fileName);
Response.TransmitFile(filePath);
Response.End();
}
****************************************************
<asp:DropDownList ID="ddlState" runat="server" CssClass="dropdown"/>
if (!Page.IsPostBack)
{
this.LoadState();
}
private void LoadState()
{
UserBO userBO = new UserBO();
ddlState.DataSource = userBO.GetStateName();
ddlState.DataValueField = "State1";
ddlState.DataTextField = "State1";
ddlState.DataBind();
}
public List<State> GetStateName()
{
using (dbcntx = new FiduciaryKEntities())
{
return dbcntx.States.ToList();
}
}
Load Form Data
if (Request.QueryString["userId"] != null)
{
UserBO userBO = new UserBO();
int userId = int.Parse(Request.QueryString["userId"]);
this.LoadUser(userId);
}
private void LoadUser(int uId)
{
UserBO userBO = new UserBO();
FiduciaryK_User objUser = userBO.GetUserById(uId);
if (objUser != null)
{
ddlTitle.Text = objUser.Title;
txtFirstName.Value = objUser.FirstName;
txtLastName.Value = objUser.LastName;
ddlState.SelectedValue= objUser.State;
}
}
Form
<input type="text" class="validate[required]" value="" id="txtFirstName" runat="server" /><strong>*</strong></li>
<asp:DropDownList ID="ddlState" runat="server" CssClass="dropdown"/>
Load DropDownList
<li class="clearfix">
<label>Title:</label>
<asp:DropDownList ID="ddlTitle" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Mr.</asp:ListItem>
<asp:ListItem>Miss</asp:ListItem>
<asp:ListItem>Mrs.</asp:ListItem>
<asp:ListItem>Ms.</asp:ListItem>
</asp:DropDownList>
</li>
Save
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
userBO = new UserBO();
user.Title = ddlTitle.SelectedItem.Text;
user.FirstName = txtFirstName.Value.Trim();
user.LastName = txtLastName.Value.Trim();
user.State = ddlState.SelectedItem.Text;
user.Email = txtEmail.Value.Trim();
if (!string.IsNullOrEmpty(txtEmail.Value))
{
if (userBO.CheckEmailExist(txtEmail.Value.Trim()) == true)
{
this.lblerror.Text = "Account already exists for this email!";
return;
};
}
if (!string.IsNullOrEmpty(txtReferralCode.Value))
{
user.ReferralId = SaveReferral(txtReferralCode.Value);
}
Guid registercode = Guid.NewGuid();
user.VerificationCode = registercode;
user.IsActive = true;
userBO.SaveUserInfo(user);
this.SendMail(user.ReferralId == null ? 0 : user.ReferralId.Value, registercode, txtUserName.Value.Trim(), txtFirstName.Value.Trim(), txtEmail.Value.Trim());
Response.Redirect("../Account/Login.aspx");
}
catch (Exception ex)
{ }
finally
{ }
}
Edit
protected void btnSubmit_Click(object sender, EventArgs e)
{
UserBO userBO = new UserBO();
try
{
if (Request.QueryString["userId"] !=null)
{
int userId = Convert.ToInt32(Request.QueryString["userId"]);
objUser = new FiduciaryK_User();
objUser = userBO.GetUserById(userId);
objUser.Title = ddlTitle.SelectedValue;
objUser.FirstName = txtFirstName.Value.Trim();
objUser.LastName = txtLastName.Value.Trim();
objUser.Address1 = txtAdd.Value;
objUser.City = txtCity.Value.Trim();
objUser.State = ddlState.SelectedValue;
userBO.SaveUserInfo(objUser);
Session["FirstName"] = txtFirstName.Value.Trim();
}
}
catch (Exception ex)
{
}
public void SaveUserInfo(FiduciaryK_User user)
{
try
{
if (user.Id == 0)
{
dbcntx.FiduciaryK_User.Add(user);
}
dbcntx.SaveChanges();
}
catch (Exception ex)
{ }
finally
{
}
}
public FiduciaryK_User GetUserById(int userid)
{
return dbcntx.FiduciaryK_User.Where(u => u.Id == userid).FirstOrDefault();
}
public Boolean CheckEmailExist(string email)
{
try
{
if (dbcntx.FiduciaryK_User.Count(x => x.Email.Trim() == email) > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}
private void SendMail(int refId, Guid registercode, string userName,string firstName, string emailto)
{
this.SendInternalEmail();
}
private void SendInternalEmail()
{
string to = "adrienne@redhawkwa.com,rick@redhawkwa.com,internalsales@julyservices.com";
string cc = "gsnyder@julyservices.com,mahfuz@julyservices.com";
string subject = "Fiduciaryk – Registration Request";
string name = txtFirstName.Value.Trim() + " " + txtLastName.Value.Trim();
string body = "<style>img{border: none; display:block;}</style><table style='background:#FAFAFA; border: 1px solid #990000; border-top: 30px solid #990000; border-bottom: 30px solid #990000;'><tr><td colspan='3' style='height:20px;'></td></tr><tr><td width='20'> </td><td><img src='https://fiduciaryk.com/Content/images/logo.png' width='387' height='100' alt='FiduciaryK Logo' /></td></tr><tr><td colspan='3' style='height:20px;'></td></tr><tr><td width='20'> </td><td style='font-family:Arial; font-size:14px; line-height:20px; color:#333333;'>Registration Request:</BR>Name: " + name + "</BR>Email: " + txtEmail.Value.Trim() + "</BR>Phone: " + txtPhone.Value.Trim() + "</td><td width='20'> </td></td><tr><td colspan='3' style='height:30px;'></td></tr></table>";
email.SendEmailAsyn(ContactEmails, to, cc, subject, body);
}
Send Mail
public void SendEmailAsyn(string mailFrom, string mailTo,string mailCC, string subject, string body)
{
try
{
if (mailTo.Trim() != "" && mailTo.Trim() != " ")
{
if (isEmail(mailTo))
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.From = new MailAddress(mailFrom);
var mailTos = mailTo.Split(new Char[] { ',', ';' });
foreach (var to in mailTos)
{
if (!String.IsNullOrEmpty(to))
message.To.Add(new MailAddress(to));
}
var mailCCs = mailCC.Split(',');
foreach (var cc in mailCCs)
{
if (!String.IsNullOrEmpty(cc))
message.CC.Add(new MailAddress(cc));
}
message.Subject = subject;
message.Body = body;
message.Priority = System.Net.Mail.MailPriority.Normal;
message.IsBodyHtml = true;
System.Net.Mail.SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = "mail.julyservices.com";
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("dp_smtp", "Dp$123456", "julyservices");
smtpClient.Credentials = SMTPUserInfo;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Send(message);
}
}
}
catch (Exception ex)
{
}
}
public bool isEmail(string inputEmail)
{
var mails = inputEmail.Split(new Char[] { ',', ';' });
//inputEmail = NulltoString(inputEmail);
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex re = new Regex(strRegex);
Boolean isValidMail = false;
foreach (var mail in mails)
{
if (!String.IsNullOrEmpty(mail))
{
if (re.IsMatch(mail))
{
isValidMail = true;
}
else
{
isValidMail = false;
break;
}
}
}
return isValidMail;
}
Download Excel Template
<div class="dwnld-excel">
<asp:LinkButton CssClass="downloadlink" ID="censusFileDlLink" runat="server" OnClick="downloadSampleCensusFile">Download Excel Template</asp:LinkButton>
</div>
protected void downloadSampleCensusFile(object sender, EventArgs e)
{
string fileName = "Census-Spreadsheet.xls";
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
filePath = Server.MapPath("/Documents/" + fileName);
Response.TransmitFile(filePath);
Response.End();
}
****************************************************
No comments:
Post a Comment