Ejemplo n.º 1
0
        protected void rgReceiver_InsertCommand(object sender, GridCommandEventArgs e)
        {
            UpdateDifferences();

            //Cast the GridCommandEventArgs item as an editable item
            GridEditableItem editedItem = e.Item as GridEditableItem;
            //Find the user control used by that item save it as a UserControl
            UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
            var         rec         = new AccountFundSource();

            GrabValuesFromUserControl(userControl, ref rec);

            try
            {
                int id = siftaDB.AccountFundSources.Max(p => p.AFSID);
                rec.AFSID = id + 1;
            }
            catch (Exception ex)
            {
                rec.AFSID = 0;
            }

            siftaDB.AccountFundSources.InsertOnSubmit(rec);
            siftaDB.SubmitChanges();
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            GetOrgCode();
            AgreementID = int.Parse(Request.QueryString["AgreementID"]);
            AddModsToComboBox();

            //Insert
            if (DataItem is GridInsertionObject)
            {
                rec = new AccountFundSource();
                btnInsert.Visible = true;

                var ag = siftaDB.Agreements.FirstOrDefault(p => p.AgreementID == AgreementID);
                try
                {
                    rcbMatchPair.SelectedValue          = ag.MatchPair.ToString();
                    rcbProgramElementCode.SelectedValue = ag.ProgramElementCode.ToString();
                }
                catch { }
            }
            //Update
            else if (DataItem != null && DataItem.GetType() == typeof(AccountFundSource))
            {
                rec = (AccountFundSource)DataItem;
                rcbAccount.SelectedValue            = rec.AccountNumber;
                rddlCustomerClass.SelectedValue     = rec.CustomerClass;
                rddlStatus.SelectedValue            = rec.FundStatus;
                rcbMatchPair.SelectedValue          = rec.MatchPair;
                rcbProgramElementCode.SelectedValue = rec.ProgramElementCode;
                btnUpdate.Visible = true;
            }
        }
