• static instance examples


    Code C#:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data;
    using System.Web.Security;
    using System.Xml;
    
    namespace HyeyCRM.BLL.Comm
    {
        /// <summary>
        /// 终端采购会员
        /// </summary>
         public class FinalUser
        {
            public string TrueName
            {
                get { return getUserData("Truename"); }
            }
    
    
            public string UserName
            {
                get
                {
    
                    return getUserData("UserName");
                }
    
            }
    
            public string UserID
            {
                get
                {
    
                    return getUserData("UserID");
                }
    
            }
    
            /// <summary>
            /// 会员组编号
            /// </summary>
            public string GroupID
            {
                get
                {
    
                    return getUserData("GroupID");
                }
    
            }
            /// <summary>
            /// 用户权限字符串
            /// </summary>
            public string RightList
            {
                get
                {
                    return getUserData("RightList");
                }
            }
    
            string getUserData(string dataTitle)
            {
                string dataValue = null;
    
                if (System.Web.HttpContext.Current.User != null)
                {
                    if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
                    {
                        if (System.Web.HttpContext.Current.User.Identity is FormsIdentity)
                        {
                            FormsIdentity id = (FormsIdentity)System.Web.HttpContext.Current.User.Identity;
                            FormsAuthenticationTicket ticket = id.Ticket;
    
    
                            // 取存储在票据中的用户数据,
                            string userData = ticket.UserData;
                            string[] roles = userData.Split(';');
    
                            foreach (string s in roles)
                            {
                                if (s.StartsWith(dataTitle))
                                {
                                    dataValue = s.Substring(dataTitle.Length + 1);
                                    break;
                                }
                            }
    
                        }
    
                    }
                }
    
                return dataValue;
    
    
            }
    
            #region 静态化实例对象
    
            private static readonly FinalUser _user = null;
    
            static FinalUser()
            {
                _user = new FinalUser();
            }
            public static FinalUser Instance()
            {
                return _user;
            }
            private FinalUser()
            {
    
            }
    
            #endregion
    
        }
        public class UserManager
        { 
           /// <summary>
            /// 获取当前终端采购会员的会员组和所属的业务员ID
           /// </summary>
           /// <param name="userid"></param>
           /// <returns></returns>
            public Dictionary<int, int> getYwUserAndGroupIDByUserID(string userid)
            {
                Dictionary<int, int> dicValue = new Dictionary<int, int>();
    
                string strSql = "select sid,userGroup From CustomerRelationship where cid="+userid;
                try
                {
                    DataSet ds = CommonClass.GetList(strSql);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        dicValue.Add(int.Parse(ds.Tables[0].Rows[0]["sid"].ToString()), int.Parse(ds.Tables[0].Rows[0]["userGroup"].ToString()));
                    }
                }
                catch
                {
                }
    
                
                return dicValue;
    
            }
            /// <summary>
            ///  获取当前终端采购会员的库存名状态和销售状态的业务员ID
            /// </summary>
            /// <param name="YwUserid"></param>
            /// <returns></returns>
            public Dictionary<int, int> getYwCkAndYwSalesStateByUserID(string YwUserid)
            {
                Dictionary<int, int> dicValue = new Dictionary<int, int>();
    
                string strSql = "select ywck,YwsalesState From MembersView where userid=" + YwUserid;
                try
                {
                    DataSet ds = CommonClass.GetList(strSql);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        dicValue.Add(int.Parse(ds.Tables[0].Rows[0]["ywck"].ToString()), int.Parse(ds.Tables[0].Rows[0]["YwsalesState"].ToString()));
                    }
                }
                catch
                {
                }
    
    
                return dicValue;
    
            }
            /// <summary>
            /// 根据用户ID获取所属的业务员ID
            /// </summary>
            /// <param name="UserID">用户ID</param>
            /// <returns>返回业务员ID</returns>
            public int getYwUserIDByUserID(string UserID)
            {
                int YwUserID = 0;
    
                string strSql = "select sid From CustomerRelationship where cid=" + UserID;
                try
                {
                    string resultYwUserID = CommonClass.ExecScalar(strSql);
                    if (resultYwUserID != "")
                    {
                         YwUserID =  int.Parse(resultYwUserID);
                    }
                }
                catch
                {
                }
    
    
                return YwUserID;
            }
            /// <summary>
            /// 获取会员信息
            /// </summary>
            /// <returns></returns>
            public DataSet GetUserAndContacter()
            {
    
    
                string strSql = "select * from MembersView where Userid=" + YwUser.Instance().UserID;
                return CommonClass.GetList(ConnConfig.ConnString, strSql);
            }
    
            public int UpdateUserInfo(string updateSql)
            {
                updateSql = updateSql + " where  contacterid=(select contacterid from hyey_power.dbo.pe_user where userid=" + YwUser.Instance().UserID + ")";
    
                string myConnString = ConnConfig.ConnString;
                int i = CommonClass.ExecNonQuery(updateSql);
                return i;
    
            }
    
            //修改密码
            public int changePass(string newpass)
            {
                string md5Passworde = SysCode.md5(newpass, 16);
                string strSql = "Update pe_user Set UserPassWord = '" + md5Passworde + "',OldPassWord='" + newpass + "' WHERE UserName = '" + YwUser.Instance().UserName + "'";
    
                int i = CommonClass.ExecNonQuery(strSql);
                return i;
            }
            //修改密码
            /// <summary>
            /// 功能:修改密码
            /// Changes the pass by ID.
            /// </summary>
            /// <param name="newpass">新密码</param>
            /// <param name="id">用户ID</param>
            /// <returns></returns>
            public int changePassByID(string newpass, int id)
            {
                string md5Passworde = SysCode.md5(newpass, 16);
                string strSql = "Update pe_user Set UserPassWord = '" + md5Passworde + "',OldPassWord='" + newpass + "' WHERE Userid = '" + id + "'";
    
                int i = CommonClass.ExecNonQuery(strSql);
                return i;
            }
            public int Delete(string IDstr)
            {
                string sql = "delete pe_user where Userid in (" + IDstr + ")";
                return CommonClass.ExecNonQuery(sql);
    
            }
    
            #region 静态化实例对象
    
            private static readonly UserManager _usermanager = null;
    
            static UserManager()
            {
                _usermanager = new UserManager();
            }
            public static UserManager Instance()
            {
                return _usermanager;
            }
            private UserManager()
            {
    
            }
    
            #endregion
    
        }
    }
    
    

  • 相关阅读:
    Windows 8实用窍门系列:18.windows 8开发模拟器和windows 8程序中关联文件类型
    Silverlight实用窍门系列:75.Silverlight中DataGrid制作复杂表头
    Windows 8实用窍门系列:11.Windows 8 中的Toast Tile Badge通知
    Windows 8实用窍门系列:9.Windows 8中使用FlipView
    Windows 8实用窍门系列:12.windows 8的文件管理1.File创建和String Stream Buffer方式读写
    Silverlight实用窍门系列:74.Silverlight使用Perst数据库Demo
    Windows 8实用窍门系列:17.文件选择器 文件保存器 文件夹选择器
    Windows 8实用窍门系列:16.Windows 8的右键菜单
    Windows 8实用窍门系列:3.第一个拆分布局应用程序修改Logo
    Windows 8实用窍门系列:19.Windows 8中的GridView使用(一)
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1825789.html
Copyright © 2020-2023  润新知