Ejemplo n.º 1
0
        /// <summary>
        /// Обновление listview с Клиентами. Каждому клиенту ставится в соответствие его бонусная карта
        /// </summary>
        /// <returns></returns>
        private async Task Update_ListView_Clients()
        {
            List <Client_Card> lClient_Card = new List <Client_Card>();

            List <Clients> lClients = await oClientsRepository.Select_All_Clients_Async();

            foreach (var c in lClients)
            {
                Client_Card client_card = new Client_Card();

                client_card.client = c;
                client_card.card   = await conn.GetAsync <Cards>(c.cards_id);

                lClient_Card.Add(client_card);
            }

            listview_Clients.ItemsSource = lClient_Card;
        }
Ejemplo n.º 2
0
        /// Обновление содержимого ListView
        private async Task Update_ListView()
        {
            List <Clients_Cards> clientcard = new List <Clients_Cards>();

            List <Clients> result = await oClientsRepository.Select_All_Clients_Async();

            foreach (Clients client in result)
            {
                Clients_Cards cc = new Clients_Cards();
                cc.client = client;
                cc.card   = await conn.GetAsync <Cards>(client.cards_id);

                if (client.referer_id != -1)
                {
                    cc.referer = await conn.GetAsync <Clients>(client.referer_id);
                }

                clientcard.Add(cc);
            }

            listview_Clients_Cards.ItemsSource = clientcard;

            Clear_Controls();
        }
Ejemplo n.º 3
0
        private async Task Update_ListBox_View()
        {
            List <ClientCard> clientcard = new List <ClientCard>();

            List <Clients> result = await oClientsRepository.Select_All_Clients_Async();

            SQLite.SQLiteAsyncConnection conn = oDBConnection.GetAsyncConnection();

            foreach (Clients client in result)
            {
                ClientCard cc = new ClientCard();
                cc.client = client;
                cc.card   = await conn.GetAsync <Cards>(client.cards_id);

                clientcard.Add(cc);
            }

            listview.ItemsSource = clientcard;
        }
Ejemplo n.º 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 файл");
            }
        }