private void CreateMHTML(string zipfile, string tempdir, string destpath) { ExtractArchive(zipfile, tempdir); string filePath = FindFirstHtml(tempdir); if (filePath == null) { throw new IOException("File not present"); } string dir = Path.GetDirectoryName(filePath); TextReader tr = File.OpenText(filePath); mht mhtml = new mht(dir); TextWriter tw = File.CreateText(destpath); string html = tr.ReadToEnd(); tr.Close(); if (html.ToLower().IndexOf("tustena.") < 0) { throw new ExecutionEngineException("Does not contain prefix Tustena.*"); } string mhtmlFile = mhtml.WriteStructure(html); tw.Write(mhtmlFile); tw.Close(); }
private void estPrint_Click(object sender, EventArgs e) { try { if (this.Activity == null || this.Activity.Length == 0 || this.Activity == "-1") { Page.RegisterStartupScript("noprint", "<script>alert('" + Root.rm.GetString("Esttxt46") + "');</script>"); return; } } catch { Page.RegisterStartupScript("noprint", "<script>alert('" + Root.rm.GetString("Esttxt46") + "');</script>"); return; } StreamReader objReader; string template = string.Empty; if (this.EstTemplateFile.SelectedValue.StartsWith("fix_")) { objReader = new StreamReader(Request.PhysicalApplicationPath + Path.DirectorySeparatorChar + "template" + Path.DirectorySeparatorChar + "quote" + Path.DirectorySeparatorChar + this.EstTemplateFile.SelectedItem.Text); template = objReader.ReadToEnd(); objReader.Close(); } else { objReader = new StreamReader(ConfigSettings.DataStoragePath + Path.DirectorySeparatorChar + "template" + Path.DirectorySeparatorChar + this.EstTemplateFile.SelectedValue); template = objReader.ReadToEnd(); objReader.Close(); } objReader = new StreamReader(Request.PhysicalApplicationPath + Path.DirectorySeparatorChar + "template" + Path.DirectorySeparatorChar + Request["LayOut"]); string style = objReader.ReadToEnd(); objReader.Close(); DataRow drquote = DatabaseConnection.CreateDataset("SELECT * FROM CRM_WORKACTIVITY WHERE ID=" + this.Activity).Tables[0].Rows[0]; DataRow drquoteInfo = DatabaseConnection.CreateDataset("SELECT * FROM ESTIMATES WHERE ACTIVITYID=" + this.Activity).Tables[0].Rows[0]; DataRow drquoteCompany; drquoteCompany = DatabaseConnection.CreateDataset("SELECT COMPANYNAME,ADDRESS,CITY,PROVINCE,ZIPCODE FROM TUSTENA_DATA").Tables[0].Rows[0]; template = template.Replace("Tustena.QuoteDate", UC.LTZ.ToLocalTime((DateTime)drquote["ActivityDate"]).ToShortDateString()); template = template.Replace("Tustena.QuoteExpire", UC.LTZ.ToLocalTime((DateTime)drquoteInfo["ExpirationDate"]).ToShortDateString()); template = template.Replace("Tustena.QuoteSubject", drquote["Subject"].ToString()); template = template.Replace("Tustena.Owner", DatabaseConnection.SqlScalar("SELECT ISNULL(NAME,'')+' '+ISNULL(SURNAME,'') FROM ACCOUNT WHERE UID=" + drquote["ownerid"].ToString())); template = template.Replace("Tustena.QuoteNumber", drquoteInfo["number"].ToString()); template = template.Replace("Tustena.MyCompany", drquoteCompany["companyname"].ToString()); template = template.Replace("Tustena.MyAddress", drquoteCompany["address"].ToString()); template = template.Replace("Tustena.MyCity", drquoteCompany["city"].ToString()); template = template.Replace("Tustena.MyProvince", drquoteCompany["province"].ToString()); template = template.Replace("Tustena.MyZipCode", drquoteCompany["zipcode"].ToString()); template = template.Replace("Tustena.Message", drquote["Description"].ToString()); if (drquote["CompanyID"] != DBNull.Value) { DataRow drCompany = DatabaseConnection.CreateDataset("SELECT COMPANYNAME,INVOICINGADDRESS,INVOICINGCITY,INVOICINGSTATEPROVINCE,INVOICINGSTATE,INVOICINGZIPCODE FROM BASE_COMPANIES WHERE ID=" + drquote["CompanyID"].ToString()).Tables[0].Rows[0]; template = template.Replace("Tustena.CompanyName", drCompany["CompanyName"].ToString()); template = template.Replace("Tustena.CompanyAddress", drCompany["InvoicingAddress"].ToString()); template = template.Replace("Tustena.CompanyZipCode", drCompany["InvoicingZIPCode"].ToString()); template = template.Replace("Tustena.CompanyCity", drCompany["InvoicingCity"].ToString()); template = template.Replace("Tustena.CompanyProvince", drCompany["InvoicingStateProvince"].ToString()); if (drquote["ReferrerID"] != DBNull.Value) { DataRow drContact = DatabaseConnection.CreateDataset("SELECT TITLE,NAME,SURNAME FROM BASE_CONTACTS WHERE ID=" + drquote["ReferrerID"].ToString()).Tables[0].Rows[0]; template = template.Replace("Tustena.ContactTitle", drContact["title"].ToString()); template = template.Replace("Tustena.ContactName", drContact["Name"].ToString()); template = template.Replace("Tustena.ContactSurname", drContact["Surname"].ToString()); } } else if (drquote["ReferrerID"] != DBNull.Value) { DataRow drContact = DatabaseConnection.CreateDataset("SELECT TITLE,NAME,SURNAME FROM BASE_CONTACTS WHERE ID=" + drquote["ReferrerID"].ToString()).Tables[0].Rows[0]; template = template.Replace("Tustena.ContactTitle", drContact["title"].ToString()); template = template.Replace("Tustena.ContactName", drContact["Name"].ToString()); template = template.Replace("Tustena.ContactSurname", drContact["Surname"].ToString()); } else { DataRow drlead = DatabaseConnection.CreateDataset("SELECT COMPANYNAME,TITLE,NAME,SURNAME,ADDRESS,CITY,PROVINCE,ZIPCODE,STATE FROM CRM_LEAD WHERE ID=" + drquote["LeadID"].ToString()).Tables[0].Rows[0]; template = template.Replace("Tustena.CompanyName", drlead["CompanyName"].ToString()); template = template.Replace("Tustena.CompanyAddress", drlead["Address"].ToString()); template = template.Replace("Tustena.CompanyZipCode", drlead["ZIPCode"].ToString()); template = template.Replace("Tustena.CompanyCity", drlead["ICity"].ToString()); template = template.Replace("Tustena.CompanyProvince", drlead["Province"].ToString()); template = template.Replace("Tustena.ContactTitle", drlead["title"].ToString()); template = template.Replace("Tustena.ContactName", drlead["Name"].ToString()); template = template.Replace("Tustena.ContactSurname", drlead["Surname"].ToString()); } StringWriterWithEncoding SW = new StringWriterWithEncoding(Encoding.UTF8); HtmlTextWriter hw = new HtmlTextWriter(SW); hw.Write(style); hw.WriteLine("<br> "); ArrayList np = new ArrayList(); np = (ArrayList)Session["newprod"]; RepeaterEstProductForPrint.DataSource = np; RepeaterEstProductForPrint.DataBind(); this.RepeaterEstProductForPrint.RenderControl(hw); template = template.Replace("Tustena.QuoteTable", SW.ToString()); RepeaterEstProductForPrint.Visible = false; if (template.IndexOf("Tustena.Products") > 0) { SW = new StringWriterWithEncoding(Encoding.UTF8); hw = new HtmlTextWriter(SW); ProductSchemaPrint.idQuote = drquoteInfo["id"].ToString(); ProductSchemaPrint.EstCurrency = EstCurrency.SelectedValue.Split('|')[2]; ProductSchemaPrint.EstChange = EstChange.Text; ProductSchemaPrint.FillSchema(); ProductSchemaPrint.RenderControl(hw); template = template.Replace("Tustena.Products", SW.ToString()); DataTable dtimage = ProductSchemaPrint.QuoteProducts(); string[] images = new string[dtimage.Rows.Count + 1]; int imgcount = 0; foreach (DataRow dr in dtimage.Rows) { if (dr["image"] != null) { images[imgcount++] = dr["image"].ToString(); } } images[dtimage.Rows.Count] = "TustenaLogoOS.gif"; mht m = new mht(""); string basePath; basePath = ConfigSettings.DataStoragePath + Path.DirectorySeparatorChar + "catalog" + Path.DirectorySeparatorChar; template = m.InjectImages(template, images, basePath, Request.PhysicalApplicationPath + Path.DirectorySeparatorChar + "images" + Path.DirectorySeparatorChar); ProductSchemaPrint.Visible = false; } Response.AddHeader("Content-Disposition", "attachment; filename=quote.doc"); Response.AddHeader("Expires", "Thu, 01 Dec 1994 16:00:00 GMT"); Response.AddHeader("Pragma", "nocache"); Response.ContentType = "application/octet-stream"; Response.Write(template); Response.End(); }