Example #1
0
        public bool Add(FisherGPS fg)
        {
            string dateAssigned = "null";

            if (fg.DateAssigned != null)
            {
                dateAssigned = $"'{((DateTime)fg.DateAssigned).ToString()}'";
            }
            string dateReturned = "null";

            if (fg.DateReturned != null)
            {
                dateReturned = $"'{((DateTime)fg.DateReturned).ToString()}'";
            }
            bool success = false;

            using (OleDbConnection conn = new OleDbConnection(Global.ConnectionString))
            {
                conn.Open();
                var sql = $@"Insert into fisher_gps (GPS, RowID, Project, DateAssigned,DateReturned,Fisher)
                           Values 
                           ({{{fg.GPS.ID}}},{{{fg.RowID}}},{{{fg.ProjectSetting.ProjectID}}},{dateAssigned},{dateReturned}, {{{fg.Fisher.FisherID}}})";
                using (OleDbCommand update = new OleDbCommand(sql, conn))
                {
                    success = update.ExecuteNonQuery() > 0;
                }
            }
            return(success);
        }
Example #2
0
        public bool Update(FisherGPS fg)
        {
            bool   success      = false;
            string dateAssigned = "null";

            if (fg.DateAssigned != null)
            {
                dateAssigned = $"'{((DateTime)fg.DateAssigned).ToString()}'";
            }
            string dateReturned = "null";

            if (fg.DateReturned != null)
            {
                dateReturned = $"'{fg.DateReturned.ToString()}'";
            }
            using (OleDbConnection conn = new OleDbConnection(Global.ConnectionString))
            {
                conn.Open();
                var sql = $@"Update fisher_gps set
                                GPS = {{{fg.GPS.ID}}},
                                Project = {{{fg.ProjectSetting.ProjectID}}},
                                DateAssigned ={dateAssigned},
                                DateReturned= {dateReturned},
                                Fisher={{{fg.Fisher.FisherID}}}
                            WHERE RowID={{{fg.RowID}}}";
                using (OleDbCommand update = new OleDbCommand(sql, conn))
                {
                    success = update.ExecuteNonQuery() > 0;
                }
            }
            return(success);
        }
Example #3
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);
        }
Example #4
0
 public void AddRecordToRepo(FisherGPS fg)
 {
     if (fg == null)
     {
         throw new ArgumentNullException("Error: The argument is Null");
     }
     FisherGPSCollection.Add(fg);
 }
Example #5
0
 public AssignedGPSDetails(GPS gps, FisherGPS fisherGPS, int numberOfTimesAssigned)
 {
     if (FisherGPSList == null)
     {
         FisherGPSList = new List <FisherGPS>();
     }
     GPS = gps;
     FisherGPSList.Add(fisherGPS);
     NumberOfTimesAssigned = numberOfTimesAssigned;
 }
Example #6
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;
 }
Example #7
0
        public List <FisherGPS> GetAllFisherGPS(GPS g, FisherGPS fg = null)
        {
            if (fg == null)
            {
                return(FisherGPSCollection.Where(t => t.GPS.ID == g.ID).ToList());
            }
            else

            {
                return(FisherGPSCollection
                       .Where(t => t.GPS.ID == g.ID)
                       .Where(t => t.DateReturned != null)
                       .Where(t => t.RowID != fg.RowID).ToList());
            }
        }
