Пример #1
0
 public bool ExistsFeeLogForYear(int year)
 {
     using (var db = new FeeStatusesDBContext())
     {
         return(FeeLogs.Any(fl => fl.Year == (short)year));
     }
 }
Пример #2
0
 public void AddDefaultFeeLogForYear(int year)
 {
     if (!ExistsFeeLogForYear(year))
     {
         FeeLogs.Add(
             new FeeLogs
         {
             Member          = this,
             Year            = (short)year,
             PaymentStatusID = PaymentStatus.NI_PLACAL,
             FeeToPay        =
                 this.Gender
                         ? ConfigHelper.GetConfigValue <decimal>(ConfigFields.ZNESEK_CLANI)
                         : ConfigHelper.GetConfigValue <decimal>(ConfigFields.ZNESEK_CLANICE),
         }
             );
     }
 }
        private void ImportPaymentHistory(string fullFilePath)
        {
            string line;
            var file = new StreamReader(fullFilePath, Encoding.UTF8);

            try
            {
                using (var db = new FeeStatusesDBContext())
                {
                    while ((line = file.ReadLine()) != null)
                    {
                        string[] lineData = line.Split(';');

                        short year = 2001;
                        Member member = db.Member.Find(lineData[0]);
                        if (member != null && member.Gender) // moski
                        {
                            for (int i = 8; i < 20; i++)
                            {
                                string stat = lineData[i];
                                var log = new FeeLogs
                                              {
                                                  Member = member,
                                                  Year = year
                                              };

                                switch (stat)
                                {
                                    case "DA":
                                        log.PaymentStatusID = PaymentStatus.PLACAL;
                                        break;
                                    case "NE":
                                        log.PaymentStatusID = PaymentStatus.NI_PLACAL;
                                        break;
                                    case "VETERAN":
                                        log.PaymentStatusID = PaymentStatus.VETERAN;
                                        break;
                                    case "XXX":
                                        log.PaymentStatusID = PaymentStatus.MLADOLETNIK;
                                        break;
                                    default:
                                        if (member.GetMemberAgeForYear(year) < 18)
                                        {
                                            log.PaymentStatusID = PaymentStatus.MLADOLETNIK;
                                        }
                                        else if (member.GetMemberAgeForYear(year) >= 60)
                                        {
                                            log.PaymentStatusID = PaymentStatus.VETERAN;
                                        }
                                        else
                                        {
                                            log.PaymentStatusID = PaymentStatus.NI_PODATKA;
                                        }
                                        break;
                                }

                                member.FeeLogs.Add(log);
                                year++;
                            }
                        }
                    }

                    db.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (DbEntityValidationResult eve in e.EntityValidationErrors)
                {
                    Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                    eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (DbValidationError ve in eve.ValidationErrors)
                    {
                        Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                        ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.StackTrace);
            }

            BindPaymentsDataGridView(onlyMustPayers, includeDeleted);
        }