Ejemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Trasy trasy = db.Trasy.Find(id);

            db.Trasy.Remove(trasy);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "ID,Dlugosc,OplatyDodatkowe,IDCentrum1,IDCentrum2")] Trasy trasy)
 {
     if (ModelState.IsValid)
     {
         db.Entry(trasy).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.IDCentrum1 = new SelectList(db.CentraLogistyczne, "ID", "Kod", trasy.IDCentrum1);
     ViewBag.IDCentrum2 = new SelectList(db.CentraLogistyczne, "ID", "Kod", trasy.IDCentrum2);
     return(View(trasy));
 }
Ejemplo n.º 3
0
        // GET: Trasy/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Trasy trasy = db.Trasy.Find(id);

            if (trasy == null)
            {
                return(HttpNotFound());
            }
            return(View(trasy));
        }
Ejemplo n.º 4
0
        // GET: Trasy/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Trasy trasy = db.Trasy.Find(id);

            if (trasy == null)
            {
                return(HttpNotFound());
            }
            ViewBag.IDCentrum1 = new SelectList(db.CentraLogistyczne, "ID", "Kod", trasy.IDCentrum1);
            ViewBag.IDCentrum2 = new SelectList(db.CentraLogistyczne, "ID", "Kod", trasy.IDCentrum2);
            return(View(trasy));
        }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Include = "ID,Dlugosc,OplatyDodatkowe,IDCentrum1,IDCentrum2")] Trasy trasy)
        {
            if (ModelState.IsValid)
            {
                if (trasy != null)
                {
                    string        a = null, b = null;
                    SqlConnection sqlConnection1 = new SqlConnection("Server=SPIERDOLENIE;Database=LogisticDB;Trusted_Connection=True; ");

                    using (sqlConnection1)
                    {
                        SqlCommand command = new SqlCommand(
                            "SELECT Miasto, Ulica, Numer FROM CentraLogistyczne WHERE ID = " + trasy.IDCentrum1 + ";",
                            sqlConnection1);
                        sqlConnection1.Open();

                        SqlDataReader reader = command.ExecuteReader();

                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                a = reader.GetString(0) + " " + reader.GetString(1) + " " + reader.GetInt32(2);
                            }
                        }
                        else
                        {
                            Console.WriteLine("No rows found.");
                        }
                        reader.Close();

                        SqlCommand command1 = new SqlCommand(
                            "SELECT Miasto, Ulica, Numer FROM CentraLogistyczne WHERE ID = " + trasy.IDCentrum2 + ";",
                            sqlConnection1);

                        SqlDataReader reader1 = command1.ExecuteReader();

                        if (reader1.HasRows)
                        {
                            while (reader1.Read())
                            {
                                b = reader1.GetString(0) + " " + reader1.GetString(1) + " " + reader1.GetInt32(2);
                            }
                        }
                        else
                        {
                            Console.WriteLine("No rows found.");
                        }
                        reader1.Close();
                        sqlConnection1.Close();
                        trasy.Dlugosc = getDistance(a, b) / 1000;
                    }
                    //SqlCommand cmd = new SqlCommand();
                    //SqlCommand cmd1 = new SqlCommand();
                    //SqlDataReader reader;
                    //SqlDataReader reader1;
                    //cmd.CommandText = "SELECT * FROM Trasy" ;
                    //cmd.CommandType = CommandType.Text;
                    //cmd.Connection = sqlConnection1;

                    //sqlConnection1.Open();

                    //reader = cmd.ExecuteReader();
                    //// Data is accessible through the DataReader object here.
                    //string a = reader.GetString(0);
                    //sqlConnection1.Close();
                    //cmd1.CommandText = "SELECT Miasto FROM CentraLogistyczne WHERE ID = '2'";
                    //cmd1.CommandType = CommandType.Text;
                    //cmd1.Connection = sqlConnection1;

                    //sqlConnection1.Open();

                    //reader1 = cmd1.ExecuteReader();
                    //// Data is accessible through the DataReader object here.
                    //string b = reader1.GetString(0);
                    //sqlConnection1.Close();


                    //string centrum1 = trasy.CentraLogistyczne.Miasto + trasy.CentraLogistyczne.Ulica +
                    //                  trasy.CentraLogistyczne.Numer;
                    //string centrum2 = trasy.CentraLogistyczne1.Miasto + trasy.CentraLogistyczne1.Ulica +
                    //                  trasy.CentraLogistyczne1.Numer;
                }
                db.Trasy.Add(trasy);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.IDCentrum1 = new SelectList(db.CentraLogistyczne, "ID", "Kod", trasy.IDCentrum1);
            ViewBag.IDCentrum2 = new SelectList(db.CentraLogistyczne, "ID", "Kod", trasy.IDCentrum2);
            return(View(trasy));
        }