?? bookmanager.cs
字號(hào):
// }
// }
// return book;
// }
// }
//}
//增加類別
public static void AddBookClass(string name, string remark,byte [] orginal)
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
{
using (SqlCommand command = new SqlCommand("AddCategory", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@name", name));
command.Parameters.Add(new SqlParameter("@remark", remark));
command .Parameters .Add (new SqlParameter("@image",ResizeImageFile(orginal,100)));
connection.Open();
command.ExecuteNonQuery();
}
}
}
//增加圖書
public static void AddBook(string BookName,int CategoryID,byte[]orginal,string ISDN,string BookTips)
{
MembershipUser user=Membership.GetUser ();
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
{
using (SqlCommand command = new SqlCommand("AddBook", connection))
{
command.CommandType = CommandType.StoredProcedure;
command .Parameters .Add (new SqlParameter ("@BookName",BookName ));
command.Parameters.Add(new SqlParameter("@CategoryID", CategoryID));
command.Parameters.Add(new SqlParameter("@BookImageS", ResizeImageFile(orginal, 100)));
command.Parameters.Add(new SqlParameter("@BookImageL", ResizeImageFile(orginal, 250)));
command.Parameters.Add(new SqlParameter("@ISBN", ISDN ));
command .Parameters .Add (new SqlParameter ("@UserID",user .UserName .ToString ()));
command.Parameters.Add(new SqlParameter("@BookTips", BookTips));
command.Parameters.Add(new SqlParameter("@AddDateTime", DateTime.Now));
connection.Open();
command.ExecuteNonQuery();
}
}
}
//修改圖書
public static void EditBook(int BookID,string BookName, int CategoryID, byte[] orginal, string ISDN, string BookTips)
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
{
using (SqlCommand command = new SqlCommand("EditBook", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@BookID", BookID));
command.Parameters.Add(new SqlParameter("@BookName", BookName));
command.Parameters.Add(new SqlParameter("@CategoryID", CategoryID));
command.Parameters.Add(new SqlParameter("@BookImageS", ResizeImageFile(orginal, 100)));
command.Parameters.Add(new SqlParameter("@BookImageL", ResizeImageFile(orginal, 250)));
command.Parameters.Add(new SqlParameter("@ISBN", ISDN));
command.Parameters.Add(new SqlParameter("@BookTips", BookTips));
connection.Open();
command.ExecuteNonQuery();
}
}
}
//移除類別
public static void RemoveCategory(int CategoryID)
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
{
using (SqlCommand command = new SqlCommand("RemoveCategory", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@categoryID", CategoryID));
connection.Open();
command.ExecuteNonQuery();
}
}
}
//移除圖書
public static void RemoveBook(int BookID)
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
{
using (SqlCommand command = new SqlCommand("RemoveBook", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@BookID", BookID));
connection.Open();
command.ExecuteNonQuery();
}
}
}
//獲得圖書封面圖像
public static Stream GetBookImage(int bookid, ImageSize size)
{
using ( SqlConnection connection = new SqlConnection (ConfigurationManager .ConnectionStrings ["BookShow"].ConnectionString ))
{
using (SqlCommand command = new SqlCommand ("GetBookImage",connection ))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@BookID", bookid));
command .Parameters .Add (new SqlParameter ("@size",(int)size));
connection.Open();
object result = command.ExecuteScalar();
try
{
return new MemoryStream((byte[])result);
}
catch
{
return null;
}
}
}
}
//獲得類別圖片
public static Stream GetClassImage(int categoryid, ImageSize size)
{
using (SqlConnection connection = new SqlConnection (ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString ))
{
using(SqlCommand command = new SqlCommand ("GetClassImage",connection ))
{
command .CommandType=CommandType.StoredProcedure;
command .Parameters .Add (new SqlParameter ("@categoryid",categoryid ));
connection .Open ();
object result=command .ExecuteScalar();
try
{
return new MemoryStream ((byte[])result );
}
catch
{return null;}
}
}
}
//當(dāng)無圖像時(shí),獲得無圖像封面
public static Stream GetImage(ImageSize size)
{
string path =HttpContext.Current .Server.MapPath("~/Images/");
switch (size)
{
case ImageSize .Small :
path += "placeholder-100.jpg";
break;
case ImageSize .Large:
path += "placeholder-600.jpg";
break;
default :
path += "placeholder-600.jpg";
break;
}
return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
}
//計(jì)算維度, 當(dāng)高比寬高時(shí),按高為基礎(chǔ)計(jì)算比例,當(dāng)寬更大時(shí),剛以寬為基礎(chǔ)
private static Size CalculateDimensions(Size oldSize, int targetSize)
{
Size newSize = new Size();
if (oldSize.Height > oldSize.Width)
{
newSize.Width = (int)(oldSize.Width * ((float)targetSize / (float)oldSize.Height));
newSize.Height = targetSize;
}
else
{
newSize.Width = targetSize;
newSize.Height = (int)(oldSize.Height * ((float)targetSize / (float)oldSize.Width));
}
return newSize;
}
//比例緞縮放圖像。
private static byte[] ResizeImageFile(byte[] imageFile, int targetSize)
{
using (System.Drawing.Image oldImage = System.Drawing.Image.FromStream(new MemoryStream(imageFile)))
{
Size newSize = CalculateDimensions(oldImage.Size, targetSize);
using (Bitmap newImage = new Bitmap(newSize.Width ,newSize.Height ,System .Drawing .Imaging.PixelFormat.Format24bppRgb))
{
using (Graphics canvas = Graphics.FromImage(newImage))
{
canvas.SmoothingMode = SmoothingMode.AntiAlias;
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
canvas.PixelOffsetMode = PixelOffsetMode.HighQuality;
canvas .DrawImage(oldImage ,new Rectangle(new Point (0,0),newSize ));
MemoryStream m = new MemoryStream ();
newImage.Save (m,System .Drawing .Imaging .ImageFormat.Jpeg );
return m.GetBuffer ();
}
}
}
}
//修改類別
public static void EidtCategory(string CategoryName, string CategoryRemark, byte[] orginal, int CategoryID)
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
{
using (SqlCommand command = new SqlCommand ("EidtCategory",connection ))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters .Add (new SqlParameter("@CategoryID",CategoryID));
command.Parameters.Add(new SqlParameter("@CategoryName", CategoryName));
command.Parameters.Add(new SqlParameter("@CategoryRemark", CategoryRemark));
command.Parameters.Add(new SqlParameter("@CategoryImage",ResizeImageFile (orginal ,100)));
connection.Open();
command.ExecuteNonQuery();
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -