public static UserService getInstance() { if (Bll==null) { Bll = new ImplUser(); } if (instance == null) { instance = new UserService(); } if (userDao == null) { userDao = new UserDao(); } if (userClassDao == null) { userClassDao = new UserClassDao(); } return instance; }
private void theout(object sender, ElapsedEventArgs e) { Console.Write("..超时调用方法.."); if (RunDoWhile) { //超时之后假如是老师或者管理员(非学生登录)则将Ip设定为该机器IP LoginRoler.serverIp = GetAddressIP(); isLocalIp = true; if (1 == 2) { //从本地库获取角色 获取不到说明不是 正式库 ImplUser Bll = new ImplUser(); string username = loginId.Text; string password = this.textBox2.Text; int a = Bll.ExistsName(username); if (a != 0) { //DataSet ds = Bll.ExistsPwd(username, password, ((ComboxItem)this.comboBox3.Items[comboBox3selectIndex]).Value); DataSet ds = Bll.ExistsPwd(username, password, ""); if (ds.Tables[0].Rows.Count > 0) { LoginRoler.roleid = Convert.ToString(ds.Tables[0].Rows[0][2].ToString()); } } string user_type = LoginRoler.roleid; if (user_type == Constant.RoleManager)//管理员 { LoginRoler.serverType = Constant.RoleManager; } else if (user_type == Constant.RoleTeacher)//老师 { LoginRoler.serverType = Constant.RoleTeacher; } else//学生 if (user_type == Constant.RoleStudent) { LoginRoler.serverType = Constant.RoleStudent; } else { LoginRoler.serverType = "unknown"; } } RunDoWhile = false; if (searchServerIpRecv != null) { searchServerIpRecv.Abort(); } } }
private bool login() { this.label6.Text = "开始登录操作"; Application.DoEvents(); bool flag = false; string username = loginId.Text; string password = this.textBox2.Text; if (username == "") { MessageBox.Show("用户名不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else if (password == "") { MessageBox.Show("密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { this.label6.Text = "开始登录操作【检查用户是否存在】"; Application.DoEvents(); ImplUser Bll = new ImplUser(); int a = Bll.ExistsName(username); if (a != 0) { //DataSet ds = Bll.ExistsPwd(username, password, ((ComboxItem)this.comboBox3.Items[comboBox3selectIndex]).Value); this.label6.Text = "开始登录操作【用户信息验证】"; Application.DoEvents(); DataSet ds = Bll.ExistsPwd(username, password, ""); if (ds.Tables[0].Rows.Count > 0) { LoginRoler.login_id = Convert.ToString(ds.Tables[0].Rows[0][0].ToString()); LoginRoler.username = Convert.ToString(ds.Tables[0].Rows[0][1].ToString()); LoginRoler.roleid = Convert.ToString(ds.Tables[0].Rows[0][2].ToString()); LoginRoler.language = comboBox1.SelectedIndex; LoginRoler.ip = GetAddressIP(); LoginRoler.userId = Convert.ToInt32(ds.Tables[0].Rows[0][3].ToString()); LoginRoler.pwd = password; this.label6.Text = "开始登录操作【加载协议指令】"; Application.DoEvents(); loadAgreeMent(); Console.WriteLine("模拟人协议加载数量" + LoginRoler.AgreeMents.Count); if (!LoginRoler.isLocalIp) { LoginRoler.serverType = LoginRoler.roleid; } if (LoginRoler.roleid == Constant.RoleStudent && LoginRoler.isLocalIp) { MessageBox.Show("目前该用户登录在本地数据库", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } //判断下是否局域网中已经有老师存在 //string user_type = ((ComboxItem)this.comboBox3.Items[comboBox3selectIndex]).Value; string user_type = LoginRoler.serverType; if (user_type == Constant.RoleTeacher && Constant.RoleTeacher == LoginRoler.serverType && !isLocalIp) { MessageBox.Show("局域网中已经有教师登录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); button1.Enabled = true; return flag; } if (user_type == Constant.RoleManager && Constant.RoleManager == LoginRoler.serverType && !isLocalIp) { MessageBox.Show("局域网中已经有管理员登录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); button1.Enabled = true; return flag; } checkCode = ""; flag = true; } else { MessageBox.Show("密码输入错误,请重新输入密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.loginId.Text = ""; this.textBox2.Text = ""; } } else { MessageBox.Show("用户名不存在,请确认教师是否已经登录系统", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.loginId.Text = ""; this.textBox2.Text = ""; } } this.label6.Text = "登录结束进入主界面"; Application.DoEvents(); return flag; }