Пример #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            DialogResult dlgResult            = DialogResult.None;
            SelectGimnasticarUcesnikForm form = null;

            try
            {
                form = new SelectGimnasticarUcesnikForm(rezTakmicenje.Takmicenje.Id,
                                                        rezTakmicenje.Gimnastika, null);
                dlgResult = form.ShowDialog();
            }
            catch (InfrastructureException ex)
            {
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }

            if (dlgResult != DialogResult.OK || form.SelectedEntities.Count == 0)
            {
                return;
            }

            Ekipa ekipa = (Ekipa)entity;
            bool  added = false;

            string msg = String.Empty;

            foreach (GimnasticarUcesnik g in form.SelectedEntities)
            {
                Ekipa ekipa2 = rezTakmicenje.findEkipa(g, DeoTakmicenjaKod.Takmicenje1);
                if (ekipa2 != null && !ekipa2.Equals(ekipa))
                {
                    msg += String.Format(
                        Strings.GIMNASTICAR_JE_CLAN_DRUGE_EKIPE_ERROR_MSG, g.ImeSrednjeImePrezime, ekipa2.Naziv);
                    continue;
                }
                if (ekipa.addGimnasticar(g))
                {
                    added = true;
                }
            }
            if (added)
            {
                setClanovi(ekipa.Gimnasticari);
            }

            if (msg != String.Empty)
            {
                string msg2 = "Sledeci gimnasticari nisu dodati jer su clanovi drugih ekipa: \n\n" + msg;
                MessageDialogs.showMessage(msg2, this.Text);
            }
        }
Пример #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            DialogResult dlgResult            = DialogResult.None;
            SelectGimnasticarUcesnikForm form = null;

            try
            {
                form      = new SelectGimnasticarUcesnikForm(takmicenjeId, gimnastika, null);
                dlgResult = form.ShowDialog();
            }
            catch (InfrastructureException ex)
            {
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }

            if (dlgResult != DialogResult.OK || form.SelectedEntities.Count == 0)
            {
                return;
            }

            bool   added = false;
            string msg   = String.Empty;

            foreach (GimnasticarUcesnik g in form.SelectedEntities)
            {
                StartListaNaSpravi startLista2 = raspored.getStartLista(g, startLista.Grupa, startLista.Rotacija);
                if (startLista2 != null && startLista2.Sprava != startLista.Sprava)
                {
                    msg += g.ImeSrednjeImePrezime + " (" + Sprave.toString(startLista2.Sprava) + ")\n";
                    continue;
                }
                if (startLista.addGimnasticar(g))
                {
                    added = true;
                }
            }

            if (msg != String.Empty)
            {
                MessageDialogs.showMessage("Sledeci gimnsticari nisu dodati jer vec postoje u rotaciji:\n\n" + msg,
                                           this.Text);
            }

            if (added)
            {
                dirty = true;
                spravaGridUserControl1.setItems(startLista.Nastupi);
                spravaGridUserControl1.clearSelection();
            }
        }
Пример #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            DialogResult dlgResult = DialogResult.None;
            SelectGimnasticarUcesnikForm form = null;
            try
            {
                form = new SelectGimnasticarUcesnikForm(rezTakmicenje.Takmicenje.Id,
                    rezTakmicenje.Pol, null);
                dlgResult = form.ShowDialog();
            }
            catch (InfrastructureException ex)
            {
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }

            if (dlgResult != DialogResult.OK || form.SelectedEntities.Count == 0)
                return;

            Ekipa ekipa = (Ekipa)entity;
            List<GimnasticarUcesnik> okGimnasticari = new List<GimnasticarUcesnik>();
            List<GimnasticarUcesnik> illegalGimnasticari = new List<GimnasticarUcesnik>();
            foreach (GimnasticarUcesnik g in form.SelectedEntities)
            {
                if (canAddGimnasticar(ekipa, g))
                {
                    ekipa.addGimnasticar(g);
                    okGimnasticari.Add(g);
                }
                else
                {
                    illegalGimnasticari.Add(g);
                }

            }
            if (okGimnasticari.Count > 0)
            {
                setClanovi(ekipa.Gimnasticari);
                dgwUserControlClanovi.setSelectedItem<GimnasticarUcesnik>
                    (okGimnasticari[okGimnasticari.Count - 1]);
            }

            if (illegalGimnasticari.Count > 0)
            {
                string msg = "Sledec gimnasticari nisu dodati: \n\n";
                msg += StringUtil.getListString(illegalGimnasticari.ToArray());
                //       MessageDialogs.showMessage(msg, this.Text);
            }
        }