Ejemplo n.º 3
0
        private void GrabValuesFromUserControl(UserControl uc, ref AccountFundSource rec)
        {
            #region User Controls
            //Grab the controls from the user controls
            var rtbAgreementMod       = (uc.FindControl("rtbAgreementMod") as RadTextBox);
            var rtbFiscalYear         = (uc.FindControl("rtbFiscalYear") as RadTextBox);
            var rcbAccount            = (uc.FindControl("rcbAccount") as RadComboBox);
            var rddlCustomerClass     = (uc.FindControl("rddlCustomerClass") as RadDropDownList);
            var rcbMatchPair          = (uc.FindControl("rcbMatchPair") as RadComboBox);
            var rcbProgramElementCode = (uc.FindControl("rcbProgramElementCode") as RadComboBox);
            var rtbFunding            = (uc.FindControl("rtbFunding") as RadTextBox);
            var rddlStatus            = (uc.FindControl("rddlStatus") as RadDropDownList);
            var rtbRemarks            = (uc.FindControl("rtbRemarks") as RadTextBox);

            #endregion

            #region Assign Values
            int?mod;
            if (rtbAgreementMod.Text.Length > 0)
            {
                mod = Convert.ToInt32(rtbAgreementMod.Text);
            }
            else
            {
                mod = null;
            }

            var aModID = siftaDB.AgreementMods.First(p => p.AgreementID == agreement.AgreementID).AgreementModID;

            rec.AgreementModID     = aModID;
            rec.FundSourceFY       = Convert.ToInt32(rtbFiscalYear.Text);
            rec.AccountNumber      = rcbAccount.SelectedValue;
            rec.CustomerClass      = rddlCustomerClass.SelectedValue;
            rec.MatchPair          = rcbMatchPair.SelectedValue;
            rec.ProgramElementCode = rcbProgramElementCode.SelectedValue;
            rec.Funding            = Convert.ToDouble(rtbFunding.Text);
            rec.FundStatus         = rddlStatus.SelectedValue;
            rec.Remarks            = rtbRemarks.Text;
            rec.ModifiedBy         = user.ID;
            rec.ModifiedDate       = DateTime.Now;

            if (String.IsNullOrEmpty(rec.CreatedBy))
            {
                rec.CreatedBy   = user.ID;
                rec.CreatedDate = DateTime.Now;
            }
            #endregion
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Called to copy an agreement 1 fiscal year ahead
        /// </summary>
        /// <param name="agreement">The agreement to be copied</param>
        protected void CopyAgreement(Agreement agreement)
        {
            //Add metrics
            var metric = new MetricHandler(customer.OrgCode, customer.CustomerID, null, MetricType.RecordCopied, "Agreement", String.Format("Copied AgreemendID = {0}", agreement.AgreementID));

            metric.SubmitChanges();
            //Grabs Mod 0 for the Agreement (the original agreement information is what we are copying over)
            var mod = agreement.AgreementMods.FirstOrDefault(p => p.Number == 0);
            //Grabs the list of Site funding for the original mod
            var siteFunding = mod.FundingSites.ToList();
            //Grab all coop funding for mod 0;
            var coopFunding = mod.CooperativeFundings.ToList();
            //Grabs the list of studies funding for the original mod
            var studiesFunding = mod.FundingStudies.ToList();

            //Grab list of account fund sources
            var accFundSrc = siftaDB.AccountFundSources.Where(x => x.AgreementModID == mod.AgreementModID).ToList();


            //Create a new mod
            var copyMod = new AgreementMod();
            //Create a new Agreement and assign it values from the old one
            var copy = new Agreement()
            {
                BillingCycleFrequency = agreement.BillingCycleFrequency,
                PurchaseOrderNumber   = agreement.PurchaseOrderNumber + "_Copy",
                FundsType             = agreement.FundsType,
                Remarks = agreement.Remarks,
                CustomerBillingContact   = agreement.CustomerBillingContact,
                CustomerTechnicalContact = agreement.CustomerTechnicalContact,
                Customer2Group           = agreement.Customer2Group,
                USGSBillingContact       = agreement.USGSBillingContact,
                USGSTechnicalContact     = agreement.USGSTechnicalContact,
                CreatedBy    = user.ID,
                CreatedDate  = DateTime.Now,
                ModifiedBy   = user.ID,
                ModifiedDate = DateTime.Now
            };

            //The Start date needs to be pushed up a year if it isn't null
            if (mod.StartDate != null)
            {
                //Set the start date for the agreement to 1 year after the previous agreements start date
                copy.StartDate = Convert.ToDateTime(mod.StartDate).AddYears(1);
            }
            else
            {
                copy.StartDate = null;
            }
            //The End date needs to be pushed up a year if it isn't null
            if (mod.EndDate != null)
            {
                //Set the end date for the agreement to 1 year after the previous agreements end date
                copy.EndDate = Convert.ToDateTime(mod.EndDate).AddYears(1);
            }
            else
            {
                copy.EndDate = null;
            }
            //Set the Mods Start and End Date to be the one from the copied Agreement
            copyMod.StartDate = copy.StartDate;
            copyMod.EndDate   = copy.EndDate;

            //Assign values from old mod to new mod
            copyMod.FundingUSGSCMF     = mod.FundingUSGSCMF;
            copyMod.FundingCustomer    = mod.FundingCustomer;
            copyMod.FundingOther       = mod.FundingOther;
            copyMod.FundingOtherReason = mod.FundingOtherReason;
            copyMod.Number             = 0;
            copyMod.Remarks            = mod.Remarks;
            copyMod.CreatedBy          = copyMod.ModifiedBy = user.ID;
            copyMod.CreatedDate        = copyMod.ModifiedDate = DateTime.Now;

            //Add Site Funding to copy mod
            foreach (var siteF in siteFunding)
            {
                copyMod.FundingSites.Add(new FundingSite()
                {
                    AgencyCode             = siteF.AgencyCode,
                    CollectionCodeID       = siteF.CollectionCodeID,
                    DifficultyFactor       = siteF.DifficultyFactor,
                    DifficultyFactorReason = siteF.DifficultyFactorReason,
                    FundingCustomer        = siteF.FundingCustomer,
                    FundingUSGSCMF         = siteF.FundingUSGSCMF,
                    CollectionUnits        = siteF.CollectionUnits,
                    SiteNumber             = siteF.SiteNumber,
                    StartDate    = siteF.StartDate?.AddYears(1),
                    EndDate      = siteF.EndDate?.AddYears(1),
                    Remarks      = siteF.Remarks,
                    CreatedBy    = user.ID,
                    CreatedDate  = DateTime.Now,
                    ModifiedBy   = user.ID,
                    ModifiedDate = DateTime.Now
                });
            }
            //Add Studies Funding to the copyMod
            foreach (var studiesF in studiesFunding)
            {
                copyMod.FundingStudies.Add(new FundingStudy()
                {
                    BasisProjectNumber = studiesF.BasisProjectNumber,
                    ResearchCodeID     = studiesF.ResearchCodeID,
                    Units           = studiesF.Units,
                    Remarks         = studiesF.Remarks,
                    FundingCustomer = studiesF.FundingCustomer,
                    FundingUSGSCMF  = studiesF.FundingUSGSCMF,
                    StartDate       = studiesF.StartDate?.AddYears(1),
                    EndDate         = studiesF.EndDate?.AddYears(1),
                    CreatedBy       = user.ID,
                    CreatedDate     = DateTime.Now,
                    ModifiedBy      = user.ID,
                    ModifiedDate    = DateTime.Now
                });
            }

            //Add Copied Mod to the copied agreement
            copy.AgreementMods.Add(copyMod);
            //Add copied agreement to the customer
            customer.Agreements.Add(copy);
            //Submit changes to the database
            siftaDB.SubmitChanges();
            //Add the cooperative funding to the new agreement mod
            foreach (var cfunding in coopFunding)
            {
                copyMod.CooperativeFundings.Add(new CooperativeFunding()
                {
                    AccountNumber   = cfunding.AccountNumber,
                    AgreementID     = copy.AgreementID,
                    CreatedBy       = user.ID,
                    CreatedDate     = DateTime.Now,
                    ModifiedBy      = user.ID,
                    ModifiedDate    = DateTime.Now,
                    Remarks         = cfunding.Remarks,
                    Status          = "LOW",
                    ModNumber       = cfunding.ModNumber,
                    FiscalYear      = Convert.ToInt32(cfunding.FiscalYear) + 1,
                    FundingCustomer = cfunding.FundingCustomer,
                    FundingUSGSCMF  = cfunding.FundingUSGSCMF
                });
            }
            siftaDB.SubmitChanges();

            foreach (var accFund in accFundSrc)
            {
                var newFund = new AccountFundSource();
                newFund.AgreementModID     = copyMod.AgreementModID;
                newFund.FundSourceFY       = accFund.FundSourceFY + 1;
                newFund.AccountNumber      = accFund.AccountNumber;
                newFund.CustomerClass      = accFund.CustomerClass;
                newFund.MatchPair          = accFund.MatchPair;
                newFund.ProgramElementCode = accFund.ProgramElementCode;
                newFund.Funding            = accFund.Funding;
                newFund.FundStatus         = "LOW";
                newFund.Remarks            = accFund.Remarks;
                newFund.CreatedBy          = user.ID;
                newFund.CreatedDate        = DateTime.Now;
                newFund.ModifiedBy         = user.ID;
                newFund.ModifiedDate       = DateTime.Now;

                siftaDB.AccountFundSources.InsertOnSubmit(newFund);
            }
            siftaDB.SubmitChanges();

            //Update Records with Unique Record ID's
            RecordIdentifiers.UpdateRecords();
            //Rebind the agreement grid
            rgAgreements.Rebind();
        }