Your IP : 216.73.216.57
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using ImageResizer;
public partial class admin_Default2 : System.Web.UI.Page
{
private string smallimageName;
public static int altkatid, katid;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.Cookies["UserID"] != null)
{
Genel.Duyuruid = 0;
using (OleDbConnection vt = new baglanti().baglan())
{
vt.Open();
OleDbCommand cmd = new OleDbCommand("SELECT D.*,DK.adi AS DuyuruAdi FROM DuyuruResimler D INNER JOIN Duyurular DK ON DK.id=D.DuyId ORDER BY D.id DESC", vt);
OleDbDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
rptDuyuruResimListesi.DataSource = dt;
rptDuyuruResimListesi.DataBind();
vt.Close();
}
using (OleDbConnection vt = new baglanti().baglan())
{
vt.Open();
OleDbCommand cmd = new OleDbCommand("SELECT id,adi FROM Duyurular", vt);
OleDbDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
Genel.FillDropDownList(ddlDuyuruListesi, dt, "id", "adi", "Lütfen Resim Eklemek İstediğiniz Duyuruyu Seçiniz!");
vt.Close();
}
Genel.SoruButon1(btnEvet,btnHayir,btnTumunuSil,false,false,true);
if (Request.QueryString["altkatid"] != null && Request.QueryString["altkatid"] != null)
{
altkatid = Convert.ToInt32(Request.QueryString["altkatid"].ToString());
katid = Convert.ToInt32(Request.QueryString["katid"].ToString());
}
}
else
{
Response.Redirect("Login.aspx");
}
}
}
[WebMethod]
public static bool Sil(int id)
{
string resimTemp;
using (OleDbConnection vt = new baglanti().baglan())
{
vt.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM DuyuruResimler WHERE id=" + id, vt);
OleDbDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
if (dt.Rows.Count > 0)
{
resimTemp = "../upload/duyurular/" + dt.Rows[0]["resim"].ToString();
if (dt.Rows[0]["resim"].ToString() != "noimage.jpg")
{
if (File.Exists(HttpContext.Current.Server.MapPath(resimTemp)))
{
File.Delete(HttpContext.Current.Server.MapPath(resimTemp));
}
}
}
}
using (OleDbConnection vt = new baglanti().baglan())
{
vt.Open();
OleDbCommand cmd = new OleDbCommand("DELETE FROM DuyuruResimler WHERE id=" + id, vt);
cmd.ExecuteNonQuery();
vt.Close();
}
return true;
}
//public string imageSave(string folder, int width, int height)
//{
// if (fuMobilIlTarihiResim.HasFile)
// {
// string[] imageFormat = new[] { ".jpg", ".png", ".gif" };
// string extension = Path.GetExtension(fuMobilIlTarihiResim.PostedFile.FileName).ToLower();
// foreach (var s in imageFormat)
// {
// if (s == extension)
// {
// smallimageName = "_mobilduyuru_" +
// DateTime.Now.ToString("MMddyyhhmmss") + extension;
// string tempPath = Server.MapPath("../upload/_Temp/" + smallimageName);
// string imagesPath = Server.MapPath("../upload/" + folder + "/" + smallimageName);
// fuMobilIlTarihiResim.SaveAs(tempPath);
// int LargeSize = width; //resmin küçültüleceği boyut
// var image = new Bitmap(tempPath);
// using (Bitmap newImage = image)
// {
// //double height = newImage.Height;
// //double width = newImage.Width;
// //double ratio = 0;
// if (width >= LargeSize)
// {
// /* 700 boyutundaki resim oluşturma alanı başlangıç */
// //ratio = width / height;
// width = width;
// height = height; // ratio;
// var newValues = new Size(Convert.ToInt32(width), Convert.ToInt32(height));
// var lastImage = new Bitmap(newImage, newValues);
// lastImage.Save(imagesPath);
// /* 700 boyutundaki resim oluşturma alanı bitiş */
// }
// else
// {
// if (!File.Exists(imagesPath))
// {
// fuMobilIlTarihiResim.SaveAs(imagesPath);
// fuMobilIlTarihiResim.Dispose();
// }
// }
// if (File.Exists(tempPath))
// {
// image.Dispose();
// File.Delete(tempPath);
// }
// }
// }
// }
// }
// return smallimageName;
//}
private string imageSave(FileUpload fileupload, string dosya, int genislik, int yukseklik)
{
if (fileupload.HasFile)
{
string extension = Path.GetExtension(fileupload.PostedFile.FileName).ToLower();
//Resmin adını bir değişkene atatım
string resimadi = "Resim" + DateTime.Now.ToString("MMddyyhhmmss") + ".jpg";
//Resmimi kayıt edeceğim klasörümü seçtim.
string uploadFolder = Server.MapPath("../upload/Temp/");
//Resmimin boyutlandırmamış halini kayıt ettim.
fileupload.SaveAs(uploadFolder + resimadi);
//Daha sonra eklentimin metodlarını kullanarak resmimin boyutlandırma işlemini yaptım.
ResizeSettings resizeCropSettings1 = new ResizeSettings("width=" + genislik + "&height=" + yukseklik + "&mode=pad");
string fileName = Path.Combine(uploadFolder, resimadi);
fileName = ImageBuilder.Current.Build(uploadFolder + resimadi, string.Concat(uploadFolder, Path.GetFileNameWithoutExtension(fileName)), resizeCropSettings1, false, true);//ŞU SATIRDAN SONRA İKİNCİ UZANTI EKLİYO yani jpg.jpg yapıyo bunu nasıl engellerim
Bitmap imgOutput = new Bitmap(Server.MapPath("../upload/Temp/" + resimadi));// Büyük Boyutlu resmimizin Alındı Dosya Yeri dosyanın önceki boyutu : 560 kb
Graphics outputGraphics = Graphics.FromImage(imgOutput);
EncoderParameters myEncoderParameters = new EncoderParameters(3);
myEncoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L); // buradaki 45L yazan yer resmin kalitesine doğru orantılı olarak çalışıyor 100 yaparsanız en iyi şekilde resmi çıkarıyor ben boyuttan kısmak istediğim için 45 yaptım
myEncoderParameters.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.ScanMethod, (int)EncoderValue.ScanMethodInterlaced);
myEncoderParameters.Param[2] = new EncoderParameter(System.Drawing.Imaging.Encoder.RenderMethod, (int)EncoderValue.RenderProgressive);
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ici = null;
foreach (ImageCodecInfo codec in codecs)
{
if (codec.MimeType == "image/jpeg")
ici = codec;
}
imgOutput.Save(Server.MapPath("../upload/" + dosya + "/" + resimadi), ici, myEncoderParameters);//buraada ise resminizin nereye kaydedilmesini istiyorsanız onu seçiyorsunuz bu kod blogunu çalıştırdıktan sonra resimim kalitesi düşmüş olarak ( boyutu kb ) geri geldi ve sonraki halide 37 kb di
if (File.Exists(uploadFolder + resimadi))
{
outputGraphics.Dispose();
imgOutput.Dispose();
File.Delete(uploadFolder + resimadi);
}
smallimageName = resimadi;
}
return smallimageName;
}
protected void btnIlTarihiOnizleme_OnServerClick(object sender, EventArgs e)
{
Response.Redirect("DuyuruGaleriOnizleme.aspx");
}
protected void btnIlTarihiKaydet_OnServerClick(object sender, EventArgs e)
{
if (ddlDuyuruListesi.SelectedValue!="-1")
{
var newimage = imageSave(fuMobilIlTarihiResim, "duyurular", 980, 380);
if (newimage != null)
{
using (OleDbConnection vt = new baglanti().baglan())
{
vt.Open();
OleDbCommand cmd = new OleDbCommand("INSERT INTO DuyuruResimler (resim,DuyId) VALUES (@Resim,@DuyId)", vt);
cmd.Parameters.AddWithValue("@Resim", newimage);
cmd.Parameters.AddWithValue("@DuyId", ddlDuyuruListesi.SelectedValue);
cmd.ExecuteNonQuery();
vt.Close();
Response.Redirect("FotoGaleriMobilDuyuru.aspx?altkatid=" + altkatid + "&katid=" + katid + "");
}
}
}
}
protected void btnTumunuSil_OnClick(object sender, EventArgs e)
{
Genel.SoruButon1(btnEvet, btnHayir, btnTumunuSil, true, true, false);
}
protected void btnHayir_OnClick(object sender, EventArgs e)
{
Genel.SoruButon1(btnEvet, btnHayir, btnTumunuSil, false, false, true);
}
protected void btnEvet_OnClick(object sender, EventArgs e)
{
string resimTemp;
using (OleDbConnection vt = new baglanti().baglan())
{
vt.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM DuyuruResimler", vt);
OleDbDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
resimTemp = "../upload/duyurular/" + dt.Rows[i]["resim"].ToString();
if (dt.Rows[i]["resim"].ToString() != "noimage.jpg")
{
if (File.Exists(HttpContext.Current.Server.MapPath(resimTemp)))
{
File.Delete(HttpContext.Current.Server.MapPath(resimTemp));
}
}
}
}
}
using (OleDbConnection vt = new baglanti().baglan())
{
vt.Open();
OleDbCommand cmd = new OleDbCommand("DELETE FROM DuyuruResimler", vt);
cmd.ExecuteNonQuery();
vt.Close();
}
Response.Redirect("FotoGaleriMobilDuyuru.aspx?altkatid=" + altkatid + "&katid=" + katid + "");
}
}