Esempio n. 1
0
        private string GetSelectPart(IncomingBookCriteriaGet crit)
        {
            var query = "SELECT " + QueryList + Environment.NewLine + "FROM IncomingRegisters";

            if (!string.IsNullOrEmpty(crit.FullText))
            {
                query += ", IncomingView";
            }

            query += Environment.NewLine;
            return(query);
        }
Esempio n. 2
0
        private void BuildWhereClause(IncomingBookCriteriaGet crit, string dateTypeName, ref string query,
                                      ref ClauseStatus clauseStatus)
        {
            if (!crit.CriteriaStartDate.IsEmpty)
            {
                QueryBuilder.AddClause(ref query, ref clauseStatus);
                query       += QueryBuilder.NormalizeToDate("IncomingRegisters.", dateTypeName) + " >= @CriteriaStartDate";
                clauseStatus = ClauseStatus.ClauseAdded;
            }

            if (!crit.CriteriaEndDate.IsEmpty)
            {
                QueryBuilder.AddClause(ref query, ref clauseStatus);
                query       += QueryBuilder.NormalizeToDate("IncomingRegisters.", dateTypeName) + " <= @CriteriaEndDate";
                clauseStatus = ClauseStatus.ClauseAdded;
            }
        }
Esempio n. 3
0
        private string GetIncomingBookInlineQuery(IncomingBookCriteriaGet crit)
        {
            var clauseStatus = ClauseStatus.NoClause;

            var query = GetSelectPart(crit);

            if (!string.IsNullOrEmpty(crit.FullText) ||
                !string.IsNullOrEmpty(crit.ArchiveLocation) ||
                !crit.CriteriaStartDate.IsEmpty ||
                !crit.CriteriaEndDate.IsEmpty)
            {
                query = GetWherePart(query, crit, ref clauseStatus);
            }

            query = GetOrderPart(query);

            return(query);
        }
