using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.Personal
{
    public partial class PersonMeetingEdit : PageBase
    {
        #region 定义项
        /// 
        /// 主键
        /// 
        public string MeetingId
        {
            get
            {
                return (string)ViewState["MeetingId"];
            }
            set
            {
                ViewState["MeetingId"] = value;
            }
        }
        #endregion
        /// 
        /// 
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
                UserService.InitUserDropDownList(this.drpAttendeeManIds, this.CurrUser.LoginProjectId, true);
                UserService.InitUserDropDownList(this.drpCompileMan, this.CurrUser.LoginProjectId, true);
                this.MeetingId = Request.Params["MeetingId"];
                if (!string.IsNullOrEmpty(this.MeetingId))
                {
                    var getMeet = BLL.Person_MeetingService.GetPerson_MeetingById(this.MeetingId);
                    if (getMeet != null)
                    {
                        this.txtMeetingTitle.Text = getMeet.MeetingTitle;
                        if (!string.IsNullOrEmpty(getMeet.AttendeeManIds))
                        {
                            this.drpAttendeeManIds.SelectedValueArray = getMeet.AttendeeManIds.Split(',');
                        }
                        this.txtMeetingDate.Text = string.Format("{0:yyyy-MM-dd HH:mm:ss}", getMeet.MeetingDate);
                        this.drpCompileMan.SelectedValue = getMeet.CompileManId;
                        this.txtConferenceLink.Text = getMeet.ConferenceLink;
                    }
                }else
                {
                    this.txtMeetingDate.Text = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);
                    this.drpCompileMan.SelectedValue = this.CurrUser.UserId;
                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Model.Person_Meeting newMeet = new Model.Person_Meeting()
            {              
                CompileManId = (this.drpCompileMan.SelectedValue ==Const._Null ? null : this.drpCompileMan.SelectedValue),
                MeetingDate = Funs.GetNewDateTime(this.txtMeetingDate.Text),
                MeetingTitle = this.txtMeetingTitle.Text.Trim(),
                ConferenceLink =this.txtConferenceLink.Text.Trim(),
            };
            if (this.drpAttendeeManIds.SelectedValue != BLL.Const._Null)
            {
                newMeet.AttendeeManIds = Funs.GetStringByArray(this.drpAttendeeManIds.SelectedValueArray);
            }
            if (!string.IsNullOrEmpty(this.MeetingId))
            {
                newMeet.MeetingId = this.MeetingId;
                BLL.Person_MeetingService.UpdatePerson_Meeting(newMeet);
            }
            else
            {
                newMeet.MeetingId = SQLHelper.GetNewID();
                BLL.Person_MeetingService.AddPerson_Meeting(newMeet);
            }
            ShowNotify("保存成功!", MessageBoxIcon.Success);
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        protected void drpAttendeeManIds_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.drpAttendeeManIds.SelectedValueArray = Funs.RemoveDropDownListNull(this.drpAttendeeManIds.SelectedValueArray);
        }
    }
}