using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Core.XgMes.Client.StorageBase;

namespace Core.XgMes.Client.JGKC.RollManager
{
    public partial class UCSendQueryJB : UserControl
    {
        public UCSendQueryJB()
        {
            InitializeComponent();
        }



        private string _WhereStr = "";
        public string WhereStr
        {
            get
            {
                _WhereStr = GetSteelCondition();
                _WhereStr = _WhereStr + GetPactNOCondition();
                _WhereStr = _WhereStr + GetSendDateCondition();
                _WhereStr = _WhereStr + GetBookInDateCondition();
                _WhereStr = _WhereStr + GetListCondingCondition();
                //_WhereStr = _WhereStr + GetIncpNameCondition();
                //_WhereStr = _WhereStr + GetStationNameCondition();
                _WhereStr = _WhereStr + GetRollNOCondition();
                _WhereStr = _WhereStr + GetPlyCondition();
                _WhereStr = _WhereStr + GetWidthCondition();
                _WhereStr = _WhereStr + GetLengthCondition();
                _WhereStr = _WhereStr + GetPlanNOCondition();
                _WhereStr = _WhereStr + GetVecihleNOCondition();
                _WhereStr = _WhereStr + GetClassTeamCondition();
                _WhereStr = _WhereStr + GetSendManCondition();
                _WhereStr = _WhereStr + GetSendType();
            
                _WhereStr = _WhereStr + GetCondole();
                _WhereStr = _WhereStr + GetBookInManCondition();
                _WhereStr = _WhereStr + GetGJH();
                //_WhereStr = _WhereStr + GetQuality();
                //_WhereStr = _WhereStr + GetPLCondition();
               // _WhereStr = _WhereStr + GetCutStateCondition();
                return _WhereStr;
            }
        }
        #region "Method"
     
