Ejemplo n.º 1
0
        /// <summary>
        /// Fill a GenTest.Entities.TList&lt;Fattura&gt; From a DataReader.
        /// </summary>
        /// <param name="reader">Datareader</param>
        /// <param name="rows">The collection to fill</param>
        /// <param name="start">Row number at which to start reading, the first row is 0.</param>
        /// <param name="pageLength">number of rows.</param>
        /// <returns>a <see cref="GenTest.Entities.TList&lt;Fattura&gt;"/></returns>
        public static GenTest.Entities.TList <Fattura> Fill(IDataReader reader, GenTest.Entities.TList <Fattura> rows, int start, int pageLength)
        {
            // advance to the starting row
            for (int i = 0; i < start; i++)
            {
                if (!reader.Read())
                {
                    return(rows);    // not enough rows, just return
                }
            }
            for (int i = 0; i < pageLength; i++)
            {
                if (!reader.Read())
                {
                    break;     // we are done
                }
                string key = null;

                GenTest.Entities.Fattura c = null;
                if (DataRepository.Provider.UseEntityFactory)
                {
                    key = new System.Text.StringBuilder("Fattura")
                          .Append("|").Append((reader.IsDBNull(((int)GenTest.Entities.FatturaColumn.ID - 1))?(int)0:(System.Int32)reader[((int)GenTest.Entities.FatturaColumn.ID - 1)]).ToString()).ToString();
                    c = EntityManager.LocateOrCreate <Fattura>(
                        key.ToString(),                                      // EntityTrackingKey
                        "Fattura",                                           //Creational Type
                        DataRepository.Provider.EntityCreationalFactoryType, //Factory used to create entity
                        DataRepository.Provider.EnableEntityTracking);       // Track this entity?
                }
                else
                {
                    c = new GenTest.Entities.Fattura();
                }

                if (!DataRepository.Provider.EnableEntityTracking ||
                    c.EntityState == EntityState.Added ||
                    (DataRepository.Provider.EnableEntityTracking &&
                     ((DataRepository.Provider.CurrentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
                      (DataRepository.Provider.CurrentLoadPolicy == LoadPolicy.DiscardChanges && (c.EntityState == EntityState.Unchanged ||
                                                                                                  c.EntityState == EntityState.Changed)))))
                {
                    c.SuppressEntityEvents = true;
                    c.Intestatario         = (System.String)reader["Intestatario"];
                    c.Descrizione          = (System.String)reader["Descrizione"];
                    c.Data   = (System.String)reader["Data"];
                    c.Numero = (System.Int32)reader["Numero"];
                    c.ID     = (System.Int32)reader["ID"];
                    c.ComposedRigaFatturaID   = reader.IsDBNull(reader.GetOrdinal("ComposedRigaFatturaID")) ? null : (System.Int32?)reader["ComposedRigaFatturaID"];
                    c.AggregatedRigaFatturaID = reader.IsDBNull(reader.GetOrdinal("AggregatedRigaFatturaID")) ? null : (System.Int32?)reader["AggregatedRigaFatturaID"];
                    c.AssociatedRigaFatturaID = reader.IsDBNull(reader.GetOrdinal("AssociatedRigaFatturaID")) ? null : (System.Int32?)reader["AssociatedRigaFatturaID"];
                    c.EntityTrackingKey       = key;
                    c.AcceptChanges();
                    c.SuppressEntityEvents = false;
                }
                rows.Add(c);
            }
            return(rows);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Gets rows from the datasource based on the FK_Aggregated_Fattura_RigaFattura key.
        ///		FK_Aggregated_Fattura_RigaFattura Description:
        /// </summary>
        /// <param name="start">Row number at which to start reading.</param>
        /// <param name="pageLength">Number of rows to return.</param>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="aggregatedRigaFatturaID"></param>
        /// <param name="count">out parameter to get total records for query</param>
        /// <remarks></remarks>
        /// <returns>Returns a typed collection of GenTest.Entities.Fattura objects.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override GenTest.Entities.TList <Fattura> GetByAggregatedRigaFatturaID(TransactionManager transactionManager, System.Int32?aggregatedRigaFatturaID, int start, int pageLength, out int count)
        {
            SqlDatabase database       = new SqlDatabase(this._connectionString);
            DbCommand   commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Fattura_GetByAggregatedRigaFatturaID", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@AggregatedRigaFatturaID", DbType.Int32, aggregatedRigaFatturaID);

            IDataReader reader = null;

            GenTest.Entities.TList <Fattura> rows = new GenTest.Entities.TList <Fattura>();
            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "GetByAggregatedRigaFatturaID", rows));

                if (transactionManager != null)
                {
                    reader = Utility.ExecuteReader(transactionManager, commandWrapper);
                }
                else
                {
                    reader = Utility.ExecuteReader(database, commandWrapper);
                }

                //Create Collection
                Fill(reader, rows, start, pageLength);
                count = -1;
                if (reader.NextResult())
                {
                    if (reader.Read())
                    {
                        count = reader.GetInt32(0);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "GetByAggregatedRigaFatturaID", rows));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                commandWrapper = null;
            }
            return(rows);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Gets rows from the datasource based on the UQ__Fattura__15502E78 index.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="associatedRigaFatturaID"></param>
        /// <param name="start">Row number at which to start reading.</param>
        /// <param name="pageLength">Number of rows to return.</param>
        /// <param name="count">out parameter to get total records for query</param>
        /// <returns>Returns an instance of the <see cref="GenTest.Entities.Fattura"/> class.</returns>
        /// <remarks></remarks>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override GenTest.Entities.Fattura GetByAssociatedRigaFatturaID(TransactionManager transactionManager, System.Int32?associatedRigaFatturaID, int start, int pageLength, out int count)
        {
            SqlDatabase database       = new SqlDatabase(this._connectionString);
            DbCommand   commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Fattura_GetByAssociatedRigaFatturaID", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@AssociatedRigaFatturaID", DbType.Int32, associatedRigaFatturaID);

            IDataReader reader = null;

            GenTest.Entities.TList <Fattura> tmp = new GenTest.Entities.TList <Fattura>();
            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "GetByAssociatedRigaFatturaID", tmp));

                if (transactionManager != null)
                {
                    reader = Utility.ExecuteReader(transactionManager, commandWrapper);
                }
                else
                {
                    reader = Utility.ExecuteReader(database, commandWrapper);
                }

                //Create collection and fill
                Fill(reader, tmp, start, pageLength);
                count = -1;
                if (reader.NextResult())
                {
                    if (reader.Read())
                    {
                        count = reader.GetInt32(0);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "GetByAssociatedRigaFatturaID", tmp));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                commandWrapper = null;
            }

            if (tmp.Count == 1)
            {
                return(tmp[0]);
            }
            else if (tmp.Count == 0)
            {
                return(null);
            }
            else
            {
                throw new DataException("Cannot find the unique instance of the class.");
            }

            //return rows;
        }
