示例#1
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();
                    }
                }
            }
        }
示例#2
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);
        }
示例#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;
            }
        }
示例#4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            SelectGimnasticarUcesnikForm form = null;

            try
            {
                form = new SelectGimnasticarUcesnikForm(ActiveKategorija.Takmicenje.Id,
                                                        takmicenje.Gimnastika, ActiveKategorija);
                form.MultiSelect = false;
                if (form.ShowDialog() != DialogResult.OK ||
                    form.SelectedEntities.Count != 1)
                {
                    return;
                }
            }
            catch (InfrastructureException ex)
            {
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }

            GimnasticarUcesnik g = (GimnasticarUcesnik)form.SelectedEntities[0];

            if (!ucestvuje(g, deoTakKod))
            {
                string msg = String.Format(
                    "Gimnasticar '{0}' ne ucestvuje u {1}.",
                    g.ImeSrednjeImePrezime, DeoTakmicenjaKodovi.toString(deoTakKod));
                MessageDialogs.showMessage(msg, this.Text);
                return;
            }

            Ocena    ocena   = null;
            ISession session = null;

            try
            {
                using (session = NHibernateHelper.Instance.OpenSession())
                    using (session.BeginTransaction())
                    {
                        CurrentSessionContext.Bind(session);
                        ocena = DAOFactoryFactory.DAOFactory.GetOcenaDAO().FindOcena(g, deoTakKod, ActiveSprava);
                    }
            }
            catch (Exception ex)
            {
                if (session != null && session.Transaction != null && session.Transaction.IsActive)
                {
                    session.Transaction.Rollback();
                }
                MessageDialogs.showError(ex.Message, this.Text);
                Close();
                return;
            }
            finally
            {
                CurrentSessionContext.Unbind(NHibernateHelper.Instance.SessionFactory);
            }

            bool      edit;
            OcenaForm f;

            if (ocena != null)
            {
                edit = true;
                f    = new OcenaForm(ocena.Id, g, ActiveSprava, deoTakKod, takmicenje.Id);
            }
            else
            {
                edit = false;
                f    = new OcenaForm(null, g, ActiveSprava, deoTakKod, takmicenje.Id);
            }

            try
            {
                if (f.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }
            catch (InfrastructureException ex)
            {
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            Cursor.Show();
            ocena   = null;
            session = null;
            try
            {
                using (session = NHibernateHelper.Instance.OpenSession())
                    using (session.BeginTransaction())
                    {
                        CurrentSessionContext.Bind(session);
                        ocena = DAOFactoryFactory.DAOFactory.GetOcenaDAO().FindByIdFetch(f.Entity.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);
            }

            bool opened = gridOpened(g.TakmicarskaKategorija, ActiveSprava);

            showGridOcene(g.TakmicarskaKategorija, ActiveSprava);
            List <Ocena> activeOcene = ocene[calculateOceneKey(g.TakmicarskaKategorija, ActiveSprava)];

            if (!edit)
            {
                // nova ocena se dodaje u listu activeOcene samo ako je grid vec bio
                // prikazivan; ako se grid prvi put prikazuje, ocene se ucitavaju i
                // medju njima se nalazi i ona koja je upravo dodata.
                if (opened)
                {
                    activeOcene.Add(ocena);
                }
            }
            else
            {
                activeOcene[activeOcene.IndexOf(ocena)] = ocena;
            }

            setOcene(activeOcene);
            selectOcena(ocena);
        }
示例#5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            SelectGimnasticarUcesnikForm form = null;
            try
            {
                form = new SelectGimnasticarUcesnikForm(ActiveKategorija.Takmicenje.Id,
                    ActiveKategorija.Pol, ActiveKategorija);
                form.MultiSelect = false;
                if (form.ShowDialog() != DialogResult.OK
                || form.SelectedEntities.Count != 1)
                    return;
            }
            catch (InfrastructureException ex)
            {
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }

            GimnasticarUcesnik g = (GimnasticarUcesnik)form.SelectedEntities[0];
            if (!ucestvuje(g, deoTakKod))
            {
                string msg = String.Format(
                    "Gimnasticar '{0}' ne ucestvuje u {1}.",
                    g.ImeSrednjeImePrezime, DeoTakmicenjaKodovi.toString(deoTakKod));
                MessageDialogs.showMessage(msg, this.Text);
                return;
            }

            Ocena ocena = null;
            try
            {
                DataAccessProviderFactory factory = new DataAccessProviderFactory();
                dataContext = factory.GetDataContext();
                dataContext.BeginTransaction();

                ocena = findOcena(g, deoTakKod, ActiveSprava);
            }
            catch (Exception ex)
            {
                if (dataContext != null && dataContext.IsInTransaction)
                    dataContext.Rollback();
                MessageDialogs.showMessage(
                    Strings.getFullDatabaseAccessExceptionMessage(ex), this.Text);
                Close();
                return;
            }
            finally
            {
                if (dataContext != null)
                    dataContext.Dispose();
                dataContext = null;
            }

            bool edit;
            OcenaForm f;
            if (ocena != null)
            {
                edit = true;
                f = new OcenaForm(ocena.Id, g, ActiveSprava, deoTakKod, takmicenje.Id);
            }
            else
            {
                edit = false;
                f = new OcenaForm(null, g, ActiveSprava, deoTakKod, takmicenje.Id);
            }

            try
            {
                if (f.ShowDialog() != DialogResult.OK)
                    return;
            }
            catch (InfrastructureException ex)
            {
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }

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

                    ocena = loadOcena(f.Entity.Id);
                }
                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;
                }

                bool opened = gridOpened(g.TakmicarskaKategorija, ActiveSprava);
                showGridOcene(g.TakmicarskaKategorija, ActiveSprava);
                List<Ocena> activeOcene = ocene[calculateOceneKey(g.TakmicarskaKategorija, ActiveSprava)];
                if (!edit)
                {
                    // nova ocena se dodaje u listu activeOcene samo ako je grid vec bio
                    // prikazivan; ako se grid prvi put prikazuje, ocene se ucitavaju i
                    // medju njima se nalazi i ona koja je upravo dodata.
                    if (opened)
                        activeOcene.Add(ocena);
                }
                else
                    activeOcene[activeOcene.IndexOf(ocena)] = ocena;

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