using System;
using System.Collections.Generic;

namespace Stat.web.Manerger
{
    /// <summary>
    /// 
    /// </summary>
    public partial class MCompany : System.Web.UI.Page
    {
        Stat.Cache.IRemoveCache removeCache = Stat.Cache.CacheFatory.CreateRemoveCache();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                editBox(1);
            }
        }
        /// <summary>
        /// 添加/修改
        /// </summary>
        /// <param name="id"></param>
        private void editBox(int id)
        {
            this.pnWebList.Visible = false;
            this.pnEditWeb.Visible = true;
            this.hdfId.Value = id.ToString();
            //if (id > 0)
            //{
            IList<Stat.Model.Company> list = Stat.BLL.Company.Get();
            if (list.Count > 0)
            {
                this.txtGSJJ.Value = list[0].About.ToString();
                this.txtCCJS.Value = list[0].Product;
                this.txtRCZP.Value = list[0].Advertise;
                this.txtLXWM.Value = list[0].Contacts;
            }
            //}
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnEditSave_Click(object sender, EventArgs e)
        {
            Stat.Model.Company model = new Stat.Model.Company();

            model.ID = 1;
            model.About = this.txtGSJJ.Value;
            model.Product = this.txtCCJS.Value;
            model.Advertise = this.txtRCZP.Value;
            model.Contacts = this.txtLXWM.Value;
            model.IsPass = 1;
            model.IsTop = 1;

            removeCache.RemoveCompanyCache();
            if (model.ID > 0)
            {
                if (Stat.BLL.Company.Update(model))
                    Plugin.Common.Alert("修改成功！", "?");
                else
                    Plugin.Common.Alert("修改失败！");
            }
            else
            {
                if (Stat.BLL.Company.Insert(model))
                    Plugin.Common.Alert("添加成功！", "?");
                else
                    Plugin.Common.Alert("添加失败！");
            }
        }
    }
}
