📄 usersbusiness.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Reflection;
using DBaoBookingManagement.DataAccess;
using DBaoBookingManagement.Entity;
namespace DBaoBookingManagement.BusinessLogic
{
/// <summary>
/// 对会员进行业务逻辑操作
/// </summary>
public class UsersBusiness : Business
{
private UsersAccessor ua = new UsersAccessor();
private static UsersBusiness instance = null;
private UsersBusiness() { }//私有构造函数
/// <summary>
/// 获取UsersBusiness对象
/// </summary>
/// <returns></returns>
public static UsersBusiness GetInstance()
{
if (instance == null)
{
instance = new UsersBusiness();
}
return instance;
}
/// <summary>
/// 增加会员
/// </summary>
/// <param name="userName"></param>
/// <param name="pwd"></param>
/// <param name="realName"></param>
/// <param name="sex"></param>
/// <param name="iDCard"></param>
/// <param name="phoneNum"></param>
/// <param name="goal"></param>
/// <param name="userTypeId"></param>
/// <returns></returns>
public bool Insert(string userName,string pwd,string realName,string sex,string iDCard,
string phoneNum,int goal,int userTypeId,int recId)
{
Users entity = new Users();
entity.UserName = userName;
entity.Pwd = pwd;
entity.RealName = realName;
entity.Sex = sex;
entity.IDCard = iDCard;
entity.PhoneNum = phoneNum;
entity.Goal = goal;
entity.UserTypeId = userTypeId;
entity.RecId = recId;
try
{
return ua.Insert(entity);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 修改会员
/// </summary>
/// <param name="id"></param>
/// <param name="userName"></param>
/// <param name="pwd"></param>
/// <param name="realName"></param>
/// <param name="sex"></param>
/// <param name="iDCard"></param>
/// <param name="phoneNum"></param>
/// <param name="goal"></param>
/// <param name="userTypeId"></param>
/// <returns></returns>
public bool Update(int id,string userName,string pwd,string realName,string sex,
string iDCard,string phoneNum,int goal,int userTypeId,int recId)
{
Users entity = new Users();
entity.UserId = id;
entity.UserName = userName;
entity.Pwd = pwd;
entity.RealName = realName;
entity.Sex = sex;
entity.IDCard = iDCard;
entity.PhoneNum = phoneNum;
entity.Goal = goal;
entity.UserTypeId = userTypeId;
entity.RecId = recId;
try
{
return ua.Update(entity);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据会员ID删除会员
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public bool DeleteById(int id)
{
try
{
return ua.DeleteById(id);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据会员ID查询会员
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public Users QueryById(int id)
{
Users entity = null;
try
{
DataTable dt = ua.QueryById(id);
if (dt.Rows.Count > 0)
{
entity = new Users();
PropertyInfo[] props = typeof(Users).GetProperties();
for (int j = 0; j < props.Length; j++)
{
string columnName = props[j].Name;
object value = dt.Rows[0][columnName];
props[j].SetValue(entity, value, null);
}
}
return entity;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据用户名查询会员
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public Users QueryByUserName(string userName)
{
Users entity = null;
try
{
DataTable dt = ua.QueryByUserName(userName);
if (dt.Rows.Count > 0)
{
entity = new Users();
PropertyInfo[] props = typeof(Users).GetProperties();
for (int j = 0; j < props.Length; j++)
{
string columnName = props[j].Name;
object value = dt.Rows[0][columnName];
props[j].SetValue(entity, value, null);
}
}
return entity;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 查询所有会员
/// </summary>
/// <returns></returns>
public Users[] QueryAll()
{
Users[] entityList = null;
try
{
DataTable dt = ua.QueryAll();
entityList = FillEntityList(entityList, dt);
return entityList;
}
catch (Exception ex)
{
throw ex;
}
}
//填充实体类列表
private Users[] FillEntityList(Users[] entityList, DataTable dt)
{
if (dt.Rows.Count > 0)
{
entityList = new Users[dt.Rows.Count];
//用反射给实体类赋值
for (int i = 0; i < entityList.Length; i++)
{
Users entity = new Users();
PropertyInfo[] props = typeof(Users).GetProperties();
for (int j = 0; j < props.Length; j++)
{
string columnName = props[j].Name;
object value = dt.Rows[i][columnName];
props[j].SetValue(entity, value, null);
}
entityList[i] = entity;
}
}
return entityList;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -