Example #1
0
        private void LandingSiteCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            LandingSite editedLandingSite = new LandingSite();

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                int newIndex = e.NewStartingIndex;
                editedLandingSite = LandingSiteCollection[newIndex];
                LandingSites.Add(editedLandingSite);
            }
            break;

            case NotifyCollectionChangedAction.Remove:
            {
                List <LandingSite> tempListOfRemovedItems = e.OldItems.OfType <LandingSite>().ToList();
                editedLandingSite = tempListOfRemovedItems[0];
                LandingSites.Delete(editedLandingSite.LandingSiteID);
            }
            break;

            case NotifyCollectionChangedAction.Replace:
            {
                List <LandingSite> tempListOfLandingSites = e.NewItems.OfType <LandingSite>().ToList();
                editedLandingSite = tempListOfLandingSites[0];
                LandingSites.Update(editedLandingSite);              // As the IDs are unique, only one row will be effected hence first index only
            }
            break;
            }
            EntityChangedEventArgs args = new EntityChangedEventArgs(editedLandingSite.GetType().Name, editedLandingSite);

            EntityChanged?.Invoke(this, args);
        }
Example #2
0
 public void AddRecordToRepo(LandingSite ls)
 {
     if (ls == null)
     {
         throw new ArgumentNullException("Error: The argument is Null");
     }
     LandingSiteCollection.Add(ls);
 }
        public void RefreshFisherLandingSite(LandingSite ls)
        {
            foreach (var fisher in FisherCollection
                     .Where(t => t.LandingSite.LandingSiteID == ls.LandingSiteID))

            {
                fisher.LandingSite = ls;
            }
        }
Example #4
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 #5
0
        public bool CanDeleteEntity(LandingSite ls)
        {
            return(BSCEntities.SamplingViewModel.SamplingCollection
                   .Where(t => t.LandingSite.LandingSiteID == ls.LandingSiteID).ToList().Count == 0

                   &&

                   BSCEntities.FisherViewModel.FisherCollection
                   .Where(l => l.LandingSite.LandingSiteID == ls.LandingSiteID).ToList().Count == 0);
        }
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 bool EntityValidated(LandingSite landingSite, out List <string> messages, bool isNew = false)
        {
            messages = new List <string>();

            if (landingSite.LandingSiteName.Length < 5)
            {
                messages.Add("Landing site's name must be at least 5 characters long");
            }


            if (landingSite.Municipality == null)
            {
                messages.Add("Municipality cannot be empty");
            }

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

            using (OleDbConnection conn = new OleDbConnection(Global.ConnectionString))
            {
                conn.Open();
                var sql = $@"Update LandingSite set
                                LandingSiteName = '{ls.LandingSiteName}',
                                Municipality = '{ls.Municipality.MunicipalityID}',
                                Waypoint = '{ls.Waypoint.SerializeString()}'
                            WHERE LandingSiteId={{{ls.LandingSiteID}}}";
                using (OleDbCommand update = new OleDbCommand(sql, conn))
                {
                    success = update.ExecuteNonQuery() > 0;
                }
            }
            return(success);
        }
Example #9
0
        public void UpdateRecordInRepo(LandingSite ls)
        {
            if (ls.LandingSiteID == null)
            {
                throw new Exception("Error: ID cannot be null");
            }

            int index = 0;

            while (index < LandingSiteCollection.Count)
            {
                if (LandingSiteCollection[index].LandingSiteID == ls.LandingSiteID)
                {
                    LandingSiteCollection[index] = ls;
                    break;
                }
                index++;
            }
        }
        private List <LandingSite> getLandingSites()
        {
            List <LandingSite> listLandingSites = new List <LandingSite>();
            var dt = new DataTable();

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

                    var adapter = new OleDbDataAdapter(query, conection);
                    adapter.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        listLandingSites.Clear();
                        foreach (DataRow dr in dt.Rows)
                        {
                            LandingSite ls = new LandingSite();
                            ls.LandingSiteID   = dr["LandingSiteId"].ToString();
                            ls.LandingSiteName = dr["LandingSiteName"].ToString();
                            if (dr["Municipality"].ToString().Length > 0)
                            {
                                ls.Municipality = BSCEntities.MunicipalityViewModel.GetMunicipality(Convert.ToInt32(dr["Municipality"]));
                            }
                            ls.Waypoint = new Waypoint(dr["Waypoint"].ToString());
                            listLandingSites.Add(ls);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }
            }

            return(listLandingSites);
        }
        public bool Add(LandingSite ls)
        {
            string wpt = "";

            if (ls.Waypoint != null)
            {
                wpt = ls.Waypoint.SerializeString();
            }

            bool success = false;

            using (OleDbConnection conn = new OleDbConnection(Global.ConnectionString))
            {
                conn.Open();
                var sql = $@"Insert into LandingSite (LandingSiteID, LandingSiteName,Municipality,Waypoint)
                           Values 
                           ({{{ls.LandingSiteID}}},'{ls.LandingSiteName}',{ls.Municipality.MunicipalityID},'{wpt}')";
                using (OleDbCommand update = new OleDbCommand(sql, conn))
                {
                    success = update.ExecuteNonQuery() > 0;
                }
            }
            return(success);
        }
Example #12
0
 public Fisher(string id, string fisherName, LandingSite landingSite)
 {
     FisherID    = id;
     FisherName  = fisherName;
     LandingSite = landingSite;
 }
Example #13
0
 public List <Sampling> GetAllSamplings(LandingSite ls)
 {
     return(SamplingCollection
            .Where(t => t.LandingSite.LandingSiteID == ls.LandingSiteID).ToList());
 }