功能说明:当客户上机卡里的钱消费完之后自动下机。
逻辑说明:首先在上机表中我们把当前客户的余额和我们的收费标准做了一下运算,把客户的余额根据收费标准折合成了可上机时长,当我们的上机时间等于可上机时长的时候就说明客户卡里的钱已经消费完了,这个时候就会自动下机。
代码展示:
U层:
private void DynamicOff_Tick(object sender, EventArgs e) { List<dynamic> list = new List<dynamic>(); OnlineEntity online = new OnlineEntity(); InvariableEntity invariable = new InvariableEntity(); ISelect iselect = AbstractFactory.Factory.CreateConcreteClass("ConcreteBLL","BLL","T_Online"); list = iselect.Select(invariable.UserID); ILogout logout = AbstractFactory.Factory.CreateConcreteClass("ConcreteBLL","BLL","T_Line"); if (list[0].OnBoardTime == list[0].CardRemainTime) { logout.Logout(); Application.Exit(); } }
B层:
//查询上机表,获取可上机时长 public List<dynamic> Select(string cardID) { List<dynamic> list = new List<dynamic>(); ISelect iselect = AbstractFactory.Factory.CreateConcreteClass("ConcreteDAL", "DAL", "T_Online"); list = iselect.Select(cardID); return list; }
//当用户卡内余额不足时调用下机接口进行下机。 public void Logout(params string[] values) { CustomerEntity enCustomer = new CustomerEntity(); List<dynamic> customerList = new List<dynamic>(); ISelect iSelectCustomer = AbstractFactory.Factory.CreateConcreteClass("ConcreteDAL", "DAL", "T_Customer"); customerList = iSelectCustomer.Select(invariable.UserID); enCustomer.CardID = customerList[0].CardID; enCustomer.UserName = customerList[0].UserName; enCustomer.CardType = customerList[0].CardType; enCustomer.CardCash = customerList[0].CardCash; CustomerOffChain.Handler checkbasic = new CheckBasicHandler(); CustomerOffChain.Handler checktype = new CheckTypeHandler(); CustomerOffChain.Handler checkonline = new CheckOnlineHandler(); CustomerOffChain.Handler insertline = new InsertLineHandler(); CustomerOffChain.Handler updateuser = new UpdateUserHandler(); checkbasic.SetSuccessor(checktype); checktype.SetSuccessor(checkonline); checkonline.SetSuccessor(insertline); insertline.SetSuccessor(updateuser); checkbasic.HandlerRequest(enCustomer); }
D层:
public List<dynamic> Select(string cardID) { string sql = "select * from T_Online"; DataTable dataTable = SQLHelper.GetDataTable(sql); List<dynamic> list = new List<dynamic>(); foreach (DataRow row in dataTable.Rows) { list.Add(new OnlineEntity() { CardID = Convert.ToInt32(row["cardID"]), LandTime = Convert.ToDateTime(row["LandTime"]), OnBoardTime = Convert.ToInt32(row["onBoardTime"]), Computer = row["computer"].ToString(), CardRemainTime = Convert.ToInt32(row["cardRemainTime"]) }) ; } return list; }
public int Insert(dynamic enOnline , params decimal[] values) { string sql = "insert into T_Line(cardID,onTime,offTime,onBoardTime,consumeCash,isCheck) values (@cardID,@onTime,@offTime,@onBoardTime,@consumeCash,@isCheck)"; SqlParameter[] sqlParameter = { new SqlParameter("@cardID", enOnline.CardID), new SqlParameter("@onTime",enOnline.LandTime), new SqlParameter("@offTime",DateTime.Now), new SqlParameter("@onBoardTime",enOnline.OnBoardTime), new SqlParameter("@consumeCash",values[0]), new SqlParameter("@isCheck","未结账") }; return SQLHelper.ExecuteNonQuery(sql, sqlParameter); }