internal virtual StringBuilder GetAutoPropertyFilterString()
        {
            var res = new StringBuilder();

            if (AsycudaDocumentIdFilter.HasValue)
            {
                res.Append(" && " + string.Format("AsycudaDocumentId == {0}", AsycudaDocumentIdFilter.ToString()));
            }

            if (!string.IsNullOrEmpty(LineNumberFilter))
            {
                res.Append(" && " + string.Format("LineNumber == {0}", LineNumberFilter));
            }

            if (IsAssessedFilter.HasValue)
            {
                res.Append(" && " + string.Format("IsAssessed == {0}", IsAssessedFilter));
            }


            if (DoNotAllocateFilter.HasValue)
            {
                res.Append(" && " + string.Format("DoNotAllocate == {0}", DoNotAllocateFilter));
            }


            if (DoNotEXFilter.HasValue)
            {
                res.Append(" && " + string.Format("DoNotEX == {0}", DoNotEXFilter));
            }


            if (AttributeOnlyAllocationFilter.HasValue)
            {
                res.Append(" && " + string.Format("AttributeOnlyAllocation == {0}", AttributeOnlyAllocationFilter));
            }


            if (string.IsNullOrEmpty(Description_of_goodsFilter) == false)
            {
                res.Append(" && " + string.Format("Description_of_goods.Contains(\"{0}\")", Description_of_goodsFilter));
            }


            if (string.IsNullOrEmpty(Commercial_DescriptionFilter) == false)
            {
                res.Append(" && " + string.Format("Commercial_Description.Contains(\"{0}\")", Commercial_DescriptionFilter));
            }


            if (Gross_weight_itmFilter.HasValue)
            {
                res.Append(" && " + string.Format("Gross_weight_itm == {0}", Gross_weight_itmFilter.ToString()));
            }

            if (Net_weight_itmFilter.HasValue)
            {
                res.Append(" && " + string.Format("Net_weight_itm == {0}", Net_weight_itmFilter.ToString()));
            }

            if (Item_priceFilter.HasValue)
            {
                res.Append(" && " + string.Format("Item_price == {0}", Item_priceFilter.ToString()));
            }

            if (ItemQuantityFilter.HasValue)
            {
                res.Append(" && " + string.Format("ItemQuantity == {0}", ItemQuantityFilter.ToString()));
            }

            if (string.IsNullOrEmpty(Suppplementary_unit_codeFilter) == false)
            {
                res.Append(" && " + string.Format("Suppplementary_unit_code.Contains(\"{0}\")", Suppplementary_unit_codeFilter));
            }


            if (string.IsNullOrEmpty(ItemNumberFilter) == false)
            {
                res.Append(" && " + string.Format("ItemNumber.Contains(\"{0}\")", ItemNumberFilter));
            }


            if (string.IsNullOrEmpty(TariffCodeFilter) == false)
            {
                res.Append(" && " + string.Format("TariffCode.Contains(\"{0}\")", TariffCodeFilter));
            }


            if (TariffCodeLicenseRequiredFilter.HasValue)
            {
                res.Append(" && " + string.Format("TariffCodeLicenseRequired == {0}", TariffCodeLicenseRequiredFilter));
            }


            if (TariffCategoryLicenseRequiredFilter.HasValue)
            {
                res.Append(" && " + string.Format("TariffCategoryLicenseRequired == {0}", TariffCategoryLicenseRequiredFilter));
            }


            if (string.IsNullOrEmpty(TariffCodeDescriptionFilter) == false)
            {
                res.Append(" && " + string.Format("TariffCodeDescription.Contains(\"{0}\")", TariffCodeDescriptionFilter));
            }


            if (DutyLiabilityFilter.HasValue)
            {
                res.Append(" && " + string.Format("DutyLiability == {0}", DutyLiabilityFilter.ToString()));
            }

            if (Total_CIF_itmFilter.HasValue)
            {
                res.Append(" && " + string.Format("Total_CIF_itm == {0}", Total_CIF_itmFilter.ToString()));
            }

            if (FreightFilter.HasValue)
            {
                res.Append(" && " + string.Format("Freight == {0}", FreightFilter.ToString()));
            }

            if (Statistical_valueFilter.HasValue)
            {
                res.Append(" && " + string.Format("Statistical_value == {0}", Statistical_valueFilter.ToString()));
            }

            if (DPQtyAllocatedFilter.HasValue)
            {
                res.Append(" && " + string.Format("DPQtyAllocated == {0}", DPQtyAllocatedFilter.ToString()));
            }

            if (DFQtyAllocatedFilter.HasValue)
            {
                res.Append(" && " + string.Format("DFQtyAllocated == {0}", DFQtyAllocatedFilter.ToString()));
            }

            if (PiQuantityFilter.HasValue)
            {
                res.Append(" && " + string.Format("PiQuantity == {0}", PiQuantityFilter.ToString()));
            }

            if (ImportCompleteFilter.HasValue)
            {
                res.Append(" && " + string.Format("ImportComplete == {0}", ImportCompleteFilter));
            }


            if (string.IsNullOrEmpty(CNumberFilter) == false)
            {
                res.Append(" && " + string.Format("CNumber.Contains(\"{0}\")", CNumberFilter));
            }



            if (Convert.ToDateTime(StartRegistrationDateFilter).Date != DateTime.MinValue &&
                Convert.ToDateTime(EndRegistrationDateFilter).Date != DateTime.MinValue)
            {
                res.Append(" && (");
            }

            if (Convert.ToDateTime(StartRegistrationDateFilter).Date != DateTime.MinValue)
            {
                if (StartRegistrationDateFilter.HasValue)
                {
                    res.Append(
                        (Convert.ToDateTime(EndRegistrationDateFilter).Date != DateTime.MinValue?"":" && ") +
                        string.Format("RegistrationDate >= \"{0}\"", Convert.ToDateTime(StartRegistrationDateFilter).Date.ToString("MM/dd/yyyy")));
                }
            }

            if (Convert.ToDateTime(EndRegistrationDateFilter).Date != DateTime.MinValue)
            {
                if (EndRegistrationDateFilter.HasValue)
                {
                    res.Append(" && " + string.Format("RegistrationDate <= \"{0}\"", Convert.ToDateTime(EndRegistrationDateFilter).Date.AddHours(23).ToString("MM/dd/yyyy HH:mm:ss")));
                }
            }

            if (Convert.ToDateTime(StartRegistrationDateFilter).Date != DateTime.MinValue &&
                Convert.ToDateTime(EndRegistrationDateFilter).Date != DateTime.MinValue)
            {
                res.Append(" )");
            }

            if (Convert.ToDateTime(_registrationDateFilter).Date != DateTime.MinValue)
            {
                if (RegistrationDateFilter.HasValue)
                {
                    res.Append(" && " + string.Format("RegistrationDate == \"{0}\"", Convert.ToDateTime(RegistrationDateFilter).Date.ToString("MM/dd/yyyy")));
                }
            }


            if (Number_of_packagesFilter.HasValue)
            {
                res.Append(" && " + string.Format("Number_of_packages == {0}", Number_of_packagesFilter.ToString()));
            }

            if (string.IsNullOrEmpty(Country_of_origin_codeFilter) == false)
            {
                res.Append(" && " + string.Format("Country_of_origin_code.Contains(\"{0}\")", Country_of_origin_codeFilter));
            }


            if (PiWeightFilter.HasValue)
            {
                res.Append(" && " + string.Format("PiWeight == {0}", PiWeightFilter.ToString()));
            }

            if (Currency_rateFilter.HasValue)
            {
                res.Append(" && " + string.Format("Currency_rate == {0}", Currency_rateFilter.ToString()));
            }

            if (string.IsNullOrEmpty(Currency_codeFilter) == false)
            {
                res.Append(" && " + string.Format("Currency_code.Contains(\"{0}\")", Currency_codeFilter));
            }


            if (InvalidHSCodeFilter.HasValue)
            {
                res.Append(" && " + string.Format("InvalidHSCode == {0}", InvalidHSCodeFilter));
            }


            if (string.IsNullOrEmpty(WarehouseErrorFilter) == false)
            {
                res.Append(" && " + string.Format("WarehouseError.Contains(\"{0}\")", WarehouseErrorFilter));
            }
            return(res.ToString().StartsWith(" &&") || res.Length == 0 ? res:  res.Insert(0, " && "));
        }
        internal virtual StringBuilder GetAutoPropertyFilterString()
        {
            var res = new StringBuilder();


            if (string.IsNullOrEmpty(Amount_deducted_from_licenceFilter) == false)
            {
                res.Append(" && " + string.Format("Amount_deducted_from_licence.Contains(\"{0}\")", Amount_deducted_from_licenceFilter));
            }


            if (string.IsNullOrEmpty(Licence_numberFilter) == false)
            {
                res.Append(" && " + string.Format("Licence_number.Contains(\"{0}\")", Licence_numberFilter));
            }


            if (string.IsNullOrEmpty(Free_text_1Filter) == false)
            {
                res.Append(" && " + string.Format("Free_text_1.Contains(\"{0}\")", Free_text_1Filter));
            }


            if (string.IsNullOrEmpty(Free_text_2Filter) == false)
            {
                res.Append(" && " + string.Format("Free_text_2.Contains(\"{0}\")", Free_text_2Filter));
            }


            if (LineNumberFilter.HasValue)
            {
                res.Append(" && " + string.Format("LineNumber == {0}", LineNumberFilter.ToString()));
            }

            if (IsAssessedFilter.HasValue)
            {
                res.Append(" && " + string.Format("IsAssessed == {0}", IsAssessedFilter));
            }


            if (DPQtyAllocatedFilter.HasValue)
            {
                res.Append(" && " + string.Format("DPQtyAllocated == {0}", DPQtyAllocatedFilter.ToString()));
            }

            if (DFQtyAllocatedFilter.HasValue)
            {
                res.Append(" && " + string.Format("DFQtyAllocated == {0}", DFQtyAllocatedFilter.ToString()));
            }



            if (Convert.ToDateTime(StartEntryTimeStampFilter).Date != DateTime.MinValue &&
                Convert.ToDateTime(EndEntryTimeStampFilter).Date != DateTime.MinValue)
            {
                res.Append(" && (");
            }

            if (Convert.ToDateTime(StartEntryTimeStampFilter).Date != DateTime.MinValue)
            {
                if (StartEntryTimeStampFilter.HasValue)
                {
                    res.Append(
                        (Convert.ToDateTime(EndEntryTimeStampFilter).Date != DateTime.MinValue?"":" && ") +
                        string.Format("EntryTimeStamp >= \"{0}\"", Convert.ToDateTime(StartEntryTimeStampFilter).Date.ToString("MM/dd/yyyy")));
                }
            }

            if (Convert.ToDateTime(EndEntryTimeStampFilter).Date != DateTime.MinValue)
            {
                if (EndEntryTimeStampFilter.HasValue)
                {
                    res.Append(" && " + string.Format("EntryTimeStamp <= \"{0}\"", Convert.ToDateTime(EndEntryTimeStampFilter).Date.AddHours(23).ToString("MM/dd/yyyy HH:mm:ss")));
                }
            }

            if (Convert.ToDateTime(StartEntryTimeStampFilter).Date != DateTime.MinValue &&
                Convert.ToDateTime(EndEntryTimeStampFilter).Date != DateTime.MinValue)
            {
                res.Append(" )");
            }

            if (Convert.ToDateTime(_entryTimeStampFilter).Date != DateTime.MinValue)
            {
                if (EntryTimeStampFilter.HasValue)
                {
                    res.Append(" && " + string.Format("EntryTimeStamp == \"{0}\"", Convert.ToDateTime(EntryTimeStampFilter).Date.ToString("MM/dd/yyyy")));
                }
            }


            if (AttributeOnlyAllocationFilter.HasValue)
            {
                res.Append(" && " + string.Format("AttributeOnlyAllocation == {0}", AttributeOnlyAllocationFilter));
            }


            if (DoNotAllocateFilter.HasValue)
            {
                res.Append(" && " + string.Format("DoNotAllocate == {0}", DoNotAllocateFilter));
            }


            if (DoNotEXFilter.HasValue)
            {
                res.Append(" && " + string.Format("DoNotEX == {0}", DoNotEXFilter));
            }


            if (Item_priceFilter.HasValue)
            {
                res.Append(" && " + string.Format("Item_price == {0}", Item_priceFilter.ToString()));
            }

            if (string.IsNullOrEmpty(ItemNumberFilter) == false)
            {
                res.Append(" && " + string.Format("ItemNumber.Contains(\"{0}\")", ItemNumberFilter));
            }


            if (string.IsNullOrEmpty(TariffCodeFilter) == false)
            {
                res.Append(" && " + string.Format("TariffCode.Contains(\"{0}\")", TariffCodeFilter));
            }


            if (DutyLiabilityFilter.HasValue)
            {
                res.Append(" && " + string.Format("DutyLiability == {0}", DutyLiabilityFilter.ToString()));
            }

            if (Total_CIF_itmFilter.HasValue)
            {
                res.Append(" && " + string.Format("Total_CIF_itm == {0}", Total_CIF_itmFilter.ToString()));
            }

            if (FreightFilter.HasValue)
            {
                res.Append(" && " + string.Format("Freight == {0}", FreightFilter.ToString()));
            }

            if (Statistical_valueFilter.HasValue)
            {
                res.Append(" && " + string.Format("Statistical_value == {0}", Statistical_valueFilter.ToString()));
            }

            if (PiQuantityFilter.HasValue)
            {
                res.Append(" && " + string.Format("PiQuantity == {0}", PiQuantityFilter.ToString()));
            }

            if (string.IsNullOrEmpty(Description_of_goodsFilter) == false)
            {
                res.Append(" && " + string.Format("Description_of_goods.Contains(\"{0}\")", Description_of_goodsFilter));
            }


            if (string.IsNullOrEmpty(Commercial_DescriptionFilter) == false)
            {
                res.Append(" && " + string.Format("Commercial_Description.Contains(\"{0}\")", Commercial_DescriptionFilter));
            }


            if (string.IsNullOrEmpty(Suppplementary_unit_codeFilter) == false)
            {
                res.Append(" && " + string.Format("Suppplementary_unit_code.Contains(\"{0}\")", Suppplementary_unit_codeFilter));
            }


            if (ItemQuantityFilter.HasValue)
            {
                res.Append(" && " + string.Format("ItemQuantity == {0}", ItemQuantityFilter.ToString()));
            }

            if (string.IsNullOrEmpty(NumberFilter) == false)
            {
                res.Append(" && " + string.Format("Number.Contains(\"{0}\")", NumberFilter));
            }


            if (string.IsNullOrEmpty(DocumentTypeFilter) == false)
            {
                res.Append(" && " + string.Format("DocumentType.Contains(\"{0}\")", DocumentTypeFilter));
            }
            return(res.ToString().StartsWith(" &&") || res.Length == 0 ? res:  res.Insert(0, " && "));
        }
        internal virtual StringBuilder GetAutoPropertyFilterString()
        {
            var res = new StringBuilder();


            if (LineNumberFilter.HasValue)
            {
                res.Append(" && " + string.Format("LineNumber == {0}", LineNumberFilter.ToString()));
            }

            if (IsAssessedFilter.HasValue)
            {
                res.Append(" && " + string.Format("IsAssessed == {0}", IsAssessedFilter));
            }


            if (DoNotAllocateFilter.HasValue)
            {
                res.Append(" && " + string.Format("DoNotAllocate == {0}", DoNotAllocateFilter));
            }


            if (DoNotEXFilter.HasValue)
            {
                res.Append(" && " + string.Format("DoNotEX == {0}", DoNotEXFilter));
            }


            if (AttributeOnlyAllocationFilter.HasValue)
            {
                res.Append(" && " + string.Format("AttributeOnlyAllocation == {0}", AttributeOnlyAllocationFilter));
            }


            if (string.IsNullOrEmpty(Description_of_goodsFilter) == false)
            {
                res.Append(" && " + string.Format("Description_of_goods.Contains(\"{0}\")", Description_of_goodsFilter));
            }


            if (string.IsNullOrEmpty(Commercial_DescriptionFilter) == false)
            {
                res.Append(" && " + string.Format("Commercial_Description.Contains(\"{0}\")", Commercial_DescriptionFilter));
            }


            if (Gross_weight_itmFilter.HasValue)
            {
                res.Append(" && " + string.Format("Gross_weight_itm == {0}", Gross_weight_itmFilter.ToString()));
            }

            if (Net_weight_itmFilter.HasValue)
            {
                res.Append(" && " + string.Format("Net_weight_itm == {0}", Net_weight_itmFilter.ToString()));
            }

            if (Item_priceFilter.HasValue)
            {
                res.Append(" && " + string.Format("Item_price == {0}", Item_priceFilter.ToString()));
            }

            if (ItemQuantityFilter.HasValue)
            {
                res.Append(" && " + string.Format("ItemQuantity == {0}", ItemQuantityFilter.ToString()));
            }

            if (string.IsNullOrEmpty(Suppplementary_unit_codeFilter) == false)
            {
                res.Append(" && " + string.Format("Suppplementary_unit_code.Contains(\"{0}\")", Suppplementary_unit_codeFilter));
            }


            if (string.IsNullOrEmpty(ItemNumberFilter) == false)
            {
                res.Append(" && " + string.Format("ItemNumber.Contains(\"{0}\")", ItemNumberFilter));
            }


            if (string.IsNullOrEmpty(TariffCodeFilter) == false)
            {
                res.Append(" && " + string.Format("TariffCode.Contains(\"{0}\")", TariffCodeFilter));
            }


            if (TariffCodeLicenseRequiredFilter.HasValue)
            {
                res.Append(" && " + string.Format("TariffCodeLicenseRequired == {0}", TariffCodeLicenseRequiredFilter));
            }


            if (TariffCategoryLicenseRequiredFilter.HasValue)
            {
                res.Append(" && " + string.Format("TariffCategoryLicenseRequired == {0}", TariffCategoryLicenseRequiredFilter));
            }


            if (string.IsNullOrEmpty(TariffCodeDescriptionFilter) == false)
            {
                res.Append(" && " + string.Format("TariffCodeDescription.Contains(\"{0}\")", TariffCodeDescriptionFilter));
            }


            if (DutyLiabilityFilter.HasValue)
            {
                res.Append(" && " + string.Format("DutyLiability == {0}", DutyLiabilityFilter.ToString()));
            }

            if (Total_CIF_itmFilter.HasValue)
            {
                res.Append(" && " + string.Format("Total_CIF_itm == {0}", Total_CIF_itmFilter.ToString()));
            }

            if (FreightFilter.HasValue)
            {
                res.Append(" && " + string.Format("Freight == {0}", FreightFilter.ToString()));
            }

            if (Statistical_valueFilter.HasValue)
            {
                res.Append(" && " + string.Format("Statistical_value == {0}", Statistical_valueFilter.ToString()));
            }

            if (DPQtyAllocatedFilter.HasValue)
            {
                res.Append(" && " + string.Format("DPQtyAllocated == {0}", DPQtyAllocatedFilter.ToString()));
            }

            if (DFQtyAllocatedFilter.HasValue)
            {
                res.Append(" && " + string.Format("DFQtyAllocated == {0}", DFQtyAllocatedFilter.ToString()));
            }

            if (PiQuantityFilter.HasValue)
            {
                res.Append(" && " + string.Format("PiQuantity == {0}", PiQuantityFilter.ToString()));
            }

            if (ImportCompleteFilter.HasValue)
            {
                res.Append(" && " + string.Format("ImportComplete == {0}", ImportCompleteFilter));
            }
            return(res.ToString().StartsWith(" &&") || res.Length == 0 ? res:  res.Insert(0, " && "));
        }
        internal virtual StringBuilder GetAutoPropertyFilterString()
        {
            var res = new StringBuilder();


            if (TotalValueFilter.HasValue)
            {
                res.Append(" && " + string.Format("TotalValue == {0}", TotalValueFilter.ToString()));
            }

            if (AllocatedValueFilter.HasValue)
            {
                res.Append(" && " + string.Format("AllocatedValue == {0}", AllocatedValueFilter.ToString()));
            }

            if (string.IsNullOrEmpty(StatusFilter) == false)
            {
                res.Append(" && " + string.Format("Status.Contains(\"{0}\")", StatusFilter));
            }


            if (QtyAllocatedFilter.HasValue)
            {
                res.Append(" && " + string.Format("QtyAllocated == {0}", QtyAllocatedFilter.ToString()));
            }



            if (Convert.ToDateTime(StartInvoiceDateFilter).Date != DateTime.MinValue &&
                Convert.ToDateTime(EndInvoiceDateFilter).Date != DateTime.MinValue)
            {
                res.Append(" && (");
            }

            if (Convert.ToDateTime(StartInvoiceDateFilter).Date != DateTime.MinValue)
            {
                if (StartInvoiceDateFilter.HasValue)
                {
                    res.Append(
                        (Convert.ToDateTime(EndInvoiceDateFilter).Date != DateTime.MinValue ? "" : " && ") +
                        string.Format("InvoiceDate >= \"{0}\"",
                                      Convert.ToDateTime(StartInvoiceDateFilter).Date.ToString("MM/dd/yyyy")));
                }
            }

            if (Convert.ToDateTime(EndInvoiceDateFilter).Date != DateTime.MinValue)
            {
                if (EndInvoiceDateFilter.HasValue)
                {
                    res.Append(" && " + string.Format("InvoiceDate <= \"{0}\"",
                                                      Convert.ToDateTime(EndInvoiceDateFilter).Date.AddHours(23).ToString("MM/dd/yyyy HH:mm:ss")));
                }
            }

            if (Convert.ToDateTime(StartInvoiceDateFilter).Date != DateTime.MinValue &&
                Convert.ToDateTime(EndInvoiceDateFilter).Date != DateTime.MinValue)
            {
                res.Append(" )");
            }

            if (Convert.ToDateTime(_invoiceDateFilter).Date != DateTime.MinValue)
            {
                if (InvoiceDateFilter.HasValue)
                {
                    res.Append(" && " + string.Format("InvoiceDate == \"{0}\"",
                                                      Convert.ToDateTime(InvoiceDateFilter).Date.ToString("MM/dd/yyyy")));
                }
            }


            if (SalesQuantityFilter.HasValue)
            {
                res.Append(" && " + string.Format("SalesQuantity == {0}", SalesQuantityFilter.ToString()));
            }

            if (SalesQtyAllocatedFilter.HasValue)
            {
                res.Append(" && " + string.Format("SalesQtyAllocated == {0}", SalesQtyAllocatedFilter.ToString()));
            }

            if (string.IsNullOrEmpty(InvoiceNoFilter) == false)
            {
                res.Append(" && " + string.Format("InvoiceNo.Contains(\"{0}\")", InvoiceNoFilter));
            }


            if (string.IsNullOrEmpty(ItemNumberFilter) == false)
            {
                res.Append(" && " + string.Format("ItemNumber.Contains(\"{0}\")", ItemNumberFilter));
            }


            if (string.IsNullOrEmpty(ItemDescriptionFilter) == false)
            {
                res.Append(" && " + string.Format("ItemDescription.Contains(\"{0}\")", ItemDescriptionFilter));
            }


            if (string.IsNullOrEmpty(DutyFreePaidFilter) == false)
            {
                res.Append(" && " + string.Format("DutyFreePaid.Contains(\"{0}\")", DutyFreePaidFilter));
            }


            if (TaxAmountFilter.HasValue)
            {
                res.Append(" && " + string.Format("TaxAmount == {0}", TaxAmountFilter.ToString()));
            }

            if (CostFilter.HasValue)
            {
                res.Append(" && " + string.Format("Cost == {0}", CostFilter.ToString()));
            }

            if (DoNotAllocateSalesFilter.HasValue)
            {
                res.Append(" && " + string.Format("DoNotAllocateSales == {0}", DoNotAllocateSalesFilter));
            }

            if (SANumberFilter.HasValue)
            {
                res.Append(" && " + string.Format("SANumber == {0}", SANumberFilter.ToString()));
            }



            if (string.IsNullOrEmpty(pCNumberFilter) == false)
            {
                res.Append(" && " + string.Format("pCNumber.Contains(\"{0}\")", pCNumberFilter));
            }

            if (Convert.ToDateTime(StartpRegistrationDateFilter).Date != DateTime.MinValue &&
                Convert.ToDateTime(EndpRegistrationDateFilter).Date != DateTime.MinValue)
            {
                res.Append(" && (");
            }

            if (Convert.ToDateTime(StartpRegistrationDateFilter).Date != DateTime.MinValue)
            {
                if (StartpRegistrationDateFilter.HasValue)
                {
                    res.Append(
                        (Convert.ToDateTime(EndpRegistrationDateFilter).Date != DateTime.MinValue ? "" : " && ") +
                        string.Format("pRegistrationDate >= \"{0}\"",
                                      Convert.ToDateTime(StartpRegistrationDateFilter).Date.ToString("MM/dd/yyyy")));
                }
            }

            if (Convert.ToDateTime(EndpRegistrationDateFilter).Date != DateTime.MinValue)
            {
                if (EndpRegistrationDateFilter.HasValue)
                {
                    res.Append(" && " + string.Format("pRegistrationDate <= \"{0}\"",
                                                      Convert.ToDateTime(EndpRegistrationDateFilter).Date.AddHours(23)
                                                      .ToString("MM/dd/yyyy")));
                }
            }

            if (Convert.ToDateTime(StartpRegistrationDateFilter).Date != DateTime.MinValue &&
                Convert.ToDateTime(EndpRegistrationDateFilter).Date != DateTime.MinValue)
            {
                res.Append(" )");
            }

            if (Convert.ToDateTime(_pRegistrationDateFilter).Date != DateTime.MinValue)
            {
                if (pRegistrationDateFilter.HasValue)
                {
                    res.Append(" && " + string.Format("pRegistrationDate == \"{0}\"",
                                                      Convert.ToDateTime(pRegistrationDateFilter).Date.ToString("MM/dd/yyyy")));
                }
            }


            if (pQuantityFilter.HasValue)
            {
                res.Append(" && " + string.Format("pQuantity == {0}", pQuantityFilter.ToString()));
            }

            if (pQtyAllocatedFilter.HasValue)
            {
                res.Append(" && " + string.Format("pQtyAllocated == {0}", pQtyAllocatedFilter.ToString()));
            }

            if (PiQuantityFilter.HasValue)
            {
                res.Append(" && " + string.Format("PiQuantity == {0}", PiQuantityFilter.ToString()));
            }

            if (string.IsNullOrEmpty(TariffCodeFilter) == false)
            {
                res.Append(" && " + string.Format("TariffCode.Contains(\"{0}\")", TariffCodeFilter));
            }


            if (InvalidFilter.HasValue)
            {
                res.Append(" && " + string.Format("Invalid == {0}", InvalidFilter));
            }
            if (pLineNumberFilter.HasValue)
            {
                res.Append(" && " + string.Format("pLineNumber == {0}", pLineNumberFilter.ToString()));
            }



            if (Convert.ToDateTime(StartpExpiryDateFilter).Date != DateTime.MinValue &&
                Convert.ToDateTime(EndpExpiryDateFilter).Date != DateTime.MinValue)
            {
                res.Append(" && (");
            }

            if (Convert.ToDateTime(StartpExpiryDateFilter).Date != DateTime.MinValue)
            {
                if (StartpExpiryDateFilter.HasValue)
                {
                    res.Append(
                        (Convert.ToDateTime(EndpExpiryDateFilter).Date != DateTime.MinValue ? "" : " && ") +
                        string.Format("pExpiryDate >= \"{0}\"",
                                      Convert.ToDateTime(StartpExpiryDateFilter).Date.ToString("MM/dd/yyyy")));
                }
            }

            if (Convert.ToDateTime(EndpExpiryDateFilter).Date != DateTime.MinValue)
            {
                if (EndpExpiryDateFilter.HasValue)
                {
                    res.Append(" && " + string.Format("pExpiryDate <= \"{0}\"",
                                                      Convert.ToDateTime(EndpExpiryDateFilter).Date.AddHours(23).ToString("MM/dd/yyyy HH:mm:ss")));
                }
            }

            if (Convert.ToDateTime(StartpExpiryDateFilter).Date != DateTime.MinValue &&
                Convert.ToDateTime(EndpExpiryDateFilter).Date != DateTime.MinValue)
            {
                res.Append(" )");
            }

            if (Convert.ToDateTime(_pExpiryDateFilter).Date != DateTime.MinValue)
            {
                if (pExpiryDateFilter.HasValue)
                {
                    res.Append(" && " + string.Format("pExpiryDate == \"{0}\"",
                                                      Convert.ToDateTime(pExpiryDateFilter).Date.ToString("MM/dd/yyyy")));
                }
            }


            if (string.IsNullOrEmpty(pReferenceNumberFilter) == false)
            {
                res.Append(" && " + string.Format("pReferenceNumber.Contains(\"{0}\")", pReferenceNumberFilter));
            }

            if (Total_CIF_itmFilter.HasValue)
            {
                res.Append(" && " + string.Format("Total_CIF_itm == {0}", Total_CIF_itmFilter.ToString()));
            }

            if (DutyLiabilityFilter.HasValue)
            {
                res.Append(" && " + string.Format("DutyLiability == {0}", DutyLiabilityFilter.ToString()));
            }

            if (pIsAssessedFilter.HasValue)
            {
                res.Append(" && " + string.Format("pIsAssessed == {0}", pIsAssessedFilter));
            }

            if (DoNotAllocatePreviousEntryFilter.HasValue)
            {
                res.Append(" && " + string.Format("DoNotAllocatePreviousEntry == {0}", DoNotAllocatePreviousEntryFilter));
            }



            if (string.IsNullOrEmpty(xCNumberFilter) == false)
            {
                res.Append(" && " + string.Format("xCNumber.Contains(\"{0}\")", xCNumberFilter));
            }


            if (xLineNumberFilter.HasValue)
            {
                res.Append(" && " + string.Format("xLineNumber == {0}", xLineNumberFilter.ToString()));
            }

            if (Convert.ToDateTime(StartxRegistrationDateFilter).Date != DateTime.MinValue &&
                Convert.ToDateTime(EndxRegistrationDateFilter).Date != DateTime.MinValue)
            {
                res.Append(" && (");
            }

            if (Convert.ToDateTime(StartxRegistrationDateFilter).Date != DateTime.MinValue)
            {
                if (StartxRegistrationDateFilter.HasValue)
                {
                    res.Append(
                        (Convert.ToDateTime(EndxRegistrationDateFilter).Date != DateTime.MinValue ? "" : " && ") +
                        string.Format("xRegistrationDate >= \"{0}\"",
                                      Convert.ToDateTime(StartxRegistrationDateFilter).Date.ToString("MM/dd/yyyy")));
                }
            }

            if (Convert.ToDateTime(EndxRegistrationDateFilter).Date != DateTime.MinValue)
            {
                if (EndxRegistrationDateFilter.HasValue)
                {
                    res.Append(" && " + string.Format("xRegistrationDate <= \"{0}\"",
                                                      Convert.ToDateTime(EndxRegistrationDateFilter).Date.AddHours(23)
                                                      .ToString("MM/dd/yyyy")));
                }
            }

            if (Convert.ToDateTime(StartxRegistrationDateFilter).Date != DateTime.MinValue &&
                Convert.ToDateTime(EndxRegistrationDateFilter).Date != DateTime.MinValue)
            {
                res.Append(" )");
            }

            if (Convert.ToDateTime(_xRegistrationDateFilter).Date != DateTime.MinValue)
            {
                if (xRegistrationDateFilter.HasValue)
                {
                    res.Append(" && " + string.Format("xRegistrationDate == \"{0}\"",
                                                      Convert.ToDateTime(xRegistrationDateFilter).Date.ToString("MM/dd/yyyy")));
                }
            }

            if (string.IsNullOrEmpty(xReferenceNumberFilter) == false)
            {
                res.Append(" && " + string.Format("xReferenceNumber.Contains(\"{0}\")", xReferenceNumberFilter));
            }


            return(res.ToString().StartsWith(" &&") || res.Length == 0 ? res : res.Insert(0, " && "));
        }