Example #1
0
        private void AddRecordButton_Click(object sender, RoutedEventArgs e)
        {
            String errString = ValidateBat((Bat)BatNameListBox.SelectedItem);
            int    index     = BatNameListBox.SelectedIndex;

            if (String.IsNullOrWhiteSpace(errString))
            {
                Bat bat = new Bat();
                bat.Name       = "bat";
                bat.Batgenus   = "BatGenus";
                bat.BatSpecies = "BatSpecies";
                BatCommonName bcn = new BatCommonName();
                bcn.SortIndex      = (short)-1;
                bcn.BatCommonName1 = "BatCommonName";

                short max = short.MinValue;
                foreach (var cn in bat.BatCommonNames)
                {
                    if (cn.SortIndex > max)
                    {
                        max = cn.SortIndex;
                    }
                }
                bcn.SortIndex = ++max;
                bat.BatCommonNames.Add(bcn);
                BatTag bt = new BatTag();
                bt.BatTag1 = "BatTag";
                max        = short.MinValue;
                foreach (var tg in bat.BatTags)
                {
                    if (tg.SortIndex.Value > max)
                    {
                        max = tg.SortIndex.Value;
                    }
                }
                bt.SortIndex = ++max;

                bat.BatTags.Add(bt);

                int?maxi = int.MaxValue;
                foreach (var b in BatList)
                {
                    if (b.SortIndex > maxi)
                    {
                        maxi = b.SortIndex;
                    }
                }
                bat.SortIndex = maxi.Value + 1;
                BatList.Add(bat);
                BatList = new ObservableCollection <Bat>(BatList.OrderBy(newbat => newbat.SortIndex));
                BatNameListBox.ItemsSource  = BatList;
                BatNameListBox.SelectedItem = bat;
            }
            else
            {
                DisplayInvalidErrorMessage(errString);
            }
        }
Example #2
0
        /// <summary>
        /// Handles the Click event of the TagAddButton control.
        /// Adds the text in the edit box as a new TagID
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void TagAddButton_Click(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(IDTagEditBox.Text))
            {
                var selectedBat = SelectedBat(); // returns NULL !!!!!!!!!!!!!!!!!!!!!!!!!
                var tags        = from tg in selectedBat.BatTags
                                  orderby tg.SortIndex
                                  select tg;


                if (tags != null)
                {
                    foreach (var tag in tags)
                    {
                        if (tag.BatTag1 == IDTagEditBox.Text)
                        {
                            return;// tag already exists so we can't add it again
                        }
                    }

                    foreach (var tag in tags)
                    {
                        tag.SortIndex++;
                    }

                    BatTag newTag = new BatTag();
                    newTag.BatTag1   = IDTagEditBox.Text;
                    newTag.SortIndex = 0;
                    selectedBat.BatTags.Add(newTag);
                    batReferenceDataContext.SubmitChanges();
                }


                /*
                 * if(nullTag!= null)
                 * {
                 *  nullTag.Remove();
                 * }
                 * var existingTags = selectedBat.DescendantsAndSelf("BatTag");
                 * if (existingTags == null || existingTags.Count() <= 0)
                 * {
                 *  selectedBat.Add(new XElement("BatTag", IDTagEditBox.Text));
                 * }
                 * else
                 * {
                 *
                 *  existingTags.LastOrDefault().AddAfterSelf(new XElement("BatTag", IDTagEditBox.Text));
                 * }*/
                //selectedBat.Add(new XElement("BatCommonName", CommonNameEditBox.Text));
                RefreshBatNameListBox(true);
            }
        }
