Ejemplo n.º 1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                layeredLabel5.Text = "";
                if (string.IsNullOrEmpty(txtAccount.Text))
                {
                    layeredLabel5.Text      = "用户名不能为空!";
                    layeredLabel5.ForeColor = Color.Red;
                    txtAccount.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(txtPassword.Text))
                {
                    layeredLabel5.Text      = "密码不能为空!";
                    layeredLabel5.ForeColor = Color.Red;
                    txtPassword.Focus();
                    return;
                }
                TLoginDTO dto     = null;
                string    message = string.Empty;
                bool      result  = _client.TLoginCheckLogin(out message, out dto, txtAccount.Text, txtPassword.Text);
                layeredLabel5.Text = message;
                if (!result)
                {
                    layeredLabel5.ForeColor = Color.Red;
                    return;
                }
                //保存账号信息
                if (cbRemind.Checked)
                {
                    SettingHelper.WriteString(section, account, txtAccount.Text);
                    SettingHelper.WriteString(section, password, txtPassword.Text);
                }
                else
                {
                    SettingHelper.WriteString(section, account, string.Empty);
                    SettingHelper.WriteString(section, password, string.Empty);
                }
                //检查版本更新
                string version = Application.ProductVersion.ToString();
                bool   update  = _client.TLoginCheckUpdate(version);
                if (update)
                {
                    DialogResult dialogResult = MessageBox.Show("系统存在更新,是否现在升级?", "升级提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (dialogResult == DialogResult.Yes)
                    {
                        System.Diagnostics.Process.Start(Path.Combine(Application.StartupPath, "Update.exe"), "true");
                        Application.Exit();
                        return;
                    }
                }

                layeredLabel5.ForeColor = Color.Green;
                if (main == null)
                {
                    main     = new FormMain(this);
                    this.Tag = dto;
                }
                main.Show();
                this.Hide();
            }
            catch (Exception)
            {
                layeredLabel5.ForeColor = Color.Red;
                layeredLabel5.Text      = "远程服务器连接失败";
            }
        }