Example #1
0
        public FisherGPS GetFisherGPS(Fisher fisher, GPS gps,
                                      ProjectSetting projectSetting,
                                      DateTime dateTimeDeparted, out EntityValidationMessage errorMessage)
        {
            errorMessage = new EntityValidationMessage("");
            FisherGPS rv = null;

            foreach (FisherGPS fg in FisherGPSCollection.OrderBy(p => p.DateAssigned))
            {
                if (fg.Fisher.FisherID == fisher.FisherID &&
                    fg.GPS.ID == gps.ID &&
                    fg.ProjectSetting.ProjectID == projectSetting.ProjectID)
                {
                    if (fg.DateReturned != null)
                    {
                    }
                    rv = fg;
                    break;
                }
            }
            if (rv == null)
            {
                errorMessage = new EntityValidationMessage("No matching Fisher-GPS record was found. Check date and time departed");
            }
            return(rv);
        }
 public List <Fisher> GetAllFishersInProject(ProjectSetting p)
 {
     return(BSCEntities.FisherGPSViewModel.FisherGPSCollection
            .Where(t => t.ProjectSetting.ProjectID == p.ProjectID)
            .GroupBy(t => t.Fisher.FisherID)
            .Select(t => t.First().Fisher).ToList());
 }
Example #3
0
 public FisherGPS GetFisherGPS(Fisher f, GPS g, ProjectSetting p)
 {
     return((from fg in FisherGPSCollection
             where fg.Fisher.FisherID == f.FisherID
             where fg.GPS.ID == g.ID
             where fg.ProjectSetting.ProjectID == p.ProjectID
             select fg).FirstOrDefault());
 }
Example #4
0
 public GPS GetSuggestedGPS(Fisher f, ProjectSetting p)
 {
     return(BSCEntities.FisherGPSViewModel.FisherGPSCollection
            .Where(t => t.Fisher.FisherID == f.FisherID)
            .Where(t => t.ProjectSetting.ProjectID == p.ProjectID)
            .OrderByDescending(t => t.DateAssigned)
            .Select(t => t.GPS).FirstOrDefault());
 }
Example #5
0
 public void AddRecordToRepo(ProjectSetting ps)
 {
     if (ps == null)
     {
         throw new ArgumentNullException("Error: The argument is Null");
     }
     ProjectSettingCollection.Add(ps);
 }
Example #6
0
 public List <GPS> GetAllGPSAssignedToFisher(Fisher f, ProjectSetting p)
 {
     return(BSCEntities.FisherGPSViewModel.FisherGPSCollection
            .Where(x => x.ProjectSetting.ProjectID == p.ProjectID)
            .Where(x => x.Fisher.FisherID == f.FisherID)
            .GroupBy(t => t.GPS.ID)
            .Select(t => t.First().GPS).ToList());
 }
Example #7
0
 public FisherGPS(string id, GPS gps, Fisher fisher, ProjectSetting projectSetting, DateTime?dateAssigned, DateTime?dateReturned)
 {
     RowID          = id;
     GPS            = gps;
     Fisher         = fisher;
     ProjectSetting = projectSetting;
     DateAssigned   = dateAssigned;
     DateReturned   = dateReturned;
 }
Example #8
0
 public List <Sampling> GetAllSamplings(ProjectSetting pr, LandingSite ls, Gear g, DateTime month)
 {
     return(SamplingCollection
            .Where(t => t.ProjectSetting.ProjectID == pr.ProjectID)
            .Where(t => t.LandingSite.LandingSiteID == ls.LandingSiteID)
            .Where(t => t.Gear.GearName == g.GearName)
            .Where(t => t.DateTimeSampled >= month)
            .Where(t => t.DateTimeSampled < month.AddMonths(1)).ToList());
 }
Example #9
0
        public bool CanDeleteEntity(ProjectSetting ps)
        {
            return(BSCEntities.SamplingViewModel.SamplingCollection
                   .Where(t => t.ProjectSetting.ProjectID == ps.ProjectID).ToList().Count == 0

                   &&

                   BSCEntities.FisherGPSViewModel.FisherGPSCollection
                   .Where(l => l.ProjectSetting.ProjectID == ps.ProjectID).ToList().Count == 0);
        }
Example #10
0
        public Dictionary <GPS, int> GetAllGPSAssignedToFisherEx1(Fisher f, ProjectSetting p)
        {
            var tempList = from g in BSCEntities.FisherGPSViewModel.FisherGPSCollection
                           where g.Fisher.FisherID == f.FisherID
                           where g.ProjectSetting.ProjectID == p.ProjectID
                           group g.GPS by g.GPS into t
                           select new
            {
                key   = t.Key,
                value = t.Count()
            };

            return(tempList.ToDictionary(x => x.key, x => x.value));
        }
Example #11
0
 public Sampling(FisherGPS fisherGPS, LandingSite landingSite, string rowID, Gear gear, DateTime?datetimeDeparted,
                 DateTime?dateTimeArrived, string nsapSamplingID, ProjectSetting projectSetting, DateTime dateTimeSampled, DateTime dateAdded)
 {
     FisherGPS        = fisherGPS;
     RowID            = rowID;
     DateTimeDeparted = datetimeDeparted;
     DateTimeArrived  = dateTimeArrived;
     NSAPSamplingID   = nsapSamplingID;
     ProjectSetting   = projectSetting;
     DateTimeSampled  = dateTimeSampled;
     LandingSite      = landingSite;
     Gear             = gear;
     DateAdded        = dateAdded;
 }
        public bool Add(ProjectSetting ps)
        {
            bool success = false;

            using (OleDbConnection conn = new OleDbConnection(Global.ConnectionString))
            {
                conn.Open();
                var sql = $@"Insert into ProjectSettings (ProjectID, ProjectName, DateStart)
                           Values 
                           ({{{ps.ProjectID}}},'{ps.ProjectName}','{ps.DateStart}')";
                using (OleDbCommand update = new OleDbCommand(sql, conn))
                {
                    success = update.ExecuteNonQuery() > 0;
                }
            }
            return(success);
        }
