/// <summary>
        /// Retrieves the location identified by m_locationId from the organisation and populates the form controls.
        /// Only occurs in update mode.
        /// </summary>
        private void LoadLocation()
        {
            // retrieve the location and store it in viewstate
            Facade.IOrganisationLocation facOrganisationLocation = new Facade.Organisation();
            m_location            = facOrganisationLocation.GetLocationForOrganisationLocationId(m_locationId);
            ViewState[C_LOCATION] = m_location;

            Facade.IIndividual facIndividual = new Facade.Individual();
            _individual = facIndividual.GetForOrganisationLocationID(m_location.OrganisationLocationId);

            if (_individual != null)
            {
                ViewState["VS_Individual"] = _individual;
                // populate the form controls
                cboTitle.ClearSelection();
                cboTitle.Items.FindByValue(_individual.Title.ToString()).Selected = true;
                txtFirstNames.Text = _individual.FirstNames;
                txtLastName.Text   = _individual.LastName;
                if (_individual.Contacts.GetForContactType(eContactType.Email) != null)
                {
                    txtEmailAddress.Text = _individual.Contacts.GetForContactType(eContactType.Email).ContactDetail;
                }
            }

            // location information
            txtLocationName.Text = m_location.OrganisationLocationName;
            cboType.Items.FindByValue(((int)m_location.OrganisationLocationType).ToString()).Selected = true;
            txtTelephone.Text = m_location.TelephoneNumber;
            txtFax.Text       = m_location.FaxNumber;

            // post town information
            cboClosestTown.Text          = m_location.Point.PostTown.TownName;
            cboClosestTown.SelectedValue = m_location.Point.PostTown.TownId.ToString();

            // address information
            txtAddressLine1.Text = m_location.Point.Address.AddressLine1;
            txtAddressLine2.Text = m_location.Point.Address.AddressLine2;
            txtAddressLine3.Text = m_location.Point.Address.AddressLine3;
            txtPostTown.Text     = m_location.Point.Address.PostTown;
            txtCounty.Text       = m_location.Point.Address.County;
            txtPostCode.Text     = m_location.Point.Address.PostCode;
            txtLongitude.Text    = m_location.Point.Address.Longitude.ToString();
            txtLatitude.Text     = m_location.Point.Address.Latitude.ToString();

            if (m_isUpdate)
            {
                cboTrafficArea.Items.FindByValue(m_location.Point.Address.TrafficArea.TrafficAreaId.ToString()).Selected = true;
                cboCountry.SelectedValue = m_location.Point.Address.CountryId.ToString();
            }

            btnAdd.Text = "Update";
        }
        /// <summary>
        /// Updates the location
        /// </summary>
        /// <returns>true if the update succeeded, false otherwise</returns>
        private bool UpdateLocation()
        {
            Facade.IOrganisationLocation facOrganisationLocation = new Facade.Organisation();
            string userId = ((Entities.CustomPrincipal)Page.User).UserName;

            Entities.FacadeResult result = facOrganisationLocation.Update(m_location, _individual, userId);
            if (!result.Success)
            {
                infringementDisplay.Infringements = result.Infringements;
                infringementDisplay.DisplayInfringments();
            }

            m_location = facOrganisationLocation.GetLocationForOrganisationLocationId(m_location.OrganisationLocationId);
            cboTrafficArea.SelectedValue = m_location.Point.Address.TrafficArea.TrafficAreaId.ToString();

            return(result.Success);
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            Orchestrator.WebUI.Security.Authorise.EnforceAuthorisation(eSystemPortion.AddEditOrganisations, eSystemPortion.AddEditPoints, eSystemPortion.GeneralUsage);
            btnAdd.Enabled = Orchestrator.WebUI.Security.Authorise.CanAccess(eSystemPortion.AddEditOrganisations, eSystemPortion.AddEditPoints);

            m_organisationName = Convert.ToString(Request.QueryString["organisationName"]);
            m_identityId       = Convert.ToInt32(Request.QueryString["identityId"]);
            m_locationId       = Convert.ToInt32(Request.QueryString["organisationLocationId"]);

            SetWhereIAm();
            if (m_locationId > 0)
            {
                m_isUpdate = true;
            }

            if (!IsPostBack)
            {
                PopulateStaticControls();
                ConfigureReturnLink();

                if (m_isUpdate)
                {
                    LoadLocation();
                }
                else
                {
                    this.txtLocationName.Text = m_organisationName + " - ";
                }
            }
            else
            {
                // retrieve the location from the view state
                m_location  = (Entities.OrganisationLocation)ViewState[C_LOCATION];
                _individual = (Entities.Individual)ViewState["VS_Individual"];
            }

            infringementDisplay.Visible = false;
        }
        /// <summary>
        /// Populates the location object with the new information.
        /// </summary>
        private void PopulateLocation()
        {
            Entities.Point thisPoint;

            if (m_location == null)
            {
                // adding a new location, configure identity and a new address
                m_location            = new Orchestrator.Entities.OrganisationLocation();
                m_location.IdentityId = m_identityId;
                thisPoint             = new Entities.Point();
                m_location.Point      = thisPoint;
            }
            else
            {
                thisPoint = m_location.Point;
            }

            if (_individual == null)
            {
                _individual = new Orchestrator.Entities.Individual();
                _individual.IndividualType = eIndividualType.Contact;
            }

            //Set the indiviudal details;
            _individual.FirstNames = txtFirstNames.Text;
            _individual.LastName   = txtLastName.Text;
            _individual.Title      = (eTitle)Enum.Parse(typeof(eTitle), cboTitle.SelectedValue);
            if (_individual.Contacts == null)
            {
                _individual.Contacts = new Orchestrator.Entities.ContactCollection();
            }

            _individual.Contacts.Add(new Orchestrator.Entities.Contact(eContactType.Email, txtEmailAddress.Text));
            _individual.Contacts.Add(new Orchestrator.Entities.Contact(eContactType.Telephone, txtTelephone.Text));
            _individual.Contacts.Add(new Orchestrator.Entities.Contact(eContactType.Fax, txtFax.Text));


            // Update the location based on it's settings.
            // location information
            m_location.OrganisationLocationName = txtLocationName.Text;
            m_location.OrganisationLocationType = (eOrganisationLocationType)Enum.Parse(typeof(eOrganisationLocationType), cboType.SelectedValue.Replace(" ", ""), true);
            m_location.TelephoneNumber          = txtTelephone.Text;
            m_location.FaxNumber = txtFax.Text;

            // address information
            thisPoint.Description = m_organisationName + " - " + txtPostTown.Text;
            Facade.IPostTown facPostTown = new Facade.Point();
            thisPoint.PostTown = facPostTown.GetPostTownForTownId(Convert.ToInt32(cboClosestTown.SelectedValue));
            if (thisPoint.Address == null)
            {
                thisPoint.Address = new Entities.Address();
            }
            thisPoint.Address.AddressType  = eAddressType.Correspondence;
            thisPoint.Address.AddressLine1 = txtAddressLine1.Text;
            thisPoint.Address.AddressLine2 = txtAddressLine2.Text;
            thisPoint.Address.AddressLine3 = txtAddressLine3.Text;
            thisPoint.Address.PostTown     = txtPostTown.Text;
            thisPoint.Address.County       = txtCounty.Text;
            thisPoint.Address.PostCode     = txtPostCode.Text;
            thisPoint.Address.Longitude    = Decimal.Parse(txtLongitude.Text);
            thisPoint.Address.Latitude     = Decimal.Parse(txtLatitude.Text);
            if (thisPoint.Address.TrafficArea == null)
            {
                thisPoint.Address.TrafficArea = new Entities.TrafficArea();
            }

            thisPoint.Address.CountryDescription        = cboCountry.SelectedItem.Text;
            thisPoint.Address.CountryId                 = Convert.ToInt32(cboCountry.SelectedValue);
            thisPoint.Address.TrafficArea.TrafficAreaId = Convert.ToInt32(cboTrafficArea.SelectedValue);
            thisPoint.IdentityId       = m_identityId;
            thisPoint.Latitude         = thisPoint.Address.Latitude;
            thisPoint.Longitude        = thisPoint.Address.Longitude;
            thisPoint.OrganisationName = m_organisationName;

            Facade.IOrganisation facOrganisation            = new Facade.Organisation();
            Orchestrator.Entities.Organisation organisation = facOrganisation.GetForIdentityId(thisPoint.IdentityId);

            // set the radius if the address was changed by addressLookup
            // if the org has a default, use it, if not, use the system default.
            if (!String.IsNullOrEmpty(this.hdnSetPointRadius.Value))
            {
                if (organisation.Defaults[0].DefaultGeofenceRadius == null)
                {
                    thisPoint.Radius = Globals.Configuration.GPSDefaultGeofenceRadius;
                }
                else
                {
                    thisPoint.Radius = organisation.Defaults[0].DefaultGeofenceRadius;
                }
            }
        }
