using System.Collections;
using System.Data;
using System.Data.SqlClient;
using Business.System.Op.Entity;
using Common;

namespace Business.System.Op.Vo
{
    public class OpVo
    {
        /// <summary>
        /// 获取所有操作
        /// </summary>
        /// <returns>数据表</returns>
        public DataTable AllOp()
        {
            var sql = "select * from SysOp order by parentcode";
            return SqlHelper.ExecSqlDateTable(sql);
        }


        /// <summary>
        /// 执行sql,返回操作实体类列表
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="sqlParameters">sql参数</param>
        public ArrayList OpList(string sql, params SqlParameter[] sqlParameters)
        {
            var con = new SqlConnection(SqlHelper.ConStr);
            var cmd = new SqlCommand { Connection = con, CommandType = CommandType.Text, CommandText = sql };
            var op = new ArrayList();
            if (sqlParameters.Length > 0)
            {
                SqlHelper.CmdGetParam(cmd, sqlParameters);
            }
            try
            {
                con.Open();
            }
            catch
            {
                return op;
            }
            using (var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
            {
                if (!reader.HasRows)
                    return op;
                while (reader.Read())
                {
                    var opEty = new OpEty
                    {
                        Code = SqlHelper.ReaderString("code", reader),
                        Name = SqlHelper.ReaderString("name", reader),
                        ParentCode = SqlHelper.ReaderString("parentcode", reader)
                    };
                    op.Add(opEty);
                }
            }
            return op;
        }
    }
}
