WinTaskInfo.xaml.cs 5.73 KB
using HHECS.Bll;
using HHECS.Controls;
using HHECS.Model;
using HHECS.ViewModel;
using System;
using System.Collections.Generic;
using System.Data;
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 HHECS.View.TaskInfo
{
    /// <summary>
    /// Frm_TaskInfo.xaml 的交互逻辑
    /// </summary>
    public partial class WinTaskInfo : Window
    {
        public PageInfoVM PageInfo { get; set; } = new PageInfoVM();
        public WinTaskInfo()
        {
            InitializeComponent();
            InitControl();
        }

        private void InitControl()
        {
            endTime.SelectedDate = DateTime.Now.AddDays(1);
            beginTime.SelectedDate = DateTime.Now.AddDays(-7);
            var temp = AppSession.Bll.GetDictWithDetails("TaskStatus");
            if (temp.Success)
            {
                var dictDetails = temp.Data.DictDetails.ToDictionary(t => t.Value, i => i.Name);
                dictDetails.Add("", "全部");
                cbx_TaskStatus.ItemsSource = dictDetails;
                cbx_TaskStatus.DisplayMemberPath = "Value";
                cbx_TaskStatus.SelectedValuePath = "Key";
            }
               
            this.DPMain.DataContext = PageInfo;
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }

        private void btn_Query_Click(object sender, RoutedEventArgs e)
        {

            //dgv_1.ItemsSource = AppCommon.Bll.GetTasks((String)cbx_TaskStatus.SelectedValue, txt_TaskNo.Text, txt_Pallet.Text, beginTime.SelectedDate, endTime.SelectedDate).Data;
            Query();
        }

        private void Query()
        {
            string sql = "where 1=1 and zoneCode = 'LK' ";
            if (!String.IsNullOrWhiteSpace(txt_Pallet.Text))
            {
                sql += $" and containerCode like '%{txt_Pallet.Text}%'";
            }
            if (!String.IsNullOrWhiteSpace(txt_TaskNo.Text))
            {
                sql += $" and id ={txt_TaskNo.Text}";
            }
            var status = cbx_TaskStatus.SelectedValue?.ToString();
            if (!String.IsNullOrWhiteSpace(status))
            {
                sql += $" and firstStatus = {status} and lastStatus = {status} ";
            }
            if (beginTime.SelectedDate != null)
            {
                sql += $" and created >= '{beginTime.ToString()}'";
            }
            if (endTime.SelectedDate != null)
            {
                sql += $" and created <= '{endTime.ToString()}'";
            }
            BllResult<int> result = AppSession.Bll.GetCommonModelCount<TaskEntity>(sql);
            if (result.Success)
            {
                PageInfo.TotalCount = result.Data;
                dgv_1.ItemsSource = AppSession.Bll.GetCommonModeByPageCondition<TaskEntity>(PageInfo.PageIndex, PageInfo.PageSize, sql, "id desc").Data;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            WinTaskAdd frm_TaskAdd = new WinTaskAdd();
            frm_TaskAdd.ShowDialog();
            btn_Query_Click(null, null);
        }

        private void btn_Delete_Click(object sender, RoutedEventArgs e)
        {
            //MessageBox.Show("删除功能在当前版本下不可用");
            //return;
            if (dgv_1.SelectedItems == null || dgv_1.SelectedItems.Count == 0)
            {
                MessageBox.Show("未选中数据");
            }
            foreach (TaskEntity item in dgv_1.SelectedItems)
            {
                BllResult a = AppSession.Bll.DeleteTask(item.Id);
                if (!a.Success)
                {
                    MessageBox.Show("删除出现问题,操作中止:" + a.Msg);
                    return;
                }
                AppSession.Bll.UpdateLocationStatus(item.DestinationLocation, item.WarehouseId, "empty");
            }
            MessageBox.Show("删除成功");
            btn_Query_Click(null, null);
        }

        private void btn_SendToWCS_Click(object sender, RoutedEventArgs e)
        {
            if (dgv_1.SelectedItems == null || dgv_1.SelectedItems.Count == 0)
            {
                MessageBox.Show("未选中数据");
                return;
            }
            foreach (TaskEntity item in dgv_1.SelectedItems)
            {
                BllResult a = AppSession.Bll.SendTaskToWCS(item.Id);
                if (!a.Success)
                {
                    MessageBox.Show("下发出现问题,操作中止:" + a.Msg);
                    return;
                }
            }
            MessageBox.Show("下发成功");
        }

        private void btn_modifyStatus_Click(object sender, RoutedEventArgs e)
        {

            if (dgv_1.SelectedItems == null || dgv_1.SelectedItems.Count != 1)
            {
                MessageBox.Show("只允许选中一个数据");
            }
            else
            {
                List<TaskEntity> temp = new List<TaskEntity>();
                foreach (var item in dgv_1.SelectedItems)
                {
                    temp.Add((TaskEntity)item);
                }
                WinTaskInfoStatusChange frm = new WinTaskInfoStatusChange(temp.First().Id);
                frm.ShowDialog();
                btn_Query_Click(null, null);
            }
        }


        private void page_PageChanged(object sender, PageChangedEventArgs e)
        {
            PageInfo.PageIndex = e.CurrentPageIndex;
            Query();
        }
    }
}