Пример #1
0
        private void btnAddNew_Click(object sender, EventArgs e)
        {
            double d;
            if (!model.IsValid() || (tbLat.Text.Length > 0 && !double.TryParse(tbLat.Text, out d)) || 
                (tbLng.Text.Length > 0 && !double.TryParse(tbLng.Text, out d)))
            {
                MessageBox.Show(Translations.ValidationError, Translations.ValidationErrorTitle);
                return;
            }
            if (model.AdminLevels == null || model.AdminLevels.Count < 1)
            {
                MessageBox.Show(Translations.LocationRequired, Translations.ValidationErrorTitle);
                return;
            }

            bsSentinelSite.EndEdit();
            SurveyRepository r = new SurveyRepository();
            int userid = ApplicationData.Instance.GetUserId();
            if (model.Id > 0)
                model = r.Update(model, userid);
            else
                model = r.Insert(model, userid);

            OnSave(model);
            this.Close();
        }
Пример #2
0
 private void sites_OnAdd(SentinelSite newSite)
 {
     // Add the new site to the collection
     SentinelSites.Add(newSite);
     // Update the list
     UpdateSiteList(newSite);
 }
Пример #3
0
 private void sites_OnEdit(SentinelSite editedSite)
 {
     // Find the corresponding site
     SentinelSite matchingSite = SentinelSites.Where(s => s.Id == editedSite.Id).FirstOrDefault();
     if (matchingSite != null)
     {
         int currentIndex = SentinelSites.IndexOf(matchingSite);
         // Replace the matching site
         if (currentIndex >= 0)
             SentinelSites[currentIndex] = editedSite;
     }
     else
     {
         // Add the site to the collection
         SentinelSites.Add(editedSite);
     }
     // Update the list
     UpdateSiteList(editedSite);
 }
Пример #4
0
 private void CloneSite(AdminLevel source, List<AdminLevelAllocation> dests, OleDbCommand command, OleDbConnection connection, Dictionary<int, SentinelSite> newSites, SentinelSite site)
 {
     var newSite = Util.DeepClone(site);
     // remove other admin levels
     site.AdminLevels = new List<AdminLevel> { source };
     surveyRepo.Update(site, userId, connection, command);
     // update admin levels to new dests
     newSite.Id = 0;
     newSite.AdminLevels.RemoveAll(a => a.Id == source.Id);
     newSite.AdminLevels.AddRange(dests.Select(a => a.Unit));
     newSites.Add(site.Id, surveyRepo.Insert(newSite, userId, connection, command));
 }
Пример #5
0
 public SentinelSiteAdd(List<AdminLevel> adminLevels)
     : base()
 {
     model = new SentinelSite { AdminLevels = adminLevels };
     InitializeComponent();
 }
Пример #6
0
 public SentinelSiteAdd(SentinelSite m)
     : base()
 {
     model = m;
     InitializeComponent();
 }
Пример #7
0
 private void UpdateSiteList(SentinelSite savedSite)
 {
     // Order the sites
     SentinelSites = SentinelSites.OrderBy(s => s.SiteName).ToList();
     // Update the ListView
     sentinelSiteListView.SetObjects(SentinelSites);
     // Update the Survey
     if (savedSite != null)
         Survey.SentinelSiteId = savedSite.Id;
     // Callback action to update the invoking UI
     OnSave();
 }