Exemple #1
0
        private void PopulatePoint()
        {
            if (ViewState["point"] == null)
            {
                point         = new Entities.Point();
                point.Address = new Entities.Address();
            }
            else
            {
                point = (Entities.Point)ViewState["point"];
            }

            point.Description = txtDescription.Text;
            point.PointCode   = this.txtPointCode.Text;

            //Always make a Point both Collection and Delivery
            point.Collect = true;
            point.Deliver = true;

            point.IdentityId = int.Parse(cboClient.SelectedValue);

            // Get the town object for the town
            point.PostTown = new Entities.PostTown();
            Facade.IPostTown facPostTown = new Facade.Point();
            point.PostTown = facPostTown.GetPostTownForTownId(Convert.ToInt32(cboTown.SelectedValue));

            point.Address.AddressLine1       = txtAddressLine1.Text;
            point.Address.AddressLine2       = txtAddressLine2.Text;
            point.Address.AddressLine3       = txtAddressLine3.Text;
            point.Address.AddressType        = eAddressType.Point;
            point.Address.PostTown           = txtPostTown.Text;
            point.Address.County             = txtCounty.Text;
            point.Address.PostCode           = txtPostCode.Text;
            point.Address.CountryDescription = this.cboCountry.Text;
            point.Address.CountryId          = Convert.ToInt32(this.cboCountry.SelectedValue);

            if (txtLongitude.Text.Length > 0 && txtLatitude.Text.Length > 0)
            {
                point.Longitude = point.Address.Longitude = Decimal.Parse(txtLongitude.Text);
                point.Latitude  = point.Address.Latitude = Decimal.Parse(txtLatitude.Text);
            }

            Facade.IOrganisation facOrganisation            = new Facade.Organisation();
            Orchestrator.Entities.Organisation organisation = facOrganisation.GetForIdentityId(point.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.Count == 0 || organisation.Defaults[0].DefaultGeofenceRadius == null)
                {
                    point.Radius = Globals.Configuration.GPSDefaultGeofenceRadius;
                }
                else
                {
                    point.Radius = organisation.Defaults[0].DefaultGeofenceRadius;
                }
            }

            if (point.Address.TrafficArea == null)
            {
                point.Address.TrafficArea = new Entities.TrafficArea();
            }

            if (m_isUpdate)
            {
                point.Address.TrafficArea.TrafficAreaId = Convert.ToInt32(cboTrafficArea.SelectedValue);
            }
            else
            {
                point.Address.TrafficArea.TrafficAreaId = 0; //Convert.ToInt32(hidTrafficArea.Value);
            }
            point.PointNotes = txtPointNotes.Text;

            // get the delivery point for saving
            point.DeliveryMatrix = Convert.ToInt32(this.cboDeliveryPeriod.SelectedValue);
        }
