Exemple #1
0
        public static void ExcuteNonQuery(string query, DGCParameter[] param)
        {
            IFactory factory = CreateFactory();

            try
            {
                DbCommand cmd = factory.MakeCommand(query);
                GenerateQuery.PrepareParametersList(cmd, param);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Write2Log.WriteLogs("DBHelper", "ExcuteNonQuery(string query, DGCParameter[] param)", ex.Message);
            }
        }
Exemple #2
0
        public static DataSet ExcuteDataSetFromCmd(string stroreName, DGCParameter[] parameters)
        {
            DataSet  ds = null;
            Database db = CreateDB();

            try
            {
                DbCommand cmd = db.GetSqlStringCommand(stroreName);
                GenerateQuery.PrepareParametersList(cmd, parameters);
                ds = db.ExecuteDataSet(cmd);
            }
            catch (Exception ex)
            {
                Write2Log.WriteLogs("Generic<T>", "ExcuteFromStore(string stroreName, DGCParameter[] parameters)", ex.Message);
            }
            return(ds);
        }
Exemple #3
0
        /// <summary>
        /// Get All by a table in DB with where Clause
        /// </summary>
        /// <param name="obj">a object in Model</param>
        /// <param name="whereClause"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static DataSet GetAllByDataSet(object obj, string whereClause, DGCParameter[] parameters)
        {
            DataSet  ds = null;
            Database db = CreateDB();

            try
            {
                string    query = GenerateQuery.CommandTextList(obj, whereClause);
                DbCommand cmd   = db.GetSqlStringCommand(query);
                GenerateQuery.PrepareParametersList(cmd, parameters);
                ds = db.ExecuteDataSet(cmd);
            }
            catch (Exception ex)
            {
                Write2Log.WriteLogs("DBHElper", "GetAllByDataSet(object obj, string whereClause, DGCParameter[] parameters)", ex.Message);
            }
            return(ds);
        }
Exemple #4
0
        public static DataTable ExcuteFromCmd(string query, DGCParameter[] parameters)
        {
            DataTable dt = new DataTable();
            Database  db = CreateDB();

            try
            {
                DbCommand cmd = db.GetSqlStringCommand(query);
                GenerateQuery.PrepareParametersList(cmd, parameters);
                DataSet ds = db.ExecuteDataSet(cmd);
                dt = ds.Tables[0];
            }
            catch (Exception ex)
            {
                Write2Log.WriteLogs("Generic<T>", "ExcuteFromCmd(string query, DGCParameter[] parameters)", ex.Message);
            }
            return(dt);
        }
Exemple #5
0
        public static int ProcessUpdate(DataSet ds, string insert, string update, DGCParameter[] paramInsert, DGCParameter[] paramUpdate)
        {
            Database db           = CreateDB();
            int      rowsAffected = 0;

            try
            {
                DbCommand cmdInsert = db.GetSqlStringCommand(insert);
                GenerateQuery.PrepareParametersListWithSourceColumn(cmdInsert, paramInsert);
                DbCommand cmdUpdate = db.GetSqlStringCommand(update);
                GenerateQuery.PrepareParametersListWithSourceColumn(cmdUpdate, paramUpdate);
                rowsAffected = db.UpdateDataSet(ds, "Table", cmdInsert, cmdUpdate, null, UpdateBehavior.Transactional);
            }
            catch (Exception ex)
            {
                Write2Log.WriteLogs("Generic<T>", "ExcuteFromCmd(string query, DGCParameter[] parameters)", ex.Message);
            }
            return(rowsAffected);
        }
Exemple #6
0
        public static void ExcuteFromStoreNonQuery(string stroreName, DGCParameter[] parameters)
        {
            Database  db  = CreateDB();
            DbCommand cmd = null;

            try
            {
                cmd = db.GetStoredProcCommand(stroreName);
                GenerateQuery.PrepareParametersList(cmd, parameters);
                db.ExecuteNonQuery(cmd);
            }
            catch (Exception ex)
            {
                Write2Log.WriteLogs("Generic<T>", "ExcuteFromStore(string stroreName, DGCParameter[] parameters)", ex.Message);
            }
            finally
            {
                cmd.Connection.Close();
                cmd.Dispose();
            }
        }
Exemple #7
0
        public static int ExcuteIntFromStore(string stroreName, DGCParameter[] parameters)
        {
            DataSet  ds  = null;
            Database db  = CreateDB();
            int      ret = 0;

            try
            {
                DbCommand cmd = db.GetStoredProcCommand(stroreName);
                GenerateQuery.PrepareParametersList(cmd, parameters);
                ds = db.ExecuteDataSet(cmd);
                if (ds != null && ds.Tables.Count > 0)
                {
                    ret = ds.Tables.Count;
                }
            }
            catch (Exception ex)
            {
                Write2Log.WriteLogs("Generic<T>", "ExcuteFromStore(string stroreName, DGCParameter[] parameters)", ex.Message);
            }
            return(ret);
        }
        public static object ParseDBToObject(IDataReader dre, PropertyInfo property)
        {
            object result = null;
            Type   t      = property.PropertyType;

            switch (Type.GetTypeCode(t))
            {
            case TypeCode.Int32:
                result = INT_MIN_VALUE;
                break;

            case TypeCode.String:
                result = string.Empty;
                break;

            case TypeCode.Double:
                result = DOUBLE_MIN_VALUE;
                break;

            case TypeCode.DateTime:
                result = DATETIME_MIN_VALUE;
                break;

            case TypeCode.Decimal:
                result = DECIMAL_MIN_VALUE;
                break;

            case TypeCode.Int16:
                result = SMALLINT_MIN_VALUE;
                break;

            case TypeCode.Byte:
                result = BYTE_MIN_VALUE;
                break;

            case TypeCode.Char:
                result = TIMESPAN_MIN_VALUE;
                break;

            case TypeCode.Boolean:
                result = false;
                break;
            }

            try
            {
                //truong hop ten file giong ten properties va them chu Desc
                if (HasCoulmn(dre, property.Name) && !dre.IsDBNull(dre.GetOrdinal(property.Name)))
                {
                    result = dre.GetValue(dre.GetOrdinal(property.Name));
                }
                else
                {
                    string propertyNameDesc = property.Name.Replace("Desc", string.Empty);
                    if (HasCoulmn(dre, propertyNameDesc) && !dre.IsDBNull(dre.GetOrdinal(propertyNameDesc)))
                    {
                        result = dre.GetValue(dre.GetOrdinal(propertyNameDesc));
                    }
                }
            }
            catch (Exception ex)
            {
                Write2Log.WriteLogs("DBConvert", "ParseDBToObject(IDataReader dre, PropertyInfo property)", ex.Message);
            }
            if (result != null && result.GetType() == typeof(byte[]))
            {
                result = ConvertByteArrToObject((byte[])result, Type.GetTypeCode(t));
            }
            return(result);
        }