private void button1_Click(object sender, EventArgs e) { string username = txtUser.Text; string userpwd = txtPwd.Text; if (username == "请输入用户名") { new Warning("请输入用户名", 图标.Erro).Show(); //MessageBox.Show("请输入账号!"); return; } if (userpwd == "") { new Warning("请输入密码", 图标.Erro).Show(); return; } try { List <AdminsMDL> list = AdminsBLL.GetLogin(username); if (list.Count > 0) { if (list[0].LoginType == 1) { //登录成功 admins.UserCompellation = list[0].UserCompellation; admins.name = list[0].UserName; admins.id = list[0].headID; admins.UserId = list[0].userid; AdminsMDL a = new AdminsMDL(); a.LoginType = 2; a.UserName = username; AdminsBLL.logintype(a); FrmMain f = new FrmMain(); f.Show(); this.Hide(); } else if (list[0].LoginType == 2) { new Warning("请勿重复登录", 图标.Erro).Show(); } } else { new Warning("密码错误", 图标.Erro).Show(); } } catch (Exception) { MessageBox.Show("发生未只的异常,请联系开发者", "未知异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public async void SendRequest(string account, string pass, string action) { try { UserManager.UserVerification userVerification = new UserManager.UserVerification(); pass = userVerification.GetSHA256(pass); byte[] tempBuff = Encoding.UTF8.GetBytes(action + "%" + account + "%" + pass); SmallPackage package = new SmallPackage(1024, 1024, "M", tempBuff, "0"); byte[] buffMessage = package.Packing(); await server.GetStream().WriteAsync(buffMessage, 0, buffMessage.Length); byte[] buffReceive = new byte[1024]; await server.GetStream().ReadAsync(buffReceive, 0, buffReceive.Length); SmallPackage packageReceive = new SmallPackage(); packageReceive.DividePackage(buffReceive); string[] data = (Encoding.UTF8.GetString(packageReceive.Data).Trim('\0', '\t', '\n')).Split('%'); if (data[0] == "LOGINOKE") { User user = new User(data[1], account, true, @"./images/avatarDefault/avatarDefault.png"); FrmMain mainform = new FrmMain(this, user, client, server, data[2]); mainform.Show(); this.Hide(); label2.Visible = false; } else if (data[0] == "ERRORLOGINED") { MessageBox.Show("Account was logined in other computer", "Login error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { label2.Text = "Tai khoan hoac mat khau khong chinh xac"; label2.Visible = true; } } catch (Exception ex) { MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.lnConnect.Text = "No connection"; } }