Пример #5
0
        private void ImportOrganisationValues()
        {
            cboEmail.Text              = String.Empty;
            cboEmail.SelectedValue     = String.Empty;
            cboEmail.DataSource        = null;
            cboFaxNumber.SelectedValue = String.Empty;
            cboFaxNumber.Text          = String.Empty;
            cboFaxNumber.DataSource    = null;
            txtFaxNumber.Text          = String.Empty;
            txtEmail.Text              = String.Empty;

            if (m_identityId > 0)
            {
                Facade.IOrganisation  facOrganisation = new Facade.Organisation();
                Entities.Organisation organisation    = facOrganisation.GetForIdentityId(m_identityId);

                //RJD: changed to use IndividualContacts instead of PrimaryContact STILL NEEDS WORK
                if (organisation != null && (organisation.IndividualContacts != null && organisation.IndividualContacts.Count > 0))
                {
                    DataSet emailDataSet = this.GetContactDataSet(organisation.IndividualContacts, eContactType.Email);

                    cboEmail.DataSource     = emailDataSet;
                    cboEmail.DataMember     = "contactTable";
                    cboEmail.DataValueField = "ContactDetail";
                    cboEmail.DataTextField  = "ContactDisplay";
                    cboEmail.DataBind();

                    if (this.cboEmail.Items.Count > 0)
                    {
                        this.txtEmail.Text = this.cboEmail.Items[0].Value;
                    }

                    DataSet faxDataSet = this.GetContactDataSet(organisation.IndividualContacts, eContactType.Fax);

                    if (organisation != null && organisation.Locations != null)
                    {
                        Entities.OrganisationLocation headOffice = organisation.Locations.GetHeadOffice();

                        if (!String.IsNullOrEmpty(headOffice.FaxNumber))
                        {
                            DataRow dr = faxDataSet.Tables[0].NewRow();
                            dr["ContactName"]    = "Head Office";
                            dr["ContactDetail"]  = headOffice.FaxNumber;
                            dr["ContactDisplay"] = String.Format("{0} - {1}", dr["ContactName"], headOffice.FaxNumber);
                            faxDataSet.Tables[0].Rows.InsertAt(dr, 0);
                        }
                    }

                    cboFaxNumber.DataSource     = faxDataSet;
                    cboFaxNumber.DataMember     = "contactTable";
                    cboFaxNumber.DataValueField = "ContactDetail";
                    cboFaxNumber.DataTextField  = "ContactDisplay";
                    cboFaxNumber.DataBind();

                    if (this.cboFaxNumber.Items.Count > 0)
                    {
                        this.txtFaxNumber.Text = this.cboFaxNumber.Items[0].Value;
                    }
                }
            }
            else
            {
                cboFaxNumber.Text = txtFaxNumber.Text = String.Empty;
            }
        }
