protected void Page_Load(object sender, EventArgs e) { // json示例 // {"ExecResult":"Success","ErrorMsg":""} // {"ExecResult":"Failed","ErrorMsg":"错误信息"} int iFileID = 0; int iContactID = 0; int iContactRoleID = 0; int iCurrrentUserID = this.CurrUser.iUserID; #region 校验页面参数 bool bIsValid = PageCommon.ValidateQueryString(this, "FileID", QueryStringType.ID); if (bIsValid == false) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"Missing required query string.\"}"); this.Response.End(); } string sFileID = this.Request.QueryString["FileID"]; iFileID = Convert.ToInt32(sFileID); bIsValid = PageCommon.ValidateQueryString(this, "ContactID", QueryStringType.ID); if (bIsValid == false) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"Missing required query string.\"}"); this.Response.End(); } string sContactID = this.Request.QueryString["ContactID"]; iContactID = Convert.ToInt32(sContactID); bIsValid = PageCommon.ValidateQueryString(this, "ContactRoleID", QueryStringType.ID); if (bIsValid == false) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"Missing required query string.\"}"); this.Response.End(); } string sContactRoleID = this.Request.QueryString["ContactRoleID"]; iContactRoleID = Convert.ToInt32(sContactRoleID); #endregion #region 调用ReassignContact ServiceManager sm = new ServiceManager(); using (LP2ServiceClient service = sm.StartServiceClient()) { #region Build ReassignContactRequest ReassignContactRequest req = new ReassignContactRequest(); req.hdr = new ReqHdr(); req.hdr.SecurityToken = "SecurityToken"; //todo:check dummy data req.hdr.UserId = this.CurrUser.iUserID; List <ReassignContactInfo> ContactList = new List <ReassignContactInfo>(); ReassignContactInfo ContactInfo = new ReassignContactInfo(); ContactInfo.FileId = iFileID; ContactInfo.ContactRoleId = iContactRoleID; ContactInfo.NewContactId = iContactID; ContactList.Add(ContactInfo); req.reassignContacts = ContactList.ToArray(); #endregion #region invoke ReassignContact bool bSuccess = false; string sError = string.Empty; try { ReassignContactResponse respone = service.ReassignContact(req); bSuccess = respone.hdr.Successful; if (bSuccess == false) { sError = "Failed to assign contact, reason:" + respone.hdr.StatusInfo; } } catch (System.ServiceModel.EndpointNotFoundException ex) { bSuccess = false; sError = "Failed to assign contact: Point Manager is not running."; LPLog.LogMessage(ex.Message); } catch (Exception exception) { bSuccess = false; sError = "Failed to assign contact. Exception: " + exception.Message; LPLog.LogMessage(exception.Message); } finally { if (bSuccess == false) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sError + "\"}"); this.Response.End(); } } #endregion } #endregion #region Reassign Loan Contact LPWeb.Model.LoanContacts lcModel = new LPWeb.Model.LoanContacts(); lcModel.FileId = iFileID; lcModel.ContactRoleId = iContactRoleID; lcModel.ContactId = iContactID; LPWeb.Model.LoanContacts oldlcModel = new LPWeb.Model.LoanContacts(); oldlcModel.FileId = iFileID; oldlcModel.ContactRoleId = 0; oldlcModel.ContactId = 0; LPWeb.BLL.LoanContacts LoanContacts1 = new LPWeb.BLL.LoanContacts(); LoanContacts1.Reassign(oldlcModel, lcModel, iCurrrentUserID); #endregion this.Response.Write("{\"ExecResult\":\"Success\",\"ErrorMsg\":\"\"}"); this.Response.End(); }
/// <summary> /// Link button click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnLink_Click(object sender, EventArgs e) { string sLoanIds = this.hdLoanIds.Value; string sLinkType = this.hdLinkType.Value; int iLinkType = 1; if (sLoanIds.Length < 1) { return; } try { LPWeb.BLL.ContactRoles contactRoles = new LPWeb.BLL.ContactRoles(); DataSet dsRole = contactRoles.GetList("Name='" + sLinkType + "'"); if (dsRole.Tables.Count > 0 && dsRole.Tables[0].Rows.Count > 0) { iLinkType = Convert.ToInt32(dsRole.Tables[0].Rows[0]["ContactRoleId"].ToString()); } LPWeb.BLL.LoanContacts loanContact = new LPWeb.BLL.LoanContacts(); foreach (string sLoanID in sLoanIds.Split(',')) { if (sLoanID.Trim() == "") { continue; } int iLoanID = 0; int iOldContactID = 0; if (sLoanID == "" || Int32.TryParse(sLoanID, out iLoanID) == false) { continue; } DataSet dsloancontact = loanContact.GetList("FileId=" + sLoanID + " AND ContactRoleId=" + iLinkType.ToString()); if (dsloancontact.Tables.Count > 0 && dsloancontact.Tables[0].Rows.Count > 0) { iOldContactID = Convert.ToInt32("0" + dsloancontact.Tables[0].Rows[0]["ContactId"].ToString()); } LPWeb.Model.LoanContacts modelOld = loanContact.GetModel(iLoanID, iLinkType, iOldContactID); if (modelOld == null) { modelOld = new Model.LoanContacts(); modelOld.ContactId = 0; } LPWeb.Model.LoanContacts model = new LPWeb.Model.LoanContacts(); model.FileId = iLoanID; model.ContactRoleId = iLinkType; model.ContactId = this.iProspectID; loanContact.Reassign(modelOld, model, 0); ServiceManager sm = new ServiceManager(); using (LP2ServiceClient service = sm.StartServiceClient()) { UpdateBorrowerRequest req = new UpdateBorrowerRequest(); req.hdr = new ReqHdr(); req.hdr.SecurityToken = "SecurityToken"; req.hdr.UserId = this.CurrUser.iUserID; req.ContactId = model.ContactId; UpdateBorrowerResponse respone = null; try { respone = service.UpdateBorrower(req); } catch (System.ServiceModel.EndpointNotFoundException) { string sExMsg = string.Format("Exception happened when Update loan (ContactId={0}): {1}", model.ContactId, "Point Manager is not running."); LPLog.LogMessage(LogType.Logerror, sExMsg); } catch (Exception ex) { string sExMsg = string.Format("Exception happened when Update loan (ContactId={0}): {1}", model.ContactId, ex.Message); LPLog.LogMessage(LogType.Logerror, sExMsg); } } } } catch (Exception ex) { LPLog.LogMessage(LogType.Logdebug, ex.ToString()); PageCommon.WriteJsEnd(this, "Failed to link the selected loans.", this.sCloseDialogCodes + this.sRefreshCodes); } this.hdLoanIds.Value = string.Empty; this.hdLinkType.Value = string.Empty; // success PageCommon.WriteJsEnd(this, "Link the selected loans successfully.", this.sCloseDialogCodes + this.sRefreshCodes); }