Esempio n. 1
0
        private void btnIzracunaj_Click(object sender, EventArgs e)
        {
            string msg;

            if (kvalColumnVisible())
            {
                msg = "Da li zelite da izracunate poredak, kvalifikante i rezerve?";
            }
            else
            {
                msg = "Da li zelite da izracunate poredak?";
            }
            if (!MessageDialogs.queryConfirmation(msg, this.Text))
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            Cursor.Show();
            ISession session = null;

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

                        OcenaDAO      ocenaDAO = DAOFactoryFactory.DAOFactory.GetOcenaDAO();
                        IList <Ocena> ocene    = ocenaDAO.FindByDeoTakmicenja(takmicenje.Id, deoTakKod);
                        if (ActiveSprava != Sprava.Preskok)
                        {
                            PoredakSprava p = ActiveTakmicenje.getPoredakSprava(deoTakKod, ActiveSprava);
                            p.create(ActiveTakmicenje, ocene);
                            DAOFactoryFactory.DAOFactory.GetPoredakSpravaDAO().Update(p);
                        }
                        else
                        {
                            PoredakPreskok p = ActiveTakmicenje.getPoredakPreskok(deoTakKod);
                            p.create(ActiveTakmicenje, ocene);
                            DAOFactoryFactory.DAOFactory.GetPoredakPreskokDAO().Update(p);
                        }
                        foreach (Ocena o in ocene)
                        {
                            ocenaDAO.Evict(o);
                        }

                        takmicenje = DAOFactoryFactory.DAOFactory.GetTakmicenjeDAO().FindById(takmicenje.Id);
                        takmicenje.LastModified = DateTime.Now;
                        session.Transaction.Commit();
                    }
            }
            catch (Exception ex)
            {
                if (session != null && session.Transaction != null && session.Transaction.IsActive)
                {
                    session.Transaction.Rollback();
                }
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }
            finally
            {
                Cursor.Hide();
                Cursor.Current = Cursors.Arrow;
                CurrentSessionContext.Unbind(NHibernateHelper.Instance.SessionFactory);
            }

            setItems();
        }
Esempio n. 2
0
        private void mnSpraveKojeSeBoduju_Click(object sender, EventArgs e)
        {
            IList <GimnasticarUcesnik> selItems = getActiveDataGridViewUserControl()
                                                  .getSelectedItems <GimnasticarUcesnik>();

            if (selItems.Count != 1)
            {
                return;
            }
            GimnasticarUcesnik g = selItems[0];

            List <int> checkedItems = new List <int>();

            foreach (Sprava s in Sprave.getSprave(ActiveRezTakmicenje.Gimnastika))
            {
                if (g.getSpravaSeBoduje(s))
                {
                    checkedItems.Add(Sprave.indexOf(s, ActiveRezTakmicenje.Gimnastika));
                }
            }

            CheckListForm form = new CheckListForm(
                new List <string>(Sprave.getSpraveNazivi(ActiveRezTakmicenje.Gimnastika)), checkedItems,
                "Izaberite sprave koje se boduju", "Sprave koje se boduju", true, "Izaberite sprave", true);

            if (form.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Sprava[]       sprave             = Sprave.getSprave(ActiveRezTakmicenje.Gimnastika);
            IList <Sprava> spraveKojeSeBoduju = new List <Sprava>();

            g.clearSpraveKojeSeBoduju();
            foreach (int i in form.CheckedIndices)
            {
                g.setSpravaSeBoduje(sprave[i]);
            }

            Cursor.Current = Cursors.WaitCursor;
            Cursor.Show();
            ISession session = null;

            try
            {
                using (session = NHibernateHelper.Instance.OpenSession())
                    using (session.BeginTransaction())
                    {
                        CurrentSessionContext.Bind(session);
                        DAOFactoryFactory.DAOFactory.GetGimnasticarUcesnikDAO().Update(g);

                        PoredakSpravaDAO  poredakSpravaDAO  = DAOFactoryFactory.DAOFactory.GetPoredakSpravaDAO();
                        PoredakPreskokDAO poredakPreskokDAO = DAOFactoryFactory.DAOFactory.GetPoredakPreskokDAO();

                        OcenaDAO      ocenaDAO = DAOFactoryFactory.DAOFactory.GetOcenaDAO();
                        IList <Ocena> ocene    = ocenaDAO.FindByDeoTakmicenja(takmicenje.Id, DeoTakmicenjaKod.Takmicenje1);

                        foreach (Sprava s in Sprave.getSprave(ActiveRezTakmicenje.Gimnastika))
                        {
                            if (s != Sprava.Preskok)
                            {
                                PoredakSprava p = ActiveRezTakmicenje.getPoredakSprava(DeoTakmicenjaKod.Takmicenje1, s);
                                poredakSpravaDAO.Attach(p, false);
                                p.create(ActiveRezTakmicenje, ocene);
                                poredakSpravaDAO.Update(p);
                            }
                            else
                            {
                                PoredakPreskok p = ActiveRezTakmicenje.getPoredakPreskok(DeoTakmicenjaKod.Takmicenje1);
                                poredakPreskokDAO.Attach(p, false);
                                p.create(ActiveRezTakmicenje, ocene);
                                poredakPreskokDAO.Update(p);
                            }
                        }
                        foreach (Ocena o in ocene)
                        {
                            ocenaDAO.Evict(o);
                        }

                        takmicenje = DAOFactoryFactory.DAOFactory.GetTakmicenjeDAO().FindById(takmicenje.Id);
                        takmicenje.LastModified = DateTime.Now;
                        session.Transaction.Commit();
                    }
            }
            catch (Exception ex)
            {
                if (session != null && session.Transaction != null && session.Transaction.IsActive)
                {
                    session.Transaction.Rollback();
                }
                MessageDialogs.showError(ex.Message, this.Text);
                Close();
                return;
            }
            finally
            {
                Cursor.Hide();
                Cursor.Current = Cursors.Arrow;
                CurrentSessionContext.Unbind(NHibernateHelper.Instance.SessionFactory);
            }
        }