Ejemplo n.º 4
0
        }        //end getall

        #endregion

        #region GetPaged Methods

        /// <summary>
        /// Gets a page of rows from the DataSource.
        /// </summary>
        /// <param name="start">Row number at which to start reading.</param>
        /// <param name="pageLength">Number of rows to return.</param>
        /// <param name="count">Number of rows in the DataSource.</param>
        /// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
        /// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <remarks></remarks>
        /// <returns>Returns a typed collection of GenTest.Entities.Fattura objects.</returns>
        public override GenTest.Entities.TList <Fattura> GetPaged(TransactionManager transactionManager, string whereClause, string orderBy, int start, int pageLength, out int count)
        {
            SqlDatabase database       = new SqlDatabase(this._connectionString);
            DbCommand   commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Fattura_GetPaged", _useStoredProcedure);


            if (commandWrapper.CommandType == CommandType.Text &&
                commandWrapper.CommandText != null)
            {
                commandWrapper.CommandText = commandWrapper.CommandText.Replace(SqlUtil.PAGE_INDEX, string.Concat(SqlUtil.PAGE_INDEX, Guid.NewGuid().ToString("N").Substring(0, 8)));
            }

            database.AddInParameter(commandWrapper, "@WhereClause", DbType.String, whereClause);
            database.AddInParameter(commandWrapper, "@OrderBy", DbType.String, orderBy);
            database.AddInParameter(commandWrapper, "@PageIndex", DbType.Int32, start);
            database.AddInParameter(commandWrapper, "@PageSize", DbType.Int32, pageLength);

            IDataReader reader = null;

            //Create Collection
            GenTest.Entities.TList <Fattura> rows = new GenTest.Entities.TList <Fattura>();

            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "GetPaged", rows));

                if (transactionManager != null)
                {
                    reader = Utility.ExecuteReader(transactionManager, commandWrapper);
                }
                else
                {
                    reader = Utility.ExecuteReader(database, commandWrapper);
                }

                Fill(reader, rows, 0, int.MaxValue);
                count = rows.Count;

                if (reader.NextResult())
                {
                    if (reader.Read())
                    {
                        count = reader.GetInt32(0);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "GetPaged", rows));
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                commandWrapper = null;
            }

            return(rows);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Returns rows from the DataSource that meet the parameter conditions.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="parameters">A collection of <see cref="SqlFilterParameter"/> objects.</param>
        /// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
        /// <param name="start">Row number at which to start reading.</param>
        /// <param name="pageLength">Number of rows to return.</param>
        /// <param name="count">out. The number of rows that match this query.</param>
        /// <returns>Returns a typed collection of GenTest.Entities.Fattura objects.</returns>
        public override GenTest.Entities.TList <Fattura> Find(TransactionManager transactionManager, IFilterParameterCollection parameters, string orderBy, int start, int pageLength, out int count)
        {
            SqlFilterParameterCollection filter = null;

            if (parameters == null)
            {
                filter = new SqlFilterParameterCollection();
            }
            else
            {
                filter = parameters.GetParameters();
            }

            SqlDatabase database       = new SqlDatabase(this._connectionString);
            DbCommand   commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Fattura_Find_Dynamic", typeof(FatturaColumn), filter, orderBy, start, pageLength);

            SqlFilterParameter param;

            for (int i = 0; i < filter.Count; i++)
            {
                param = filter[i];
                database.AddInParameter(commandWrapper, param.Name, param.DbType, param.GetValue());
            }

            GenTest.Entities.TList <Fattura> rows = new GenTest.Entities.TList <Fattura>();
            IDataReader reader = null;

            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "Find", rows));

                if (transactionManager != null)
                {
                    reader = Utility.ExecuteReader(transactionManager, commandWrapper);
                }
                else
                {
                    reader = Utility.ExecuteReader(database, commandWrapper);
                }

                Fill(reader, rows, 0, int.MaxValue);
                count = rows.Count;

                if (reader.NextResult())
                {
                    if (reader.Read())
                    {
                        count = reader.GetInt32(0);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "Find", rows));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                commandWrapper = null;
            }

            return(rows);
        }