Example #3
0
        /// <summary>
        /// Merges the tags contained in the XElement Bat into the database
        /// whose DataContext is provided linked to the bat entry ID
        /// </summary>
        /// <param name="bat">The bat.</param>
        /// <param name="thisBatID">The this bat identifier.</param>
        /// <param name="batReferenceDataContext">The bat reference data context.</param>
        private void MergeTags(XElement bat, int thisBatID, BatReferenceDBLinqDataContext batReferenceDataContext)
        {
            var newTags = bat.Descendants("BatTag");
            var oldTags = from tag in batReferenceDataContext.BatTags
                          where tag.BatID == thisBatID
                          select tag.BatTag1;
            var oldTagsAsList = oldTags.ToList();

            foreach (string tag in newTags)
            {
                if (!oldTagsAsList.Contains(tag))
                {
                    BatTag bt = new BatTag();
                    bt.BatTag1 = tag;
                    bt.BatID   = thisBatID;
                    batReferenceDataContext.BatTags.InsertOnSubmit(bt);
                    batReferenceDataContext.SubmitChanges();
                }
            }
        }
Example #4
0
        /// <summary>
        /// Merges the bat to database.
        /// </summary>
        /// <param name="bat">The bat.</param>
        /// <param name="batReferenceDataContext">The bat reference data context.</param>
        /// <exception cref="NotImplementedException"></exception>
        private void MergeBatToDB(XElement bat, BatReferenceDBLinqDataContext batReferenceDataContext, short i)
        {
            try
            {
                Bat newBat = null;
                if (batReferenceDataContext == null)
                {
                    return;
                }
                if (bat == null)
                {
                    return;
                }
                bool isNew = false;
                if (batReferenceDataContext.Bats.Count() <= 0)
                {
                    isNew     = true;
                    newBat    = new Bat();
                    newBat.Id = -1;
                }
                else
                {
                    var newBats = (from dBbat in batReferenceDataContext.Bats
                                   where dBbat.Name == bat.Attribute("Name").Value
                                   select dBbat);
                    if (newBats != null && newBats.Count() > 0)
                    {
                        newBat = newBats.FirstOrDefault();
                    }
                }
                if (newBat == null || newBat.Id < 0)
                {
                    newBat    = new Bat();
                    newBat.Id = -1;
                    isNew     = true;
                }
                newBat.Name       = bat.Attribute("Name").Value;
                newBat.Batgenus   = bat.Descendants("BatGenus").FirstOrDefault().Value;
                newBat.BatSpecies = bat.Descendants("BatSpecies").FirstOrDefault().Value;
                newBat.SortIndex  = i;
                if (isNew)
                {
                    batReferenceDataContext.Bats.InsertOnSubmit(newBat);
                }
                batReferenceDataContext.SubmitChanges();
                var newCommonNames = bat.Descendants("BatCommonName");
                if (newCommonNames != null && newCommonNames.Count() > 0)
                {
                    short index = 0;
                    foreach (var name in newCommonNames)
                    {
                        BatCommonName bcn = new BatCommonName();
                        bcn.BatCommonName1 = name.Value;
                        bcn.BatID          = newBat.Id;
                        bcn.SortIndex      = index++;
                        newBat.BatCommonNames.Add(bcn);
                    }
                }

                var newTags = bat.Descendants("BatTag");
                if (newTags != null && newTags.Count() > 0)
                {
                    short index = 0;
                    foreach (var tag in newTags)
                    {
                        BatTag bt = new BatTag();
                        bt.BatTag1   = tag.Value;
                        bt.BatID     = newBat.Id;
                        bt.SortIndex = index++;
                        newBat.BatTags.Add(bt);
                    }
                }

                /*     if (isNew)
                 *   {
                 *       batReferenceDataContext.Bats.InsertOnSubmit(newBat);
                 *   }*/
                batReferenceDataContext.SubmitChanges();
                //int thisBatID = newBat.Id;

                //MergeCommonNames(bat, thisBatID, batReferenceDataContext);


                //MergeTags(bat, thisBatID, batReferenceDataContext);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex);
            }
        }
 partial void DeleteBatTag(BatTag instance);
 partial void UpdateBatTag(BatTag instance);
 partial void InsertBatTag(BatTag instance);
		private void detach_BatTags(BatTag entity)
		{
			this.SendPropertyChanging();
			entity.Bat = null;
		}
