using BLL;
using System;
namespace FineUIPro.Web.TestRun.DriverGoods
{
    public partial class GoodsBuyEdit : PageBase
    {
        #region 加载
        /// 
        /// 页面加载
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BLL.UserService.InitUserDropDownList(this.drpCompileMan, this.CurrUser.LoginProjectId, true);
                string id = Request.Params["id"];
                if (!string.IsNullOrEmpty(id))
                {
                    Model.DriverGoods_GoodsBuy data = BLL.GoodsBuyService.GetGoodsBuyById(id);
                    if (data != null)
                    {
                        this.hdId.Text = id;
                        this.txtCode.Text = data.Code;
                        this.txtBuyName.Text = data.BuyName;
                        this.txtBuyCode.Text = data.BuyCode;
                        if (!string.IsNullOrEmpty(data.CompileMan))
                        {
                            this.drpCompileMan.SelectedValue = data.CompileMan;
                        }
                        this.txtApprovalDate.Text = data.ApprovalDate.HasValue ? string.Format("{0:yyyy-MM-dd}", data.ApprovalDate) : "";
                        this.txtSubmitDate.Text = data.SubmitDate.HasValue ? string.Format("{0:yyyy-MM-dd}", data.SubmitDate) : "";
                        this.txtGetGoodsDate.Text = data.GetGoodsDate.HasValue ? string.Format("{0:yyyy-MM-dd}", data.GetGoodsDate) : "";
                        this.txtRemark.Text = data.Remark;
                    }
                }
            }
        }
        #endregion
        #region 附件上传
        /// 
        /// 附件上传
        /// 
        /// 
        /// 
        protected void btnAttach_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.hdId.Text))   //新增记录
            {
                this.hdId.Text = SQLHelper.GetNewID(typeof(Model.DriverGoods_GoodsBuy));
            }
            PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/TestRun/DriverGoods/GoodsBuy&menuId={1}", this.hdId.Text, BLL.Const.GoodsBuyMenuId)));
        }
        #endregion
        #region 保存
        /// 
        /// 保存按钮
        /// 
        /// 
        /// 
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string id = Request.Params["id"];
            Model.DriverGoods_GoodsBuy newData = new Model.DriverGoods_GoodsBuy();
            newData.Code = this.txtCode.Text.Trim();
            newData.BuyName = this.txtBuyName.Text.Trim();
            newData.BuyCode = this.txtBuyCode.Text.Trim();
            if (this.drpCompileMan.SelectedValue != BLL.Const._Null)
            {
                newData.CompileMan = this.drpCompileMan.SelectedValue;
            }
            newData.ApprovalDate = Funs.GetNewDateTime(this.txtApprovalDate.Text.Trim());
            newData.SubmitDate = Funs.GetNewDateTime(this.txtSubmitDate.Text.Trim());
            newData.GetGoodsDate = Funs.GetNewDateTime(this.txtGetGoodsDate.Text.Trim());
            newData.Remark = this.txtRemark.Text.Trim();
            newData.ProjectId = this.CurrUser.LoginProjectId;
            if (!string.IsNullOrEmpty(id))
            {
                newData.GoodsBuyId = id;
                BLL.GoodsBuyService.UpdateGoodsBuy(newData);
            }
            else
            {
                if (!string.IsNullOrEmpty(this.hdId.Text))
                {
                    newData.GoodsBuyId = this.hdId.Text.Trim();
                }
                else
                {
                    newData.GoodsBuyId = SQLHelper.GetNewID(typeof(Model.DriverGoods_GoodsBuy));
                    this.hdId.Text = newData.GoodsBuyId;
                }
                BLL.GoodsBuyService.AddGoodsBuy(newData);
            }
            ShowNotify("保存成功!", MessageBoxIcon.Success);
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        #endregion
    }
}