/// <summary>
        /// The object factory for a particular data collection instance.
        /// </summary>
        public virtual void CreateObjectsFromData(Borrowers borrowers, System.Data.DataSet data)
        {
            // Do nothing if we have nothing
            if (data == null || data.Tables.Count == 0 || data.Tables[0].Rows.Count == 0)
            {
                return;
            }


            // Create a local variable for the new instance.
            Borrower newobj = null;

            // Create a local variable for the data row instance.
            System.Data.DataRow dr = null;


            // Iterate through the table rows
            for (int i = 0; i < data.Tables[0].Rows.Count; i++)
            {
                // Get a reference to the data row
                dr = data.Tables[0].Rows[i];
                // Create a new object instance
                newobj = System.Activator.CreateInstance(borrowers.ContainsType[0]) as Borrower;
                // Let the instance set its own members
                newobj.SetMembers(ref dr);
                // Add the new object to the collection instance
                borrowers.Add(newobj);
            }
        }
Beispiel #2
0
        public void PayDeb(Borrower b)
        {
            var value = Math.Min(b.Borrow, Debt);

            if (value <= 0)
            {
                return;
            }

            Debt -= value;
            Borrowers.Add(b, value);
            b.Decrease(value);
        }
Beispiel #3
0
        public void AddBorrower(string name, decimal amount, bool shouldSaveToFile = true)
        {
            var borrower = new Borrower
            {
                Name       = name,
                CashAmount = amount
            };

            Borrowers.Add(borrower);

            if (shouldSaveToFile)
            {
                File.WriteAllLines(FileName, new List <string> {
                    borrower.ToString()
                });
            }
        }
Beispiel #4
0
        public void AddBorrower(string name, decimal amount, DateTime date, bool shouldSaveToFile = true)
        {
            var borrower = new Borrower
            {
                Name   = name,
                Amount = amount,
                Date   = date
            };

            Borrowers.Add(borrower);

            if (shouldSaveToFile)
            {
                File.AppendAllLines(FileName, new List <string> {
                    borrower.ToString()
                });
            }
        }
        /// <summary>
        /// The object factory for a particular data collection instance.
        /// </summary>
        public virtual void CreateObjectsFromData(Borrowers borrowers, System.Data.SqlClient.SqlDataReader data)
        {
            // Do nothing if we have nothing
            if (data == null)
            {
                return;
            }


            // Create a local variable for the new instance.
            Borrower newobj = null;

            // Iterate through the data reader
            while (data.Read())
            {
                // Create a new object instance
                newobj = System.Activator.CreateInstance(borrowers.ContainsType[0]) as Borrower;
                // Let the instance set its own members
                newobj.SetMembers(ref data);
                // Add the new object to the collection instance
                borrowers.Add(newobj);
            }
        }
