using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Reflection;

namespace SiaSun.LMS.WPFClient.UC
{
    /// <summary>
    /// ucManagePosition.xaml 的交互逻辑
    /// </summary>
    public partial class ucManagePosition : UserControl
    {
        //判断是否加载完成
        bool boolIsLoaded = false;
        bool boolAllowChooseStartPosition = false;
        bool boolAllowChooseEndPosition = false;

        #region     ------定义代理和事件

        public delegate void U_StockBarcodeKeyDownHandler();

        public event U_StockBarcodeKeyDownHandler U_StockBarcodeKeyDown;

        /// <summary>
        /// 输送位置更改
        /// </summary>
        public delegate void U_StartPositionValueChangedHandler();

        //输送位置更改
        public event U_StartPositionValueChangedHandler U_StartPositionChanged;

        /// <summary>
        /// 输送位置更改
        /// </summary>
        public delegate void U_EndPositionValueChangedHandler();

        //输送位置更改
        public event U_EndPositionValueChangedHandler U_EndPositionChanged;

        /// <summary>
        /// 货位规格类型更改
        /// </summary>
        public delegate void U_CellModelValueChangedHandler();

        //货位规格类型更改
        public event U_CellModelValueChangedHandler U_CellModelChanged;


        #endregion

        #region     ------可在数据库表MANAGE_TYPE_PARAM中设备的属性

        bool boolShowStockBarcode = true;

        /// <summary>
        /// 是否显示托盘条码
        /// </summary>
        public bool U_AllowShowStockBarcode
        {
            get { return boolShowStockBarcode; }
            set
            {
                boolShowStockBarcode = value;
                this.panelStockBarcode.Visibility = this.boolShowStockBarcode ? Visibility.Visible : System.Windows.Visibility.Collapsed;
            }
        }


        bool boolAllowShowCellModel = true;

        /// <summary>
        /// 是否显示货位规格
        /// </summary>
        public bool U_AllowShowCellModel
        {
            get { return boolAllowShowCellModel; }
            set { boolAllowShowCellModel = value; this.panelCellModel.Visibility = this.boolAllowShowCellModel ? Visibility.Visible : System.Windows.Visibility.Collapsed; }
        }


        bool boolAllowShowOccupyPercent = false;

        /// <summary>
        /// 是否显示托盘占用百分比
        /// </summary>
        public bool U_AllowShowOccupyPercent
        {
            get { return boolAllowShowOccupyPercent; }
            set { boolAllowShowOccupyPercent = value; this.panelOccupyPercent.Visibility = this.boolAllowShowOccupyPercent ? Visibility.Visible : Visibility.Collapsed; }
        }


        bool boolShowStartPostion = true;

        /// <summary>
        /// 是否显示起始位置
        /// </summary>
        public bool U_AllowShowStartPosition
        {
            get { return boolShowStartPostion; }
            set
            {
                boolShowStartPostion = value;
                this.panelStartPosition.Visibility = value ? Visibility.Visible : System.Windows.Visibility.Collapsed;
            }
        }

        bool boolShowEndPosition = true;

        /// <summary>
        /// 是否显示终止位置
        /// </summary>
        public bool U_AllowShowEndPosition
        {
            get { return boolShowEndPosition; }
            set
            {
                boolShowEndPosition = value;
                this.panelEndPosition.Visibility = value ? Visibility.Visible : System.Windows.Visibility.Collapsed;
            }
        }

        string strAssembleResource = "1";

        public string U_AssembleResource
        {
            get { return this.strAssembleResource; }
            set { this.strAssembleResource = value; }
        }


        string strStartCellType = string.Empty;

        public string U_StartCellType
        {
            get { return this.strStartCellType; }
            set { this.strStartCellType = value; }
        }


        string strStartCellInOut = string.Empty;

        public string U_StartCellInOut
        {
            get { return this.strStartCellInOut; }
            set { this.strStartCellInOut = value; }
        }

