using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;

namespace JLHHJSvr.Com.Model
{
    public sealed class Power
    {
        public int? funid { get; set; }
        /// <summary>
        /// 模块
        /// </summary>
        public string moduleName { get; set; }
        /// <summary>
        /// 窗口名称
        /// </summary>
        public string winName { get; set; }
        /// <summary>
        /// 功能名称
        /// </summary>
        public string funcName { get; set; }
        /// <summary>
        /// 是否有权限
        /// </summary>
        public byte? inuse { get; set; }
        /// <summary>
        /// 排序序号
        /// </summary>
        public int? sortid { get; set; }

        public List<Power> GetAllPowers()
        {
            return new List<Power>
            {
                new Power {funid = 1, moduleName = "PC", winName = "账号管理", funcName = "查看", sortid = 1},
                new Power {funid = 2, moduleName = "PC", winName = "账号管理", funcName = "新增", sortid = 2},
                new Power {funid = 3, moduleName = "PC", winName = "账号管理", funcName = "修改", sortid = 3},
                new Power {funid = 4, moduleName = "PC", winName = "账号管理", funcName = "删除", sortid = 4},
                new Power {funid = 26, moduleName = "PC", winName = "账号管理", funcName = "恢复密码", sortid = 4},
                new Power {funid = 5, moduleName = "PC", winName = "车位管理", funcName = "查看", sortid = 5},
                new Power {funid = 6, moduleName = "PC", winName = "车位管理", funcName = "新增", sortid = 6},
                new Power {funid = 7, moduleName = "PC", winName = "车位管理", funcName = "修改", sortid = 7},
                new Power {funid = 8, moduleName = "PC", winName = "车位管理", funcName = "删除", sortid = 8},
                new Power {funid = 9, moduleName = "PC", winName = "车位管理", funcName = "打印", sortid = 9},
                new Power {funid = 10, moduleName = "PC", winName = "违停管理", funcName = "查看", sortid = 10},
                new Power {funid = 11, moduleName = "PC", winName = "备案管理", funcName = "查看", sortid = 11},
                new Power {funid = 12, moduleName = "PC", winName = "备案管理", funcName = "新增", sortid = 12},
                new Power {funid = 13, moduleName = "PC", winName = "备案管理", funcName = "修改", sortid = 13},
                new Power {funid = 14, moduleName = "PC", winName = "备案管理", funcName = "删除", sortid = 14},
                new Power {funid = 15, moduleName = "PC", winName = "车辆信息", funcName = "查看", sortid = 15},
                new Power {funid = 16, moduleName = "PC", winName = "车辆信息", funcName = "新增", sortid = 16},
                new Power {funid = 17, moduleName = "PC", winName = "车辆信息", funcName = "修改", sortid = 17},
                new Power {funid = 18, moduleName = "PC", winName = "车辆信息", funcName = "删除", sortid = 18},
                new Power {funid = 19, moduleName = "PC", winName = "系统参数设置", funcName = "路段-查看", sortid = 19},
                new Power {funid = 20, moduleName = "PC", winName = "系统参数设置", funcName = "路段-新增", sortid = 20},
                new Power {funid = 21, moduleName = "PC", winName = "系统参数设置", funcName = "路段-修改", sortid = 21},
                new Power {funid = 22, moduleName = "PC", winName = "系统参数设置", funcName = "路段-删除", sortid = 22},
                new Power {funid = 23, moduleName = "PC", winName = "系统参数设置", funcName = "收款二维码-修改", sortid = 23},
                new Power {funid = 24, moduleName = "PC", winName = "系统参数设置", funcName = "参数-修改", sortid = 24},
                new Power {funid = 25, moduleName = "APP", winName = "登录", funcName = "登录", sortid = 25},
                new Power {funid = 27, moduleName = "APP", winName = "乱违停取证、处理(二维码收款)", funcName = "乱违停取证、处理(二维码收款)", sortid = 26},
                new Power {funid = 28, moduleName = "APP", winName = "车牌查询", funcName = "车牌查询", sortid = 27},
                new Power {funid = 29, moduleName = "APP", winName = "报备查询", funcName = "报备查询", sortid = 28}
            };
        }

        public bool CheckPower(DbCommand cmd, int userid, int funid)
        {
            cmd.CommandText = string.Format("SELECT userid FROM st_user_power WHERE userid = {0} AND funid = {1}",
                userid, funid);
            cmd.Parameters.Clear();
            using (var reader = cmd.ExecuteReader())
            {
                if (reader.Read())
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
    }
}
