Esempio n. 1
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="UID"></param>
        /// <returns></returns>
        public static Models.UserModel GetUserModel(int UID)
        {
            Models.UserModel model = null;
            if (UID > 0)
            {
                //缓存
                DateTime expiry = DateTime.Now.AddMinutes(1);
                string   key    = "BaseController.GetUserModel." + UID;
                Memcached.ClientLibrary.MemcachedClient mc = new Memcached.ClientLibrary.MemcachedClient();
                if (mc.KeyExists(key))
                {
                    model = mc.Get(key) as Models.UserModel;
                    if (model != null)
                    {
                        return(model);
                    }
                }

                SOSOshop.BLL.Db db  = new SOSOshop.BLL.Db();
                StringBuilder   sql = new StringBuilder();
                sql.Append("select UserId, MobilePhone, Email, UserType, UserGroup, ");                                                          //账号
                sql.Append("TrueName, ");                                                                                                        //联系人
                sql.Append("isnull((select top(1) Name from DrugsBase_Enterprise where ID=b.ParentId),'') as IncName, b.ParentId, b.Parents, "); //单位
                sql.Append("Member_Type, Member_Class, ");                                                                                       //用户类别
                sql.Append("b.Province,b.City,b.Borough,b.Address, ");                                                                           //所在地
                sql.Append("b.OfficePhone, b.Fax, ");                                                                                            //电话、传真
                sql.Append("ISNULL((SELECT TOP(1) 1 AS M FROM membercheck WHERE CheckType='M' AND UID=a.UID),0) AS membercheckM, ");             //手机验证
                sql.Append("ISNULL((SELECT TOP(1) 1 AS M FROM membercheck WHERE CheckType='E' AND UID=a.UID),0) AS membercheckE, ");             //邮箱验证
                sql.Append("c.* ");                                                                                                              //权限
                sql.AppendFormat("from memberaccount a inner join memberinfo b on a.UID=b.UID inner join memberpermission c on a.UID=c.UID where a.UID={0}", UID);
                using (IDataReader rd = (IDataReader)db.ExecuteReader(sql.ToString()))
                {
                    if (rd != null && rd.Read())
                    {
                        //类别
                        model              = new Models.UserModel();
                        model.UserType     = int.Parse(rd["UserType"].ToString()) < 0 ? SOSOshop.Model.MemberKeyValue.UserType.无 : (SOSOshop.Model.MemberKeyValue.UserType)Enum.Parse(typeof(SOSOshop.Model.MemberKeyValue.UserType), rd["UserType"].ToString());
                        model.Member_Class = int.Parse(rd["Member_Class"].ToString()) < 0 ? SOSOshop.Model.MemberKeyValue.Member_Class.无 : (SOSOshop.Model.MemberKeyValue.Member_Class)Enum.Parse(typeof(SOSOshop.Model.MemberKeyValue.Member_Class), rd["Member_Class"].ToString());
                        model.Member_Type  = (SOSOshop.Model.MemberKeyValue.Member_Type)Enum.Parse(typeof(SOSOshop.Model.MemberKeyValue.Member_Type), rd["Member_Type"].ToString());
                        model.UserId       = Convert.ToString(rd["UserId"]);
                        model.MobilePhone  = Convert.ToString(rd["MobilePhone"]);
                        model.Email        = Convert.ToString(rd["Email"]);
                        model.LinkMan      = Convert.ToString(rd["TrueName"]);
                        model.IncName      = Convert.ToString(rd["IncName"]);
                        model.ParentId     = int.Parse(rd["ParentId"].ToString());
                        model.Province     = int.Parse(rd["Province"].ToString());
                        model.City         = int.Parse(rd["City"].ToString());
                        model.Borough      = int.Parse(rd["Borough"].ToString());
                        model.Address      = Convert.ToString(rd["Address"]);
                        model.OfficePhone  = Convert.ToString(rd["OfficePhone"]);
                        model.Fax          = Convert.ToString(rd["Fax"]);
                        //验证
                        model.CheckM = int.Parse(rd["membercheckM"].ToString()) == 1;
                        model.CheckE = int.Parse(rd["membercheckE"].ToString()) == 1;
                        //权限
                        SOSOshop.BLL.MemberPermission mpBll = new SOSOshop.BLL.MemberPermission();
                        model.MemberPermission = mpBll.GetModelByDataReader(rd);
                        rd.Close();
                        //缓存
                        mc.Set(key, model, expiry);
                    }
                }
            }
            return(model);
        }