コード例 #1
0
ファイル: CheckOut.aspx.cs プロジェクト: donor/Projects
        public void PrintWebControl(Control ControlToPrint)
        {
            StringWriter stringWrite = new StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
            if (ControlToPrint is WebControl)
            {
                Unit w = new Unit(100, UnitType.Percentage);
                ((WebControl)ControlToPrint).Width = w;

            }

            Page pg = new Page();

            pg.EnableEventValidation = false;
            HtmlForm frm = new HtmlForm();
            pg.Controls.Add(frm);
            frm.Attributes.Add("runat", "server");
            frm.Controls.Add(ControlToPrint);
            pg.DesignerInitialize();
            pg.RenderControl(htmlWrite);

            string strHTML = stringWrite.ToString();
            string wstawka = Server.MapPath("~").ToString();
            string path = String.Format("{0}\\Images\\Rezerwacje\\{1}.gif", Server.MapPath("~"), Session["ZamowienieId"]);

            //korzystanie z biblioteki websiteScreenshote

            WebsitesScreenshot.WebsitesScreenshot _Obj = new WebsitesScreenshot.WebsitesScreenshot();
            WebsitesScreenshot.WebsitesScreenshot.Result _Result = _Obj.CaptureHTML(htmlToImage(strHTML, zmianaAdresu(wstawka)));

            if (_Result == WebsitesScreenshot.WebsitesScreenshot.Result.Captured)
            {
                _Obj.ImageFormat = WebsitesScreenshot.WebsitesScreenshot.ImageFormats.GIF;
                _Obj.SaveImage(path);
            }
            _Obj.Dispose();

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(strHTML);
            Session[Cart.Ident] = null;
            HttpContext.Current.Response.Write("<script>window.print();</script>");
            HttpContext.Current.Response.End();

            Response.Redirect("~/ListaImprez.aspx");
        }
コード例 #2
0
ファイル: CheckOut.aspx.cs プロジェクト: donor/Projects
        protected void btnWysliMail_Click(object sender, EventArgs e)
        {
            UkryjKontrolkeWListView("SelectButton");
            btnAkceptuj.Visible = false;
            btnWysliMail.Visible = false;
            Label1.Visible = false;

            string path = String.Format("{0}\\Images\\Rezerwacje\\{1}.gif", Server.MapPath("~"), Session["ZamowienieId"]);

            //----------------------wstawka----------------------------------- --------------------
            btnAkceptuj.Visible = false;

            Session["ctrl"] = Panel1;
            Control ctrl = (Control)Session["ctrl"];

            StringWriter stringWrite = new StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
            if (ctrl is WebControl)
            {
                Unit w = new Unit(100, UnitType.Percentage);
                ((WebControl)ctrl).Width = w;

            }

            Page pg = new Page();

            pg.EnableEventValidation = false;
            HtmlForm frm = new HtmlForm();
            pg.Controls.Add(frm);
            frm.Attributes.Add("runat", "server");
            frm.Controls.Add(ctrl);
            pg.DesignerInitialize();
            pg.RenderControl(htmlWrite);

            string strHTML = stringWrite.ToString();
            string wstawka = Server.MapPath("~").ToString();

            //korzystanie z biblioteki websiteScreenshote

            WebsitesScreenshot.WebsitesScreenshot _Obj = new WebsitesScreenshot.WebsitesScreenshot();
            WebsitesScreenshot.WebsitesScreenshot.Result _Result = _Obj.CaptureHTML(htmlToImage(strHTML, zmianaAdresu(wstawka)));

            if (_Result == WebsitesScreenshot.WebsitesScreenshot.Result.Captured)
            {
                _Obj.ImageFormat = WebsitesScreenshot.WebsitesScreenshot.ImageFormats.GIF;
                _Obj.SaveImage(path);
            }
            _Obj.Dispose();

            //----------------------wstawka----------------------------------- -----------------------------------------------

            StringBuilder emailMessage = new StringBuilder();
            emailMessage.Append("Przesyłamy twoje Rezerwacje w załączniku.");
            emailMessage.Append("<br />");
            emailMessage.Append("Wydrukuj plik gif, aby okazać go przy wejściu na impreze");

            MailMessage email = new MailMessage();
            email.From = new MailAddress("*****@*****.**");
            email.To.Add(new MailAddress(tdEmail.InnerText));
            email.Subject = "Twoje rezerwacje";
            email.Body = emailMessage.ToString();
            email.IsBodyHtml = true;
            email.Attachments.Add(new System.Net.Mail.Attachment(path));

            SmtpClient client = new SmtpClient();

            try
            {
                client.Send(email);

            }
            catch (Exception ex)
            {

            }
            finally
            {
                Session[Cart.Ident] = null;
                Session[Cart.ZamowienieId] = null;
                Session[Potwierdzenie] = 1;
                Response.Redirect("~/RezerwacjeWyslane.aspx");

            }
        }