/// <summary>
        /// 检测顶级企业的登陆用户是否存在
        /// </summary>
        /// <param name="userName">登陆名</param>
        /// <param name="password">登陆密码</param>
        /// <returns></returns>
        public static Model_Customer CheckCustomerUser(string userName, string password)
        {
            string         sql      = "select * from customer where role = 1 and actived = 0 limit 1;";
            Model_Customer customer = _SqlHelp.ExecuteObject <Model_Customer>(sql);

            if (customer == null)
            {
                throw new Exception("顶级企业不存在!");
            }
            sql = "select * from customer_users where userName=?p1 and customerId = ?p2 limit 1;";
            MySqlParameter[] p = new MySqlParameter[2];
            p[0] = new MySqlParameter("p1", userName);
            p[1] = new MySqlParameter("p2", customer.Id);
            Model_CustomerUser user = _SqlHelp.ExecuteObject <Model_CustomerUser>(sql, p);

            if (user == null)
            {
                throw new Exception(string.Format("用户名'{0}'不存在!", userName));
            }
            if (user.Password.ToUpper() != MyTool.UserMd5(password).ToUpper())
            {
                throw new Exception("密码不正确!");
            }
            if (user.Actived == Model.MyEnum.Enum_Active.Disable)
            {
                throw new Exception("用户已停用");
            }

            return(customer);
        }
Beispiel #2
0
        public static Model_CustomerUser ChangePassWord(Model_CustomerUser customerUser)
        {
            string sql = "";

            if (customerUser.Id == 0)
            {
                //查询用户是否存在
                Model_CustomerUser user = GetUserName(customerUser);
                if (user != null)
                {
                    throw new Exception("用户已存在");
                }
            }
            if (customerUser.Id != 0)
            {
                //查询管理员账号是否存在一个
                Model_Customer custmer = CustomerServer.GetQueryCustomer(customerUser.CustomerId);
                if (custmer.Role == Enum_Role.Administrator && customerUser.Actived == Enum_Active.Disable)
                {
                    List <Model_CustomerUser> counts = GetActived(customerUser);
                    if (counts.Count <= 1)
                    {
                        throw new Exception("不能全部停用,至少要存在一个启用账号");
                    }
                }
                Model_CustomerUser use = GetPassword(customerUser);
                //if (use.CustomerId== customerUser.CustomerId && use.DisplayName== customerUser.DisplayName && use.UserName== customerUser.UserName && use.Password== customerUser.Password && use.CreateAt== customerUser.CreateAt && use.Actived== customerUser.Actived)
                //    throw new Exception("密码相同,请修改密码");
                if (use.UserName != customerUser.UserName)
                {
                    Model_CustomerUser user = GetUserName(customerUser);
                    if (user != null)
                    {
                        throw new Exception("用户已存在");
                    }
                }
                if (use.Password.ToUpper() == MyTool.UserMd5(customerUser.Password).ToUpper())
                {
                    throw new Exception("用户密码已存在,请修改密码");
                }
            }
            if (customerUser.Id == 0)
            {
                sql = "insert into customer_users(customerId,username,password,displayName,createAt,actived) values(?customerId,?username,?password,?displayName,?createAt,?actived)";
            }
            else
            {
                sql = "update customer_users set displayName=?displayName,username=?username,password=?password,actived=?actived where id=?id";
            }
            MySqlParameter[] para = new MySqlParameter[7];
            para[0] = new MySqlParameter("customerId", customerUser.CustomerId);
            para[1] = new MySqlParameter("username", customerUser.UserName);
            if (customerUser.Id != 0)
            {
                //判断是否修改过密码
                Model_CustomerUser use = GetPassword(customerUser);
                if (use.Password.ToUpper() == customerUser.Password.ToUpper())
                {
                    para[2] = new MySqlParameter("password", customerUser.Password.ToUpper());
                }
                else
                {
                    para[2] = new MySqlParameter("password", MyTool.UserMd5(customerUser.Password).ToUpper());
                }
            }
            else
            {
                para[2] = new MySqlParameter("password", MyTool.UserMd5(customerUser.Password).ToUpper());
            }
            para[3] = new MySqlParameter("displayName", customerUser.DisplayName);
            para[4] = new MySqlParameter("createAt", customerUser.CreateAt);
            para[5] = new MySqlParameter("actived", customerUser.Actived);
            para[6] = new MySqlParameter("id", customerUser.Id);


            int result = 0;

            if (customerUser.Id == 0)
            {
                result = _SqlHelp.ExecuteNonQuery(sql, para);
            }
            else
            {
                result = _SqlHelp.ExecuteNonQuery(sql, para);
            }
            if (result != 1)
            {
                throw new Exception("操作失败");
            }

            return(customerUser);
        }