using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Stat.web.Manerger
{
    /// <summary>
    /// 
    /// </summary>
    public partial class MStatLogo : System.Web.UI.Page
    {
        static Stat.Security.ISecurity security = Stat.Security.DataFatory.CreateSecurity();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="p"></param>
        /// <param name="fileUpload"></param>
        /// <param name="newfilename"></param>
        /// <returns></returns>
        protected string FileUpAndReturnGetNewFileName(Page p, FileUpload fileUpload, string newfilename)
        {//根据上传页面,上传控件,标记,返回上传后新图片的名称 


            if (fileUpload.HasFile)
            {
                string fileExt = System.IO.Path.GetExtension(fileUpload.FileName);
                if (fileExt.ToLower() == ".gif")
                {
                    try
                    {
                        fileUpload.SaveAs(p.Server.MapPath("../img/" + newfilename));
                    }
                    catch (Exception ex)
                    {
                        Response.Write("<script>alert('错误：" + ex.Message.ToString() + "');</script>");
                        return null;
                    }
                }
                else
                {
                    Response.Write("<script>alert('只能上传.gif图片!');</script>");
                    return null;
                }
            }
            else
            {
                Response.Write("<script>alert('请选择图片!');</script>");
                return null;
            }

            return newfilename;
        }

        /// <summary>
        /// 更新第一个
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn1_Click(object sender, EventArgs e)
        {
            string newfilename = "1.gif";
            string ss = FileUpAndReturnGetNewFileName(this.Page, this.fu1, newfilename);
            if (ss != null)
            {
                Plugin.Common.Alert("更新成功！", "?");
                return;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn2_Click(object sender, EventArgs e)
        {
            string newfilename = "2.gif";
            string ss = FileUpAndReturnGetNewFileName(this.Page, this.fu2, newfilename);
            if (ss != null)
            {
                Plugin.Common.Alert("更新成功！", "?");
                return;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn3_Click(object sender, EventArgs e)
        {
            string newfilename = "3.gif";
            string ss = FileUpAndReturnGetNewFileName(this.Page, this.fu3, newfilename);
            if (ss != null)
            {
                Plugin.Common.Alert("更新成功！", "?");
                return;
            }
        }
    }
}
