public Login() { InitializeComponent(); protocolqq = new ProtocolQQ(); oldIdFont = idTextBox.Font; oldPswFont = pswTextBox.Font; headPic = new MyPicture(); //新建本地用户类 #region 记到莫乱删 //网络套接字------ user = new clientUser(); user.Start(); Variable.client = user; //建立一个用户登录对象 userLogin = new UserLogin(); //建立一个本地用户类 l = new LocMess(); ls = new Dictionary <string, LocMess>(); #endregion }
//登录 public void loginBut_Click(object sender, EventArgs e) { if (idTextBox.Text.Trim() == idText || idTextBox.Text.Trim() == "") { ToolTip.Show("请输入账号在登录", idTextBox); //这边的强制转换我暂时不清楚会不会成功 //idTextBox_MouseDown(sender, (MouseEventArgs)e); if (pswTextBox.Text.Trim() == idText || pswTextBox.Text.Trim() == "") { ToolTip.Show("请输入账号再登录", idTextBox); //idTextBox_MouseDown(sender, (MouseEventArgs)e); } } else if (pswTextBox.Text.Trim() == pswText || pswTextBox.Text.Trim() == "") { ToolTip.Show("请输入密码再登录", idTextBox); // pswTextBox_MouseDown(sender, (MouseEventArgs)e); } else { //用户如果是第一次登录---需要验证 if (Variable.fl) { Y y = new Y(); y.Show(); //初始化用户名 y.login = this; y.name = idTextBox.Text.Trim(); y.psw = pswTextBox.Text.Trim(); } if (Variable.fl == false) { //this.Show(); userLogin.Name = idTextBox.Text.Trim(); userLogin.Pwd = pswTextBox.Text.Trim(); //将用户的勾选自动登录、记住密码的操作更新到数据库 if (remeber.Checked) { userLogin.Remember = 1; } else { userLogin.Remember = 0; } if (AutoLogin.Checked) { userLogin.AutoLogin = 1; } else { userLogin.AutoLogin = 0; } //对登录的操作 protocolqq.mode = 0; protocolqq.ope = 0; protocolqq.data = userLogin; //这个线程会睡1秒 user.SendMsg(protocolqq); //如果登录成功 if (Variable.IsLogin) { //将该用户的用户名-密码-头像-勾选记住密码、自动登录记录到本地文件 #region 将这个类写入文件 l = new LocMess(); l.I = Variable.user.ID; l.H = Variable.user.HeadId; //用户勾选了记住密码才想文件中存入密码 if (userLogin.Remember == 1) { l.P = userLogin.Pwd; } else { l.P = ""; } l.R = userLogin.Remember; l.A = userLogin.AutoLogin; // FileStream fs = new FileStream("LocalMess.bin", FileMode.Create); BinaryFormatter bf = new BinaryFormatter(); // 选在集合中是否存在用户名 if (ls.ContainsKey(l.I)) { ls.Remove(l.I); } ls.Add(l.I, l); //要先将l类先设为可以序列化(即在类的前面加[Serializable]) bf.Serialize(fs, ls); //user.Password = this.PassWord.Text; fs.Close(); #endregion //显示主窗口 Main form = new Main(); this.Visible = false; form.Show(); } //用户密码错误,显示可以修改密码的pannel //用户密码错误,显示可以修改密码的pannel else { headPic.Visible = false; errorPsw.Visible = true; } } } }