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;
        }
        public void RunImport(int startLine, int endLine)
        {
            MainDataContext db = new MainDataContext();

            HttpServerUtility Server = HttpContext.Current.Server;

            using (StreamReader reader = new StreamReader(Server.MapPath("/taskscript/scotschools.csv")))
            {
                lineNumber = 0;

                while (!reader.EndOfStream)
                {
                    lineNumber++;

                    string contents = reader.ReadLine();
                    if (lineNumber >= startLine && lineNumber <= endLine)
                    {
                        string[] contentsSplit = contents.Split(',');
                        string   errorMessage  = "";

                        string postcode = contentsSplit[(int)accountPos.postcodea] + " " + contentsSplit[(int)accountPos.postcodeb];

                        CRM_School school = db.CRM_Schools.FirstOrDefault(s => s.Name == contentsSplit[(int)accountPos.name] &&
                                                                          s.CRM_Address.Postcode.Trim().Replace(" ", "").ToLower() == postcode.Trim().Replace(" ", "").ToLower());

                        CRM_LEA        lea     = db.CRM_LEAs.Single(s => s.ID == 25);       // blank
                        CRM_SchoolType type    = db.CRM_SchoolTypes.Single(s => s.ID == 1); // none
                        Country        country = db.Countries.Single(s => s.ID == 1);       // uk

                        if (school == null)
                        {
                            CRM_Address address = new CRM_Address()
                            {
                                AddressLine1 = contentsSplit[(int)accountPos.address1].Trim(),
                                AddressLine2 = "",
                                AddressLine3 = "",
                                AddressLine4 = "",
                                AddressLine5 = "",
                                Town         = contentsSplit[(int)accountPos.address2],
                                County       = "",
                                Postcode     = postcode,
                                CountryID    = country.ID
                            };


                            db.CRM_Addresses.InsertOnSubmit(address);
                            db.SubmitChanges();

                            school = new CRM_School()
                            {
                                CRM_AddressID           = address.ID,
                                ApproxPupils            = 0,
                                CRM_LEAID               = lea.ID,
                                CRM_RegionID            = null,
                                CRM_SchoolTypeID        = type.ID,
                                Email                   = "",
                                IsArchived              = false,
                                IsSEN                   = false,
                                Name                    = contentsSplit[(int)accountPos.name].Trim(),
                                Phone                   = "",
                                SageAccountNumber       = "",
                                PrimaryContactReference = "",
                                SENSupportFreq          = "",
                            };

                            db.CRM_Schools.InsertOnSubmit(school);
                            db.SubmitChanges();
                        }
                    }
                }
            }
        }