private void CloseLoan(int FolderId) { int FileId = Convert.ToInt32(hdnFileId.Value); int UserId = Convert.ToInt32(hdnUserId.Value); string ErrMsg = LoanTaskCommon.CloseLoan(FileId, UserId, FolderId); if (ErrMsg != null && ErrMsg.Length > 0) { PageCommon.WriteJsEnd(this, ErrMsg, "window.parent.close();"); } }
private void CloseLoan(int FolderId) { int FileId = Convert.ToInt32(hdnFileId.Value); int UserId = Convert.ToInt32(hdnUserId.Value); string ErrMsg = LoanTaskCommon.CloseLoan(FileId, UserId, FolderId); if (ErrMsg != null && ErrMsg.Length > 0) { if (nullflag == true) { sCloseDialogCodes = "window.parent.CloseDialog_CloseLoan();"; } PageCommon.WriteJsEnd(this, ErrMsg, sCloseDialogCodes); return; } else { ErrMsg = "Moved Point file successfully."; PageCommon.WriteJsEnd(this, ErrMsg, sCloseDialogCodes); return; } }
private string CompleteTask(int iLoanTaskId) { #region complete task string sErrorMsg = string.Empty; int iEmailTemplateId = 0; bool bIsSuccess = LPWeb.DAL.WorkflowManager.CompleteTask(iLoanTaskId, this.CurrUser.iUserID, ref iEmailTemplateId); if (bIsSuccess == false) { sErrorMsg = "Failed to invoke WorkflowManager.CompleteTask."; return(sErrorMsg); } #endregion #region update point file stage int iLoanStageID = 0; #region get loan task info LoanTasks LoanTaskManager = new LoanTasks(); DataTable LoanTaskInfo = LoanTaskManager.GetLoanTaskInfo(iLoanTaskId); if (LoanTaskInfo.Rows.Count == 0) { sErrorMsg = "Invalid task id."; return(sErrorMsg); } string sLoanStageID = LoanTaskInfo.Rows[0]["LoanStageId"].ToString(); if (sLoanStageID == string.Empty) { sErrorMsg = "Invalid loan stage id."; return(sErrorMsg); } iLoanStageID = Convert.ToInt32(sLoanStageID); #endregion if (WorkflowManager.StageCompleted(iLoanStageID) == true) { #region invoke PointManager.UpdateStage() //add by gdc 20111212 Bug #1306 LPWeb.BLL.PointFiles pfile = new PointFiles(); var model = pfile.GetModel(iLoanID); if (model != null && !string.IsNullOrEmpty(model.Name.Trim())) { #region UPdatePointFileStage WCF string sError = LoanTaskCommon.UpdatePointFileStage(iLoanID, this.CurrUser.iUserID, iLoanStageID); #endregion } #endregion } #endregion return(sErrorMsg); }
protected void btnSave_Click(object sender, EventArgs e) { int Valid_LoanStageId = 0; string sErrorJs = string.Empty; if (this.Request.QueryString["CloseDialogCodes"] == null) { sErrorJs = "window.parent.RefreshPage();"; } else { sErrorJs = this.Request.QueryString["CloseDialogCodes"] + ";"; } #region 获取数据 DataTable LoanStages = this.LoanManager.GetLoanStages(this.iLoanID); if (LoanStages == null || LoanStages.Rows.Count <= 0) { this.iCurrentLoanStageId = GetTaskStageID(this.iLoanID); if ((this.iCurrentLoanStageId == null) || (this.iCurrentLoanStageId <= 0)) { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Failed0", "$('#divContainer').hide();alert('The loan does not have any stage to add the task to.');" + sErrorJs, true); return; } } int iStageID = string.IsNullOrEmpty(ddlStage.SelectedValue) ? this.iCurrentLoanStageId : Convert.ToInt32(ddlStage.SelectedValue); //CR54 this.iCurrentLoanStageId; string sTaskName = string.Empty; if (radTaskList.Checked == true) { sTaskName = this.ddlTaskList.SelectedValue; if (sTaskName == "-- select --") { sTaskName = string.Empty; } } else { sTaskName = this.txtTaskName.Text.Trim(); } string sDesc = this.txtDescription.Text.Trim(); int iOwnerID = Convert.ToInt32(this.ddlOwner.SelectedItem.Value); string sDueDate = this.txtDueDate.Text.Trim(); int iDaysToEstClose = 0; if (this.txtDaysToEst.Text != string.Empty) { iDaysToEstClose = Convert.ToInt32(this.txtDaysToEst.Text); } int iDaysAfterCreation = 0; if (this.txtDaysAfterCreation.Text != string.Empty) { iDaysAfterCreation = Convert.ToInt32(this.txtDaysAfterCreation.Text); } //int iDaysDueAfterPrevStage = 0; //if (this.txtDaysDueAfterPrevStage.Text != string.Empty) //{ // iDaysDueAfterPrevStage = Convert.ToInt32(this.txtDaysDueAfterPrevStage.Text.Trim()); //} int iPrerequisiteID = Convert.ToInt32(this.ddlPrerequisite.SelectedItem.Value); int iDaysDueAfterPre = 0; if (this.txtDaysDueAfter.Text != string.Empty) { iDaysDueAfterPre = Convert.ToInt32(this.txtDaysDueAfter.Text); } int iCompletionEmailID = 0; int iWarningEmailID = Convert.ToInt32(this.ddlWarningEmail.SelectedItem.Value); int iOverdueEmailID = Convert.ToInt32(this.ddlOverdueEmail.SelectedItem.Value); bool bExternalViewing = false; #endregion #region 检查任务名称重复 if (string.IsNullOrEmpty(sTaskName) || sTaskName.Trim() == string.Empty) { PageCommon.AlertMsg(this, "The task name cannot be blank."); return; } var loanInfo = this.LoanManager.GetModel(this.iLoanID); if (loanInfo == null || loanInfo.Status != "Prospect") //CR54 当为Prospect时检查重复 { bool bIsExist = this.LoanTaskManager.IsLoanTaskExists_Insert(this.iLoanID, sTaskName); if (bIsExist == true) { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Duplicate", "$('#divContainer').hide();alert('The task name is already taken.');$('#divContainer').show();", true); return; } } #endregion #region Invoke Workflow Manager checking and task API bool StageCompleted = LPWeb.BLL.WorkflowManager.StageCompleted(iStageID); // get next seq num int iNextSeq = LoanTaskManager.GetNextSequenceNum(this.iLoanID); // add task LPWeb.Model.LoanTasks taskModel = new LPWeb.Model.LoanTasks(); taskModel.LoanTaskId = 0; taskModel.FileId = iLoanID; taskModel.Name = sTaskName.Trim(); taskModel.Desc = sDesc.Trim(); taskModel.LoanStageId = iStageID; taskModel.OldLoanStageId = 0; taskModel.Owner = iOwnerID; taskModel.ModifiedBy = CurrUser.iUserID; taskModel.LastModified = DateTime.Now; taskModel.FileId = iLoanID; if (string.IsNullOrEmpty(sDueDate)) { taskModel.Due = DateTime.MinValue; } else { taskModel.Due = DateTime.Parse(sDueDate); } string sDueTime = ddlDueTime_hour.Text + ":" + ddlDueTime_min.Text; //this.txtDueTime.Text.Trim(); CR54 sDueTime = sDueTime.Replace("am", "").Replace("pm", ""); DateTime DTN = DateTime.Now; string sDueTime_Span = null; TimeSpan DueTime = new TimeSpan(); if (sDueTime == string.Empty) { taskModel.DueTime = null; } else { taskModel.DueTime = null; if (DateTime.TryParse(sDueTime, out DTN) == true) { sDueTime_Span = DTN.ToString("HH:mm"); if (TimeSpan.TryParse(sDueTime_Span, out DueTime) == true) { taskModel.DueTime = DueTime; } } } taskModel.DaysDueFromEstClose = (short)iDaysToEstClose; taskModel.DaysFromCreation = (short)iDaysAfterCreation; taskModel.PrerequisiteTaskId = iPrerequisiteID; taskModel.DaysDueAfterPrerequisite = (short)iDaysDueAfterPre; taskModel.CompletionEmailId = iCompletionEmailID; taskModel.WarningEmailId = iWarningEmailID; taskModel.OverdueEmailId = iOverdueEmailID; taskModel.SequenceNumber = (short)iNextSeq; taskModel.ExternalViewing = bExternalViewing; #endregion // create task int iLoanTaskId = LPWeb.BLL.WorkflowManager.AddTask(taskModel, this.txtDaysToEst.Text.Trim(), this.txtDaysAfterCreation.Text.Trim(), this.txtDaysDueAfter.Text.Trim(), txtDaysDueAfterPrevStage.Text.Trim()); if (iLoanTaskId > 0) { SaveCompletetionEmails(iLoanTaskId); string Notes = txtNotes.Text; this.CreateLoanNotes(taskModel.FileId, iLoanTaskId, Notes); //gdc CR40 try { LPWeb.BLL.Company_Alerts companyAlertBLL = new Company_Alerts(); LPWeb.Model.Company_Alerts modelAlert = companyAlertBLL.GetModel(); if (modelAlert != null && modelAlert.SendEmailCustomTasks == true && modelAlert.CustomTaskEmailTemplId > 0) { SaveOKAndSendEmail(modelAlert, iLoanTaskId); } } catch { } //gdc CR40 END } else { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Failed", "$('#divContainer').hide();alert('Failed to save the record.');" + sErrorJs, true); } #region update point file stage if (StageCompleted) { string sError = LoanTaskCommon.UpdatePointFileStage(this.iLoanID, this.CurrUser.iUserID, iStageID); // if failed //if (sError != string.Empty) //{ // this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Failed0", "$('#divContainer').hide();alert('Added task successfully but failed to update stage date in Point.');$('#divContainer').show();", true); // return; //} } #endregion #region completed if (chkCompleted.Checked == true) { string sResult = this.CompleteTask(iLoanTaskId); if (sResult != string.Empty) { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Failed", "$('#divContainer').hide();alert('Failed to complete task.');" + sErrorJs, true); } } #endregion // success if (((Button)sender).Text == "Save and Create Another") { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Redirect", "$('#divContainer').hide();alert('Added task successfully.');window.location.href=window.location.href;", true); } else { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Success", "$('#divContainer').hide();alert('Added task successfully.');" + sErrorJs, true); } }
protected void Page_Load(object sender, EventArgs e) { #region 接收参数 if (this.Request.QueryString["TaskIDs"] == null) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"Missing required query string.\"}"); return; } string sTaskIDs = this.Request.QueryString["TaskIDs"].ToString(); if (Regex.IsMatch(sTaskIDs, @"^([1-9]\d*)(,[1-9]\d*)*$") == false) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"Invalid query string[" + sTaskIDs + "].\"}"); return; } // LoanID bool bIsValid = PageCommon.ValidateQueryString(this, "LoanID", QueryStringType.ID); if (bIsValid == false) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"Missing required query string.\"}"); return; } string sLoanID = this.Request.QueryString["LoanID"].ToString(); int iLoanID = Convert.ToInt32(sLoanID); #endregion // json示例 // {"ExecResult":"Success","ErrorMsg":""} // {"ExecResult":"Failed","ErrorMsg":"执行数据库脚本时发生错误。"} string sExecResult = string.Empty; string sErrorMsg = string.Empty; string sLoanClosed = "No"; string result = ""; bool bIsSuccess = false; try { // workflow api string[] TaskIDArray = sTaskIDs.Split(','); foreach (string sTaskID in TaskIDArray) { int iTaskID = Convert.ToInt32(sTaskID); #region get loan task info LoanTasks LoanTaskManager = new LoanTasks(); DataTable LoanTaskInfo = LoanTaskManager.GetLoanTaskInfo(iTaskID); if (LoanTaskInfo.Rows.Count == 0) { sErrorMsg = "Failed to delete the tasks(s) invalid task id."; return; } string sLoanStageID = LoanTaskInfo.Rows[0]["LoanStageId"].ToString(); if (sLoanStageID == string.Empty) { sErrorMsg = "Failed to delete the task(s) invalid Stage Id"; return; } int iLoanStageID = Convert.ToInt32(sLoanStageID); #endregion #region delete task bIsSuccess = LPWeb.DAL.WorkflowManager.DeleteTask(iTaskID, this.CurrUser.iUserID); if (bIsSuccess == false) { sErrorMsg = "Failed to delete the task(s) due to a Workflow Manager problem."; return; } bool StageCompletedAfter = LPWeb.BLL.WorkflowManager.StageCompleted(iLoanStageID); #endregion if (StageCompletedAfter) { #region update point file stage #region invoke PointManager.UpdateStage() string sError = LoanTaskCommon.UpdatePointFileStage(iLoanID, this.CurrUser.iUserID, iLoanStageID); // the last one, sleep 1 second System.Threading.Thread.Sleep(1000); if (sError == string.Empty) // success { bIsSuccess = true; sErrorMsg = "Deleted the task(s) successfully."; } else { sErrorMsg = "Deleted the task(s) but failed to update stage date in Point."; return; } if (WorkflowManager.IsLoanClosed(iLoanID)) { sLoanClosed = "Yes"; } #endregion #endregion } } return; } catch (Exception ex) { sErrorMsg = "Failed to delete selected task(s): " + ex.ToString().Replace("\"", "\\\""); return; } finally { string sEmailTemplateID = ""; if (bIsSuccess) { result = "{\"ExecResult\":\"Success\",\"ErrorMsg\":\"" + sErrorMsg + "\",\"EmailTemplateID\":\"" + sEmailTemplateID + "\",\"LoanClosed\":\"" + sLoanClosed + "\"}"; } else { result = "{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sErrorMsg + "\"}"; } Response.Write(result); } }
protected void Page_Load(object sender, EventArgs e) { #region 接收参数 // TaskID bool bIsValid = PageCommon.ValidateQueryString(this, "TaskID", QueryStringType.ID); if (bIsValid == false) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"Missing required query string.\"}"); return; } string sTaskID = this.Request.QueryString["TaskID"].ToString(); int iTaskID = Convert.ToInt32(sTaskID); // LoanID bIsValid = PageCommon.ValidateQueryString(this, "LoanID", QueryStringType.ID); if (bIsValid == false) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"Missing required query string.\"}"); return; } string sLoanID = this.Request.QueryString["LoanID"].ToString(); int iLoanID = Convert.ToInt32(sLoanID); #endregion // json示例 // {"ExecResult":"Success","ErrorMsg":"","EmailTemplateID":"1", "LoanClosed":"Yes"} // {"ExecResult":"Failed","ErrorMsg":"执行数据库脚本时发生错误。"} string sErrorMsg = string.Empty; string sEmailTemplateID = string.Empty; bool bIsSuccess = false; string LoanClosed = "No"; var result = ""; try { #region complete task int iEmailTemplateId = 0; bIsSuccess = LPWeb.DAL.WorkflowManager.CompleteTask(iTaskID, this.CurrUser.iUserID, ref iEmailTemplateId); if (bIsSuccess == false) { sErrorMsg = "Failed to invoke WorkflowManager.CompleteTask."; return; } if (iEmailTemplateId != 0) { sEmailTemplateID = iEmailTemplateId.ToString(); } #endregion #region update point file stage int iLoanStageID = 0; #region get loan task info LoanTasks LoanTaskManager = new LoanTasks(); DataTable LoanTaskInfo = LoanTaskManager.GetLoanTaskInfo(iTaskID); if (LoanTaskInfo.Rows.Count == 0) { bIsSuccess = false; sErrorMsg = "Invalid task id."; return; } string sLoanStageID = LoanTaskInfo.Rows[0]["LoanStageId"].ToString(); if (sLoanStageID == string.Empty) { bIsSuccess = false; sErrorMsg = "Invalid loan stage id."; return; } iLoanStageID = Convert.ToInt32(sLoanStageID); #endregion bIsSuccess = true; if (!WorkflowManager.StageCompleted(iLoanStageID)) { sErrorMsg = "Completed task successfully."; return; } #region invoke PointManager.UpdateStage() //add by gdc 20111212 Bug #1306 LPWeb.BLL.PointFiles pfile = new PointFiles(); var model = pfile.GetModel(iLoanID); if (model != null && !string.IsNullOrEmpty(model.Name.Trim())) { #region check Point File Status first ServiceManager sm = new ServiceManager(); using (LP2ServiceClient service = sm.StartServiceClient()) { CheckPointFileStatusReq checkFileReq = new CheckPointFileStatusReq(); checkFileReq.hdr = new ReqHdr(); checkFileReq.hdr.UserId = CurrUser.iUserID; checkFileReq.hdr.SecurityToken = "SecurityToken"; checkFileReq.FileId = iLoanID; CheckPointFileStatusResp checkFileResp = service.CheckPointFileStatus(checkFileReq); if (checkFileResp == null || checkFileResp.hdr == null || !checkFileResp.hdr.Successful) { sErrorMsg = "Unable to get Point file status from Point Manager."; WorkflowManager.UnCompleteTask(iTaskID, CurrUser.iUserID); bIsSuccess = false; return; } if (checkFileResp.FileLocked) { sErrorMsg = checkFileResp.hdr.StatusInfo; WorkflowManager.UnCompleteTask(iTaskID, CurrUser.iUserID); bIsSuccess = false; return; } } #endregion #region UPdatePointFileStage WCF string sError = LoanTaskCommon.UpdatePointFileStage(iLoanID, this.CurrUser.iUserID, iLoanStageID); // the last one, sleep 1 second System.Threading.Thread.Sleep(1000); if (sError == string.Empty) // success { sErrorMsg = "Completed task successfully."; } else { sErrorMsg = "Completed task successfully but failed to update stage date in Point."; //sErrorMsg = "Failed to update point file stage: " + sError.Replace("\"", "\\\""); } #endregion } if (WorkflowManager.IsLoanClosed(iLoanID)) { LoanClosed = "Yes"; } return; #endregion } catch (System.ServiceModel.EndpointNotFoundException ee) { sErrorMsg = "Completed task successfully but failed to update stage date in Point."; return; } catch (Exception ex) { if (bIsSuccess) { sErrorMsg = "Completed task successfully but encountered an error:" + ex.Message; } else { sErrorMsg = "Failed to complete task, reason:" + ex.Message; } //sErrorMsg = "Exception happened when invoke WorkflowManager.CompleteTask: " + ex.ToString().Replace("\"", "\\\""); bIsSuccess = false; return; } finally { if (bIsSuccess) { result = "{\"ExecResult\":\"Success\",\"ErrorMsg\":\"" + sErrorMsg + "\",\"EmailTemplateID\":\"" + sEmailTemplateID + "\",\"TaskID\":\"" + sTaskID + "\",\"LoanClosed\":\"" + LoanClosed + "\"}"; } //result = "{\"ExecResult\":\"Success\",\"ErrorMsg\":\"\",\"EmailTemplateID\":\"" + sEmailTemplateID + "\",\"LoanClosed\":\"" + LoanClosed + "\"}"; else { result = "{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sErrorMsg + "\"}"; } this.Response.Write(result); } #endregion }
protected void Page_Load(object sender, EventArgs e) { #region 接收参数 // TaskID bool bIsValid = PageCommon.ValidateQueryString(this, "TaskID", QueryStringType.ID); if (bIsValid == false) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"Missing required query string.\"}"); this.Response.End(); } string sTaskID = this.Request.QueryString["TaskID"].ToString(); int iTaskID = Convert.ToInt32(sTaskID); // LoanID bIsValid = PageCommon.ValidateQueryString(this, "LoanID", QueryStringType.ID); if (bIsValid == false) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"Missing required query string.\"}"); this.Response.End(); } string sLoanID = this.Request.QueryString["LoanID"].ToString(); int iLoanID = Convert.ToInt32(sLoanID); #endregion // json示例 // {"ExecResult":"Success","ErrorMsg":""} // {"ExecResult":"Failed","ErrorMsg":"执行数据库脚本时发生错误。"} string sErrorMsg = string.Empty; int iLoanStageID; bool StageCompleted = false; try { #region get loan task info LoanTasks LoanTaskManager = new LoanTasks(); DataTable LoanTaskInfo = LoanTaskManager.GetLoanTaskInfo(iTaskID); if (LoanTaskInfo.Rows.Count == 0) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"Invalid task id.\"}"); return; } string sLoanStageID = LoanTaskInfo.Rows[0]["LoanStageId"].ToString(); if (sLoanStageID == string.Empty) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"Invalid loan stage id.\"}"); return; } iLoanStageID = Convert.ToInt32(sLoanStageID); #endregion #region uncomplete task StageCompleted = WorkflowManager.StageCompleted(iLoanStageID); bool bIsSuccess = LPWeb.DAL.WorkflowManager.UnCompleteTask(iTaskID, this.CurrUser.iUserID); if (bIsSuccess == false) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"Failed to invoke WorkflowManager.UnCompleteTask api.\"}"); return; } #endregion } catch (Exception ex) { sErrorMsg = "Failed to invoke Workflow Manager, reason:" + ex.Message; //sErrorMsg = "Exception happened when invoke WorkflowManager.UnCompleteTask: " + ex.ToString().Replace("\"", "\\\""); this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sErrorMsg + "\"}"); return; } if (!StageCompleted) // if the stage was not completed prior to the un-complete { this.Response.Write("{\"ExecResult\":\"Success\",\"ErrorMsg\":\"\"}"); return; } try { //add by gdc 20111212 Bug #1306 LPWeb.BLL.PointFiles pfile = new PointFiles(); var model = pfile.GetModel(iLoanID); if (model != null && !string.IsNullOrEmpty(model.Name.Trim())) { #region check Point File Status first //ServiceManager sm = new ServiceManager(); //using (LP2ServiceClient service = sm.StartServiceClient()) //{ // CheckPointFileStatusReq checkFileReq = new CheckPointFileStatusReq(); // checkFileReq.hdr = new ReqHdr(); // checkFileReq.hdr.UserId = CurrUser.iUserID; // checkFileReq.hdr.SecurityToken = "SecurityToken"; // checkFileReq.FileId = iLoanID; // int emailTemplateId = 0; // CheckPointFileStatusResp checkFileResp = service.CheckPointFileStatus(checkFileReq); // if (checkFileResp == null || checkFileResp.hdr == null || !checkFileResp.hdr.Successful) // { // sErrorMsg = "Unable to get Point file status from Point Manager."; // WorkflowManager.CompleteTask(iTaskID, CurrUser.iUserID, ref emailTemplateId); // this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sErrorMsg + "\"}"); // return; // } // if (checkFileResp.FileLocked) // { // sErrorMsg = checkFileResp.hdr.StatusInfo; // WorkflowManager.CompleteTask(iTaskID, CurrUser.iUserID, ref emailTemplateId); // this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sErrorMsg + "\"}"); // return; // } //} #endregion #region update point file stage string sError = LoanTaskCommon.UpdatePointFileStage(iLoanID, this.CurrUser.iUserID, iLoanStageID); // the last one, sleep 1 second System.Threading.Thread.Sleep(1000); if (sError == string.Empty) // success { this.Response.Write("{\"ExecResult\":\"Success\",\"ErrorMsg\":\"\"}"); } else { sErrorMsg = "Un-completed task successfully but failed to update stage date in Point."; //sErrorMsg = "Uncomplete task successfully, but failed to update point file stage: " + sError.Replace("\"", "\\\""); this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sErrorMsg + "\"}"); } #endregion } else { this.Response.Write("{\"ExecResult\":\"Success\",\"ErrorMsg\":\"\"}"); } } catch (Exception ex) { sErrorMsg = "Un-completed task successfully but failed to update stage date in Point, reason:" + ex.Message; //sErrorMsg = "Uncomplete task successfully, but exception happened when update point stage: " + ex.ToString().Replace("\"", "\\\""); this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sErrorMsg + "\"}"); } }
protected void Page_Load(object sender, EventArgs e) { #region 接收参数 // TaskID bool bIsValid = PageCommon.ValidateQueryString(this, "TaskID", QueryStringType.ID); if (bIsValid == false) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"Missing required query string.\"}"); return; } string sTaskID = this.Request.QueryString["TaskID"].ToString(); int iTaskID = Convert.ToInt32(sTaskID); string sLoanID = this.Request.QueryString["LoanID"].ToString(); int iLoanID = Convert.ToInt32(sLoanID); #endregion // json示例 // {"ExecResult":"Success","ErrorMsg":"","EmailTemplateID":"1"} // {"ExecResult":"Failed","ErrorMsg":"执行数据库脚本时发生错误。"} string sErrorMsg = string.Empty; string sEmailTemplateID = string.Empty; string LoanClosed = "No"; ProspectTasks bpTasks = new ProspectTasks(); int iEmailTemplateId = 0; bool bIsSuccess = false; string result = string.Empty; try { if (iLoanID == -1) { bIsSuccess = bpTasks.ComplateSelProspectTask(iTaskID, this.CurrUser.iUserID, ref iEmailTemplateId); if (bIsSuccess == false) { sErrorMsg = "Failed to CompleteTask."; return; } else { sErrorMsg = "Completed task successfully."; } } else { bIsSuccess = LPWEBDAL.WorkflowManager.CompleteTask(iTaskID, this.CurrUser.iUserID, ref iEmailTemplateId); if (bIsSuccess == false) { sErrorMsg = "Failed to invoke WorkflowManager.CompleteTask."; return; } #region update point file stage int iLoanStageID = 0; #region get loan task info LoanTasks LoanTaskManager = new LoanTasks(); DataTable LoanTaskInfo = LoanTaskManager.GetLoanTaskInfo(iTaskID); if (LoanTaskInfo.Rows.Count == 0) { bIsSuccess = false; sErrorMsg = "Invalid task id."; return; } string sLoanStageID = LoanTaskInfo.Rows[0]["LoanStageId"].ToString(); if (sLoanStageID == string.Empty) { bIsSuccess = false; sErrorMsg = "Invalid loan stage id."; return; } iLoanStageID = Convert.ToInt32(sLoanStageID); #endregion bIsSuccess = true; if (!WorkflowManager.StageCompleted(iLoanStageID)) { sErrorMsg = "Completed task successfully."; } #region invoke PointManager.UpdateStage() string sError = LoanTaskCommon.UpdatePointFileStage(iLoanID, this.CurrUser.iUserID, iLoanStageID); if (sError == string.Empty) // success { sErrorMsg = "Completed task successfully."; } else { sErrorMsg = "Completed task successfully but failed to update stage date in Point."; } #endregion if (iEmailTemplateId != 0) { //根据Lin 2011-02-28邮件,暂不增加发送邮件功能。 sEmailTemplateID = iEmailTemplateId.ToString(); } } #endregion if (string.Equals(new Loans().GetLoanInfo(iLoanID).Rows[0]["Status"], "Processing")) { LoanClosed = "Yes"; } } catch (Exception ex) { if (bIsSuccess) { sErrorMsg = "Completed task successfully but encountered an error:" + ex.Message; } else { sErrorMsg = "Failed to complete task, reason:" + ex.Message; } bIsSuccess = false; } finally { if (bIsSuccess) { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sErrorMsg + "\",\"EmailTemplateID\":\"" + sEmailTemplateID + "\",\"LoanID\":\"" + sLoanID + "\",\"LoanClosed\":\"" + LoanClosed + "\"}"); } else { this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sErrorMsg + "\"}"); } this.Response.End(); } }
protected void btnSave_Click(object sender, EventArgs e) { #region 获取数据 DataTable LoanStages = this.LoanManager.GetLoanStages(this.iLoanID); if (LoanStages == null || LoanStages.Rows.Count <= 0) { this.iCurrentLoanStageId = GetTaskStageID(this.iLoanID); if ((this.iCurrentLoanStageId == null) || (this.iCurrentLoanStageId <= 0)) { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Failed0", "$('#divContainer').hide();alert('The loan does not have any stage to add the task to.');window.parent.RefreshPage();", true); return; } } //int iStageID = Convert.ToInt32(this.ddlStage.SelectedItem.Value); int iStageID = string.IsNullOrEmpty(ddlStage.SelectedValue) ? this.iCurrentLoanStageId : Convert.ToInt32(ddlStage.SelectedValue); //CR54 this.iCurrentLoanStageId; string sTaskName = this.txtTaskName.Text.Trim(); int iOwnerID = Convert.ToInt32(this.ddlOwner.SelectedItem.Value); string sDueDate = this.txtDueDate.Text.Trim(); int iDaysToEstClose = 0; if (this.txtDaysToEst.Text != string.Empty) { iDaysToEstClose = Convert.ToInt32(this.txtDaysToEst.Text); } int iDaysAfterCreation = 0; if (this.txtDaysAfterCreation.Text != string.Empty) { iDaysAfterCreation = Convert.ToInt32(this.txtDaysAfterCreation.Text); } //int iDaysDueAfterPrevStage = 0; //if (this.txtDaysDueAfterPrevStage.Text != string.Empty) //{ // iDaysDueAfterPrevStage = Convert.ToInt32(this.txtDaysDueAfterPrevStage.Text.Trim()); //} int iPrerequisiteID = Convert.ToInt32(this.ddlPrerequisite.SelectedItem.Value); int iDaysDueAfterPre = 0; if (this.txtDaysDueAfter.Text != string.Empty) { iDaysDueAfterPre = Convert.ToInt32(this.txtDaysDueAfter.Text); } int iCompletionEmailID = Convert.ToInt32(this.ddlCompletionEmail.SelectedItem.Value); int iWarningEmailID = Convert.ToInt32(this.ddlWarningEmail.SelectedItem.Value); int iOverdueEmailID = Convert.ToInt32(this.ddlOverdueEmail.SelectedItem.Value); bool bExternalViewing = chbExternalViewing.Checked; #endregion #region 检查任务名称重复 if (string.IsNullOrEmpty(sTaskName) || sTaskName.Trim() == string.Empty) { PageCommon.AlertMsg(this, "The task name cannot be blank."); return; } bool bIsExist = this.LoanTaskManager.IsLoanTaskExists_Insert(this.iLoanID, sTaskName); if (bIsExist == true) { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Duplicate", "$('#divContainer').hide();alert('The task name is already taken.');$('#divContainer').show();", true); return; } #endregion #region Invoke Workflow Manager checking and task API bool StageCompleted = LPWeb.BLL.WorkflowManager.StageCompleted(iStageID); // get next seq num int iNextSeq = LoanTaskManager.GetNextSequenceNum(this.iLoanID); // add task LPWeb.Model.LoanTasks taskModel = new LPWeb.Model.LoanTasks(); taskModel.LoanTaskId = 0; taskModel.FileId = iLoanID; taskModel.Name = sTaskName.Trim(); taskModel.LoanStageId = iStageID; taskModel.OldLoanStageId = 0; taskModel.Owner = iOwnerID; taskModel.ModifiedBy = CurrUser.iUserID; taskModel.LastModified = DateTime.Now; taskModel.FileId = iLoanID; if (string.IsNullOrEmpty(sDueDate)) { taskModel.Due = DateTime.MinValue; } else { taskModel.Due = DateTime.Parse(sDueDate); } taskModel.DaysDueFromEstClose = (short)iDaysToEstClose; taskModel.DaysFromCreation = (short)iDaysAfterCreation; taskModel.PrerequisiteTaskId = iPrerequisiteID; taskModel.DaysDueAfterPrerequisite = (short)iDaysDueAfterPre; taskModel.CompletionEmailId = iCompletionEmailID; taskModel.WarningEmailId = iWarningEmailID; taskModel.OverdueEmailId = iOverdueEmailID; taskModel.SequenceNumber = (short)iNextSeq; taskModel.ExternalViewing = bExternalViewing; #endregion // update //bool bIsSuccess1 = this.LoanTaskManager.UpdateLoanTask(this.iTaskID, sTaskName, sDueDate, iCurrentUserID, iOwnerID, iStageID, iPrerequisiteID, iDaysToEstClose, iDaysDueAfterPre, iWarningEmailID, iOverdueEmailID, iCompletionEmailID, iOldStageID); // we need to invoke Workflow Manager UpdateTask in order to set up everything correctly! //bool bIsSuccess1 = LPWeb.BLL.WorkflowManager.UpdateTask(this.iTaskID, sTaskName, sDueDate, iCurrentUserID, iOwnerID, iStageID, iPrerequisiteID, iDaysToEstClose, iDaysDueAfterPre, iWarningEmailID, iOverdueEmailID, iCompletionEmailID, iOldStageID); int iLoanTaskId = LPWeb.BLL.WorkflowManager.AddTask(taskModel, this.txtDaysToEst.Text.Trim(), this.txtDaysAfterCreation.Text.Trim(), this.txtDaysDueAfter.Text.Trim(), txtDaysDueAfterPrevStage.Text.Trim()); if (iLoanTaskId > 0) { SaveCompletetionEmails(iLoanTaskId); //gdc CR40 try { LPWeb.BLL.Company_Alerts companyAlertBLL = new Company_Alerts(); LPWeb.Model.Company_Alerts modelAlert = companyAlertBLL.GetModel(); if (modelAlert != null && modelAlert.SendEmailCustomTasks == true && modelAlert.CustomTaskEmailTemplId > 0) { SaveOKAndSendEmail(modelAlert, iLoanTaskId); } } catch { } //gdc CR40 END this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Success", "$('#divContainer').hide();alert('Saved successfully.');window.parent.RefreshPage();", true); } else { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Failed", "$('#divContainer').hide();alert('Failed to save the record.');window.parent.RefreshPage();", true); } //LoanTaskManager.InsertLoanTask(this.iLoanID, sTaskName, sDueDate, iOwnerID, iStageID, iPrerequisiteID, iNextSeq, iDaysToEstClose, iDaysDueAfterPre, iWarningEmailID, iOverdueEmailID, iCompletionEmailID); #region update point file stage if (StageCompleted) { string sError = LoanTaskCommon.UpdatePointFileStage(this.iLoanID, this.CurrUser.iUserID, iStageID); // if failed if (sError != string.Empty) { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Failed0", "$('#divContainer').hide();alert('Added task successfully but failed to update stage date in Point.');$('#divContainer').show();", true); return; } } #endregion // success this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Success", "$('#divContainer').hide();alert('Added task successfully.');window.parent.RefreshPage();", true); }
protected void Page_Load(object sender, EventArgs e) { string sTaskIDs = this.Request.QueryString["TaskIDs"].ToString(); string sSendEmail = this.Request.QueryString["SendEmail"].ToString(); string sLoanIDs = this.Request.QueryString["LoanIDs"].ToString(); string sErrorMsg = string.Empty; string sEmailTemplateID = string.Empty; bool bIsSuccess = false; var result = ""; string LoanClosed = "No"; string sGlobalLoanID = "0"; try { string[] TaskIDs = sTaskIDs.Split(",".ToCharArray()); string[] LoanIDs = sLoanIDs.Split(",".ToCharArray()); for (int i = 0; i < TaskIDs.Length; i++) { int iTaskID = Convert.ToInt32(TaskIDs[i]); int iLoanID = Convert.ToInt32(LoanIDs[i]); int iEmailTemplateId = 0; // if the task is client task if (iLoanID == -1) { ProspectTasks bpTasks = new ProspectTasks(); bIsSuccess = bpTasks.ComplateSelProspectTask(iTaskID, this.CurrUser.iUserID, ref iEmailTemplateId); if (bIsSuccess == false) { sErrorMsg = "Failed to CompleteTask."; return; } if (iEmailTemplateId != 0) { //根据Lin 2011-02-28邮件,暂不增加发送邮件功能。 sEmailTemplateID = iEmailTemplateId.ToString(); } } else { #region complete task; bIsSuccess = LPWEBDAL.WorkflowManager.CompleteTask(iTaskID, this.CurrUser.iUserID, ref iEmailTemplateId); sGlobalLoanID = iLoanID.ToString(); if (bIsSuccess == false) { sErrorMsg = "Failed to invoke WorkflowManager.CompleteTask."; return; } if (iEmailTemplateId != 0 && sSendEmail == "OK") { sEmailTemplateID = iEmailTemplateId.ToString(); sErrorMsg = SendEmail(iLoanID, iTaskID, iEmailTemplateId); } #endregion #region update point file stage int iLoanStageID = 0; #region get loan task info LoanTasks LoanTaskManager = new LoanTasks(); DataTable LoanTaskInfo = LoanTaskManager.GetLoanTaskInfo(iTaskID); if (LoanTaskInfo.Rows.Count == 0) { bIsSuccess = false; sErrorMsg = "Invalid task id."; return; } string sLoanStageID = LoanTaskInfo.Rows[0]["LoanStageId"].ToString(); if (sLoanStageID == string.Empty) { bIsSuccess = false; sErrorMsg = "Invalid loan stage id."; return; } iLoanStageID = Convert.ToInt32(sLoanStageID); #endregion bIsSuccess = true; if (!WorkflowManager.StageCompleted(iLoanStageID)) { sErrorMsg = "Completed task successfully."; continue; } #region invoke PointManager.UpdateStage() BLL.Loans loanMgr = new Loans(); Model.Loans loan = loanMgr.GetModel(iLoanID); // if it's a prospect loan, don't update the Point file. if (string.IsNullOrEmpty(loan.Status) || loan.Status.ToUpper() == "PROSPECT") { continue; } string sError = LoanTaskCommon.UpdatePointFileStage(iLoanID, this.CurrUser.iUserID, iLoanStageID); if (sError == string.Empty) // success { sErrorMsg = "Completed task successfully."; } else { sErrorMsg = "Completed task successfully but failed to update stage date in Point."; //sErrorMsg = "Failed to update point file stage: " + sError.Replace("\"", "\\\""); } if (WorkflowManager.IsLoanClosed(iLoanID)) { LoanClosed = "Yes"; } #endregion #endregion } } return; } catch (System.ServiceModel.EndpointNotFoundException ee) { sErrorMsg = "Completed task successfully but failed to update stage date in Point."; return; } catch (Exception ex) { if (bIsSuccess) { sErrorMsg = "Completed task successfully but encountered an error:" + ex.Message; } else { sErrorMsg = "Failed to complete task, reason:" + ex.Message; } //sErrorMsg = "Exception happened when invoke WorkflowManager.CompleteTask: " + ex.ToString().Replace("\"", "\\\""); bIsSuccess = false; return; } finally { if (bIsSuccess) { result = "{\"ExecResult\":\"Success\",\"ErrorMsg\":\"" + sErrorMsg + "\",\"TaskID\":\"" + sTaskIDs + "\",\"LoanID\":\"" + sGlobalLoanID + "\",\"LoanClosed\":\"" + LoanClosed + "\"}"; } //result = "{\"ExecResult\":\"Success\",\"ErrorMsg\":\"\",\"EmailTemplateID\":\"" + sEmailTemplateID + "\",\"LoanClosed\":\"" + LoanClosed + "\"}"; else { result = "{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sErrorMsg + "\"}"; } this.Response.Write(result); } }