using System;
using System.Collections.Generic;
using System.Text;
using Dapper;
using AutoTurnOver.Models;

namespace AutoTurnOver.DB
{
    public class common:connectionHelper
    {
        /// <summary>
        /// 获取仓库列表
        /// </summary>
        /// <returns></returns>
        public static List<dc_base_warehouse> ListWareHouse(int? type)
        {
            var sql = "select * from dc_base_warehouse_oa where is_enabled=1";

            if (type.HasValue)
            {
                sql += " and warehouse_type="+type.Value;
            }


            return _connection.Query<Models.dc_base_warehouse>(sql).AsList();
        }

        public static dc_base_warehouse GetWareHouseByCode(string code)
        {
            var sql = "select * from dc_base_warehouse_oa where is_enabled=1 and warehouse_code='" + code+"'";
            return _connection.QueryFirstOrDefault<dc_base_warehouse>(sql);
        }

        /// <summary>
        /// 获取仓库类型列表
        /// </summary>
        /// <returns></returns>
        public static List<mwarehousetype> ListWareHouseType()
        {
            var sql = "select warehouse_type as id,warehouse_type_name as name from dc_base_warehouse_oa GROUP BY warehouse_type";
            return _connection.Query<mwarehousetype>(sql).AsList();
        }

    }
}
