Frm_PalletAdd.xaml.cs 3.36 KB
using HHWCS.Bll;
using HHWCS.Model;
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 HHWCSHost.View.Pallet
{
    /// <summary>
    /// Frm_PalletAdd.xaml 的交互逻辑
    /// </summary>
    public partial class Frm_PalletAdd : Window
    {
        public Frm_PalletAdd()
        {
            InitializeComponent();
        }

        private void btn_Add_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txt_PalletCode.Text))
            {
                MessageBox.Show("请输入条码");
            }
            else
            {
                var temp = AppCommon.Bll.GetAllContainer(txt_PalletCode.Text, false, false);
                if (temp.Success)
                {
                    MessageBox.Show($"托盘{txt_PalletCode.Text}已存在");
                }
                else
                {
                    var temp2 = AppCommon.Bll.CreateContainer(txt_PalletCode.Text, AppCommon.WarehouseCode, AppCommon.WarehouseId, 1);
                    if (temp2.Success)
                    {
                        MessageBox.Show("创建成功");
                    }
                    else
                    {
                        MessageBox.Show("创建失败");
                    }
                }
            }
        }

        private void btn_BatchAdd_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txt_Begin.Text) || string.IsNullOrEmpty(txt_End.Text) || string.IsNullOrEmpty(txt_Length.Text))
            {
                MessageBox.Show("开始、结束或长度为空");
            }
            int begin;
            int end;
            int length;
            if(int.TryParse(txt_Begin.Text,out begin)&&int.TryParse(txt_End.Text,out end)&&int.TryParse(txt_Length.Text,out length))
            {
                if (begin > end || length < 1)
                {
                    MessageBox.Show("开始要小于结束,长度要大于1");
                }
                else
                {
                    string p = txt_P.Text;
                    for (int i = begin; i < end+1; i++)
                    {
                        string pallet = p + i.ToString().PadLeft(length, '0');
                        var temp = AppCommon.Bll.GetAllContainer(pallet, false, false);
                        if (temp.Success)
                        {
                            MessageBox.Show($"托盘{pallet}已存在,操作中止");
                            break;
                        }
                        var temp2 = AppCommon.Bll.CreateContainer(pallet, AppCommon.WarehouseCode, AppCommon.WarehouseId, 1);
                        if (!temp2.Success)
                        {
                            MessageBox.Show("创建失败,操作中止:消息:"+temp2.Msg);
                            break;
                        }
                    }
                    MessageBox.Show("创建成功!");
                }
            }
            else
            {
                MessageBox.Show("请检查输入");
            }
            
        }
    }
}