Exemple #1
0
        public int InsertIDENTITY(T obj)
        {
            IFactory factory = DBHelper.CreateFactory();

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

            try
            {
                string    query = GenerateQuery.CommandTextInsertIDENTITY(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);
        }
Exemple #2
0
        public int InsertIDENTITYWithTransactionWithMaxField(T obj, IFactory factory, string fieldMax)
        {
            string    query = GenerateQuery.CommandTextInsertIDENTITYWithMaxFiels(obj, fieldMax);
            DbCommand cmd   = factory.MakeCommand(query);

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

            return(int.Parse(output.ToString()));
        }
Exemple #3
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));
        }