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();
            }
        }
        /// <summary>
        /// 添加/修改
        /// </summary>
        private void editBox()
        {
            this.pnWebList.Visible = false;
            this.pnEditWeb.Visible = true;

            IList<Stat.Model.Company> list = Stat.BLL.Company.Get();
            if (list.Count > 0)
            {
                this.hdfId.Value = list[0].ID.ToString();
                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 = Convert.ToInt32("0" + this.hdfId.Value);
            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("添加失败！");
            }
        }
    }
}