        string strEndCellType = string.Empty;

        public string U_EndCellType
        {
            get { return this.strEndCellType; }
            set { this.strEndCellType = value; }
        }


        string strEndCellInOut = string.Empty;

        public string U_EndCellInOut
        {
            get { return this.strEndCellInOut; }
            set { this.strEndCellInOut = value; }
        }


        bool boolCheckStockExistStorage = false;

        public bool U_CheckStockExistStorage
        {
            get { return this.boolCheckStockExistStorage; }
            set { this.boolCheckStockExistStorage = value; }
        }


        bool boolAutoDownloadControlTask = false;


        public bool U_AutoDownloadControlTask
        {
            get { return this.boolAutoDownloadControlTask; }
            set { this.boolAutoDownloadControlTask = value; }
        }


        bool boolAutoCompleteTask = false;

        public bool U_AutoCompleteTask
        {
            get { return this.boolAutoCompleteTask; }
            set { this.boolAutoCompleteTask = value; }
        }

        bool boolAllowAutoStartPostion = false;

        /// <summary>
        /// 是否允许自动选择起始位置
        /// </summary>
        public bool U_AllowAutoStartPostion
        {
            get { return boolAllowAutoStartPostion; }
            set { boolAllowAutoStartPostion = value; }
        }

        bool boolAllowAutoEndPostion = false;

        /// <summary>
        /// 是否允许自动选择终止位置
        /// </summary>
        public bool U_AllowAutoEndPostion
        {
            get { return boolAllowAutoEndPostion; }
            set { boolAllowAutoEndPostion = value; }
        }

        int intStartPositionDefault = 0;
        /// <summary>
        ///
        /// </summary>
        public int U_StartPositionDefault
        {
            get { return this.intStartPositionDefault; }
            set
            {
                this.cmbStartPosition.IsEnabled = !(Convert.ToInt32(value) > 0);
                this.intStartPositionDefault = value;
            }
        }

        int intEndPositionDefault = 0;

        /// <summary>
        /// 设置目标位置是否可用
        /// </summary>
        public int U_EndPositionDefault
        {
            get { return this.intEndPositionDefault; }
            set
            {
                this.cmbEndPosition.IsEnabled = !(Convert.ToInt32(value) > 0);
                this.intEndPositionDefault = value;
            }
        }


