Exemplo n.º 1
0
        //用户登录
        void LoginbuttonClick(object sender, EventArgs e)
        {
            if (this.UserIDtextBox.Text == "")
            {
                MessageBox.Show("用户ID不能为空", "警告");
                return;
            }

            if (this.UserIDtextBox.Text == "所有人")
            {
                MessageBox.Show("不能使用 所有人 这个ID", "警告");
                return;
            }

            this.Loginbutton.Enabled = false;

            //从配置文件System.ini中读取服务器的IP和端口
            IniFile_RW.OperateIniFile iniFile = new IniFile_RW.OperateIniFile();
            string path = Environment.CurrentDirectory;          //获取当前程序路径
            string ip   = iniFile.ReadIniData("Server", "IP", "NO", path + "\\System.ini");
            string prot = iniFile.ReadIniData("Server", "PROT", "NO", path + "\\System.ini");

            if (ip == "NO" || prot == "NO")
            {
                MessageBox.Show("配置文件读取失败!请检查" + path + "\\System.ini文件", "提示");
                return;
            }

            //连接服务器
            if (!clientcontrol.Connect(ip, int.Parse(prot)))
            {
                MessageBox.Show("连接服务器失败!", "提示");
                Loginbutton.Enabled = true;

                return;
            }

            if (clientcontrol.UserLogin(UserIDtextBox.Text, UserPwdtextBox.Text))
            {
                MessageBox.Show("登录成功!", "提示");
                this.Hide();                //隐藏登录窗口
                MainForm temp = new MainForm();
                temp.ShowDialog();
                this.Close();        //关闭登录窗口
            }
            else
            {
                clientcontrol.CloseConnect();                //断开连接
                MessageBox.Show("登录失败用户已在线,请换个用户名登录!", "提示");
            }
            Loginbutton.Enabled = true;
        }
Exemplo n.º 2
0
 void Sotp()
 {
     clientcontrol.CloseConnect();
 }