【C#重构】——充值

男娘i 2022-05-12 14:34 309阅读 0赞

教师端功能:实现对学生卡号的充值
用到的表:student_info 查询相应卡号学生信息;recharge_info充值记录表

recharge_info充值记录表

在这里插入图片描述

在这里插入图片描述
UI

  1. public partial class frmTRecharge : Form
  2. {
  3. //窗体默认
  4. public frmTRecharge()
  5. {
  6. InitializeComponent();
  7. }
  8. //点击注册
  9. private void btnRecharge_Click(object sender, EventArgs e)
  10. {
  11. if (txtCardNO.Text.Trim ()=="" || txtRecharge.Text.Trim()=="")
  12. {
  13. MessageBox.Show ("请把信息填写完整");
  14. }
  15. //实例化实体层的studnetinfo类和rechargeinfo类
  16. Entity.StudentInfo student = new Entity.StudentInfo();
  17. Entity.RechargeInfo money = new Entity.RechargeInfo();
  18. money.UserID = Convert.ToInt32(txtCardNO.Text.Trim());
  19. money.Addmoney = Convert.ToInt32(txtRecharge.Text.Trim());
  20. student.UserID = money.UserID;
  21. DataTable table;
  22. //查询student表的UserID
  23. DataTable table1;
  24. //DataTable table2;
  25. //实例化外观层
  26. Facade.RechargeFacade facade = new Facade.RechargeFacade();
  27. //外观层的查询UserID
  28. table1 = facade.SelectStudentFacade(student);
  29. //判断查找到用户输入的UserID是否在使用状态
  30. if (table1.Rows[0][7].ToString().Trim()=="正使用")
  31. {
  32. //如果卡号的状态是正在使用的haul,那就找到status和balance返回回来
  33. //cash 暂存一个变量等待和充值的前进行加和,状态写在客户端窗体上
  34. //存在问题:如果这个卡号涉及到是否结账,还需要增加什么内容?
  35. //如果这个卡号已经注销了怎么进行判断?
  36. if (table1.Rows[0][4].ToString()!="")
  37. {
  38. //查到的状态赋值到recharge表的status列
  39. student.Status=table1.Rows[0][4].ToString();
  40. //查到的学生余额暂时存放在balance中
  41. student.Balance= Convert.ToInt32(table1.Rows[0][2].ToString());
  42. int a = student.Balance;
  43. int b = money.Addmoney;
  44. //增加表信息内容
  45. money.Status = student.Status;
  46. table = facade.InsertRechargeFacade(money);
  47. int c = a + b;
  48. student.Balance = c;
  49. //table2 = facade.UpdateStudentFacade(student);
  50. //更新student表之后得到的new balance 和固定还是临时用户 显示在在窗体上
  51. txtBalance.Text = Convert.ToString(student.Balance);
  52. cmbState.Text = student.Status;
  53. MessageBox.Show("充值成功");
  54. }
  55. else
  56. {
  57. MessageBox.Show("卡号不存在");
  58. }
  59. }
  60. else
  61. {
  62. if (table1.Rows[0][7].ToString().Trim() == "已经注销")
  63. {
  64. MessageBox.Show("卡号已经注销");
  65. }
  66. }
  67. }
  68. }

D层

  1. public class RechargeDAL:IDAL.IRechargeIDL
  2. {
  3. /// <summary>
  4. /// 查询学生表的初始注册钱+学生注册状态
  5. /// </summary>
  6. /// <param name="student"></param>
  7. /// <returns></returns>
  8. public DataTable SelectStudent(Entity.StudentInfo student)
  9. {
  10. SQLHelper sqlHelper = new SQLHelper();
  11. SqlParameter[] sqlParams = { new SqlParameter("@UserID", student.UserID) };
  12. String sql = "Select * from student_info where userID =@UserID ";
  13. DataTable table = sqlHelper.ExecuteQuery(sql, sqlParams, CommandType.Text);
  14. return table;
  15. }
  16. public DataTable InsertRecharge(Entity.RechargeInfo money)
  17. {
  18. DateTime date = DateTime.Now;
  19. SQLHelper sqlHelper = new SQLHelper();
  20. SqlParameter[] sqlParams = { new SqlParameter("@CardNO",money.UserID),
  21. new SqlParameter("@Date",date.ToShortDateString()),
  22. new SqlParameter("@Status",money.Status),
  23. new SqlParameter("@Addmoney",money.Addmoney)};
  24. String sql = "Insert into recharge_info(userID,addmoney,date,status) Values(@CardNO,@Addmoney,@Date,@Status)";
  25. DataTable table = sqlHelper.ExecuteNonQuery(sql,sqlParams,CommandType.Text);
  26. return table;
  27. }

IDAL层

  1. public interface IRechargeIDL
  2. {
  3. //查询student表,目的返回balance,state,status
  4. DataTable SelectStudent(Entity.StudentInfo student);
  5. //增加信息(卡号 status addmoney)到recharge表,
  6. DataTable InsertRecharge(Entity.RechargeInfo money);
  7. //更新student表的balance
  8. //DataTable UpdateStudent(Entity.StudentInfo student);
  9. }

颗粒归仓,继续往后走,,,

发表评论

表情:
评论列表 (有 0 条评论,309人围观)

还没有评论,来说两句吧...

相关阅读

    相关 java实现会员功能

    近期负责的项目中有关于充值会员的功能,特做一个会员充值流程小结,这中间或许也存在着不足。希望可以得到大家的理解和建议。在调用第三方接口支付时修改表的状态(此处不做详细阐述)。

    相关 机房重构——

    写在前面的话:     其实重构开始有一段时间了但是由于开始不知道如何下手搞得乱七八糟,浪费了很多时间,因为看博客什么的好多人都用了存储过程,泛型什么的感觉自己需要学的有