/* * /// 1 登录成功 * /// 0 登录失败 * /// -1 出错 * */ public async Task <LoginResult> LoginAsync(string username, string password) { if (username != null) { _userName = username; _password = password; } Login_93 request = new Login_93() { CN_LoginUserId_r = _userName, CO_LoginPassword_r = _password, }; request.SetDefaulValue(); // 发送和接收消息 string requestText = request.ToText(); var result = await SendAndRecvAsync(requestText); if (result.Value == -1) { return(new LoginResult { Value = -1, ErrorInfo = result.ErrorInfo, ErrorCode = result.ErrorCode }); } var response94 = result.Response as LoginResponse_94; if (response94 == null) { return(new LoginResult { Value = -1, ErrorInfo = "返回的不是 94 消息" }); } if (response94.Ok_1 == "0") { return(new LoginResult { Value = 0, ErrorInfo = "登录失败", Result = response94 }); } return(new LoginResult { Value = 1, ErrorInfo = "登录成功", Result = response94 }); }
/// <summary> /// 登录 /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="error"></param> /// <returns> /// 1 登录成功 /// 0 登录失败 /// -1 出错 /// </returns> public int Login(string username, string password, out LoginResponse_94 response94, out string responseText, out string error) { error = ""; int nRet = 0; response94 = null; responseText = ""; Login_93 request = new Login_93() { CN_LoginUserId_r = username, CO_LoginPassword_r = password, }; request.SetDefaultValue(); // 发送和接收消息 string requestText = request.ToText(); BaseMessage response = null; nRet = SCHelper.Instance.SendAndRecvMessage(requestText, out response, out responseText, out error); if (nRet == -1) { return(-1); } response94 = response as LoginResponse_94; if (response94 == null) { error = "返回的不是94消息"; return(-1); } if (response94.Ok_1 == "0") { return(0); } return(1); }
private void button_login_Click(object sender, EventArgs e) { string responseText = ""; string error = ""; for (int i = 0; i < int.Parse(this.textBox_login_copies.Text); i++) { Login_93 request = new Login_93() { UIDAlgorithm_1 = " ", PWDAlgorithm_1 = " ", CN_LoginUserId_r = this.textBox_username.Text, CO_LoginPassword_r = this.textBox_password.Text, CP_LocationCode_o = this.textBox_locationCode.Text }; string cmdText = request.ToText(); this.Print("send:" + cmdText); BaseMessage response = null; int nRet = SCHelper.Instance.SendAndRecvMessage(cmdText, out response, out responseText, out error); if (nRet == -1) { MessageBox.Show(error); this.Print("error:" + error); return; } this.Print("recv:" + responseText); this.button_login.Text = "登录(" + (i + 1).ToString() + ")"; this.button_login.Update(); } }
//发送消息 private void toolStripLabel_send_Click(object sender, EventArgs e) { string cmdText = ""; try { if (this.tabControl_main.SelectedTab == this.tabPage_Login93) { Login_93 request93 = new Login_93() { UIDAlgorithm_1 = this.textBox_Login93_UIDAlgorithm_1.Text, PWDAlgorithm_1 = this.textBox_Login93_PWDAlgorithm_1.Text, CN_LoginUserId_r = getText(this.textBox_Login93_loginUserId_CN_r), //.Text == "null" ? null : this.textBox_Login93_loginUserId_CN_r.Text CO_LoginPassword_r = getText(this.textBox_Login93_loginPassword_CO_r), //.Text == "null" ? null : this.textBox_Login93_loginPassword_CO_r.Text, CP_LocationCode_o = getText(this.textBox_Login93_locationCode_CP_o), //.Text == "null" ? null : this.textBox_Login93_locationCode_CP_o.Text }; cmdText = request93.ToText(); } else if (this.tabControl_main.SelectedTab == this.tabPage_SCStatus99) { SCStatus_99 request = new SCStatus_99() { StatusCode_1 = this.textBox_SCStatus99_statusCode_1.Text, MaxPrintWidth_3 = this.textBox_SCStatus99_maxPrintWidth_3.Text, ProtocolVersion_4 = this.textBox_SCStatus99_protocolVersion_4.Text }; cmdText = request.ToText(); } else if (this.tabControl_main.SelectedTab == this.tabPage_Checkout11) { Checkout_11 request = new Checkout_11() { SCRenewalPolicy_1 = this.textBox_Checkout11_SCRenewalPolicy_1.Text, NoBlock_1 = this.textBox_Checkout11_noBlock_1.Text, TransactionDate_18 = this.textBox_Checkout11_transactionDate_18.Text, NbDueDate_18 = this.textBox_Checkout11_nbDueDate_18.Text, AO_InstitutionId_r = getText(this.textBox_Checkout11_institutionId_AO_r), //.Text == "null" ? null : this.textBox_Checkout11_institutionId_AO_r.Text, AA_PatronIdentifier_r = getText(this.textBox_Checkout11_patronIdentifier_AA_r), //.Text == "null" ? null : this.textBox_Checkout11_patronIdentifier_AA_r.Text, AB_ItemIdentifier_r = getText(this.textBox_Checkout11_itemIdentifier_AB_r), //.Text == "null" ? null : this.textBox_Checkout11_itemIdentifier_AB_r.Text, AC_TerminalPassword_r = getText(this.textBox_Checkout11_terminalPassword_AC_r), //.Text == "null" ? null : this.textBox_Checkout11_terminalPassword_AC_r.Text; CH_ItemProperties_o = getText(this.textBox_Checkout11_itemProperties_CH_o), AD_PatronPassword_o = getText(this.textBox_Checkout11_patronPassword_AD_o), BO_FeeAcknowledged_1_o = getText(this.textBox_Checkout11_feeAcknowledged_BO_1_o), BI_Cancel_1_o = getText(this.textBox_Checkout11_cancel_BI_1_o), }; cmdText = request.ToText(); } else if (this.tabControl_main.SelectedTab == this.tabPage_Checkin09) { Checkin_09 request = new Checkin_09() { NoBlock_1 = this.textBox_Checkin09_noBlock_1.Text, TransactionDate_18 = this.textBox_Checkin09_transactionDate_18.Text, ReturnDate_18 = this.textBox_Checkin09_returnDate_18.Text, AP_CurrentLocation_r = getText(this.textBox_Checkin09_currentLocation_AP_r), AO_InstitutionId_r = getText(this.textBox_Checkin09_institutionId_AO_r), AB_ItemIdentifier_r = getText(this.textBox_Checkin09_itemIdentifier_AB_r), AC_TerminalPassword_r = getText(this.textBox_Checkin09_terminalPassword_AC_r), CH_ItemProperties_o = getText(this.textBox_Checkin09_itemProperties_CH_o), BI_Cancel_1_o = getText(this.textBox_Checkin09_cancel_BI_1_o), }; cmdText = request.ToText(); } else if (this.tabControl_main.SelectedTab == this.tabPage_PatronInformation63) { PatronInformation_63 request = new PatronInformation_63() { Language_3 = this.textBox_PatronInformation63_language_3.Text, TransactionDate_18 = this.textBox_PatronInformation63_transactionDate_18.Text, Summary_10 = this.textBox_PatronInformation63_summary_10.Text, AO_InstitutionId_r = getText(this.textBox_PatronInformation63_institutionId_AO_r), AA_PatronIdentifier_r = getText(this.textBox_PatronInformation63_patronIdentifier_AA_r), AC_TerminalPassword_o = getText(this.textBox_PatronInformation63_terminalPassword_AC_o), AD_PatronPassword_o = getText(this.textBox_PatronInformation63_patronPassword_AD_o), BP_StartItem_o = getText(this.textBox_PatronInformation63_startItem_BP_o), BQ_EndItem_o = getText(this.textBox_PatronInformation63_endItem_BQ_o), }; cmdText = request.ToText(); } else if (this.tabControl_main.SelectedTab == this.tabPage_ItemInformation17) { ItemInformation_17 request = new ItemInformation_17() { TransactionDate_18 = this.textBox_ItemInformation17_transactionDate_18.Text, AO_InstitutionId_r = getText(this.textBox_ItemInformation17_institutionId_AO_r), AB_ItemIdentifier_r = getText(this.textBox_ItemInformation17_itemIdentifier_AB_r), AC_TerminalPassword_o = getText(this.textBox_ItemInformation17_terminalPassword_AC_o), }; cmdText = request.ToText(); } else if (this.tabControl_main.SelectedTab == this.tabPage_Renew29) { Renew_29 request = new Renew_29() { ThirdPartyAllowed_1 = this.textBox_Renew29_thirdPartyAllowed_1.Text, NoBlock_1 = this.textBox_Renew29_noBlock_1.Text, TransactionDate_18 = this.textBox_Renew29_transactionDate_18.Text, NbDueDate_18 = this.textBox_Renew29_nbDueDate_18.Text, AO_InstitutionId_r = getText(this.textBox_Renew29_institutionId_AO_r), AA_PatronIdentifier_r = getText(this.textBox_Renew29_patronIdentifier_AA_r), AD_PatronPassword_o = getText(this.textBox_Renew29_patronPassword_AD_o), AB_ItemIdentifier_o = getText(this.textBox_Renew29_itemIdentifier_AB_o), AJ_TitleIdentifier_o = getText(this.textBox_Renew29_titleIdentifier_AJ_o), AC_TerminalPassword_o = getText(this.textBox_Renew29_terminalPassword_AC_o), CH_ItemProperties_o = getText(this.textBox_Renew29_itemProperties_CH_o), BO_FeeAcknowledged_1_o = getText(this.textBox_Renew29_feeAcknowledged_BO_1_o), }; cmdText = request.ToText(); } else if (this.tabControl_main.SelectedTab == this.tabPage_FeePaid37) { FeePaid_37 request = new FeePaid_37() { TransactionDate_18 = getText(this.textBox_FeePaid37_transactionDate_18), FeeType_2 = getText(this.textBox_FeePaid37_feeType), PaymentType_2 = getText(this.textBox_FeePaid37_paymentType), CurrencyType_3 = getText(this.textBox_FeePaid37_currencyType), BV_FeeAmount_r = getText(this.textBox_FeePaid37_feeAmount), AO_InstitutionId_r = getText(this.textBox_FeePaid37_institutionId_AO_r), AA_PatronIdentifier_r = getText(this.textBox_FeePaid37_patronIdentifier_AA_r), AC_TerminalPassword_o = getText(this.textBox_FeePaid37_terminalPassword_AC_o), AD_PatronPassword_o = getText(this.textBox_FeePaid37_patronPassword_AD_o), CG_FeeIdentifier_o = getText(this.textBox_FeePaid37_feeIdentifier_CG_o), BK_TransactionId_o = getText(this.textBox_FeePaid37_transactionId_BK_o), }; cmdText = request.ToText(); } //发送命令 this.txtMsg.Text = cmdText; this.sendCmd(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }