Beispiel #1
0
        /// <summary>
        ///
        /// select a set of rows from table t_RBSR_AUFW_u_User.
        /// </summary>
        /// <param name="maxRowsToReturn">Max number of rows to return. If null or 0 all rows are returned.</param>
        /// <returns>returnListUser[]</returns>
        public returnListUser[] ListUser(int?maxRowsToReturn)
        {
            returnListUser[] rv = null;
            DBConnect();
            OdbcCommand cmd = new OdbcCommand();

            cmd.CommandText = "select" + (maxRowsToReturn.HasValue && maxRowsToReturn.Value != 0 ? " top " + maxRowsToReturn.Value.ToString() : "") + " " + "\"c_id\",\"c_u_EID\",\"c_u_Name\" from \"t_RBSR_AUFW_u_User\"";
            cmd.Connection  = _dbConnection;
            OdbcDataReader        dr  = cmd.ExecuteReader();
            List <returnListUser> rvl = new List <returnListUser>();

            while (dr.Read())
            {
                returnListUser cr = new returnListUser();
                if (!dr.IsDBNull(0))
                {
                    cr.ID = dr.GetInt32(0);
                }
                else
                {
                    throw new Exception("Value 'null' is not allowed for 'ID'");
                }
                if (!dr.IsDBNull(1))
                {
                    cr.EID = dr.GetString(1);
                }
                else
                {
                    throw new Exception("Value 'null' is not allowed for 'EID'");
                }
                if (!dr.IsDBNull(2))
                {
                    cr.Name = dr.GetString(2);
                }
                else
                {
                    throw new Exception("Value 'null' is not allowed for 'Name'");
                }
                rvl.Add(cr);
            }
            dr.Close();
            dr.Dispose();
            rv = rvl.ToArray();
            cmd.Dispose();
            DBClose();
            return(rv);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// select a set of rows from table t_RBSR_AUFW_u_User.
        /// </summary>
        /// <param name="maxRowsToReturn">Max number of rows to return. If null or 0 all rows are returned.</param>
        /// <param name="extendedCriteria">Statement appended to the end of the WHERE-clause</param>
        /// <param name="extentedParameters">Values bound to the query (?) marks in <code>extendedCriteria</code></param>
        /// <param name="extendedSortOrder">Statement appended to the end of the ORDER BY-clause</param>
        /// <returns>returnListUser[]</returns>
        public returnListUser[] ListUser(int?maxRowsToReturn, string extendedCriteria, string[] extendedParameters, string extendedSortOrder)
        {
            returnListUser[] rv = null;
            DBConnect();
            OdbcCommand cmd              = _dbConnection.CreateCommand();
            string      runTimeCriteria  = (extendedCriteria != null ? extendedCriteria.ToLower() : string.Empty).Replace("\"id\"", "\"c_id\"").Replace("\"eid\"", "\"c_u_EID\"").Replace("\"name\"", "\"c_u_Name\"").Replace("\"privilegelevel\"", "\"c_u_PrivilegeLevel\"").Replace("\"namesurname\"", "\"c_u_NameSurname\"").Replace("\"namefirst\"", "\"c_u_NameFirst\"").Replace("\"password\"", "\"c_u_Password\"");
            string      runTimeSortOrder = (extendedSortOrder != null ? extendedSortOrder.ToLower() : string.Empty).Replace("\"id\"", "\"c_id\"").Replace("\"eid\"", "\"c_u_EID\"").Replace("\"name\"", "\"c_u_Name\"").Replace("\"privilegelevel\"", "\"c_u_PrivilegeLevel\"").Replace("\"namesurname\"", "\"c_u_NameSurname\"").Replace("\"namefirst\"", "\"c_u_NameFirst\"").Replace("\"password\"", "\"c_u_Password\"");

            if (maxRowsToReturn.HasValue && maxRowsToReturn.Value > 0)
            {
                if (_dbConnection.Driver.ToLower().StartsWith("sql"))
                {
                    cmd.CommandText = "SELECT TOP " + maxRowsToReturn.Value + " \"c_id\", \"c_u_EID\", \"c_u_Name\", \"c_u_PrivilegeLevel\", \"c_u_NameSurname\", \"c_u_NameFirst\" FROM \"t_RBSR_AUFW_u_User\"" + (string.IsNullOrEmpty(runTimeCriteria) ? "" : " where (" + runTimeCriteria + ")") + (string.IsNullOrEmpty(runTimeSortOrder) ? "" : " order by " + runTimeSortOrder);
                }
                else
                {
                    cmd.CommandText = "SELECT \"c_id\", \"c_u_EID\", \"c_u_Name\", \"c_u_PrivilegeLevel\", \"c_u_NameSurname\", \"c_u_NameFirst\" FROM \"t_RBSR_AUFW_u_User\"" + (string.IsNullOrEmpty(runTimeCriteria) ? "" : " where (" + runTimeCriteria + ")") + (string.IsNullOrEmpty(runTimeSortOrder) ? "" : " order by " + runTimeSortOrder) + " LIMIT " + maxRowsToReturn.Value;
                }
            }
            else
            {
                cmd.CommandText = "SELECT \"c_id\", \"c_u_EID\", \"c_u_Name\", \"c_u_PrivilegeLevel\", \"c_u_NameSurname\", \"c_u_NameFirst\" FROM \"t_RBSR_AUFW_u_User\"" + (string.IsNullOrEmpty(runTimeCriteria) ? "" : " where (" + runTimeCriteria + ")") + (string.IsNullOrEmpty(runTimeSortOrder) ? "" : " order by " + runTimeSortOrder);
            }
            for (int i = 0; i < extendedParameters.Length; i++)
            {
                cmd.Parameters.Add("@ExtendedParam_" + i.ToString(), OdbcType.NVarChar);
                cmd.Parameters["@ExtendedParam_" + i.ToString()].Value = (object)extendedParameters[i];
            }
            OdbcDataReader        dr  = cmd.ExecuteReader();
            List <returnListUser> rvl = new List <returnListUser>();

            while (dr.Read())
            {
                returnListUser cr = new returnListUser();
                if (dr.IsDBNull(0))
                {
                    cmd.Dispose(); DBClose(); throw new Exception("Value 'null' is not allowed for 'ID'");
                }
                else
                {
                    cr.ID = dr.GetInt32(0);
                }
                if (dr.IsDBNull(1))
                {
                    cmd.Dispose(); DBClose(); throw new Exception("Value 'null' is not allowed for 'EID'");
                }
                else
                {
                    cr.EID = dr.GetString(1);
                }
                if (dr.IsDBNull(2))
                {
                    cmd.Dispose(); DBClose(); throw new Exception("Value 'null' is not allowed for 'Name'");
                }
                else
                {
                    cr.Name = dr.GetString(2);
                }
                if (dr.IsDBNull(3))
                {
                    cr.PrivilegeLevel = null;
                }
                else
                {
                    cr.PrivilegeLevel = dr.GetString(3);
                }
                if (dr.IsDBNull(4))
                {
                    cr.NameSurname = null;
                }
                else
                {
                    cr.NameSurname = dr.GetString(4);
                }
                if (dr.IsDBNull(5))
                {
                    cr.NameFirst = null;
                }
                else
                {
                    cr.NameFirst = dr.GetString(5);
                }
                rvl.Add(cr);
            }
            dr.Close();
            dr.Dispose();
            rv = rvl.ToArray();
            cmd.Dispose();
            DBClose();
            return(rv);
        }