Exemple #1
0
        public static NetDTO CreatePhonyNet(int count)
        {
            NetDTO dto = new NetDTO();

            dto.Key  = String.Format("NetID {0}", count);
            dto.Name = String.Format("Name {0}", count);
            //dto.Type = String.Format("Type {0}", count);
            //dto.Details = String.Format("Details {0}", count);
            //dto.Description = String.Format("Description {0}", count);
            return(dto);
        }
Exemple #2
0
 private DataTab NetsDataTab()
 {
     return(new DataTab("LIST_Nets", XlColor.Orange, NetDTO.GetSchema(), generalDet.Nets.Values));
 }
Exemple #3
0
        private void CheckHeaders(XlWorksheet worksheet)
        {
            if (worksheet != null)
            {
                Schema        s;
                List <string> h;
                if (worksheet.Name == "DET_CatchEffort")
                {
                    s = CatchEffortDTO.GetSchema();
                }
                else if (worksheet.Name == "DET_NetHaulEvent")
                {
                    s = NetHaulEventDTO.GetSchema();
                }
                else if (worksheet.Name == "DET_FishCount")
                {
                    s = FishCountDTO.GetSchema();
                }
                else if (worksheet.Name == "DET_CatchMetric")
                {
                    s = CatchMetricDTO.GetSchema();
                }
                else if (worksheet.Name == "DET_Fish")
                {
                    s = FishDTO.GetSchema();
                }
                else if (worksheet.Name == "DET_IdTags")
                {
                    s = IdTagDTO.GetSchema();
                }
                else if (worksheet.Name == "DET_Genetics")
                {
                    s = GeneticDTO.GetSchema();
                }
                else if (worksheet.Name == "DET_Diet")
                {
                    s = DietDTO.GetSchema();
                }
                else if (worksheet.Name == "LIST_FishSpecies")
                {
                    s = FishSpeciesDTO.GetSchema();
                }
                else if (worksheet.Name == "LIST_MacroSpecies")
                {
                    s = MacroSpeciesDTO.GetSchema();
                }
                else if (worksheet.Name == "LIST_Sites")
                {
                    s = SiteDTO.GetSchema();
                }
                else if (worksheet.Name == "LIST_Nets")
                {
                    s = NetDTO.GetSchema();
                }
                else
                {
                    return;
                }

                h = new List <string>();
                List <string> hdrs = ExcelBaseDet.Headers(worksheet);
                bool          bad  = false;
                for (int i = 0; i < hdrs.Count - 1; i++)
                {
                    string t = hdrs[i];
                    for (int j = i + 1; j < hdrs.Count; j++)
                    {
                        if (t == hdrs[j])
                        {
                            bad = true;
                            break; //inner
                        }
                    }
                    if (bad)
                    {
                        break; //outer
                    }
                }
                if (bad)
                {
                    generalDet.ValidationIssues.Add(ValidationIssue.Code.DuplicateHeader, "Duplicate column header in " + worksheet.Name);
                }
                foreach (SchemaEntry c in s)
                {
                    h.Add(c.LowerColumnName);
                }
                if (!ExcelBaseDet.HasHeaders(hdrs, h))
                {
                    generalDet.ValidationIssues.Add(ValidationIssue.Code.MissingFieldHeader, "Missing column header in " + worksheet.Name);
                }
            }
        }
