Exemplo n.º 1
0
        public int Insert(T obj)
        {
            IFactory factory = DBHelper.CreateFactory();

            factory.BeginTransaction();
            object output = null;
            int    re     = int.MinValue;

            try
            {
                string    query = GenerateQuery.CommandTextInsert(obj);
                DbCommand cmd   = factory.MakeCommand(query);
                GenerateQuery.PrepareParametersInsert(cmd, obj);
                output = factory.ExecuteScalar(cmd);
                factory.Commit();
                re = DBConvert.ParseInt(output);
            }
            catch (Exception ex)
            {
                Write2Log.WriteLogs("Generic<T>", string.Format("Insert({0} obj)", obj.GetType().Name), ex.Message);
                factory.Rollback();
            }
            finally
            {
                factory.Release();
            }
            return(re);
        }
Exemplo n.º 2
0
        public int InsertWithTransaction(T obj, IFactory factory)
        {
            string    query = GenerateQuery.CommandTextInsert(obj);
            DbCommand cmd   = factory.MakeCommand(query);

            GenerateQuery.PrepareParametersInsert(cmd, obj);
            object output = factory.ExecuteScalar(cmd);

            return(DBConvert.ParseInt(output));
        }