protected void Page_Load(object sender, EventArgs e) { QuickPMWebsite.DatabaseSettings.UpdateDatabaseConnectionString(HttpContext.Current.Profile, Request); long PropertyId = long.Parse(Request["PropertyId"]); int year = int.Parse(Request["Year"]); int month = int.Parse(Request["Month"]); PrintTenantBilling.url = "http://cmd.quickpm.net" + "/Public/Tenant.aspx"; PDFjet.NET.PDF document = PrintBillings.GetPdf(PropertyId, year, month); string filePathName = Request.PhysicalApplicationPath + "/Billings/" + "Billings.pdf"; document.Save(filePathName); byte[] fileBytes = System.IO.File.ReadAllBytes(filePathName); QuickPM.Period period = new QuickPM.Period(year, month); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=\"#" + PropertyId.ToString() + " " + new QuickPM.Property(PropertyId).Name + " " + period.ToString() + ".pdf\""); Response.AddHeader("Content-Length", fileBytes.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(filePathName); Response.End(); }
protected void ButtonEmail_Click(object sender, EventArgs e) { QuickPM.Tenant tenant = new QuickPM.Tenant(GetTenantId()); string html = "<table id=\"email\" cellspacing=\"0px\" cellpadding=\"10px\">" + @" <tr> <th>Tenant Name/Id</th><th>Email</th><th>Status</th> </tr> "; int year = Int32.Parse(DropDownListYear.SelectedValue); int month = QuickPM.Util.ConvertMonthToInt(DropDownListMonth.SelectedValue); QuickPM.Period period = new QuickPM.Period(year, month); string email = tenant.BillingEmail; string status = ""; if (email.Trim() != "") { PrintTenantBilling.url = "http://cmd.quickpm.net" + "/Public/Tenant.aspx"; PDFjet.NET.PDF document = PrintBillings.GetPdf(tenant.TenantId, year, month); string filePath = Request.PhysicalApplicationPath + "\\App_Data\\tmpbilling.pdf"; document.Save(filePath); System.IO.Stream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open); QuickPM.RemitInfo remitInfo = new QuickPM.RemitInfo(tenant.Property); status = "Sent"; string questions = remitInfo.Email.Trim() != "" ? "\r\nIf you have a question about your billing statement please email " + remitInfo.Email : ""; string message = "Please see the attached pdf for your billing statement.\r\nThis is an automated message, do not respond. " + questions; try { SendEmail.Send(email, period.ToString() + " " + "Billing Statement", message, Request.PhysicalApplicationPath, stream, "BillingStatement.pdf"); } catch (Exception ex) { if (ex is System.Net.Mail.SmtpFailedRecipientException) { status = "Failed to send email"; } else if (ex is System.Net.Mail.SmtpFailedRecipientsException) { status = "Failed to send email"; } else { status = "Unknown error"; } } finally { stream.Close(); System.IO.File.Delete(filePath); } } html += "<tr>"; string billingemail = tenant.BillingEmail.Trim() != "" ? tenant.BillingEmail.Trim() : "No Email"; html += "<td>" + "<a href=" + QuickPMWebsite.AppCode.Link.LinkTo(tenant, this, HttpContext.Current.Profile.IsAnonymous) + ">" + tenant.Name + " (#" + tenant.TenantId + ")" + "</a>" + "</td>" + "<td>" + billingemail + "</td>" + "<td>" + status + "</td>"; html += "</tr>"; html += "</table>"; Session["email"] = html; }
protected void ButtonSubmit_Click(object sender, EventArgs e) { long PropertyId = GetPropertyId(); int year = Int32.Parse(DropDownListYear.SelectedValue); int month = QuickPM.Util.ConvertMonthToInt(DropDownListMonth.SelectedValue); PrintTenantBilling.url = "http://cmd.quickpm.net" + "/Public/Tenant.aspx"; PDFjet.NET.PDF document = PrintBillings.GetPdf(PropertyId, year, month); string filePathName = Request.PhysicalApplicationPath + "/Billings/" + "Billings.pdf"; document.Save(filePathName); byte[] fileBytes = System.IO.File.ReadAllBytes(filePathName); //Response.Redirect("~/Billings/ViewPrint.aspx"); QuickPM.Period period = new QuickPM.Period(year, month); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=\"#" + PropertyId.ToString() + " " + new QuickPM.Property(PropertyId).Name + " " + period.ToString() + ".pdf\""); Response.AddHeader("Content-Length", fileBytes.Length.ToString()); Response.ContentType = "application/octet-stream"; //byte[] byteBuffer = document.GetData().GetBuffer(); //char[] charBuffer = System.Text.Encoding.ASCII.GetChars(byteBuffer); //Response.Write(charBuffer, 0, charBuffer.Length); Response.WriteFile(filePathName); Response.End(); }