        string strCellModelDefault = string.Empty;
        /// <summary>
        /// 设置货位规格是否可用
        /// </summary>
        public string U_CellModelDefault
        {
            get { return strCellModelDefault; }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    //this.cmbCellModel.IsEnabled = false;
                    this.strCellModelDefault = value;
                }
            }
        }


        string strOccupyPercentDefault = string.Empty;
        /// <summary>
        /// 设置托盘占有率是否可用
        /// </summary>
        public string U_OccupyPercentDefault
        {
            get { return strOccupyPercentDefault; }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    //this.cmbOccupyPercent.IsEnabled = false;
                    this.strOccupyPercentDefault = value;
                }
            }
        }


        string strWarehouseType = string.Empty;
        /// <summary>
        /// 加载货位选择时的仓库类型
        /// </summary>
        public string U_WarehouseType
        {
            get { return strWarehouseType; }
            set { strWarehouseType = value; }
        }


        string strStartPositonCellStatus = string.Empty;
        /// <summary>
        /// 选择起始位置要求的货位状态
        /// </summary>
        public string U_StartPositionCellStatus
        {
            get { return strStartPositonCellStatus; }
            set { strStartPositonCellStatus = value; }
        }

        string strEndPositonCellStatus = string.Empty;
        /// <summary>
        /// 选择起始位置要求的货位状态
        /// </summary>
        public string U_EndPositionCellStatus
        {
            get { return strEndPositonCellStatus; }
            set { strEndPositonCellStatus = value; }
        }

        #endregion




        /// <summary>
        /// 货位规格
        /// </summary>
        public string U_CELL_MODEL
        {
            get { return this.cmbCellModel.SelectedValue == null ? string.Empty : this.cmbCellModel.SelectedValue.ToString(); }
            set { if (value != null)this.cmbCellModel.SelectedValue = value; }
        }

        /// <summary>
        /// 托盘占用率
        /// </summary>
        public string U_OCCUPY_PERCENT
        {
            get { return this.cmbOccupyPercent.SelectedValue == null ? string.Empty : this.cmbOccupyPercent.SelectedValue.ToString(); }
            set { if (value != null)this.cmbOccupyPercent.SelectedValue = value; }
        }


        /// <summary>
        /// 起始输送位置编号
        /// </summary>
        public int U_START_POSITION_ID
        {
            get { return cmbStartPosition.SelectedValue == null ? 0 : Convert.ToInt32(this.cmbStartPosition.SelectedValue); }
            set { this.cmbStartPosition.SelectedValue = value; }
        }

        /// <summary>
        /// 终止输送位置编号
        /// </summary>
        public int U_END_POSITION_ID
        {
            get { return cmbEndPosition.SelectedValue == null ? 0 : Convert.ToInt32(this.cmbEndPosition.SelectedValue); }
            set { this.cmbEndPosition.SelectedValue = value; }
        }

        public string U_STOCK_BARCODE
        {
            get { return this.txtStockBarcode.Text.TrimEnd(); }
            set { this.txtStockBarcode.Text = value; }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public ucManagePosition()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 初始化控件
        /// </summary>
        public void U_InitControl( int MANAGE_TYPE_ID)
        {
            IList<SiaSun.LMS.Model.MANAGE_TYPE_PARAM> lsMANAGE_TYPE_PARAM = MainApp._I_ManageService.ManageTypeParamGetList(MANAGE_TYPE_ID);

            foreach (SiaSun.LMS.Model.MANAGE_TYPE_PARAM mMANAGE_TYPE_PARAM in lsMANAGE_TYPE_PARAM)
            {
                if (string.IsNullOrEmpty(mMANAGE_TYPE_PARAM.PARAM_VALUE))
                {
                    continue;
                }

                PropertyInfo[] propertys_info = this.GetType().GetProperties();

                foreach (PropertyInfo pi in propertys_info)
                {
                    if (pi.Name.Equals(mMANAGE_TYPE_PARAM.PARAM_CODE, StringComparison.CurrentCultureIgnoreCase))
                    {
                        pi.SetValue(this, Convert.ChangeType( mMANAGE_TYPE_PARAM.PARAM_VALUE,pi.PropertyType), null);
                    }
                }
            }
            this.boolIsLoaded = false;

            //货位规格
            this.CELL_MODEL_BIND();

            if (this.U_AllowShowOccupyPercent)
                this.OCCUPY_PERCENT_BIND();

            this.START_POSITION_BIND();

            this.END_POSITION_BIND();

            //设置默认值
            this.LoadDefaultValue();
            //设置是否显示选择位置按钮
            this.SetEnableChoosePositon();
        }

        /// <summary>
        /// 设置是否允许设置显示选择位置按钮
        /// </summary>
        private void SetEnableChoosePositon()
        {
            try
            {

                this.boolAllowChooseStartPosition = this.U_StartCellType == Enum.CELL_TYPE.Cell.ToString();
                this.btnStartPosition.Visibility = this.boolAllowChooseStartPosition ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
                this.cmbStartPosition.IsEnabled = !this.boolAllowChooseStartPosition;


                this.boolAllowChooseEndPosition = this.U_EndCellType == Enum.CELL_TYPE.Cell.ToString();
                this.btnEndPosition.Visibility = this.boolAllowChooseEndPosition ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
                this.cmbEndPosition.IsEnabled = !this.boolAllowChooseEndPosition;


            }
            catch (Exception ex)
            {
                MainApp._MessageDialog.ShowException(ex);
            }
        }

        #region     ------根据加载规则,加载起始库区和目标库区

        /// <summary>
        /// 清除数据绑定
        /// </summary>
        private void DataBindClear()
        {
            this.cmbStartPosition.ItemsSource = null;

            this.cmbEndPosition.ItemsSource = null;
        }


        /// <summary>
        /// 加载默认的库区
        /// </summary>
        private void LoadDefaultValue()
        {
            this.boolIsLoaded = false;

            //CellModel
            if (this.cmbCellModel.HasItems && this.cmbCellModel.SelectedValue == null)
            {
                if (!string.IsNullOrEmpty(this.strCellModelDefault))
                    this.cmbCellModel.SelectedValue = strCellModelDefault;
            }

            if (this.cmbStartPosition.HasItems && this.cmbStartPosition.SelectedValue == null)
            {
                if (this.intStartPositionDefault != 0)
                    this.cmbStartPosition.SelectedValue = this.intStartPositionDefault;
            }


            if (this.cmbEndPosition.HasItems && this.cmbEndPosition.SelectedValue == null)
            {
                if (this.intEndPositionDefault != 0)
                    this.cmbEndPosition.SelectedValue = this.intEndPositionDefault;
            }

            //托盘占有率
            if (this.cmbOccupyPercent.HasItems && this.cmbOccupyPercent.SelectedValue == null)
            {
                if (!string.IsNullOrEmpty(this.strOccupyPercentDefault))
                {
                    this.cmbOccupyPercent.SelectedValue = this.strOccupyPercentDefault;
                }
            }

            this.txtStockBarcode.Text = string.Empty;

            this.boolIsLoaded = true;
        }

        /// <summary>
        /// 加载默认的库区
        /// </summary>
        public void U_Refresh()
        {
            this.boolIsLoaded = false;

            this.txtStockBarcode.Text = string.Empty;

            this.cmbCellModel.SelectedValue = null;

            this.cmbOccupyPercent.SelectedValue = null;

            this.cmbStartPosition.SelectedValue = null;

            this.cmbEndPosition.SelectedValue = null;

            this.boolIsLoaded = true;
        }
        
        #endregion

        #region     ------CELL_MODEL绑定及变更

        /// <summary>
        /// 货位规格绑定
        /// </summary>
        private void CELL_MODEL_BIND()
        {
            try
            {

                IList<SiaSun.LMS.Model.SYS_ITEM_LIST> listITEM_LIST = MainApp._I_SystemService.ITEM_LIST_GetList_ITEM_CODE("CELL_MODEL");

                this.cmbCellModel.DisplayMemberPath = "ITEM_LIST_NAME";
                this.cmbCellModel.SelectedValuePath = "ITEM_LIST_CODE";
                this.cmbCellModel.ItemsSource = listITEM_LIST;
            }
            catch (Exception ex)
            {
                MainApp._MessageDialog.ShowException(ex);
            }
        }


        /// <summary>
        /// 托盘占用率
        /// </summary>
        private void OCCUPY_PERCENT_BIND()
        {
            try
            {

                IList<SiaSun.LMS.Model.SYS_ITEM_LIST> listITEM_LIST = MainApp._I_SystemService.ITEM_LIST_GetList_ITEM_CODE("FULL_FLAG");

                this.cmbOccupyPercent.DisplayMemberPath = "ITEM_LIST_NAME";
                this.cmbOccupyPercent.SelectedValuePath = "ITEM_LIST_CODE";
                this.cmbOccupyPercent.ItemsSource = listITEM_LIST;
            }
            catch (Exception ex)
            {
                MainApp._MessageDialog.ShowException(ex);
            }
        }

        /// <summary>
        /// CELL_MODEL变更,更改其他流程属性
        /// </summary>
        private void cmbCellModel_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //如果没有加载完成,不处理
            if (this.boolIsLoaded)
            {
                //默认值
                //this.LoadDefaultValue();

                //激活注册事件
                if (this.U_CellModelChanged != null)
                {
                    this.U_CellModelChanged();
                }
            }
        }

        #endregion



        #region     ------START_POSITION绑定及变更
        
        /// <summary>
        /// 根据流程加载起始位置
        /// </summary>
        private void START_POSITION_BIND()
        {

            this.cmbStartPosition.DisplayMemberPath = "CELL_NAME";
            this.cmbStartPosition.SelectedValuePath = "CELL_ID";


            if (this.U_StartCellType != Enum.CELL_TYPE.Cell.ToString())
            {
                this.cmbStartPosition.ItemsSource = MainApp._I_BaseService.GetList(
                                                                                  string.Format("select * from wh_cell where 1=1 {0} {1}",
                                                                                  this.U_StartCellType == string.Empty ? string.Empty : string.Format(" and cell_type like '%{0}%' ", this.U_StartCellType),
                                                                                  this.U_StartCellInOut == string.Empty ? string.Empty : string.Format(" and cell_inout like '%{0}%' ", this.U_StartCellInOut))
                                                                                  ).DefaultView;
            }
            //设置起始位置
            this.SetStartPositionDefault();
            //判断是否显示选择位置的按钮
            btnStartPosition.Visibility = (this.boolAllowChooseStartPosition && cmbStartPosition.HasItems) ? Visibility.Visible : System.Windows.Visibility.Hidden;
        }

        /// <summary>
        /// 设置默认起始位置值
        /// </summary>
        private void SetStartPositionDefault()
        {
            if (this.cmbStartPosition.HasItems && this.cmbStartPosition.SelectedValue == null)
            {
                //判断是否存在默认值
                if (this.intStartPositionDefault > 0)
                {
                    this.cmbStartPosition.SelectedValue = this.intStartPositionDefault;
                }

            }
        }

        /// <summary>
        /// 起始位置变更
        /// </summary>
        private void cmbStartPosition_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.boolIsLoaded)
            {
                //判断是否注册相应的事件
                if (this.U_StartPositionChanged != null)
                {
                    this.U_StartPositionChanged();
                }
            }
        }

        #endregion

        #region     ------END_POSITION绑定及变更

        /// <summary>
        /// 根据流程加载目标位置
        /// </summary>
        private void END_POSITION_BIND()
        {

            

            this.cmbEndPosition.DisplayMemberPath = "CELL_NAME";
            this.cmbEndPosition.SelectedValuePath = "CELL_ID";

            if (this.U_EndCellType != Enum.CELL_TYPE.Cell.ToString())
            {
                this.cmbEndPosition.ItemsSource = MainApp._I_BaseService.GetList(
                                                                                  string.Format("select * from wh_cell where 1=1 {0} {1}",
                                                                                  this.U_EndCellType == string.Empty ? string.Empty : string.Format(" and cell_type like '%{0}%' ", this.U_EndCellType),
                                                                                  this.U_EndCellInOut == string.Empty ? string.Empty : string.Format(" and cell_inout like '%{0}%' ", this.U_EndCellInOut))
                                                                                  ).DefaultView;
            }
            //设置目标位置
            this.SetEndPositionDefault();

            //判断是否显示选择位置的按钮
            btnEndPosition.Visibility = (this.boolAllowChooseEndPosition && cmbEndPosition.Items.Count > 0) ? Visibility.Visible : System.Windows.Visibility.Hidden;
        }

        /// <summary>
        /// 设置默认目标位置值
        /// </summary>
        private void SetEndPositionDefault()
        {
            if (this.cmbEndPosition.HasItems && this.cmbEndPosition.SelectedValue == null)
            {
                //判断是否存在默认值
                if (this.intEndPositionDefault > 0)
                {
                    this.cmbEndPosition.SelectedValue = this.intEndPositionDefault;
                }

            }
        }

        /// <summary>
        /// 目标位置变更
        /// </summary>
        private void cmbEndPosition_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.boolIsLoaded)
            {
                //判断是否注册相应的事件
                if (this.U_EndPositionChanged != null)
                {
                    this.U_EndPositionChanged();
                }
            }
        }

        #endregion

        #region     ------选择起始位置、目标位置

        /// <summary>
        /// 按钮事件
        /// </summary>
        private void WrapPanel_Click(object sender, RoutedEventArgs e)
        {
            Button btn = e.OriginalSource as Button;
            if (btn != null)
            {
                switch (btn.Name)
                {
                    case "btnStartPosition":
                        this.SelectStartPosition();
                        break;
                    case "btnEndPosition":
                        this.SelectEndPosition();
                        break;
                }
            }
        }

        /// <summary>
        /// 选择起始位置
        /// </summary>
        private void SelectStartPosition()
        {
            //判断可选择货位

            try
            {
                //获得起始库区
                //Model.WH_AREA mWH_AREA_Start = MainApp._I_CellService.AREA_GetModel(Convert.ToInt32(this.cmbStartArea.SelectedValue));
                //获得选定的货位
                Model.WH_CELL mWH_CELL_Selected = new Model.WH_CELL();// cmbStartPosition.SelectedValue == null ? null : MainApp._I_CellService.CELL_GetModel(Convert.ToInt32(cmbStartPosition.SelectedValue));
                mWH_CELL_Selected.CELL_STATUS = this.U_StartPositionCellStatus;
                WH.WAREHOUSE_CELL_SELECT window = new WH.WAREHOUSE_CELL_SELECT(this.U_WarehouseType, mWH_CELL_Selected);
                if (window.ShowDialog() == true)
                {
                    SiaSun.LMS.Model.WH_CELL mWH_CELL = window.U_WH_CELL;
                    if (mWH_CELL != null)
                    {
                        this.cmbStartPosition.ItemsSource = MainApp._I_BaseService.GetList(
                                                              string.Format("select * from wh_cell where cell_id={0}",
                                                              mWH_CELL.CELL_ID)
                                                              ).DefaultView;


                        cmbStartPosition.SelectedValue = mWH_CELL.CELL_ID;

                        //判断是否正确
                        if (cmbStartPosition.SelectedValue == null)
                        {
                            MainApp._MessageDialog.Show(false,"请检查起始位置是否合法!");
                            return;
                        }
                        else
                        {
                            //触发事件
                            if (this.U_StartPositionChanged != null)
                            {
                                this.U_StartPositionChanged();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MainApp._MessageDialog.ShowException(ex);
            }

        }

        /// <summary>
        /// 选择目标位置
        /// </summary>
        private void SelectEndPosition()
        {

                try
                {
                    //获得起始库区
                    //Model.WH_AREA mWH_AREA_End = MainApp._I_CellService.AREA_GetModel(Convert.ToInt32(this.cmbEndArea.SelectedValue));
                    //获得选定的货位
                    Model.WH_CELL mWH_CELL_Selected = new Model.WH_CELL();// MainApp._I_CellService.CELL_GetModel(Convert.ToInt32(cmbEndPosition.SelectedValue));
                    mWH_CELL_Selected.CELL_STATUS = this.U_EndPositionCellStatus;
                    WH.WAREHOUSE_CELL_SELECT window = new WH.WAREHOUSE_CELL_SELECT(this.U_WarehouseType, mWH_CELL_Selected);
                    if (window.ShowDialog() == true)
                    {
                        SiaSun.LMS.Model.WH_CELL mWH_CELL = window.U_WH_CELL;
                        if (mWH_CELL != null)
                        {

                            this.cmbEndPosition.ItemsSource = MainApp._I_BaseService.GetList(
                                                                  string.Format("select * from wh_cell where cell_id={0}",
                                                                  mWH_CELL.CELL_ID)
                                                                  ).DefaultView;
                            

                            cmbEndPosition.SelectedValue = mWH_CELL.CELL_ID;

                            //判断是否正确
                            if (cmbEndPosition.SelectedValue == null)
                            {
                                MainApp._MessageDialog.Show(false, "检查目标位置是否合法");
                                return;
                            }
                            else
                            {
                                //触发事件
                                if (this.U_EndPositionChanged != null)
                                {
                                    this.U_EndPositionChanged();
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MainApp._MessageDialog.ShowException(ex);
                }

        }

        #endregion

        #region     -------设置各个属性值

        /// <summary>
        /// 设置货位规格值
        /// </summary>
        public void U_SetCellModel(string CELL_MODEL)
        {
            this.cmbCellModel.SelectedValue = CELL_MODEL;
        }


        #endregion

        #region     ------校验填写的值是否合法

        //校验信息是否正确
        public bool U_CHECK_WAREHOUSE()
        {
            if (boolShowStockBarcode && !SiaSun.LMS.Common.RegexValid.GetCodeCheck(this.txtStockBarcode.Text, "StockCodeCheck"))
            {
                MainApp._MessageDialog.Show(false, "检查托盘条码是否合法");
                return false;
            }

            //货位规格
            if (this.boolAllowShowCellModel && this.cmbCellModel.SelectedValue == null)
            {
                MainApp._MessageDialog.Show(false, "检查货位规格是否合法");
                return false;
            }
            //托盘占用百分比
            if (this.boolAllowShowOccupyPercent && this.cmbOccupyPercent.SelectedValue == null)
            {
                MainApp._MessageDialog.Show(false, "检查托盘占用率");
                return false;
            }

            //起始位置
            if (boolShowStartPostion && !boolAllowAutoStartPostion && cmbStartPosition.SelectedValue == null)
            {
                MainApp._MessageDialog.Show(false, "检查起始位置是否合法");
                return false;
            }

            //终止位置
            if (boolShowEndPosition && !boolAllowAutoEndPostion && cmbEndPosition.SelectedValue == null)
            {
                MainApp._MessageDialog.Show(false, "检查目标位置是否合法");
                return false;
            }



            return true;
        }

        /// <summary>
        /// 检查起始位置是否合法,检查货位编码是否等于设备编码
        /// </summary>
        public bool U_CheckStartPosition(string START_POSITION_CODE)
        {
            bool boolResult = false;
            using (DataTable tableStartPosition = (this.cmbStartPosition.ItemsSource as DataView).Table)
            {
                if (tableStartPosition != null)
                {
                    boolResult = tableStartPosition.Select(string.Format("DEVICE_CODE='{0}'", START_POSITION_CODE)).Length > 0;
                }
            }
            return boolResult;
        }

        /// <summary>
        /// 检查目标位置是否合法,检查货位编码是否等于设备编码
        /// </summary>
        public bool U_CheckEndPosition(string END_POSITION_CODE)
        {
            bool boolResult = false;
            using (DataTable tableEndPosition = (this.cmbEndPosition.ItemsSource as DataView).Table)
            {
                if (tableEndPosition != null)
                {
                    boolResult = tableEndPosition.Select(string.Format("DEVICE_CODE='{0}'", END_POSITION_CODE)).Length > 0;
                }
            }
            return boolResult;
        }

        #endregion

        /// <summary>
        /// 刷新控件显示
        /// </summary>
        public void U_Update()
        {
            this.LoadDefaultValue();
        }

        /// <summary>
        /// 清除操作
        /// </summary>
        public void U_Clear()
        {
            this.boolIsLoaded = false;
            this.cmbCellModel.ItemsSource = null;
            this.DataBindClear();
            this.boolIsLoaded = true;
        }

        private void StockBarcode_KeyDown(object sender, KeyEventArgs e)
        {
            if (this.U_StockBarcodeKeyDown != null && e.Key == Key.Enter)
            {
                this.U_StockBarcodeKeyDown();
            }
        }



    }
}