Exemplo n.º 1
0
        public bool TaxNoticeExists(TaxNotice notice)
        {
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["AWSDatabase"].ConnectionString))
            {
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT COUNT(1) FROM TaxNotice WHERE Id = @Id";
                    command.Parameters.AddParameter("@Id", SqlDbType.BigInt, notice.Id);

                    connection.Open();
                    return (int)command.ExecuteScalar() >= 1;
                }
            }
        }
Exemplo n.º 2
0
        public override void Monitor()
        {
            IAuthentifier authentifier = new TaxesAuthentifier(Profile);
            WebClient client = authentifier.GetAuthenticatedClient();

            string redirectPage1 = client.DownloadString(Url);

            Match match = Regex.Match(redirectPage1, "document\\.location\\.replace\\s*\\(\"([^\"]+)\"\\);", RegexOptions.RightToLeft);
            string redirectPage2Url = match.Groups[1].Value;

            client.DownloadString(Domain + redirectPage2Url);

            NameValueCollection values = new NameValueCollection();
            values.Add("templatename", "charpente");
            values.Add("pagedemande", "paiementcertificat1");
            values.Add("numeroscenario", "310");
            values.Add("menu", "");

            string response = Encoding.UTF8.GetString(client.UploadValues(Url2, values));

            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(response);
            
            if (WebUtility.HtmlDecode(response).Contains(NoTaxToPay))
                return;

            HtmlNodeCollection taxesToPay = doc.DocumentNode.SelectNodes("//table[@id='tableaufacturesavisnonpayees1']//tr[@class='cssTableauLigne']");

            ITaxesManager taxManager = new TaxesRepository();

            foreach(HtmlNode taxNode in taxesToPay)
            {
                TaxNotice notice = new TaxNotice()
                {
                    Id = Int64.Parse(taxNode.ChildNodes[1].InnerText),
                    Amount = Decimal.Parse(WebUtility.HtmlDecode(taxNode.ChildNodes[7].InnerText), NumberStyles.Currency, CultureInfo.GetCultureInfo("fr-FR")),
                    PaymentDate = DateTime.ParseExact(taxNode.ChildNodes[5].InnerText.Trim(), "dd/MM/yyyy", null),
                };
                if (taxManager.TaxNoticeExists(notice))
                    continue;

                taxManager.SaveTaxNotice(notice);
                OnMonitorEnded(notice);
            }
        }
Exemplo n.º 3
0
        public void SaveTaxNotice(TaxNotice notice)
        {
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["AWSDatabase"].ConnectionString))
            {
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = @"
INSERT INTO 
    TaxNotice (Id, Amount, PaymentDate)
VALUES
    (@Id, @Amount, @PaymentDate)";
                    command.Parameters.AddParameter("@IdUser", SqlDbType.BigInt, notice.Id);
                    command.Parameters.AddParameter("@Amount", SqlDbType.Decimal, notice.PaymentDate);
                    command.Parameters.AddParameter("@PaymentDate", SqlDbType.DateTime2, notice.PaymentDate);

                    connection.Open();
                    command.ExecuteNonQuery();
                }
            }
        }