Пример #1
0
 private void btn_Login_Click(object sender, EventArgs e)
 {
     if (com_ServerList.Text == "")
     {
         MessageBox.Show("对不起,请先选择连接服务器后再登录。", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         return;
     }
     if (texUserName.Text.Trim() == "")
     {
         MessageBox.Show("请输入登录用户名。", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         return;
     }
     try
     {
         //初始化全局数据库缓存MainDataSet
         DB_Service.InitMainDataSet();
         DataRow[] rows = DB_Service.MainDataSet.Tables["UserTable"].Select("UserName = '******'");
         if (rows.Length == 1)
         {
             if (rows[0]["Password"].ToString().CompareTo(texPassword.Text) == 0 || Global.AutoLogin)
             {
                 if (Convert.ToBoolean(rows[0]["IsAlive"]))
                 {
                     if (Socket_Service.ConnectServer(Global.ServerIP, Global.ServerPort))
                     {
                         if (Socket_Service.SendMessage_Safe(Socket_Service.Command_C2S_Reg, texUserName.Text.Trim(), "", "", "", "", "", "", "", ""))
                         {
                             this.Tag           = true;
                             Global.PresentUser = texUserName.Text.Trim();
                             this.Close();
                         }
                         else
                         {
                             try
                             {
                                 Socket_Service.DisconnectServer();
                             }
                             catch
                             { }
                             MessageBox.Show("对不起,您的帐户已经在别处登陆或者连接数目超限,请联系管理员。", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                         }
                     }
                     else
                     {
                         MessageBox.Show("与服务器的连接失败,请确保服务器已经启动后重新运行。", "服务器通信失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     }
                 }
                 else
                 {
                     MessageBox.Show("对不起,您的帐户已停用,请联系管理员。", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
                 return;
             }
             else
             {
                 MessageBox.Show("请输入正确的用户名和密码。", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 texPassword.Text = "";
             }
         }
         else
         {
             MessageBox.Show("请输入正确的用户名和密码。", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             texPassword.Text = "";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, Application.ProductName + (Global.IsTempVersion ? "(演示版)" : ""));
     }
 }