Пример #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);

        // 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)
    {
        if (Request.QueryString["FileID"] == null && Request.QueryString["ContactID"] != null)
        {
            var ContactID = string.IsNullOrEmpty(Request.QueryString["ContactID"]) ? 0 : Convert.ToInt32(Request.QueryString["ContactID"]);
            LPWeb.BLL.LoanContacts loancontacts = new LoanContacts();
            var ds = loancontacts.GetContactLoans(ContactID);

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                iFileID = (ds.Tables[0].Rows[0]["FileId"] == DBNull.Value || ds.Tables[0].Rows[0]["FileId"].ToString() == "") ? 0 : Convert.ToInt32(ds.Tables[0].Rows[0]["FileId"]);
            }
            else
            {
                iFileID = 0;
            }
        }
        else
        {
            iFileID = Request.QueryString["FileID"] == null ? 0 : Convert.ToInt32(Request.QueryString["FileID"]);
        }
        CheckPointFileStatusReq  req  = new CheckPointFileStatusReq();
        CheckPointFileStatusResp resp = new CheckPointFileStatusResp();

        try
        {
            ServiceManager sm = new ServiceManager();
            using (LP2ServiceClient service = sm.StartServiceClient())
            {
                req.FileId = iFileID;
                req.hdr    = new ReqHdr()
                {
                    UserId = loginUser.iUserID
                };

                resp = service.CheckPointFileStatus(req);

                if (resp == null || resp.hdr == null)
                {
                    Write(false, "Err : CheckPointFileStatusResp is NULL");
                    return;
                }
                if (resp.FileLocked)
                {
                    Write(false, resp.hdr.StatusInfo);
                }
                else
                {
                    Write(true, "");
                }
            }
        }
        catch (System.ServiceModel.EndpointNotFoundException)
        {
            string sExMsg = string.Format("Failed to sync data from Point. Reason: Point Manager is not running.");
            LPLog.LogMessage(LogType.Logerror, sExMsg);
            Write(false, sExMsg);
        }
        catch (Exception ex)
        {
            string sExMsg = string.Format("error: {0}", ex.Message);
            LPLog.LogMessage(LogType.Logerror, sExMsg);

            Write(false, sExMsg);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // json示例
        // {"ExecResult":"Success","ErrorMsg":""}
        // {"ExecResult":"Failed","ErrorMsg":"Failed to do sth."}

        #region 校验页面参数


        string sError_Lost    = "Lost required query string.";
        string sError_Invalid = "Invalid query string.";

        if (this.Request.QueryString["FileId"] == null)
        {
            this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sError_Lost + "\"}");
            this.Response.End();
        }
        string sFileId = this.Request.QueryString["FileId"];

        if (PageCommon.IsID(sFileId) == false)
        {
            this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sError_Invalid + "\"}");
            this.Response.End();
        }
        int iFileId = Convert.ToInt32(sFileId);

        #endregion

        #region Invoke WCF

        string sErrorMsg = string.Empty;

        CheckPointFileStatusReq  req  = new CheckPointFileStatusReq();
        CheckPointFileStatusResp resp = new CheckPointFileStatusResp();

        try
        {
            ServiceManager sm = new ServiceManager();
            using (LP2ServiceClient service = sm.StartServiceClient())
            {
                req.FileId = iFileId;
                req.hdr    = new ReqHdr()
                {
                    UserId = this.CurrUser.iUserID
                };

                resp = service.CheckPointFileStatus(req);

                if (resp == null || resp.hdr == null)
                {
                    this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"CheckPointFileStatusResp is NULL\"}");
                    return;
                }

                sErrorMsg = resp.hdr.StatusInfo;

                if (resp.hdr.Successful == true)
                {
                    if (resp.FileLocked == true)    // locked
                    {
                        this.Response.Write("{\"ExecResult\":\"Success\",\"ErrorMsg\":\"" + sErrorMsg + "\"}");
                        return;
                    }
                    else
                    {
                        this.Response.Write("{\"ExecResult\":\"Success\",\"ErrorMsg\":\"\"}");
                        return;
                    }
                }
                else
                {
                    sErrorMsg = "Point Manager Exception: Database login failed";
                    this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sErrorMsg + "\"}");
                    return;
                }
            }
        }
        catch (System.ServiceModel.EndpointNotFoundException)
        {
            sErrorMsg = string.Format("Exception: Point Manager is not running.");
            LPLog.LogMessage(LogType.Logerror, sErrorMsg);

            this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sErrorMsg + "\"}");
            return;
        }
        catch (Exception ex)
        {
            sErrorMsg = string.Format("error: {0}", ex.Message);
            LPLog.LogMessage(LogType.Logerror, sErrorMsg);
            sErrorMsg = "Point Manager Exception: Database timeout expired";

            this.Response.Write("{\"ExecResult\":\"Failed\",\"ErrorMsg\":\"" + sErrorMsg + "\"}");
            return;
        }

        #endregion
    }