Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            RunSecurity(CRM.Code.Models.Admin.AllowedSections.NotSet);

            Entity = db.CRM_Schools.SingleOrDefault(o => o.ID.ToString() == Request.QueryString["id"]);

            // buttons //
            btnDelete.EventHandler        = btnDelete_Click;
            btnSubmit.EventHandler        = btnSubmit_Click;
            btnSubmitChanges.EventHandler = btnSubmitChanges_Click;
            ucCustomFields._DataTableID   = db._DataTables.Single(c => c.TableReference == "CRM_School").ID;
            btnReinstate.EventHandler     = btnReinstate_Click;

            ucLogHistory.IHistory = Entity;
            ucLogNotes.INotes     = Entity;

            // confirmations //

            confirmationDelete.StandardDeleteHidden("organisation", btnRealDelete_Click);

            CRMContext = Entity;
            // process //

            if (!IsPostBack)
            {
                ddlSchoolType.DataSource = CRM_SchoolType.SetDropDown(db.CRM_SchoolTypes.Select(s => (IArchivable)s), Entity == null ? null : Entity.CRM_SchoolType);
                ddlSchoolType.DataBind();

                ddlLEA.DataSource = CRM_LEA.BaseSet(db);
                ddlLEA.DataBind();

                chkKeyStages.DataSource = CRM_KeyStage.SetCheckboxList(db.CRM_KeyStages.Select(s => (IArchivable)s), Entity == null ? null : Entity.CRM_SchoolKeystages.Select(s => (ICRMRecord)s.CRM_KeyStage));
                chkKeyStages.DataBind();

                if (Entity != null)
                {
                    PopulateFields();
                }
                else
                {
                    ucCustomFields.Populate(String.Empty);
                }
            }

            ucNavSchool.Entity = Entity;
        }
Beispiel #2
0
        protected void lnkAutoSearch(object sender, EventArgs e)
        {
            CRM.Code.Models.CRM_School Item = db.CRM_Schools.SingleOrDefault(c => c.ID.ToString() == acSchool.SelectedID);

            if (Item != null)
            {
                if (!Entity.CRM_OrganisationSchools.Any((a => a.CRM_SchoolID == Item.ID)))
                {
                    CRM_OrganisationSchool CRM_OrganisationSchool = new CRM_OrganisationSchool()
                    {
                        CRM_SchoolID       = Item.ID,
                        CRM_OrganisationID = Entity.ID
                    };

                    db.CRM_OrganisationSchools.InsertOnSubmit(CRM_OrganisationSchool);
                    db.SubmitChanges();
                }
            }

            NoticeManager.SetMessage(Item.DisplayName + " tagged to " + Entity.DisplayName);
        }
Beispiel #3
0
        protected void SaveRecord(bool newRecord)
        {
            // new record / exiting record //
            object oldEntity  = null;
            object oldAddress = null;

            if (newRecord)
            {
                Entity                         = new CRM_School();
                Entity.IsArchived              = false;
                Entity.CRM_Address             = new CRM_Address();
                Entity.PrimaryContactReference = "";
                db.CRM_Schools.InsertOnSubmit(Entity);
            }
            else
            {
                oldEntity  = Entity.ShallowCopy();
                oldAddress = Entity.CRM_Address.ShallowCopy();
            }


            if (ddlLEA.SelectedValue != "")
            {
                Entity.CRM_LEAID = Convert.ToInt32(ddlLEA.SelectedValue);
            }
            else
            {
                Entity.CRM_LEAID = null;
            }

            Entity.Name             = txtOrganisationName.Text;
            Entity.CRM_SchoolTypeID = Convert.ToInt32(ddlSchoolType.SelectedValue);

            Entity.ApproxPupils      = Convert.ToInt32(txtPupils.Text);
            Entity.SageAccountNumber = txtSage.Text;
            Entity.SENSupportFreq    = txtSENFrequency.Text;
            Entity.IsSEN             = chkIsSEN.Checked;
            Entity.Email             = txtEmail.Text;
            Entity.Phone             = txtPhone.Text;

            ucAddress.Save(Entity.CRM_Address);

            db.CRM_SchoolKeystages.DeleteAllOnSubmit(Entity.CRM_SchoolKeystages);

            db.SubmitChanges();

            foreach (ListItem item in chkKeyStages.Items)
            {
                if (item.Selected)
                {
                    CRM_SchoolKeystage sKs = new CRM_SchoolKeystage()
                    {
                        CRM_KeyStageID = Convert.ToInt32(item.Value),
                        CRM_SchoolID   = Entity.ID
                    };

                    db.CRM_SchoolKeystages.InsertOnSubmit(sKs);
                    db.SubmitChanges();
                }
            }

            if (oldEntity != null)
            {
                CRM.Code.History.History.RecordLinqUpdate(AdminUser, oldEntity, Entity);
                CRM.Code.History.History.RecordLinqUpdate(AdminUser, oldAddress, Entity.CRM_Address);
                db.SubmitChanges();
            }
            else
            {
                CRM.Code.History.History.RecordLinqInsert(AdminUser, Entity);
                CRM.Code.History.History.RecordLinqInsert(AdminUser, Entity.CRM_Address);
            }

            ucCustomFields.Save(Entity.Reference);
        }