コード例 #1
0
        public IEnumerable <Ruta> FindAll()
        {
            List <Ruta> list = new List <Ruta>();

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

                using (IDbCommand command = database.CreateStoredProcCommand("SelectAllRoutes", connection))
                {
                    try
                    {
                        command.Connection  = connection;
                        command.Transaction = tran;
                        using (IDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                IPutniNalogRepository putnirepo  = new PutniNalogRepository();
                                PutniNalog            putninalog = putnirepo.FindById(reader.GetInt32(1));
                                Ruta temp = new Ruta
                                {
                                    IDRuta               = reader.GetInt32(0),
                                    PutniNalog           = putninalog,
                                    Vrijeme              = reader.GetDateTime(2),
                                    ACoordX              = reader.GetInt32(3),
                                    ACoordY              = reader.GetInt32(4),
                                    BCoordX              = reader.GetInt32(5),
                                    BCoordY              = reader.GetInt32(6),
                                    PrijedeniKM          = reader.GetDouble(7),
                                    ProsjecniKMH         = reader.GetDouble(8),
                                    PotrosenoGorivoLitre = reader.GetDouble(9)
                                };
                                list.Add(temp);
                            }
                        }
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            tran.Rollback();
                        }
                        catch (Exception ex2)
                        {
                            throw;
                        }
                    }
                }
            }
            return(list.AsEnumerable());
        }
コード例 #2
0
        public Ruta FindById(int id)
        {
            Ruta temp = null;

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

                using (IDbCommand command = database.CreateStoredProcCommand("FindRoute", connection))
                {
                    try
                    {
                        command.Connection  = connection;
                        command.Transaction = tran;
                        command.Parameters.Add(database.CreateParameter("pID", id));
                        using (IDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                IPutniNalogRepository putnirepo  = new PutniNalogRepository();
                                PutniNalog            putninalog = putnirepo.FindById(reader.GetInt32(1));
                                temp = new Ruta
                                {
                                    IDRuta               = reader.GetInt32(0),
                                    PutniNalog           = putninalog,
                                    Vrijeme              = reader.GetDateTime(2),
                                    ACoordX              = reader.GetInt32(3),
                                    ACoordY              = reader.GetInt32(4),
                                    BCoordX              = reader.GetInt32(5),
                                    BCoordY              = reader.GetInt32(6),
                                    PrijedeniKM          = reader.GetDouble(7),
                                    ProsjecniKMH         = reader.GetDouble(8),
                                    PotrosenoGorivoLitre = reader.GetDouble(9)
                                };
                            }
                        }
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            tran.Rollback();
                        }
                        catch (Exception ex2)
                        {
                            throw;
                        }
                    }
                }
            }
            return(temp);
        }
コード例 #3
0
        public IEnumerable <KupnjaGoriva> FindAll()
        {
            List <KupnjaGoriva> list = new List <KupnjaGoriva>();

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

                using (IDbCommand command = database.CreateStoredProcCommand("SelectAllFuelBuying", connection))
                {
                    try
                    {
                        command.Connection  = connection;
                        command.Transaction = tran;
                        using (IDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                IPutniNalogRepository putrepo    = new PutniNalogRepository();
                                PutniNalog            putniNalog = putrepo.FindById(reader.GetInt32(1));
                                KupnjaGoriva          temp       = new KupnjaGoriva
                                {
                                    IDKupnjaGoriva = reader.GetInt32(0),
                                    Lokacija       = reader.GetString(2),
                                    GorivoPoLitri  = reader.GetFloat(3),
                                    CijenaPoLitri  = reader.GetFloat(4),
                                    PutniNalog     = putniNalog
                                };
                                list.Add(temp);
                            }
                        }
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            tran.Rollback();
                        }
                        catch (Exception ex2)
                        {
                            throw;
                        }
                    }
                }
            }
            return(list.AsEnumerable());
        }
コード例 #4
0
        public KupnjaGoriva FindById(int id)
        {
            KupnjaGoriva temp = null;

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

                using (IDbCommand command = database.CreateStoredProcCommand("FindFuelBuyingByID", connection))
                {
                    try
                    {
                        command.Connection  = connection;
                        command.Transaction = tran;
                        command.Parameters.Add(database.CreateParameter("pID", id));
                        using (IDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                IPutniNalogRepository putrepo    = new PutniNalogRepository();
                                PutniNalog            putniNalog = putrepo.FindById(reader.GetInt32(1));
                                temp = new KupnjaGoriva
                                {
                                    IDKupnjaGoriva = reader.GetInt32(0),
                                    Lokacija       = reader.GetString(2),
                                    GorivoPoLitri  = reader.GetFloat(3),
                                    CijenaPoLitri  = reader.GetFloat(4),
                                    PutniNalog     = putniNalog
                                };
                            }
                        }
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            tran.Rollback();
                        }
                        catch (Exception ex2)
                        {
                            throw;
                        }
                    }
                }
            }
            return(temp);
        }