Esempio n. 4
0
        /// <summary>
        /// Loads a <see cref="IncomingBook"/> collection from the database, based on given criteria.
        /// </summary>
        /// <param name="crit">The fetch criteria.</param>
        protected void DataPortal_Fetch(IncomingBookCriteriaGet crit)
        {
            using (var ctx = ConnectionManager <SqlConnection> .GetManager(Database.InterwayDocsConnection, false))
            {
                using (var cmd = new SqlCommand(GetIncomingBookInlineQuery(crit), ctx.Connection))
                {
                    var archiveLocation = string.Empty;
                    var fullText        = string.Empty;

                    if (!string.IsNullOrEmpty(crit.ArchiveLocation))
                    {
                        archiveLocation = "%" + crit.ArchiveLocation + "%";
                    }

                    if (!string.IsNullOrEmpty(crit.FullText))
                    {
                        fullText = "%" + crit.FullText + "%";
                    }

                    cmd.CommandType = CommandType.Text;
                    if (!crit.CriteriaStartDate.IsEmpty)
                    {
                        cmd.Parameters.AddWithValue("@CriteriaStartDate", crit.CriteriaStartDate.DBValue).DbType = DbType.Date;
                    }
                    if (!crit.CriteriaEndDate.IsEmpty)
                    {
                        cmd.Parameters.AddWithValue("@CriteriaEndDate", crit.CriteriaEndDate.DBValue).DbType = DbType.Date;
                    }
                    if (!string.IsNullOrEmpty(crit.ArchiveLocation))
                    {
                        cmd.Parameters.AddWithValue("@ArchiveLocation", archiveLocation).DbType = DbType.String;
                    }
                    if (!string.IsNullOrEmpty(crit.FullText))
                    {
                        cmd.Parameters.AddWithValue("@FullText", fullText).DbType = DbType.String;
                    }
                    var args = new DataPortalHookArgs(cmd, crit);
                    OnFetchPre(args);
                    LoadCollection(cmd);
                    OnFetchPost(args);
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Factory method. Loads a <see cref="IncomingBook"/> collection, based on given parameters.
 /// </summary>
 /// <param name="crit">The fetch criteria.</param>
 /// <returns>A reference to the fetched <see cref="IncomingBook"/> collection.</returns>
 public static IncomingBook GetIncomingBook(IncomingBookCriteriaGet crit)
 {
     return(DataPortal.Fetch <IncomingBook>(crit));
 }
Esempio n. 6
0
        private string GetWherePart(string query, IncomingBookCriteriaGet crit, ref ClauseStatus clauseStatus)
        {
            QueryBuilder.AddClause(ref query, ref clauseStatus);

            if (!string.IsNullOrEmpty(crit.FullText))
            {
                query       += "IncomingView.RegisterId = IncomingRegisters.RegisterId";
                clauseStatus = ClauseStatus.ClauseAdded;
            }

            if (crit.SelectedDateTypeName == "AllDates")
            {
                if (!crit.CriteriaStartDate.IsEmpty && !crit.CriteriaEndDate.IsEmpty)
                {
                    QueryBuilder.AddClause(ref query, ref clauseStatus);
                    query += "(" + Environment.NewLine;
                    for (var dateTypeItem = 0; dateTypeItem < crit.DateTypeList.Count - 1; dateTypeItem++)
                    {
                        if (dateTypeItem > 0)
                        {
                            QueryBuilder.AddOrClause(ref query, ref clauseStatus);
                        }

                        var dateTypeName = crit.DateTypeList[dateTypeItem].DateTypeName;
                        query += "(";
                        query += QueryBuilder.NormalizeToDate("IncomingRegisters.", dateTypeName) +
                                 " >= @CriteriaStartDate";
                        clauseStatus = ClauseStatus.ClauseAdded;

                        QueryBuilder.AddClause(ref query, ref clauseStatus);
                        query += QueryBuilder.NormalizeToDate("IncomingRegisters.", dateTypeName) +
                                 " <= @CriteriaEndDate";
                        clauseStatus = ClauseStatus.ClauseAdded;
                        query       += ")";
                    }
                    query += Environment.NewLine + ")";
                }
                else
                {
                    QueryBuilder.AddClause(ref query, ref clauseStatus);
                    query += "(" + Environment.NewLine;
                    for (var dateTypeItem = 0; dateTypeItem < crit.DateTypeList.Count - 1; dateTypeItem++)
                    {
                        if (!crit.CriteriaStartDate.IsEmpty)
                        {
                            QueryBuilder.AddOrClause(ref query, ref clauseStatus);

                            var dateTypeName = crit.DateTypeList[dateTypeItem].DateTypeName;
                            query += QueryBuilder.NormalizeToDate("IncomingRegisters.", dateTypeName) +
                                     " >= @CriteriaStartDate";
                            clauseStatus = ClauseStatus.ClauseAdded;
                        }

                        if (!crit.CriteriaEndDate.IsEmpty)
                        {
                            QueryBuilder.AddOrClause(ref query, ref clauseStatus);

                            var dateTypeName = crit.DateTypeList[dateTypeItem].DateTypeName;
                            query += QueryBuilder.NormalizeToDate("IncomingRegisters.", dateTypeName) +
                                     " <= @CriteriaEndDate";
                            clauseStatus = ClauseStatus.ClauseAdded;
                        }
                    }
                    query += Environment.NewLine + ")";
                }
            }
            else
            {
                foreach (var dateTypeInfo in crit.DateTypeList)
                {
                    if (dateTypeInfo.DateTypeName == crit.SelectedDateTypeName)
                    {
                        BuildWhereClause(crit, crit.SelectedDateTypeName, ref query, ref clauseStatus);
                        break;
                    }
                }
            }

            if (!string.IsNullOrEmpty(crit.ArchiveLocation))
            {
                QueryBuilder.AddClause(ref query, ref clauseStatus);
                query       += "ArchiveLocation LIKE @ArchiveLocation";
                clauseStatus = ClauseStatus.ClauseAdded;
            }

            if (!string.IsNullOrEmpty(crit.FullText))
            {
                QueryBuilder.AddClause(ref query, ref clauseStatus);
                query       += "(" + Environment.NewLine;
                query       += "FullText LIKE @FullText";
                clauseStatus = ClauseStatus.ClauseAdded;
                QueryBuilder.AddClause(ref query, ref clauseStatus, true);
                query += "FullText LIKE @FullText21";
                QueryBuilder.AddClause(ref query, ref clauseStatus, true);
                query += "FullText LIKE @FullText22";
                QueryBuilder.AddClause(ref query, ref clauseStatus, true);
                query += "FullText LIKE @FullText31";
                QueryBuilder.AddClause(ref query, ref clauseStatus, true);
                query += "FullText LIKE @FullText32";
                QueryBuilder.AddClause(ref query, ref clauseStatus, true);
                query += "FullText LIKE @FullText33";
                QueryBuilder.AddClause(ref query, ref clauseStatus, true);
                query += "FullText LIKE @FullText34";
                QueryBuilder.AddClause(ref query, ref clauseStatus, true);
                query += "FullText LIKE @FullText35";
                QueryBuilder.AddClause(ref query, ref clauseStatus, true);
                query += "FullText LIKE @FullText36";
                query += Environment.NewLine;
                query += ")";
            }

            return(query);
        }