예제 #1
0
        private void SetFlatClassified(FlatDescription flat)
        {
            double maxParticipation = Convert.ToDouble(Max_participation.Text);
            bool   participationFit = false;

            if (maxParticipation == 0)
            {
                participationFit = true;
            }

            if (!participationFit && maxParticipation > flat.Participation)
            {
                participationFit = true;
            }

            if (flat.RoomsCount > 1 && participationFit)
            {
                if (KitchenCB.IsChecked == true && !flat.IsAneks)
                {
                    DistrictClassified(flat);
                }
                else if (KitchenetteCB.IsChecked == true && flat.IsAneks)
                {
                    DistrictClassified(flat);
                }
                else
                {
                    flat.IsClassified = false;
                }
            }
            else
            {
                flat.IsClassified = false;
            }
        }
예제 #2
0
        private async Task CreateAndSend(FlatDescription item)
        {
            mainWindow.Cursor = Cursors.Wait;
            string notiffication = NotificationTB.Text;

            Dispatcher.Invoke(() => { NotificationTB.Text = "Tworzę wniosek"; });

            while (File.Exists(pdfFromDocPath))
            {
                Thread.Sleep(100);
            }
            CreateProposal(item);

            while (!File.Exists(pdfFromDocPath))
            {
                Thread.Sleep(100);
            }
            while (IsFileLocked(pdfFromDocPath))
            {
                Thread.Sleep(100);
            }

            Dispatcher.Invoke(() => { NotificationTB.Text = "Wysyłam wniosek"; });
            item.IsSend = await SendEmail(item);

            NotificationTB.Text = notiffication;
            mainWindow.Cursor   = Cursors.Arrow;
        }
예제 #3
0
        private async Task <bool> SendEmail(FlatDescription flat)
        {
            string subject = "ogłoszenie ";
            string body    = "W załączeniu przesyłam wniosek dot. ogłoszenia nr: ";
            string path    = AppDomain.CurrentDomain.BaseDirectory;
            string zalPath = path + "zalTBS.pdf";
            string pdfPath = zalPath;

            if (flat != null)
            {
                subject += flat.Number;
                body    += flat.Number;
                pdfPath  = pdfFromDocPath;
            }
            MailMessage mail       = new MailMessage();
            Attachment  attachment = new Attachment(pdfPath);

            try
            {
                SmtpClient smtp = new SmtpClient(ServerSmtpTB.Text);

                mail.From = new MailAddress(EmailTB.Text);
                mail.To.Add(RecievEmailTB.Text);
                mail.Subject = subject;
                mail.Body    = body;


                mail.Attachments.Add(attachment);

                smtp.Port        = Convert.ToInt32(SmtpPortTB.Text);
                smtp.Credentials = new NetworkCredential(EmailTB.Text, PasswordTB.Password);
                smtp.EnableSsl   = true;

                await smtp.SendMailAsync(mail);

                if (flat == null)
                {
                    MessageBox.Show("Wysłano wiadomość");
                }

                DisposeMailContent(mail, attachment);
            }
            catch (Exception ex)
            {
                Dispatcher.Invoke(() => { FlatDescriptionTB.Text = ex.ToString(); });
                DisposeMailContent(mail, attachment);
                isEmailSenderError = true;
                return(false);
            }

            return(true);
        }
