コード例 #1
0
        public IEnumerable <PutniNalog> FindBetweenDates(DateTime begin, DateTime end)
        {
            PutniNalog        temp           = null;
            List <PutniNalog> listPutniNalog = new List <PutniNalog>();

            using (IDbConnection connection = database.CreateOpenConnection())
            {
                IDbTransaction tran = connection.BeginTransaction();

                using (IDbCommand command = database.CreateStoredProcCommand("FindWarrantBetweenDates", connection))
                {
                    try
                    {
                        command.Connection  = connection;
                        command.Transaction = tran;
                        command.Parameters.Add(database.CreateParameter("pBegin", begin));
                        command.Parameters.Add(database.CreateParameter("pEnd", end));
                        using (IDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                IVozacRepository  vozrepo    = new VozacRepository();
                                IVoziloRepository vozilorepo = new VoziloRepository();
                                Vozac             tempvoz    = vozrepo.FindById(reader.GetInt32(1));
                                Vozilo            tempvozilo = vozilorepo.FindById(reader.GetInt32(2));
                                temp = new PutniNalog
                                {
                                    IDPutniNalog = reader.GetInt32(0),
                                    Vozac        = tempvoz,
                                    Vozilo       = tempvozilo,
                                    StartGrad    = reader.GetString(3),
                                    StopGrad     = reader.GetString(4),
                                    StartDate    = reader.GetDateTime(5),
                                    StopDate     = reader.GetDateTime(6)
                                };
                                listPutniNalog.Add(temp);
                            }
                        }
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            tran.Rollback();
                            throw ex;
                        }
                        catch (Exception ex2)
                        {
                            throw ex2;
                        }
                    }
                }
            }
            return(listPutniNalog.AsEnumerable());
        }
コード例 #2
0
        public IEnumerable <PutniNalog> FindAll()
        {
            List <PutniNalog> list = new List <PutniNalog>();

            using (IDbConnection connection = database.CreateOpenConnection())
            {
                IDbTransaction tran = connection.BeginTransaction();

                using (IDbCommand command = database.CreateStoredProcCommand("SelectAllWarrants", connection))
                {
                    try
                    {
                        command.Connection  = connection;
                        command.Transaction = tran;
                        using (IDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                IVozacRepository  vozrepo    = new VozacRepository();
                                IVoziloRepository vozilorepo = new VoziloRepository();
                                Vozac             tempvoz    = vozrepo.FindById(reader.GetInt32(1));
                                Vozilo            tempvozilo = vozilorepo.FindById(reader.GetInt32(2));
                                PutniNalog        temp       = new PutniNalog
                                {
                                    IDPutniNalog = reader.GetInt32(0),
                                    Vozac        = tempvoz,
                                    Vozilo       = tempvozilo,
                                    StartGrad    = reader.GetString(3),
                                    StopGrad     = reader.GetString(4),
                                    StartDate    = reader.GetDateTime(5),
                                    StopDate     = reader.GetDateTime(6)
                                };
                                list.Add(temp);
                            }
                        }
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            tran.Rollback();
                        }
                        catch (Exception ex2)
                        {
                            throw;
                        }
                    }
                }
            }
            return(list.AsEnumerable());
        }
コード例 #3
0
        public PutniNalog FindById(int id)
        {
            PutniNalog temp = null;

            using (IDbConnection connection = database.CreateOpenConnection())
            {
                IDbTransaction tran = connection.BeginTransaction();

                using (IDbCommand command = database.CreateStoredProcCommand("FindWarrantByID", connection))
                {
                    try
                    {
                        command.Connection  = connection;
                        command.Transaction = tran;
                        command.Parameters.Add(database.CreateParameter("pID", id));
                        using (IDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                IVozacRepository  vozrepo    = new VozacRepository();
                                IVoziloRepository vozilorepo = new VoziloRepository();
                                Vozac             tempvoz    = vozrepo.FindById(reader.GetInt32(1));
                                Vozilo            tempvozilo = vozilorepo.FindById(reader.GetInt32(2));
                                temp = new PutniNalog
                                {
                                    IDPutniNalog = reader.GetInt32(0),
                                    Vozac        = tempvoz,
                                    Vozilo       = tempvozilo,
                                    StartGrad    = reader.GetString(3),
                                    StopGrad     = reader.GetString(4),
                                    StartDate    = reader.GetDateTime(5),
                                    StopDate     = reader.GetDateTime(6)
                                };
                            }
                        }
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            tran.Rollback();
                        }
                        catch (Exception ex2)
                        {
                            throw;
                        }
                    }
                }
            }
            return(temp);
        }