예제 #1
0
        private IList <DolazakNaTreningMesecni> getDolasciMesecni(Clan c, DateTime from, DateTime to)
        {
            if (c == null || c.Broj == CitacKartica.TEST_KARTICA_BROJ)
            {
                return(new List <DolazakNaTreningMesecni>());
            }

            IList <DolazakNaTreningMesecni> result = null;

            try
            {
                using (ISession session = NHibernateHelper.Instance.OpenSession())
                    using (session.BeginTransaction())
                    {
                        CurrentSessionContext.Bind(session);
                        DolazakNaTreningMesecniDAO dolazakNaTreningMesecniDAO
                               = DAOFactoryFactory.DAOFactory.GetDolazakNaTreningMesecniDAO();
                        result = dolazakNaTreningMesecniDAO.getDolazakNaTrening(c, from.Year, from.Month, to.Year, to.Month);
                    }
            }
            catch (Exception ex)
            {
                MessageDialogs.showMessage(ex.Message, "Uplata clanarine");
            }
            finally
            {
                CurrentSessionContext.Unbind(NHibernateHelper.Instance.SessionFactory);
            }
            if (result == null)
            {
                result = new List <DolazakNaTreningMesecni>();
            }
            return(result);
        }
예제 #2
0
    private void UpdateDolazakNaTreningMesecniJedanDnevniTrening()
    {
        IDictionary <ClanGodinaMesec, ISet> dolasciMap = getDolasciMapJedanDnevniTrening();
        ISession session = null;

        try
        {
            using (session = NHibernateHelper.Instance.OpenSession())
                using (session.BeginTransaction())
                {
                    CurrentSessionContext.Bind(session);
                    DolazakNaTreningMesecniDAO dolazakNaTreningMesecniDAO
                        = DAOFactoryFactory.DAOFactory.GetDolazakNaTreningMesecniDAO();

                    IDictionary <ClanGodinaMesec, DolazakNaTreningMesecni> dolasciMesecniMap
                        = new Dictionary <ClanGodinaMesec, DolazakNaTreningMesecni>();
                    foreach (DolazakNaTreningMesecni d in dolazakNaTreningMesecniDAO.FindAll())
                    {
                        ClanGodinaMesec key = new ClanGodinaMesec(d.Clan.Id, d.Godina, d.Mesec);
                        if (!dolasciMesecniMap.ContainsKey(key))
                        {
                            dolasciMesecniMap.Add(key, d);
                        }
                        else
                        {
                            throw new Exception("Greska prilikom azuriranja programa");
                        }
                    }
                    foreach (KeyValuePair <ClanGodinaMesec, ISet> entry in dolasciMap)
                    {
                        if (!dolasciMesecniMap.ContainsKey(entry.Key))
                        {
                            throw new Exception("Greska prilikom azuriranja programa");
                        }
                        DolazakNaTreningMesecni dolazakMesecni = dolasciMesecniMap[entry.Key];
                        dolazakMesecni.BrojDolazaka = entry.Value.Count;
                        dolazakNaTreningMesecniDAO.MakePersistent(dolazakMesecni);
                    }
                    session.Transaction.Commit();
                }
        }
        catch (Exception ex)
        {
            if (session != null && session.Transaction != null && session.Transaction.IsActive)
            {
                session.Transaction.Rollback();
            }
            throw new InfrastructureException(ex.Message, ex);
        }
        finally
        {
            CurrentSessionContext.Unbind(NHibernateHelper.Instance.SessionFactory);
        }
    }
예제 #3
0
    private void UpdateDolazakNaTreningMesecni()
    {
        ISession session = null;

        try
        {
            using (session = NHibernateHelper.Instance.OpenSession())
                using (session.BeginTransaction())
                {
                    CurrentSessionContext.Bind(session);
                    DolazakNaTreningMesecniDAO dolazakNaTreningMesecniDAO
                        = DAOFactoryFactory.DAOFactory.GetDolazakNaTreningMesecniDAO();
                    List <DolazakNaTreningMesecni> dolasciMesecni
                        = new List <DolazakNaTreningMesecni>(dolazakNaTreningMesecniDAO.FindAll());
                    if (dolasciMesecni.Count > 0)
                    {
                        return;
                    }

                    DolazakNaTreningDAO      dolazakNaTreningDAO = DAOFactoryFactory.DAOFactory.GetDolazakNaTreningDAO();
                    IList <DolazakNaTrening> dolasci             = dolazakNaTreningDAO.FindAll();
                    IDictionary <ClanGodinaMesec, DolazakNaTreningMesecni> dolasciMap
                        = new Dictionary <ClanGodinaMesec, DolazakNaTreningMesecni>();
                    foreach (DolazakNaTrening d in dolasci)
                    {
                        ClanGodinaMesec key = new ClanGodinaMesec(d.Clan.Id, d.DatumDolaska.Value.Year,
                                                                  d.DatumDolaska.Value.Month);
                        if (!dolasciMap.ContainsKey(key))
                        {
                            DolazakNaTreningMesecni dolazak = new DolazakNaTreningMesecni();
                            dolazak.Clan         = d.Clan;
                            dolazak.Godina       = d.DatumDolaska.Value.Year;
                            dolazak.Mesec        = d.DatumDolaska.Value.Month;
                            dolazak.BrojDolazaka = 1;
                            dolasciMap.Add(key, dolazak);
                        }
                        else
                        {
                            ++(dolasciMap[key].BrojDolazaka);
                        }
                    }
                    foreach (KeyValuePair <ClanGodinaMesec, DolazakNaTreningMesecni> entry in dolasciMap)
                    {
                        dolazakNaTreningMesecniDAO.MakePersistent(entry.Value);
                    }
                    session.Transaction.Commit();
                }
        }
        catch (Exception ex)
        {
            if (session != null && session.Transaction != null && session.Transaction.IsActive)
            {
                session.Transaction.Rollback();
            }
            throw new InfrastructureException(ex.Message, ex);
        }
        finally
        {
            CurrentSessionContext.Unbind(NHibernateHelper.Instance.SessionFactory);
        }
    }