版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xml1996/article/details/83041968
教师端给学生注册功能
数据库worklog_info 表
功能实现:
注册学号、姓名、状态、充值金额 点击注册后卡号自动生成,返回在卡号一栏
U层
/// <summary>
/// 点击注册
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSave_Click(object sender, EventArgs e)
{
//判断是否为空
if (txtSID.Text.Trim() == ""|| txtName.Text.Trim() == ""|| cmbState.Text.Trim() == ""|| txtRecharge.Text.Trim()=="")
{
MessageBox.Show("请把信息填写完整", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
try
{
//实例化实体层
Entity.StudentInfo student = new Entity.StudentInfo();
student.StudentID= Convert.ToInt32(txtSID.Text.Trim());
student.Studentname = txtName.Text.Trim();
student.Status = cmbState.Text.Trim();
student.Balance = Convert.ToInt32(txtRecharge.Text.Trim());
//外观层实例化
//查找数据库中学号是否注册过
DataTable table;
Boolean flag;
Facade.StudentFacade facade = new Facade.StudentFacade();
flag = facade.SelectStudentIDFacade(student);
//如果没有被注册
if (flag!=false)
{
//把注册信息插入数据库表
table = facade.InsterStudentFacade(student);
DataTable table1 = facade.SelectUserIDFacade(student);
//插入一行后不为空,卡号返回
if (table1.Rows.Count != 0)
{
student.UserID = Convert.ToInt32(table1.Rows[0][0].ToString().Trim());
txtCardNO.Text = Convert.ToString (student.UserID);
MessageBox.Show("卡号注册成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
MessageBox.Show("找不到卡号请联系管理员!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
MessageBox.Show("学号已经注册过!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Facade层
public class RechargeFacade
{
/// <summary>
/// 查询student表,核对学号是否被注册
/// </summary>
/// <param name="student"></param>
/// <returns></returns>
public DataTable SelectStudentFacade(Entity.StudentInfo student)
{
BLL.RechargeBLL bll = new BLL.RechargeBLL();
DataTable table = bll.SelectStudnetBLL(student);
return table;
}
/// <summary>
/// 插入注册信息入表
/// </summary>
/// <param name="money"></param>
/// <returns></returns>
public DataTable InsertRechargeFacade(Entity.RechargeInfo money)
{
BLL.RechargeBLL bll = new BLL.RechargeBLL();
DataTable table = bll.InsertRechargeBLL(money);
return table;
}
/// <summary>
/// 更新
/// </summary>
/// <param name="student"></param>
/// <returns></returns>
public DataTable UpdateStudentFacade(Entity.StudentInfo student)
{
BLL.RechargeBLL bll = new BLL.RechargeBLL();
DataTable table = bll.UpdateStudentBLL(student);
return table;
}
}
BLL层
public class RechargeBLL
{
public DataTable SelectStudnetBLL(Entity.StudentInfo student)
{
Factory.RechargeFactory factory = new Factory.RechargeFactory();
IDAL.IRechargeIDL dll = factory.CreateUser();
DataTable table = dll.SelectStudent(student);
return table;
}
public DataTable InsertRechargeBLL(Entity.RechargeInfo money)
{
Factory.RechargeFactory factory = new Factory.RechargeFactory();
IDAL.IRechargeIDL dll = factory.CreateUser();
DataTable table = dll.InsertRecharge(money);
return table;
}
public DataTable UpdateStudentBLL(Entity.StudentInfo student)
{
Factory.RechargeFactory factory = new Factory.RechargeFactory();
IDAL.IRechargeIDL dll = factory.CreateUser();
DataTable table = dll.UpdateStudent(student);
return table;
}
}
DAL层
public class RechargeDAL:IDAL.IRechargeIDL
{
/// <summary>
/// 查询学生表的初始注册钱+学生注册状态
/// </summary>
/// <param name="student"></param>
/// <returns></returns>
public DataTable SelectStudent(Entity.StudentInfo student)
{
SQLHelper sqlHelper = new SQLHelper();
SqlParameter[] sqlParams = { new SqlParameter("@UserID", student.UserID) };
String sql = "Select * from student_info where userID =@UserID ";
DataTable table = sqlHelper.ExecuteQuery(sql, sqlParams, CommandType.Text);
return table;
}
public DataTable InsertRecharge(Entity.RechargeInfo money)
{
DateTime date = DateTime.Now;
SQLHelper sqlHelper = new SQLHelper();
SqlParameter[] sqlParams = { new SqlParameter("@CardNO",money.UserID),
new SqlParameter("@Date",date.ToShortDateString()),
new SqlParameter("@Status",money.Status),
new SqlParameter("@Addmoney",money.Addmoney)};
String sql = "Insert into recharge_info(userID,addmoney,date,status) Values(@CardNO,@Addmoney,@Date,@Status)";
DataTable table = sqlHelper.ExecuteNonQuery(sql,sqlParams,CommandType.Text);
return table;
}
public DataTable UpdateStudent(Entity.StudentInfo student)
{
SQLHelper sqlHelper = new SQLHelper();
SqlParameter[] sqlParams = { new SqlParameter("@Balance",student.Balance)};
String sql = "Update student_info Set balance =@Balance ";
DataTable table = sqlHelper.ExecuteNonQuery(sql,sqlParams,CommandType.Text);
return table;
}
}