Пример #1
0
        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();
            }
        }
Пример #2
0
        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);
            }
        }