HandDeviceTask.xaml.cs 3 KB
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;

namespace HH_WCS_Standard
{
    /// <summary>
    /// HandDeviceTask.xaml 的交互逻辑
    /// </summary>
    public partial class HandDeviceTask
    {
        public HandDeviceTask()
        {
            InitializeComponent();
        }

        private void DMSkinWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // 设备绑定
            List<BindComboxType<string>> bindComboxTypes = new List<BindComboxType<string>>();
            var deviceList = App.f_ServiceModels.FindAll(a => a.device.Type == "Srm" || a.device.Type == "Rgv");
            foreach (F_ServiceModel device in deviceList)
            {
                bindComboxTypes.Add(new BindComboxType<string> { Name = device.device.Name, Type = device.device.Code });
            }
            //Comm_Device.ItemsSource = bindComboxTypes;
            //Comm_Device.DisplayMemberPath = "Name";
            //Comm_Device.SelectedValuePath = "Type";

            //任务类型绑定
            Comm.ItemsSource = BindComboxEnumType<E_SrmHandTask>.BindTyps;
            Comm.DisplayMemberPath = "Name";
            Comm.SelectedValuePath = "Type";
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (Comm.SelectedValue == null) //Comm_Device.SelectedValue == null && 
            {
                MessageBox.Show("请选择必选项", "提示");
                return;
            }
            //var deviceCode = Comm_Device.SelectedValue.ToString();
            var deviceCode = "Srm01";
            var taskType = (E_SrmHandTask)Comm.SelectedValue;
            if (string.IsNullOrWhiteSpace(from.Text))
            {
                MessageBox.Show("起点不能为空");
                return;
            }
            if (string.IsNullOrWhiteSpace(to.Text))
            {
                MessageBox.Show("终点不能为空");
            }
            var excute_device = App.i_Excutes.FirstOrDefault(a => a.f_service.device.Code == deviceCode);
            if (excute_device == null)
            {
                MessageBox.Show($"找不到此设备{deviceCode}对应的处理类");
                return;
            }
            var excute = excute_device as I_Excute_S; //堆垛机处理类
            if (excute != null)
            {
                var result = excute.HandDeviceTask(taskType.GetIndexInt(), from.Text, to.Text);
                if (!result.Success)
                {
                    MessageBox.Show($"手动下发设备{deviceCode}任务失败,错误原因是:【{result.Msg}】");
                    return;
                }
                else
                {
                    MessageBox.Show($"手动下发设备{deviceCode}任务成功");
                }
            }
            else
            {
                MessageBox.Show($"手动下发设备{deviceCode}任务失败,找不到此设备的类型");
                return;
            }
        }
    }
}