Пример #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)
        {
            DialogResult dlgResult            = DialogResult.None;
            SelectGimnasticarUcesnikForm form = null;

            try
            {
                form = new SelectGimnasticarUcesnikForm(
                    ActiveRezTakmicenje.Takmicenje.Id, ActiveRezTakmicenje.Gimnastika,
                    ActiveRezTakmicenje.Kategorija);
                dlgResult = form.ShowDialog();
            }
            catch (InfrastructureException ex)
            {
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }

            if (dlgResult != DialogResult.OK || form.SelectedEntities.Count == 0)
            {
                return;
            }

            IList <GimnasticarUcesnik> addedGimnasticari = new List <GimnasticarUcesnik>();

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

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

                        IList <GimnasticarUcesnik> selGimnasticari = new List <GimnasticarUcesnik>();
                        foreach (GimnasticarUcesnik g in form.SelectedEntities)
                        {
                            selGimnasticari.Add(g);
                        }
                        RezultatskoTakmicenjeService.addGimnasticariToRezTak(selGimnasticari, ActiveRezTakmicenje,
                                                                             addedGimnasticari);
                        if (addedGimnasticari.Count > 0)
                        {
                            takmicenje = DAOFactoryFactory.DAOFactory.GetTakmicenjeDAO().FindById(takmicenje.Id);
                            takmicenje.LastModified = DateTime.Now;
                            session.Transaction.Commit();
                        }
                    }
            }
            catch (InfrastructureException ex)
            {
                if (session != null && session.Transaction != null && session.Transaction.IsActive)
                {
                    session.Transaction.Rollback();
                }
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }
            catch (Exception ex)
            {
                if (session != null && session.Transaction != null && session.Transaction.IsActive)
                {
                    session.Transaction.Rollback();
                }
                MessageDialogs.showMessage(ex.Message, this.Text);
                return;
            }
            finally
            {
                Cursor.Hide();
                Cursor.Current = Cursors.Arrow;
                CurrentSessionContext.Unbind(NHibernateHelper.Instance.SessionFactory);
            }

            if (addedGimnasticari.Count > 0)
            {
                setGimnasticari(ActiveRezTakmicenje.Takmicenje1.Gimnasticari);
                updateGimnasticariCount();
            }
        }
Пример #6
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;
            }
        }
