Ejemplo n.º 1
0
        public void DeleteDaps(List <int> dapIDsToDelete)
        {
            //Validate Input
            foreach (int dapID in dapIDsToDelete)
            {
                if (dapID.IsInvalidKey())
                {
                    BusinessLayerHelper.ThrowErrorForInvalidDataKey("DapID");
                }
            }

            List <Dap> dapsToBeDeleted = new List <Dap>();

            foreach (int dapID in dapIDsToDelete)
            {
                Dap dap = new Dap {
                    DapID = dapID
                };
                _DatabaseContext.Daps.Attach(dap);
                _DatabaseContext.Daps.DeleteObject(dap);
                dapsToBeDeleted.Add(dap);
                OnDapDeleting(dap);
            }

            int numberOfAffectedRows = _DatabaseContext.SaveChanges();

            if (numberOfAffectedRows != dapIDsToDelete.Count)
            {
                throw new DataNotUpdatedException("One or more dap records have not been deleted.");
            }
            foreach (Dap dapToBeDeleted in dapsToBeDeleted)
            {
                OnDapDeleted(dapToBeDeleted);
            }
        }
Ejemplo n.º 2
0
        public void UpdateDap(Dap updatedDap)
        {
            // Validate Parameters
            if (updatedDap == null)
            {
                throw (new ArgumentNullException("updatedDap"));
            }

            // Validate Primary key value
            if (updatedDap.DapID.IsInvalidKey())
            {
                BusinessLayerHelper.ThrowErrorForInvalidDataKey("DapID");
            }

            // Apply business rules
            OnDapSaving(updatedDap);
            OnDapUpdating(updatedDap);

            //attaching and making ready for parsistance
            if (updatedDap.EntityState == EntityState.Detached)
            {
                _DatabaseContext.Daps.Attach(updatedDap);
            }
            _DatabaseContext.ObjectStateManager.ChangeObjectState(updatedDap, System.Data.EntityState.Modified);            //this line makes the code un-testable!
            int numberOfAffectedRows = _DatabaseContext.SaveChanges();

            if (numberOfAffectedRows == 0)
            {
                throw new DataNotUpdatedException("No dap updated!");
            }

            //Apply business workflow
            OnDapUpdated(updatedDap);
            OnDapSaved(updatedDap);
        }
Ejemplo n.º 3
0
        public void DeleteDap(Dap dapToBeDeleted)
        {
            //Validate Input
            if (dapToBeDeleted == null)
            {
                throw (new ArgumentNullException("dapToBeDeleted"));
            }

            // Validate Primary key value
            if (dapToBeDeleted.DapID.IsInvalidKey())
            {
                BusinessLayerHelper.ThrowErrorForInvalidDataKey("DapID");
            }

            OnDapSaving(dapToBeDeleted);
            OnDapDeleting(dapToBeDeleted);

            if (dapToBeDeleted.EntityState == EntityState.Detached)
            {
                _DatabaseContext.Daps.Attach(dapToBeDeleted);
            }
            _DatabaseContext.Daps.DeleteObject(dapToBeDeleted);
            int numberOfAffectedRows = _DatabaseContext.SaveChanges();

            if (numberOfAffectedRows == 0)
            {
                throw new DataNotUpdatedException("No Dap deleted!");
            }

            OnDapDeleted(dapToBeDeleted);
            OnDapSaved(dapToBeDeleted);
        }
Ejemplo n.º 4
0
        public virtual int CreateNewDap(Dap newDap)
        {
            // Validate Parameters
            if (newDap == null)
            {
                throw (new ArgumentNullException("newDap"));
            }

            // Apply business rules
            OnDapSaving(newDap);
            OnDapCreating(newDap);

            _DatabaseContext.Daps.AddObject(newDap);
            int numberOfAffectedRows = _DatabaseContext.SaveChanges();

            if (numberOfAffectedRows == 0)
            {
                throw new DataNotUpdatedException("No dap created!");
            }

            // Apply business workflow
            OnDapCreated(newDap);
            OnDapSaved(newDap);

            return(newDap.DapID);
        }
Ejemplo n.º 5
0
 partial void OnDapDeleting(Dap dap);
Ejemplo n.º 6
0
 partial void OnDapSaved(Dap dap);
Ejemplo n.º 7
0
 partial void OnDapUpdated(Dap dap);
Ejemplo n.º 8
0
 partial void OnDapUpdating(Dap dap);
Ejemplo n.º 9
0
        protected void ButtonDeleteSelected_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Create a List to hold the ProjectID values to delete
                List <Int32> TreeDetailIDsToDelete       = new List <Int32>();
                List <Int32> ProjectOrganismsIDsToDelete = new List <Int32>();
                List <Int32> DapIDsToDelete = new List <Int32>();

                // Iterate through the Projects.Rows property
                foreach (GridViewRow row in gridViewTreeDetails.Rows)
                {
                    // Access the CheckBox
                    CheckBox cb = (CheckBox)(row.FindControl("chkTreeDetailsSelector"));
                    if (cb != null && cb.Checked)
                    {
                        // Save the ProjectID value for deletion
                        // First, get the ProjectID for the selected row
                        Int32 treeDetailsID = (Int32)gridViewTreeDetails.DataKeys[row.RowIndex].Value;
                        Eisk.BusinessEntities.TreeDetail treeDetail = new TreeDetailBLL().GetTreeDetailByTreeDetailsID(treeDetailsID);

                        List <Int32> tempDaps = new DapBLL().GetDapsByTreeDetailsID(treeDetailsID).Select(instance => instance.DapID).ToList();

                        // Add it to the List...
                        ProjectOrganismsIDsToDelete.Add(treeDetail.ProjectOrganismID);
                        TreeDetailIDsToDelete.Add(treeDetail.TreeDetailsID);
                        DapIDsToDelete.AddRange(tempDaps);
                    }
                }

                using (DatabaseContext _DatabaseContext = new DatabaseContext())
                {
                    foreach (int dapID in DapIDsToDelete)
                    {
                        Dap dap = _DatabaseContext.Daps.First(instance => instance.DapID == dapID);
                        _DatabaseContext.Daps.DeleteObject(dap);

                        _DatabaseContext.SaveChanges();
                    }
                    foreach (int treeDetailsID in TreeDetailIDsToDelete)
                    {
                        TreeDetail treeDetail = _DatabaseContext.TreeDetails.First(instance => instance.TreeDetailsID == treeDetailsID);
                        _DatabaseContext.TreeDetails.DeleteObject(treeDetail);

                        _DatabaseContext.SaveChanges();
                    }
                    foreach (int ProjectOrganismID in ProjectOrganismsIDsToDelete)
                    {
                        Project_Organisms project_Organism = _DatabaseContext.Project_Organisms.First(instance => instance.ProjectOrganismID == ProjectOrganismID);
                        _DatabaseContext.Project_Organisms.DeleteObject(project_Organism);

                        _DatabaseContext.SaveChanges();
                    }

                    //Sort Numbers after deleting
                    int projectIDINT = Convert.ToInt32(RouteData.Values["Project_id"]);
                    List <TreeDetail> treeDetails =
                        _DatabaseContext.TreeDetails
                        .Where(instance => instance.Project_Organisms.ProjectID == projectIDINT)
                        .OrderBy(instance => instance.Number)
                        .ToList();

                    int number = 1;
                    foreach (TreeDetail tDetail in treeDetails)
                    {
                        tDetail.Number = number;
                        number++;
                    }
                    //

                    _DatabaseContext.SaveChanges();
                }

                // Add a confirmation message
                ltlMessage.Text += String.Format(MessageFormatter.GetFormattedSuccessMessage("Eliminación de árboles satisfactoria. <b>{0}</b> árboles eliminados"), ProjectOrganismsIDsToDelete.Count);
            }
            catch (Exception ex)
            {
                ltlMessage.Text = ExceptionManager.DoLogAndGetFriendlyMessageForException(ex);
            }

            //binding the grid
            gridViewTreeDetails.PageIndex = 0;
            gridViewTreeDetails.PageSize  = Convert.ToInt32(ddlPageSize.SelectedValue);
            gridViewTreeDetails.DataBind();
        }