Example #9
0
        private void AddRecordButton_Click(object sender, RoutedEventArgs e)
        {
            String errString = ValidateBat((Bat)BatNameListBox.SelectedItem);
            int index = BatNameListBox.SelectedIndex;
            if (String.IsNullOrWhiteSpace(errString))
            {
                Bat bat = new Bat();
                bat.Name = "bat";
                bat.Batgenus = "BatGenus";
                bat.BatSpecies = "BatSpecies";
                BatCommonName bcn = new BatCommonName();
                bcn.SortIndex = (short)-1;
                bcn.BatCommonName1 = "BatCommonName";
                
                short max = short.MinValue;
                foreach(var cn in bat.BatCommonNames)
                {
                    if (cn.SortIndex > max) max = cn.SortIndex;
                }
                bcn.SortIndex = ++max;
                bat.BatCommonNames.Add(bcn);
                BatTag bt = new BatTag();
                bt.BatTag1 = "BatTag";
                max = short.MinValue;
                foreach(var tg in bat.BatTags)
                {
                    if (tg.SortIndex.Value > max) max = tg.SortIndex.Value;
                }
                bt.SortIndex = ++max;
                
                bat.BatTags.Add(bt);

                int? maxi = int.MaxValue;
                foreach(var b in BatList)
                {
                    if (b.SortIndex > maxi) maxi = b.SortIndex;
                }
                bat.SortIndex = maxi.Value + 1;
                BatList.Add(bat);
                BatList = new ObservableCollection<Bat>(BatList.OrderBy(newbat => newbat.SortIndex));
                BatNameListBox.ItemsSource = BatList;
                BatNameListBox.SelectedItem = bat;

            }
            else
            {
                DisplayInvalidErrorMessage(errString);
            }
        }
Example #10
0
        /// <summary>
        /// Merges the bat to database.
        /// </summary>
        /// <param name="bat">The bat.</param>
        /// <param name="batReferenceDataContext">The bat reference data context.</param>
        /// <exception cref="NotImplementedException"></exception>
        private void MergeBatToDB(XElement bat, BatReferenceDBLinqDataContext batReferenceDataContext,short i)
        {
            try
            {
                Bat newBat = null;
                if (batReferenceDataContext == null) return;
                if (bat == null) return;
                bool isNew = false;
                if (batReferenceDataContext.Bats.Count() <= 0)
                {
                    isNew = true;
                    newBat = new Bat();
                    newBat.Id = -1;
                }
                else
                {
                    var newBats = (from dBbat in batReferenceDataContext.Bats
                                   where dBbat.Name == bat.Attribute("Name").Value
                                   select dBbat);
                    if (newBats != null && newBats.Count() > 0)
                    {
                        newBat = newBats.FirstOrDefault();
                    }
                }
                if (newBat == null || newBat.Id < 0)
                {
                    newBat = new Bat();
                    newBat.Id = -1;
                    isNew = true;
                }
                newBat.Name = bat.Attribute("Name").Value;
                newBat.Batgenus = bat.Descendants("BatGenus").FirstOrDefault().Value;
                newBat.BatSpecies = bat.Descendants("BatSpecies").FirstOrDefault().Value;
                newBat.SortIndex = i;
                if (isNew)
                {
                    batReferenceDataContext.Bats.InsertOnSubmit(newBat);
                }
                batReferenceDataContext.SubmitChanges();
                var newCommonNames = bat.Descendants("BatCommonName");
                if (newCommonNames != null && newCommonNames.Count() > 0)
                {
                    short index = 0;
                    foreach (var name in newCommonNames)
                    {
                        BatCommonName bcn = new BatCommonName();
                        bcn.BatCommonName1 = name.Value;
                        bcn.BatID = newBat.Id;
                        bcn.SortIndex = index++;
                        newBat.BatCommonNames.Add(bcn);
                    }
                }

                var newTags = bat.Descendants("BatTag");
                if (newTags != null && newTags.Count() > 0)
                {
                    short index = 0;
                    foreach (var tag in newTags)
                    {
                        BatTag bt = new BatTag();
                        bt.BatTag1 = tag.Value;
                        bt.BatID = newBat.Id;
                        bt.SortIndex = index++;
                        newBat.BatTags.Add(bt);
                    }
                }

           /*     if (isNew)
                {
                    batReferenceDataContext.Bats.InsertOnSubmit(newBat);
                }*/
                batReferenceDataContext.SubmitChanges();
                //int thisBatID = newBat.Id;

                //MergeCommonNames(bat, thisBatID, batReferenceDataContext);


                //MergeTags(bat, thisBatID, batReferenceDataContext);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex);
            }

            


        }