        private string GetSteelCondition()
        {
            try
            {
                string rtnStr = "";
                if (this.Chk_SteelName.Checked && this.Cmb_SteelName.Text.Trim().Length > 0)
                {
                    rtnStr = " AND A.SPEC_STL_GRD LIKE '" + this.Cmb_SteelName.Text.Trim() + "%' ";
                }
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //合同号B
        private string GetPactNOCondition()
        {
            try
            {
                string rtnStr = "";
                if (this.Chk_PactNO.Checked && this.txt_PactNO.Text.Trim().Length > 0)
                {
                    rtnStr = " AND B.ORD_NO LIKE '%" + this.txt_PactNO.Text.Trim() + "%' ";
                }
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //发运日期A
        private string GetSendDateCondition()
        {
            try
            {
                string rtnStr = "";
                if (this.Chk_SendDate.Checked && this.Dte_SendBegin.Value != null)
                {
                    rtnStr = " AND TO_CHAR(A.PICKSTORAGETIME,'YY-MM-DD')>='" + Convert.ToDateTime(this.Dte_SendBegin.Value).ToString("yy-MM-dd") + "' "
                        + " AND TO_CHAR(A.PICKSTORAGETIME,'YY-MM-DD')<='" + Convert.ToDateTime(this.Dte_SendEnd.Value).ToString("yy-MM-dd") + "' ";
                }
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //登记日期A
        private string GetBookInDateCondition()
        {
            try
            {
                string rtnStr = "";
                if (this.Chk_BookInDate.Checked && this.Dte_BookInBegin.Value != null)
                {
                    rtnStr = " AND TO_CHAR(A.CREATETIME,'YY-MM-DD')>='" + Convert.ToDateTime(this.Dte_BookInBegin.Value).ToString("yy-MM-dd") + "' "
                        + " AND TO_CHAR(A.CREATETIME,'YY-MM-DD')<='" + Convert.ToDateTime(this.Dte_BookInEnd.Value).ToString("yy-MM-dd") + "' ";
                }
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //发运明细A
        private string GetListCondingCondition()
        {
            try
            {
                string rtnStr = "";
                if (this.Chk_ListCode.Checked && this.txt_ListCodingEnd.Text.Trim().Length > 0)
                {

                    rtnStr = " AND A.LISTNUMBER LIKE '%" + this.txt_ListCodingEnd.Text.Trim() + "%' ";
                }
               


                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
     
        ////收货单位C
        private string GetIncpNameCondition()
        {
            try
            {
                string rtnStr = "";
                if (this.Chk_IncpName.Checked && this.txt_IncpName.Text.Trim().Length > 0)
                {
                    rtnStr = " AND C.CUST_CD LIKE '%" + this.txt_IncpName.Text.Trim() + "%' ";
                }
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        ////到站D
        private string GetStationNameCondition()
        {
            try
            {
                string rtnStr = "";
                if (this.Chk_StationName.Checked && this.txt_StationName.Text.Trim().Length > 0)
                {
                    rtnStr = " AND D.SM_CD LIKE '%" + this.txt_StationName.Text.Trim() + "%' ";
                }
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //钢卷包号
        private string GetRollNOCondition()
        {
            try
            {
                string rtnStr = "";
                if (this.chk_RollNum.Checked && this.txt_BH.Text.Trim().Length > 0)
                {
                    rtnStr = " AND A.COIL_NO_ID LIKE '%" + this.txt_BH.Text.Trim() + "%' ";
                }
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //厚度
        private string GetPlyCondition()
        {
            try
            {
                if (this.chk_Ply.Checked)
                {
                    string rtnStr = "";
                    if (StorageBaseClass.CheckDecimal(this.txt_PlyBegin.Value) > 0 && StorageBaseClass.CheckDecimal(this.txt_PlyEnd.Value) == 0)
                    {
                        rtnStr = " AND A.ZSLAB_PLY=" + StorageBaseClass.CheckNullStr(this.txt_PlyBegin.Value);
                        return rtnStr;
                    }
                    if (StorageBaseClass.CheckDecimal(this.txt_PlyBegin.Value) == 0 && StorageBaseClass.CheckDecimal(this.txt_PlyEnd.Value) > 0)
                    {
                        rtnStr = " AND A.ZSLAB_PLY<=" + StorageBaseClass.CheckNullStr(this.txt_PlyEnd.Value);
                        return rtnStr;
                    }
                    if (StorageBaseClass.CheckDecimal(this.txt_PlyBegin.Value) > 0 && StorageBaseClass.CheckDecimal(this.txt_PlyEnd.Value) > 0)
                    {
                        rtnStr = " AND A.ZSLAB_PLY>=" + StorageBaseClass.CheckNullStr(this.txt_PlyBegin.Value)
                            + " AND A.ZSLAB_PLY<=" + StorageBaseClass.CheckNullStr(this.txt_PlyEnd.Value);
                        return rtnStr;
                    }
                }
                return "";
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //宽度
        private string GetWidthCondition()
        {
            try
            {
                if (this.chk_Width.Checked)
                {
                    string rtnStr = "";
                    if (StorageBaseClass.CheckDecimal(this.txt_WidthBegin.Value) > 0 && StorageBaseClass.CheckDecimal(this.txt_WidthEnd.Value) == 0)
                    {
                        rtnStr = " AND A.ZSLAB_WIDTH=" + StorageBaseClass.CheckNullStr(this.txt_WidthBegin.Value);
                        return rtnStr;
                    }
                    if (StorageBaseClass.CheckDecimal(this.txt_WidthBegin.Value) == 0 && StorageBaseClass.CheckDecimal(this.txt_WidthEnd.Value) > 0)
                    {
                        rtnStr = " AND A.ZSLAB_WIDTH<=" + StorageBaseClass.CheckNullStr(this.txt_WidthEnd.Value);
                        return rtnStr;
                    }
                    if (StorageBaseClass.CheckDecimal(this.txt_WidthBegin.Value) > 0 && StorageBaseClass.CheckDecimal(this.txt_WidthEnd.Value) > 0)
                    {
                        rtnStr = " AND A.ZSLAB_WIDTH>=" + StorageBaseClass.CheckNullStr(this.txt_WidthBegin.Value)
                            + " AND A.ZSLAB_WIDTH<=" + StorageBaseClass.CheckNullStr(this.txt_WidthEnd.Value);
                        return rtnStr;
                    }
                }
                return "";
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //长度
        private string GetLengthCondition()
        {
            try
            {
                if (this.chk_Length.Checked)
                {
                    string rtnStr = "";
                    if (StorageBaseClass.CheckDecimal(this.txt_LenghtBegin.Value) > 0 && StorageBaseClass.CheckDecimal(this.txt_LengthEnd.Value) == 0)
                    {
                        rtnStr = " AND A.ZSLAB_LENGTH=" + StorageBaseClass.CheckNullStr(this.txt_LenghtBegin.Value);
                        return rtnStr;
                    }
                    if (StorageBaseClass.CheckDecimal(this.txt_LenghtBegin.Value) == 0 && StorageBaseClass.CheckDecimal(this.txt_LengthEnd.Value) > 0)
                    {
                        rtnStr = " AND A.ZSLAB_LENGTH<=" + StorageBaseClass.CheckNullStr(this.txt_LengthEnd.Value);
                        return rtnStr;
                    }
                    if (StorageBaseClass.CheckDecimal(this.txt_LenghtBegin.Value) > 0 && StorageBaseClass.CheckDecimal(this.txt_LengthEnd.Value) > 0)
                    {
                        rtnStr = " AND A.ZSLAB_LENGTH>=" + StorageBaseClass.CheckNullStr(this.txt_LenghtBegin.Value)
                            + " AND A.ZSLAB_LENGTH<=" + StorageBaseClass.CheckNullStr(this.txt_LengthEnd.Value);
                        return rtnStr;
                    }
                }
                return "";
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //批号
        private string GetPlanNOCondition()
        {
            try
            {
                string rtnStr = "";
                if (this.Chk_Condole.Checked && this.Txt_Condole.Text.Trim().Length > 0)
                {
                    rtnStr = " AND A.SLAB_NO LIKE '%" + this.Txt_Condole.Text.Trim() + "%' ";
                }
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //车牌号
        private string GetVecihleNOCondition()
        {
            try
            {
                string rtnStr = "";
                if (this.Chk_VecihleNO.Checked && this.txt_VecihleNO.Text.Trim().Length > 0)
                {
                    rtnStr = " AND A.TRAINWAGON LIKE '%" + this.txt_VecihleNO.Text.Trim() + "%' ";
                }
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //班组
        private string GetClassTeamCondition()
        {
            try
            {
                string rtnStr = "";
                if (this.Chk_ClassTeam.Checked && StorageBaseClass.CheckNullStr(this.Cmb_ClassTeam.Value).Length > 0)
                {
                    rtnStr = " AND A.CLASSTEAM='" + StorageBaseClass.CheckNullStr(this.Cmb_ClassTeam.Value) + "' ";
                }
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //发运人
        private string GetSendManCondition()
        {
            try
            {
                string rtnStr = "";
                if (this.Chk_SendMan.Checked && this.txt_SendMan.Text.Trim().Length > 0)
                {
                    rtnStr = " AND A.PICKSTORAGEMAN='" + this.txt_SendMan.Text.Trim() + "' ";
                }
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //发运明细的登记人
        private string GetBookInManCondition()
        {
            try
            {
                string rtnStr = "";
                if (this.Chk_BookInMan.Checked && this.txt_BookInMan.Text.Trim().Length > 0)
                {
                    rtnStr = " AND A.CREATOR='" + this.txt_BookInMan.Text.Trim() + "' ";
                }
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //钢卷号
        private string GetGJH()
        {
            try
            {
                string rtnStr = "";
                if (this.ultChk_SampleNo.Checked && this.txt_SampleNo.Text.Trim().Length > 0)
                {
                    rtnStr = " AND A.OLD_SAMPL_NO LIKE '" + this.txt_SampleNo.Text.Trim() + "%' ";
                }
                
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //获得发运类型的条件
        private string GetSendType()
        {
            try
            {
                string rtnStr = "";
                if (this.Chk_SendType.Checked && StorageBaseClass.CheckNullStr(this.Cmb_SendType.Value).Length > 0)
                {
                    rtnStr = " AND A.SENDTYPE='" + StorageBaseClass.CheckNullStr(this.Cmb_SendType.Value) + "' ";
                }
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }
        //发运号码
        private string GetCondole()
        {
            try
            {
                string rtnStr = "";
                if (this.chk_SendNo.Checked && this.txt_SendNo.Text.Length > 0)
                {
                    rtnStr = " AND A.PLANVEHICLEID LIKE '%" + this.txt_SendNo.Text + "%' ";
                }
                return rtnStr;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return "";
            }
        }

        private void UCSendQueryJB_Load(object sender, EventArgs e)
        {
            this.Cmb_SendType.Value = "0";
        }
        //获得是正品还是次品的条件
        //private string GetQuality()
        //{
        //    try
        //    {
        //        if ((this.Chk_IsGood.Checked && this.Chk_IsWaster.Checked) | (!this.Chk_IsGood.Checked && !this.Chk_IsWaster.Checked))
        //            return "";
        //        if (this.Chk_IsWaster.Checked)
        //            return " AND (A.CLIPTYPEPROCESS LIKE '10301%' OR A.DETERMINANTRESULT LIKE '401403%' OR A.DETERMINANTRESULT LIKE '401404%') ";
        //        if (this.Chk_IsGood.Checked)
        //            return " AND (A.CLIPTYPEPROCESS NOT LIKE '10301%'  AND A.DETERMINANTRESULT  LIKE '401401%') ";
        //        return "";
        //    }
        //    catch (System.Exception ex)
        //    {
        //        System.Diagnostics.Debug.WriteLine(ex.ToString());
        //        return "";
        //    }
        //}
        #endregion
    }
}