Пример #7
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            DialogResult dlgResult = DialogResult.None;
            SelectGimnasticarUcesnikForm form = null;
            try
            {
                form = new SelectGimnasticarUcesnikForm(takmicenjeId, raspored.Pol, null);
                dlgResult = form.ShowDialog();
            }
            catch (InfrastructureException ex)
            {
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }

            if (dlgResult != DialogResult.OK || form.SelectedEntities.Count == 0)
                return;

            List<GimnasticarUcesnik> okGimnasticari = new List<GimnasticarUcesnik>();
            List<GimnasticarUcesnik> illegalGimnasticari = new List<GimnasticarUcesnik>();
            foreach (GimnasticarUcesnik g in form.SelectedEntities)
            {
                if (startLista.canAddGimnasticar(g))
                    okGimnasticari.Add(g);
                else
                    illegalGimnasticari.Add(g);
            }

            /*for (int i = okGimnasticari.Count - 1; i >= 0; i--)
            {
                GimnasticarUcesnik g = okGimnasticari[i];
                if (!raspored.Kategorije.Contains(g.TakmicarskaKategorija))
                {
                    okGimnasticari.RemoveAt(i);
                    illegalGimnasticari.Add(g);
                }
            }*/

            foreach (GimnasticarUcesnik g in okGimnasticari)
            {
                startLista.addGimnasticar(g);
            }

            if (okGimnasticari.Count > 0)
            {
                spravaGridUserControl1.setItems(startLista.Nastupi);
                spravaGridUserControl1.clearSelection();
            }

            if (illegalGimnasticari.Count > 0)
            {
                string msg = "Sledeci gimnasticari nisu dodati, zato sto ili vec " +
                    "postoje na start listi, ili im kategorija nije odgovarajuca: \n\n";
                msg += StringUtil.getListString(illegalGimnasticari.ToArray());
                //       MessageDialogs.showMessage(msg, this.Text);
            }
        }
Пример #8
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            DialogResult dlgResult = DialogResult.None;
            SelectGimnasticarUcesnikForm form = null;
            try
            {
                form = new SelectGimnasticarUcesnikForm(
                    ActiveRezTakmicenje.Takmicenje.Id, ActiveRezTakmicenje.Pol,
                    ActiveRezTakmicenje.Kategorija);
                dlgResult = form.ShowDialog();
            }
            catch (InfrastructureException ex)
            {
                MessageDialogs.showError(ex.Message, this.Text);
                return;
            }

            if (dlgResult != DialogResult.OK || form.SelectedEntities.Count == 0)
                return;

            Cursor.Current = Cursors.WaitCursor;
            Cursor.Show();
            bool added = false;
            List<GimnasticarUcesnik> illegalGimnasticari = new List<GimnasticarUcesnik>();
            try
            {
                DataAccessProviderFactory factory = new DataAccessProviderFactory();
                dataContext = factory.GetDataContext();
                dataContext.BeginTransaction();

                dataContext.Attach(ActiveRezTakmicenje, false);
                foreach (GimnasticarUcesnik g in ActiveRezTakmicenje.Takmicenje1.Gimnasticari)
                    dataContext.Attach(g, false);

                foreach (GimnasticarUcesnik g in form.SelectedEntities)
                {
                    if (canAddGimnasticar(ActiveRezTakmicenje, g))
                    {
                        ActiveRezTakmicenje.Takmicenje1.addGimnasticar(g);

                        IList<Ocena> ocene = loadOceneTak1(g);
                        ActiveRezTakmicenje.Takmicenje1
                            .gimnasticarAdded(g, ocene, ActiveRezTakmicenje);
                        added = true;
                    }
                    else
                    {
                        illegalGimnasticari.Add(g);
                    }
                }
                if (added)
                {
                    dataContext.Save(ActiveRezTakmicenje.Takmicenje1);
                    foreach (GimnasticarUcesnik g in ActiveRezTakmicenje.Takmicenje1.Gimnasticari)
                        dataContext.Evict(g);
                    dataContext.Commit();
                }
            }
            catch (InfrastructureException ex)
            {
                if (dataContext != null && dataContext.IsInTransaction)
                    dataContext.Rollback();
                MessageDialogs.showError(ex.Message, this.Text);
                Close();
                return;
            }
            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;

                Cursor.Hide();
                Cursor.Current = Cursors.Arrow;
            }

            if (added)
            {
                setGimnasticari(ActiveRezTakmicenje.Takmicenje1.Gimnasticari);
                updateGimnasticariCount();
            }

            if (illegalGimnasticari.Count > 0)
            {
                string msg = "Sledeci gimnasticari nisu dodati: \n\n";
                msg += StringUtil.getListString(illegalGimnasticari.ToArray());
                //       MessageDialogs.showMessage(msg, this.Text);
            }
        }