using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataLinkMesWork;

//using SystemFramework;

namespace bizFacade
{
    public partial class BaseDataSystemMES
    {
        /// <summary>
        /// 登录用户与工位校验
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="opName"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        static public bool User_WorkCenter(string userName,string opName, out bool result)
        {
            string sql;
            DataTable dt = null;
            sql = "SELECT COUNT(*) as usercount FROM [dbo].[MES_Web_User]"
                 +"where[UserId] = (select top 1 ID from MES_用户管理_人员 where 用户名 = '"+userName+"') and OpName = '"+opName+"'";
            DataAccess.ExecuteDataTable(sql, out dt);
            string usercount = dt.Rows[0]["usercount"].ToString();
            if (dt.Rows.Count > 0 && usercount == "1")
            {
                return result=true;
            }
            else {
                return result=false;
            }
        }

        /// <summary>
        /// MES_用户管理_人员信息_视图_显示_查询
        /// </summary>
        /// <param name="dt"></param>
        static public void UserInfo_Select(out DataTable dt)
        {
            dt = null;
            string sql = "exec MES_用户管理_人员信息_视图_显示_查询";
            DataAccess.ExecuteDataTable(sql, out  dt);
        }

        /// <summary>
        /// [MES_用户管理_人员信息_视图_显示车间操作员_查询]
        /// </summary>
        /// <param name="dt"></param>
        static public void UserInfo_OPStaff_Select(out DataTable dt)
        {
            dt = null;
            string sql = "exec MES_用户管理_人员信息_视图_显示车间操作员_查询";
            DataAccess.ExecuteDataTable(sql, out  dt);
        }

        /// <summary>
        /// MES_用户管理_角色_查询
        /// </summary>
        static public void StaffRole_select(out DataTable dt)
        {
            string sql;
            sql = "exec MES_用户管理_角色_查询";
            DataAccess.ExecuteDataTable(sql, out  dt);
        }

        /// <summary>
        /// [MES_用户管理_人员_增加_查询]
        /// 执行后，返回count(*)
        /// </summary>
        /// <param name="userName"></param>

        public static int UserInfo_Select_ForInsert(string userID)
        {
            int count;
            string sql;
            sql = "exec MES_用户管理_人员_增加_查询 '" + userID + "'";
            DataAccess.ExecuteOutNum(sql, out  count);
            return count;
        }

        /// <summary>
        /// MES_用户管理_人员_增加
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="user"></param>
        static public bool UserInfo_Insert(string userID, string userName, int roleNum)
        {
            string procedureName;
            procedureName = "MES_用户管理_人员_增加";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@用户名", userID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@员工姓名", userName);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@角色代码", roleNum);
            return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);

        }

        /// <summary>
        /// MES_用户管理_人员_修改
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="user"></param>
        static public bool UserInfo_Update(int ID,string userID,string userPassword,string userName, int roleNum)
        {
            string procedureName;
            procedureName = "MES_用户管理_人员_修改";
            SqlParameter[] thisParms = new SqlParameter[5];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@ID", ID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@用户名", userID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@密码", userPassword);
            thisParms[3] = new System.Data.SqlClient.SqlParameter("@员工姓名", userName);
            thisParms[4] = new System.Data.SqlClient.SqlParameter("@角色代码", roleNum);
    
            return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);


        }

        /// <summary>
        /// MES_用户管理_人员_姓名_修改
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="user"></param>
        static public bool UserInfo_Name_Update(int ID, string userID,string userName)
        {
            string procedureName;
            procedureName = "MES_用户管理_人员_姓名_修改";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@ID", ID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@用户名", userID);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@员工姓名", userName);
         return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);


        }

        /// <summary>
        ///[MES_用户管理_人员_删除]
        /// </summary>
        static public bool UserInfo_Delete(int ID, string userID)
        {
            string procedureName;
            procedureName = "MES_用户管理_人员_删除";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@ID", ID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@用户名", userID);
            return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);

        }


        /// <summary>
        /// MES_用户管理_人员登录_查询
        /// </summary>
        /// <param name="engineID"></param>
        /// <param name="dt"></param>
        static public void UserInfo_Login(string userID, string userPassword, out DataTable dt)
        {
            string procedureName;
            procedureName = "MES_用户管理_人员登录_查询";
            //procedureName = "权限管理_用户登录_查询数据";
            SqlParameter[] thisParms = new SqlParameter[2];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@用户名", userID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@密码", userPassword);
            DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out dt);
        }


        /// <summary>
        /// MES_用户管理_人员登录_是否存在_查询
        /// 执行后，返回count(*)
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="newPassword"></param>
        /// <returns></returns>
        public static int UserInfo_Login_Exist_Select(string userID,string userPassword)
        {
            int count;
            string sql;
            sql = "exec MES_用户管理_人员登录_是否存在_查询 '" + userID + "'" + ",'" + userPassword + "'";
            DataAccess.ExecuteOutNum(sql, out  count);
            return count;
        }


        /// <summary>
        /// MES_用户管理_人员_密码_修改
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="user"></param>
        static public bool UserInfo_Password_Update(string userID, string userPassword,string userNewPassword)
        {
            string procedureName;
            procedureName = "MES_用户管理_人员_密码_修改";
            SqlParameter[] thisParms = new SqlParameter[3];
            thisParms[0] = new System.Data.SqlClient.SqlParameter("@用户名", userID);
            thisParms[1] = new System.Data.SqlClient.SqlParameter("@密码", userPassword);
            thisParms[2] = new System.Data.SqlClient.SqlParameter("@新密码", userNewPassword);

            return DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms);


        }

        /// <summary>
        /// 基本数据_工作日历_班次查询  2013-11-07 查出当前时间班次
        /// </summary>
        /// <param name="engineID"></param>
        /// <param name="dt"></param>
        static public void UserShift_Select(out DataTable dt)
        {
            string procedureName;
            procedureName = "基本数据_工作日历_班次查询";
            DataAccess.ExecuteStoredProcedure(procedureName,out dt);
        }


    }
}
