using BLL;
using System;
using System.Linq;
namespace FineUIPro.Web.HJGL.PersonManage
{
    public partial class PersonManageView : PageBase
    {
        #region 加载
        /// 
        /// 加载页面
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
           
                this.cbWeldMethod.DataTextField = "WeldingMethodCode";
                this.cbWeldMethod.DataValueField = "WeldingMethodId";
                this.cbWeldMethod.DataSource = BLL.WeldMethodItemService.GetWeldMethodList();
                this.cbWeldMethod.DataBind();
                this.cbSteType.DataTextField = "Text";
                this.cbSteType.DataValueField = "Value";
                this.cbSteType.DataSource = BLL.DropListService.HJGL_GetSteTypeList();
                this.cbSteType.DataBind();
                string welderId = Request.Params["welderId"];
                if (!string.IsNullOrEmpty(welderId))
                {
                    this.hdWelderId.Text = welderId;
                    Model.BS_Welder welder = BLL.WelderService.GetWelderById(this.hdWelderId.Text);
                    if (welder != null)
                    {
                        this.drpUnitId.Text = UnitService.GetUnitNameByUnitId(welder.WED_Unit);
                        this.drpTeamGroupId.Text = TeamGroupService.GetTeamGroupNameByTeamGroupId(welder.TeamGroupId);
                        if (!string.IsNullOrEmpty(welder.AttachUrl))
                        {
                            imgPhoto.ImageUrl = "~/" + welder.AttachUrl;
                        }
                        this.txtWED_Name.Text = welder.WED_Name;
                        this.txtWED_Code.Text = welder.WED_Code;
                        this.txtBirthday.Text = welder.WED_Birthday.HasValue ? string.Format("{0:yyyy-MM-dd}", welder.WED_Birthday) : "";
                        if (!string.IsNullOrEmpty(welder.WED_TYPE))
                        {
                            this.rbtype.SelectedValue = welder.WED_TYPE;
                        }
                        if (!string.IsNullOrEmpty(welder.WED_Sex))
                        {
                            this.rblSex.SelectedValue = welder.WED_Sex.Trim();
                        }
                        this.txtWorkCode.Text = welder.WED_WorkCode;
                        this.txtLimitDate.Text = welder.LimitDate.HasValue ? string.Format("{0:yyyy-MM-dd}", welder.LimitDate) : "";
                        this.txtClass.Text = welder.WED_Class;
                        if (welder.WED_IfOnGuard.HasValue)
                        {
                            if (welder.WED_IfOnGuard.Value == true)
                            {
                                this.cbIfOnGuard.Checked = true;
                            }
                            else
                            {
                                this.cbIfOnGuard.Checked = false;
                            }
                        }
                        this.txtIdentityCard.Text = welder.IdentityCard;
                        if (!string.IsNullOrEmpty(welder.WED_Remark))
                            this.txtRemak.Text = welder.WED_Remark;
                        if (!string.IsNullOrEmpty(welder.SE_EquipmentID))
                            this.txtSE_EquipmentID.Text = welder.SE_EquipmentID;
                        var items = from x in Funs.DB.BS_WeldMethodItem where x.WED_ID == welder.WED_ID select x.WME_ID;
                        this.dpWeldMethod.Values = items.ToArray();
                        if (!string.IsNullOrEmpty(welder.JOT_Sch))
                            this.dpJOTSch.SelectedValue = welder.JOT_Sch;
                        if (!string.IsNullOrEmpty(welder.Steels))
                        {
                            this.drpSteType.Values = welder.Steels.Split(',');
                        }
                    }
                }
            }
        }
        #endregion
        #region 附件上传
        /// 
        /// 上传附件
        /// 
        /// 
        /// 
        protected void btnAttachUrl_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.hdWelderId.Text))
            {
                this.hdWelderId.Text = SQLHelper.GetNewID(typeof(Model.BS_Welder));
            }
            PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/HJGL/PersonManage/&menuId={1}&type=-1", this.hdWelderId.Text, BLL.Const.HJGL_WelderManageMenuId)));
        }
        #endregion
    }
}