예제 #4
0
        private void CreateProposal(FlatDescription flat)
        {
            Excel.Application xlApp;
            Excel.Workbook    xlWorkBook;
            Excel.Worksheet   xlWorkSheet;

            xlApp = new Excel.Application();
            xlApp.DisplayAlerts = false;

            string xlmPath    = path + "dane.xlsx";
            string docxPath   = path + "wniosek.docx";
            string docxPath_a = path + "wniosek_a.docx";

            xlWorkBook  = xlApp.Workbooks.Open(xlmPath, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            xlWorkSheet.Cells[1, 1] = flat.Number;
            xlWorkSheet.Cells[2, 1] = flat.AlternationAddress;
            xlWorkSheet.Cells[3, 1] = flat.RoomsCount;
            xlWorkSheet.Cells[4, 1] = flat.FlatArea;

            xlWorkBook.Saved = true;
            xlWorkBook.SaveCopyAs(xlmPath);

            xlWorkBook.Close(null, null, null);
            xlApp.Quit();

            word.Application app = new word.Application();
            app.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
            word.Document doc = new word.Document();

            if (flat.IsAneks)
            {
                doc = app.Documents.Open(docxPath_a);
            }
            else
            {
                doc = app.Documents.Open(docxPath);
            }

            doc.SaveAs2(pdfFromDocPath, word.WdSaveFormat.wdFormatPDF);
            doc.Close();
            app.Quit();
        }
예제 #5
0
        private void DistrictClassified(FlatDescription flat)
        {
            switch (flat.District.ToLower())
            {
            case ("stabłowice"):
                if (StablowicaCB.IsChecked == true)
                {
                    flat.IsClassified = true;
                }
                break;

            case ("leśnica"):
                if (LesnicaCB.IsChecked == true)
                {
                    flat.IsClassified = true;
                }
                break;

            case ("brochów"):
                if (BrochowCB.IsChecked == true)
                {
                    flat.IsClassified = true;
                }
                break;

            case ("psie pole"):
                if (PsiePoleCB.IsChecked == true)
                {
                    flat.IsClassified = true;
                }
                break;

            default:
                if (OtherCB.IsChecked == true)
                {
                    flat.IsClassified = true;
                }
                break;
            }
        }
예제 #6
0
        private async Task GetFlatDescription(FlatDescription flat)
        {
            string result = await GetPageString(flat.Link);

            if (isConnection)
            {
                try
                {
                    result = result.Substring(result.IndexOf("OGŁOSZENIE"));

                    string flatNumber = result.Substring(0, result.IndexOf("</p>"));

                    foreach (var item in flatDescriptionReplacementList)
                    {
                        result     = result.Replace(item, "");
                        flatNumber = flatNumber.Replace(item, "");
                    }

                    flatNumber = flatNumber.Substring(14);

                    string address = result.Substring(result.IndexOf("ul.") + 3);
                    address = address.Trim();
                    address = address.Substring(0, address.IndexOf("we Wrocławiu"));

                    result = result.Substring(result.IndexOf("(") + 1);
                    string district = result.Substring(0, result.IndexOf(")"));
                    district = district.Replace("osiedle", "").Trim();

                    result = result.Substring(result.IndexOf("o powierzchni") + 14);
                    double flatArea = Convert.ToDouble(Regex.Replace(result.Substring(0, result.IndexOf("składający się") - 2), "[^0-9,]", ""));

                    string flat_description = result.Substring(result.IndexOf("składający się z") + 16);
                    flat_description = flat_description.Substring(0, flat_description.IndexOf("Mieszkanie"));

                    result = result.Substring(result.IndexOf("Partycypant wynosi") + 18);
                    result = result.Substring(0, result.IndexOf("zł."));

                    double participation = 0;
                    result = result.Trim();

                    participation = Convert.ToDouble(result);


                    flat_description = flat_description.ToLower();
                    string[] paragraphs = flat_description.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);


                    int           roomsCount    = 0;
                    bool          isAneks       = false;
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.Append("Skład mieszkania:" + Environment.NewLine);
                    foreach (var item in paragraphs)
                    {
                        if (Regex.Matches(item, "przedpok").Count > 0)
                        {
                            string subItem = item.Substring(item.IndexOf("przedpok"));
                            stringBuilder.Append(subItem + Environment.NewLine);
                        }
                        else if (Regex.Matches(item, "pok").Count > 0)
                        {
                            string subItem = item.Substring(item.IndexOf("pok"));
                            stringBuilder.Append(subItem + Environment.NewLine);
                            roomsCount++;
                        }
                        else if (Regex.Matches(item, "kuchni").Count > 0)
                        {
                            string subItem = item.Substring(item.IndexOf("kuchni"));
                            stringBuilder.Append(subItem + Environment.NewLine);
                        }
                        else if (Regex.Matches(item, "łazien").Count > 0)
                        {
                            string subItem = item.Substring(item.IndexOf("łazien"));
                            stringBuilder.Append(subItem + Environment.NewLine);
                        }
                        else if (Regex.Matches(item, "pomieszczen").Count > 0)
                        {
                            string subItem = item.Substring(item.IndexOf("pomieszczen"));
                            stringBuilder.Append(subItem + Environment.NewLine);
                        }

                        if (Regex.Matches(item, "aneksem kuchennym").Count > 0)
                        {
                            isAneks = true;
                        }
                    }


                    flat.FlatDescriptionUpdate(flatNumber, address, roomsCount, flatArea, isAneks, district, stringBuilder.ToString(), participation);
                    SetFlatClassified(flat);
                }
                catch { }
            }
        }