Example #8
0
        private List <FisherGPS> getFisherGPSes()
        {
            string           query;
            List <FisherGPS> listFisherGPSes = new List <FisherGPS>();
            var dt = new DataTable();

            using (var conection = new OleDbConnection(Global.ConnectionString))

            {
                try
                {
                    conection.Open();

                    query = $@"SELECT * from fisher_gps";


                    var adapter = new OleDbDataAdapter(query, conection);
                    adapter.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        listFisherGPSes.Clear();
                        foreach (DataRow dr in dt.Rows)
                        {
                            FisherGPS fg = new FisherGPS();
                            fg.RowID          = dr["RowID"].ToString();
                            fg.GPS            = BSCEntities.GPSViewModel.GetGPS(dr["GPS"].ToString());
                            fg.ProjectSetting = BSCEntities.ProjectSettingViewModel.GetProjectSetting(dr["Project"].ToString());
                            fg.Fisher         = BSCEntities.FisherViewModel.GetFisher(dr["Fisher"].ToString());
                            fg.DateAssigned   = (DateTime)dr["DateAssigned"];
                            if (dr["DateReturned"].ToString().Length > 0)
                            {
                                fg.DateReturned = (DateTime)dr["DateReturned"];
                            }
                            listFisherGPSes.Add(fg);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }
            }

            return(listFisherGPSes);
        }
Example #9
0
        public void UpdateRecordInRepo(FisherGPS fg)
        {
            if (fg.RowID == null)
            {
                throw new Exception("Error: ID cannot be null");
            }

            int index = 0;

            while (index < FisherGPSCollection.Count)
            {
                if (FisherGPSCollection[index].RowID == fg.RowID)
                {
                    FisherGPSCollection[index] = fg;
                    break;
                }
                index++;
            }
        }
Example #10
0
 public FisherGPS GetFisherGPS(FisherGPS fg, DateTime date)
 {
     try
     {
         return(FisherGPSCollection
                .Single(a => a.GPS.ID == fg.GPS.ID &&
                        a.DateAssigned <= date &&
                        a.RowID != fg.RowID &&
                        (a.DateReturned == null ? DateTime.Now : a.DateReturned) >= date));
     }
     catch (System.InvalidOperationException)
     {
         return(null);
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
         return(null);
     }
 }
 public FisherGPSDetail(FisherGPS fg)
 {
     _fg = fg;
 }
Example #12
0
 public FisherGPS LastGPSUser(GPS gps, FisherGPS fg)
 {
     return(GetAllFisherGPS(gps, fg)
            .OrderByDescending(t => t.DateAssigned).FirstOrDefault());
 }
Example #13
0
        public bool EntityValidated(FisherGPS fg, out List <EntityValidationMessage> entityMessages, bool isNew)
        {
            entityMessages = new List <EntityValidationMessage>();
            DateTime? dateToCompare = null;
            string    dateFormat    = "MMM-dd-yyyy";
            string    comparedDate  = "";
            FisherGPS FisherWithLatestReturnedDate = LatestReturnedDateByFisher(fg.Fisher);

            if (FisherWithLatestReturnedDate == null && fg.ProjectSetting != null)
            {
                dateToCompare = (DateTime)fg.ProjectSetting.DateStart;
                comparedDate  = $"start of Project which is {((DateTime)fg.ProjectSetting.DateStart).ToString(dateFormat)}";
            }
            else if (FisherWithLatestReturnedDate != null)
            {
                if (FisherWithLatestReturnedDate.DateReturned == null)
                {
                    dateToCompare = (DateTime)FisherWithLatestReturnedDate.DateAssigned;
                    comparedDate  = $"assigned date of last GPS assigned to fisher which is {((DateTime)FisherWithLatestReturnedDate.DateAssigned).ToString(dateFormat)}";
                }
                else
                {
                    dateToCompare = (DateTime)FisherWithLatestReturnedDate.DateReturned;
                    comparedDate  = $"returned date of last GPS assigned to fisher which is {((DateTime)FisherWithLatestReturnedDate.DateReturned).ToString(dateFormat)}";
                }
            }

            if (fg.DateAssigned == null)
            {
                entityMessages.Add(new EntityValidationMessage("Assigned date cannot be empty"));
            }
            else
            {
                if (dateToCompare != null && fg.DateAssigned < dateToCompare)
                {
                    entityMessages.Add(new EntityValidationMessage($"Date assigned should be after {comparedDate}"));
                }
                else if (fg.DateAssigned > DateTime.Now)
                {
                    entityMessages.Add(new EntityValidationMessage("Date assigned cannot be a future date"));
                }
                else
                {
                    var f = GetFisherGPS(fg, (DateTime)fg.DateAssigned);
                    if (f != null)
                    {
                        entityMessages.Add(new EntityValidationMessage("Cannot use assigned date because GPS is not available at this time"));
                    }
                }
            }

            if (fg.DateReturned != null)
            {
                if (isNew)
                {
                    entityMessages.Add(new EntityValidationMessage("Returned date is not required for new GPS assignment", MessageType.Warning));
                }

                if (fg.DateReturned < fg.DateAssigned)
                {
                    entityMessages.Add(new EntityValidationMessage("Date returned must be on or after date assigned"));
                }
                else if (fg.DateReturned > DateTime.Now)
                {
                    entityMessages.Add(new EntityValidationMessage("Date returned cannot be a future date"));
                }
                else
                {
                    var f = GetFisherGPS(fg, (DateTime)fg.DateReturned);
                    if (f != null)
                    {
                        entityMessages.Add(new EntityValidationMessage("Cannot use return date because GPS is not available at this time"));
                    }
                }
            }
            else

            {
                //check if current user is the latest GPS user. If not then date returned must not be null
                var lastUser = LastGPSUser(fg.GPS);
                if (fg.DateAssigned < lastUser.DateAssigned)
                {
                    entityMessages.Add(new EntityValidationMessage("Return date cannot be empty because this GPS has been used in a later date"));
                }
            }

            if (fg.GPS == null)
            {
                entityMessages.Add(new EntityValidationMessage("GPS cannot be empty"));
            }

            if (fg.ProjectSetting == null)
            {
                entityMessages.Add(new EntityValidationMessage("Project cannot be empty"));
            }


            return(entityMessages.Count == 0);
        }
Example #14
0
 public bool CanDeleteEntity(FisherGPS fg)
 {
     return(BSCEntities.SamplingViewModel.SamplingCollection
            .Where(t => t.FisherGPS.RowID == fg.RowID).ToList().Count == 0);
 }
Example #15
0
 public void AddFisherGPS(FisherGPS fisherGPS)
 {
     FisherGPSList.Add(fisherGPS);
 }