using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using com.hnshituo.core.webapp.vo;

namespace MeterConditionLibrary
{
    /// <summary>
    /// 收发货名称的验证
    /// </summary>
    public class validUnitName
    {
        /// <summary>
        /// 收发货单位验证
        /// </summary>
        /// <param name="weight"></param>
        /// <returns></returns>
        public bool ValidMethod(PreTrackScale trackScale)
        {
            try
            {
                if (trackScale != null && !string.IsNullOrEmpty(trackScale.matterName)
                && !string.IsNullOrEmpty(trackScale.forwardingUnitName) && !string.IsNullOrEmpty(trackScale.receivingUintName))
                {
                    if ((trackScale.matterName.Trim().Equals("连铸坯") || trackScale.matterName.Trim().Equals("方坯"))
                        && trackScale.forwardingUnitName.Equals(trackScale.receivingUintName))
                    {
                        PbCache.ResultMessage = "物资名称为【" + trackScale.matterName + "】，收货单位【" + trackScale.receivingUintName + "】与发货单位【" + trackScale.forwardingUnitName + "】" +
                            "相同，不允许进行计量操作！";
                        return false;
                    }
                }

                /*
                if (trackScale != null && !string.IsNullOrEmpty(trackScale.forwardingUnitName) && !string.IsNullOrEmpty(trackScale.receivingUintName))
                {
                    //厂际调拨：收货单位与发货单位不能都为东区或西区
                    if (trackScale.meterTypeNo.Equals("001006009") || trackScale.meterTypeNo.Equals("001006006"))
                    {
                        if ((trackScale.forwardingUnitName.Contains("东区") && trackScale.receivingUintName.Contains("东区"))
                            || (trackScale.forwardingUnitName.Contains("西区") && trackScale.receivingUintName.Contains("西区")))
                        {
                            PbCache.ResultMessage = "业务类型为【" + trackScale.meterTypeName + "】，收货单位【" + trackScale.receivingUintName + "】与发货单位【" + trackScale.forwardingUnitName + "】" +
                                "不能都为东区或西区，不允许进行计量操作！";
                            return false;
                        }
                    }

                    //厂际调拨：收货单位与发货单位必须包含东区或西区，特殊的（正天港务、众邦加工厂）
                    if (trackScale.meterTypeNo.Equals("001006009") || trackScale.meterTypeNo.Equals("001006006"))
                    {
                        if ((!trackScale.forwardingUnitName.Contains("东区") && !trackScale.forwardingUnitName.Contains("西区")
                            && !trackScale.forwardingUnitName.Contains("正天港务") && !trackScale.forwardingUnitName.Contains("众邦加工厂"))
                            ||( !trackScale.receivingUintName.Contains("东区") && !trackScale.receivingUintName.Contains("西区")
                            && !trackScale.receivingUintName.Contains("正天港务") && !trackScale.forwardingUnitName.Contains("众邦加工厂")))
                        {
                            PbCache.ResultMessage = "业务类型为【" + trackScale.meterTypeName + "】，收货单位【" + trackScale.receivingUintName + "】与发货单位【" + trackScale.forwardingUnitName + "】" +
                                "必须要包含东区、西区、正天港务、众邦加工厂，不允许进行计量操作！";
                            return false;
                        }
                    }

                    //厂内倒转：收货单位与发货单位必须都为东区或都为西区
                    if (trackScale.meterTypeNo.Equals("001006003") || trackScale.meterTypeNo.Equals("001006010"))
                    {
                        if ((!trackScale.forwardingUnitName.Contains("东区") && !trackScale.forwardingUnitName.Contains("西区"))
                            || (!trackScale.receivingUintName.Contains("东区") && !trackScale.receivingUintName.Contains("西区")))
                        {
                            PbCache.ResultMessage = "业务类型为【" + trackScale.meterTypeName + "】，收货单位【" + trackScale.receivingUintName + "】与发货单位【" + trackScale.forwardingUnitName + "】" +
                                "必须包含东区或西区，不允许进行计量操作！";
                            return false;
                        }
                        if (trackScale.forwardingUnitName.Contains("西区") && !trackScale.receivingUintName.Contains("西区"))
                        {
                            PbCache.ResultMessage = "业务类型为【" + trackScale.meterTypeName + "】，收货单位【" + trackScale.receivingUintName + "】与发货单位【" + trackScale.forwardingUnitName + "】" +
                                "必须都为东区或西区，不允许进行计量操作！";
                            return false;
                        }

                        if (trackScale.forwardingUnitName.Contains("东区") && !trackScale.receivingUintName.Contains("东区"))
                        {
                            PbCache.ResultMessage = "业务类型为【" + trackScale.meterTypeName + "】，收货单位【" + trackScale.receivingUintName + "】与发货单位【" + trackScale.forwardingUnitName + "】" +
                                "必须都为东区或西区，不允许进行计量操作！";
                            return false;
                        }
                    }

                    //001006009厂际调拨-先毛后皮   001006006厂际调拨-先皮后毛
                    //if (!trackScale.meterTypeNo.Equals("001006009") && !trackScale.meterTypeNo.Equals("001006006"))
                    //{  
                    //}

                    //发货单位含新区或东区，且计量点在1#、2#、3#、9#磅（西区）计量，显示计量点错误；
                    if (trackScale.forwardingUnitName.Contains("东区") || trackScale.forwardingUnitName.Contains("新区"))
                    {
                        //001047002  西区
                        if (!string.IsNullOrEmpty(PbCache.sportInfo.spotAreaNo) && PbCache.sportInfo.spotAreaNo.Equals("001047002"))
                        {
                            PbCache.ResultMessage = "计量点错误，发货单位【" + trackScale.forwardingUnitName + "】包括“东区”或“新区”，" +
                                "不允许在【" + PbCache.sportInfo.spotAreaName + "】的计量点过磅，请点击【语音求助】，联系司秤工！";
                            return false;
                        }
                    }

                    //发货单位是老区或西区，且计量点在4#、5#、6#、7#、8#磅（东区），显示计量点错误，不允许保存。
                    if (trackScale.forwardingUnitName.Contains("西区") || trackScale.forwardingUnitName.Contains("老区"))
                    {
                        //001047001 东区
                        if (!string.IsNullOrEmpty(PbCache.sportInfo.spotAreaNo) && PbCache.sportInfo.spotAreaNo.Equals("001047001"))
                        {
                            PbCache.ResultMessage = "计量点错误，发货单位【" + trackScale.forwardingUnitName + "】包括“西区”或“老区”，" +
                                "不允许在【" + PbCache.sportInfo.spotAreaName + "】的计量点过磅，请点击【语音求助】，联系司秤工！";
                            return false;
                        }
                    }

                    //001006001 外购进厂计量 001006008 外购进厂-三号码头  001006002 外销出厂计量  001006011 外销出厂-复磅(码头)
                    //外购进厂物料，发货单位含新区、老区、东区、西区、九江钢铁、江苏一同和众邦工厂，报检斤类型错误；
                    if (trackScale.meterTypeNo.Equals("001006001") || trackScale.meterTypeNo.Equals("001006008"))
                    {
                        if (trackScale.forwardingUnitName.Contains("东区") || trackScale.forwardingUnitName.Contains("新区")
                            || trackScale.forwardingUnitName.Contains("老区") || trackScale.forwardingUnitName.Contains("西区")
                            || trackScale.forwardingUnitName.Contains("九江钢铁") || trackScale.forwardingUnitName.Contains("江苏一同")
                            || trackScale.forwardingUnitName.Contains("众邦工厂"))
                        {
                            PbCache.ResultMessage = "检斤类型错误，【" + trackScale.meterTypeName + "】物料，发货单位【" + trackScale.forwardingUnitName + "】" +
                                "含新区、老区、东区、西区、九江钢铁、江苏一同和众邦工厂，不允许进行计量操作！";
                            return false;
                        }
                    }

                    //外销出厂物料，收货单位含新区、老区、东区、西区、九江钢铁、江苏一同和众邦工厂；报检斤类型错误，不允许保存。
                    if (trackScale.meterTypeNo.Equals("001006002") || trackScale.meterTypeNo.Equals("001006011"))
                    {
                        if (trackScale.receivingUintName.Contains("东区") || trackScale.receivingUintName.Contains("新区")
                            || trackScale.receivingUintName.Contains("老区") || trackScale.receivingUintName.Contains("西区")
                            || trackScale.receivingUintName.Contains("九江钢铁") || trackScale.receivingUintName.Contains("江苏一同")
                            || trackScale.receivingUintName.Contains("众邦工厂"))
                        {
                            PbCache.ResultMessage = "检斤类型错误，【" + trackScale.meterTypeName + "】物料，收货单位【" + trackScale.receivingUintName + "】" +
                                "含新区、老区、东区、西区、九江钢铁、江苏一同和众邦工厂，不允许进行计量操作！";
                            return false;
                        }
                    }
                }
                */
                return true;
            }
            catch (Exception ex)
            {
                PbCache.ResultMessage = "系统操作异常，请联系司秤工！" + ex.Message;
                return false;
            }
        }
    }
}
