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

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

            // buttons //
            btnDelete.EventHandler        = btnDelete_Click;
            btnSubmit.EventHandler        = btnSubmit_Click;
            btnSubmitChanges.EventHandler = btnSubmitChanges_Click;
            btnReinstate.EventHandler     = btnReinstate_Click;

            ucCustomFields._DataTableID = db._DataTables.Single(c => c.TableReference == "CRM_Organisation").ID;
            ucLogHistory.IHistory       = Entity;
            ucLogNotes.INotes           = Entity;

            // Security //

            if (!PermissionManager.CanAdd && Entity == null)
            {
                Response.Redirect("list.aspx");
            }

            // confirmations //

            confirmationDelete.StandardDeleteHidden("organisation", btnRealDelete_Click);

            // process //


            ((UserControlTextBox)ucAddress.FindControl("txtAddress1")).TextBox.Attributes[CRM_Organisation.DataKey] = ((byte)CRM_Organisation.SearchKeys.Address1).ToString();
            ((UserControlTextBox)ucAddress.FindControl("txtPostcode")).TextBox.Attributes[CRM_Organisation.DataKey] = ((byte)CRM_Organisation.SearchKeys.Postcode).ToString();
            txtOrganisationName.TextBox.Attributes[CRM_Organisation.DataKey] = ((byte)CRM_Organisation.SearchKeys.Name).ToString();

            ucNavOrganisation.Entity = Entity;

            if (!IsPostBack)
            {
                ddlOrgType.DataSource = CRM_OrganisationType.SetDropDown(db.CRM_OrganisationTypes.Cast <IArchivable>(),
                                                                         Entity == null ? null : Entity.CRM_OrganisationType);
                ddlOrgType.DataBind();

                if (Entity != null)
                {
                    PopulateFields();
                }
                else
                {
                    ucCustomFields.Populate(String.Empty);
                }
            }
        }
        protected void lnkAutoSearch(object sender, EventArgs e)
        {
            CRM.Code.Models.CRM_Organisation Item = db.CRM_Organisations.SingleOrDefault(c => c.ID.ToString() == acOrganisation.SelectedID);

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

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

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

            if (newRecord)
            {
                Entity                         = new CRM_Organisation();
                Entity.CRM_Address             = new CRM_Address();
                Entity.PrimaryContactReference = "";
                db.CRM_Organisations.InsertOnSubmit(Entity);
            }
            else
            {
                oldEntity  = Entity.ShallowCopy();
                oldAddress = Entity.CRM_Address.ShallowCopy();
            }


            Entity.Name = txtOrganisationName.Text;
            Entity.CRM_OrganisationTypeID = Convert.ToInt32(ddlOrgType.SelectedValue);
            ucAddress.Save(Entity.CRM_Address);

            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);
        }
Пример #4
0
 public IEnumerable <IDuplicate> GetBaseSet(MainDataContext db)
 {
     return(CRM_Organisation.BaseSet(db).Select(l => (IDuplicate)l));
 }