Esempio n. 1
0
        public void AddInteret(SqlConnection connection)
        {
            TauxDAO tdao    = new TauxDAO(connection);
            Taux    interet = tdao.SelectOne("WHERE nom='Interet'");

            float    reste = pret.montant;
            DateTime date1 = Convert.ToDateTime(pret.datePret);

            foreach (Remboursement r in remboursements)
            {
                if (r.fait == 0)
                {
                    DateTime date2  = Convert.ToDateTime(r.dateRemboursement);
                    TimeSpan time   = date2.Subtract(date1);
                    int      nbJour = (int)time.TotalDays;
                    r.interet = (interet.Valeur * nbJour * reste) / 100;
                    date1     = date2;
                    reste    -= r.montant;
                }
                else
                {
                    date1  = Convert.ToDateTime(r.dateRemboursement);
                    reste -= r.montant;
                }
            }
        }
Esempio n. 2
0
        public void AddRetard(SqlConnection connection)
        {
            TauxDAO          tdao   = new TauxDAO(connection);
            RemboursementDAO rbdao  = new RemboursementDAO(connection);
            Taux             retard = tdao.SelectOne("WHERE nom='Retard'");

            float    reste = pret.montant;
            DateTime date1 = default(DateTime);

            for (int i = 0; i < remboursements.Count(); i++)
            {
                Remboursement r = remboursements.ElementAt(i);
                if (r.fait == 0 || (r.fait == 1 && r.id == null))
                {
                    Models.Remboursement rb = rbdao.SelectOne("WHERE id='" + r.id + "'");
                    if ((r.id != null && rb != null) || r.id == null)
                    {
                        if (r.id != null)
                        {
                            date1 = Convert.ToDateTime(rb.DateRemboursement);
                        }
                        DateTime date2  = Convert.ToDateTime(r.dateRemboursement);
                        TimeSpan time   = date2.Subtract(date1);
                        int      nbJour = (int)time.TotalDays;
                        if (nbJour > 0)
                        {
                            r.interet += (retard.Valeur * nbJour * reste) / 100;
                        }
                        date1  = date2;
                        reste -= r.montant;
                    }
                    else
                    {
                        throw new Exception("ID du remboursement introuvable !");
                    }
                }
                else if (r.fait == 1 && r.id != null)
                {
                    Models.Remboursement rb = rbdao.SelectOne("WHERE pret='" + pret.id + "' AND id='" + r.id + "' AND fait=1");
                    if (rb != null)
                    {
                        date1  = Convert.ToDateTime(rb.DateRemboursement);
                        reste -= rb.Montant;
                    }
                    else
                    {
                        throw new Exception("Le remboursement qui se dit etre deja fait est introuvable !");
                    }
                }
            }
        }