Esempio n. 1
0
        protected static List <T> dbGetList(string query, SqlParameter[] sp)
        {
            List <T> _objList = null;

            SqlIt sqlIt = createSqlIt(query, sp);

            try
            {
                sqlIt.Connection.Open();
                SqlDataReader dar = sqlIt.Command.ExecuteReader();
                if (dar != null)
                {
                    _objList = new List <T>();
                    while (dar.Read())
                    {
                        _objList.Add(mapIt(dar));
                    }
                }
            }
            catch (Exception eObj)
            {
                throw new Exception("Database problem(s) when getting list!", eObj);
            }
            finally
            {
                if (sqlIt.Connection != null)
                {
                    sqlIt.Connection.Close();
                }
            }
            return(_objList);
        }
Esempio n. 2
0
        protected static T dbGet(string query, SqlParameter[] sp)
        {
            T     _obj  = default(T);
            SqlIt sqlIt = createSqlIt(query, sp);

            try
            {
                sqlIt.Connection.Open();
                SqlDataReader dar = sqlIt.Command.ExecuteReader();

                if (dar.Read())
                {
                    _obj = mapIt(dar);
                }
            }
            catch (Exception eObj)
            {
                throw new Exception("Database problem(s) when getting data!", eObj);
            }
            finally
            {
                if (sqlIt.Connection != null)
                {
                    sqlIt.Connection.Close();
                }
            }

            return(_obj);
        }
Esempio n. 3
0
        private static SqlIt createSqlIt(string query, SqlParameter[] sp = null)
        {
            string _connectionString = DataSource.getConnectionString("projectmanager");

            SqlIt sqlIt = new SqlIt(new SqlConnection(_connectionString), query);

            if (sp != null && sp.Length > 0)
            {
                sqlIt.Command.Parameters.AddRange(sp);
            }

            return(sqlIt);
        }
Esempio n. 4
0
        protected static object dbGetProperty(string query, string propertyname, SqlParameter[] sp)
        {
            object       _obj  = new object();
            SqlIt        sqlIt = null;
            PropertyInfo pi    = typeof(T).GetProperty(propertyname);

            if (sp != null && sp.Length == 1)
            {
                sqlIt = createSqlIt(query, sp);
            }
            else
            {
                return(null);
            }

            try
            {
                sqlIt.Connection.Open();
                SqlDataReader dar = sqlIt.Command.ExecuteReader();

                if (dar.Read())
                {
                    _obj = mapItEach(dar, pi);
                }
                else
                {
                    _obj = null;
                }
            }
            catch (Exception eObj)
            {
                throw new Exception("Database problem(s) when getting object property!", eObj);
            }
            finally
            {
                if (sqlIt.Connection != null)
                {
                    sqlIt.Connection.Close();
                }
            }

            return(_obj);
        }