Beispiel #6
0
        public void AddBorrower(string name, decimal amount, bool shouldSaveToFile = true)
        {
            var isNotExist = true;

            foreach (var checkborrower in Borrowers)
            {
                if (checkborrower.Name == name)
                {
                    isNotExist = false;
                    break;
                }
            }

            if (isNotExist)
            {
                var borrower = new Borrower
                {
                    Name   = name,
                    Amount = amount
                };

                Borrowers.Add(borrower);

                if (shouldSaveToFile)
                {
                    File.AppendAllLines(FileName, new List <string> {
                        borrower.ToString()
                    });
                }
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine("Taki dłużnik już istnieje!");
                Console.ReadLine();
            }
        }
        private async void btnSave_Click(object sender, EventArgs e)
        {
            if (this.ValidateInputs(txtFirstName.Text, txtLastname.Text, txtMiddlename.Text, txtAddress.Text, txtContacts.Text, txtBday.Text,
                                    txtOccupation.Text, txtMonthlySalary.Text))
            {
                this.Message("Warning! Please Fill Up All Fields.", "Input Validation", true);
                return;
            }

            if (ValidateAlpha(txtFirstName.Text) || ValidateAlpha(txtLastname.Text) || ValidateAlpha(txtOccupation.Text) ||
                ValidateNumeric(txtContacts.Text) || ValidateNumeric(txtMonthlySalary.Text))
            {
                this.Message("Warning! Invalid Characters are Detected. Please use letters and spaces only.", "Input Validation", true);
                return;
            }

            if (bdayValidation)
            {
                this.Message("Warning! Please input correct birthday.", "Input Validation", true);
                return;
            }

            string[]      dob      = txtBday.Text.Split('/');
            DateTime      birthday = new DateTime(int.Parse(dob[2]), int.Parse(dob[0]), int.Parse(dob[1]));
            BorrowerModel b        = new BorrowerModel()
            {
                Id            = id,
                FirstName     = txtFirstName.Text.ToUpper(),
                LastName      = txtLastname.Text.ToUpper(),
                MiddleName    = txtMiddlename.Text.ToUpper(),
                Address       = txtAddress.Text.ToUpper(),
                ContactNumber = txtContacts.Text,
                Birthday      = birthday,
                Occupation    = txtOccupation.Text.ToUpper(),
                MonthlySalary = Convert.ToDecimal(txtMonthlySalary.Text),
                Gender        = optMale.Checked == true ? "MALE" : "FEMALE",
                CivilStatus   = cboCivilStatus.SelectedItem.ToString(),
            };

            if (operation == "update")
            {
                b.Image = _image;
                if (await borrower.Update(b))
                {
                    if (b.Image.Contains("default") && b.Image != _image)
                    {
                        img.CopyImage(_image, b.Image);
                    }
                    this.Message(borrower.msg, "Borrower", false);
                    this.Hide();
                    using (frmViewBorrowers frm = new frmViewBorrowers())
                    {
                        frm.ShowDialog();
                    }
                }
                else
                {
                    this.Message(borrower.msg, "Borrower", true);
                }
            }
            else
            {
                b.Image = _image == "default.png" ? "images/" + _image : "images/" + img.RenameImage(_image);
                if (await borrower.Add(b))
                {
                    if (_image != "default.png")
                    {
                        MessageBox.Show(_image);
                        img.CopyImage(_image, b.Image);
                    }
                    this.Message(borrower.msg, "Borrower", false);
                    this.Hide();
                    using (frmViewBorrowers frm = new frmViewBorrowers())
                    {
                        frm.ShowDialog();
                    }
                }
                else
                {
                    this.Message(borrower.msg, "Borrower", true);
                }
            }
        }
Beispiel #8
0
        public void ChangeBorrower(string name, string calculation, decimal amountToChange, bool shouldSaveToFile = true)
        {
            foreach (var borrower in Borrowers)
            {
                if (borrower.Name == name)
                {
                    BorrowerAmount = borrower.Amount;
                    Borrowers.Remove(borrower);

                    break;
                }
            }

            if (calculation.ToLower() == "d")
            {
                var borrowerToChange = new Borrower
                {
                    Name   = name,
                    Amount = BorrowerAmount + amountToChange
                };

                if (borrowerToChange.Amount == amountToChange)
                {
                    Console.WriteLine();
                    Console.WriteLine("Nie ma takiego dłużnika");
                }
                else
                {
                    Borrowers.Add(borrowerToChange);
                    Console.WriteLine();
                    Console.WriteLine("Kwota długu zmnieniona");
                }
            }
            else
            {
                var borrowerToChange = new Borrower
                {
                    Name   = name,
                    Amount = BorrowerAmount - amountToChange
                };

                if (borrowerToChange.Amount > 0)
                {
                    Borrowers.Add(borrowerToChange);
                    Console.WriteLine();
                    Console.WriteLine("Kwota długu zmnieniona");
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Nie ma takiego dłużnika / Cała kwota została zwrócona - dłużnik usunięty");
                }
            }

            if (shouldSaveToFile)
            {
                var borrowersToSave = new List <string>();

                foreach (var borrower in Borrowers)
                {
                    borrowersToSave.Add(borrower.ToString());
                }

                File.Delete(FileName);
                File.WriteAllLines(FileName, borrowersToSave);
            }
        }