Ejemplo n.º 1
0
    private string GetSqlTHD()
    {
        string Sql_THD = "";

        //仓库
        if (!string.IsNullOrEmpty(this.hidCKH.Value))
        {
            Sql_THD += " CK ='" + hidCKH.Value + "' ";
        }
        //制单人
        if (!string.IsNullOrEmpty(this.hidZDR.Value))
        {
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " AND NCZDRY='" + this.hidZDR.Value.Trim() + "'";
            }
            else
            {
                Sql_THD += " NCZDRY ='" + this.hidZDR.Value.Trim() + "'";
            }
        }
        //发运单
        if (!string.IsNullOrEmpty(this.hidFYDH.Value))
        {
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " AND CKDH like '%" + this.hidFYDH.Value.Trim() + "%'";
            }
            else
            {
                Sql_THD += " CKDH like '%" + this.hidFYDH.Value.Trim() + "%'";
            }
        }
        //部门
        if (!string.IsNullOrEmpty(this.hidBM.Value))
        {
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " AND NCBM='" + this.hidBM.Value.Trim() + "'";
            }
            else
            {
                Sql_THD += " NCBM ='" + this.hidBM.Value.Trim() + "'";
            }
        }
        //退货单
        if (!string.IsNullOrEmpty(this.hidTHDH.Value))
        {
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " AND THDH like '%" + this.hidTHDH.Value.Trim() + "%'";
            }
            else
            {
                Sql_THD += " THDH like '%" + this.hidTHDH.Value.Trim() + "%'";
            }
        }
        //牌号
        if (!string.IsNullOrEmpty(this.hidPH.Value))
        {
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " AND PH like '%" + this.hidPH.Value.Trim() + "%'";
            }
            else
            {
                Sql_THD += " PH like '%" + this.hidPH.Value.Trim() + "%'";
            }
        }
        //物料号
        if (!string.IsNullOrEmpty(this.hidWLH.Value))
        {
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " AND WLH like '%" + this.hidWLH.Value.Trim() + "%'";
            }
            else
            {
                Sql_THD += " WLH like '%" + this.hidWLH.Value.Trim() + "%'";
            }
        }
        //规格
        if (!string.IsNullOrEmpty(this.hidGG.Value))
        {
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " AND GG like '%" + this.hidGG.Value.Trim() + "%'";
            }
            else
            {
                Sql_THD += " GG like '%" + this.hidGG.Value.Trim() + "%'";
            }
        }
        //属性
        if (!string.IsNullOrEmpty(this.hidSX.Value))
        {
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " AND SX like '%" + this.hidSX.Value.Trim() + "%'";
            }
            else
            {
                Sql_THD += " SX like '%" + this.hidSX.Value.Trim() + "%'";
            }
        }
        //客户号
        if (!string.IsNullOrEmpty(this.hidKHH.Value))
        {
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " AND KHBM like '%" + this.hidKHH.Value.Trim() + "%'";
            }
            else
            {
                Sql_THD += " KHBM ='%" + this.hidKHH.Value.Trim() + "%'";
            }
        }
        //IC卡号
        if (!string.IsNullOrEmpty(this.hidICKH.Value))
        {
            string ickhbm = "ACCTRUEWMS";
            try
            {
                DataSet ds = THDQuery.GetTHDIC(this.hidICKH.Value.Trim());
                if (ds != null)
                {
                    ickhbm = ds.Tables[0].Rows[0]["KHID"].ToString();
                }
            }
            catch
            {
                this.PrintfError("访问数据错误!");
            }
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " and KHBM='" + ickhbm + "'";
            }
            else
            {
                Sql_THD += " KHBM='" + ickhbm + "'";
            }
        }

        //退货日期
        if (this.chkTuiHuoRQ.Checked && !string.IsNullOrEmpty(this.TuiHuo_Start.Text))
        {
            string TuiHuo_Start = this.TuiHuo_Start.Text.Trim() + " 00:00:00";
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " AND CZRQ >='" + TuiHuo_Start + "'";
            }
            else
            {
                Sql_THD += " CZRQ >='" + TuiHuo_Start + "'";
            }
        }
        if (this.chkTuiHuoRQ.Checked && !string.IsNullOrEmpty(this.TuiHuo_End.Text.Trim()))
        {
            string TuiHuo_End = this.TuiHuo_End.Text.Trim() + " 23:59:59";
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " AND CZRQ <='" + TuiHuo_End + "'";
            }
            else
            {
                Sql_THD += " CZRQ >='" + TuiHuo_End + "'";
            }
        }
        //自由项1
        if (this.chkFree1.Checked && !string.IsNullOrEmpty(this.txtFree1.Text))
        {
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " AND vfree1 like '%" + this.txtFree1.Text.Trim() + "%'";
            }
            else
            {
                Sql_THD += " vfree1 like '%" + this.txtFree1.Text.Trim() + "%'";
            }
        }
        //自由项2
        if (this.chkFree2.Checked && !string.IsNullOrEmpty(this.txtFree2.Text))
        {
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " AND vfree2 like '%" + this.txtFree2.Text.Trim() + "%'";
            }
            else
            {
                Sql_THD += " vfree2 like '%" + this.txtFree2.Text.Trim() + "%'";
            }
        }
        //自由项3
        if (this.chkFree3.Checked && !string.IsNullOrEmpty(this.txtFree3.Text))
        {
            if (!string.IsNullOrEmpty(Sql_THD))
            {
                Sql_THD += " AND vfree3 like '%" + this.txtFree3.Text.Trim() + "%'";
            }
            else
            {
                Sql_THD += " vfree3 like '%" + this.txtFree3.Text.Trim() + "%'";
            }
        }
        return(Sql_THD);
    }