using System;
using System.Windows.Forms;
using QMAPP.Entity;
using QMAPP.FJC.Entity;
using QMAPP.FJC.Entity.Basic;
using QMAPP.FJC.Entity.Equipment;
using QMAPP.FJC.Entity.ODS;
using QMAPP.ServicesAgent;
using QMAPP.WinForm.Common;

namespace QMAPP.WinForm.Forms.ODS
{
    /// <summary>
    /// 模块编号:M11-3
    /// 作    用:设备停机维护
    /// 作    者:王庆男
    /// 编写日期:2015年06月01日
    ///</summary>
    public partial class MediaPlayerEditForm : Form
    {
        VideoInfo recorder = new VideoInfo();
        private int isUpdate = 0;

        /// <summary>
        /// 新建 t
        /// </summary>
        public MediaPlayerEditForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="pid"></param>
        public MediaPlayerEditForm(string pid)
        {
            recorder.PID = pid;
            isUpdate = 1;
            InitializeComponent();
        }

        /// <summary>
        /// 窗体加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form_Load(object sender, EventArgs e)
        {
            #region 绑定下拉列表
            BasicData basicData = new BasicData();
            //加载下拉列表
            this.comType.DataSource = basicData.GetVideoInfoList();
            this.comType.DisplayMember = "VideoType";
            this.comType.ValueMember = "VideoType";
            #endregion

            #region 编辑
            //判断是否为编辑加载编辑数据
            if (!string.IsNullOrEmpty(recorder.PID))
            {
                QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent();
                recorder = agent.InvokeServiceFunction<VideoInfo>("VideoInfoBLL_Get", recorder);

                txtName.Text = recorder.VideoName;
                txtUrl.Text = recorder.VideoUrl;
                comType.Text = recorder.VideoType;
            }
            #endregion
        }

        /// <summary>
        /// 窗体保存事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbSave_Click(object sender, EventArgs e)
        {

            #region 绑定保存信息
            recorder.VideoName = this.txtName.Text;
            recorder.VideoUrl = this.txtUrl.Text;
            recorder.VideoType = this.comType.Text;
            #endregion

            #region 保存
            QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent();

            DataResult<int> result = agent.InvokeServiceFunction<DataResult<int>>(string.IsNullOrEmpty(recorder.PID) ? "VideoInfoBLL_Insert" : "VideoInfoBLL_Update", recorder);
            //保存成功
            MessageBox.Show(result.Msg);
            if (result.IsSuccess)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            #endregion
        }

        /// <summary>
        /// 窗体关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}