Exemple #1
0
        private void btnBrisi_Click(object sender, EventArgs e)
        {
            IList <Element> selItems = elementBrowserControl1.DataGridViewUserControl
                                       .getSelectedItems <Element>();

            if (selItems.Count == 0)
            {
                return;
            }

            bool delete;

            if (selItems.Count == 1)
            {
                delete = MessageDialogs.queryConfirmation(
                    deleteConfirmationMessage(selItems[0]), this.Text);
            }
            else
            {
                delete = MessageDialogs.queryConfirmation(
                    deleteConfirmationMessage(), this.Text);
            }
            if (!delete)
            {
                return;
            }

            try
            {
                using (ISession session = NHibernateHelper.OpenSession())
                    using (session.BeginTransaction())
                    {
                        CurrentSessionContext.Bind(session);

                        foreach (Element element in selItems)
                        {
                            DAOFactoryFactory.DAOFactory.GetElementDAO().MakeTransient(element);
                        }
                        session.Transaction.Commit();
                        foreach (Element element in selItems)
                        {
                            elementi.Remove(element);
                        }
                        elementBrowserControl1.setElementi(elementi);
                    }
            }
            finally
            {
                CurrentSessionContext.Unbind(NHibernateHelper.SessionFactory);
            }
        }
Exemple #2
0
        protected void deleteCommand()
        {
            DomainObject entity = (DomainObject)getSelectedEntity();

            if (entity == null)
            {
                return;
            }
            if (!MessageDialogs.queryConfirmation(deleteConfirmationMessage(entity), this.Text))
            {
                return;
            }

            try
            {
                using (ISession session = NHibernateHelper.OpenSession())
                    using (session.BeginTransaction())
                    {
                        CurrentSessionContext.Bind(session);
                        if (refIntegrityDeleteDlg(entity))
                        {
                            delete(entity);
                            session.Transaction.Commit();
                            onEntityDeleted(entity);
                        }
                    }
            }
            catch (InfrastructureException ex)
            {
                string errMsg = deleteErrorMessage(entity);
                MessageDialogs.showError(
                    String.Format("{0} \n\n{1}", errMsg, ex.Message),
                    this.Text);
            }
            catch (Exception ex)
            {
                string errMsg = deleteErrorMessage(entity);
                MessageDialogs.showError(
                    String.Format("{0} \n\n{1}", errMsg, ex.Message),
                    this.Text);
            }
            finally
            {
                CurrentSessionContext.Unbind(NHibernateHelper.SessionFactory);
            }
        }