Ejemplo n.º 10
0
    protected void FormViewTlProject_Organism_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
        User editor = new UserBLL().GetUserByUserName((HttpContext.Current.User.Identity).Name);

        Project_Organisms project_Organisms = new Project_OrganismsBLL().GetProject_OrganismsByProjectOrganismID((int)e.Keys["ProjectOrganismID"]);

        using (DatabaseContext _DatabaseContext = new DatabaseContext())
        {
            // TreeDetail
            TextBox     txtVaras      = (TextBox)formViewTlProject_Organism.FindControl("txtVaras");
            HiddenField hfDap         = (HiddenField)formViewTlProject_Organism.FindControl("hfDap");
            TextBox     txtHeight     = (TextBox)formViewTlProject_Organism.FindControl("txtHeight");
            TextBox     txtCommentary = (TextBox)formViewTlProject_Organism.FindControl("txtCommentary");

            Label   lblNumber = (Label)formViewTlProject_Organism.FindControl("lblNumber");
            TextBox txtX      = (TextBox)formViewTlProject_Organism.FindControl("txtX");
            TextBox txtY      = (TextBox)formViewTlProject_Organism.FindControl("txtY");
            TextBox txtLat    = (TextBox)formViewTlProject_Organism.FindControl("txtLat");
            TextBox txtLon    = (TextBox)formViewTlProject_Organism.FindControl("txtLon");

            RadioButtonList rblActionProposed = (RadioButtonList)formViewTlProject_Organism.FindControl("rblActionProposed");
            RadioButtonList rblCondition      = (RadioButtonList)formViewTlProject_Organism.FindControl("rblCondition");

            // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
            // Edgardo Ramos - 20130928
            CheckBox chkLittoral     = (CheckBox)formViewTlProject_Organism.FindControl("chkLittoral");
            CheckBox chkMaritimeZone = (CheckBox)formViewTlProject_Organism.FindControl("chkMaritimeZone");
            CheckBox cbCepa          = (CheckBox)formViewTlProject_Organism.FindControl("cbCepa");
            // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

            TreeDetail treeDetail = _DatabaseContext.TreeDetails.First(instance => instance.ProjectOrganismID == project_Organisms.ProjectOrganismID);

            //Delete existing Daps
            foreach (Dap item in _DatabaseContext.Daps.Where(instance => instance.TreeDetailsID == treeDetail.TreeDetailsID).ToList())
            {
                _DatabaseContext.Daps.DeleteObject(item);
            }

            if (cbCepa.Checked)// Is Cepa
            {
                treeDetail.Dap         = 0;
                treeDetail.Dap_Counter = 0;

                treeDetail.Varas = Convert.ToInt32(string.IsNullOrEmpty(txtVaras.Text) ? "0" : txtVaras.Text);
            }
            else
            {
                treeDetail.Varas = 0;

                var dapsList = hfDap.Value.Split(',').ToList();
                if (dapsList.Count == 1) // Solo un Dap
                {
                    decimal dap = Convert.ToDecimal(dapsList[0]);

                    treeDetail.Dap         = dap;
                    treeDetail.Dap_Counter = 1;

                    Dap dapObj = new Dap();
                    dapObj.DapValue      = dap;
                    dapObj.TreeDetailsID = treeDetail.TreeDetailsID;
                    dapObj.TreeDetailReference.EntityKey = treeDetail.EntityKey;

                    _DatabaseContext.Daps.AddObject(dapObj);
                }
                else // 1 o Mas de un Dap
                {
                    string[] daps     = hfDap.Value.Split(',');
                    double   dapTotal = 0;
                    foreach (string dap in daps)
                    {
                        dapTotal += Convert.ToDouble(dap);
                    }
                    treeDetail.Dap         = Convert.ToDecimal(Math.Round(Math.Sqrt(Math.Pow(dapTotal, 2D) / Convert.ToDouble(daps.Count())) * 100) / 100);
                    treeDetail.Dap_Counter = daps.Count();

                    foreach (string dapString in daps)
                    {
                        Dap dap = new Dap();
                        dap.DapValue      = Convert.ToDecimal(dapString);
                        dap.TreeDetailsID = treeDetail.TreeDetailsID;
                        dap.TreeDetailReference.EntityKey = treeDetail.EntityKey;

                        _DatabaseContext.Daps.AddObject(dap);
                    }
                }
            }

            treeDetail.Height     = Convert.ToDecimal(txtHeight.Text);
            treeDetail.Commentary = (txtCommentary.Text.Length > txtCommentary.MaxLength) ? txtCommentary.Text.Substring(0, txtCommentary.MaxLength) : txtCommentary.Text;

            treeDetail.Number = Convert.ToInt32(lblNumber.Text);

            // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
            // Edgardo Ramos - 20130928
            decimal         dec;
            RadioButtonList rblPosition = (RadioButtonList)formViewTlProject_Organism.FindControl("rblPosition");

            if (rblPosition.SelectedValue == "0") // Nad83
            {
                treeDetail.X = decimal.TryParse(txtX.Text, out dec) ? Convert.ToDecimal(txtX.Text) : 0;
                treeDetail.Y = decimal.TryParse(txtY.Text, out dec) ? Convert.ToDecimal(txtY.Text) : 0;

                if (treeDetail.X != 0 && treeDetail.Y != 0)
                {
                    Dictionary <string, object> anewpointObj = Utility.ConvertToLatLng(treeDetail.X.ToString(), treeDetail.Y.ToString(), @"~/App_Resources/client-scripts/tl/");

                    treeDetail.Lat = Convert.ToDecimal(anewpointObj["y"]);
                    txtLat.Text    = treeDetail.Lat.ToString();
                    treeDetail.Lon = Convert.ToDecimal(anewpointObj["x"]);
                    txtLon.Text    = treeDetail.Lon.ToString();
                }
                else
                {
                    treeDetail.Lat = 0;
                    treeDetail.Lon = 0;
                }
            }
            else // StatePlanes
            {
                treeDetail.Lat = decimal.TryParse(txtLat.Text, out dec) ? Convert.ToDecimal(txtLat.Text) : 0;
                treeDetail.Lon = decimal.TryParse(txtLon.Text, out dec) ? Convert.ToDecimal(txtLon.Text) : 0;

                if (treeDetail.Lat != 0 && treeDetail.Lon != 0)
                {
                    Dictionary <string, object> anewpointObj = Utility.ConvertToStatePlane(treeDetail.Lon.ToString(), treeDetail.Lat.ToString(), @"~/App_Resources/client-scripts/tl/");

                    treeDetail.X = Convert.ToDecimal(anewpointObj["x"]);
                    txtX.Text    = treeDetail.X.ToString();
                    treeDetail.Y = Convert.ToDecimal(anewpointObj["y"]);
                    txtY.Text    = treeDetail.Y.ToString();
                }
                else
                {
                    treeDetail.X = 0;
                    treeDetail.Y = 0;
                }
            }

            //treeDetail.X = Convert.ToDecimal(txtX.Text);
            //treeDetail.Y = Convert.ToDecimal(txtY.Text);
            //treeDetail.Lat = Convert.ToDecimal(txtLat.Text);
            //treeDetail.Lon = Convert.ToDecimal(txtLon.Text);

            treeDetail.Littoral     = chkLittoral.Checked;
            treeDetail.MaritimeZone = chkMaritimeZone.Checked;

            // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

            treeDetail.EditedDate   = DateTime.Now;
            treeDetail.EditorUserID = editor.UserID;

            ActionProposed actionProposed = new ActionProposedBLL().GetActionProposedByActionProposedID(Convert.ToInt32(rblActionProposed.SelectedValue));
            treeDetail.ActionProposedID = actionProposed.ActionProposedID;
            treeDetail.ActionProposedReference.EntityKey = actionProposed.EntityKey;

            Condition condition = new ConditionBLL().GetConditionByConditionID(Convert.ToInt32(rblCondition.SelectedValue));
            treeDetail.ConditionID = condition.ConditionID;
            treeDetail.ConditionReference.EntityKey = condition.EntityKey;

            treeDetail.ProjectOrganismID = project_Organisms.ProjectOrganismID;
            treeDetail.Project_OrganismsReference.EntityKey = project_Organisms.EntityKey;

            _DatabaseContext.SaveChanges();
            //
        }

        Type myType = (typeof(Project_Organisms));

        PropertyInfo[] props = myType.GetProperties();

        string[] arrNewValues = new string[e.NewValues.Keys.Count];
        e.NewValues.Keys.CopyTo(arrNewValues, 0);

        foreach (var prop in props)
        {
            if (("System.String,System.Int,System.DateTime,System.Guid,System.Boolean").IndexOf((prop.PropertyType).FullName) >= 0) // Si la propiedad es de tipo Guid, String, Int, Boolean o DateTime
            {
                if (!arrNewValues.Contains(prop.Name))
                {
                    e.NewValues[prop.Name] = prop.GetValue(project_Organisms, null);
                }
            }
        }

        e.NewValues["ProjectID"]  = RouteData.Values["Project_id"].ToString();
        e.NewValues["OrganismID"] = ((HiddenField)formViewTlProject_Organism.FindControl("hfOrganism")).Value;

        e.NewValues["EditorUserId"] = editor.UserID.ToString();
        e.NewValues["EditedDate"]   = DateTime.Now;
    }