Exemple #2
0
        void btnAlterPoint_Click(object sender, EventArgs e)
        {
            Page.Validate("AlterPoint");

            if (Page.IsValid)
            {
                int ownerID = 0;

                #region Validate that the Point Name is Unique for this Organisation
                bool foundPointName = false;
                lblError.Visible = false;
                Orchestrator.Facade.IPoint facPoint = new Orchestrator.Facade.Point();
                Entities.Point             point    = facPoint.GetPointForPointId(PointID);

                ownerID = new Facade.Organisation().GetForName(cboNewPointOwner.Text).IdentityId;

                DataSet pointNames = facPoint.GetAllForOrganisation(ownerID, ePointType.Any, txtDescription.Text);
                foreach (DataRow row in pointNames.Tables[0].Rows)
                {
                    if (((string)row["Description"]) == txtDescription.Text && point.PointId != (int)row["PointId"])
                    {
                        foundPointName = true;
                    }
                }
                #endregion

                if (foundPointName)
                {
                    lblError.Text          = "The Description must be unique for this organisation.";
                    lblError.ForeColor     = Color.Red;
                    lblError.Visible       = true;
                    pnlPoint.Visible       = false;
                    pnlNewPoint.Visible    = true;
                    pnlFullAddress.Visible = false;
                }
                else
                {
                    Orchestrator.Facade.IPostTown  facPostTown = new Orchestrator.Facade.Point();
                    Orchestrator.Entities.PostTown town        = facPostTown.GetPostTownForTownId(int.Parse(cboClosestTown.SelectedValue));

                    // Set the point owner and description
                    point.OrganisationName = cboPoint.Text;
                    point.IdentityId       = ownerID;
                    point.Description      = txtDescription.Text;
                    point.PointCode        = this.txtPointCode.Text;

                    // Get the point type
                    switch (this.PointType)
                    {
                    case ePointType.Collect:
                        point.Collect = true;
                        break;

                    case ePointType.Deliver:
                        point.Deliver = true;
                        break;

                    case ePointType.Any:
                        point.Collect = true;
                        point.Deliver = true;
                        break;
                    }

                    // set the address
                    Orchestrator.Entities.Address address = new Orchestrator.Entities.Address();
                    address.AddressLine1       = txtAddressLine1.Text;
                    address.AddressLine2       = txtAddressLine2.Text;
                    address.AddressLine3       = txtAddressLine3.Text;
                    address.AddressType        = eAddressType.Point;
                    address.County             = txtCounty.Text;
                    address.CountryDescription = this.cboCountry.Text;
                    address.CountryId          = Convert.ToInt32(this.cboCountry.SelectedValue);
                    address.IdentityId         = ownerID;
                    decimal latitude = 0;
                    if (decimal.TryParse(hidLat.Value, out latitude))
                    {
                        address.Latitude = latitude;
                    }
                    decimal longitude = 0;
                    if (decimal.TryParse(hidLon.Value, out longitude))
                    {
                        address.Longitude = longitude;
                    }
                    address.PostCode = txtPostCode.Text.ToUpper();
                    address.PostTown = txtPostTown.Text;
                    if (address.TrafficArea == null)
                    {
                        address.TrafficArea = new Orchestrator.Entities.TrafficArea();
                    }

                    Facade.IOrganisation facOrganisation            = new Facade.Organisation();
                    Orchestrator.Entities.Organisation organisation = facOrganisation.GetForIdentityId(point.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 != null)
                        {
                            if (organisation.Defaults.Count > 0 && organisation.Defaults[0].DefaultGeofenceRadius.HasValue)
                            {
                                point.Radius = organisation.Defaults[0].DefaultGeofenceRadius;
                            }
                            else
                            {
                                point.Radius = Globals.Configuration.GPSDefaultGeofenceRadius;
                            }
                        }
                        else
                        {
                            point.Radius = Globals.Configuration.GPSDefaultGeofenceRadius;
                        }
                    }

                    // Get the Traffic Area for this Point
                    address.TrafficArea.TrafficAreaId = Convert.ToInt32(cboTrafficArea.SelectedValue);

                    point.Address   = address;
                    point.Longitude = address.Longitude;
                    point.Latitude  = address.Latitude;
                    point.PostTown  = town;

                    point.PointNotes = txtPointNotes.Text;

                    if (ClientUserOrganisationIdentityID > 0)
                    {
                        point.PointStateId = ePointState.Unapproved;
                    }
                    else
                    {
                        point.PointStateId = ePointState.Approved;
                    }

                    point.PhoneNumber = txtPhoneNumber.Text;

                    string userId = ((Orchestrator.Entities.CustomPrincipal)Page.User).UserName;

                    // Create the new point
                    Entities.FacadeResult result = facPoint.Update(point, userId);

                    if (result.Success)
                    {
                        // get the Point with all parts populated.
                        this.SelectedPoint     = point;
                        cboPoint.Text          = point.Description;
                        cboPoint.SelectedValue = point.IdentityId.ToString() + "," + point.PointId.ToString();

                        pnlNewPoint.Visible             = false;
                        pnlPoint.Visible                = true;
                        inpCreateNewPointSelected.Value = string.Empty;
                    }
                    else
                    {
                        for (int i = 0; i < result.Infringements.Count; i++)
                        {
                            lblError.Text += result.Infringements[i].Description + Environment.NewLine;
                        }

                        lblError.ForeColor     = Color.Red;
                        lblError.Visible       = true;
                        pnlPoint.Visible       = false;
                        pnlNewPoint.Visible    = true;
                        pnlFullAddress.Visible = false;
                    }
                }
            }
        }