?? entrypointcontrol.cs
字號:
?namespace Imps.Client.Pc
{
using Imps.Client;
using Imps.Client.Core;
using Imps.Client.Pc.BizControls;
using Imps.Client.Pc.BizControls.NotifyWindows;
using Imps.Client.Pc.Controls;
using Imps.Client.Pc.Password;
using Imps.Client.Pc.Utils;
using Imps.Client.Pc.WndlessControls;
using Imps.Client.Resource;
using Imps.Client.Utils;
using Imps.Common;
using Imps.Utils;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Net.NetworkInformation;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Forms;
internal class EntryPointControl : UserControl
{
private bool _causedByUser = true;
private Image _curPortrait;
private Image _defaultPortrait;
private MainPresence _initPresence = MainPresence.Online;
private UserAccountManager _manager;
private bool _suspendIdChanged;
private WndlessControlCollection _wndlessCtls;
private AutoReconnect autoReconnect;
private volatile bool AutoReconnectEventAttached;
private XButton btnLogin;
private CheckBox cbAutoLogin;
private CheckBox cbSaveAccount;
private CheckBox cbSavePassword;
private XComboBox cmbId;
private IContainer components;
private int HeightShowButton = 200;
private int HeightShowPortrait = 380;
private int HeightShowSaveInfo = 300;
private BDisplayNameAndOnlineStatus InitStatus;
private menu_widget InitStatusMenu;
private WndlessLabel lbInitStatus;
private WndlessLabel lblId;
private WndlessLabel lblPassword;
private WndlessLabel lblStep;
private WndlessLinkLabel llEraseInfo;
private WndlessLinkLabel llForgetPass;
private WndlessLinkLabel llNetSetting;
private WndlessLinkLabel llProvisioning;
private WndlessLinkLabel llReconnectAtOnce;
private const int MarginX = 0x18;
private const int MarginY = 20;
private const int PaddingX = 5;
private const int PaddingY = 3;
private WndlessPictureBox pbPortrait;
private RadioButton rbPrivate;
private RadioButton rbPublic;
private const int SpacingLogin = 30;
private XTextBox tbPassword;
private const int WidthMaxId = 150;
private const int WidthMinId = 80;
private int WidthShowProvisioning;
public EntryPointControl(UserAccountManager manager)
{
this._manager = manager;
this._manager.CurrentUser.StatusChanged += new EventHandler<UserSatusChangedEventArgs>(this.CurrentUser_StatusChanged);
this._manager.CurrentUser.LoginStepChanged += new EventHandler(this.CurrentUser_LoginStepChanged);
this._manager.CurrentUser.AutoLoginFailed += new EventHandler<ImpsErrorEventArgs>(this.CurrentUser_AutoLoginFailed);
this._manager.FrameworkWnd.MainWindowLoaded += new EventHandler(this.FrameworkWnd_Loaded);
this._manager.FrameworkWnd.MainWindow.Activated += new EventHandler(this.MainWindow_Activated);
this._manager.FrameworkWnd.SuspendRestored += new EventHandler(this.FrameworkWnd_SuspendRestored);
this._manager.FrameworkWnd.BeginSuspend += new EventHandler(this.FrameworkWnd_BeginSuspend);
base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
this.InitializeComponent();
this.InitializeWndlessComponent();
this.CalcSizeParameters();
base.SizeChanged += new EventHandler(this.EntryPointControl_SizeChanged);
base.VisibleChanged += new EventHandler(this.EntryPointControl_VisibleChanged);
ControlHelper.SetAcceptDigitOnly(this.cmbId, true);
ControlHelper.SetAcceptPasswordChar(this.tbPassword, true);
this.DoLocalize();
this.ResetCheckBox();
this.InitStatusMenuItems();
this.autoReconnect = new AutoReconnect(0x7fffffff);
this.AttachReconnEventHandlers(true);
}
private void AR_OnTick(object sender, TickEventArgs e)
{
try
{
this._manager.CurrentUser.Status = UserAccountStatus.WaitReconnect;
if (NetworkInterface.GetIsNetworkAvailable())
{
this.llReconnectAtOnce.Visible = true;
if (e != null)
{
this.UpdateStepLabelText(string.Format(StringTable.User.StepNextReconnect, e.CurrentTick));
}
}
else
{
this.llReconnectAtOnce.Visible = false;
this.UpdateStepLabelText(StringTable.User.WaitForNetworkRecover);
this.autoReconnect.StopTimer();
}
}
catch (Exception exception)
{
ClientLogger.WriteException(exception);
}
}
private void AR_TimeUp(object sender, EventArgs e)
{
try
{
if (this._manager.CurrentUser.Status == UserAccountStatus.WaitReconnect)
{
if (NetworkInterface.GetIsNetworkAvailable())
{
this.UpdateStepLabelText(StringTable.User.StepSigning);
this.autoReconnect.StopTimer();
this._manager.CurrentUser.AsyncLogin(this._initPresence, true);
}
else
{
this.llReconnectAtOnce.Visible = false;
this.UpdateStepLabelText(StringTable.User.WaitForNetworkRecover);
this.autoReconnect.StopTimer();
}
}
}
catch (Exception exception)
{
ClientLogger.WriteException(exception);
}
}
private void AttachReconnEventHandlers(bool attach)
{
if (attach)
{
if (!this.AutoReconnectEventAttached)
{
this.autoReconnect.OnTick += new EventHandler<TickEventArgs>(this.AR_OnTick);
this.autoReconnect.TimeUp += new EventHandler(this.AR_TimeUp);
}
}
else
{
this.AutoReconnectEventAttached = false;
this.autoReconnect.OnTick -= new EventHandler<TickEventArgs>(this.AR_OnTick);
this.autoReconnect.TimeUp -= new EventHandler(this.AR_TimeUp);
}
}
private void btnLogin_Click(object sender, EventArgs e)
{
try
{
if (base.Visible)
{
this.DoLoginOrCancel();
}
}
catch (Exception exception)
{
ClientLogger.WriteGeneral(exception.ToString());
}
}
private void CalcSizeParameters()
{
this.HeightShowButton = ((((((((this.lblId.Height * 2) + this.cmbId.Height) + this.lblPassword.Height) + this.tbPassword.Height) + this.btnLogin.Height) + this.llNetSetting.Height) + 20) + 30) + 0x15;
this.HeightShowSaveInfo = ((this.HeightShowButton + (this.cbSaveAccount.Height * 5)) + 20) + 12;
this.HeightShowPortrait = (this.HeightShowSaveInfo + this.pbPortrait.Height) + 20;
this.WidthShowProvisioning = (((80 + this.WidthMaxProvisioning) + 0x18) + 0x18) + 5;
}
internal void CancelLogin()
{
try
{
this.UpdateStepLabelText("取消中...");
}
catch
{
}
try
{
this.autoReconnect.StopTimer(true);
this._manager.CurrentUser.AsyncCancelLogin();
this._suspendIdChanged = false;
this.cmbId.SelectAll();
this.cmbId.Focus();
}
catch (Exception exception)
{
this._manager.FrameworkWnd.UnifiedMessageBox.ShowException(exception);
}
}
private void cbAutoLogin_CheckedChanged(object sender, EventArgs e)
{
try
{
if (this.cbAutoLogin.Checked)
{
this.cbSaveAccount.Checked = true;
this.cbSavePassword.Checked = true;
}
else if (this._causedByUser)
{
UserAccounts.SetAccountAutoLogin(this.cmbId.Text, false);
UserAccounts.SaveToLocal();
}
}
catch (Exception exception)
{
UiErrorHelper.HandExceptionSafely(this._manager.FrameworkWnd, exception);
}
}
private void cbSaveAccount_CheckedChanged(object sender, EventArgs e)
{
try
{
if (!this.cbSaveAccount.Checked)
{
this._causedByUser = false;
this.cbAutoLogin.Checked = false;
this.cbSavePassword.Checked = false;
this._causedByUser = true;
}
}
catch
{
}
}
private void cbSavePassword_CheckedChanged(object sender, EventArgs e)
{
try
{
if (this.cbSavePassword.Checked)
{
this.cbSaveAccount.Checked = true;
}
else
{
this.cbAutoLogin.Checked = false;
this.lblPassword.Enabled = true;
this.tbPassword.Enabled = true;
if (this._causedByUser)
{
UserAccounts.EraseAccountPassword(this.cmbId.Text);
UserAccounts.SaveToLocal();
}
}
}
catch (Exception exception)
{
UiErrorHelper.HandExceptionSafely(this._manager.FrameworkWnd, exception);
}
}
internal bool CheckInput(out long id, out string password)
{
id = 0L;
password = this.tbPassword.Text;
if (this.cmbId.Text.Length <= 0)
{
this.ShowErrorTip(StringTable.User.MsgEmptyId, this.cmbId);
return false;
}
char ch = this.cmbId.Text[0];
bool flag = ((ch < '1') || (ch > '9')) || !long.TryParse(this.cmbId.Text, out id);
bool flag2 = password.Length <= 0;
bool flag3 = ImpsHelper.IsSid(id);
bool flag4 = ImpsHelper.IsUnicomMobileNo(id);
bool flag5 = ImpsHelper.IsCmccMobileNo(id);
if ((flag || (id <= 0L)) || ((!flag3 && !flag5) && !flag4))
{
this.ShowErrorTip(StringTable.User.MsgInvalidId, this.cmbId);
return false;
}
if (flag4)
{
this.ShowErrorTip(StringTable.User.MsgIsUnicomMobileNo, this.cmbId);
return false;
}
if (flag2)
{
this.ShowErrorTip(StringTable.User.MsgInvalidPassword, this.tbPassword);
return false;
}
return true;
}
private void Child_KeyPress(object sender, KeyPressEventArgs e)
{
this.InnerOnKeyPress(e);
}
private void cmbId_TextChanged(object sender, EventArgs e)
{
if (!this._suspendIdChanged)
{
try
{
this.TryFillRelatedInfo();
this.EnableControls(this.cmbId.Enabled);
}
catch
{
}
}
}
private static int CompareIds(string id1, string id2)
{
if (id1.Length < 11)
{
if (id2.Length == 11)
{
return 1;
}
}
else if (id2.Length < 11)
{
return -1;
}
return string.Compare(id1, id2);
}
private void CurrentUser_AutoLoginFailed(object sender, ImpsErrorEventArgs e)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -