Exemplo n.º 1
0
        public List <Hult> GetAllHult()
        {
            Connect();
            log4net.Config.DOMConfigurator.Configure();
            log.Info("Вызывается метод который возвращает список всех остановок.");
            List <Hult> hultlList = new List <Hult>();

            SqlCommand    commandRead = new SqlCommand("SELECT*FROM Hult;", Connection);
            SqlDataReader reader      = commandRead.ExecuteReader();

            try
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Hult hult = new Hult();
                        hult.Id       = Convert.ToInt32(reader["id"]);
                        hult.HultName = Convert.ToString(reader["hultName"]);
                        hultlList.Add(hult);
                    }
                }
            }
            catch (SqlException e)
            {
                log.Error("ERROR" + e.Message);
            }
            finally
            {
                reader.Close();
                Disconnect();
            }

            return(hultlList);
        }
Exemplo n.º 2
0
        public bool AddHult(Hult hult)
        {
            bool result = true;

            Connect();
            log4net.Config.DOMConfigurator.Configure();
            log.Info("Вызывается метод который добавляет новую остановку");

            try
            {
                string     sql     = "INSERT INTO Hult (hultName) VALUES (@hultName)";
                SqlCommand cmd_SQL = new SqlCommand(sql, Connection);
                cmd_SQL.Parameters.AddWithValue("@hultName", hult.HultName);
                cmd_SQL.ExecuteNonQuery();
            }
            catch (SqlException e)
            {
                log.Error("ERROR" + e.Message);
                result = false;
            }
            finally
            {
                Disconnect();
            }
            return(result);
        }
Exemplo n.º 3
0
        public ActionResult AddHult(int id, Route route)
        {
            try
            {
                IEnumerable <Hult> hults = routeDAO.GetHultWhithout(id);
                ViewBag.AllHult = new SelectList(hults, "id", "hultName");

                List <Hult> hultList = routeDAO.GetHultById(id);
                int         count    = hultList.Count();

                if (count > 0)
                {
                    Hult hult = hultList[hultList.Count - 1];
                    hultList.RemoveAt(count - 1);
                    ViewBag.IDList   = hultList;
                    ViewBag.LustHult = hult.HultName;
                }

                if (routeDAO.AddHult(id, route.HultId))
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("AddHult"));
                }
            }
            catch
            {
                return(View("AddHult"));
            }
        }
Exemplo n.º 4
0
        public List <Hult> GetHultWhithout(int id)
        {
            List <Hult> hultList = new RouteDAO().GetHultById(id);

            Connect();
            log4net.Config.DOMConfigurator.Configure();

            log.Info("Вызывается метод который возвращает список всех остановок на маршруте.");

            List <Hult> hultlList = new List <Hult>();
            string      query     = "SELECT*FROM Hult;";

            SqlCommand    commandRead = new SqlCommand(query, Connection);
            SqlDataReader reader      = commandRead.ExecuteReader();

            try
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Hult hult = new Hult();
                        hult.HultName = Convert.ToString(reader["hultName"]);
                        hult.Id       = Convert.ToInt32(reader["Id"]);
                        bool flag = true;
                        foreach (Hult h in hultList)
                        {
                            if (hult.Id == h.Id)
                            {
                                flag = false;
                            }
                        }
                        if (flag)
                        {
                            hultlList.Add(hult);
                        }
                    }
                }
            }
            catch (SqlException e)
            {
                log.Error("ERROR: " + e.Message);
            }
            finally
            {
                reader.Close();
                Disconnect();
            }

            return(hultlList);
        }
Exemplo n.º 5
0
        public ActionResult DetailsVisitor(int id)
        {
            List <Hult> hultList = routeDAO.GetHultById(id);
            int         count    = hultList.Count();

            if (count > 0)
            {
                Hult hult = hultList[hultList.Count - 1];
                hultList.RemoveAt(count - 1);
                ViewBag.IDList   = hultList;
                ViewBag.LustHult = hult.HultName;
            }
            return(View(routeDAO.GetById(id)));
        }
Exemplo n.º 6
0
 public ActionResult Edit(int id, Hult hult)
 {
     try
     {
         if (hultDAO.UpdateHult(id, hult))
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View("Edit"));
         }
     }
     catch
     {
         return(View("Edit"));
     }
 }
Exemplo n.º 7
0
 public ActionResult Create([Bind(Exclude = "d")] Hult hult)
 {
     try
     {
         if (hultDAO.AddHult(hult))
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View("Create"));
         }
     }
     catch
     {
         return(View("Create"));
     }
 }
Exemplo n.º 8
0
        public List <Hult> GetHultById(int id)
        {
            Connect();
            log4net.Config.DOMConfigurator.Configure();

            log.Info("Вызывается метод который возвращает список всех остановок на маршруте.");

            List <Hult> hultlList = new List <Hult>();
            string      query     = "SELECT*FROM RoteHult INNER JOIN Hult " +
                                    "ON Hult.id=RoteHult.Id_Hult where Id_Route=@id  ORDER BY RoteHult.routeNumber ASC;";

            SqlCommand commandRead = new SqlCommand(query, Connection);

            commandRead.Parameters.AddWithValue("@id", id);
            SqlDataReader reader = commandRead.ExecuteReader();

            try
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Hult hult = new Hult();
                        hult.HultName = Convert.ToString(reader["hultName"]);
                        hult.Id       = Convert.ToInt32(reader["Id_Hult"]);
                        hultlList.Add(hult);
                    }
                }
            }
            catch (SqlException e)
            {
                log.Error("ERROR: " + e.Message);
            }
            finally
            {
                reader.Close();
                Disconnect();
            }

            return(hultlList);
        }
Exemplo n.º 9
0
        public Hult GetById(int id)
        {
            Connect(); Hult hult        = new Hult();
            string          query       = "SELECT*FROM Hult where id=@id";
            SqlCommand      commandRead = new SqlCommand(query, Connection);

            commandRead.Parameters.AddWithValue("@id", id);
            SqlDataReader reader = commandRead.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    hult.Id       = Convert.ToInt32(reader["id"]);
                    hult.HultName = Convert.ToString(reader["hultName"]);
                }
            }
            reader.Close();
            Disconnect();

            return(hult);
        }
Exemplo n.º 10
0
        // GET: Route/AddHult/5
        public ActionResult AddHult(int id)
        {
            IEnumerable <Hult> hults = routeDAO.GetHultWhithout(id);

            ViewBag.AllHult = new SelectList(hults, "id", "hultName");
            if (hults.Count() == 0)
            {
                return(View("ErrorAdd"));
            }

            List <Hult> hultList = routeDAO.GetHultById(id);
            int         count    = hultList.Count();

            if (count > 0)
            {
                Hult hult = hultList[hultList.Count - 1];
                hultList.RemoveAt(count - 1);
                ViewBag.IDList   = hultList;
                ViewBag.LustHult = hult.HultName;
            }

            return(View(routeDAO.GetById(id)));
        }
Exemplo n.º 11
0
        public bool UpdateHult(int id, Hult hult)
        {
            bool result = true;

            Connect();

            try
            {
                string     sql     = "UPDATE Hult SET hultName=@hultName WHERE id=@id";
                SqlCommand cmd_SQL = new SqlCommand(sql, Connection);
                cmd_SQL.Parameters.AddWithValue("@id", id);
                cmd_SQL.Parameters.AddWithValue("@hultName", hult.HultName);
                cmd_SQL.ExecuteNonQuery();
            }
            catch (Exception)
            {
                result = false;
            }
            finally
            {
                Disconnect();
            }
            return(result);
        }