예제 #1
0
        private void AddGrant(object sender, RoutedEventArgs e)
        {
            try
            {
                FCS_DBModel db = new FCS_DBModel();
                Donation    d  = new Donation();
                if (IsEvent)
                {
                    d.DonorID                 = DonorID;
                    d.Restricted              = false;
                    d.InKind                  = false;
                    d.DonationAmount          = DonationAmount;
                    d.DonationDate            = Convert.ToDateTime(DonationDate.ToString());
                    d.EventID                 = EventID;
                    d.DonationAmountRemaining = DonationAmount;
                    db.Donations.Add(d);
                }
                else
                {
                    d.DonorID                 = DonorID;
                    d.Restricted              = false;
                    d.InKind                  = false;
                    d.DonationAmount          = DonationAmount;
                    d.DonationDate            = Convert.ToDateTime(DonationDate.ToString());
                    d.DonationAmountRemaining = DonationAmount;
                    db.Donations.Add(d);
                }
                if (restrictedCheckBox.IsChecked == true)
                {
                    Purpose         p           = new Purpose();
                    DonationPurpose dp          = new DonationPurpose();
                    string          purposeName = PurposeComboBox.SelectedItem.ToString();
                    int             PurposeID   = db.Purposes.Where(x => x.PurposeName == purposeName).Select(x => x.PurposeID).First();

                    d.Restricted             = true;
                    d.DonationExpirationDate = Convert.ToDateTime(DonationExpiration.ToString());
                    dp.DonationID            = d.DonationID;
                    dp.PurposeID             = PurposeID;
                    dp.DonationPurposeAmount = DonationAmount;
                    db.DonationPurposes.Add(dp);
                    db.Donations.Remove(d);
                    db.Donations.Add(d);
                }
                db.SaveChanges();

                this.Close();
            }
            catch
            {
                MessageBox.Show("Make sure to input all the correct data.");
            }
        }
예제 #2
0
        private void AddGrant(object sender, RoutedEventArgs e)
        {
            try
            {
                //MessageBox.Show(DonationAmount.ToString() + "\n" + DonationDate + "\n" +
                //    PurposeName + "\n" + PurposeDescription);
                FCS_DBModel db = new FCS_DBModel();

                Donation d = new Donation();
                d.DonorID                 = DonorID;
                d.Restricted              = false;
                d.InKind                  = false;
                d.DonationAmount          = DonationAmount;
                d.DonationDate            = Convert.ToDateTime(DonationDate.ToString());
                d.DonationAmountRemaining = DonationAmount;
                d.GrantProposalID         = GrantProposalID;
                db.Donations.Add(d);

                if (restrictedCheckBox.IsChecked == true)
                {
                    Purpose         p           = new Purpose();
                    DonationPurpose dp          = new DonationPurpose();
                    string          purposeName = PurposeComboBox.SelectedValue.ToString();
                    int             PurposeID   = db.Purposes.Where(x => x.PurposeName == purposeName).Select(x => x.PurposeID).First();

                    d.Restricted             = true;
                    d.DonationExpirationDate = Convert.ToDateTime(DonationExpiration.ToString());
                    d.GrantProposalID        = GrantProposalID;
                    dp.DonationID            = d.DonationID;
                    dp.PurposeID             = PurposeID;
                    dp.DonationPurposeAmount = DonationAmount;
                    db.DonationPurposes.Add(dp);
                    db.Donations.Remove(d);
                    db.Donations.Add(d);
                }
                db.SaveChanges();

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot add Grant" + "\n" + ex);
            }
        }
예제 #3
0
        private void Update_Grant(object sender, RoutedEventArgs e)
        {
            FCS_Funding.Models.FCS_DBModel db = new FCS_Funding.Models.FCS_DBModel();
            //var purpose = (from p in db.Purposes
            //               where p.PurposeID == PurposeID
            //               select p).First();
            //purpose.PurposeName = PurposeName;
            //purpose.PurposeDescription = PurposeDescription;

            var donation = (from d in db.Donations
                            where d.DonationID == DonationID
                            select d).First();

            donation.DonationDate = Convert.ToDateTime(DonationDate.ToString());
            if (DonationAmount - donation.DonationAmount < 0)
            {
                MessageBox.Show("This change would result in a\nnegative balance for this donation");
            }
            else
            {
                if (restrictedCheckBox.IsChecked == true)
                {
                    if (PurposeComboBox.Text != "" && PurposeComboBox.Text != null)
                    {
                        DeletePurposes delPurp = new DeletePurposes();
                        delPurp.deletePurpose(DonationID);
                        Purpose         p           = new Purpose();
                        DonationPurpose dp          = new DonationPurpose();
                        string          purposeName = PurposeComboBox.SelectedItem.ToString();
                        int             PurposeID   = db.Purposes.Where(x => x.PurposeName == purposeName).Select(x => x.PurposeID).First();
                        donation.Restricted = true;
                        if (DonationExpiration != null && DonationExpiration.ToString() != "")
                        {
                            donation.DonationExpirationDate = Convert.ToDateTime(DonationExpiration.ToString());
                        }
                        else
                        {
                            donation.DonationExpirationDate = null;
                        }
                        dp.DonationID            = donation.DonationID;
                        dp.PurposeID             = PurposeID;
                        dp.DonationPurposeAmount = DonationAmount;
                        db.DonationPurposes.Add(dp);
                        decimal donationDiff = donation.DonationAmount - DonationAmount;
                        donation.GrantProposalID         = GrantProposalID;
                        donation.DonationAmount          = DonationAmount;
                        donation.DonationAmountRemaining = donation.DonationAmountRemaining - donationDiff;
                        db.Entry(donation);
                        db.SaveChanges();
                        db.Entry(dp);
                        db.SaveChanges();
                    }
                    else
                    {
                        MessageBox.Show("Please enter a purpose if the donation is restrcted");
                    }
                }
                else
                {
                    DeletePurposes delPurp = new DeletePurposes();
                    delPurp.deletePurpose(DonationID);
                    donation.Restricted             = false;
                    donation.DonationExpirationDate = null;
                    donation.GrantProposalID        = GrantProposalID;
                    decimal donationDiff = donation.DonationAmount - DonationAmount;
                    donation.DonationAmount          = DonationAmount;
                    donation.DonationAmountRemaining = donation.DonationAmountRemaining - donationDiff;
                    db.Entry(donation);
                    db.SaveChanges();
                }

                this.Close();
            }
        }