Пример #1
0
        protected bool Exec(string ProcedureName, params SqlParameter[] parameter)
        {
            //IList<SqlParameter> listOutput = null;
            try
            {
                if (_context.Database.Connection.State != ConnectionState.Open)
                {
                    _context.Database.Connection.Open();
                }
                var command = _context.Database.Connection.CreateCommand();
                command.CommandText = ProcedureName;
                command.CommandType = CommandType.StoredProcedure;
                SqlParameter output        = null;
                string       outputMessage = string.Empty;
                foreach (SqlParameter p in parameter)
                {
                    command.Parameters.Add(p);
                    if (string.Compare(p.ParameterName, "OutputMessage", true) == 0)
                    {
                        output = p;
                    }
                    //else if(p.Direction == ParameterDirection.Output) {
                    //    if (listOutput == null) {
                    //        listOutput = new List<SqlParameter>();
                    //    }
                    //    listOutput.Add(p);
                    //}
                }

                var count = command.ExecuteNonQuery();
                if (output != null)
                {
                    output.CheckOutputErrorMessage();
                }

                //if (listOutput != null && listOutput.Count() > 0) {

                //}
                return(true);
            }
            catch (Exception ex) { throw ex; }
            finally { if (_context != null && _context.Database.Connection.State == ConnectionState.Open)
                      {
                          _context.Database.Connection.Close();
                      }
            }

            return(false);
        }
Пример #2
0
        protected IList <T> GetList1 <T>(Func <DbDataReader, IList <T> > Method
                                         , Dictionary <string, string> Mapping, string ProcedureName, params SqlParameter[] parameter) //where T : new()
        {
            IList <T> data = null;

            try
            {
                if (_context.Database.Connection.State != ConnectionState.Open)
                {
                    _context.Database.Connection.Open();
                }
                var command = _context.Database.Connection.CreateCommand();
                command.CommandText = ProcedureName;
                command.CommandType = CommandType.StoredProcedure;
                SqlParameter output        = null;
                string       outputMessage = string.Empty;
                foreach (SqlParameter p in parameter)
                {
                    command.Parameters.Add(p);
                    if (string.Compare(p.ParameterName, "OutputMessage", true) == 0)
                    {
                        output = p;
                    }
                }

                using (var reader = command.ExecuteReader())
                {
                    if (output != null)
                    {
                        output.CheckOutputErrorMessage();
                    }

                    data = Method(reader);
                }
            }
            finally { if (_context != null && _context.Database.Connection.State == ConnectionState.Open)
                      {
                          _context.Database.Connection.Close();
                      }
            }

            return(data);
        }
Пример #3
0
        protected DbDataReader GetDbDataReader(string ProcedureName, params SqlParameter[] parameter)
        {
            DbDataReader data = null;

            try
            {
                if (_context.Database.Connection.State != ConnectionState.Open)
                {
                    _context.Database.Connection.Open();
                }
                var command = _context.Database.Connection.CreateCommand();
                command.CommandText = ProcedureName;
                command.CommandType = CommandType.StoredProcedure;
                SqlParameter output        = null;
                string       outputMessage = string.Empty;
                foreach (SqlParameter p in parameter)
                {
                    command.Parameters.Add(p);
                    if (string.Compare(p.ParameterName, "OutputMessage", true) == 0)
                    {
                        output = p;
                    }
                }

                using (var reader = command.ExecuteReader())
                {
                    if (output != null)
                    {
                        output.CheckOutputErrorMessage();
                    }
                    data = reader;
                }
            }
            finally { if (_context != null && _context.Database.Connection.State == ConnectionState.Open)
                      {
                          _context.Database.Connection.Close();
                      }
            }

            return(data);
        }
Пример #4
0
        protected DataSet GetDataSetResult(string ProcedureName, params SqlParameter[] Parameter)
        {
            DataSet        retVal  = new DataSet();
            SqlConnection  sqlConn = (SqlConnection)_context.Database.Connection;
            SqlCommand     command = new SqlCommand(ProcedureName, sqlConn);
            SqlDataAdapter da      = new SqlDataAdapter(command);

            SqlParameter output = null;

            using (command)
            {
                BindParameter(command, ref output, Parameter);
                command.CommandType = CommandType.StoredProcedure;
                da.Fill(retVal);
                if (output != null)
                {
                    output.CheckOutputErrorMessage();
                }
            }
            return(retVal);
        }