CarTaskMaintainVM.cs 5.08 KB
using HHECS.Application.Enums;
using HHECS.BllModel;
using HHECS.Infrastructure.CommonHelper;
using HHECS.Model.Entities;
using HHECS.Model.Enums.Car;
using HHECS.Model.Enums.Task;
using HHECS.WinCommon.ViewModel;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Windows;
using MessageBox = HandyControl.Controls.MessageBox;

namespace HHECS.WinClient.View.TaskInfo
{
    public class CarTaskMaintainVM : VMBase
    {
        public string Id { get; set; }
        public string StepTraceId { get; set; }
        public string WorkOrderHeadId { get; set; }
        public string CarNo { get; set; }
        public string FromLocation { get; set; }
        public string ToLocation { get; set; }
        public string Type { get; set; }
        public string Status { get; set; }
        public Dictionary<string, object> Types { get; set; }

        public Dictionary<string, object> Statuss { get; set; }

        public CarTaskMaintainVM(int id)
        {
            Id = id.ToString();
            var type = EnumHelper.EnumListDicString<CutPlanHeadState>("全部", "");
            Types = type;

            var statu = EnumHelper.EnumListDicString<CutPlanHeadState>("全部", "");
            Statuss = statu;
        }

        public Expression<Func<TaskCarEntity, bool>> GetCarTaskMaintainExpression()
        {
            Expression<Func<TaskCarEntity, bool>> filter = a => true;
            if (!string.IsNullOrWhiteSpace(Id))
            {
                filter = filter.And(a => a.Id.ToString() == Id);
            }
            if (!string.IsNullOrWhiteSpace(WorkOrderHeadId))
            {
                filter = filter.And(a => a.StepTraceId.ToString() == WorkOrderHeadId);
            }
            if (!string.IsNullOrWhiteSpace(CarNo))
            {
                filter = filter.And(a => a.CarNo == CarNo);
            }
            if (!string.IsNullOrWhiteSpace(FromLocation.ToString()))
            {
                filter = filter.And(a => a.FromLocation.ToString() == FromLocation);
            }
            if (!string.IsNullOrWhiteSpace(ToLocation.ToString()))
            {
                filter = filter.And(a => a.ToLocation.ToString() == ToLocation);
            }
            return filter;
        }

        public void EditFromLocation()
        {
            if (string.IsNullOrWhiteSpace(FromLocation))
            {
                MessageBox.Show("不允许对源库位进行清空处理");
            }
            else
            {
                if (MessageBox.Show($"是否更改源库位?", "注意", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    var fromlocaiotnCode = Convert.ToInt32(FromLocation);
                    BllResult result = App.TaskService.UpdateTaskCarFromLocationCode(Convert.ToInt32(Id), fromlocaiotnCode, App.User.UserCode);
                    if (result.Success)
                    {
                        MessageBox.Show("更改源库位成功");
                    }
                    else
                    {
                        MessageBox.Show($"更改源库位失败:{result.Msg}");
                    }
                }
            }
        }

        public void EditToLocation()
        {
            if (MessageBox.Show($"是否更改目标库位?", "注意", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                var locaiotnCode = ToLocation;
                BllResult result = App.TaskService.UpdateTaskCarToLocation(Convert.ToInt32(Id), locaiotnCode, App.User.UserCode);
                if (result.Success)
                {
                    MessageBox.Show("更改目标库位成功");
                }
                else
                {
                    MessageBox.Show($"更改目标库位失败:{result.Msg}");
                }
            }
        }

        public void EditStatus()
        {
            var id = Convert.ToInt32(Id);
            if (string.IsNullOrWhiteSpace(Status))
            {
                MessageBox.Show("请先选中需要更改的状态");
            }
            else
            {
                if (Enum.TryParse(Status, out CutPlanHeadState s))
                {
                    if (Status == CutPlanHeadState.接口冻结.GetIndexString())
                    {
                        MessageBox.Show("无法维护成任务完成,请使用强制任务完成");
                    }
                    else
                    {
                        BllResult result = App.TaskService.ChangeTaskCarStatus(id, (int)s, App.User.UserCode);
                        if (result.Success)
                        {
                            MessageBox.Show($"更改任务{id}状态成功");
                        }
                        else
                        {
                            MessageBox.Show($"更改任务{id}状态失败:{result.Msg}");
                        }
                    }
                }
                else
                {
                    MessageBox.Show($"状态:{Status}无效");
                }
            }
        }



    }
}