Пример #6
0
        ///	<summary>
        /// Populate Driver
        ///	</summary>
        private void populateDriver()
        {
            if (ViewState["driver"] == null)
            {
                _driver = new Entities.Driver();
            }
            else
            {
                _driver = (Entities.Driver)ViewState["driver"];
            }

            _driver.ResourceType = eResourceType.Driver;
            if (_driver.Individual == null)
            {
                _driver.Individual = new Entities.Individual();
            }

            _driver.Individual.Title      = (eTitle)Enum.Parse(typeof(eTitle), cboTitle.SelectedValue.Replace(" ", ""));
            _driver.Individual.FirstNames = txtFirstNames.Text;
            _driver.Individual.LastName   = txtLastName.Text;
            if (dteDOB.SelectedDate != null)
            {
                _driver.Individual.DOB = dteDOB.SelectedDate.Value;
            }
            else
            {
                _driver.Individual.DOB = DateTime.MinValue;
            }
            _driver.Individual.IndividualType = eIndividualType.Driver;
            _driver.Passcode = txtPasscode.Text;

            if (_driver.Individual.Address == null)
            {
                _driver.Individual.Addresses = new Entities.AddressCollection();
                _driver.Individual.Addresses.Add(new Entities.Address());
            }

            _driver.Individual.Address.AddressLine1 = txtAddressLine1.Text;
            _driver.Individual.Address.AddressLine2 = txtAddressLine2.Text;
            _driver.Individual.Address.AddressLine3 = txtAddressLine3.Text;
            _driver.Individual.Address.PostTown     = txtPostTown.Text;
            _driver.Individual.Address.County       = txtCounty.Text;
            _driver.Individual.Address.PostCode     = txtPostCode.Text;

            if (_driver.Individual.Address.TrafficArea == null)
            {
                _driver.Individual.Address.TrafficArea = new Orchestrator.Entities.TrafficArea();
            }
            if (hidTrafficArea.Value != "")
            {
                _driver.Individual.Address.TrafficArea.TrafficAreaId = Convert.ToInt32(hidTrafficArea.Value);
            }

            if (_driver.Individual.Contacts == null)
            {
                _driver.Individual.Contacts = new Entities.ContactCollection();
            }

            Entities.Contact contact = _driver.Individual.Contacts.GetForContactType(eContactType.Telephone);
            if (null == contact)
            {
                contact             = new Entities.Contact();
                contact.ContactType = eContactType.Telephone;
                _driver.Individual.Contacts.Add(contact);
            }

            contact.ContactDetail = txtTelephone.Text;

            contact = _driver.Individual.Contacts.GetForContactType(eContactType.MobilePhone);
            if (null == contact)
            {
                contact             = new Entities.Contact();
                contact.ContactType = eContactType.MobilePhone;
                _driver.Individual.Contacts.Add(contact);
            }

            contact.ContactDetail = txtMobilePhone.Text;

            contact = _driver.Individual.Contacts.GetForContactType(eContactType.PersonalMobile);

            if (contact == null)
            {
                contact             = new Entities.Contact();
                contact.ContactType = eContactType.PersonalMobile;
                _driver.Individual.Contacts.Add(contact);
            }

            contact.ContactDetail = txtPersonalMobile.Text;

            // Retrieve the organisation and place it in viewstate
            Facade.IOrganisation          facOrganisation             = new Facade.Organisation();
            Entities.Organisation         m_organisation              = facOrganisation.GetForIdentityId(Orchestrator.Globals.Configuration.IdentityId);
            Entities.OrganisationLocation currentOrganisationLocation = null;
            Entities.Point   currentPoint   = null;
            Entities.Address currentAddress = null;
            if (m_organisation != null && m_organisation.Locations.Count > 0)
            {
                currentOrganisationLocation = m_organisation.Locations.GetHeadOffice();
                currentPoint   = currentOrganisationLocation.Point;
                currentAddress = currentPoint.Address;
            }

            if (cboPoint.SelectedValue != "")
            {
                _driver.HomePointId = Convert.ToInt32(cboPoint.SelectedValue);
            }
            else
            {
                _driver.HomePointId = currentPoint.PointId;
            }
            if (Convert.ToInt32(cboVehicle.SelectedValue) > 0)
            {
                _driver.AssignedVehicleId = Convert.ToInt32(cboVehicle.SelectedValue);
            }
            else
            {
                _driver.AssignedVehicleId = 0;
            }

            if (chkDelete.Checked)
            {
                _driver.Individual.IdentityStatus = eIdentityStatus.Deleted;
                _driver.ResourceStatus            = eResourceStatus.Deleted;
            }
            else
            {
                _driver.Individual.IdentityStatus = eIdentityStatus.Active;
                _driver.ResourceStatus            = eResourceStatus.Active;
            }

            if (_driver.Point == null && cboTown.SelectedValue != "")
            {
                _driver.Point = new Entities.Point();
            }

            if (cboDepot.SelectedValue != "")
            {
                _driver.DepotId = Convert.ToInt32(cboDepot.SelectedValue);
            }
            else
            {
                _driver.DepotId = currentOrganisationLocation.OrganisationLocationId;
            }

            if (_driver.Point != null)
            {
                decimal dLatitude = 0;
                decimal.TryParse(txtLatitude.Text, out dLatitude);
                decimal dLongtitude = 0;
                decimal.TryParse(txtLongitude.Text, out dLongtitude);

                _driver.Individual.Address.Latitude  = dLatitude;
                _driver.Individual.Address.Longitude = dLongtitude;
                _driver.Point.PostTown = new Entities.PostTown();
                Facade.IPostTown facPostTown = new Facade.Point();
                _driver.Point.IdentityId  = 0;
                _driver.Point.PostTown    = facPostTown.GetPostTownForTownId(Convert.ToInt32(cboTown.SelectedValue));
                _driver.Point.Address     = _driver.Individual.Address;
                _driver.Point.Latitude    = dLatitude;
                _driver.Point.Longitude   = dLongtitude;
                _driver.Point.Description = _driver.Individual.FirstNames + " " + _driver.Individual.LastName + " - Home";
                // We must try to set the radius of the point so that a new geofence
                // can be generated as we have just changed the point location through the address lookup.
                // not sure that this is neccessary for drivers though
                if (!String.IsNullOrEmpty(this.hdnSetPointRadius.Value))
                {
                    _driver.Point.Radius = Globals.Configuration.GPSDefaultGeofenceRadius;
                }
            }

            if (cboDriverType.SelectedValue != "")
            {
                _driver.DriverType.DriverTypeID = int.Parse(cboDriverType.SelectedValue);
            }
            else
            {
                _driver.DriverType.DriverTypeID = 1;
            }

            _driver.DigitalTachoCardId = txtDigitalTachoCardId.Text;
            _driver.IsAgencyDriver     = chkAgencyDriver.Checked;
            if (dteSD.SelectedDate != null)
            {
                _driver.StartDate = dteSD.SelectedDate.Value;
            }
            else
            {
                _driver.StartDate = null;
            }
            _driver.PayrollNo = txtPayrollNo.Text;

            string selectedCommunicationType = rblDefaultCommunicationType.SelectedValue;

            if (selectedCommunicationType == "None")
            {
                _driver.DefaultCommunicationTypeID = 0;
            }
            else
            {
                _driver.DefaultCommunicationTypeID = (int)Enum.Parse(typeof(eDriverCommunicationType), rblDefaultCommunicationType.SelectedValue);
            }

            _driver.OrgUnitIDs = trvResourceGrouping.CheckedNodes.Select(x => Int32.Parse(x.Attributes["OrgUnitID"])).ToList();

            // if the telematics option is visible use the selected solution (validation enforces a non-null selection)
            if (telematicsOption.Visible)
            {
                _driver.TelematicsSolution = (eTelematicsSolution?)Enum.Parse(typeof(eTelematicsSolution), cboTelematicsSolution.SelectedValue);
            }
            else
            {
                // if telematics option is not visible and we're creating, use the default
                if (!_isUpdate && ViewState["defaultTelematicsSolution"] != null)
                {
                    _driver.TelematicsSolution = (eTelematicsSolution)ViewState["defaultTelematicsSolution"];
                }
                //otherwise leave the telematics solution as it is
            }

            if (!string.IsNullOrEmpty(cboDriverPlanner.SelectedValue))
            {
                _driver.PlannerIdentityID = Convert.ToInt32(cboDriverPlanner.SelectedValue);
            }
            else
            {
                _driver.PlannerIdentityID = null;   //PROT-6452 - un-allocating a driver from its planner
            }

            if (chkAgencyDriver.Checked)
            {
                if (cboAgency.SelectedIndex == -1)
                {
                    var agency = new Agency()
                    {
                        Name = cboAgency.Text
                    };

                    using (var uow = DIContainer.CreateUnitOfWork())
                    {
                        var agenciesRepo = DIContainer.CreateRepository <IAgencyRepository>(uow);
                        agenciesRepo.Add(agency);
                        uow.SaveChanges();
                    }
                    _driver.AgencyId = agency.AgencyId;
                }
                else
                {
                    _driver.AgencyId = int.Parse(cboAgency.SelectedItem.Value);
                }
            }
            else
            {
                _driver.AgencyId = null;
            }


            ViewState["driver"] = _driver;
        }
