protected void SubmitButton_Click(object sender, System.EventArgs e) { NotFound.Visible = false; ValidPaymentAmount.Validate(); if (!ValidPaymentAmount.IsValid) { return; } if (Request.Params["InvoiceID"] != null) { int invoiceid = Convert.ToInt32(Request.Params["InvoiceID"]); InvoicesAdapter.SelectCommand.Parameters["@InvoiceID"].Value = invoiceid; InvoicesSet.Clear(); int fillres; //lock (CommonFunctions.Connection) fillres = InvoicesAdapter.Fill(InvoicesSet); if (fillres > 0) { try { InvoicesSet.Tables["Invoices"].Rows[0]["InvoiceDate"] = new DateTime(Convert.ToInt32(InvoiceYear.SelectedValue), Convert.ToInt32(InvoiceMonth.SelectedValue), Convert.ToInt32(InvoiceDay.SelectedValue)); } catch (Exception) { } try { InvoicesSet.Tables["Invoices"].Rows[0]["PaymentDate"] = new DateTime(Convert.ToInt32(PaymentYear.SelectedValue), Convert.ToInt32(PaymentMonth.SelectedValue), Convert.ToInt32(PaymentDay.SelectedValue)); } catch (Exception) { } if ((InvoicesSet.Tables["Invoices"].Rows[0]["InvoiceDate"] is DateTime) && (InvoicesSet.Tables["Invoices"].Rows[0]["PaymentDate"] is DateTime) && ((DateTime)InvoicesSet.Tables["Invoices"].Rows[0]["PaymentDate"] > ((DateTime)InvoicesSet.Tables["Invoices"].Rows[0]["InvoiceDate"]).AddDays(15))) { InvoicesSet.Tables["Invoices"].Rows[0]["InvoiceDate"] = InvoicesSet.Tables["Invoices"].Rows[0]["PaymentDate"]; } try { InvoicesSet.Tables["Invoices"].Rows[0]["PaymentAmount"] = Convert.ToDecimal(PaymentAmount.Text); } catch (Exception) { } try { InvoicesSet.Tables["Invoices"].Rows[0]["PaymentType"] = PaymentType.SelectedValue; } catch (Exception) { } //lock (CommonFunctions.Connection) InvoicesAdapter.Update(InvoicesSet); PropertiesAdapter.SelectCommand.Parameters["@PropertyID"].Value = InvoicesSet.Tables["Invoices"].Rows[0]["PropertyID"]; PropertiesFullSet.Clear(); if ((CommonFunctions.SyncFill(PropertiesAdapter, PropertiesFullSet) > 0) && !(PropertiesFullSet.Tables["Properties"].Rows[0]["Email"] is DBNull)) { string emailbody; emailbody = "A payment was just applied! Thank you for making payment on your property<br />\n" + "Invoice No: " + ((int)InvoicesSet.Tables["Invoices"].Rows[0]["ID"]).ToString() + "<br />\n" + "Payment Amount: $" + ((decimal)InvoicesSet.Tables["Invoices"].Rows[0]["PaymentAmount"]).ToString() + "<br />\n"; SmtpClient smtpclient = new SmtpClient(ConfigurationManager.AppSettings["SMTPServer"], int.Parse(ConfigurationManager.AppSettings["SMTPPort"])); MailMessage message = new MailMessage("noreply@" + CommonFunctions.GetDomainName(), (string)PropertiesFullSet.Tables["Properties"].Rows[0]["Email"]); message.Subject = CommonFunctions.GetSiteAddress() + CommonFunctions.PrepareURL(((string)PropertiesFullSet.Tables["Properties"].Rows[0]["Country"]).Replace(" ", "_").ToLower() + "/" + ((string)PropertiesFullSet.Tables["Properties"].Rows[0]["StateProvince"]).Replace(" ", "_").ToLower() + "/" + ((string)PropertiesFullSet.Tables["Properties"].Rows[0]["City"]).Replace(" ", "_").ToLower() + "/" + ((int)PropertiesFullSet.Tables["Properties"].Rows[0]["ID"]).ToString() + "/default.aspx"); message.Body = emailbody; message.IsBodyHtml = true; message.Body = message.Body.Replace("\r", "").Replace("\n", Environment.NewLine); message.Headers["Content-Type"] = "text/plain; charset = \"iso-8859-1\""; smtpclient.Send(message); } Response.Redirect(backlinkurl); } } }
protected void SendButton_Click(object sender, System.EventArgs e) { EmailRequired.Validate(); bool toall = false; if (!EmailRequired.IsValid) { return; } PropertiesSet.Clear(); if (SendProperty.Checked) { PropertyNumberRequired.Validate(); PropertyNumberValid.Validate(); if (!PropertyNumberRequired.IsValid || !PropertyNumberValid.IsValid) { return; } GetIDsByNumber.SelectCommand.Parameters["@PropertyID"].Value = Convert.ToInt32(PropertyNumber.Text); //lock (CommonFunctions.Connection) GetIDsByNumber.Fill(PropertiesSet); } else if (SendOwner.Checked) { OwnerUsernameRequired.Validate(); OwnerUsernameValid.Validate(); if (!OwnerUsernameRequired.IsValid || !OwnerUsernameValid.IsValid) { return; } GetIDsByUsername.SelectCommand.Parameters["@Username"].Value = OwnerUsername.Text; //lock (CommonFunctions.Connection) GetIDsByUsername.Fill(PropertiesSet); } else if (SendAll.Checked) { toall = true; List <SqlParameter> sparam = new List <SqlParameter>(); ds_owners = BookDBProvider.getDataSet("usp_get_all_owners_proved_properties", sparam); } //lock (CommonFunctions.Connection) if (toall) { if (ds_owners.Tables.Count > 0) { string emails = ""; foreach (DataRow datarow in ds_owners.Tables[0].Rows) { System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"); if ((datarow["Email"] is string) && regex.Match((string)datarow["Email"]).Success) { SmtpClient smtpclient = new SmtpClient("mail.vacations-abroad.com", 25); MailMessage message = new MailMessage("noreply@" + CommonFunctions.GetDomainName(), (string)datarow["Email"]); message.Subject = CommonFunctions.GetSiteAddress() + CommonFunctions.PrepareURL(((string)datarow["Country"]).Replace(" ", "_").ToLower() + "/" + ((string)datarow["StateProvince"]).Replace(" ", "_").ToLower() + "/" + ((string)datarow["City"]).Replace(" ", "_").ToLower() + "/" + ((int)datarow["ID"]).ToString() + "/default.aspx"); message.Body = "Dear " + (string)datarow["FirstName"] + " " + (string)datarow["LastName"] + "!\n\n" + "You received a new message from " + CommonFunctions.GetSiteName() + " administration:\n\n" + EmailBody.Text; message.IsBodyHtml = false; message.Body = message.Body.Replace("\r", "").Replace("\n", Environment.NewLine); message.Headers["Content-Type"] = "text/plain; charset = \"iso-8859-1\""; BookDBProvider.SendEmail((string)datarow["Email"], message.Subject, message.Body); } DataRow newrow = EmailsSet.Tables["Emails"].NewRow(); newrow["PropertyID"] = datarow["ID"]; newrow["DateTime"] = DateTime.Now; newrow["Email"] = EmailBody.Text; newrow["IfCustom"] = true; EmailsSet.Tables["Emails"].Rows.Add(newrow); } EmailsAdapter.Update(EmailsSet); EmailsSent.Text = ds_owners.Tables[0].Rows.Count.ToString() + " e-mails sent"; } else { EmailsSent.Text = "0 e-mails sent"; } //lock (CommonFunctions.Connection) EmailsSent.Visible = true; } else { foreach (DataRow datarow in PropertiesSet.Tables["Properties"].Rows) { System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"); if ((datarow["Email"] is string) && regex.Match((string)datarow["Email"]).Success) { SmtpClient smtpclient = new SmtpClient("mail.vacations-abroad.com", 25); MailMessage message = new MailMessage("noreply@" + CommonFunctions.GetDomainName(), (string)datarow["Email"]); message.Subject = CommonFunctions.GetSiteAddress() + CommonFunctions.PrepareURL(((string)datarow["Country"]).Replace(" ", "_").ToLower() + "/" + ((string)datarow["StateProvince"]).Replace(" ", "_").ToLower() + "/" + ((string)datarow["City"]).Replace(" ", "_").ToLower() + "/" + ((int)datarow["ID"]).ToString() + "/default.aspx"); message.Body = "Dear " + (string)datarow["FirstName"] + " " + (string)datarow["LastName"] + "!\n\n" + "You received a new message from " + CommonFunctions.GetSiteName() + " administration:\n\n" + EmailBody.Text; message.IsBodyHtml = false; message.Body = message.Body.Replace("\r", "").Replace("\n", Environment.NewLine); message.Headers["Content-Type"] = "text/plain; charset = \"iso-8859-1\""; try { smtpclient.Send(message); } catch (Exception ex) { } } DataRow newrow = EmailsSet.Tables["Emails"].NewRow(); newrow["PropertyID"] = datarow["ID"]; newrow["DateTime"] = DateTime.Now; newrow["Email"] = EmailBody.Text; newrow["IfCustom"] = true; EmailsSet.Tables["Emails"].Rows.Add(newrow); } //lock (CommonFunctions.Connection) EmailsAdapter.Update(EmailsSet); EmailsSent.Text = PropertiesSet.Tables["Properties"].Rows.Count.ToString() + " e-mails sent"; EmailsSent.Visible = true; } }