コード例 #1
0
 void DailyInputWizard_FormClosing(object sender, FormClosingEventArgs e)
 {
     // A bit of tidying up
     Cursor.Current = Cursors.Default;
     DailyData.Current.Dispose();
     NHibernateHelper.DisposeCurrentSession();
 }
コード例 #2
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            string id = textBoxId.Text;

            if (id.Length < 2)
            {
                MessageBox.Show("The ID '" + id + "' is invalid (too short).");
                return;
            }
            if (id.Length > 8)
            {
                MessageBox.Show("The ID '" + id + "' is invalid (too long).");
                return;
            }

            // Check the database for a conflict
            ISession     s       = NHibernateHelper.OpenNewSession();
            ITransaction tx      = s.BeginTransaction();
            Location     current = s.Get <Location>(id);


            if (current != null)
            {
                MessageBox.Show("The ID '" + id + "' is invalid (already exists).");
                tx.Commit();
                NHibernateHelper.DisposeCurrentSession();
                return;
            }

            location                  = new Domain.Location();
            location.ID               = textBoxId.Text;
            location.CommonName       = textBoxCommonName.Text;
            location.LocationTypeEnum = Domain.Location.Type.S;
            location.Comments         = textBoxComments.Text;

            this.DialogResult = System.Windows.Forms.DialogResult.OK;

            s.SaveOrUpdate(location);

            tx.Commit();
            NHibernateHelper.DisposeCurrentSession();
            this.Close();
        }
コード例 #3
0
ファイル: SessionForm.cs プロジェクト: ounsley/TBPDatabase
 void SessionForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     // Only save on a OK dialog result
     if (DialogResult == System.Windows.Forms.DialogResult.OK)
     {
         try
         {
             this.tx.Commit();
             //this.session.Close();
             NHibernateHelper.DisposeCurrentSession();
             this.session = null;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString(), "Failed to update database", MessageBoxButtons.OK);
         }
     }
     else
     {
         // Don't save
         NHibernateHelper.DisposeCurrentSession();
         this.session = null;
     }
 }
コード例 #4
0
        public void Save()
        {
            // This should be called when all the steps in the wizard are complete
            NHibernateHelper.DisposeCurrentSession();
            ISession     session = NHibernateHelper.OpenNewSession();
            ITransaction tx      = session.BeginTransaction();

            foreach (Location l in NewLocations)
            {
                session.SaveOrUpdate(l);
            }
            session.SaveOrUpdate(current.TroopVisit);

            // Go through deletes first
            foreach (IndividualSighting s in SightingsToDelete)
            {
                // Quick check that the ID has been set, this is a bit
                // nauhgty can't guarentee 0 is not valid,
                // but auto increment starts at 1 so should be fine
                if (s.ID != 0)
                {
                    session.Delete(s);
                }
            }
            foreach (IndividualReproductiveState irs in ReproductiveStatesToDelete)
            {
                if (irs.ID != 0)
                {
                    session.Delete(irs);
                }
            }
            foreach (Individual s in IndividualsToDelete)
            {
                session.Delete(s);
            }


            foreach (Individual i in NewIndividuals)
            {
                session.SaveOrUpdate(i);
            }
            foreach (IndividualSighting s in NewSightings)
            {
                session.SaveOrUpdate(s);
            }
            foreach (TroopVisitObserver tvo in NewTroopVisitObservers)
            {
                session.SaveOrUpdate(tvo);
            }
            foreach (IndividualReproductiveState s in NewReproductiveStates)
            {
                session.SaveOrUpdate(s);
            }
            foreach (IndividualAgeClass iac in NewAgeClass)
            {
                session.SaveOrUpdate(iac);
            }


            tx.Commit();
            NHibernateHelper.DisposeCurrentSession();
        }