using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
namespace FineUIPro.Web.HSSE.InformationProject
{
    public partial class ConstructionStandardIdentifyFileEdit : PageBase
    {
        #region 定义变量
        /// 
        /// 主键
        /// 
        public string ConstructionStandardIdentifyFileId
        {
            get
            {
                return (string)ViewState["ConstructionStandardIdentifyFileId"];
            }
            set
            {
                ViewState["ConstructionStandardIdentifyFileId"] = value;
            }
        }
        /// 
        /// 主键
        /// 
        public string ProjectId
        {
            get
            {
                return (string)ViewState["ProjectId"];
            }
            set
            {
                ViewState["ProjectId"] = value;
            }
        }
        #endregion
        #region 加载页面
        /// 
        /// 加载页面
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.btnClose.OnClientClick = ActiveWindow.GetHidePostBackReference();
                this.ProjectId = this.CurrUser.LoginProjectId;
                this.ConstructionStandardIdentifyFileId = Request.Params["ConstructionStandardIdentifyFileId"];
                var model=BLL.InformationProject_ConstructionStandardIdentifyFileService.GetInformationProject_ConstructionStandardIdentifyFileById(this.ConstructionStandardIdentifyFileId);
                if (model != null) 
                {
                    txtCode.Text=model.Code;
                    txtFileName.Text=model.FileName;
                    txtVersionNumber.Text = model.VersionNumber;
                    txtCreateUser.Text = UserService.GetUserNameByUserId(model.Creater);
                    txtRemark.Text = model.Remark;
                }
                else
                {
                    this.txtCode.Text = BLL.CodeRecordsService.ReturnCodeByMenuIdProjectId(BLL.Const.ConstructionStandardIdentifyFileMenuId, this.ProjectId, this.CurrUser.UnitId);
                    txtCreateUser.Text = UserService.GetUserNameByUserId(this.CurrUser.UserId);
                }
            }
        }
        #endregion
 
 
        #region 保存按钮
        /// 
        /// 保存按钮
        /// 
        /// 
        /// 
        protected void btnSave_Click(object sender, EventArgs e)
        {
            this.SaveData();
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        #endregion
        #region 保存方法
        /// 
        /// 保存数据
        /// 
        /// 
        private void SaveData()
        {
             var model =new Model.InformationProject_ConstructionStandardIdentifyFile ();
             model.Code = txtCode.Text;
             model.FileName = txtFileName.Text;
             model.VersionNumber = txtVersionNumber.Text;
             model.Remark = txtRemark.Text;
             model.Creater=this.CurrUser.UserId ;
             model.CreateDate = DateTime.Now;
             model.ProjectId= ProjectId;
 
            if (string.IsNullOrEmpty( ConstructionStandardIdentifyFileId) )
            {
                ConstructionStandardIdentifyFileId = SQLHelper.GetNewID(typeof(Model.InformationProject_ConstructionStandardIdentifyFile));
                model.Id = ConstructionStandardIdentifyFileId ;
                BLL.InformationProject_ConstructionStandardIdentifyFileService.AddInformationProject_ConstructionStandardIdentifyFile(model);
            }
            else
            {
                model.Id = ConstructionStandardIdentifyFileId;
                BLL.InformationProject_ConstructionStandardIdentifyFileService.UpdateInformationProject_ConstructionStandardIdentifyFile (model);               
            }
        }
        #endregion
        #region 关闭弹出窗
        /// 
        /// 关闭弹出窗
        /// 
        /// 
        /// 
        protected void Window1_Close(object sender, EventArgs e)
        {
         }
        #endregion
        #region 附件上传
        /// 
        /// 上传附件
        /// 
        /// 
        /// 
        protected void btnAttachUrl_Click(object sender, EventArgs e)
        { 
            if (string.IsNullOrEmpty(this.ConstructionStandardIdentifyFileId))
            {
                this.SaveData();
            }
            PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/ConstructionStandardIdentifyFile&menuId={1}", this.ConstructionStandardIdentifyFileId, BLL.Const.ConstructionStandardIdentifyFileMenuId)));
        }
        #endregion
        ///// 
        /////  选择培训教材类型
        ///// 
        ///// 
        ///// 
        //protected void btnTrainingType_Click(object sender, EventArgs e)
        //{
        //    if (string.IsNullOrEmpty(this.ConstructionStandardIdentifyFileId))
        //    {
        //        this.SaveData(BLL.Const.BtnSave);
        //    }
        //    PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ShowTrainingType.aspx?ConstructionStandardIdentifyFileId={0}&TrainTypeId={1}", this.ConstructionStandardIdentifyFileId, this.drpTrainType.SelectedValue, "编辑 - ")));
        //}
    }
}