예제 #1
0
 public bool DeletePerson(Person person)
 {
     try
     {
         if (person != null)
         {
             foreach (var listInclude in GetListsWithTree(person))
             {
                 var element = listInclude.Children.FirstOrDefault(x => x.child.Name == person.Name);
                 listInclude.Children.Remove(element);
                 db.Delete(element);
                 db.Store(listInclude);
             }
             foreach (var el in person.Children.ToList())
             {
                 DeleteChildFromList(person, el);
             }
             db.Delete(person);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }
예제 #2
0
 internal void RemoveFavouritFolderForAConnection()
 {
     try
     {
         FavouriteList Fav = FetchAllFavouritesForAConnection();
         if (Fav != null)
         {
             for (int i = 0; i < Fav.lstFavFolder.Count; i++)
             {
                 FavouriteFolder favFolder = Fav.lstFavFolder[i];
                 if (favFolder != null)
                 {
                     container.Delete(favFolder);
                 }
             }
             Fav.lstFavFolder.Clear();
             Fav.m_TimeOfCreation = Sharpen.Runtime.CurrentTimeMillis();
             container.Delete(Fav);
             container.Ext().Store(Fav, 5);
             container.Commit();
         }
     }
     catch (Exception oEx)
     {
         LoggingHelper.HandleException(oEx);
     }
 }
예제 #3
0
        public void DeleteContact(Contact selectedContact)
        {
            SetConfigureDelete();
            GetContact(selectedContact);

            if (Contact != null)
            {
                GetTelephones(selectedContact);
                var telephonesList = new List <Telephone>(Telephones);
                foreach (var item in telephonesList)
                {
                    _database.Delete(item);
                }

                Contact.Telephones.Clear();

                if (Contact.Address != null)
                {
                    _database.Delete(Contact.Address);
                }

                _database.Delete(Contact);
                _database.Commit();

                GetAllObjectsInDatabase();
            }
        }
예제 #4
0
        public void DeleteCategory(Guid ID)
        {
            if (ID == null)
            {
                return;
            }

            //BUILDING SODA QUERY
            var query = container.Query();

            query.Constrain(typeof(Category));
            query.Descend("_id").Constrain(ID).Equal();

            /*START USEFULDBFO STAFF*/
            var category = query.Execute().ToList <Category>(container, 2).FirstOrDefault();

            /*END USEFULDBFO STAFF*/

            if (category.CategoryProducts != null && category.CategoryProducts.Count > 0)
            {
                foreach (var product in category.CategoryProducts.Where(prod => prod != null))
                {
                    container.Delete(product);
                }

                container.Delete(category.CategoryProducts);
            }

            container.Delete(category);
        }
예제 #5
0
        private static void DeletePerson()
        {
            Console.WriteLine("Podaj imie:");
            var imie = Console.ReadLine();

            Console.WriteLine("Podaj nazwisko:");
            var nazwisko = Console.ReadLine();

            using (IObjectContainer db = Db4oEmbedded.OpenFile("baza.txt"))
            {
                var querry = db.Query <Person>(typeof(Person));
                var result = querry.FirstOrDefault(x => x.Name == imie && x.Lastname == nazwisko);
                if (result != null)
                {
                    if (result.Adress != null)
                    {
                        db.Delete(result.Adress);
                    }
                    if (result.Contacts != null)
                    {
                        foreach (var item in result.Contacts)
                        {
                            db.Delete(item);
                        }
                    }
                    db.Delete(result);
                }
            }
        }
예제 #6
0
        private bool DeleteProfile(IObjectContainer db, string username)
        {
            if (username == null)
            {
                throw new ArgumentNullException("username", "User name cannot be null.");
            }
            if (username.Length > 255)
            {
                throw new ArgumentException("User name exceeds 255 characters.");
            }
            if (username.Contains(","))
            {
                throw new ArgumentException("User name cannot contain a comma (,).");
            }

            var profiles = db.Query((Profile p) => p.Username == username && p.ApplicationName == applicationName);

            if (profiles.Count == 0)
            {
                return(false);
            }

            Profile profile = profiles[0];

            foreach (SettingsPropertyValue spv in profile.SettingsPropertyValueList)
            {
                db.Delete(spv);
            }

            db.Delete(profile);

            return(true);
        }
예제 #7
0
        public static void DeletePerson(IObjectContainer db)
        {
            Console.WriteLine("Podaj osobę, którą chcesz usunąć:");
            Console.WriteLine();
            Console.Write("Imię:\t\t");
            string firstName = Console.ReadLine();

            Console.Write("Nazwisko:\t");
            string lastName = Console.ReadLine();

            //try
            {
                Person     ex     = new Person(firstName, lastName);
                IObjectSet result = db.QueryByExample(ex);
                Person     found  = (Person)result.Next();

                db.Delete(found.Address);

                foreach (var phone in found.Phones.ToList())
                {
                    found.Phones.Remove(phone);
                }

                found.Phones.Clear();
                db.Delete(found);
                db.Commit();
                Console.WriteLine();
                Console.WriteLine("Pomyślnie usunięto osobę!");
            }
            //catch (Exception e)
            //{
            //    Console.WriteLine();
            //    Console.WriteLine("Taka osoba nie istnieje. Nie można kontynuować.");
            //}
        }
예제 #8
0
        private static void DeleteNumberForPerson()
        {
            Console.WriteLine("Podaj imie:");
            var imie = Console.ReadLine();

            Console.WriteLine("Podaj nazwisko:");
            var nazwisko = Console.ReadLine();

            using (IObjectContainer db = Db4oEmbedded.OpenFile("baza.txt"))
            {
                var querry = db.Query <Person>(typeof(Person));
                var result = querry.FirstOrDefault(x => x.Name == imie && x.Lastname == nazwisko);
                if (result != null)
                {
                    if (result.Contacts != null)
                    {
                        Console.WriteLine("Który numer chcesz usunąć?");
                        foreach (var item in result.Contacts)
                        {
                            if (item != null)
                            {
                                Console.WriteLine(item.Number);
                            }
                            else
                            {
                                Console.WriteLine("ten kontakt nie ma numerów");
                            }
                        }

                        if (result.Contacts != null)
                        {
                            var choice = Console.ReadLine().ToString();
                            foreach (var item in result.Contacts)
                            {
                                if (item == null)
                                {
                                    db.Delete(result.Contacts);
                                }
                                else
                                {
                                    if (choice == item.Number)
                                    {
                                        db.Delete(item);
                                    }
                                }
                            }
                        }
                        else
                        {
                            db.Delete(result.Contacts);
                            Console.WriteLine("ten numer nie ma kontaków");
                        }
                    }
                }
            }
        }
예제 #9
0
        public void RemovePrim(LLUUID primID)
        {
            IObjectSet result = db.Query(new UUIDQuery(primID));

            if (result.Count > 0)
            {
                PrimData found = (PrimData)result.Next();
                db.Delete(found);
            }
        }
예제 #10
0
        private void removeAuthorBtn_Click(object sender, RoutedEventArgs e)
        {
            var author = authorsListGrid.SelectedItem as Author;

            if (MessageBox.Show("Czy na pewno chcesz usunąć autora o nazwisku '" + author.LastName + "'?", "Potwierdzenie",
                                MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                _db.Delete(author);
                showAuthorsList();
            }
        }
 public void Delete(object obj)
 {
     try
     {
         inner.Delete(obj);
         inner.Commit();
     }
     catch (Db4oException ex)
     {
         throw new AmbienceException("An error occurred while deleting an object from the database.", ex);
     }
 }
예제 #12
0
        /// <summary>
        /// Checks the database for the player and if it does not exist then it adds it.
        /// Does not lock the database or commit
        /// </summary>
        /// <param name="entry">Player to record</param>
        /// <param name="overwrite">Overwrite an existing entry</param>
        /// <returns>Returns true if the player was recorded, otherwise false</returns>
        public bool RecordPlayer(PlayerEntry entry, bool overwrite)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            lock (_lobbycache)
            {
                //Return if the player has been cached and we are not overwriting.
                if (_lobbycache.Find(p => p.Id == entry.Id) != null && !overwrite)
                {
                    return(false);
                }
            }

            var match = Database.Query <PlayerEntry>().FirstOrDefault(m => m.Id == entry.Id);

            if (match == null || overwrite)
            {
                entry = entry.CloneT();

                if (match != null)
                {
                    Database.Delete(match);
                }
                Database.Store(entry);

                lock (_lobbycache)
                {
                    var idx = _lobbycache.FindIndex(p => p.Id == entry.Id);
                    if (idx != -1)
                    {
                        _lobbycache[idx] = entry;
                    }
                    else
                    {
                        _lobbycache.Add(entry);
                    }
                }
            }
            else
            {
                return(false);
            }
            OnPlayerUpdate(entry);
            return(true);
        }
예제 #13
0
        public void UpdateExecutor(ExecutorStorageView updatedExecutor)
        {
            ExecutorStorageView executor  = null;
            IObjectContainer    container = GetStorage();

            try
            {
                IList <ExecutorStorageView> executors =
                    container.Query <ExecutorStorageView>(delegate(ExecutorStorageView executorFinder)
                {
                    return(executorFinder.ExecutorId == updatedExecutor.ExecutorId);
                });

                if (executors.Count > 0)
                {
                    executor = executors[0];
                    container.Delete(executor);
                    container.Set(updatedExecutor);
                }
            }
            finally
            {
                container.Close();
            }
        }
예제 #14
0
        public void DeleteExecutor(ExecutorStorageView executor)
        {
            if (executor == null)
            {
                return;
            }

            IObjectContainer container = GetStorage();

            try
            {
                IList <ExecutorStorageView> executors =
                    container.Query <ExecutorStorageView>(delegate(ExecutorStorageView executorFinder)
                {
                    return(executorFinder.ExecutorId == executor.ExecutorId);
                });

                if (executors.Count > 0)
                {
                    container.Delete(executors[0]);
                }
            }
            finally
            {
                container.Close();
            }
        }
예제 #15
0
        public void UpdateApplication(ApplicationStorageView updatedApplication)
        {
            ApplicationStorageView application = null;
            IObjectContainer       container   = GetStorage();

            try
            {
                IList <ApplicationStorageView> apps =
                    container.Query <ApplicationStorageView>(delegate(ApplicationStorageView app)
                {
                    return(app.ApplicationId == updatedApplication.ApplicationId);
                });

                if (apps.Count > 0)
                {
                    application = apps[0];
                    container.Delete(application);
                    container.Set(updatedApplication);
                }
            }
            finally
            {
                container.Close();
            }
        }
예제 #16
0
 public Boolean excluirCliente(Cliente objCliente)
 {
     db = ServidorSingleton.obterServidor().OpenClient();
     try
     {
         IObjectSet leitor = db.QueryByExample(objCliente);
         if (leitor.HasNext())
         {
             db.Delete((Cliente)leitor.Next());
             db.Commit();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         db.Rollback();
         return(false);
     }
     finally
     {
         db.Close();
         db.Dispose();
     }
 }
예제 #17
0
 protected void DeleteObjectSet(IObjectContainer oc, IObjectSet os)
 {
     while (os.HasNext())
     {
         oc.Delete(os.Next());
     }
 }
예제 #18
0
        public Boolean excluirFuncionario(Funcionario objFuncionario)
        {
            db = ServidorSingleton.obterServidor().OpenClient();
            Funcionario objFuncionarioProt = FactoryClasses.criarFuncionario();

            objFuncionarioProt.Codigo = objFuncionario.Codigo;

            try
            {
                IObjectSet leitor = db.QueryByExample(objFuncionario);
                if (leitor.HasNext())
                {
                    db.Delete((Funcionario)leitor.Next());
                    db.Commit();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                db.Rollback();
                return(false);
            }
            finally
            {
                db.Close();
                db.Dispose();
            }
        }
예제 #19
0
        internal void RemoveFolderfromDatabase(FavouriteFolder favFolder)
        {
            try
            {
                container = Db4oClient.RecentConn;
                FavouriteList favList = FetchAllFavouritesForAConnection();


                List <FavouriteFolder> lstFavFolder = favList.lstFavFolder;
                bool            check = false;
                FavouriteFolder temp  = null;
                foreach (FavouriteFolder str in lstFavFolder)
                {
                    if (str.FolderName.Equals(favFolder.FolderName))
                    {
                        temp  = str;
                        check = true;
                        break;
                    }
                }
                if (check == true)
                {
                    lstFavFolder.Remove(temp);
                    favList.lstFavFolder = lstFavFolder;
                    container.Delete(temp);
                    container.Ext().Store(favList, 5);
                    container.Commit();
                }
            }

            catch (Exception oEx)
            {
                LoggingHelper.HandleException(oEx);
            }
        }
예제 #20
0
        private static void DeletionsReplication()
        {
            DeleteDatabases();
            StoreObjectsIn(DesktopDatabaseName);
            IObjectContainer desktopDatabase = OpenDatabase(DesktopDatabaseName);
            IObjectContainer mobileDatabase  = OpenDatabase(MobileDatabaseName);

            Replicate(desktopDatabase, mobileDatabase);

            Car carToDelete = desktopDatabase.Query <Car>()[0];

            desktopDatabase.Delete(carToDelete);
            desktopDatabase.Commit();

            PrintCars(mobileDatabase);

            IReplicationProvider dektopReplicationProvider
                = new Db4oEmbeddedReplicationProvider(desktopDatabase);
            IReplicationProvider mobileReplicationProvider
                = new Db4oEmbeddedReplicationProvider(mobileDatabase);

            // #example: Replicate deletions
            IReplicationSession replicationSession
                = Replication.Begin(dektopReplicationProvider, mobileReplicationProvider);

            replicationSession.ReplicateDeletions(typeof(Car));
            replicationSession.Commit();
            // #end example

            PrintCars(mobileDatabase);

            CloseDBs(desktopDatabase, mobileDatabase);
        }
예제 #21
0
        public void UpdateThread(ThreadStorageView updatedThread)
        {
            ThreadStorageView thread    = null;
            IObjectContainer  container = GetStorage();

            try
            {
                IList <ThreadStorageView> threads =
                    container.Query <ThreadStorageView>(delegate(ThreadStorageView threadFinder)
                {
                    return(threadFinder.ThreadId == updatedThread.ThreadId);
                });

                if (threads.Count > 0)
                {
                    thread = threads[0];
                    container.Delete(thread);
                    container.Set(updatedThread);
                }
            }
            finally
            {
                container.Close();
            }
        }
예제 #22
0
 private void BtnEliminar_Click(object sender, EventArgs e)
 {
     if (TxtNumcontrol.Text != string.Empty)
     {
         IObjectContainer BD  = Db4oFactory.OpenFile(Util.NombreArchivo);
         string           nom = TxtNumcontrol.Text;
         try
         {
             IList <Estudiante> consulta = BD.Query <Estudiante>(z => z.NoControl == nom);
             foreach (Estudiante item in consulta)
             {
                 BD.Delete(item);
                 MessageBox.Show("Registro eliminado");
                 TxtNumcontrol.Clear();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Error");
             MessageBox.Show("No hay registros que coincidan");
         }
         finally
         {
             BD.Close();
         }
     }
     else
     {
         MessageBox.Show("Inserta la clave");
     }
 }
예제 #23
0
 /// <summary>
 /// Сохранение автора в БД
 /// </summary>
 /// <param name="author"></param>
 public void SaveAuthor(Author author)
 {
     if (server == null)
     {
         return;
     }
     try
     {
         using (IObjectContainer documentStore = server.OpenClient())
         {
             var _author = documentStore
                           .Query <AuthorDb4o>(x => x != null && x.Id == author.Id)
                           .FirstOrDefault();
             if (_author != null)
             {
                 _author.author = author;
                 documentStore.Delete(_author);
                 _author.author.URL = _author.author.URL.Replace("zhurnal.lib.ru", "samlib.ru");
                 documentStore.Store(_author);
             }
             else
             {
                 documentStore.Store(new AuthorDb4o {
                     Id = author.Id, author = author
                 });
             }
             documentStore.Commit();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ошибка сохранения данных автора в БД." + ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
예제 #24
0
        public void DeleteUser(UserStorageView userToDelete)
        {
            if (userToDelete == null)
            {
                return;
            }

            IObjectContainer container = GetStorage();

            try
            {
                IList <UserStorageView> users =
                    container.Query <UserStorageView>(delegate(UserStorageView userFinder)
                {
                    return(userFinder.Username == userToDelete.Username);
                });

                if (users.Count > 0)
                {
                    container.Delete(users[0]);
                }
            }
            finally
            {
                container.Close();
            }
        }
예제 #25
0
        public void DeleteThread(ThreadStorageView threadToDelete)
        {
            if (threadToDelete == null)
            {
                return;
            }

            IObjectContainer container = GetStorage();

            try
            {
                IList <ThreadStorageView> threads =
                    container.Query <ThreadStorageView>(delegate(ThreadStorageView threadFinder)
                {
                    return(threadFinder.ThreadId == threadToDelete.ThreadId);
                });

                if (threads.Count > 0)
                {
                    container.Delete(threads[0]);
                }
            }
            finally
            {
                container.Close();
            }
        }
예제 #26
0
        public static void DeletePerson()
        {
            using (IObjectContainer db = Db4oEmbedded.OpenFile(@"C:\DBO\ODB.yap"))
            {
                db.Ext().Configure().ObjectClass(typeof(Person)).CascadeOnDelete(true);

                string userName;

                Console.WriteLine("Insert person surname who you want delete: ");

                userName = Console.ReadLine();

                IObjectSet result = db.QueryByExample(new Person(null, userName, new Address(null, null, null), new ObjectDataBase.Phone(null, null, null)));
                Person     found;
                if (result.HasNext())
                {
                    found = (Person)result.Next();
                    db.Delete(found);
                    //RetrieveAllPerson(db);

                    Console.WriteLine("\nPerson has been deleted from database");
                }
                else
                {
                    Console.WriteLine("This person don't exist in database");
                }
            }
        }
예제 #27
0
        public static void DeletePhone()
        {
            using (IObjectContainer db = Db4oEmbedded.OpenFile(@"C:\DBO\ODB.yap"))
            {
                string userName;
                string DeleteNumber;

                Console.WriteLine("Insert person surename who phone You want delete: ");

                userName = Console.ReadLine();

                Console.WriteLine("Insert phone witch You want delete, by number: ");

                Console.WriteLine("Number: ");

                DeleteNumber = Console.ReadLine();

                IObjectSet result = db.QueryByExample(new Person(null, userName, new Address(null, null, null), new ObjectDataBase.Phone(null, null, null)));
                Person     found;
                if (result.HasNext())
                {
                    found = (Person)result.Next();
                    db.Delete(found.PersonAddresses.Find(x => x.City == DeleteNumber));
                    //RetrieveAllPerson(db);

                    Console.WriteLine("\nPerson phone has been deleted from database");
                }
                else
                {
                    Console.WriteLine("This person don't exist in database");
                }
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            DB = Db4oFactory.OpenFile("dbConcessionaria.yap");
            string parametro = maskedTextBox1.Text;

            try
            {
                IList <classeFuncionario> resultFuncionario = DB.Query <classeFuncionario>(P => P.cpfFuncionario == parametro);
                foreach (classeFuncionario item in resultFuncionario)
                {
                    DB.Delete(item);
                    MessageBox.Show("Fornecedor removido com sucesso!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Fornecedor não encontrado!");
            }
            finally
            {
                DB.Close();
                exibir();
                limpar();
            }
        }
예제 #29
0
        public static void DeleteAddress(IObjectContainer db)
        {
            Console.WriteLine("Podaj osobę, której chcesz usunąć adres:");
            Console.WriteLine();
            Console.Write("Imię:\t\t");
            string firstName = Console.ReadLine();

            Console.Write("Nazwisko:\t");
            string lastName = Console.ReadLine();

            try
            {
                Person     ex     = new Person(firstName, lastName);
                IObjectSet result = db.QueryByExample(ex);
                Person     found  = (Person)result.Next();

                db.Delete(found.Address);
                db.Commit();
                Console.WriteLine();
                Console.WriteLine("Pomyślnie usunięto adres!");
            }
            catch (Exception e)
            {
                Console.WriteLine();
                Console.WriteLine("Taka osoba nie istnieje. Nie można kontynuować.");
            }
        }
예제 #30
0
        /// <summary>
        /// Updates a project in the database. Because a <see cref="LongoMatch.DB.Project"/> has
        /// many objects associated, a simple update would leave in the databse many orphaned objects.
        /// Therefore we need to delete the old project a replace it with the changed one.
        /// </summary>
        /// <param name="project">
        /// A <see cref="Project"/> to update
        /// </param>
        /// <param name="previousFileName">
        /// A <see cref="System.String"/> with the old file path
        /// </param>
        public void UpdateProject(Project project)
        {
            // Configure db4o to cascade on delete for each one of the objects stored in a Project
            SetDeleteCascadeOptions();
            IObjectContainer db = Db4oFactory.OpenFile(DBFile);

            project.Description.LastModified = DateTime.Now;
            Log.Debug("Updating project " + project);
            try     {
                IQuery     query  = GetQueryProjectById(db, project.UUID);
                IObjectSet result = query.Execute();
                //Get the stored project and replace it with the new one
                if (result.Count == 1)
                {
                    Project fd = (Project)result.Next();
                    db.Delete(fd);
                    db.Store(project);
                    db.Commit();
                }
                else
                {
                    Log.Warning("Project with ID " + project.UUID + "not found");
                }
            } catch (Exception e) {
                Log.Error("Could not update project");
                Log.Exception(e);
            } finally {
                CloseDB(db);
            }
        }
예제 #31
0
파일: NQExample.cs 프로젝트: erdincay/db4o
		public static void ClearDatabase(IObjectContainer db)
		{
			IObjectSet result = db.QueryByExample(typeof(Pilot));
			while (result.HasNext())
			{
				db.Delete(result.Next());
			}
		}
예제 #32
0
파일: Util.cs 프로젝트: erdincay/db4o
		public static void DeleteAll(IObjectContainer db) 
		{
			IObjectSet result = db.QueryByExample(typeof(Object));
			foreach (object item in result)
			{
				db.Delete(item);
			}
		}		
예제 #33
0
 public Db4oHistoryService(Uri baseUri, bool resume)
 {
     m_Db = Db4oEmbedded.OpenFile(Db4oEmbedded.NewConfiguration(),
         "NCrawlerHist_{0}.Yap".FormatWith(baseUri.GetHashCode()));
     if (!resume)
     {
         m_Db.Query<StringWrapper>().ForEach(entry => m_Db.Delete(entry));
     }
 }
예제 #34
0
        public Db4oQueueService(Uri baseUri, bool resume)
        {
            m_Db = Db4oEmbedded.OpenFile(Db4oEmbedded.NewConfiguration(),
                "NCrawlerQueue_{0}.Yap".FormatWith(baseUri.GetHashCode()));

            if (!resume)
            {
                m_Db.Query<CrawlerQueueEntry>().ForEach(entry => m_Db.Delete(entry));
            }
        }
예제 #35
0
			protected override void Exercise(IObjectContainer db)
			{
				Assert.AreEqual(1, db.Query(typeof(ConcurrentRenameTestCase.QueryItem)).Count);
				ConcurrentRenameTestCase.QueryItem newItem = new ConcurrentRenameTestCase.QueryItem
					();
				db.Store(newItem);
				db.Commit();
				db.Delete(newItem);
				db.Commit();
			}
예제 #36
0
 private static void DeleteData(IObjectContainer container, Random rnd)
 {
     IList<DataObject> data = container.Query<DataObject>();
     for (int i = 0; i < rnd.Next(4096); i++)
     {
         DataObject obj = data[rnd.Next(data.Count)];
         if (null != obj)
         {
             container.Delete(obj);
         }
     }
 }
예제 #37
0
 private void DeleteAndReadd(IObjectContainer db, Collection4 removed)
 {
     var removeIter = removed.GetEnumerator();
     while (removeIter.MoveNext())
     {
         db.Delete(removeIter.Current);
     }
     db.Commit();
     var readdIter = removed.GetEnumerator();
     while (readdIter.MoveNext())
     {
         db.Store(readdIter.Current);
     }
     db.Commit();
 }
예제 #38
0
 public Boolean excluirStatus(clsStatus objStatus)
 {
     FilmeDAO objFilmeDAO = new FilmeDAO();
     if (!objFilmeDAO.temStatusEmFilme(objStatus))
     {
         try
         {
             db = ServidorSingleton.obterServidor().OpenClient();
             IObjectSet leitor = db.QueryByExample(objStatus);
             clsStatus s = (clsStatus)leitor.Next();
             db.Delete(s);
             db.Commit();
             return true;
         }
         catch (Exception ex)
         {
             throw new Exception("Erro tentando excluir o Status :" + ex.ToString());
         }
         finally
         {
             db.Close();
             db.Dispose();
         }
     }
     else {
         return false;
     }
 }
예제 #39
0
        public void cadastrarPedido(SolicitacaoMateriais objSolicitacao)
        {
            //Atualiza a solicitação no db
            SolicitacaoMateriaisDAO objSolicitacaoDAO = FactoryDAO.criarSolicitacaoMateriaisDAO();
            if (objSolicitacaoDAO.atualizarSolicitacao(objSolicitacao))
            {
                SolicitacaoMateriais objSolicitacaoProt = FactoryClasses.criarSolicitacaoMateriais();
                objSolicitacaoProt.Codigo = objSolicitacao.Codigo;
                db = ServidorSingleton.obterServidor().OpenClient();
                IObjectSet leitor = db.QueryByExample(objSolicitacaoProt);
                if (leitor.HasNext())
                {
                    objSolicitacaoProt = null;
                    objSolicitacaoProt = (SolicitacaoMateriais)leitor.Next();
                }
                leitor = null;
                Collection<Pedido> objPedidoColecao = new Collection<Pedido>();

                foreach (Materiais material in objSolicitacaoProt.Materiais)
                {
                    Pedido objPedido = FactoryClasses.criarPedido();
                    objPedido.SolicitacaoMateriais = objSolicitacaoProt;
                    Collection<Materiais> objMateriaisColecao = new Collection<Materiais>();
                    objMateriaisColecao.Add(material);
                    objPedido.Materiais = objMateriaisColecao;
                    objPedido.Codigo = obtemNovoId();
                    db = ServidorSingleton.obterServidor().OpenClient();
                    db.Store(objPedido);
                    db.Commit();
                }

                //Le os pedidos
                Pedido objPedidoProt = FactoryClasses.criarPedido();
                objPedidoProt.SolicitacaoMateriais = objSolicitacaoProt;
                db = ServidorSingleton.obterServidor().OpenClient();
                IObjectSet leitorPedidoCache = db.QueryByExample(objPedidoProt);
                int codFornecedor = 0;
                int contador = 0;
                int codPedido = 0;

                while (leitorPedidoCache.HasNext())
                {
                    Pedido objPedidoLer = (Pedido)leitorPedidoCache.Next();
                    if (contador == 0)
                    {
                        codFornecedor = objPedidoLer.Materiais[0].Fornecedor.Codigo;
                    }
                    else
                    {
                        if (codFornecedor == objPedidoLer.Materiais[0].Fornecedor.Codigo)
                        {
                            //Retira os itens deste pedido e coloca no anterior
                            Collection<Materiais> objMateriaisColecaoTmp = new Collection<Materiais>();
                            foreach (Materiais item in objPedidoLer.Materiais)
                            {
                                objMateriaisColecaoTmp.Add(item);
                            }
                            //exclui o pedido atual
                            db.Delete(objPedidoLer);
                            //Carrega o anterior em cache
                            Pedido p = FactoryClasses.criarPedido();
                            p.Codigo = codPedido;
                            IObjectSet leitorPedido2 = db.QueryByExample(p);
                            if (leitorPedido2.HasNext())
                            {
                                p = null;
                                p = (Pedido)leitorPedido2.Next();
                                //Atualiza o pedido anterior com os dados do pedido que foi apagado
                                foreach (Materiais item in p.Materiais)
                                {
                                    objMateriaisColecaoTmp.Add(item);
                                }
                                p.Materiais = objMateriaisColecaoTmp;
                                db.Store(p);
                                db.Commit();
                            }
                            leitorPedido2 = null;
                        }
                    }
                    codFornecedor = objPedidoLer.Materiais[0].Fornecedor.Codigo;
                    codPedido = objPedidoLer.Codigo;
                    contador++;
                }
                leitorPedidoCache = null;
                db.Close();
                db.Dispose();
            }
        }
예제 #40
0
 public static void RetrieveByDefaultFieldValue(IObjectContainer db)
 {
     Pilot somebody = new Pilot("Somebody else", 0);
     db.Store(somebody);
     IQuery query = db.Query();
     query.Constrain(typeof(Pilot));
     query.Descend("_points").Constrain(0);
     IObjectSet result = query.Execute();
     ListResult(result);
     db.Delete(somebody);
 }
예제 #41
0
 public static void ClearDatabase(IObjectContainer db)
 {
     IObjectSet result = db.QueryByExample(typeof(Pilot));
     foreach (object item in result)
     {
         db.Delete(item);
     }
 }
예제 #42
0
 public Boolean excluirCargo(Cargo objCargo)
 {
     //Validação de existência do cargo utilizado por algum usuário
     FuncionarioDAO objFuncionarioDAO = FactoryDAO.criarFuncionarioDAO();
     if (!objFuncionarioDAO.possuiFuncionarioPorCargo(objCargo))
     {
         db = ServidorSingleton.obterServidor().OpenClient();
         try
         {
             IObjectSet leitor = db.QueryByExample(objCargo);
             if (leitor.HasNext())
             {
                 db.Delete((Cargo)leitor.Next());
                 db.Commit();
                 return true;
             }
             else
             {
                 return false;
             }
         }
         catch
         {
             db.Rollback();
             return false;
         }
         finally
         {
             db.Close();
             db.Dispose();
         }
     }
     else {
         return false;
     }
 }
예제 #43
0
 public Boolean excluirSolicitacao(SolicitacaoMateriais objSolicitacao)
 {
     try
     {
         db = ServidorSingleton.obterServidor().OpenClient();
         IObjectSet leitor = db.QueryByExample(objSolicitacao);
         if (leitor.HasNext())
         {
             db.Delete((SolicitacaoMateriais)leitor.Next());
             db.Commit();
         }
         leitor = null;
         return true;
     }
     catch
     {
         db.Rollback();
         throw new Exception("Erro excluindo a solicitação de materiais");
     }
     finally {
         db.Close();
         db.Dispose();
     }
 }
예제 #44
0
        internal void AddFolderToDatabase(FavouriteFolder favFolder)
        {
            try
            {
                container = Db4oClient.RecentConn;
                if (m_lstFavfolder != null)
                {
                    FavouriteList favList = FetchAllFavouritesForAConnection();
                   
                    if (favList == null)
                    {
                        favList = new FavouriteList(m_connParam);
                        List<FavouriteFolder> lstFavfolder = new List<FavouriteFolder>();
                        favList.m_TimeOfCreation = Sharpen.Runtime.CurrentTimeMillis();   
                        lstFavfolder.Add(favFolder);
                        container.Store(favList);
                        container.Commit();
                        return;
                    }
                    container.Activate(favList, 5);
                    List<FavouriteFolder> lstFavFolder = favList.lstFavFolder;
                   
                    bool check = false;
                    FavouriteFolder temp = null;
                    foreach (FavouriteFolder str in lstFavFolder)
                    {
                        if (str != null)
                        {
                            if (str.FolderName.Equals(favFolder.FolderName))
                            {
                                temp = str;
                                check = true;
                                break;
                            }
                        }
                    }
                    if (check == false)
                    {

                        lstFavFolder.Add(favFolder);
                    }
                    else
                    {
                        lstFavFolder.Remove(temp);
                        lstFavFolder.Add(favFolder);
                        container.Delete(temp);
                    }


                    favList.lstFavFolder = lstFavFolder;
                    container.Ext().Store(favList, 5);
                    container.Commit();


                }
            }
            catch (Exception oEx)
            {
                LoggingHelper.HandleException(oEx);  
            }
        }
예제 #45
0
        public static void DeleteQuestionnaire(IObjectContainer db, string questionnaireName)
        {
            var questionnaires =
                (from Questionnaire q in db
                 where q.Name == questionnaireName
                 select q).ToList();

            foreach (var questionnaire in questionnaires)
            {
                db.Delete(questionnaire);
            }
        }
예제 #46
0
 public static void DeleteSecondPilotByName(IObjectContainer db)
 {
     IObjectSet result = db.QueryByExample(new Pilot("Rubens Barrichello", 0));
     Pilot found = (Pilot)result.Next();
     db.Delete(found);
     Console.WriteLine("Deleted {0}", found);
     RetrieveAllPilots(db);
 }
예제 #47
0
        internal void RenameFolderInDatabase(FavouriteFolder oldFavFolder, FavouriteFolder newFavFolder)
        {
            try
            {
                container = Db4oClient.RecentConn;
                FavouriteList favList = FetchAllFavouritesForAConnection();


                List<FavouriteFolder> lstFavFolder = favList.lstFavFolder;
                bool check = false;
                FavouriteFolder temp = null;
                foreach (FavouriteFolder str in lstFavFolder)
                {
                    if (str != null)
                    {
                        if (str.FolderName.Equals(oldFavFolder.FolderName))
                        {
                            temp = str;
                            check = true;
                            break;
                        }
                    }
                }
                if (check == true)
                {
                    lstFavFolder.Remove(temp);
                    container.Delete(temp);
                    temp.FolderName = newFavFolder.FolderName;
                    lstFavFolder.Add(temp);
                    favList.lstFavFolder = lstFavFolder;
                    container.Ext().Store(favList, 5);
                    container.Commit();
                }
            }
            catch (Exception oEx)
            {
                LoggingHelper.HandleException(oEx);
            }

        }
예제 #48
0
 public static void DeleteFirstPilotByName(IObjectContainer db)
 {
     IObjectSet result = db.QueryByExample(new Pilot("Michael Schumacher", 0));
     Pilot found = (Pilot)result.Next();
     db.Delete(found);
     Console.WriteLine("Deleted {0}", found);
     RetrieveAllPilots(db);
 }
예제 #49
0
 public static void DeleteFlat(IObjectContainer db)
 {
     IObjectSet result = db.QueryByExample(new Car("Ferrari"));
     Car found = (Car)result.Next();
     db.Delete(found);
     result = db.QueryByExample(new Car(null));
     ListResult(result);
 }
예제 #50
0
		private void DeleteTemporaryObjects(IObjectContainer objectContainer)
		{
			IQuery query = objectContainer.Query();
			query.Constrain(typeof(MonitoringDemo.Item));
			query.Descend("name").Constrain("temp");
			IObjectSet objectSet = query.Execute();
			while (objectSet.HasNext())
			{
				objectContainer.Delete(((MonitoringDemo.Item)objectSet.Next()));
			}
			objectContainer.Commit();
		}
예제 #51
0
 private void Populate(IObjectContainer container)
 {
     for (var i = 0; i < 10; i++)
     {
         container.Store(new Item("delme"));
     }
     var one = new CrashData(null
         , "one");
     var two = new CrashData(one
         , "two");
     var three = new CrashData
         (one, "three");
     container.Store(one);
     container.Store(two);
     container.Store(three);
     container.Commit();
     var objectSet = container.Query(typeof (Item));
     while (objectSet.HasNext())
     {
         container.Delete(objectSet.Next());
     }
 }
예제 #52
0
		protected void DeleteObjectSet(IObjectContainer oc, IObjectSet os)
		{
			while (os.HasNext())
			{
				oc.Delete(os.Next());
			}
		}
예제 #53
0
 public Boolean excluirGenero(clsGenero objGenero)
 {
     FilmeDAO objFilmeDAO = new FilmeDAO();
     if (!objFilmeDAO.temGeneroEmFilme(objGenero)) //Verifica se possui algum filme com aquele genero
     {
         try
         {
             db = ServidorSingleton.obterServidor().OpenClient();
             IObjectSet leitor = db.QueryByExample(objGenero);
             clsGenero g = (clsGenero)leitor.Next();
             db.Delete(g);
             db.Commit();
             return true;
         }
         catch (Exception ex)
         {
             throw new Exception("Erro tentando excluir o genero :" + ex.ToString());
         }
         finally
         {
             db.Close();
             db.Dispose();
         }
     }
     else {
         return false;
     }
 }
			private void Populate(IObjectContainer container)
			{
				for (int i = 0; i < 10; i++)
				{
					container.Store(new CrashSimulatingTestSuite.Item("delme"));
				}
				CrashSimulatingTestSuite.CrashData one = new CrashSimulatingTestSuite.CrashData(null
					, "one");
				CrashSimulatingTestSuite.CrashData two = new CrashSimulatingTestSuite.CrashData(one
					, "two");
				CrashSimulatingTestSuite.CrashData three = new CrashSimulatingTestSuite.CrashData
					(one, "three");
				container.Store(one);
				container.Store(two);
				container.Store(three);
				container.Commit();
				IObjectSet objectSet = container.Query(typeof(CrashSimulatingTestSuite.Item));
				while (objectSet.HasNext())
				{
					container.Delete(objectSet.Next());
				}
			}
예제 #55
0
 private void FragmentDatabase(IObjectContainer container)
 {
     var items = CreateItems();
     for (var i = 0; i < items.Length; ++i)
     {
         container.Store(items[i]);
     }
     for (var i = 0; i < items.Length; i += 2)
     {
         container.Delete(items[i]);
     }
 }
예제 #56
0
 protected override void Exercise(IObjectContainer db)
 {
     Assert.AreEqual(1, db.Query(typeof (QueryItem)).Count);
     var newItem = new QueryItem
         ();
     db.Store(newItem);
     db.Commit();
     db.Delete(newItem);
     db.Commit();
 }
			public virtual void ObjectOnDelete(IObjectContainer container)
			{
				container.Delete(child);
			}
예제 #58
0
		private void FragmentDatabase(IObjectContainer container)
		{
			LegacyDatabaseDefragTestCase.Item[] items = CreateItems();
			for (int i = 0; i < items.Length; ++i)
			{
				container.Store(items[i]);
			}
			for (int i = 0; i < items.Length; i += 2)
			{
				container.Delete(items[i]);
			}
		}
예제 #59
0
 public Boolean excluirFilme(clsFilme objFilme)
 {
     db = ServidorSingleton.obterServidor().OpenClient();
     try
     {
         IObjectSet leitor = db.QueryByExample(objFilme);
         if (leitor.HasNext())
         {
             db.Delete((clsFilme)leitor.Next());
             db.Commit();
             return true;
         }
         else {
             return false;
         }
     }
     catch
     {
         db.Rollback();
         return false;
     }
     finally {
         db.Close();
         db.Dispose();
     }
 }
예제 #60
0
        public Boolean excluirFuncionario(Funcionario objFuncionario)
        {
            db = ServidorSingleton.obterServidor().OpenClient();
            Funcionario objFuncionarioProt = FactoryClasses.criarFuncionario();

            objFuncionarioProt.Codigo = objFuncionario.Codigo;

            try
            {
                IObjectSet leitor = db.QueryByExample(objFuncionario);
                if (leitor.HasNext())
                {
                    db.Delete((Funcionario)leitor.Next());
                    db.Commit();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch
            {
                db.Rollback();
                return false;
            }
            finally
            {
                db.Close();
                db.Dispose();
            }
        }