using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Company_WebInfo :PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!this.Page.IsPostBack)
        {
            BindPage();
        }
    }
    #region 绑定页面信息
    /// <summary>
    /// 绑定页面信息
    /// </summary>
    public void BindPage()
    {
        DataSet ds = Operation.GetDataSet("SELECT CompanyLogo,webName,webDescribe FROM dbo.tabN_Company WHERE Cid=1");
        if (ds.Tables[0].Rows.Count > 0)
        {
            //txtCompanyName.Text = Convert.ToString(ds.Tables[0].Rows[0]["CompanyName"]);
            imgLogos.Src = Convert.ToString(ds.Tables[0].Rows[0]["CompanyLogo"]);//网站logo
            txtWebName.Text = Convert.ToString(ds.Tables[0].Rows[0]["webName"]);//网站名
            //txtWebDescribe.Text = Convert.ToString(ds.Tables[0].Rows[0]["webDescribe"]);
        }
    }
    #endregion

    //#region 绑定网站名和logo图片
    ///// <summary>
    ///// 绑定网站名和logo图片
    ///// </summary>
    //public void BindWebTitle()
    //{
    //    DataSet ds = Operation.GetDataSet("SELECT CompanyLogo,webName,webDescribe FROM dbo.tabN_Company WHERE Cid=1");
    //    if (ds.Tables[0].Rows.Count > 0)
    //    {
    //        h3Title.InnerHtml = Convert.ToString(ds.Tables[0].Rows[0]["webName"]);//网站名
    //        this.Page.Title = Convert.ToString(ds.Tables[0].Rows[0]["webName"]) + "-网站信息";//页面标题
    //        if (Convert.ToString(ds.Tables[0].Rows[0]["CompanyLogo"]) != "")
    //        {
    //            imgLogo.Src = Convert.ToString(ds.Tables[0].Rows[0]["CompanyLogo"]);//网站logo
    //        }
    //        else
    //        {
    //            imgLogo.Src = "~/Image/nopic.gif";//即默认图片
    //        }
    //    }
    //}
    //#endregion

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        string filename = fuImg.FileName;
        string virtualPath = "";
        if (filename != "")
        {
            virtualPath = "~/Image/" + filename;
            string truePath = Server.MapPath("~/Image") + "\\" + filename;
            fuImg.SaveAs(truePath);
        }
        else//上传控件值为空（即不修改图片时）
        {
            DataSet ds = Operation.GetDataSet("SELECT CompanyLogo FROM dbo.tabN_Company WHERE Cid=1");
            if (ds.Tables[0].Rows.Count > 0)
            {
                virtualPath = Convert.ToString(ds.Tables[0].Rows[0]["CompanyLogo"]);//数据库中logo路径
            }
        }
        try
        {
            Operation.Operations("UPDATE dbo.tabN_Company SET CompanyLogo='" + virtualPath + "',webName='" + txtWebName.Text.Trim() + "' WHERE Cid=1");
            BindPage();
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script language='javascript' defer>alert('修改成功！');window.location.href('../b2c/index.aspx')</script>");
        }
        catch
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script language='javascript' defer>alert('修改失败，请联系管理员！')</script>");
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script language='javascript' defer>window.location.href('../News/FirstPage.aspx')</script>");
    }
}
