using System; using System.Collections; using System.Threading; using System.Windows.Forms; namespace NJCIT { public partial class InfomationForm : Form { public Thread updateThread; private bool tag = true; public InfomationForm() { InitializeComponent(); } private void InformationForm_Load(object sender, EventArgs e) { this.ChangeForm(); this.UpdateInfomation(); CheckForIllegalCrossThreadCalls = false; StartTimer(); } private void Button_Logout_Click(object sender, EventArgs e) { DialogResult r = MessageBox.Show("确定要退出登录吗?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (r == DialogResult.OK) { LoginServer.DoLogout(); if (LoginServer.Online) { MessageBox.Show("退出登录失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { this.ChangeForm(); } } } private void Button_exit_Click(object sender, EventArgs e) { this.StopTimer(); Environment.Exit(0); } public void UpdateInfomation() { ArrayList result = LoginServer.GetInformation(); if (result.Count == 7) { label_info.Text = "登录状态:" + result[0].ToString(); label_username.Text = "用 户 名 :" + result[1].ToString(); label_domain.Text = "认 证 域 :" + result[2].ToString(); label_ip.Text = "登 录 IP :" + result[3].ToString(); label_timer.Text = "已用时长:" + FormatTime1(result[4].ToString()); label_account.Text = "账户余额:" + result[5].ToString() + "元"; label_timeamount.Text = "已用时长:" + FormatTime2(result[6].ToString()); } } // 切换窗体 private void ChangeForm() { this.Hide(); new LoginForm(this).ShowDialog(); } private static String FormatTime2(string timeStr) { long time = 0; try { time = long.Parse(timeStr); } catch (Exception) { time = 0; } long second = time % 60; time = time / 60; long minute = time % 60; time = time / 60; long hour = time % 60; return hour + "小时" + minute + "分" + second + "秒"; } private static String FormatTime1(string timeStr) { long time = 0; try { time = long.Parse(timeStr); } catch (Exception) { time = 0; } long second = time % 60; time = time / 60; long minute = time % 60; time = time / 60; long hour = time % 60; return hour + ":" + minute + ":" + second; } public void StartTimer() { updateThread = new Thread(new ThreadStart(ThreadMethod)); updateThread.Start(); } public void StopTimer() { tag = false; } private void ThreadMethod() { while (tag) { UpdateInfomation(); Thread.Sleep(1000); } } // 处理退出操作 private void InfomationForm_FormClosing(object sender, FormClosingEventArgs e) { StopTimer(); Environment.Exit(0); } public void GetFocus() { button_exit.Focus(); } private void toolStripButton1_Click(object sender, EventArgs e) { } private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { } private void toolStripButton_about_Click(object sender, EventArgs e) { new AboutForm().ShowDialog(); } private void toolStripLabel_help_Click(object sender, EventArgs e) { try { System.Diagnostics.Process.Start("help.html"); } catch (Exception ee) { MessageBox.Show(ee.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }