備註程式碼怕自己忘了

tokikou發表於2020-11-04
using BookShop.Model.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;

namespace BookShop.Web.ashx
{
    /// <summary>
    /// UserReg 的摘要說明
    /// </summary>
    public class UserReg : IHttpHandler,System.Web.SessionState.IRequiresSessionState
    {
        /// <summary>
        /// 註冊時表單中的資料提交過來。
        /// 自己完成服務端的資料驗證
        /// </summary>
        /// <param name="context"></param>
        BLL.UserManager userManager = new BLL.UserManager();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (!CheckUserCode(context))
            {
                context.Response.Write("no:驗證碼錯誤!!");
                context.Response.End();
            }
            //if (userManager.GetModel(context.Request["txtUserName"]) != null)
            //{
            //    context.Response.Write("no:使用者名稱已經存在!!");
            //    context.Response.End();
            //}
            context.Session["vCode"] = null;//驗證碼清空
            string msg = string.Empty;
            context.Response.Write(UserRegister(context,out msg)?"ok:"+msg:"no:"+msg);
            //傳送啟用連結.
        }
        /// <summary>
        /// 使用者註冊
        /// </summary>
        /// <param name="context"></param>
        private bool UserRegister(HttpContext context,out string msg)
        {
            Model.User userInfo = new Model.User();
            userInfo.Address = context.Request["txtUserAddress"];
            userInfo.LoginId = context.Request["txtUserName"];
            userInfo.LoginPwd =Common.WebCommon.GetMd5String(Common.WebCommon.GetMd5String(context.Request["txtUserPwd"]));
            userInfo.Mail = context.Request["txtUserEmail"];
            userInfo.Name = context.Request["txtRealUserName"];
            userInfo.Phone = context.Request["txtUserPhone"];
            userInfo.UserState.Id =Convert.ToInt32(UserStateEnum.NormalState);
           
            return userManager.Add(userInfo, out msg) > 0;
        }

        //驗證碼校驗
        private bool CheckUserCode(HttpContext context)
        {
            string vcode = context.Request["txtValidateCode"];
           return Common.WebCommon.ValidateCode(vcode);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

接下來程式碼

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BookShop.Web.ashx
{
    /// <summary>
    /// ValidateUserName 的摘要說明
    /// </summary>
    public class ValidateUserName : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string userName=context.Request["userName"];
            BLL.UserManager userManager = new BLL.UserManager();
            context.Response.Write(userManager.GetModel(userName)!=null?"ok":"no");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

還有程式碼


```csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BookShop.Web.ashx
{
    /// <summary>
    /// ValidateUserMail 的摘要說明
    /// </summary>
    public class ValidateUserMail : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
             string userMail=context.Request["userMail"];
             BLL.UserManager userManager = new BLL.UserManager();
             context.Response.Write(userManager.ValidateUserMail(userMail)?"ok":"no");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

```csharp

```csharp
using System;
using System.Data;
using System.Collections.Generic;
using LTP.Common;
using BookShop.Model;
using BookShop.DAL;


namespace BookShop.BLL
{
	/// <summary>
	/// 業務邏輯類UsersManager 的摘要說明。
	/// </summary>
	public partial class UserManager
	{
     
        UserStateServices userStateServices = new UserStateServices();
		private readonly BookShop.DAL.UserServices dal=new BookShop.DAL.UserServices();
		public UserManager()
		{}
		#region  成員方法

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在該記錄
		/// </summary>
		public bool Exists(int Id)
		{
			return dal.Exists(Id);
		}


		/// <summary>
		/// 增加一條資料
		/// </summary>
		public int  Add(BookShop.Model.User model)
		{
          
                return dal.Add(model);
           
		}

       

		/// <summary>
		/// 更新一條資料
		/// </summary>
		public void Update(BookShop.Model.User model)
		{
			dal.Update(model);
		}

		/// <summary>
		/// 刪除一條資料
		/// </summary>
		public void Delete(int Id)
		{
			
			dal.Delete(Id);
		}

		/// <summary>
		/// 得到一個物件實體
		/// </summary>
		public BookShop.Model.User GetModel(int Id)
		{
			
			return dal.GetModel(Id);
		}

 

		/// <summary>
		/// 得到一個物件實體,從快取中。
		/// </summary>
		public BookShop.Model.User GetModelByCache(int Id)
		{
			
			string CacheKey = "UsersModel-" + Id;
			object objModel = LTP.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(Id);
					if (objModel != null)
					{
						int ModelCache = LTP.Common.ConfigHelper.GetConfigInt("ModelCache");
						LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (BookShop.Model.User)objModel;
		}

		/// <summary>
		/// 獲得資料列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 獲得前幾行資料
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 獲得資料列表
		/// </summary>
		public List<BookShop.Model.User> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 獲得資料列表
		/// </summary>
		public List<BookShop.Model.User> DataTableToList(DataTable dt)
		{
			List<BookShop.Model.User> modelList = new List<BookShop.Model.User>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				BookShop.Model.User model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new BookShop.Model.User();
					if(dt.Rows[n]["Id"].ToString()!="")
					{
						model.Id=int.Parse(dt.Rows[n]["Id"].ToString());
					}
					model.LoginId=dt.Rows[n]["LoginId"].ToString();
					model.LoginPwd=dt.Rows[n]["LoginPwd"].ToString();
					model.Name=dt.Rows[n]["Name"].ToString();
					model.Address=dt.Rows[n]["Address"].ToString();
					model.Phone=dt.Rows[n]["Phone"].ToString();
					model.Mail=dt.Rows[n]["Mail"].ToString();
					
					if(dt.Rows[n]["UserStateId"].ToString()!="")
					{
					    int UserStateId=int.Parse(dt.Rows[n]["UserStateId"].ToString());
                        model.UserState = userStateServices.GetModel(UserStateId);
					}
                  
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 獲得資料列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}



		#endregion  成員方法
	}
}



相關文章