注册个人觉得只有操作员具有此功能,所以放在了操作员的权限当中。
UI层
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
namespace UI
{
public partial class FrmLogon : Form
{
public FrmLogon()
{
InitializeComponent();
}
private void btLogon_Click(object sender, EventArgs e)
{
if (txtCardno.Text=="" || txtCharge.Text=="" || txtIdentity.Text=="" ||txtName.Text=="" || txtPwd.Text=="" || comboBox1.Text=="")
{
MessageBox.Show("请您将注册信息填写完整", "温馨提示");
}
else
{
//student表
Facade.StudentFacade facade = new Facade.StudentFacade();//实例化外观层
Entity.Student_Info stu = new Entity.Student_Info();//实例化学生实体
stu.cardno = txtCardno.Text.Trim();//将文本中的卡号给实体层,实体层传到DAL层进行查询。
DataTable flag = facade.SelectStudent(stu);
if (flag.Rows.Count != 0)//rows不等于0,说明存在cardno为控件内容的那么一行,所以已经存在。
{
MessageBox.Show("用户已经存在", "温馨提示");
return;
}
else//将控件中的信息给实体层,后面再有的代码将实体层的信息给数据库。
{
stu.cardno = txtCardno.Text.Trim();
stu.StudentName = txtName.Text.Trim();
stu.sex = comboBox1.Text.Trim();
stu.Ischeck = "未结账";
stu.studentNo = txtIdentity.Text.Trim();
stu.PWD = txtPwd.Text.Trim();
stu.cash =Convert.ToDouble( txtCharge.Text.Trim());
stu.UserID = txtLogoner.Text.Trim();
}
DataTable flag1 = facade.AddStudent(stu);
MessageBox.Show("用户注册成功");
}
}
}
}
Facade层
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
namespace Facade
{
public class StudentFacade
{
//添加
public DataTable AddStudent(Entity.Student_Info StudentInfo)
{
BLL.StudentBLL studentbll = new BLL.StudentBLL();//实例化一个BLL层
DataTable result= studentbll.AddStudent(StudentInfo);
return result;
}
}
}
BLL层
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
namespace BLL
{
public class StudentBLL
{
//添加
public DataTable AddStudent(Entity.Student_Info Student)
{
Factory.StudentFactory fact = new Factory.StudentFactory();
IDAL.IStudentDAL idal = fact.Student();
DataTable table = idal.AddStudent(Student);
return table;
}
}
}
Factory层
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Reflection;
namespace Factory
{
public class StudentFactory
{
string StrDB = ConfigurationManager.AppSettings["DB"];//需要引用命名空间Configuration;
//打开StudentDAL层
public IDAL.IStudentDAL Student()
{
string ClassName = StrDB + "." + "StudentDAL";//DAL.StudentDAL;
return (IDAL.IStudentDAL)Assembly.Load(StrDB).CreateInstance(ClassName);
}
}
}
IDAL层
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
namespace IDAL
{
public interface IStudentDAL
{
DataTable AddStudent(Entity.Student_Info Student);//添加数据
}
}
DAL层
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Entity;
using System.Configuration;
namespace DAL
{
public class StudentDAL:IDAL.IStudentDAL
{
public DataTable AddStudent(Entity.Student_Info Student)
{
SQLHelper sqlHelper = new SQLHelper();//实例化一个数据查询的对象。
SqlParameter[] sqlParamsstu = { new SqlParameter("@cardno",Student.cardno ),
new SqlParameter("@PWD", Student.PWD ),//SqlParameter是范围的意思,个人理解这行代码是规定新的东西。就是将PWD换成@password。
new SqlParameter("@StudentName",Student.StudentName),
new SqlParameter("@sex",Student.sex),
new SqlParameter("@UserID",Student.UserID),
new SqlParameter("@Ischeck",Student.Ischeck),
new SqlParameter("@cash",Student.cash),
new SqlParameter("@studentNo",Student.studentNo)};
string sqlstu = @"INSERT INTO Student_Info (cardno,PWD,StudentName,sex,UserID,Ischeck,cash,studentNo)
values(@cardno,@PWD,@StudentName,@sex,@UserID,@Ischeck,@cash,@studentNo)";//向数据库中插入新的数据。
DataTable result = sqlHelper.ExecuteQuery1(sqlstu, sqlParamsstu, CommandType.Text);//SQLHelper查询,里面的参数依次是数据库插入、设置新参数、默认的枚举类型。
return result;
}
}
}