using ProjectBase.Data.BaseDAL.BaseDatabase;
using System;
using SIASUN.Autopilot.Model;
using System.Text;
using SIASUN.Autopilot.DAL.IDALSQL;
using System.Data;
using System.Collections;
using ProjectBase.Util;

namespace SIASUN.Autopilot.DAL.DALSQL
{
    public class DalLogOperation : BaseDALSQL<MoLogOperation>, IDalLogOperation
    {
        #region 对象实例及构造函数

        public static DalLogOperation Instance
        {
            get
            {
                return new DalLogOperation();
            }
        }

        public DalLogOperation() : base("log_operation", new string[] { "operation_id" })
        {
            this.sortField = "operation_id";
            this.isDescending = false;
        }

        #endregion

        /// <summary>
        /// 将DataReader的属性值转化为实体类的属性值，返回实体类
        /// </summary>
        /// <param name="dr">有效的DataReader对象</param>
        /// <returns>实体类对象</returns>
        protected override MoLogOperation DataReaderToEntity(IDataReader dataReader)
        {
            MoLogOperation info = new MoLogOperation();
            SmartDataReader reader = new SmartDataReader(dataReader);

            info.ID = reader.GetInt64("operation_id");
            info.Account = reader.GetString("operation_account");
            info.Name = reader.GetString("operation_name");
            info.GroupId = reader.GetString("operation_groupId");
            info.TableName = reader.GetString("operation_tableName");
            info.Type = reader.GetString("operation_type");
            info.Ip = reader.GetString("operation_ip");
            info.Mac = reader.GetString("operation_mac");
            info.Time = Convert.ToDateTime(reader.GetString("operation_time"));
            return info;
        }

        /// <summary>
        /// 将实体对象的属性值转化为Hashtable对应的键值
        /// </summary>
        /// <param name="obj">有效的实体对象</param>
        /// <returns>包含键值映射的Hashtable</returns>
        protected override Hashtable GetHashByEntity(MoLogOperation obj)
        {
            MoLogOperation info = obj as MoLogOperation;
            Hashtable hash = new Hashtable();

            //hash.Add("logIn_id", info.ID);
            hash.Add("operation_account", info.Account);
            hash.Add("operation_name", info.Name);
            hash.Add("operation_groupId", info.GroupId);
            hash.Add("operation_tableName", info.TableName);
            hash.Add("operation_type", info.Type);
            hash.Add("operation_ip", info.Ip);
            hash.Add("operation_mac", info.Mac);
            hash.Add("operation_time", info.Time);

            return hash;
        }
    }
}
