using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;
using System.Configuration;
using System.IO;

namespace norke.admin
{
	/// <summary>
	/// 的摘要说明。
	/// </summary>
	public partial class otherLogo : System.Web.UI.Page
	{
    
		protected void Page_Load(object sender, System.EventArgs e)
		{
            //权限检查
            if( Session["adminName"]==null || Session["adminName"].ToString() == String.Empty )
            {
                Response.Write("<font color=#ff0000 style='FONT-SIZE: 12px'>对不起,您没足够权限访问此页!!</font><br>");
                Response.Write("<a href=Default.aspx target=_top style='FONT-SIZE: 12px'>重新登陆</a><br>");
                Response.End();
                return;
            }
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    

        }
		#endregion

        protected void btnOK_Click(object sender, System.EventArgs e)
        {
            if(uploadFile.PostedFile.FileName.Trim() != String.Empty && (Path.GetExtension(uploadFile.PostedFile.FileName)!=".gif" && Path.GetExtension(uploadFile.PostedFile.FileName)!=".jpg"))
            {
                Response.Write("<Script>alert('上传的图片格式必须为.gif或.jpg!!')</Script>");
                return;
            }

            if ( uploadFile.PostedFile.FileName.Trim() != String.Empty )
            {
                //----------- update图片
                Stream imagedatastream;
                SqlConnection myConn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
                imagedatastream = Request.Files["uploadFile"].InputStream ;
                int imagedatalen = Request.Files["uploadFile"].ContentLength ;
                string imagedatatype = Request.Files["uploadFile"].ContentType ;

                byte[] image = new byte[imagedatalen];
                imagedatastream.Read(image,0,imagedatalen);

                String Psql="update [append] set [image]=@imgdata where [id]='1'";

                SqlCommand Pcommand=new SqlCommand(Psql,myConn);

                SqlParameter imgdata = new SqlParameter("@imgdata",SqlDbType.Image);
                imgdata.Value=image;
                Pcommand.Parameters.Add (imgdata);

                myConn.Open();
                Pcommand.ExecuteReader();
                myConn.Close();
                //-----------
                
                Response.Write("<script>");
                Response.Write("alert('修改添加!!!');");
                Response.Write("</script>");
            }

            
        }
	}
}
