/*
 * 作者:吴隆健
 * 日期: 2019-04-07
 * 时间: 20:05
 *
 */

#if MMSQL
using System;
using System.Data;
using System.Data.SqlClient;

namespace MrWu.DB
{
    /// <summary>
    /// 存储过程查询键
    /// </summary>
    public class SqlProcedureParameter : IProdureParameter<SqlCommand>
    {
        SqlCommand _sqlcommand;

        /// <summary>
        /// 查询键
        /// </summary>
        public SqlCommand command
        {
            get => _sqlcommand;
        }

        private string _dbName;

        /// <summary>
        /// 数据库名称
        /// </summary>
        public string dbName
        {
            get => _dbName;
        }

        /// <summary>
        /// 错误信息
        /// </summary>
        public Exception exception { get; set; }

        /// <summary>
        /// 是否报错
        /// </summary>
        public bool isException
        {
            get { return exception != null; }
        }

        private SqlProcedureParameter()
        {
        }

        internal SqlProcedureParameter(SqlCommand sqlcommand, string dbName)
        {
            this._sqlcommand = sqlcommand;
            this._dbName = dbName;
        }

        /// <summary>
        /// 释放
        /// </summary>
        public void Dispose()
        {
            if (_sqlcommand != null)
            {
                _sqlcommand.Dispose();
                _sqlcommand = null;
            }
        }
    }

    /// <summary>
    /// 单独设置参数
    /// </summary>
    public class SqlAloneParameter : ISqlAloneParameter<SqlDbType>
    {
        string _paramname;

        /// <summary>
        /// 参数名称
        /// </summary>
        public string paramname
        {
            get => _paramname;
        }

        object _paramvalue;

        /// <summary>
        /// 参数值
        /// </summary>
        public object paramvalue
        {
            get => _paramvalue;
            set => _paramvalue = value;
        }

        SqlDbType _type;

        /// <summary>
        /// 参数类型
        /// </summary>
        public SqlDbType type => _type;

        int _valueLength;

        /// <summary>
        /// 参数长度
        /// </summary>
        public int valueLength => _valueLength;

        /// <summary>
        /// sql语句单独设置参数
        /// </summary>
        /// <param name="paramname">参数名称</param>
        /// <param name="paramvalue">参数值</param>
        /// <param name="valuelength">参数值的长度</param>
        /// <param name="type">参数类型</param>
        public SqlAloneParameter(string paramname, object paramvalue, int valuelength = 0,
            SqlDbType type = SqlDbType.Binary)
        {
            this._paramname = paramname;
            this._paramvalue = paramvalue;
            this._valueLength = valuelength;
            this._type = type;
        }

        /// <summary>
        /// Direction
        /// </summary>
        public ParameterDirection Direction { get; set; }
    }
}
#endif