Exemple #1
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            IList <Ocena> selItems = getDataGridViewUserControl()
                                     .getSelectedItems <Ocena>();

            if (selItems.Count != 1)
            {
                return;
            }

            Ocena selectedItem = selItems[0];

            try
            {
                OcenaForm form = new OcenaForm(selectedItem.Id,
                                               selectedItem.Gimnasticar, ActiveSprava, deoTakKod, takmicenje.Id);
                if (form.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }
            catch (InfrastructureException ex)
            {
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }

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

            try
            {
                using (session = NHibernateHelper.Instance.OpenSession())
                    using (session.BeginTransaction())
                    {
                        CurrentSessionContext.Bind(session);
                        // NOTE: Ne koristi se form.Entity nego se ponovo ucitava ocena
                        // da bi se izbegla zavisnost od toga na koji nacin OcenaForm
                        // ucitava ocenu, tj. da bi bio siguran da su inicijalizovane sve
                        // asocijacije kao i prilikom ucitavanja ocena u loadOcene.

                        editedItem = DAOFactoryFactory.DAOFactory.GetOcenaDAO().FindByIdFetch(selectedItem.Id);
                    }
            }
            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);
            }

            List <Ocena> activeOcene = ocene[calculateOceneKey(ActiveKategorija, ActiveSprava)];

            activeOcene[activeOcene.IndexOf(editedItem)] = editedItem;

            setOcene(activeOcene);
            selectOcena(editedItem);
        }
Exemple #2
0
        private void unesiOcenu(SpravaGridUserControl c, bool openedWithEnter)
        {
            DataGridViewSelectedRowCollection selRows = c.DataGridViewUserControl.DataGridView.SelectedRows;
            if (selRows.Count != 1)
                return;

            NastupNaSpravi nastup = selRows[0].DataBoundItem as NastupNaSpravi;
            Ocena ocena = null;
            GimnasticarUcesnik g = null;
            bool ok = false;
            try
            {
                DataAccessProviderFactory factory = new DataAccessProviderFactory();
                dataContext = factory.GetDataContext();
                dataContext.BeginTransaction();

                g = nastup.Gimnasticar;
                ocena = findOcena(g, deoTakKod, c.Sprava);

                ok = true;
            }
            catch (Exception ex)
            {
                if (dataContext != null && dataContext.IsInTransaction)
                    dataContext.Rollback();
                MessageDialogs.showMessage(
                    Strings.getFullDatabaseAccessExceptionMessage(ex), this.Text);
            }
            finally
            {
                if (dataContext != null)
                    dataContext.Dispose();
                dataContext = null;
            }

            if (!ok)
            {
                Close();
                return;
            }

            Nullable<int> ocenaId = null;
            if (ocena != null)
                ocenaId = ocena.Id;
            OcenaForm f = new OcenaForm(ocenaId, g, c.Sprava, deoTakKod,
                takmicenje.Id);
            if (f.ShowDialog() == DialogResult.OK)
            {
                int index = c.DataGridViewUserControl.getSelectedItemIndex();
                if (openedWithEnter)
                {
                    // Enter ce automatski selektovati novu vrstu. Potrebno je samo proveriti da li je ovo poslednja vrsta.
                    if (index == c.DataGridViewUserControl.DataGridView.Rows.Count - 1)
                    {
                        // uneta je zadnja ocena
                        c.clearSelection();
                    }
                }
                else
                {
                    ++index;
                    if (index < c.DataGridViewUserControl.DataGridView.Rows.Count)
                    {
                        // selektuj sledecu ocenu
                        c.DataGridViewUserControl.setSelectedItemIndex(index);
                    }
                    else
                    {
                        // uneta je zadnja ocena
                        c.clearSelection();
                    }
                }
            }
        }
Exemple #3
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            IList<Ocena> selItems = getDataGridViewUserControl()
                .getSelectedItems<Ocena>();
            if (selItems.Count != 1)
                return;

            Ocena selectedItem = selItems[0];
            try
            {
                OcenaForm form = new OcenaForm(selectedItem.Id,
                    selectedItem.Gimnasticar, ActiveSprava, deoTakKod, takmicenje.Id);
                if (form.ShowDialog() != DialogResult.OK)
                    return;
            }
            catch (InfrastructureException ex)
            {
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            Cursor.Show();
            try
            {
                Ocena editedItem = null;
                try
                {
                    DataAccessProviderFactory factory = new DataAccessProviderFactory();
                    dataContext = factory.GetDataContext();
                    dataContext.BeginTransaction();

                    // NOTE: Ne koristi se form.Entity nego se ponovo ucitava ocena
                    // da bi se izbegla zavisnost od toga na koji nacin OcenaForm
                    // ucitava ocenu, tj. da bi bio siguran da su inicijalizovane sve
                    // asocijacije kao i prilikom ucitavanja ocena u loadOcene.

                    editedItem = loadOcena(selectedItem.Id);

                    //dataContext.Commit();
                }
                catch (Exception ex)
                {
                    if (dataContext != null && dataContext.IsInTransaction)
                        dataContext.Rollback();
                    MessageDialogs.showError(Strings.getFullDatabaseAccessExceptionMessage(ex), this.Text);
                    Close();
                    return;
                }
                finally
                {
                    if (dataContext != null)
                        dataContext.Dispose();
                    dataContext = null;
                }

                List<Ocena> activeOcene = ocene[calculateOceneKey(ActiveKategorija, ActiveSprava)];
                activeOcene[activeOcene.IndexOf(editedItem)] = editedItem;

                setOcene(activeOcene);
                selectOcena(editedItem);
            }
            finally
            {
                Cursor.Hide();
                Cursor.Current = Cursors.Arrow;
            }
        }