Example #1
0
        /// <summary>
        /// The add criteria data.
        /// </summary>
        /// <param name="criteria">
        /// The criteria.
        /// </param>
        /// <param name="deatachQuery">
        /// The deatach query.
        /// </param>
        /// <param name="dpersonDatum">
        /// The dperson datum.
        /// </param>
        /// <param name="ddocument">
        /// The ddocument.
        /// </param>
        /// <param name="dmedicalInsurance">
        /// The dmedical Insurance.
        /// </param>
        /// <param name="emptyCriteria">
        /// The empty Criteria.
        /// </param>
        private void AddCriteriaData(
            SearchStatementCriteria criteria,
            QueryOver <Statement, Statement> deatachQuery,
            InsuredPersonDatum dpersonDatum,
            Document ddocument,
            MedicalInsurance dmedicalInsurance,
            bool emptyCriteria)
        {
            // Номер ВС
            if (!string.IsNullOrEmpty(criteria.CertificateNumber))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => dmedicalInsurance.PolisNumber == criteria.CertificateNumber)
                .And(x => dmedicalInsurance.PolisType.Id == PolisType.В);
            }

            // Имя
            if (!string.IsNullOrEmpty(criteria.FirstName))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => dpersonDatum.FirstName == criteria.FirstName.Trim());
            }

            // Фамилия
            if (!string.IsNullOrEmpty(criteria.LastName))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => dpersonDatum.LastName == criteria.LastName.Trim());
            }

            // Отчество
            if (!string.IsNullOrEmpty(criteria.MiddleName))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => dpersonDatum.MiddleName == criteria.MiddleName.Trim());
            }

            // СНИЛС
            if (!string.IsNullOrEmpty(criteria.SNILS))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => dpersonDatum.Snils == SnilsChecker.SsToShort(criteria.SNILS));
            }

            // Тип документа
            if (criteria.DocumentTypeId > 0 &&
                (!string.IsNullOrEmpty(criteria.DocumentSeries) || !string.IsNullOrEmpty(criteria.DocumentNumber)))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => ddocument.DocumentType.Id == criteria.DocumentTypeId);
            }

            // Серия документа
            if (!string.IsNullOrEmpty(criteria.DocumentSeries))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => ddocument.Series == criteria.DocumentSeries);
            }

            // Номер документа
            if (!string.IsNullOrEmpty(criteria.DocumentNumber))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => ddocument.Number == criteria.DocumentNumber);
            }

            // Номер документа
            if (!string.IsNullOrEmpty(criteria.BirthPlace))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => dpersonDatum.Birthplace == criteria.BirthPlace.Trim());
            }

            // Номер полиса
            if (!string.IsNullOrEmpty(criteria.PolicyNumber))
            {
                emptyCriteria = false;

                // deatachQuery.Where(x => x.NumberPolicy == criteria.PolicyNumber.Trim());
                deatachQuery.Where(x => dmedicalInsurance.Enp == criteria.PolicyNumber.Trim())
                .And(x => dmedicalInsurance.PolisType.Id != PolisType.В);
            }

            // Дата рождения
            if (criteria.BirthDate.HasValue)
            {
                emptyCriteria = false;
                deatachQuery.Where(x => dpersonDatum.Birthday == criteria.BirthDate.Value);
            }

            if (!string.IsNullOrEmpty(criteria.Error))
            {
                emptyCriteria = false;
                Error error = null;
                deatachQuery.JoinAlias(x => x.Errors, () => error).Where(x => error.Message1 == criteria.Error);
            }

            // если не сработал ни один критерий то осталяем выборку пустой
            if (emptyCriteria)
            {
                throw new SetParameterSearchException();
            }
        }