コード例 #1
0
        private void button_SpecialDeal_Window_Click(object sender, RoutedEventArgs e)
        {
            Special_Deal_Window oSpecial_Deal_Window = new Special_Deal_Window();

            oSpecial_Deal_Window.ShowDialog();
            this.Close();
        }
コード例 #2
0
ファイル: PDF_creater.cs プロジェクト: KnYaZuK/Flovers_WPF
        /// <summary>
        /// создание PDF со спецпредложением
        /// </summary>
        /// <param name="path">путь к файлу</param>
        /// <param name="win">родительское окно</param>
        public void Create_PDF_File(string path, Special_Deal_Window win)
        {
            var doc = new Document();

            PdfWriter.GetInstance(doc, new FileStream(path, FileMode.Create));
            doc.Open();

            BaseFont base_font = BaseFont.CreateFont("arialn.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

            iTextSharp.text.Phrase    head   = new Phrase(win.textbox_theme.Text, new iTextSharp.text.Font(base_font, 18, iTextSharp.text.Font.BOLD, new BaseColor(System.Drawing.Color.Red)));
            iTextSharp.text.Paragraph header = new iTextSharp.text.Paragraph(head);
            header.Alignment = Element.ALIGN_CENTER;
            doc.Add(header);

            iTextSharp.text.Phrase    text      = new Phrase(new TextRange(win.textbox_text.Document.ContentStart, win.textbox_text.Document.ContentEnd).Text, new iTextSharp.text.Font(base_font, 14, iTextSharp.text.Font.NORMAL, new BaseColor(System.Drawing.Color.Black)));
            iTextSharp.text.Paragraph main_text = new iTextSharp.text.Paragraph(text);
            doc.Add(main_text);

            for (int i = 0; i < win.added_images.Count; i++)
            {
                iTextSharp.text.Image photo = iTextSharp.text.Image.GetInstance(win.added_images[i].ToString());
                doc.Add(photo);
            }
            doc.Close();
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void button_SpecialDeal_Create_Click(object sender, RoutedEventArgs e)
        {
            SpecialDeals query = null;

            try
            {
                query = (await oSpecialDealsRepository.Select_SpecialDeals_Async("select * from specialdeals where bouquets_id = " + oBouquet.bouquets_id))[0];
            }
            catch
            {
            }

            if (query == null)
            {
                await oSpecialDealsRepository.Insert_SpecialDeals_Async(new SpecialDeals(oBouquet.bouquets_id, (double)numericUD_SpecialDeal_Percent.Value, DateTime.Parse(datepicker.Text)));

                await Update_ListView_SpecialDeals();

                Special_Deal_Window oSpecial_Deal_Window = new Special_Deal_Window();
                oSpecial_Deal_Window.ShowDialog();
                this.Close();
            }
            else
            {
                MessageBox.Show("Спец. предложения для данного букета уже существует.");
            }
        }
コード例 #4
0
        /// <summary>
        /// метод рассылки писем
        /// </summary>
        /// <param name="win">родительское окно</param>
        /// <param name="theme">тема сообщения</param>
        /// <param name="text">текст сообщения</param>
        /// <param name="PDF_path">путь к pdf предложения</param>
        /// <param name="added_images">список изображений для прикреплений</param>
        public async void Send_Messages(Special_Deal_Window win, string theme, System.Windows.Controls.RichTextBox text, string PDF_path, List <object> added_images, ClientsRepository oClients, ConstantsRepository oConstants)
        {
            win.mail_addresses = await oConstants.Select_Constants_Async("select value from Constants where name=\'e_mail_address\'");

            string mail_adr = win.mail_addresses.First().value.ToString();

            win.mail_passwords = await oConstants.Select_Constants_Async("select value from Constants where name=\'e_mail_pass\'");

            string mail_pas = win.mail_passwords.First().value.ToString();

            if (PDF_path != null)
            {
                if (mail_adr != null && mail_pas != null)
                {
                    try
                    {
                        string     smtpHost = "smtp.yandex.ru";
                        SmtpClient client   = new SmtpClient(smtpHost, 25);
                        var        cred     = new NetworkCredential(mail_adr, mail_pas);
                        client.Credentials = cred;
                        client.EnableSsl   = true;

                        string        from    = mail_adr;
                        string        subject = theme;
                        string        to;
                        string        body  = "<html><body><div><div style=\"height:10%; background-color:#6DD4FF; border-radius:10px\"><p style=\"margin-left:20px; color:red\">Внимание! для тех,у кого не поддерживается HTML - снизу письма дубликат в формате PDF</p></div><div style=\"height:300px; border: 1px solid black; border-radius:10px\"><p style=\"margin-left:20px\">" + new TextRange(text.Document.ContentStart, text.Document.ContentEnd).Text.ToString() + "</p>";
                        AlternateView htmlv = AlternateView.CreateAlternateViewFromString(body, null, "text/html");
                        for (int i = 0; i < added_images.Count; i++)
                        {
                            LinkedResource imageResource = new LinkedResource(added_images[i].ToString(), "image/jpg");
                            imageResource.ContentId        = "photo" + i.ToString();
                            imageResource.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
                            htmlv.LinkedResources.Add(imageResource);

                            body += "<img style=\"margin-left:20px\" src=\"cid:" + imageResource.ContentId.ToString() + "\" alt='photo' />";
                        }
                        body += "</div></div></body></html>";
                        Attachment pdfFile = new Attachment(PDF_path);

                        List <Clients> all_clients = await oClients.Select_All_Clients_Async();

                        foreach (var c in all_clients)
                        {
                            to = c.email;
                            MailMessage mes = new MailMessage(from, to, subject, body);
                            mes.IsBodyHtml      = true;
                            mes.SubjectEncoding = Encoding.GetEncoding(1251);
                            mes.BodyEncoding    = Encoding.GetEncoding(1251);
                            mes.AlternateViews.Add(htmlv);
                            mes.Attachments.Add(pdfFile);
                            client.Send(mes);
                        }
                        System.Windows.MessageBox.Show("Рассылка завершена!");
                    }
                    catch
                    {
                        System.Windows.MessageBox.Show("Ваш адреc почты или пароль некорректны!");
                    }
                }
                else
                {
                    System.Windows.MessageBox.Show("Проверьте правильность адреса почты или пароль в окне Констант");
                }
            }
            else
            {
                System.Windows.MessageBox.Show("Сначала необходимо сохранить или загрузить готовый PDF файл");
            }
        }