Пример #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["identityId"] == string.Empty || Request.QueryString["identityId"] == null)
                {
                    return;
                }
                string identityId = Request.QueryString["identityId"].ToString();

                if (!string.IsNullOrEmpty(identityId))
                {
                    // Split string to see if we need to get details for an individual or an organisation

                    string[] s          = identityId.Split(":".ToCharArray());
                    string   driverType = s[0].ToLower().Trim();

                    switch (driverType)
                    {
                    case "organisation":
                        tblSubContractorIndividual.Visible = false;

                        int organisationId = Convert.ToInt32(s[1]);
                        BusinessLogicLayer.Organisation busOrg = new BusinessLogicLayer.Organisation();
                        Entities.Organisation           org    = busOrg.GetForIdentityId(organisationId);

                        Entities.OrganisationLocation headOffice = null;
                        if (org.Locations != null)
                        {
                            headOffice = org.Locations.GetHeadOffice();
                        }

                        lblOrganisationFullName.Text      = org.OrganisationDisplayName;
                        lblOrganisationMainTelephone.Text = org.Locations[0].TelephoneNumber;

                        if (headOffice != null && headOffice.Point != null)
                        {
                            lblOrganisationAddressLine1.Text = headOffice.Point.Address.AddressLine1;
                            lblOrganisationAddressLine2.Text = headOffice.Point.Address.AddressLine2;
                            lblOrganisationAddressLine3.Text = headOffice.Point.Address.AddressLine3;
                            lblOrganisationPostTown.Text     = headOffice.Point.Address.PostTown;
                            lblOrganisationCounty.Text       = headOffice.Point.Address.County;
                            lblOrganisationPostCode.Text     = headOffice.Point.Address.PostCode;
                        }

                        break;

                    case "individual":

                        tblSubContractorOrganisation.Visible = false;

                        int individualIdentityId             = Convert.ToInt32(s[1]);
                        DataAccess.IIndividual dacIndividual = new DataAccess.Individual();
                        DataSet dsIndividual = dacIndividual.GetContactDetails(individualIdentityId);

                        lblIndividualFullName.Text       = dsIndividual.Tables[0].Rows[0]["FullName"].ToString();
                        lblIndiviualHomePhone.Text       = dsIndividual.Tables[0].Rows[0]["HomePhone"].ToString();
                        lblIndividualMobilePhone.Text    = dsIndividual.Tables[0].Rows[0]["MobilePhone"].ToString();
                        lblIndividualPersonalMobile.Text = dsIndividual.Tables[0].Rows[0]["PersonalMobile"].ToString();
                        lblIndividualAddressLine1.Text   = dsIndividual.Tables[0].Rows[0]["AddressLine1"].ToString();
                        lblIndividualAddressLine2.Text   = dsIndividual.Tables[0].Rows[0]["AddressLine2"].ToString();
                        lblIndividualAddressLine3.Text   = dsIndividual.Tables[0].Rows[0]["AddressLine3"].ToString();
                        lblIndividualPostTown.Text       = dsIndividual.Tables[0].Rows[0]["PostTown"].ToString();
                        lblIndividualCounty.Text         = dsIndividual.Tables[0].Rows[0]["County"].ToString();
                        lblIndividualPostCode.Text       = dsIndividual.Tables[0].Rows[0]["PostCode"].ToString();

                        break;

                    default:

                        break;
                    }
                }
            }
        }