WinOrganization.xaml.cs 12.3 KB
using XingYe_ACS.BaseStruct;
using XingYe_ACS.Business;
using XingYe_ACS.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Shapes;

namespace XingYe_ACS.UI
{
    /// <summary>
    /// WinOrganization.xaml 的交互逻辑
    /// </summary>
    public partial class WinOrganization : Window
    {
        public WinOrganization()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 关闭按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        //重写Closing方法
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }

        /// <summary>
        /// 拖动事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DGrid_AGV.ItemsSource = App.AgvList.OrderBy(a => a.strAgvNo);
            DGrid_Charge.ItemsSource = App.StationList.Where(a => a.stationType == EnumMsg.StationType.充电桩).OrderBy(a => a.strStationNo);
            DGrid_Station.ItemsSource = App.StationList.Where(a => a.stationType >= EnumMsg.StationType.回家位 || a.stationType == EnumMsg.StationType.临时输送线等待区).OrderBy(a => a.strStationNo);
            DGrid_MatixManager.ItemsSource = App.PointList;
            DGrid_Hoister.ItemsSource = App.HoisterList;
        }

        /// <summary>
        /// 解锁站台事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MItem_Locked_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //if (DGrid_Station.SelectedItem == null) return;
                //Station station = DGrid_Station.SelectedItem as Station;
                //if (station == null) return;
                //station.isLocked = false;
                //bool updateResult = UpdateManage.UpdateStation(station);
                //if (updateResult)
                //{
                //    MessageBox.Show("解锁成功");
                //}
                //else
                //{
                //    MessageBox.Show("解锁失败");
                //}
            }
            catch (Exception Ex)
            {
                MessageBox.Show("操作失败:" + Ex.ToString());
            }
        }

        private void MItem_AgvOnline_Click(object sender, RoutedEventArgs e)
        {
            Agv agv = DGrid_AGV.SelectedItem as Agv;
            if (agv == null || agv.agvTask != null) return;
            try
            {
                string sqlUpdate = string.Format("UPDATE  T_Base_Agv SET isEnable = '1' WHERE strAgvNo =  '{0}';", agv.strAgvNo);
                int updateResult = DbHelperSQL.ExecuteSql(sqlUpdate);
                if (updateResult == 1)
                {
                    agv.isEnable = true;
                    MessageBox.Show(string.Format("{0}上线成功!", agv.strAgvNo));
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.ToString());
            }
        }

        private void MItem_AgvOut_Click(object sender, RoutedEventArgs e)
        {
            Agv agv = DGrid_AGV.SelectedItem as Agv;
            if (agv == null || agv.agvTask != null) return;
            try
            {
                string sqlUpdate = string.Format("UPDATE  T_Base_Agv SET strBarcode = '0',strChooseStation = '', isEnable = '0' WHERE strAgvNo =  '{0}';", agv.strAgvNo);
                int updateResult = DbHelperSQL.ExecuteSql(sqlUpdate);
                if (updateResult == 1)
                {
                    agv.agvState = 0;
                    agv.strBarcode = "0";
                    agv.isEnable = false;
                    agv.isOnline = false;
                    agv.strChooseStation = "";
                    List<BaseStruct.Point> agvLockedList = App.PointList.FindAll(a => a.lockedAgv == agv);
                    foreach (BaseStruct.Point point in agvLockedList)
                    {
                        point.lockedAgv = null;
                    }
                    //更新界面小车位置
                    App.Sharp.AgvChange(agv);
                    MessageBox.Show(string.Format("{0}下线成功!", agv.strAgvNo));
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.ToString());
            }
        }

        /// <summary>
        /// 禁用充电桩
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MItem_Cforbit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Station chargeStation = DGrid_Charge.SelectedItem as Station;
                if (chargeStation == null) return;
                chargeStation.isEnable = false;
                bool isResult = UpdateManage.UpdateStation(chargeStation);
                if (isResult)
                {
                    MessageBox.Show(string.Format("{0}充电桩禁用成功!", chargeStation.strStationNo));
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.ToString());
            }
        }

        /// <summary>
        /// 启用充电桩
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MItem_CEnable_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Station chargeStation = DGrid_Charge.SelectedItem as Station;
                if (chargeStation == null) return;
                chargeStation.isEnable = true;
                bool isResult = UpdateManage.UpdateStation(chargeStation);
                if (isResult)
                {
                    MessageBox.Show(string.Format("{0}充电桩启用成功!", chargeStation.strStationNo));
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.ToString());
            }
        }

        private void MItem_CUnLock_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Station chargeStation = DGrid_Charge.SelectedItem as Station;
                if (chargeStation == null) return;
                Agv agv = App.AgvList.FirstOrDefault(a => a.strBarcode == chargeStation.strBarcode);
                if (agv!=null)
                {
                    MessageBox.Show(string.Format("{0}占用当前充电桩无法解锁!",agv.strAgvNo));
                    return;
                }
                chargeStation.isLocked = false;
                bool isResult = UpdateManage.UpdateStation(chargeStation);
                if (isResult)
                {
                    MessageBox.Show(string.Format("{0}充电桩解锁成功!", chargeStation.strStationNo));
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.ToString());
            }
        }

        /// <summary>
        /// 更改站台的出入库类型
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MItem_ChangeStationType_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Station station = DGrid_Station.SelectedItem as Station;
                if (station == null) return;
                string stype = station.stationState.ToString() == "满" ? "空" : "满";
                if (MessageBox.Show("确定将" + station.strRemark + "站台状态更改为" + stype, "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    //判断是否有前往人工分拣口的任务
                    FTask fTask = App.TaskList.FirstOrDefault(a => a.endPoint.strBarcode == station.strBarcode);
                    if (fTask != null)
                    {
                        MessageBox.Show("存在往当前工位的任务,不可以切换状态");
                        return;
                    }
                    string sqlUpdate = string.Format("UPDATE T_Base_Station SET stationState = '{1}' WHERE strStationNo = '{0}';", station.strStationNo, stype == "满" ? 1 : 2);
                    int intSqlResult = DbHelperSQL.ExecuteSql(sqlUpdate);
                    if (intSqlResult == 1)
                    {
                        station.stationState = Extends.ToEnum<EnumMsg.StationState>(stype);
                        MessageBox.Show(string.Format("切换{0}状态成功!", station.strRemark));
                    }
                    else
                    {
                        MessageBox.Show(string.Format("切换{0}状态失败!", station.strRemark));
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.ToString());
            }
        }

        /// <summary>
        /// 启用站台
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MItem_OnEnable_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Station station = DGrid_Station.SelectedItem as Station;
                if (station == null) return;
                string sqlUpdate = string.Format("UPDATE  T_Base_Station SET isEnable = 1 WHERE strStationNo = '{0}';", station.strStationNo);
                int intSqlResult = DbHelperSQL.ExecuteSql(sqlUpdate);
                if (intSqlResult == 1)
                {
                    station.isEnable = true;

                }
                else 
                {
                    MessageBox.Show(string.Format("启用{0}站台失败!", station.strStationNo));
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.ToString());
            }
        }

        /// <summary>
        /// 禁用站台
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MItem_OffEnable_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Station station = DGrid_Station.SelectedItem as Station;
                if (station == null) return;
                string sqlUpdate = string.Format("UPDATE  T_Base_Station SET isEnable = 0 WHERE strStationNo = '{0}';", station.strStationNo);
                int intSqlResult = DbHelperSQL.ExecuteSql(sqlUpdate);
                if (intSqlResult == 1)
                {
                    station.isEnable = false;

                }
                else
                {
                    MessageBox.Show(string.Format("禁用{0}站台失败!", station.strStationNo));
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.ToString());
            }
        }

        /// <summary>
        /// 更改货架信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MItem_ChangeShelf_Click(object sender, RoutedEventArgs e)
        {

        }

        private void MItem_ShelfUnLock_Click(object sender, RoutedEventArgs e)
        {

        }

        private void MItem_SelectShelf_Click(object sender, RoutedEventArgs e)
        {

        }

        private void MItem_Hoister_Click(object sender, RoutedEventArgs e)
        {
            Hoister hositer = DGrid_Hoister.SelectedItem as Hoister;
            if (hositer == null) return;
            if (hositer.read_isFull) hositer.read_isFull = false;
            else
            {
                hositer.read_isFull = true;
            }
            MessageBox.Show("清除成功");
        }
    }
}