private void DoLogin(string userName, string password) { // btnOk.Enabled = false; lblMsg.Text = "登录中"; _tickTimer = new System.Timers.Timer(1 * 200); _tickTimer.Elapsed += new System.Timers.ElapsedEventHandler(delegate(object source, System.Timers.ElapsedEventArgs ee) { BeginInvoke(new Action(() => { if (lblMsg.Text.IndexOf(".") == -1) { lblMsg.Text += "."; } else if (lblMsg.Text.IndexOf(".") + 5 == lblMsg.Text.Length) { lblMsg.Text = lblMsg.Text.Substring(0, lblMsg.Text.Length - 5); } else { lblMsg.Text += "."; } })); }); //到达时间的时候执行事件; _tickTimer.AutoReset = true; //设置是执行一次(false)还是一直执行(true); _tickTimer.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件; HttpAdapter.postAsyncAsJSON(authEndPoint + "/AuthenticateMerchant", new AuthMerchantParam { StationCode = userName, PasswordHash = MD5Provider.Generate(password) }.ToStringObjectDictionary(), new { ApplicationId = Common.APPLICATION_ID }.ToStringObjectDictionary(), (ret, res) => { //MessageBoxAdapter.ShowDebug(_MonitorId.ToString()); //dynamic ret = new { Error = "", Success = false }; //ret = JsonConvert.DeserializeObject(result); MerchantVar.Load(userName, ret.ret); if ((bool)ret.Success) { INIAdapter.WriteValue(Common.INI_SECTION_LOCAL, Common.INI_KEY_USER_NAME_SINCE_LAST, userName, Common.INI_FILE_PATH); this.DialogResult = DialogResult.OK; this.Close(); } else { lblMsg.Text = ret.ErrorMessage; this.UIInvoke(() => { btnOk.Enabled = true; }); } _tickTimer.Enabled = false; _tickTimer = null; }); }
private void DoLogin(string userCode, string password) { // btnOk.Enabled = false; lblMsg.Text = "登录中"; _tickTimer = new System.Timers.Timer(1 * 200); _tickTimer.Elapsed += new System.Timers.ElapsedEventHandler(delegate(object source, System.Timers.ElapsedEventArgs ee) { BeginInvoke(new Action(() => { if (lblMsg.Text.IndexOf(".") == -1) { lblMsg.Text += "."; } else if (lblMsg.Text.IndexOf(".") + 5 == lblMsg.Text.Length) { lblMsg.Text = lblMsg.Text.Substring(0, lblMsg.Text.Length - 5); } else { lblMsg.Text += "."; } })); }); //到达时间的时候执行事件; _tickTimer.AutoReset = true; //设置是执行一次(false)还是一直执行(true); _tickTimer.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件; #if V2X byte runMode = byte.Parse(strRunMode);//测试1 正式0 string objectId = null; string objectName = null; TreeNode theSelectedNode = ctvObjectNodes.TreeView.SelectedNode; if (theSelectedNode != null && theSelectedNode.Name != "default") { objectId = theSelectedNode.Name; objectName = theSelectedNode.Text; } else { objectName = "自动"; } HttpAdapter.postAsyncAsJSON(authEndPoint, new { RunMode = runMode, ObjectId = objectId, UserCode = userCode, PasswordHash = MD5Provider.Generate(password) }.ToStringObjectDictionary(), new { ApplicationId = Common.APPLICATION_ID }.ToStringObjectDictionary(), (ret, res) => { if ((bool)ret.Success) { MerchantVar.UserCode = userCode; MerchantVar.Password = password; MerchantVar.LoadV2X(ret.ret); INIAdapter.WriteValue(Common.INI_SECTION_LOCAL, Common.INI_KEY_USER_NAME_SINCE_LAST, userCode, Common.INI_FILE_PATH); INIAdapter.WriteValue(Common.INI_SECTION_LOCAL, Common.INI_KEY_OBJECT_ID_SINCE_LAST, (objectId ?? "default"), Common.INI_FILE_PATH); INIAdapter.WriteValue(Common.INI_SECTION_LOCAL, Common.INI_KEY_OBJECT_NAME_SINCE_LAST, objectName, Common.INI_FILE_PATH); this.DialogResult = DialogResult.OK; this.Close(); } else { lblMsg.Text = ret.ErrorMessage; this.UIInvoke(() => { btnOk.Enabled = true; }); } _tickTimer.Enabled = false; _tickTimer = null; }); #else HttpAdapter.postAsyncAsJSON(authEndPoint + "/AuthenticateMerchant", new AuthMerchantParam { StationCode = userCode, PasswordHash = MD5Provider.Generate(password) }.ToStringObjectDictionary(), new { ApplicationId = Common.APPLICATION_ID }.ToStringObjectDictionary(), (ret, res) => { //MessageBoxAdapter.ShowDebug(_MonitorId.ToString()); //dynamic ret = new { Error = "", Success = false }; //ret = JsonConvert.DeserializeObject(result); MerchantVar.Load(userCode, ret.ret); if ((bool)ret.Success) { INIAdapter.WriteValue(Common.INI_SECTION_LOCAL, Common.INI_KEY_USER_NAME_SINCE_LAST, userCode, Common.INI_FILE_PATH); this.DialogResult = DialogResult.OK; this.Close(); } else { lblMsg.Text = ret.ErrorMessage; this.UIInvoke(() => { btnOk.Enabled = true; }); } _tickTimer.Enabled = false; _tickTimer = null; }); #endif }