Ejemplo n.º 6
0
        }        //end Delete

        #endregion

        #region Find Functions

        #region Parsed Find Methods
        /// <summary>
        ///     Returns rows meeting the whereclause condition from the DataSource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
        /// <param name="start">Row number at which to start reading.</param>
        /// <param name="pageLength">Number of rows to return.</param>
        /// <param name="count">out. The number of rows that match this query.</param>
        /// <remarks>Operators must be capitalized (OR, AND)</remarks>
        /// <returns>Returns a typed collection of GenTest.Entities.Fattura objects.</returns>
        public override GenTest.Entities.TList <Fattura> Find(TransactionManager transactionManager, string whereClause, int start, int pageLength, out int count)
        {
            count = -1;
            if (whereClause.IndexOf(";") > -1)
            {
                return(new GenTest.Entities.TList <Fattura>());
            }

            SqlDatabase database       = new SqlDatabase(this._connectionString);
            DbCommand   commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Fattura_Find", _useStoredProcedure);

            bool searchUsingOR = false;

            if (whereClause.IndexOf(" OR ") > 0)     // did they want to do "a=b OR c=d OR..."?
            {
                searchUsingOR = true;
            }

            database.AddInParameter(commandWrapper, "@SearchUsingOR", DbType.Boolean, searchUsingOR);

            database.AddInParameter(commandWrapper, "@Intestatario", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Descrizione", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Data", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Numero", DbType.Int32, DBNull.Value);
            database.AddInParameter(commandWrapper, "@ID", DbType.Int32, DBNull.Value);
            database.AddInParameter(commandWrapper, "@ComposedRigaFatturaID", DbType.Int32, DBNull.Value);
            database.AddInParameter(commandWrapper, "@AggregatedRigaFatturaID", DbType.Int32, DBNull.Value);
            database.AddInParameter(commandWrapper, "@AssociatedRigaFatturaID", DbType.Int32, DBNull.Value);

            // replace all instances of 'AND' and 'OR' because we already set searchUsingOR
            whereClause = whereClause.Replace(" AND ", "|").Replace(" OR ", "|");
            string[] clauses = whereClause.ToLower().Split('|');

            // Here's what's going on below: Find a field, then to get the value we
            // drop the field name from the front, trim spaces, drop the '=' sign,
            // trim more spaces, and drop any outer single quotes.
            // Now handles the case when two fields start off the same way - like "Friendly='Yes' AND Friend='john'"

            char[] equalSign   = { '=' };
            char[] singleQuote = { '\'' };
            foreach (string clause in clauses)
            {
                if (clause.Trim().StartsWith("intestatario ") || clause.Trim().StartsWith("intestatario="))
                {
                    database.SetParameterValue(commandWrapper, "@Intestatario",
                                               clause.Trim().Remove(0, 12).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("descrizione ") || clause.Trim().StartsWith("descrizione="))
                {
                    database.SetParameterValue(commandWrapper, "@Descrizione",
                                               clause.Trim().Remove(0, 11).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("data ") || clause.Trim().StartsWith("data="))
                {
                    database.SetParameterValue(commandWrapper, "@Data",
                                               clause.Trim().Remove(0, 4).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("numero ") || clause.Trim().StartsWith("numero="))
                {
                    database.SetParameterValue(commandWrapper, "@Numero",
                                               clause.Trim().Remove(0, 6).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("id ") || clause.Trim().StartsWith("id="))
                {
                    database.SetParameterValue(commandWrapper, "@ID",
                                               clause.Trim().Remove(0, 2).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("composedrigafatturaid ") || clause.Trim().StartsWith("composedrigafatturaid="))
                {
                    database.SetParameterValue(commandWrapper, "@ComposedRigaFatturaID",
                                               clause.Trim().Remove(0, 21).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("aggregatedrigafatturaid ") || clause.Trim().StartsWith("aggregatedrigafatturaid="))
                {
                    database.SetParameterValue(commandWrapper, "@AggregatedRigaFatturaID",
                                               clause.Trim().Remove(0, 23).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("associatedrigafatturaid ") || clause.Trim().StartsWith("associatedrigafatturaid="))
                {
                    database.SetParameterValue(commandWrapper, "@AssociatedRigaFatturaID",
                                               clause.Trim().Remove(0, 23).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }

                throw new ArgumentException("Unable to use this part of the where clause in this version of Find: " + clause);
            }

            IDataReader reader = null;

            //Create Collection
            GenTest.Entities.TList <Fattura> rows = new GenTest.Entities.TList <Fattura>();


            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "Find", rows));

                if (transactionManager != null)
                {
                    reader = Utility.ExecuteReader(transactionManager, commandWrapper);
                }
                else
                {
                    reader = Utility.ExecuteReader(database, commandWrapper);
                }

                Fill(reader, rows, start, pageLength);

                if (reader.NextResult())
                {
                    if (reader.Read())
                    {
                        count = reader.GetInt32(0);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "Find", rows));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                commandWrapper = null;
            }
            return(rows);
        }