Пример #1
0
        /// <summary>
        /// Проверка на наличие в БД записей с Адресом и Номером Телефона, если записей нет - добавление в БД данных записей.
        /// </summary>
        private async Task Check_Address_and_Phone()
        {
            List <Constants> lConstants = await oConstantsRepository.Select_Constants_Async("select * from constants where name = 'Address' or name = 'Phone_Number' or name = 'e_mail_address' or name = 'e_mail_pass'");

            bool Address        = true;
            bool Phone_Number   = true;
            bool e_mail_address = true;
            bool e_mail_pass    = true;

            foreach (var c in lConstants)
            {
                if (c.name == "Address")
                {
                    Address = false;
                }

                if (c.name == "Phone_Number")
                {
                    Phone_Number = false;
                }

                if (c.name == "e_mail_address")
                {
                    e_mail_address = false;
                }

                if (c.name == "e_mail_pass")
                {
                    e_mail_pass = false;
                }
            }

            if (Address)
            {
                await oConstantsRepository.Insert_Constants_Async(new Constants("Address", "Value"));
            }

            if (Phone_Number)
            {
                await oConstantsRepository.Insert_Constants_Async(new Constants("Phone_Number", "Phone_Number"));
            }

            if (e_mail_address)
            {
                await oConstantsRepository.Insert_Constants_Async(new Constants("e_mail_address", "e_mail"));
            }

            if (e_mail_pass)
            {
                await oConstantsRepository.Insert_Constants_Async(new Constants("e_mail_pass", "pass"));
            }
        }
Пример #2
0
        /// <summary>
        /// Метод сортировки адресов по мере удаленности и построения маршрута
        /// </summary>
        /// <returns></returns>
        private async Task Sort_Addresses()
        {
            List <Constants> start_list = await oConstantsRepository.Select_Constants_Async("select value from Constants where name=\'Address\'");

            Start_address = start_list.First().value.ToString();

            needded_addresses.Add(Start_address);
            needded_adr_copy.Add(Start_address);
            sorted_addresses.Add(Start_address);

            List <GMapRoute> routes_list = new List <GMapRoute>();

            LOrders = await oOrdersRepository.Select_All_Orders_Async();

            #region выборка всех нужных адресов из БД

            foreach (var c in LOrders)
            {
                if (c.status == "Готовится к отправке")
                {
                    needded_addresses.Add(c.address.ToString());
                    needded_adr_copy.Add(c.address.ToString());
                }
            }

            #endregion

            string Close_position = needded_addresses[0].ToString();

            #region Сортировка адресов по мере удаленности от адреса компании

            for (int i = 0; i < needded_addresses.Count - 1; i++)
            {
                double        min_Dist             = 1000000.0;
                string        Start_position       = Close_position;
                int           closest_id           = 1;
                string        Closest_Adr          = "";
                List <double> Start_position_point = m.Geocoding(Start_position);
                sorted_points.Add(new GMap.NET.PointLatLng(Start_position_point[0], Start_position_point[1]));


                for (int j = closest_id; j < needded_adr_copy.Count; j++)
                {
                    if (needded_adr_copy[j] != Start_position)
                    {
                        double        Distance   = 0.0;
                        List <double> adr_latlng = m.Geocoding(needded_adr_copy[j].ToString());
                        Distance = gmap_routes.MapProvider.Projection.GetDistance(new GMap.NET.PointLatLng(Start_position_point[0], Start_position_point[1]), new GMap.NET.PointLatLng(adr_latlng[0], adr_latlng[1]));

                        if (Distance < min_Dist)
                        {
                            min_Dist    = Distance;
                            Closest_Adr = needded_adr_copy[j].ToString();
                        }
                    }
                }
                sorted_addresses.Add(Closest_Adr.ToString());
                List <double> closest_address_points = m.Geocoding(Closest_Adr.ToString());
                sorted_points.Add(new GMap.NET.PointLatLng(closest_address_points[0], closest_address_points[1]));
                needded_adr_copy.Remove(Closest_Adr);
                Close_position = Closest_Adr;
            }

            #endregion

            GMap.NET.RoutingProvider rp = gmap_routes.MapProvider as GMap.NET.RoutingProvider;
            if (rp == null)
            {
                rp = GMapProviders.OpenStreetMap;
            }
            GMap.NET.MapRoute route;

            #region построение маршрута по отсортированным адресам

            for (int i = 0; i < sorted_addresses.Count - 1; i++)
            {
                List <double> first = m.Geocoding(sorted_addresses[i]);
                List <double> last  = m.Geocoding(sorted_addresses[i + 1]);
                route = rp.GetRoute(new GMap.NET.PointLatLng(first[0], first[1]), new GMap.NET.PointLatLng(last[0], last[1]), false, false, (int)gmap_routes.Zoom);
                if (route != null)
                {
                    GMapRoute mRoute = new GMapRoute(route.Points);
                    {
                        mRoute.ZIndex = -1;
                    }
                    routes_list.Add(mRoute);
                }
            }

            foreach (var l in routes_list)
            {
                gmap_routes.Markers.Add(l);
                l.RegenerateShape(gmap_routes);
            }

            #endregion
        }
Пример #3
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 файл");
            }
        }