private void btnLogin_Click(object sender, EventArgs e) { this.btnLogin.Enabled = false; this.txtId.Enabled = false; KoiInfo.settings.KoiID = this.txtId.Text; KoiInfo.settings.Save(); var sys = new KoiSystem(); string ver = sys.GetVersion(KoiInfo.settings.KoiID); sys.Progress += value => this.BeginInvoke(new Action(() => { if (value != 0) { this.progress.Style = ProgressBarStyle.Continuous; this.progress.Value = (int)(value * 1000); } else { this.progress.Value = 0; this.progress.Style = ProgressBarStyle.Marquee; } })); sys.Finish += success => { this.BeginInvoke(new Action(() => { this.btnLogin.Enabled = true; this.txtId.Enabled = true; if (!success) { KoiInfo.settings.Version = ""; KoiInfo.settings.Save(); MessageBox.Show("Login failed.", "Koi System", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { KoiInfo.settings.Version = ver; KoiInfo.settings.Save(); this.DialogResult = DialogResult.OK; } })); }; sys.Login(this.txtId.Text); }
private void btnDl_Click(object sender, EventArgs e) { this.txtId.Enabled = this.btnRefr.Enabled = this.btnDl.Enabled = false; var sys = new KoiSystem(); string ver = sys.GetVersion(KoiInfo.settings.KoiID); sys.Progress += value => this.BeginInvoke(new Action(() => { if (value != 0) { this.progress.Style = ProgressBarStyle.Continuous; this.progress.Value = (int)(value * 1000); } else { this.progress.Value = 0; this.progress.Style = ProgressBarStyle.Marquee; } })); sys.Finish += success => { this.BeginInvoke(new Action(() => { this.txtId.Enabled = this.btnRefr.Enabled = this.btnDl.Enabled = true; if (success) { this.verCurrent.Text = KoiInfo.settings.Version = ver; MessageBox.Show("Download finished.", "Koi System", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { this.verCurrent.Text = "<< None >>"; KoiInfo.settings.Version = ""; MessageBox.Show("Login failed.", "Koi System", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); }; sys.Login(this.txtId.Text); }
void CheckVersion() { verServer.Text = "<< Loading... >>"; btnRefr.Enabled = btnDl.Enabled = false; ThreadPool.QueueUserWorkItem(_ => { var sys = new KoiSystem(); string ver; if (string.IsNullOrEmpty(KoiInfo.settings.KoiID)) { ver = "<< Enter your Koi ID >>"; } else { ver = sys.GetVersion(KoiInfo.settings.KoiID); ver = ver ?? "<< Fail to retrieve version >>"; } BeginInvoke(new Action(() => { verServer.Text = ver; btnRefr.Enabled = btnDl.Enabled = true; })); }); }