using System; using System.Data; using System.Data.Sql; using System.Data.SqlClient; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Drawing; using System.IO; /// /// Summary description for Class1 /// public class Tooteabi { SqlConnection cn; public Tooteabi() { cn = new SqlConnection(ConfigurationManager.ConnectionStrings["yhendus1"].ConnectionString); cn.Open(); } public void LisaToode(String nimetus, byte[] pilt) { SqlCommand cm=new SqlCommand("INSERT INTO tooted(nimetus, pilt) "+ "VALUES(@nimetus, @pilt)", cn); cm.Parameters.AddWithValue("nimetus", nimetus); cm.Parameters.AddWithValue("pilt", pilt); cm.ExecuteNonQuery(); } public byte[] KysiPilt(int id) { SqlCommand cm = new SqlCommand("SELECT pilt FROM tooted WHERE id=@id", cn); cm.Parameters.AddWithValue("id", id); byte[] pilt = (byte[])cm.ExecuteScalar(); return pilt; /* SqlDataReader r=cm.ExecuteReader(); if (r.Read()) { byte[] pilt = (byte[])r["pilt"]; return pilt; } return null;*/ } public byte[] KysiPisiPilt(int id) { byte[] pilt = KysiPilt(id); //System.Drawing.Image imobj = new System.Drawing.Bitmap(pilt); System.Drawing.Image imobj = Bitmap.FromStream(new MemoryStream(pilt)); int laius = imobj.Width * 100 / imobj.Height; System.IO.MemoryStream malu = new System.IO.MemoryStream(); imobj.GetThumbnailImage(laius, 100, null, new IntPtr()).Save(malu, ImageFormat.Gif); return malu.GetBuffer(); } public int KysiToodeteArv() { return 5; } }