Exemple #4
0
        private void LoadRow(string sheetName, Dictionary <string, string> values)
        {
            ValidationIssues issues = generalDet.ValidationIssues;

            if (sheetName == "DET_CatchEffort")
            {
                CatchEffortDTO newDto = new CatchEffortDTO(values);
                newDto.Validate();
                issues.Merge(newDto.ValidationIssues);
                bool success = generalDet.CatchEfforts.Add(newDto);
                if (!success)
                {
                    issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The catch effort with code {0} is not unique.", newDto.LookupKey));
                }
            }
            else if (sheetName == "DET_NetHaulEvent")
            {
                NetHaulEventDTO newDto = new NetHaulEventDTO(values);
                newDto.Validate();
                issues.Merge(newDto.ValidationIssues);
                bool success = generalDet.NetHaulEvents.Add(newDto);
                if (!success)
                {
                    issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The net haul event with code {0} is not unique.", newDto.LookupKey));
                }
            }
            else if (sheetName == "DET_FishCount")
            {
                FishCountDTO newDto = new FishCountDTO(values);
                newDto.Validate();
                issues.Merge(newDto.ValidationIssues);
                bool success = generalDet.FishCounts.Add(newDto);
                if (!success)
                {
                    issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The fish count with code {0} is not unique.", newDto.LookupKey));
                }
            }
            else if (sheetName == "DET_CatchMetric")
            {
                CatchMetricDTO newDto = new CatchMetricDTO(values);
                newDto.Validate();
                issues.Merge(newDto.ValidationIssues);
                bool success = generalDet.CatchMetrics.Add(newDto);
                if (!success)
                {
                    issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The catch metric with code {0} is not unique.", newDto.LookupKey));
                }
            }
            else if (sheetName == "DET_Fish")
            {
                FishDTO newDto = new FishDTO(values);
                newDto.Validate();
                issues.Merge(newDto.ValidationIssues);
                bool success = generalDet.Fish.Add(newDto);
                if (!success)
                {
                    issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The fish with code {0} is not unique.", newDto.LookupKey));
                }
            }
            else if (sheetName == "DET_IdTags")
            {
                IdTagDTO newDto = new IdTagDTO(values);
                newDto.Validate();
                issues.Merge(newDto.ValidationIssues);
                bool success = generalDet.IdTags.Add(newDto);
                if (!success)
                {
                    issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The ID tag with code {0} is not unique.", newDto.LookupKey));
                }
            }
            else if (sheetName == "DET_Genetics")
            {
                GeneticDTO newDto = new GeneticDTO(values);
                newDto.Validate();
                issues.Merge(newDto.ValidationIssues);
                bool success = generalDet.Genetics.Add(newDto);
                if (!success)
                {
                    issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The genetic with code {0} is not unique.", newDto.LookupKey));
                }
            }
            else if (sheetName == "DET_Diet")
            {
                DietDTO newDto = new DietDTO(values);
                newDto.Validate();
                issues.Merge(newDto.ValidationIssues);
                bool success = generalDet.Diet.Add(newDto);
                if (!success)
                {
                    issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The diet with code {0} is not unique.", newDto.LookupKey));
                }
            }
            else if (sheetName == "LIST_FishSpecies")
            {
                FishSpeciesDTO newDto = new FishSpeciesDTO(values);
                newDto.Validate();
                issues.Merge(newDto.ValidationIssues);
                bool success = generalDet.FishSpecies.Add(newDto);
                if (!success)
                {
                    issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The fish-species with code {0} is not unique.", newDto.LookupKey));
                }
            }
            else if (sheetName == "LIST_MacroSpecies")
            {
                MacroSpeciesDTO newDto = new MacroSpeciesDTO(values);
                newDto.Validate();
                issues.Merge(newDto.ValidationIssues);
                bool success = generalDet.MacroSpecies.Add(newDto);
                if (!success)
                {
                    issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The macro-species with code {0} is not unique.", newDto.LookupKey));
                }
            }
            else if (sheetName == "LIST_Sites")
            {
                SiteDTO newDto = new SiteDTO(values);
                newDto.Validate();
                issues.Merge(newDto.ValidationIssues);
                bool success = generalDet.Sites.Add(newDto);
                if (!success)
                {
                    issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The site with code {0} is not unique.", newDto.LookupKey));
                }
            }
            else if (sheetName == "LIST_Nets")
            {
                NetDTO newDto = new NetDTO(values);
                newDto.Validate();
                issues.Merge(newDto.ValidationIssues);
                bool success = generalDet.Nets.Add(newDto);
                if (!success)
                {
                    issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The net with code {0} is not unique.", newDto.LookupKey));
                }
            }
        }
Exemple #5
0
        public FilestoreFile Create(SampleEventMap map, EntityBundle sites, EntityBundle nets, EntityBundle fishSpecies, EntityBundle macroSpecies, bool isPrivate)
        {
            if (this.CanModify(map))
            {
                Guid    id  = Guid.NewGuid();
                FishDET det = new FishDET();
                det.Id    = id;
                det.Owner = "originator:" + sites.PrincipalOrgId.Identity.ToString() + ":" + nets.PrincipalOrgId.Identity.ToString();

                int ct = 0;
                foreach (BundleElement cur in sites.Elements)
                {
                    SiteDTO tmp = new SiteDTO();
                    tmp.Key  = cur.LocalKey;
                    tmp.Name = cur.DisplayName;
                    det.Sites.Add(tmp);
                    ct++;
                }
                if (ct > 0) //has to be elements in the collection
                {
                    ct = 0;

                    foreach (BundleElement cur in nets.Elements)
                    {
                        NetDTO tmp = new NetDTO();
                        tmp.Key  = cur.LocalKey;
                        tmp.Name = cur.DisplayName;
                        det.Nets.Add(tmp);
                        ct++;
                    }

                    if (ct > 0)
                    {
                        ct = 0;

                        foreach (BundleElement cur in fishSpecies.Elements)
                        {
                            FishSpeciesDTO tmp = new FishSpeciesDTO();
                            tmp.Key  = cur.LocalKey;
                            tmp.Name = cur.DisplayName;
                            det.FishSpecies.Add(tmp);
                            ct++;
                        }

                        if (ct > 0)
                        {
                            if (macroSpecies != null)
                            {
                                ct = 0;
                                foreach (BundleElement cur in macroSpecies.Elements)
                                {
                                    MacroSpeciesDTO tmp = new MacroSpeciesDTO();
                                    tmp.Key  = cur.LocalKey;
                                    tmp.Name = cur.DisplayName;
                                    det.MacroSpecies.Add(tmp);
                                    ct++;
                                }
                            }

                            if (ct > 0)
                            {
                                det.Validate();
                                if (det.ValidationIssues.Count == 0)
                                {
                                    IFileStoreProvider prov = this.FileStore;

                                    if (prov != null)
                                    {
                                        FilestoreFile fil = prov.Make(id);
                                        if (fil != null)
                                        {
                                            ExcelFishDET excel = new ExcelFishDET(det);
                                            excel.Save(fil);
                                            fil.Flush();
                                            fil.Seek(0, System.IO.SeekOrigin.Begin);
                                            return(fil);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }