Imports System.Data.SqlClient Imports System.Configuration.ConfigurationManager Imports System.Drawing 'bitmap icin Imports System.Drawing.Imaging 'image çizimi için Partial Class panel_firma_rehberi_duzenle Inherits System.Web.UI.Page Private Sub panel_firma_rehberi_duzenle_Init(sender As Object, e As EventArgs) Handles Me.Init Dim cookie As HttpCookie = Request.Cookies("kullanici") 'cookie silindi ise ana sayfaya döner If cookie Is Nothing Then Response.Redirect("default.aspx") End If '---------------------------------------------------------- If Page.IsPostBack = False Then 'sayfa ilk yüklendiğinde çalışıp bir daha bu koda girmemesi için Dim conn As New SqlConnection(ConnectionStrings("ConnectionString").ToString) Dim COMM As New SqlCommand Dim rdr As SqlDataReader conn.Open() COMM = conn.CreateCommand() COMM.CommandText = "SELECT * FROM FIRMAREHBERI WHERE id = '" & Request.QueryString("K") & "'" rdr = COMM.ExecuteReader If rdr.Read Then e_firmaid.Value = Request.QueryString("K") e_kategori.SelectedValue = rdr("KATEGORI").ToString e_unvan.Text = rdr("UNVAN").ToString e_yetkili.Text = rdr("YETKILI").ToString e_web.Text = rdr("WEBADRES").ToString e_tel.Text = rdr("TELEFON").ToString e_eposta.Text = rdr("EMAIL").ToString e_adres.Text = rdr("ADRES").ToString e_harita.Text = rdr("KONUM").ToString e_bilgi.Content = "" & rdr("FIRMABILGI").ToString & "" 'resimler resim1.Text = rdr("RESIM1").ToString Image1.ImageUrl = "~/imagesfirmarehber/" + rdr("RESIM1").ToString resim2.Text = rdr("RESIM2").ToString Image2.ImageUrl = "~/imagesfirmarehber/" + rdr("RESIM2").ToString End If conn.Close() End If End Sub Private Sub kaydet_Click(sender As Object, e As EventArgs) Handles kaydet.Click On Error GoTo hata_kayit Dim conn As New SqlConnection(ConnectionStrings("ConnectionString").ToString) Dim COMM As New SqlCommand Dim sql1 As String Dim SAYI As Long Dim dosyaad As String Dim bmp As Bitmap mesaj1.Text = "" mesaj1.Visible = False mesaj2.Text = "" mesaj2.Visible = False '----------------------------------------------------------------------------------------------------------------------------------------------------- '1.resim resmin boyutlandırmasını yaparak gönderir SAYI = Randomizer(1000, 9999) Label29.Text = "" If FileUpload1.FileName <> "" Then If FileUpload1.HasFile Then 'dosya var ise If FileUpload1.PostedFile.ContentLength < 2000000 Then '2 mbit ten büyük dosya yüklenemez dosyaad = SAYI.ToString + "_" + FileUpload1.FileName If resim1.Text <> "" Then System.IO.File.Delete("" + Server.MapPath("~/imagesfirmarehber/") + "" + resim1.Text) 'daha önceki resmi silip değişen resmi atar FileUpload1.SaveAs(Server.MapPath("~/imagesfirmarehber/") + dosyaad) 'fotoyu server a attık '------------------------------yüklenmek istenen resmin boyutunu ayarlar------------------------------------------------- bmp = New Bitmap(Server.MapPath("~/imagesfirmarehber/" + dosyaad)) 'Kayıt ettğimiz fotoyu çağırıp üzerinde işlem yapıyoruz 'resmi en/boy oranında orantılı küçültür ------------------------------------------ Dim genislik As Integer = 800 'resmin genişliği max 800 yüksekliği max 700 olsun istiyoruz Dim yukseklik As Integer = 700 Dim ebatlar As New Size(bmp.Width, bmp.Height) If bmp.Width > genislik OrElse bmp.Height > yukseklik Then 'eğer istenilen ebatlardan büyükse boyutlandırma yapar 'resmin genişlik ve yükseklik oranını alıyoruz. Dim oran As Double = (CDbl(bmp.Width) / CDbl(bmp.Height)) If bmp.Width > genislik Then ebatlar.Width = genislik ebatlar.Height = CInt(CDbl(genislik) / oran) End If If ebatlar.Height > yukseklik Then ebatlar.Height = yukseklik ebatlar.Width = CInt(CDbl(yukseklik) * oran) End If Dim yeniresim As Bitmap = New Bitmap(bmp, ebatlar) bmp.Dispose() 'eskisini silip boyutlanan resimleri atar System.IO.File.Delete("" + Server.MapPath("~/imagesfirmarehber/") + "" + dosyaad) 'İlk yüklediğimiz resmin boyutlarını değiştirdiği için ilk yüklediğimiz resmi siliyor. yeniresim.Save(Server.MapPath("~/imagesfirmarehber/" + dosyaad), ImageFormat.Jpeg) yeniresim.Dispose() End If '------------------------------------------------------------------------------------------------------------------------ resim1.Text = dosyaad Label29.Text = FileUpload1.FileName + " resim yüklendi" Image1.ImageUrl = "~/imagesfirmarehber/" + resim1.Text Else Label29.Text = "Resim boyutu 2mb den büyük.Yüklenemedi" End If Else Label29.Text = FileUpload1.FileName + " resim yüklenemedi !!!" End If End If '2.resim resmin boyutlandırmasını yaparak gönderir SAYI = Randomizer(1000, 9999) Label30.Text = "" If FileUpload2.FileName <> "" Then If FileUpload2.HasFile Then 'dosya var ise If FileUpload2.PostedFile.ContentLength < 2000000 Then '2 mbit ten büyük dosya yüklenemez dosyaad = SAYI.ToString + "_" + FileUpload2.FileName If resim2.Text <> "" Then System.IO.File.Delete("" + Server.MapPath("~/imagesfirmarehber/") + "" + resim2.Text) 'daha önceki resmi silip değişen resmi atar FileUpload2.SaveAs(Server.MapPath("~/imagesfirmarehber/") + dosyaad) 'fotoyu server a attık '------------------------------yüklenmek istenen resmin boyutunu ayarlar------------------------------------------------- bmp = New Bitmap(Server.MapPath("~/imagesfirmarehber/" + dosyaad)) 'Kayıt ettğimiz fotoyu çağırıp üzerinde işlem yapıyoruz 'resmi en/boy aranında orantılı küçültür ------------------------------------------ Dim genislik As Integer = 800 'resmin genişliği max 800 yüksekliği max 700 olsun istiyoruz Dim yukseklik As Integer = 700 Dim ebatlar As New Size(bmp.Width, bmp.Height) If bmp.Width > genislik OrElse bmp.Height > yukseklik Then 'eğer istenilen ebatlardan büyükse boyutlandırma yapar 'resmin genişlik ve yükseklik oranını alıyoruz. Dim oran As Double = (CDbl(bmp.Width) / CDbl(bmp.Height)) If bmp.Width > genislik Then ebatlar.Width = genislik ebatlar.Height = CInt(CDbl(genislik) / oran) End If If ebatlar.Height > yukseklik Then ebatlar.Height = yukseklik ebatlar.Width = CInt(CDbl(yukseklik) * oran) End If Dim yeniresim As Bitmap = New Bitmap(bmp, ebatlar) bmp.Dispose() 'eskisini silip boyutlanan resimleri atar System.IO.File.Delete("" + Server.MapPath("~/imagesfirmarehber/") + "" + dosyaad) 'İlk yüklediğimiz resmin boyutlarını değiştirdiği için ilk yüklediğimiz resmi siliyor. yeniresim.Save(Server.MapPath("~/imagesfirmarehber/" + dosyaad), ImageFormat.Jpeg) yeniresim.Dispose() End If '------------------------------------------------------------------------------------------------------------------------ resim2.Text = dosyaad Label30.Text = FileUpload2.FileName + " resim yüklendi" Image2.ImageUrl = "~/imagesfirmarehber/" + resim2.Text Else Label30.Text = "Resim boyutu 2mb den büyük.Yüklenemedi" End If Else Label30.Text = FileUpload2.FileName + " resim yuklenemedi !!!" End If End If '----------------------------------------------------------------------------------------------------------------------------------------------------- conn.Open() COMM = conn.CreateCommand() sql1 = "UPDATE FIRMAREHBERI SET KATEGORI = '" & e_kategori.SelectedValue & "', UNVAN = '" & e_unvan.Text.Replace("'", Chr(180)) & "', YETKILI = '" & e_yetkili.Text.Replace("'", Chr(180)) & "', ADRES = '" & e_adres.Text.Replace("'", Chr(180)) & "', TELEFON = '" & e_tel.Text & "', EMAIL = '" & e_eposta.Text & "', WEBADRES = '" & e_web.Text & "', FIRMABILGI = '" & e_bilgi.Content.Replace("'", Chr(180)) & "', KONUM = '" & e_harita.Text & "', RESIM1 = '" & resim1.Text & "' , RESIM2 = '" & resim2.Text & "' WHERE id = '" & e_firmaid.Value & "'" COMM.CommandText = sql1 COMM.ExecuteNonQuery() conn.Close() mesaj2.Text = "Bilgiler güncellendi" mesaj2.Visible = "true" Exit Sub hata_kayit: mesaj1.Text = "Kayıt işlemi sırasında bir hata oluştu, bilgi kaydedilemedi. Lütfen girişinizi kontrol ediniz!!!" mesaj1.Visible = "true" End Sub Private Sub sil_Click(sender As Object, e As EventArgs) Handles sil.Click On Error GoTo hata_kayitsil Dim conn As New SqlConnection(ConnectionStrings("ConnectionString").ToString) Dim COMM As New SqlCommand Dim sql1 As String 'önce kayıt için içeride yüklü olan resimleri siler-------------------- If resim1.Text <> "" Then System.IO.File.Delete("" + Server.MapPath("~/imagesfirmarehber/") + "" + resim1.Text) If resim2.Text <> "" Then System.IO.File.Delete("" + Server.MapPath("~/imagesfirmarehber/") + "" + resim2.Text) 'kaydı siler conn.Open() sql1 = "DELETE FROM FIRMAREHBERI WHERE id ='" & e_firmaid.Value & "'" COMM = conn.CreateCommand() COMM.CommandText = sql1 COMM.ExecuteNonQuery() conn.Close() Response.Redirect("firma-rehberi.aspx") hata_kayitsil: mesaj1.Text = "Silme işlemi sırasında bir hata oluştu!!!" mesaj1.Visible = "true" End Sub Private Function Randomizer(ByVal iStart As Integer, ByVal iEnd As Integer) As Integer Dim iRandomValue As Integer Randomize() iRandomValue = iStart + (Rnd() * (iEnd - iStart)) Return iRandomValue End Function End Class