Example #11
0
 /// <summary>
 /// Merges the tags contained in the XElement Bat into the database
 /// whose DataContext is provided linked to the bat entry ID
 /// </summary>
 /// <param name="bat">The bat.</param>
 /// <param name="thisBatID">The this bat identifier.</param>
 /// <param name="batReferenceDataContext">The bat reference data context.</param>
 private void MergeTags(XElement bat,int thisBatID, BatReferenceDBLinqDataContext batReferenceDataContext)
 {
     var newTags = bat.Descendants("BatTag");
     var oldTags = from tag in batReferenceDataContext.BatTags
                   where tag.BatID == thisBatID
                   select tag.BatTag1;
     var oldTagsAsList = oldTags.ToList();
     foreach (string tag in newTags)
     {
         if (!oldTagsAsList.Contains(tag))
         {
             BatTag bt = new BatTag();
             bt.BatTag1 = tag;
             bt.BatID = thisBatID;
             batReferenceDataContext.BatTags.InsertOnSubmit(bt);
             batReferenceDataContext.SubmitChanges();
         }
     }
 }
Example #12
0
 partial void DeleteBatTag(BatTag instance);
Example #13
0
 partial void UpdateBatTag(BatTag instance);
Example #14
0
 partial void InsertBatTag(BatTag instance);
Example #15
0
 private void detach_BatTags(BatTag entity)
 {
     this.SendPropertyChanging();
     entity.Bat = null;
 }
Example #16
0
 private void attach_BatTags(BatTag entity)
 {
     this.SendPropertyChanging();
     entity.Bat = this;
 }
		private void attach_BatTags(BatTag entity)
		{
			this.SendPropertyChanging();
			entity.Bat = this;
		}
Example #18
0
        /// <summary>
        /// Handles the Click event of the TagAddButton control.
        /// Adds the text in the edit box as a new TagID
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void TagAddButton_Click(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(IDTagEditBox.Text))
            {

                var selectedBat = SelectedBat(); // returns NULL !!!!!!!!!!!!!!!!!!!!!!!!!
                var tags = from tg in selectedBat.BatTags
                           orderby tg.SortIndex
                           select tg;

                
                if (tags != null)
                {
                    foreach (var tag in tags)
                    {
                        if (tag.BatTag1 == IDTagEditBox.Text)
                        {
                            return;// tag already exists so we can't add it again
                        }
                    }

                    foreach(var tag in tags)
                    {
                        tag.SortIndex++;
                    }

                    BatTag newTag = new BatTag();
                    newTag.BatTag1 = IDTagEditBox.Text;
                    newTag.SortIndex = 0;
                    selectedBat.BatTags.Add(newTag);
                    batReferenceDataContext.SubmitChanges();
                }


                /*
                if(nullTag!= null)
                {
                    nullTag.Remove();
                }
                var existingTags = selectedBat.DescendantsAndSelf("BatTag");
                if (existingTags == null || existingTags.Count() <= 0)
                {
                    selectedBat.Add(new XElement("BatTag", IDTagEditBox.Text));
                }
                else
                {

                    existingTags.LastOrDefault().AddAfterSelf(new XElement("BatTag", IDTagEditBox.Text));
                }*/
                //selectedBat.Add(new XElement("BatCommonName", CommonNameEditBox.Text));
                RefreshBatNameListBox(true);

            }
        }