Exemplo n.º 1
0
        void OpenHandler()
        {
            Debtors.Clear();

            string         filePath       = null;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";

            if (openFileDialog.ShowDialog() == true)
            {
                filePath = openFileDialog.FileName;

                using (StreamReader reader = new StreamReader(filePath))
                {
                    string inputFromFile;

                    while ((inputFromFile = reader.ReadLine()) != null)
                    {
                        string[] words      = inputFromFile.Split(",");
                        Debtor   openDebtor = new Debtor(words[0], 0);
                        for (int i = 1; i < words.Length - 1; i += 2)
                        {
                            Debt openDebt = new Debt(words[i], double.Parse(words[i + 1]));
                            openDebtor.DebtsList.Add(openDebt);
                        }
                        Debtors.Add(openDebtor);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public MainWindowViewModel(Debtors debtBook, INavigationService n)
 {
     _debtBook = debtBook;
     _debtBook.addDebtor(new Debtor("Alicja"));
     _debtBook.addDebtor(new Debtor("Garrett"));
     _nav = n;
 }
Exemplo n.º 3
0
        public void NewDebtor()
        {
            DateTime dateTime = new DateTime(2025, 10, 12);
            Debtors  debtor   = new Debtors("1111-2222-3333", "Petur Petrov", 200, dateTime, 2, 123123);

            Assert.AreEqual(Math.Round(3.46512, 2), debtor.installment);
        }
 public ListOfDebtorsForm(Form form, Root root)
 {
     InitializeComponent();
     _form    = form;
     _root    = root;
     _debtors = new Debtors();
 }
Exemplo n.º 5
0
        //Load a specified Debtor's information
        private void metroButton2_Click(object sender, EventArgs e)
        {
            Exception IBANorNameNotFound = new Exception("The Debtors was not found.\nCheck the IBAN/Name and try again");
            string    exceptionText      = "";

            try
            {
                if (Access.GetDebtors(id).Where(x => (x.name.Trim() == IBANTextBox.Text || x.IBAN.Trim() == IBANTextBox.Text)).Count() != 0)
                {
                    changed                 = Access.GetDebtors(id).Where(x => (x.name.Trim() == IBANTextBox.Text || x.IBAN.Trim() == IBANTextBox.Text)).First();
                    debtTextBox.Text        = changed.debt.ToString();
                    EndDateTime.Value       = changed.endDate;
                    interestTextBox.Text    = changed.interest.ToString();
                    debtTextBox.Enabled     = true;
                    EndDateTime.Enabled     = true;
                    interestTextBox.Enabled = true;
                    metroButton1.Enabled    = true;
                    metroButton3.Enabled    = true;
                }
                else
                {
                    exceptionText = IBANorNameNotFound.Message;
                    throw IBANorNameNotFound;
                }
            }
            catch (Exception)
            {
                MetroMessageBox.Show(this, exceptionText, "Error", MessageBoxButtons.OK);
            }
        }
Exemplo n.º 6
0
 public MainViewModel()
 {
     debtors = new ObservableCollection <IDebtor>();
     Debtors.Add(new Debtor("Britta Nielsen"));
     Debtors.Add(new Debtor("Tobias Lund"));
     Debtors[0].PayOrBorrow(-012397345);
     Debtors[1].PayOrBorrow(6969);
 }
Exemplo n.º 7
0
        public void AddDebtorWithFixedDebt(Person person, double debt)
        {
            if (!IsPersonInDebtors(person))
            {
                Debtor debtor = new Debtor(person, Debtor.FactorType.WithoutFactor, debt);
                Debtors.Add(debtor);

                RecountDebtorsData();
            }
        }
Exemplo n.º 8
0
        public void AddUsualDebtor(Person person)
        {
            if (!IsPersonInDebtors(person))
            {
                Debtor debtor = new Debtor(person, Debtor.FactorType.Standart, person.DebtFactor);
                Debtors.Add(debtor);

                RecountDebtorsData();
            }
        }
Exemplo n.º 9
0
        public void AddDebtorWithFactor(Person person, double debtFactor)
        {
            if (!IsPersonInDebtors(person))
            {
                Debtor debtor = new Debtor(person, Debtor.FactorType.SpecialForProduct, debtFactor);
                Debtors.Add(debtor);

                RecountDebtorsData();
            }
        }
Exemplo n.º 10
0
        public void RemoveDebtor(Person person)
        {
            Debtor debtor = GetDebtor(person);

            if (debtor != null)
            {
                Debtors.Remove(debtor);
                RecountDebtorsData();
            }
        }
Exemplo n.º 11
0
        private void NewFileCommand_Execute()
        {
            MessageBoxResult res = MessageBox.Show("Any unsaved data will be lost. Are you sure you want to initiate a new file?", "Warning",
                                                   MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);

            if (res == MessageBoxResult.Yes)
            {
                Debtors.Clear();
                filename = "";
            }
        }
Exemplo n.º 12
0
 public ShellViewModel()
 {
     Debtors.Add(new Debtor {
         Name = "Mickey Mouse", Amount = -100
     });
     Debtors.Add(new Debtor {
         Name = "Donald Duck", Amount = 1321
     });
     Debtors.Add(new Debtor {
         Name = "Tom Cruise", Amount = 300
     });
 }
Exemplo n.º 13
0
        private void AnalyzeCandidate
        (
            [NotNull] ReaderInfo reader
        )
        {
            DebtorInfo debtor = _debtorManager.GetDebtor(reader);

            if (!ReferenceEquals(debtor, null))
            {
                Debtors.Add(debtor);
            }
        }
Exemplo n.º 14
0
        public void InvolveEveryone()
        {
            Recalculate();
            var alreadyPresentDebtors = Debtors.Where(t => t.UserId != null).Select(t => t.UserId).ToArray();
            var missingDebtors        = AllUsers.Where(t => alreadyPresentDebtors.All(d => d != t.Id)).ToArray();
            var missingTransactions   = missingDebtors.Select(t => new TransactionData()
            {
                UserId = t.Id, Name = t.Name, Amount = AmountDifference / missingDebtors.Count()
            });

            Debtors.AddRange(missingTransactions);

            DebtorsChanged();
        }
Exemplo n.º 15
0
        public string Info()
        {
            var    userId      = GetUserId();
            var    groupId     = Convert.ToInt32(Context.Parameters["GroupId"]);
            var    paymentId   = Context.Parameters["Id"];
            string uID         = userId.ToString();
            string gID         = Convert.ToString(Context.Parameters["GroupId"]);
            string date        = DateTime.Today.ToString();
            string description = Data.Description;
            string currency    = Data.Currency;
            string text        = EmailService.Text(Payers.ToList(), Debtors.ToList(), uID, gID, date, description, currency);

            return(text);
        }
Exemplo n.º 16
0
 public void EditRow(TransactionRowData row, string context)
 {
     if (context == "payers")
     {
         var item = Payers.Find(n => n == row);
         item.Name             = "";
         item.IsUserboxVisible = false;
     }
     else if (context == "debtors")
     {
         var item = Debtors.Find(n => n == row);
         item.Name             = "";
         item.IsUserboxVisible = false;
     }
 }
Exemplo n.º 17
0
        public void FilterDebtorsNames(string filter)
        {
            IEnumerable <TransactionData> debtorsDatas = AllDebtors;

            if (!string.IsNullOrWhiteSpace(filter))
            {
                debtorsDatas = debtorsDatas.Where(t => t.Name.Contains(filter));
            }

            FilteredNames = debtorsDatas.Select(t => t.Name)                                         //select only names
                            .Concat(Debtors.Select(t => t.Name))                                     //merge Names of allready added debtors with names of all debtors
                            .GroupBy(t => t).Where(g => g.Count() == 1).Select(g => g.Key).ToList(); //select only unique entries

            MoveCurrentUserToTop(FilteredNames);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Saves the payment.
        /// </summary>
        public void Save()
        {
            try
            {
                var userId = GetUserId();
                PaymentService.SavePayment(userId, Data, Payers, Debtors);
                string text = Info();
                EmailService.SendEmail(Debtors.Concat(Payers).ToList(), text);
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return;
            }

            GoBack();
        }
Exemplo n.º 19
0
        private void AddDebtorCommandExecute()
        {
            if (!String.IsNullOrEmpty(newDebtorName))
            {
                var newDebtor = new Debtor();
                // Set properties and add to list
                newDebtor.Name = newDebtorName;
                newDebtor.PayOrBorrow(newDebtorDebt);
                Debtors.Add(newDebtor);
                _modelDebtor = newDebtor;

                //Reset textbox binded properties
                newDebtorName = "";
                newDebtorDebt = 0;
            }
            else
            {
                MessageBox.Show($"Cannot add debtor with no name");
            }
        }
Exemplo n.º 20
0
        public void AddSelectedUser(string name, TransactionRowData row, string context)
        {
            if (context == "payers")
            {
                var user = AllPayers.FirstOrDefault(n => n.Name == name);
                if (user != null)
                {
                    var item = Payers.First(n => n.RowId == row.RowId);
                    item.Name             = user.Name;
                    item.UserId           = user.UserId;
                    item.ImageUrl         = user.ImageUrl;
                    item.Id               = user.Id;
                    item.IsUserboxVisible = true;
                }

                if (AllPayers.Count > Payers.Count)
                {
                    AddRow(Payers);
                }
            }
            else if (context == "debtors")
            {
                var user = AllDebtors.FirstOrDefault(n => n.Name == name);
                if (user != null)
                {
                    var item = Debtors.First(n => n.RowId == row.RowId);
                    item.Name             = user.Name;
                    item.UserId           = user.UserId;
                    item.ImageUrl         = user.ImageUrl;
                    item.Id               = user.Id;
                    item.IsUserboxVisible = true;
                }


                if (AllDebtors.Count > Debtors.Count)
                {
                    AddRow(Debtors);
                }
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// Recalculates the remaining amount.
 /// </summary>
 public void Recalculate()
 {
     AmountDifference = (Payers.Where(p => p.Amount != null).Sum(p => p.Amount) ?? 0) - (Debtors.Where(p => p.Amount != null).Sum(p => p.Amount) ?? 0);
 }
Exemplo n.º 22
0
 public void DeleteDebtor(TransactionData debtor)
 {
     Debtors.Remove(debtor);
     EnsureInsertRowPresent(Debtors);
     Recalculate();
 }
Exemplo n.º 23
0
        public List <Loan> GetLoans(string userID)
        {
            List <Loan> loans = null;

            try
            {
                using (var context = new DebtyDBContext())
                {
                    var loanss = (from loan in context.Loans
                                  join creditor in context.Persons on loan.Creditor.Id equals creditor.Id
                                  where loan.Creditor.Id == userID
                                  select new
                    {
                        loanID = loan.LoanID,
                        loanName = loan.LoanName,
                        loanDesc = loan.LoanDesc,
                        loanDate = loan.LoanDate,
                        deadline = loan.Deadline,
                        loanAmount = loan.LoanAmount,
                        Creditor = new Creditor {
                            PersonID = loan.Creditor.Id, FirstName = creditor.FirstName, LastName = creditor.LastName
                        },
                    }).ToList();

                    var debtors = (from dl in context.DebtorLoans
                                   join debtor in context.Persons on dl.DebtorID equals debtor.Id
                                   select new
                    {
                        loanID = dl.LoanID,
                        debtor = new Debtor {
                            FirstName = debtor.FirstName, LastName = debtor.LastName
                        }
                    } into D
                                   group D by D.loanID into Debtors
                                   select new
                    {
                        loanID = Debtors.Key,
                        Debtors = Debtors.ToList()
                    }).ToList();

                    loans = (from loan in loanss
                             join debtor in debtors on loan.loanID equals debtor.loanID
                             select new Loan
                    {
                        LoanID = loan.loanID,
                        LoanName = loan.loanName,
                        LoanDesc = loan.loanDesc,
                        LoanDate = loan.loanDate,
                        Deadline = loan.deadline,
                        LoanAmount = loan.loanAmount,
                        Creditor = loan.Creditor,
                        Debtors = debtor.Debtors.Select(x => x.debtor).ToList()
                    }).ToList();

                    return(loans);
                }
            }
            catch (Exception ex)
            {
                return(loans.DefaultIfEmpty().ToList());
            }
        }
Exemplo n.º 24
0
 public AddDebtorViewModel(Debtors debtBook, INavigationService n)
 {
     _debtBook = debtBook;
     _nav      = n;
 }
Exemplo n.º 25
0
 public ViewDebtorViewModel(Debtors debtBook, String debtorName, INavigationService n)
 {
     _debtBook       = debtBook;
     _selectedDebtor = _debtBook.getDebtor(debtorName);
     _nav            = n;
 }
Exemplo n.º 26
0
        private void LoadReaders()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            WriteLine("Начало загрузки читателей");

            IEnumerable <MarcRecord> records
                = BatchRecordReader.WholeDatabase
                  (
                      Connection,
                      Connection.Database,
                      1000
                  );
            BatchRecordReader batch
                = records as BatchRecordReader;

            if (!ReferenceEquals(batch, null))
            {
                batch.BatchRead += Batch_BatchRead;
            }

            records.ProcessData(ParseAndAddReader);
            Readers.CompleteAdding();

            WriteDelimiter();
            WriteLine("Распределение читателей");
            string[] keys = ReadersByStatus.Keys;
            foreach (string key in keys)
            {
                WriteLine
                (
                    "Статус {0}: {1} читателей",
                    key,
                    ReadersByStatus[key].Length
                );
            }
            WriteDelimiter();

            DateTime today = DateTime.Today;

            _debtorManager
                = new DebtorManager(Connection)
                {
                FromDate = today.AddYears(-1),
                ToDate   = today.AddMonths(-1)
                };
            _debtorManager.SetupDates();

            ReadersByStatus["0"].ProcessData(AnalyzeCandidate);
            Debtors.CompleteAdding();

            WriteLine
            (
                "Кандидатов в должники: {0}",
                Debtors.Count
            );

            WriteLine("Окончание загрузки читателей");
            stopwatch.Stop();
            WriteLine
            (
                "Загрузка заняла: {0}",
                stopwatch.Elapsed.ToAutoString()
            );
            WriteLine("Загружено: {0}", Readers.Count);
            WriteDelimiter();
        }