Ejemplo n.º 11
0
        /// <summary>
        /// Add this dataset into the kml document
        /// </summary>
        /// <param name="oDapCommand"></param>
        /// <param name="oXmlNode"></param>
        /// <param name="oDataset"></param>
        private static void OutputDataset(Command oDapCommand, System.Xml.XmlNode oXmlNode, Dap.Common.DataSet oDataset)
        {
            System.Xml.XmlElement oDisplayMapNode;
            System.Xml.XmlAttribute oAttr;

            // --- write out the dataset node ---

            oDisplayMapNode = oXmlNode.OwnerDocument.CreateElement("display_map");

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("type");
            oAttr.Value = "DAP";
            oDisplayMapNode.Attributes.Append(oAttr);

            string strDapUrl = oDapCommand.Url;
            if (strDapUrl.ToUpper().StartsWith("HTTP://"))
                strDapUrl = strDapUrl.Substring(7);
            oAttr = oXmlNode.OwnerDocument.CreateAttribute("server");
            oAttr.Value = strDapUrl;
            oDisplayMapNode.Attributes.Append(oAttr);

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("layername");
            oAttr.Value = oDataset.Name;
            oDisplayMapNode.Attributes.Append(oAttr);

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("datasetname");
            oAttr.Value = oDataset.Name;
            oDisplayMapNode.Attributes.Append(oAttr);

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("layertitle");
            oAttr.Value = oDataset.Title;
            oDisplayMapNode.Attributes.Append(oAttr);

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("datasettype");
            oAttr.Value = oDataset.Type;
            oDisplayMapNode.Attributes.Append(oAttr);

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("edition");
            oAttr.Value = oDataset.Edition;
            oDisplayMapNode.Attributes.Append(oAttr);

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("hierarchy");
            oAttr.Value = oDataset.Hierarchy;
            oDisplayMapNode.Attributes.Append(oAttr);

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("minx");
            oAttr.Value = oDataset.Boundary.MinX.ToString(System.Globalization.CultureInfo.InvariantCulture);
            oDisplayMapNode.Attributes.Append(oAttr);

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("miny");
            oAttr.Value = oDataset.Boundary.MinY.ToString(System.Globalization.CultureInfo.InvariantCulture);
            oDisplayMapNode.Attributes.Append(oAttr);

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("maxx");
            oAttr.Value = oDataset.Boundary.MaxX.ToString(System.Globalization.CultureInfo.InvariantCulture);
            oDisplayMapNode.Attributes.Append(oAttr);

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("maxy");
            oAttr.Value = oDataset.Boundary.MaxY.ToString(System.Globalization.CultureInfo.InvariantCulture);
            oDisplayMapNode.Attributes.Append(oAttr);

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("height");
            oAttr.Value = "0";
            oDisplayMapNode.Attributes.Append(oAttr);

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("size");
            oAttr.Value = "256";
            oDisplayMapNode.Attributes.Append(oAttr);

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("levels");
            oAttr.Value = DappleUtils.Levels(oDapCommand, oDataset).ToString();
            oDisplayMapNode.Attributes.Append(oAttr);

            oAttr = oXmlNode.OwnerDocument.CreateAttribute("levelzerotilesize");
            oAttr.Value = DappleUtils.LevelZeroTileSize(oDataset).ToString(System.Globalization.CultureInfo.InvariantCulture);
            oDisplayMapNode.Attributes.Append(oAttr);

            oXmlNode.AppendChild(oDisplayMapNode);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Add this dataset into the kml document
        /// </summary>
        /// <param name="strWmsUrl"></param>
        /// <param name="oKmlNode"></param>
        /// <param name="oDataset"></param>
        private static void OutputDataset(string strWmsUrl, System.Xml.XmlNode oKmlNode, Dap.Common.DataSet oDataset)
        {
            string strHierarchy = oDataset.Hierarchy.Trim('/');
            System.Xml.XmlNode oCurFolder = oKmlNode;
            System.Xml.XmlNode oNextFolder;
            System.Xml.XmlElement oGroundOverlayNode;
            System.Xml.XmlElement oNameNode;
            System.Xml.XmlElement oOpenNode;
            System.Xml.XmlElement oIconNode;
            System.Xml.XmlElement oHRefNode;
            System.Xml.XmlElement oViewRefreshTimeNode;
            System.Xml.XmlElement oViewBoundScaleNode;
            System.Xml.XmlElement oViewFormatNode;
            System.Xml.XmlElement oViewRefreshModeNode;
            System.Xml.XmlElement oWGS84BoundingBoxNode;
            System.Xml.XmlElement oCNode;
            System.Xml.XmlElement oTitleNode;
            System.Xml.XmlElement oVisibleNode;
            System.Xml.XmlAttribute oOutputAttr;

            // --- create the folder structure ---

            string[] oFolders = strHierarchy.Split('/');
            foreach (string strFolderName in oFolders)
            {
                oNextFolder = FindFolder(oCurFolder, strFolderName);

                if (oNextFolder == null)
                {

                    oNextFolder = oKmlNode.OwnerDocument.CreateElement("Folder", "http://earth.google.com/kml/2.1");

                    oTitleNode = oKmlNode.OwnerDocument.CreateElement("name", "http://earth.google.com/kml/2.1");
                    oTitleNode.InnerText = strFolderName;
                    oNextFolder.AppendChild(oTitleNode);

                    oVisibleNode = oKmlNode.OwnerDocument.CreateElement("visibility", "http://earth.google.com/kml/2.1");
                    oVisibleNode.InnerText = "1";
                    oNextFolder.AppendChild(oVisibleNode);

                    oOpenNode = oKmlNode.OwnerDocument.CreateElement("open", "http://earth.google.com/kml/2.1");
                    oOpenNode.InnerText = "0";
                    oNextFolder.AppendChild(oOpenNode);
                    oCurFolder.AppendChild(oNextFolder);
                }
                oCurFolder = oNextFolder;
            }

            // --- write out the dataset node ---

            oGroundOverlayNode = oKmlNode.OwnerDocument.CreateElement("GroundOverlay", "http://earth.google.com/kml/2.1");
            oOutputAttr = oKmlNode.OwnerDocument.CreateAttribute("id");
            oOutputAttr.Value = oDataset.Name;
            oGroundOverlayNode.Attributes.Append(oOutputAttr);

            oNameNode = oKmlNode.OwnerDocument.CreateElement("name", "http://earth.google.com/kml/2.1");
            oNameNode.InnerText = oDataset.Title;
            oGroundOverlayNode.AppendChild(oNameNode);

            oOpenNode = oKmlNode.OwnerDocument.CreateElement("open", "http://earth.google.com/kml/2.1");
            oOpenNode.InnerText = "0";
            oGroundOverlayNode.AppendChild(oOpenNode);

            oIconNode = oKmlNode.OwnerDocument.CreateElement("Icon", "http://earth.google.com/kml/2.1");
            oGroundOverlayNode.AppendChild(oIconNode);

            oHRefNode = oKmlNode.OwnerDocument.CreateElement("href", "http://earth.google.com/kml/2.1");
            oHRefNode.InnerText = strWmsUrl + "?Request=googlemap&LAYERID=" + oDataset.Name;
            oIconNode.AppendChild(oHRefNode);

            oViewRefreshModeNode = oKmlNode.OwnerDocument.CreateElement("viewRefreshMode", "http://earth.google.com/kml/2.1");
            oViewRefreshModeNode.InnerText = "onStop";
            oIconNode.AppendChild(oViewRefreshModeNode);

            oViewRefreshTimeNode = oKmlNode.OwnerDocument.CreateElement("viewRefreshTime", "http://earth.google.com/kml/2.1");
            oViewRefreshTimeNode.InnerText = "0.5";
            oIconNode.AppendChild(oViewRefreshTimeNode);

            oViewBoundScaleNode = oKmlNode.OwnerDocument.CreateElement("viewBoundScale", "http://earth.google.com/kml/2.1");
            oViewBoundScaleNode.InnerText = "1.2";
            oIconNode.AppendChild(oViewBoundScaleNode);

            oViewFormatNode = oKmlNode.OwnerDocument.CreateElement("viewFormat", "http://earth.google.com/kml/2.1");
            oViewFormatNode.InnerText = "BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]";
            oIconNode.AppendChild(oViewFormatNode);

            oWGS84BoundingBoxNode = oKmlNode.OwnerDocument.CreateElement("LatLonBox", "http://earth.google.com/kml/2.1");
            oGroundOverlayNode.AppendChild(oWGS84BoundingBoxNode);

            oCNode = oKmlNode.OwnerDocument.CreateElement("north", "http://earth.google.com/kml/2.1");
            oCNode.InnerText = oDataset.Boundary.MaxY.ToString(System.Globalization.CultureInfo.InvariantCulture);
            oWGS84BoundingBoxNode.AppendChild(oCNode);

            oCNode = oKmlNode.OwnerDocument.CreateElement("south", "http://earth.google.com/kml/2.1");
            oCNode.InnerText = oDataset.Boundary.MinY.ToString(System.Globalization.CultureInfo.InvariantCulture);
            oWGS84BoundingBoxNode.AppendChild(oCNode);

            oCNode = oKmlNode.OwnerDocument.CreateElement("east", "http://earth.google.com/kml/2.1");
            oCNode.InnerText = oDataset.Boundary.MaxX.ToString(System.Globalization.CultureInfo.InvariantCulture);
            oWGS84BoundingBoxNode.AppendChild(oCNode);

            oCNode = oKmlNode.OwnerDocument.CreateElement("west", "http://earth.google.com/kml/2.1");
            oCNode.InnerText = oDataset.Boundary.MinX.ToString(System.Globalization.CultureInfo.InvariantCulture);
            oWGS84BoundingBoxNode.AppendChild(oCNode);

            oCurFolder.AppendChild(oGroundOverlayNode);
        }
Ejemplo n.º 13
0
        protected void btnCloneSelected_Click(object sender, EventArgs e)
        {
            pnlCloneError.Style["display"] = "none";
            lblCloneError.Text             = "";
            string invalidMessage = "";
            string successMessage = "";

            bool dapOrVaras = false;

            if (pnlCloneDap.Visible)
            {
                dapOrVaras = chkCloneDap.Checked;
            }
            else
            {
                dapOrVaras = chkCloneVaras.Checked;
            }

            #region Validate Characteristics
            if (
                !chkCloneNombre.Checked &&
                !dapOrVaras &&
                !chkAltura.Checked &&
                !chkAcciónPropuesta.Checked &&
                !chkCondicion.Checked &&
                !chkLitoral.Checked &&
                !chkMaritimoTerrestre.Checked &&
                !chkComentarios.Checked
                )
            {
                invalidMessage += " • Seleccione al menos una característica <br />";
            }
            #endregion

            #region Validate Árbol a ser Clonado
            Project_Organisms project_OrganismBase;
            if (!Project_OrganismsBLL.TryParse_ByNumber(txtCloneBase.Text, out project_OrganismBase))
            {
                invalidMessage = " • Número del Árbol a ser Copiado Inválido<br />";
            }
            #endregion

            List <Project_Organisms> ProjectOrganismsIDsToClone = new List <Project_Organisms>();
            Project_Organisms        project_OrganismFROM       = null;
            Project_Organisms        project_OrganismTO         = null;

            if (!rbtCloneRange.Checked && rbtCloneSelect.Checked)
            {// Selected
                #region validate selected

                // Iterate through the Projects.Rows property
                foreach (GridViewRow row in gridViewTreeDetails.Rows)
                {
                    // Access the CheckBox
                    CheckBox cb = (CheckBox)(row.FindControl("chkTreeDetailsSelector"));
                    if (cb != null && cb.Checked)
                    {
                        // Save the ProjectID value for deletion
                        // First, get the ProjectID for the selected row
                        Int32 treeDetailsID = (Int32)gridViewTreeDetails.DataKeys[row.RowIndex].Value;
                        Eisk.BusinessEntities.TreeDetail treeDetail = new TreeDetailBLL().GetTreeDetailByTreeDetailsID(treeDetailsID);
                        ProjectOrganismsIDsToClone.Add(treeDetail.Project_Organisms);
                    }
                }

                if (ProjectOrganismsIDsToClone.Count == 0)
                {
                    invalidMessage += " • Para copiar las características a los árboles previamente seleccionados debe seleccionar al menos uno <br />";
                }
                #endregion
            }
            else
            {// Range
                #region validate range

                if (!Project_OrganismsBLL.TryParse_ByNumber(txtCloneFrom.Text, out project_OrganismFROM))
                {
                    invalidMessage += " • Número del Árbol " + '"' + "Desde" + '"' + " Inválido <br />";
                }

                if (!Project_OrganismsBLL.TryParse_ByNumber(txtCloneTo.Text, out project_OrganismTO))
                {
                    invalidMessage += " • Número del Árbol " + '"' + "Hasta" + '"' + " Inválido <br />";
                }

                if (project_OrganismFROM != null && project_OrganismTO != null)
                {
                    if (project_OrganismFROM.TreeDetails.First().Number > project_OrganismTO.TreeDetails.First().Number)
                    {
                        invalidMessage += " • Número del Árbol " + '"' + "Desde" + '"' + " menor que " + '"' + "Hasta" + '"' + " <br />";
                    }
                }
                #endregion
            }

            if (!string.IsNullOrEmpty(invalidMessage))
            {
                pnlCloneError.Style["display"] = "block";
                pnlLoading.Style["display"]    = "block";
                pnlClone.Style["display"]      = "block";
                pnlCloneRange.Style["display"] = (rbtCloneRange.Checked) ? "block" : "none";
                lblCloneError.Text             = "<strong>Favor validar los siguientes detalles:</strong><br />" + invalidMessage;
                return;
            }
            else
            {
                using (DatabaseContext _DatabaseContext = new DatabaseContext())
                {
                    var treeDetailBASE = project_OrganismBase.TreeDetails.First();
                    if (!rbtCloneRange.Checked && rbtCloneSelect.Checked)
                    {// Selected
                        foreach (var projectOrganism in ProjectOrganismsIDsToClone)
                        {
                            var projectOrganismTHIS = _DatabaseContext.Project_Organisms.Where(i => i.ProjectOrganismID == projectOrganism.ProjectOrganismID).First();
                            var treeDetailTHIS      = _DatabaseContext.TreeDetails.First(i => i.ProjectOrganismID == projectOrganismTHIS.ProjectOrganismID);

                            if (chkCloneNombre.Checked)
                            {
                                Organism organism = new OrganismBLL().GetOrganismByOrganismID(project_OrganismBase.OrganismID);
                                projectOrganismTHIS.OrganismID = organism.OrganismID;
                                projectOrganismTHIS.OrganismReference.EntityKey = organism.EntityKey;
                            }

                            foreach (var item in _DatabaseContext.Daps.Where(instance => instance.TreeDetailsID == treeDetailTHIS.TreeDetailsID).ToList())
                            {
                                _DatabaseContext.Daps.DeleteObject(item);
                            }

                            if (chkCloneVaras.Checked)
                            {
                                treeDetailTHIS.Varas = treeDetailBASE.Varas;
                            }

                            if (chkCloneDap.Checked)
                            {
                                treeDetailTHIS.Dap         = treeDetailBASE.Dap;
                                treeDetailTHIS.Dap_Counter = treeDetailBASE.Dap_Counter;

                                foreach (var dap in treeDetailBASE.Daps)
                                {
                                    Dap dapTHIS = new Dap();
                                    dapTHIS.DapValue      = dap.DapValue;
                                    dapTHIS.TreeDetailsID = treeDetailTHIS.TreeDetailsID;
                                    dapTHIS.TreeDetailReference.EntityKey = treeDetailTHIS.EntityKey;

                                    _DatabaseContext.Daps.AddObject(dapTHIS);
                                }
                            }

                            if (chkAltura.Checked)
                            {
                                treeDetailTHIS.Height = treeDetailBASE.Height;
                            }

                            if (chkAcciónPropuesta.Checked)
                            {
                                ActionProposed actionProposed = new ActionProposedBLL().GetActionProposedByActionProposedID(Convert.ToInt32(treeDetailBASE.ActionProposedID));
                                treeDetailTHIS.ActionProposedID = actionProposed.ActionProposedID;
                                treeDetailTHIS.ActionProposedReference.EntityKey = actionProposed.EntityKey;
                            }

                            if (chkCondicion.Checked)
                            {
                                Condition condition = new ConditionBLL().GetConditionByConditionID(Convert.ToInt32(treeDetailBASE.ConditionID));
                                treeDetailTHIS.ConditionID = condition.ConditionID;
                                treeDetailTHIS.ConditionReference.EntityKey = condition.EntityKey;
                            }

                            if (chkLitoral.Checked)
                            {
                                treeDetailTHIS.Littoral = treeDetailBASE.Littoral;
                            }

                            if (chkMaritimoTerrestre.Checked)
                            {
                                treeDetailTHIS.MaritimeZone = treeDetailBASE.MaritimeZone;
                            }

                            if (chkComentarios.Checked)
                            {
                                treeDetailTHIS.Commentary = treeDetailBASE.Commentary;
                            }
                        }
                        successMessage = "Las siguientes cararcterísticas del árbol #" + txtCloneBase.Text + " han sido copiadas satisfactóriamente a los " + ProjectOrganismsIDsToClone.Count + " árboles seleccionados: ";
                    }
                    else
                    {// Range
                        int from = project_OrganismFROM.TreeDetails.FirstOrDefault().Number.Value;
                        int to   = project_OrganismTO.TreeDetails.FirstOrDefault().Number.Value;
                        for (int i = from; i <= to; i++)
                        {
                            var projectOrganismTHIS = _DatabaseContext.Project_Organisms.Where(instance => instance.TreeDetails.FirstOrDefault().Number == i).First();
                            var treeDetailTHIS      = _DatabaseContext.TreeDetails.First(instance => instance.ProjectOrganismID == projectOrganismTHIS.ProjectOrganismID);

                            if (chkCloneNombre.Checked)
                            {
                                Organism organism = new OrganismBLL().GetOrganismByOrganismID(project_OrganismBase.OrganismID);
                                projectOrganismTHIS.OrganismID = organism.OrganismID;
                                projectOrganismTHIS.OrganismReference.EntityKey = organism.EntityKey;
                            }

                            foreach (var item in _DatabaseContext.Daps.Where(instance => instance.TreeDetailsID == treeDetailTHIS.TreeDetailsID).ToList())
                            {
                                _DatabaseContext.Daps.DeleteObject(item);
                            }

                            if (chkCloneVaras.Checked)
                            {
                                treeDetailTHIS.Varas = treeDetailBASE.Varas;
                            }

                            if (chkCloneDap.Checked)
                            {
                                treeDetailTHIS.Dap         = treeDetailBASE.Dap;
                                treeDetailTHIS.Dap_Counter = treeDetailBASE.Dap_Counter;

                                foreach (var dap in treeDetailBASE.Daps)
                                {
                                    Dap dapTHIS = new Dap();
                                    dapTHIS.DapValue      = dap.DapValue;
                                    dapTHIS.TreeDetailsID = treeDetailTHIS.TreeDetailsID;
                                    dapTHIS.TreeDetailReference.EntityKey = treeDetailTHIS.EntityKey;

                                    _DatabaseContext.Daps.AddObject(dapTHIS);
                                }
                            }

                            if (chkAltura.Checked)
                            {
                                treeDetailTHIS.Height = treeDetailBASE.Height;
                            }

                            if (chkAcciónPropuesta.Checked)
                            {
                                ActionProposed actionProposed = new ActionProposedBLL().GetActionProposedByActionProposedID(Convert.ToInt32(treeDetailBASE.ActionProposedID));
                                treeDetailTHIS.ActionProposedID = actionProposed.ActionProposedID;
                                treeDetailTHIS.ActionProposedReference.EntityKey = actionProposed.EntityKey;
                            }

                            if (chkCondicion.Checked)
                            {
                                Condition condition = new ConditionBLL().GetConditionByConditionID(Convert.ToInt32(treeDetailBASE.ConditionID));
                                treeDetailTHIS.ConditionID = condition.ConditionID;
                                treeDetailTHIS.ConditionReference.EntityKey = condition.EntityKey;
                            }

                            if (chkLitoral.Checked)
                            {
                                treeDetailTHIS.Littoral = treeDetailBASE.Littoral;
                            }

                            if (chkMaritimoTerrestre.Checked)
                            {
                                treeDetailTHIS.MaritimeZone = treeDetailBASE.MaritimeZone;
                            }

                            if (chkComentarios.Checked)
                            {
                                treeDetailTHIS.Commentary = treeDetailBASE.Commentary;
                            }
                        }
                        successMessage = "Las siguientes cararcterísticas del árbol <b>#" + txtCloneBase.Text + "</b> han sido copiadas satisfactóriamente a los árboles desde el árbol <b>#" + from + "</b> al árbol <b>#" + to + "</b>: <br />";
                    }

                    if (chkCloneNombre.Checked)
                    {
                        successMessage += "<b> • Nombre Común - Nombre Científico</b><br />";
                    }
                    if (chkCloneVaras.Checked)
                    {
                        successMessage += "<b> • Varas</b><br />";
                    }
                    if (chkCloneDap.Checked)
                    {
                        successMessage += "<b> • D.A.P</b><br />";
                    }
                    if (chkAltura.Checked)
                    {
                        successMessage += "<b> • Altura (pies)</b><br />";
                    }
                    if (chkAcciónPropuesta.Checked)
                    {
                        successMessage += "<b> • Acción Propuesta</b><br />";
                    }
                    if (chkCondicion.Checked)
                    {
                        successMessage += "<b> • Condición</b><br />";
                    }
                    if (chkLitoral.Checked)
                    {
                        successMessage += "<b> • Árbol en la Servidumbre de Vigilancia de Litoral</b><br />";
                    }
                    if (chkMaritimoTerrestre.Checked)
                    {
                        successMessage += "<b> • Árbol en la Zona Marítimo Terrestre</b><br />";
                    }
                    if (chkComentarios.Checked)
                    {
                        successMessage += "<b> • Comentarios</b>";
                    }

                    _DatabaseContext.SaveChanges();
                    pnlCloneRange.Style["display"] = (rbtCloneRange.Checked) ? "block" : "none";

                    gridViewTreeDetails.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
                    gridViewTreeDetails.DataBind();

                    ltlMessage.Text += MessageFormatter.GetFormattedSuccessMessage(successMessage);

                    btnClear_Click(null, null);
                    pnlClone.Style["display"]   = "none";
                    pnlLoading.Style["display"] = "none";
                }
            }
        }
Ejemplo n.º 14
0
 partial void OnDapDeleted(Dap dap);
Ejemplo n.º 15
0
 partial void OnDapSaving(Dap dap);
Ejemplo n.º 16
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------------------

        public TreeDetail CreateProject_Organism(int varas, decimal height, decimal lat, decimal lon, int[] daps, ActionProposed actionProposed, Condition condition, string commentary, Organism organism, Project project, Eisk.BusinessEntities.User user)
        {
            Project_Organisms project_Organism = new Project_Organisms();

            project_Organism.CreatorUserID = user.UserID;
            project_Organism.CreatedDate   = DateTime.Now;
            project_Organism.EditorUserID  = user.UserID;
            project_Organism.EditedDate    = DateTime.Now;

            project_Organism.OrganismID = organism.OrganismID;
            project_Organism.OrganismReference.EntityKey = organism.EntityKey;

            project_Organism.ProjectID = project.ProjectID;
            project_Organism.ProjectReference.EntityKey = project.EntityKey;

            int project_OrganismID = new Project_OrganismsBLL().CreateNewProject_Organisms(project_Organism);

            TreeDetail treeDetail = new TreeDetail();

            if (varas != 0) // Is Cepa
            {
                treeDetail.Dap         = 0;
                treeDetail.Dap_Counter = 0;
            }
            else if (daps.Length == 1) // Solo un Dap
            {
                treeDetail.Dap         = daps[0];
                treeDetail.Dap_Counter = 1;
            }
            else // Mas de un Dap
            {
                double dapTotal = 0;
                foreach (int dap in daps)
                {
                    dapTotal += dap;
                }
                treeDetail.Dap         = Convert.ToDecimal(Math.Round(Math.Sqrt(Math.Pow(dapTotal, 2D) / Convert.ToDouble(daps.Length)) * 100) / 100);
                treeDetail.Dap_Counter = daps.Length;
            }

            treeDetail.Varas = varas;

            treeDetail.Height     = height;
            treeDetail.Commentary = commentary;

            List <Project_Organisms> project_Organisms = new Project_OrganismsBLL().GetProject_OrganismsByProjectID(project.ProjectID);

            Dictionary <string, object> anewpointObj = JavaScriptHelper.ConvertToStatePlane(lon.ToString(), lat.ToString());

            treeDetail.Number = project_Organisms.Count;
            treeDetail.Y      = Convert.ToDecimal(anewpointObj["y"]);
            treeDetail.X      = Convert.ToDecimal(anewpointObj["x"]);
            treeDetail.Lat    = Convert.ToDecimal(lat);
            treeDetail.Lon    = Convert.ToDecimal(lon);

            treeDetail.CreatedDate   = DateTime.Now;
            treeDetail.CreatorUserID = user.UserID;
            treeDetail.EditedDate    = DateTime.Now;
            treeDetail.EditorUserID  = user.UserID;


            treeDetail.ActionProposedID = actionProposed.ActionProposedID;
            treeDetail.ActionProposedReference.EntityKey = actionProposed.EntityKey;

            treeDetail.ConditionID = condition.ConditionID;
            treeDetail.ConditionReference.EntityKey = condition.EntityKey;

            treeDetail.ProjectOrganismID = project_Organism.ProjectOrganismID;
            treeDetail.Project_OrganismsReference.EntityKey = project_Organism.EntityKey;

            int treeDetailID = new TreeDetailBLL().CreateNewTreeDetail(treeDetail);

            foreach (decimal dapDecimal in daps)
            {
                Dap dap = new Dap();
                dap.DapValue      = dapDecimal;
                dap.TreeDetailsID = treeDetailID;
                dap.TreeDetailReference.EntityKey = treeDetail.EntityKey;

                new DapBLL().CreateNewDap(dap);
            }
            return(treeDetail);
        }
Ejemplo n.º 17
0
 partial void OnDapCreating(Dap dap);
Ejemplo n.º 18
0
    protected void OdsProject_Organism_Details_Inserted(object sender, System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs e)
    {
        int result = Convert.ToInt32(e.ReturnValue, System.Globalization.CultureInfo.CurrentCulture.NumberFormat);

        //string lat = "";
        //string lon = "";
        if (result != 0)
        {
            Project_Organisms       project_Organisms       = new Project_OrganismsBLL().GetProject_OrganismsByProjectOrganismID(result);
            ProjectInfoTreeLocation projectInfoTreeLocation = new ProjectInfoTreeLocationBLL().GetProjectInfoTreeLocationsByProjectID(project_Organisms.ProjectID)[0];
            bool fromInventory = false;

            UserBLL userBLL = new UserBLL();
            Eisk.BusinessEntities.User user = userBLL.GetUserByUserName((HttpContext.Current.User.Identity).Name);

            if (user != null)
            {
                // TreeDetail
                TextBox     txtVaras      = (TextBox)formViewTlProject_Organism.FindControl("txtVaras");
                HiddenField hfDap         = (HiddenField)formViewTlProject_Organism.FindControl("hfDap");
                TextBox     txtDap        = (TextBox)formViewTlProject_Organism.FindControl("txtDap");
                TextBox     txtDapCounter = (TextBox)formViewTlProject_Organism.FindControl("txtDapCounter");
                TextBox     txtHeight     = (TextBox)formViewTlProject_Organism.FindControl("txtHeight");
                TextBox     txtCommentary = (TextBox)formViewTlProject_Organism.FindControl("txtCommentary");

                Label   lblNumber = (Label)formViewTlProject_Organism.FindControl("lblNumber");
                TextBox txtX      = (TextBox)formViewTlProject_Organism.FindControl("txtX");
                TextBox txtY      = (TextBox)formViewTlProject_Organism.FindControl("txtY");
                TextBox txtLat    = (TextBox)formViewTlProject_Organism.FindControl("txtLat");
                TextBox txtLon    = (TextBox)formViewTlProject_Organism.FindControl("txtLon");

                RadioButtonList rblActionProposed = (RadioButtonList)formViewTlProject_Organism.FindControl("rblActionProposed");
                RadioButtonList rblCondition      = (RadioButtonList)formViewTlProject_Organism.FindControl("rblCondition");

                // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                // Edgardo Ramos - 20130928
                CheckBox chkLittoral     = (CheckBox)formViewTlProject_Organism.FindControl("chkLittoral");
                CheckBox chkMaritimeZone = (CheckBox)formViewTlProject_Organism.FindControl("chkMaritimeZone");
                // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

                TreeDetail treeDetail = new TreeDetail();

                if (!string.IsNullOrEmpty(txtVaras.Text) && txtVaras.Text != "0") // Is Cepa
                {
                    treeDetail.Dap         = 0;
                    treeDetail.Dap_Counter = 0;
                }
                else if (txtDapCounter.Text == "1") // Solo un Dap
                {
                    //treeDetail.Dap = Convert.ToDecimal(txtDap.Text);// new DapBLL().GetDap(0);
                    //treeDetail.Dap_Counter = Convert.ToInt32(txtDapCounter.Text); //new DapBLL().GetDapCount(0);
                    treeDetail.Dap         = Convert.ToDecimal(hfDap.Value); // new DapBLL().GetDap(0);
                    treeDetail.Dap_Counter = Convert.ToInt32(1);             //new DapBLL().GetDapCount(0);
                }
                else // Mas de un Dap
                {
                    string[] daps     = hfDap.Value.Split(',');
                    double   dapTotal = 0;
                    foreach (string dap in daps)
                    {
                        dapTotal += Convert.ToDouble(dap);
                    }//dapTotal;// new DapBLL().GetDap(0);
                    treeDetail.Dap         = Convert.ToDecimal(Math.Round(Math.Sqrt(Math.Pow(dapTotal, 2D) / Convert.ToDouble(daps.Count())) * 100) / 100);
                    treeDetail.Dap_Counter = Convert.ToInt32(txtDapCounter.Text); //new DapBLL().GetDapCount(0);
                }

                treeDetail.Varas = Convert.ToInt32(string.IsNullOrEmpty(txtVaras.Text) ? "0" : txtVaras.Text);

                treeDetail.Height     = Convert.ToDecimal(txtHeight.Text);
                treeDetail.Commentary = (txtCommentary.Text.Length > txtCommentary.MaxLength) ? txtCommentary.Text.Substring(0, txtCommentary.MaxLength) : txtCommentary.Text;

                treeDetail.Number = Convert.ToInt32(lblNumber.Text);


                // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                // Edgardo Ramos - 20130928
                decimal         dec;
                RadioButtonList rblPosition = (RadioButtonList)formViewTlProject_Organism.FindControl("rblPosition");

                if (rblPosition.SelectedValue == "0") // Nad83
                {
                    treeDetail.X = decimal.TryParse(txtX.Text, out dec) ? Convert.ToDecimal(txtX.Text) : 0;
                    treeDetail.Y = decimal.TryParse(txtY.Text, out dec) ? Convert.ToDecimal(txtY.Text) : 0;

                    if (treeDetail.X != 0 && treeDetail.Y != 0)
                    {
                        Dictionary <string, object> anewpointObj = Utility.ConvertToLatLng(treeDetail.X.ToString(), treeDetail.Y.ToString(), @"~/App_Resources/client-scripts/tl/");

                        treeDetail.Lat = Convert.ToDecimal(anewpointObj["y"]);
                        txtLat.Text    = treeDetail.Lat.ToString();
                        treeDetail.Lon = Convert.ToDecimal(anewpointObj["x"]);
                        txtLon.Text    = treeDetail.Lon.ToString();
                    }
                    else
                    {
                        treeDetail.Lat = 0;
                        treeDetail.Lon = 0;
                    }
                }
                else // StatePlanes
                {
                    treeDetail.Lat = decimal.TryParse(txtLat.Text, out dec) ? Convert.ToDecimal(txtLat.Text) : 0;
                    treeDetail.Lon = decimal.TryParse(txtLon.Text, out dec) ? Convert.ToDecimal(txtLon.Text) : 0;

                    if (treeDetail.Lat != 0 && treeDetail.Lon != 0)
                    {
                        Dictionary <string, object> anewpointObj = Utility.ConvertToStatePlane(treeDetail.Lon.ToString(), treeDetail.Lat.ToString(), @"~/App_Resources/client-scripts/tl/");

                        treeDetail.X = Convert.ToDecimal(anewpointObj["x"]);
                        txtX.Text    = treeDetail.X.ToString();
                        treeDetail.Y = Convert.ToDecimal(anewpointObj["y"]);
                        txtY.Text    = treeDetail.Y.ToString();
                    }
                    else
                    {
                        treeDetail.X = 0;
                        treeDetail.Y = 0;
                    }
                }

                //treeDetail.X = Convert.ToDecimal(txtX.Text);
                //treeDetail.Y = Convert.ToDecimal(txtY.Text);
                //treeDetail.Lat = Convert.ToDecimal(txtLat.Text);
                //treeDetail.Lon = Convert.ToDecimal(txtLon.Text);

                treeDetail.Littoral     = chkLittoral.Checked;
                treeDetail.MaritimeZone = chkMaritimeZone.Checked;

                // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

                treeDetail.CreatedDate   = DateTime.Now;
                treeDetail.CreatorUserID = user.UserID;
                treeDetail.EditedDate    = DateTime.Now;
                treeDetail.EditorUserID  = user.UserID;

                ActionProposed actionProposed = new ActionProposedBLL().GetActionProposedByActionProposedID(Convert.ToInt32(rblActionProposed.SelectedValue));
                treeDetail.ActionProposedID = actionProposed.ActionProposedID;
                treeDetail.ActionProposedReference.EntityKey = actionProposed.EntityKey;

                Condition condition = new ConditionBLL().GetConditionByConditionID(Convert.ToInt32(rblCondition.SelectedValue));
                treeDetail.ConditionID = condition.ConditionID;
                treeDetail.ConditionReference.EntityKey = condition.EntityKey;

                treeDetail.ProjectOrganismID = project_Organisms.ProjectOrganismID;
                treeDetail.Project_OrganismsReference.EntityKey = project_Organisms.EntityKey;

                int treeDetailID = new TreeDetailBLL().CreateNewTreeDetail(treeDetail);

                if (treeDetail.Varas != null && treeDetail.Varas > 0) // Is Cepa
                {
                    //
                }
                else if (txtDapCounter.Text == "1") // Solo un Dap
                {
                    Dap dap = new Dap();
                    dap.DapValue      = Convert.ToDecimal(hfDap.Value);
                    dap.TreeDetailsID = treeDetailID;
                    dap.TreeDetailReference.EntityKey = treeDetail.EntityKey;

                    new DapBLL().CreateNewDap(dap);
                }
                else // Mas de un Dap
                {
                    string[] daps = hfDap.Value.Split(',');
                    foreach (string dapString in daps)
                    {
                        Dap dap = new Dap();
                        dap.DapValue      = Convert.ToDecimal(dapString);
                        dap.TreeDetailsID = treeDetailID;
                        dap.TreeDetailReference.EntityKey = treeDetail.EntityKey;

                        new DapBLL().CreateNewDap(dap);
                    }
                }

                fromInventory = Convert.ToDecimal(projectInfoTreeLocation.X) == Convert.ToDecimal(treeDetail.X) && Convert.ToDecimal(projectInfoTreeLocation.Y) == Convert.ToDecimal(treeDetail.Y);
                //
            }

            if (fromInventory)
            {
                Response.RedirectToRoute("tl-treeinventory", new { project_id = RouteData.Values["project_id"] });
            }
            else
            {
                Response.RedirectToRoute("tl", new { Project_id = RouteData.Values["Project_id"] });
                Response.RedirectLocation += "?poid=" + project_Organisms.ProjectOrganismID + "&lat=0&lon=0";
            }

            //Response.RedirectToRoute("tl-tree-details_edit", new { edit_mode = "edit", project_id = Page.RouteData.Values["project_id"] as string, project_organism_id = result });
        }
    }
Ejemplo n.º 19
0
 partial void OnDapCreated(Dap dap);
Ejemplo n.º 20
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Daps EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDaps(Dap dap)
 {
     base.AddObject("Daps", dap);
 }
Ejemplo n.º 21
0
        public object Update([FromBody] ProjectOrganismUpdateModel projectOrganismUpdate)
        {
            //var projectOrganism = (Project_Organisms)HttpContext.Current.Items["projectOrganism"];
            //var organism = (Organism)HttpContext.Current.Items["organism"];
            var project = (Project)HttpContext.Current.Items["project"];
            var groups  = (List <Group>)HttpContext.Current.Items["groups"];
            var user    = (User)HttpContext.Current.Items["user"];
            //var actionProposed = (ActionProposed)HttpContext.Current.Items["actionProposed"];
            //var condition = (Condition)HttpContext.Current.Items["condition"];
            var daps  = (int[])HttpContext.Current.Items["daps"];
            var varas = (int)HttpContext.Current.Items["varas"];


            using (DatabaseContext _DatabaseContext = new DatabaseContext())
            {
                // TreeDetail
                Project_Organisms projectOrganism = _DatabaseContext.Project_Organisms.First(instance => instance.ProjectOrganismID == projectOrganismUpdate.ProjectOrganismID);
                TreeDetail        treeDetail      = _DatabaseContext.TreeDetails.First(instance => instance.ProjectOrganismID == projectOrganism.ProjectOrganismID);

                //Delete existing Daps
                foreach (Dap item in _DatabaseContext.Daps.Where(instance => instance.TreeDetailsID == treeDetail.TreeDetailsID).ToList())
                {
                    _DatabaseContext.Daps.DeleteObject(item);
                }

                if (varas != 0) // Is Cepa
                {
                    treeDetail.Dap         = 0;
                    treeDetail.Dap_Counter = 0;
                }
                else if (daps.Length == 1) // Solo un Dap
                {
                    treeDetail.Dap         = Convert.ToDecimal(daps[0]);
                    treeDetail.Dap_Counter = 1;

                    Dap dapObj = new Dap();
                    dapObj.DapValue      = Convert.ToDecimal(daps[0]);
                    dapObj.TreeDetailsID = treeDetail.TreeDetailsID;
                    dapObj.TreeDetailReference.EntityKey = treeDetail.EntityKey;

                    _DatabaseContext.Daps.AddObject(dapObj);
                }
                else // 1 o Mas de un Dap
                {
                    double dapTotal = 0;
                    foreach (int dap in daps)
                    {
                        dapTotal += Convert.ToDouble(dap);
                    }
                    //dapTotal;// new DapBLL().GetDap(0);
                    treeDetail.Dap         = Convert.ToDecimal(Math.Round(Math.Sqrt(Math.Pow(dapTotal, 2D) / Convert.ToDouble(daps.Count())) * 100) / 100);
                    treeDetail.Dap_Counter = Convert.ToInt32(daps.Length); //new DapBLL().GetDapCount(0);

                    foreach (int dapInt in daps)
                    {
                        Dap dap = new Dap();
                        dap.DapValue      = Convert.ToDecimal(dapInt);
                        dap.TreeDetailsID = treeDetail.TreeDetailsID;
                        dap.TreeDetailReference.EntityKey = treeDetail.EntityKey;

                        _DatabaseContext.Daps.AddObject(dap);
                    }
                }

                //treeDetail.Dap = new DapBLL().GetDap(treeDetail.TreeDetailsID); //Convert.ToDecimal(hfDap.Value);
                //treeDetail.Dap_Counter = new DapBLL().GetDapCount(treeDetail.TreeDetailsID); //Convert.ToInt32(hfDapCounter.Value);

                treeDetail.Varas = projectOrganismUpdate.Varas;

                treeDetail.Height = Convert.ToDecimal(projectOrganismUpdate.Height);
                int CommentaryMaxLength = Convert.ToInt32(ConfigurationManager.AppSettings["CommentaryMaxLength"]);
                if (!string.IsNullOrEmpty(projectOrganismUpdate.Commentary))
                {
                    treeDetail.Commentary = (projectOrganismUpdate.Commentary.Length > CommentaryMaxLength) ? projectOrganismUpdate.Commentary.Substring(0, CommentaryMaxLength) : projectOrganismUpdate.Commentary;
                }
                else
                {
                    treeDetail.Commentary = "";
                }

                treeDetail.Number = Convert.ToInt32(treeDetail.Number);

                treeDetail.Lat = Convert.ToDecimal(projectOrganismUpdate.Lat);
                treeDetail.Lon = Convert.ToDecimal(projectOrganismUpdate.Lon);
                Dictionary <string, object> anewpointObj = Utility.ConvertToStatePlane(projectOrganismUpdate.Lon.ToString(), projectOrganismUpdate.Lat.ToString(), @"~/Javascript/");
                treeDetail.X = Convert.ToDecimal(anewpointObj["x"]);
                treeDetail.Y = Convert.ToDecimal(anewpointObj["y"]);
                //

                treeDetail.EditedDate   = DateTime.Now;
                treeDetail.EditorUserID = user.UserID;

                //projectOrganism
                Organism organism = new OrganismBLL().GetOrganismByOrganismID(Convert.ToInt32(projectOrganismUpdate.OrganismID));
                projectOrganism.OrganismID = organism.OrganismID;
                projectOrganism.OrganismReference.EntityKey = organism.EntityKey;

                //ActionProposed
                ActionProposed actionProposed = new ActionProposedBLL().GetActionProposedByActionProposedID(Convert.ToInt32(projectOrganismUpdate.ActionProposedID));
                treeDetail.ActionProposedID = actionProposed.ActionProposedID;
                treeDetail.ActionProposedReference.EntityKey = actionProposed.EntityKey;

                //Condition
                Condition condition = new ConditionBLL().GetConditionByConditionID(Convert.ToInt32(projectOrganismUpdate.ConditionID));
                treeDetail.ConditionID = condition.ConditionID;
                treeDetail.ConditionReference.EntityKey = condition.EntityKey;

                treeDetail.ProjectOrganismID = (int)projectOrganismUpdate.ProjectOrganismID;
                treeDetail.Project_OrganismsReference.EntityKey = projectOrganism.EntityKey;

                _DatabaseContext.SaveChanges();
                //
            }

            var updatedProjectOrganism = new Project_OrganismsBLL().GetProject_OrganismsByProjectOrganismID((int)projectOrganismUpdate.ProjectOrganismID);

            return(ProjectOrganismModel.GetProjectOrganismObject(updatedProjectOrganism));
        }