protected void BtnUnos_Click(object sender, EventArgs e) { //Sliku uploadamo na server u direkotrij Images var koordinate = new Koordinate(); var path = ""; if (System.IO.File.Exists(Server.MapPath("~/Images/" + fileUpload.Value))) { path = "~/Images/" + fileUpload.Value; //ako postoji slika sa istim nazivom na serveru //necemo je spremiti ponovno nego cemo samo na ovu novu koordinatu //dodati njenu putanju //mogući problem su različite slike sa istim nazivom } else { path = "~/Images/" + fileUpload.Value; fileUpload.PostedFile.SaveAs(Server.MapPath(path)); } koordinate.Sirina = sirina.Value; koordinate.Duzina = duzina.Value; koordinate.Opis = opis.Value; koordinate.Slika = path.Replace("~", ""); //U bazu spremimo URL od slike SpremiKoordinate(koordinate); }
public static void SpremiKoordinate(Koordinate koordinate) { string constr = ConfigurationManager.ConnectionStrings["MapaCNSTR"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand("INSERT INTO Koordinate VALUES(@Duzina, @Sirina, @Opis)")) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@Duzina", koordinate.Duzina); cmd.Parameters.AddWithValue("@Sirina", koordinate.Sirina); cmd.Parameters.AddWithValue("@Opis", koordinate.Opis); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } }
public void SpremiKoordinate(Koordinate koordinate) { string constr = ConfigurationManager.ConnectionStrings["MapaCNSTR"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand("INSERT INTO Koordinate VALUES(@Duzina, @Sirina, @Opis, @Korisnik_Id, @urlSlika, @Stanje)")) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@Duzina", koordinate.Duzina); cmd.Parameters.AddWithValue("@Sirina", koordinate.Sirina); cmd.Parameters.AddWithValue("@Opis", koordinate.Opis); cmd.Parameters.AddWithValue("@Korisnik_Id", HttpContext.Current.Session["id"].ToString()); cmd.Parameters.AddWithValue("@urlSlika", koordinate.Slika); cmd.Parameters.AddWithValue("@Stanje", 0); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); Response.Redirect("Default.aspx?spremi=ok"); } } }
protected void BtnUnos_Click(object sender, EventArgs e) { //Sliku uploadamo na server u direkotrij Images var koordinate = new Koordinate(); var path = ""; if (System.IO.File.Exists(Server.MapPath("~/Images/" + fileUpload.Value))) { path = "~/ Images / " + fileUpload.Value.Insert(fileUpload.Value.IndexOf("."), "2"); fileUpload.PostedFile.SaveAs(Server.MapPath(path)); } else { path = "~/Images/" + fileUpload.Value; fileUpload.PostedFile.SaveAs(Server.MapPath(path)); } koordinate.Sirina = sirina.Value; koordinate.Duzina = duzina.Value; koordinate.Opis = opis.Value; koordinate.Slika = path.Replace("~", ""); //U bazu spremimo URL od slike SpremiKoordinate(koordinate); }