示例#1
0
        private void LoadDataToBatList()
        {
            int lastSelectedIndex = BatNameListBox.SelectedIndex;

            BatList.Clear();
            var bats = from bat in batReferenceDataContext.Bats
                       orderby bat.SortIndex
                       select bat;
            short i = 1;

            foreach (var bat in bats)
            {
                bat.SortIndex = i++;
            }
            batReferenceDataContext.SubmitChanges();
            BatList = new ObservableCollection <Bat>(bats.ToList <Bat>());
        }
示例#2
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();
                }
            }
        }
示例#3
0
        /// <summary>
        /// Merges the common names 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 MergeCommonNames(XElement bat, int thisBatID, BatReferenceDBLinqDataContext batReferenceDataContext)
        {
            var newCommonNames = bat.Descendants("BatCommonName");
            var oldCommonNames = from name in batReferenceDataContext.BatCommonNames
                                 where name.BatID == thisBatID
                                 select name.BatCommonName1;
            var oldCommonNamesAsList = oldCommonNames.ToList();

            foreach (string newname in newCommonNames)
            {
                if (!oldCommonNamesAsList.Contains(newname))
                {
                    BatCommonName bcn = new BatCommonName();
                    bcn.BatCommonName1 = newname;
                    bcn.BatID          = thisBatID;
                    batReferenceDataContext.BatCommonNames.InsertOnSubmit(bcn);
                    batReferenceDataContext.SubmitChanges();
                }
            }
        }
示例#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);
            }
        }
示例#5
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);
            }

            


        }
示例#6
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();
         }
     }
 }
示例#7
0
 /// <summary>
 /// Merges the common names 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 MergeCommonNames(XElement bat, int thisBatID, BatReferenceDBLinqDataContext batReferenceDataContext)
 {
     var newCommonNames = bat.Descendants("BatCommonName");
     var oldCommonNames = from name in batReferenceDataContext.BatCommonNames
                          where name.BatID == thisBatID
                          select name.BatCommonName1;
     var oldCommonNamesAsList = oldCommonNames.ToList();
     foreach (string newname in newCommonNames)
     {
         if (!oldCommonNamesAsList.Contains(newname))
         {
             BatCommonName bcn = new BatCommonName();
             bcn.BatCommonName1 = newname;
             bcn.BatID = thisBatID;
             batReferenceDataContext.BatCommonNames.InsertOnSubmit(bcn);
             batReferenceDataContext.SubmitChanges();
         }
     }
 }