Beispiel #1
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userlevel">用户</param>
        /// <returns>是否登录成功!</returns>
        public override string UserLogin(UserLevel userlevel, Form form)
        {
            //返回信息
            string StrMesg = "";
            //调用接口实例化D层查询类
            LoginIDAL idal = (LoginIDAL)fact.CreateUser("LoginDal");
            //实例化管理者实体和赋值
            Managerial Manageria = new Managerial();

            Manageria.ManId = userlevel.UserID;//登录id赋值给管理者ID
            //接受管理者信息
            DataTable ManTable = idal.SelectState(Manageria);

            //判断账号是否使用
            if (ManTable.Rows[0][3].ToString().Trim() == "使用")
            {
                #region 判断管理者是否已经登录
                //实例化值班实体与赋值
                UserOnWork userOnWork = new UserOnWork();
                userOnWork.ManId = userlevel.UserID;//值班实体的管理者id赋值
                //接受接口的返回值,返回整个值班表的信息。
                DataTable OnWorkTable = idal.SelectOnUser(userOnWork);
                //判断管理者是否已经登录
                if (OnWorkTable.Rows.Count == 0) //没有登录
                {
                    form.Hide();                 //隐藏窗体
                    #region 向值班表插入信息
                    //给值班实体赋值
                    userOnWork.Level    = userlevel.Userlevel;                              //管理者级别
                    userOnWork.Name     = ManTable.Rows[0][1].ToString().Trim();            //管理者姓名
                    userOnWork.Ondate   = DateTime.Now.Date;                                //登录日期
                    userOnWork.OnTime   = DateTime.Parse(DateTime.Now.ToShortTimeString()); //登录时间
                    userOnWork.Computer = Computer.GetMachineName();                        //计算机名
                    //调用插入方法
                    InserUserOnWork(userOnWork);
                    #endregion
                    //给全局ID赋值
                    UserLevel.UserIdall = userlevel.UserID;
                    StrMesg             = "登录成功!";
                    //显示管理员窗体
                    Form CreatForm = CreatfactForm.CreatFrom("AdminMain"); //实例化管理员窗体
                    CreatForm.Show();                                      //显示窗体
                }
                else
                {
                    StrMesg = "此账号已登录!";
                }
                #endregion
            }
            else
            {
                StrMesg = "此账号未使用,请激活使用!";
            }//end if

            return(StrMesg);
        }
Beispiel #2
0
        /// <summary>
        /// 学生上机状态查询
        /// </summary>
        /// <param name="Cardno">卡号</param>
        /// <param name="form">学生窗体</param>
        /// <returns></returns>
        public void StudnetOnLineState(string Cardno, Form form)
        {
            //转成实体
            StudentOnLine stuOnline = new StudentOnLine();

            stuOnline.StudentCardno = int.Parse(Cardno);
            //利用接口和工厂实例化具体的查询正在上机状态的数据类
            StudentOnLineStateIDAL studentlineStateIDAL = (StudentOnLineStateIDAL)fact.CreateUser("StudentOnLineStateDAL");
            DataTable SelectOnlineStudnetTable          = studentlineStateIDAL.StudnetOnLineState(stuOnline);//获取上机表此学生上机信息

            //判断学生上机状态
            if (SelectOnlineStudnetTable.Rows.Count == 0)//说明已经被强制下机
            {
                //关闭学生窗体
                form.Close();
                //显示登录窗体
                Form forlogin = factUi.CreatFrom("LoginUser");
                forlogin.Show();
            }
        }
        /// <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();                                      //显示登录窗体
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userlevel">用户</param>
        /// <returns>是否上机成功!</returns>
        public override string UserLogin(UserLevel userlevel,Form form)
        {
            #region 实例化与赋值
            string StrMsg="";//要返回的信息
            LoginIDAL idal = (LoginIDAL)fact.CreateUser("LoginDal"); //调用接口实例化,D层查询类
            RegistrationCardno RegisCardno = new RegistrationCardno(); //实例化实体
            RegisCardno.StudentCardno = userlevel.UserID;//给卡号赋值                                          
            #endregion
            DataTable StuCardnoTable = idal.SelectStuCardno(RegisCardno);//接受卡号信息
            RegisCardno.Studentbalance = double.Parse(StuCardnoTable.Rows[0][1].ToString());//给余额赋值
            DataTable BasitInfoTable = idal.SelectBasitInfo();//接受基础信息
            #region 判断卡号状态
            //判断卡号状态
            if (StuCardnoTable.Rows[0][4].ToString()=="已激活")
            {
                //判断余额是否充足
                if (RegisCardno.Studentbalance >=double.Parse(BasitInfoTable.Rows[0][0].ToString()))
                {
                    //实例化上机表实体与赋值
                    StudentOnLine stuOnLine = new StudentOnLine();
                    stuOnLine.StudentCardno = userlevel.UserID;//给卡号赋值
                    //获取上机表信息
                    DataTable OnWorkTable = idal.SelectOnStudent(stuOnLine);
                    //查询卡号是否已经登录
                    if (OnWorkTable.Rows.Count==0)//没有登录
                    {
                        form.Hide();//隐藏窗体
                      
                        #region 给上机实体赋值
                        stuOnLine.StudentLevel = StuCardnoTable.Rows[0][3].ToString();//卡号类型赋值
                        stuOnLine.OnDate = DateTime.Now.Date;//上机日期
                        stuOnLine.OnTime = DateTime.Now.ToShortTimeString();//上机时间
                        stuOnLine.NowCash =RegisCardno.Studentbalance;//当前余额
                        stuOnLine.Computer = Computer.GetMachineName();//电脑名称
                        #endregion
                        InserStudentOnlien(stuOnLine);//向上机表插入信息
                        UserLevel.UserIdall = userlevel.UserID; //给全局ID赋值
                        StrMsg = "上机成功!";
                        Form CreatForm = CreatfactForm.CreatFrom("StudentMain");//实例化学生窗体
                        CreatForm.Show();//显示窗体
                        
                    }
                    else
                    {
                        StrMsg = "此卡号已登录!";
                    }//end if
                   
                }
                else
                {
                    StrMsg = "余额不足,请充值";
                }//end if


            }
            else
            {
                StrMsg = "此卡号未激活,请激活使用!";
            }//end if
            #endregion
            return StrMsg;//返回登录信息    
        }