Beispiel #1
0
        public static bool Get <T>(T _Object, string query = "", string where_clause = "", Dictionary <string, string> Params = null)
        {
            List <PropertyInfo> _properties = GetReadableProperties <T>();

            query = QueryMaker.SelectQuery <T>(query, where_clause);

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                SqlCommand    cmd    = GetSqlCommandWithParams(query, connection, Params);
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        foreach (PropertyInfo pi in _properties)
                        {
                            DBReader(_Object, pi, reader);
                        }
                    }
                }
                connection.Close();
                return(true);
            }
        }
Beispiel #2
0
        public static List <T> GetList <T>(string query = null, string whereClause = null, Dictionary <string, string> Params = null)
        {
            var results    = new List <T>();
            var properties = GetReadableProperties <T>();

            query = QueryMaker.SelectQuery <T>(query, whereClause);
            using (SqlConnection Connection = new SqlConnection(ConnectionString))
            {
                Connection.Open();
                SqlCommand    cmd    = GetSqlCommandWithParams(query, Connection, Params);
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        var item = Activator.CreateInstance <T>();
                        foreach (var property in properties)
                        {
                            DBReader(item, property, reader);
                        }
                        results.Add(item);
                    }
                }
                Connection.Close();
                return(results);
            }
        }
Beispiel #3
0
        public bool CommitTrans(Dictionary <string, string> Params)
        {
            Query += QueryMaker.CommitTransQuery();
            bool result = ExecuteQuery(Query, Params);

            Query = string.Empty;
            return(result);
        }
Beispiel #4
0
        public bool CommitTrans()
        {
            Query += QueryMaker.CommitTransQuery();
            bool result = ExecuteQuery(Query);

            Query = string.Empty;
            return(result);
        }
Beispiel #5
0
        public static PageListObject <T> GetPagedList <T>(string query, Dictionary <string, string> sortAndOrder, int numberOfRecords, int pageNumber, Dictionary <string, string> Params)
        {
            int    offset     = numberOfRecords * pageNumber;
            var    Querries   = QueryMaker.GetPagerQueries <T>(query, sortAndOrder, offset, numberOfRecords);
            string mainquery  = Querries.Query;
            string countquery = Querries.CountQuery;

            return(PagedResults <T>(numberOfRecords, pageNumber, Params, offset, mainquery, countquery));
        }
Beispiel #6
0
 public static bool ExecuteTransactionQuery(string query, Dictionary <string, string> Params = null)
 {
     query = $"{QueryMaker.BeginTransQuery()} {query} {QueryMaker.CommitTransQuery()}";
     using (SqlConnection Connection = new SqlConnection(ConnectionString))
     {
         Connection.Open();
         SqlCommand cmd          = GetSqlCommandWithParams(query, Connection, Params);
         int        rowseffected = cmd.ExecuteNonQuery();
         Connection.Close();
         return(true);
     }
 }
Beispiel #7
0
        public string InsertAndGetId(string tableName, Dictionary <string, string> dataset)
        {
            string query = QueryMaker.InsertQueryWithID(tableName, dataset);

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                int id = 0;
                connection.Open();
                SqlCommand cmd = new SqlCommand(query, connection);
                id = Convert.ToInt32(cmd.ExecuteScalar());
                connection.Close();
                return(id.ToString());
            }
        }
Beispiel #8
0
 public static bool Update <T>(T _Object, string whereClause, Dictionary <string, string> values, string schemaName = null, string tableName = null)
 {
     return(ExecuteQuery(QueryMaker.UpdateQuery(_Object, whereClause, schemaName, tableName), values));
 }
Beispiel #9
0
 public static bool Insert(string tableName, Dictionary <string, string> dataset)
 {
     return(ExecuteQuery(QueryMaker.InsertQuery(tableName, dataset)));
 }
Beispiel #10
0
 public static bool Insert <T>(T _Object, string schemaName = null, string tableName = null)
 {
     return(ExecuteQuery(QueryMaker.InsertQuery(_Object, schemaName, tableName)));
 }
Beispiel #11
0
 public void BeginTrans()
 {
     Query  = string.Empty;
     Query += QueryMaker.BeginTransQuery();
 }
Beispiel #12
0
 public static bool Delete <T>(string whereClause, Dictionary <string, string> values, string schemaName = null, string tableName = null)
 {
     return(ExecuteQuery(QueryMaker.DeleteQuery <T>(whereClause), values));
 }
Beispiel #13
0
 public static bool Update(string tableName, Dictionary <string, string> dataset, string whereClause)
 {
     return(ExecuteQuery(QueryMaker.UpdateQuery(tableName, dataset, whereClause)));
 }