using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
namespace FineUIPro.Web.Party
{
    public partial class FocusLearnEdit : PageBase
    {
        #region 加载
        /// 
        /// 页面加载
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string id = Request.Params["focusLearnId"];
                string year = DateTime.Now.Year.ToString();
                if (!string.IsNullOrEmpty(Request.Params["Year"]))
                {
                    year = Request.Params["Year"];
                }
                ConstValue.InitConstValueDropDownList(this.drpQuarter, ConstValue.Group_0011, true);
                if (!string.IsNullOrEmpty(id))
                {
                    Model.Party_FocusLearn focusLearn = BLL.FocusLearnService.GetFocusLearnById(id);
                    if (focusLearn != null)
                    {
                        this.hdId.Text = id;
                        if (focusLearn.Year != null)
                        {
                            this.txtYear.Text = focusLearn.Year.ToString();
                        }
                        if (focusLearn.Quarter != null)
                        {
                            this.drpQuarter.SelectedValue = focusLearn.Quarter.ToString();
                        }
                    }
                }
                else
                {
                    this.txtYear.Text = year;
                }
            }
        }
        #endregion
        #region 附件上传
        /// 
        /// 附件上传
        /// 
        /// 
        /// 
        protected void btnAttach_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.hdId.Text))   //新增记录
            {
                this.hdId.Text = SQLHelper.GetNewID(typeof(Model.Party_FocusLearn));
            }
            PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/Party/FocusLearn&menuId={1}", this.hdId.Text, BLL.Const.FocusLearnMenuId)));
        }
        protected void btnAttach2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.hdId.Text))   //新增记录
            {
                this.hdId.Text = SQLHelper.GetNewID(typeof(Model.Party_FocusLearn));
            }
            PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/Party/FocusLearn&menuId={1}", this.hdId.Text + "2", BLL.Const.FocusLearnMenuId)));
        }
        protected void btnAttach3_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.hdId.Text))   //新增记录
            {
                this.hdId.Text = SQLHelper.GetNewID(typeof(Model.Party_FocusLearn));
            }
            PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/Party/FocusLearn&menuId={1}", this.hdId.Text + "3", BLL.Const.FocusLearnMenuId)));
        }
        #endregion
        #region 保存
        /// 
        /// 保存按钮
        /// 
        /// 
        /// 
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (this.drpQuarter.SelectedValue == BLL.Const._Null)
            {
                Alert.ShowInTop("请选择季度", MessageBoxIcon.Warning);
                return;
            }
            string id = Request.Params["focusLearnId"];
            Model.Party_FocusLearn newFocusLearn = new Model.Party_FocusLearn();
            newFocusLearn.Year = Funs.GetNewIntOrZero(this.txtYear.Text.Trim());
            newFocusLearn.Quarter = Funs.GetNewInt(this.drpQuarter.SelectedValue);
            if (!string.IsNullOrEmpty(id))
            {
                newFocusLearn.FocusLearnId = id;
                BLL.FocusLearnService.UpdateFocusLearn(newFocusLearn);
            }
            else
            {
                if (!string.IsNullOrEmpty(this.hdId.Text))
                {
                    newFocusLearn.FocusLearnId = this.hdId.Text.Trim();
                }
                else
                {
                    newFocusLearn.FocusLearnId = SQLHelper.GetNewID(typeof(Model.Party_FocusLearn));
                    this.hdId.Text = newFocusLearn.FocusLearnId;
                }
                newFocusLearn.CompileMan = this.CurrUser.UserId;
                newFocusLearn.CompileDate = DateTime.Now;
                BLL.FocusLearnService.AddFocusLearn(newFocusLearn);
            }
            ShowNotify("保存成功!", MessageBoxIcon.Success);
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        #endregion
    }
}