/// <summary> /// 查询学生上机记录 /// </summary> /// <param name="studentline">学生卡号</param> /// <returns>此学生全部的上机记录信息</returns> public DataTable SelectLineStudent(StudentLien studentline) { //定义参数 SqlParameter[] sqlparms = { new SqlParameter("@StudentCardno", studentline.StudentCardno) }; //定义SQL语句 string sql = @"select * from LineStudent where StudentCardno=@StudentCardno"; //接受返回值 DataTable LineTable = sqlHelper.ExecuteQuery(sql, sqlparms, CommandType.Text); return(LineTable);//返回查询结果 }
/// <summary> /// 查询上机记录 /// </summary> /// <param name="studentCardno">卡号</param> /// <param name="form">上机记录窗体</param> /// <returns>上机记录信息</returns> public DataTable SelectLineStudent(string studentCardno, Form form, ref string StrMsg) { //用于返回信息 StrMsg = ""; //接受判空返回值,判断文本框是否为空。 string isNull = IsNull.isNull(form); //接受是不是数字的判断返回值 bool isNumber = IsNull.IsNumber(studentCardno); //获取上机记录 DataTable LineStudentTable = new DataTable(); //判断文本是否为空 if (isNull == "")//没有返回值说明文本框不为空! { //判断输入的卡号是否是数字 if (isNumber == true)//返回true说明是数字 { #region 获取上机记录 //转换成对应的实体 StudentLien studentline = new StudentLien(); studentline.StudentCardno = int.Parse(studentCardno); //调用数据层接口和创建DAL层的工厂创建DAL层类 LineStudentIDAL LineStudentIDAL = (LineStudentIDAL)fact.CreateUser("LineStudentDAL"); //获取上机记录 LineStudentTable = LineStudentIDAL.SelectLineStudent(studentline); #endregion #region 判断卡号是否存在,或者有没有上机记录 if (LineStudentTable.Rows.Count == 0)//用户不存在或者没有上机记录 { StrMsg = "用户不存在或者没有上机记录"; } else { StrMsg = "查询完毕!"; } #endregion } else { StrMsg = "卡号请输入数字!"; } } else { StrMsg = isNull; //把返回结果赋值给strMsger返回给U层 } return(LineStudentTable); //返回处理结果 }
/// <summary> /// 向上机记录表插入信息 /// </summary> /// <param name="stuLine">上机记录实体</param> /// <returns>受影响行数</returns> public int InsertLineStudent(StudentLien stuLine) { //定义参数 SqlParameter[] sqlParms = { new SqlParameter("@StudentCardno", stuLine.StudentCardno), new SqlParameter("@StudentName", stuLine.StudentNam), new SqlParameter("@StudentLevel", stuLine.StudentLevel), new SqlParameter("@OnDate", stuLine.OnDate), new SqlParameter("@OnTime", stuLine.OnTime), new SqlParameter("@UpDate", stuLine.UpDate), new SqlParameter("@UpTime", stuLine.UpTime), new SqlParameter("@OnLineMin", stuLine.OnLineMin), new SqlParameter("@ConsumptionCash", stuLine.ConsumptionCash), new SqlParameter("@NowCash", stuLine.NowCash), new SqlParameter("@Computer", stuLine.Computer) }; //定义SQL语句 string sql = @"insert into LineStudent values(@StudentCardno,@StudentName,@StudentLevel,@OnDate,@OnTime,@UpDate,@UpTime,@OnLineMin,@ConsumptionCash,@NowCash,@Computer)"; //接受查询结果 int Relust = sqlHelper.ExecuteNonQuery(sql, sqlParms, CommandType.Text); return(Relust);//返回结果 }
/// <summary> /// 学生下机 /// </summary> /// <param name="StuentCardno">学生卡号</param> /// <param name="TimeSolt">上机时长</param> /// <returns></returns> public void LoginOutStudent(string StuentCardno, string stuName) { #region 实例化退出工厂 //使用工厂实例化接口 LoginOutStudentIDAL idal = (LoginOutStudentIDAL)fact.CreateUser("LoginOutStudentDAL"); DataTable BasitInfoTable = idal.SelectBasit(); //获取基础信息 //获取正在上机的卡号信息 StudentOnLine studentOnline = new StudentOnLine(); //实例化正在上机实体 studentOnline.StudentCardno = int.Parse(StuentCardno); //给卡号赋值 DataTable OnlineTable = idal.SelectOnLineStudent(studentOnline); //获取正在上机的卡号信息 #endregion #region 计算上机时长 double LimTime = double.Parse(BasitInfoTable.Rows[0][2].ToString()); //给最小上机时间赋值 //获取上机日期+时间 string LoginData = DateTime.Parse(OnlineTable.Rows[0][3].ToString()).ToString("yyyy/MM/dd"); //获取上机日期 string LoginTime = DateTime.Parse(OnlineTable.Rows[0][4].ToString()).ToShortTimeString(); //获取上机时间 string LoginDateTime = LoginData + " " + LoginTime; //合并上机日期+时间 //获取下机日期+时间 string LoginOutData = DateTime.Parse(DateTime.Now.Date.ToString()).ToString("yyyy/MM/dd"); //获取上机日期 string LoginOutTime = DateTime.Now.ToShortTimeString(); //获取上机时间 string LoginOutDateTime = LoginOutData + " " + LoginOutTime; //合并上机日期+时间 //公式:下机日期和时间-上机日期和时间=上机时长 TimeSpan TimeSolt = DateTime.Parse(LoginOutDateTime) - DateTime.Parse(LoginDateTime); #endregion #region 计算消费金额 string stuentType = OnlineTable.Rows[0][1].ToString(); //给卡号类型赋值 double Cash = 0; //收费标准 //给收费标准赋值 if (stuentType == "固定用户") { Cash = double.Parse(BasitInfoTable.Rows[0][3].ToString());//给固定用户收费标准赋值 } else if (stuentType == "临时用户") { Cash = double.Parse(BasitInfoTable.Rows[0][4].ToString());//给临时用户收费标准赋值 }//end if //实例化策略模式,传入卡号类型和对应的收费标准。 Cash.StuCashContext stuCashContext = new Cash.StuCashContext(stuentType, Cash); //传入:消费时长和最小上机时间,得到消费金额 double Money = stuCashContext.GetResult(TimeSolt.ToString(), LimTime); #endregion //计算目前余额:公式:上机前余额-消费金额=当前余额 double NowCsh = double.Parse(OnlineTable.Rows[0][2].ToString()) - Money; #region 更新学生上机记录 //给上机记录实体赋值,和实例化 #region 给上机记录实体赋值 StudentLien StuLine = new StudentLien(); StuLine.Computer = Computer.GetMachineName(); //计算机名称 StuLine.ConsumptionCash = Money; //消费金额 StuLine.NowCash = NowCsh; //目前余额 StuLine.OnDate = DateTime.Parse(OnlineTable.Rows[0][3].ToString()); //上机日期 StuLine.OnLineMin = TimeSolt.ToString(); //在线时长 StuLine.OnTime = OnlineTable.Rows[0][4].ToString(); //上机时间 StuLine.StudentCardno = int.Parse(OnlineTable.Rows[0][0].ToString()); //卡号 StuLine.StudentLevel = OnlineTable.Rows[0][1].ToString(); //用户类型 StuLine.StudentNam = stuName; //用户姓名 问题:正在上机表设计不合理,无法得到用户姓名。 StuLine.UpDate = DateTime.Now.Date; //下机日期 StuLine.UpTime = DateTime.Now.ToShortTimeString(); //下机时间 #endregion //向上机记录插入信息 idal.InsertLineStudent(StuLine); #endregion //更新卡号状态和目前余额 RegistrationCardno stuCardno = new RegistrationCardno(); stuCardno.StudentCardno = StuLine.StudentCardno;//给卡号赋值 stuCardno.Studentbalance = NowCsh; stuCardno.State = "未激活"; idal.UpdateRegiCardno(stuCardno); //删除在线学生信息 idal.DeleteOnLineStudent(studentOnline); //实例化登录窗体 Form CreatLoginForm = CreatfactForm.CreatFrom("LoginUser"); //实例化学生窗体 CreatLoginForm.Show(); //显示登录窗体 }