Example #13
0
        private void ProjectSettings_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            ProjectSetting editedEntity = new ProjectSetting();

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                int newIndex = e.NewStartingIndex;
                editedEntity = ProjectSettingCollection[newIndex];

                if (ProjectSettings.Add(editedEntity))
                {
                    EditedEntity = new EditedEntity(EditAction.Add, editedEntity);
                }
            }
            break;

            case NotifyCollectionChangedAction.Remove:
            {
                List <ProjectSetting> tempListOfRemovedItems = e.OldItems.OfType <ProjectSetting>().ToList();
                editedEntity = tempListOfRemovedItems[0];

                if (ProjectSettings.Delete(editedEntity.ProjectID))
                {
                    EditedEntity = new EditedEntity(EditAction.Delete, editedEntity);
                }
            }
            break;

            case NotifyCollectionChangedAction.Replace:
            {
                List <ProjectSetting> tempListOfProjectSettings = e.NewItems.OfType <ProjectSetting>().ToList();
                editedEntity = tempListOfProjectSettings[0];

                if (ProjectSettings.Update(tempListOfProjectSettings[0]))              // As the IDs are unique, only one row will be effected hence first index only
                {
                    EditedEntity = new EditedEntity(EditAction.Update, editedEntity);
                }
            }
            break;
            }
            EntityChangedEventArgs args = new EntityChangedEventArgs(editedEntity.GetType().Name, editedEntity);

            EntityChanged?.Invoke(this, args);
        }
Example #14
0
        public bool EntityValidated(ProjectSetting projectSetting, out List <string> messages, bool isNew = false)
        {
            messages = new List <string>();

            if (projectSetting.ProjectName.Length < 5)
            {
                messages.Add("Project's name must be at least 5 characters long");
            }


            if (projectSetting.DateStart == null)
            {
                messages.Add("Projetct's starting date cannot be empty");
            }


            return(messages.Count == 0);
        }
        public bool Update(ProjectSetting ps)
        {
            bool success = false;

            using (OleDbConnection conn = new OleDbConnection(Global.ConnectionString))
            {
                conn.Open();
                var sql = $@"Update ProjectSettings set
                                ProjectName = '{ps.ProjectName}',
                                DateStart = '{ps.DateStart}'
                            WHERE ProjectID={{{ps.ProjectID}}}";
                using (OleDbCommand update = new OleDbCommand(sql, conn))
                {
                    success = update.ExecuteNonQuery() > 0;
                }
            }
            return(success);
        }
Example #16
0
        public void UpdateRecordInRepo(ProjectSetting ps)
        {
            if (ps.ProjectID == null)
            {
                throw new Exception("Error: ID cannot be null");
            }

            int index = 0;

            while (index < ProjectSettingCollection.Count)
            {
                if (ProjectSettingCollection[index].ProjectID == ps.ProjectID)
                {
                    ProjectSettingCollection[index] = ps;
                    break;
                }
                index++;
            }
        }
        private List <ProjectSetting> getProjectSettings()
        {
            List <ProjectSetting> listProjectSettings = new List <ProjectSetting>();
            var dt = new DataTable();

            using (var conection = new OleDbConnection(Global.ConnectionString))
            {
                try
                {
                    conection.Open();
                    string query = $@"SELECT * from ProjectSettings";

                    var adapter = new OleDbDataAdapter(query, conection);
                    adapter.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        listProjectSettings.Clear();
                        foreach (DataRow dr in dt.Rows)
                        {
                            ProjectSetting ps = new ProjectSetting
                            {
                                ProjectName = dr["ProjectName"].ToString(),
                                DateStart   = (DateTime)(dr["DateStart"]),
                                ProjectID   = dr["ProjectID"].ToString()
                            };

                            listProjectSettings.Add(ps);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }
            }

            return(listProjectSettings);
        }
Example #18
0
        public Dictionary <GPS, AssignedGPSDetails> GetAllGPSAssignedToFisherEx(Fisher f, ProjectSetting p)
        {
            var dict = new Dictionary <GPS, AssignedGPSDetails>();

            foreach (var fg in BSCEntities.FisherGPSViewModel.FisherGPSCollection
                     .Where(t => t.Fisher.FisherID == f.FisherID)
                     .Where(t => t.ProjectSetting.ProjectID == p.ProjectID)
                     .OrderBy(t => t.GPS.AssignedName)
                     .ThenByDescending(t => t.DateAssigned))

            {
                var agpsd = new AssignedGPSDetails();

                if (dict.Keys.Contains(fg.GPS))
                {
                    dict[fg.GPS].NumberOfTimesAssigned++;
                    //dict[fg.GPS].AddDateToRange((DateTime)fg.DateAssigned, fg.DateReturned);
                    dict[fg.GPS].AddFisherGPS(fg);
                }
                else
                {
                    //agdr = new AssignedGPSDateRange(fg.GPS, (DateTime)fg.DateAssigned, fg.DateReturned, 1);
                    agpsd = new AssignedGPSDetails(fg.GPS, fg, 1);
                    dict.Add(fg.GPS, agpsd);
                }
            }

            return(dict);
        }