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

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

        public static DalLocationRuleInfo Instance
        {
            get
            {
                return new DalLocationRuleInfo();
            }
        }
        public DalLocationRuleInfo() : base("location_rule_info", new string[] { "rule_name", "locaton_id" })
        {
            this.sortField = "rule_name";
            this.isDescending = false;
        }

        #endregion

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

            info.RuleName = reader.GetString("rule_name");
            info.LocatonId = reader.GetInt64("locaton_id");
            info.LocationLon = reader.GetDouble("location_lon");
            info.LocationLat = reader.GetDouble("location_lat");
            info.LocationHeight = reader.GetDouble("location_height");
            info.LocationSpeed = reader.GetFloat("location_speed");

            return info;
        }

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

            hash.Add("rule_name", info.RuleName);
            hash.Add("locaton_id", info.LocatonId);
            hash.Add("location_lon", info.LocationLon);
            hash.Add("location_lat", info.LocationLat);
            hash.Add("location_speed", info.LocationSpeed);
            hash.Add("location_height", info.LocationHeight);

            return hash;
        }
    }
}
