Example #1
0
    /// <summary>
    /// 保存任务完成邮件模板关系
    /// </summary>
    /// <param name="iLoanTaskId"></param>
    public void SaveCompletetionEmails(int iLoanTaskId)
    {
        var tmp = hdnCompletionEmail.Value;


        LPWeb.BLL.LoanTask_CompletionEmails blltaskMail = new LoanTask_CompletionEmails();

        var        ds          = blltaskMail.GetList("LoanTaskid=" + iTaskID); //数据库中原有数据
        List <int> IdList      = ds.Tables[0].AsEnumerable().Select(c => c.Field <int>("TaskCompletionEmailId")).ToList();
        List <int> tmpIdList   = ds.Tables[0].AsEnumerable().Select(c => c.Field <int>("TemplEmailId")).ToList();
        var        oldDataList = ds.Tables[0].AsEnumerable().Select(c => new { Id = c.Field <int>("TaskCompletionEmailId"), tmpId = c.Field <int>("TemplEmailId") }).ToList();

        if (string.IsNullOrEmpty(tmp) && IdList.Count == 0)
        {
            return;
        }


        if (!string.IsNullOrEmpty(tmp))
        {
            var tmpList = tmp.Split('|').ToList();
            foreach (var item in tmpList)
            {
                var list = item.Split(',').ToList();

                if (list.Count == 3 && !string.IsNullOrEmpty(list[1]) && !string.IsNullOrEmpty(list[2]) &&
                    Convert.ToInt32(list[1]) != 0)
                {
                    int  Id           = Convert.ToInt32(list[0]);
                    int  templEmailId = Convert.ToInt32(list[1]);
                    bool enabled      = list[2] == "1" ? true : false;

                    var oldData = oldDataList.Where(c => c.tmpId == templEmailId).FirstOrDefault();
                    if (tmpIdList.Contains(templEmailId) && oldData != null & oldData.Id != Id)
                    {
                        continue;
                    }
                    else if (Id == 0)
                    {
                        LPWeb.Model.LoanTask_CompletionEmails modMail = new LPWeb.Model.LoanTask_CompletionEmails();

                        modMail.LoanTaskid   = iLoanTaskId;
                        modMail.TemplEmailId = templEmailId;
                        modMail.Enabled      = enabled;

                        blltaskMail.Add(modMail);
                        tmpIdList.Add(templEmailId);
                    }
                    else if (IdList.Where(c => c == Id).Count() > 0)
                    {
                        LPWeb.Model.LoanTask_CompletionEmails modMail = new LPWeb.Model.LoanTask_CompletionEmails();

                        modMail.TaskCompletionEmailId = Id;
                        modMail.LoanTaskid            = iLoanTaskId;
                        modMail.TemplEmailId          = templEmailId;
                        modMail.Enabled = enabled;

                        blltaskMail.Update(modMail);

                        IdList.Remove(Id);
                    }
                }
            }
        }

        //删除
        if (IdList.Count > 0)
        {
            var allDelId = string.Empty;
            foreach (var Id in IdList)
            {
                allDelId += "," + Id;
            }
            if (!string.IsNullOrEmpty(allDelId))
            {
                allDelId = allDelId.Remove(0, 1);
            }
            blltaskMail.DeleteList(allDelId);
        }
    }
Example #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string sErrorJs = "window.parent.CloseDialog_EditTask();";

        #region 检查必要参数

        bool bIsValid = PageCommon.ValidateQueryString(this, "LoanID", QueryStringType.ID);
        if (bIsValid == false)
        {
            PageCommon.RegisterJsMsg(this, "Missing required query string.", sErrorJs);
            return;
        }

        this.iLoanID = Convert.ToInt32(this.Request.QueryString["LoanID"]);

        bIsValid = PageCommon.ValidateQueryString(this, "TaskID", QueryStringType.ID);
        if (bIsValid == false)
        {
            PageCommon.RegisterJsMsg(this, "Missing required query string.", sErrorJs);
            return;
        }

        this.iTaskID = Convert.ToInt32(this.Request.QueryString["TaskID"]);

        #endregion

        // server now
        this.hdnNow.Value = DateTime.Now.ToString("MM/dd/yyyy");

        // task icon
        this.imgTaskIcon.ImageUrl = "../images/task/" + WorkflowManager.GetTaskIcon(this.iTaskID);

        #region 加载Loan Task信息

        this.LoanTaskInfo = this.LoanTaskManager.GetLoanTaskInfo(this.iTaskID);
        if (this.LoanTaskInfo.Rows.Count == 0)
        {
            PageCommon.RegisterJsMsg(this, "Invalid required query string.", sErrorJs);
            return;
        }

        #endregion

        #region 检查是否是Prerequisite(is a father?)

        bool bIsPrerequisite = this.LoanTaskManager.IsPrerequisite(this.iTaskID);
        this.hndIsPrerequisite.Value = bIsPrerequisite.ToString();

        #endregion

        #region 获取Borrower和Property信息

        #region Property

        DataTable LoanInfo = this.LoanManager.GetLoanInfo(this.iLoanID);
        if (LoanInfo.Rows.Count == 0)
        {
            PageCommon.RegisterJsMsg(this, "Invalid required query string.", sErrorJs);
            return;
        }
        string sPropertyAddress = LoanInfo.Rows[0]["PropertyAddr"].ToString();
        string sPropertyCity    = LoanInfo.Rows[0]["PropertyCity"].ToString();
        string sPropertyState   = LoanInfo.Rows[0]["PropertyState"].ToString();
        string sPropertyZip     = LoanInfo.Rows[0]["PropertyZip"].ToString();

        string sProperty = sPropertyAddress + ", " + sPropertyCity + ", " + sPropertyState + " " + sPropertyZip;

        // 存储Loan.EstCloseDate
        if (LoanInfo.Rows[0]["EstCloseDate"] != DBNull.Value)
        {
            this.hdnEstCloseDate.Value = Convert.ToDateTime(LoanInfo.Rows[0]["EstCloseDate"]).ToString("MM/dd/yyyy");
        }

        #endregion

        #region Borrower

        DataTable BorrowerInfo = this.LoanManager.GetBorrowerInfo(this.iLoanID);
        if (BorrowerInfo.Rows.Count == 0)
        {
            PageCommon.RegisterJsMsg(this, "There is no Borrower in this loan.", sErrorJs);
            return;
        }
        string sFirstName  = BorrowerInfo.Rows[0]["FirstName"].ToString();
        string sMiddleName = BorrowerInfo.Rows[0]["MiddleName"].ToString();
        string sLastName   = BorrowerInfo.Rows[0]["LastName"].ToString();

        string sBorrower = sLastName + ",  " + sFirstName;
        if (sMiddleName != string.Empty)
        {
            sBorrower += " " + sMiddleName;
        }

        this.lbProperty.Text = sProperty;
        this.lbBorrower.Text = sBorrower;

        #endregion

        #endregion

        if (this.IsPostBack == false)
        {
            #region 加载Stage

            DataTable LoanStages = this.LoanManager.GetLoanStages(this.iLoanID);

            this.ddlStage.DataSource = LoanStages;
            this.ddlStage.DataBind();

            this.ddlStage2.DataSource = LoanStages;
            this.ddlStage2.DataBind();

            #endregion

            #region 加载Owner

            DataTable OwnerList = this.LoanTaskManager.GetLoanTaskOwers(this.iLoanID);

            DataRow EmptyOwnerRow = OwnerList.NewRow();
            EmptyOwnerRow["UserID"]   = 0;
            EmptyOwnerRow["FullName"] = "-- select a task owner--";
            OwnerList.Rows.InsertAt(EmptyOwnerRow, 0);

            this.ddlOwner.DataSource = OwnerList;
            this.ddlOwner.DataBind();

            #endregion

            #region 加载Prerequisite

            // 先绑定Stage
            this.ddlStage.SelectedValue = this.LoanTaskInfo.Rows[0]["LoanStageId"].ToString();

            string sSelectedStageID = string.Empty;
            if (this.Request.QueryString["Stage"] == null)
            {
                sSelectedStageID = this.ddlStage.SelectedItem.Value;
            }
            else
            {
                sSelectedStageID = this.Request.QueryString["Stage"].ToString();
            }

            DataTable PrerequisiteList    = this.LoanTaskManager.GetPrerequisiteList(" and FileID=" + this.iLoanID + " and LoanStageId = " + sSelectedStageID + " and PrerequisiteTaskId is null and LoanTaskId !=" + iTaskID);
            DataRow   NonePrerequisiteRow = PrerequisiteList.NewRow();
            NonePrerequisiteRow["LoanTaskId"] = 0;
            NonePrerequisiteRow["Name"]       = "None";
            PrerequisiteList.Rows.InsertAt(NonePrerequisiteRow, 0);

            this.ddlPrerequisite.DataSource = PrerequisiteList;
            this.ddlPrerequisite.DataBind();

            this.ddlPrerequisite2.DataSource = PrerequisiteList;
            this.ddlPrerequisite2.DataBind();

            #endregion

            #region 加载email template

            Template_Email EmailTempManager = new Template_Email();
            EmailTemplates = EmailTempManager.GetEmailTemplate(" and Enabled = 1");

            DataRow NoneEmailTemplateRow = EmailTemplates.NewRow();
            NoneEmailTemplateRow["TemplEmailId"] = 0;
            NoneEmailTemplateRow["Name"]         = "None";
            EmailTemplates.Rows.InsertAt(NoneEmailTemplateRow, 0);

            this.ddlCompletionEmail.DataSource = EmailTemplates;
            this.ddlCompletionEmail.DataBind();

            this.ddlWarningEmail.DataSource = EmailTemplates;
            this.ddlWarningEmail.DataBind();

            this.ddlOverdueEmail.DataSource = EmailTemplates;
            this.ddlOverdueEmail.DataBind();


            this.ddlEmailTemplate.DataSource = EmailTemplates;
            this.ddlEmailTemplate.DataBind();

            #endregion

            #region 绑定对应模板列表

            LPWeb.BLL.LoanTask_CompletionEmails bllTaskMail = new LoanTask_CompletionEmails();

            gridCompletetionEmails.DataSource = bllTaskMail.GetList("LoanTaskid=" + iTaskID);
            gridCompletetionEmails.DataBind();

            #endregion

            #region Bind Data

            this.txtTaskName.Text = this.LoanTaskInfo.Rows[0]["Name"].ToString();


            #region Owner

            string sOwnerID = this.LoanTaskInfo.Rows[0]["Owner"].ToString();
            if (sOwnerID == string.Empty)
            {
                this.ddlOwner.SelectedIndex = 0;
            }
            else
            {
                this.ddlOwner.SelectedValue = sOwnerID;
            }

            #endregion

            #region ExternalViewing

            if (this.LoanTaskInfo.Rows[0]["ExternalViewing"] != null && this.LoanTaskInfo.Rows[0]["ExternalViewing"].ToString() != "")
            {
                bool ExternalViewing = Convert.ToBoolean(this.LoanTaskInfo.Rows[0]["ExternalViewing"]);

                this.chbExternalViewing.Checked = ExternalViewing;
            }

            #endregion


            #region Due Date

            string sDueDate = this.LoanTaskInfo.Rows[0]["Due"].ToString();
            if (sDueDate != string.Empty)
            {
                this.txtDueDate.Text = Convert.ToDateTime(this.LoanTaskInfo.Rows[0]["Due"]).ToString("MM/dd/yyyy");
            }

            #endregion

            //#region Completed Date

            string sCompletedDate = this.LoanTaskInfo.Rows[0]["Completed"].ToString();
            if (sCompletedDate != string.Empty)
            {
                this.hdnCompleted.Value = Convert.ToDateTime(this.LoanTaskInfo.Rows[0]["Completed"]).ToString("MM/dd/yyyy");
            }

            //#endregion

            this.txtDaysToEst.Text         = this.LoanTaskInfo.Rows[0]["DaysDueFromEstClose"] == DBNull.Value ? string.Empty : this.LoanTaskInfo.Rows[0]["DaysDueFromEstClose"].ToString();
            this.txtDaysAfterCreation.Text = this.LoanTaskInfo.Rows[0]["DaysFromCreation"] == DBNull.Value ? string.Empty : this.LoanTaskInfo.Rows[0]["DaysFromCreation"].ToString();

            this.txtDaysDueAfterPrevStage.Text = this.LoanTaskInfo.Rows[0]["DaysDueAfterPrevStage"] == DBNull.Value ? string.Empty : this.LoanTaskInfo.Rows[0]["DaysDueAfterPrevStage"].ToString();


            //Get task template Calculation Method
            if (this.LoanTaskInfo.Rows[0]["TemplTaskId"].ToString() != "" && this.LoanTaskInfo.Rows[0]["TemplTaskId"].ToString() != "0")
            {
                LPWeb.BLL.Template_Wfl_Tasks   taskTempMgr   = new Template_Wfl_Tasks();
                LPWeb.Model.Template_Wfl_Tasks taskTempModel = taskTempMgr.GetModel(int.Parse(this.LoanTaskInfo.Rows[0]["TemplTaskId"].ToString()));
                int iCalculationMethod = 0;
                if (taskTempModel != null)
                {
                    LPWeb.BLL.Template_Wfl_Stages   stageWflMgr = new Template_Wfl_Stages();
                    LPWeb.Model.Template_Wfl_Stages stageModel  = stageWflMgr.GetModel(taskTempModel.WflStageId);
                    if (stageModel != null)
                    {
                        LPWeb.BLL.Template_Workflow   templateMgr   = new Template_Workflow();
                        LPWeb.Model.Template_Workflow templateModel = templateMgr.GetModel(stageModel.WflTemplId);
                        if (templateModel != null)
                        {
                            iCalculationMethod = templateModel.CalculationMethod;
                        }

                        if (stageModel.CalculationMethod != null && stageModel.CalculationMethod.Value != 0)
                        {
                            iCalculationMethod = stageModel.CalculationMethod.Value;
                        }
                    }
                }

                if (iCalculationMethod == 1 && this.txtDaysAfterCreation.Text == "")
                {
                    this.txtDaysToEst.Enabled         = true;
                    this.txtDaysAfterCreation.Enabled = false;
                }
                else if (iCalculationMethod == 2 && this.txtDaysToEst.Text == "")
                {
                    this.txtDaysToEst.Enabled         = false;
                    this.txtDaysAfterCreation.Enabled = true;
                }
            }
            #region Prerequisite Task Id

            string sPrerequisiteTaskId = this.LoanTaskInfo.Rows[0]["PrerequisiteTaskId"] == DBNull.Value ? string.Empty : this.LoanTaskInfo.Rows[0]["PrerequisiteTaskId"].ToString();
            if (sPrerequisiteTaskId == string.Empty)
            {
                this.ddlPrerequisite.SelectedIndex = 0;
            }
            else
            {
                this.ddlPrerequisite.SelectedValue = sPrerequisiteTaskId;
            }

            #endregion

            this.txtDaysDueAfter.Text = LoanTaskInfo.Rows[0]["DaysDueAfterPrerequisite"] == DBNull.Value ? string.Empty : this.LoanTaskInfo.Rows[0]["DaysDueAfterPrerequisite"].ToString();

            #region Completion Email

            string sCompletionEmailID = this.LoanTaskInfo.Rows[0]["CompletionEmailId"].ToString();
            if (sCompletionEmailID == string.Empty)
            {
                this.ddlCompletionEmail.SelectedIndex = 0;
            }
            else
            {
                this.ddlCompletionEmail.SelectedValue = sCompletionEmailID;
            }

            #endregion

            #region Warning Email

            string sWarningEmailId = this.LoanTaskInfo.Rows[0]["WarningEmailId"].ToString();
            if (sWarningEmailId == string.Empty)
            {
                this.ddlWarningEmail.SelectedIndex = 0;
            }
            else
            {
                this.ddlWarningEmail.SelectedValue = sWarningEmailId;
            }

            #endregion

            #region Overdue Email

            string sOverdueEmailId = this.LoanTaskInfo.Rows[0]["OverdueEmailId"].ToString();
            if (sOverdueEmailId == string.Empty)
            {
                this.ddlOverdueEmail.SelectedIndex = 0;
            }
            else
            {
                this.ddlOverdueEmail.SelectedValue = sOverdueEmailId;
            }

            #endregion

            #endregion
        }
    }
Example #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 检查必要参数

        string sErrorJs = string.Empty;
        if (this.Request.QueryString["CloseDialogCodes"] == null)
        {
            sErrorJs = "window.parent.RefreshPage();";
        }
        else
        {
            sErrorJs = this.Request.QueryString["CloseDialogCodes"] + ";";
        }

        bool bIsValid = PageCommon.ValidateQueryString(this, "LoanID", QueryStringType.ID);
        if (bIsValid == false)
        {
            PageCommon.RegisterJsMsg(this, "Missing required query string.", sErrorJs);
            return;
        }

        this.iLoanID = Convert.ToInt32(this.Request.QueryString["LoanID"]);

        bIsValid = PageCommon.ValidateQueryString(this, "TaskID", QueryStringType.ID);
        if (bIsValid == false)
        {
            PageCommon.RegisterJsMsg(this, "Missing required query string.", sErrorJs);
            return;
        }

        this.iTaskID = Convert.ToInt32(this.Request.QueryString["TaskID"]);

        #endregion

        #region 加载Loan Task信息

        this.LoanTaskInfo = this.LoanTaskManager.GetLoanTaskInfo(this.iTaskID);
        if (this.LoanTaskInfo.Rows.Count == 0)
        {
            PageCommon.RegisterJsMsg(this, "Invalid required query string.", sErrorJs);
            return;
        }

        #endregion

        #region 检查是否是Prerequisite(is a father?)

        bool bIsPrerequisite = this.LoanTaskManager.IsPrerequisite(this.iTaskID);
        this.hndIsPrerequisite.Value = bIsPrerequisite.ToString();

        #endregion

        #region 加载LoanInfo信息

        DataTable LoanInfo = this.LoanManager.GetLoanInfo(this.iLoanID);
        if (LoanInfo.Rows.Count == 0)
        {
            PageCommon.RegisterJsMsg(this, "Invalid required query string.", sErrorJs);
            return;
        }

        // 存储Loan.EstCloseDate
        if (LoanInfo.Rows[0]["EstCloseDate"] != DBNull.Value)
        {
            this.hdnEstCloseDate.Value = Convert.ToDateTime(LoanInfo.Rows[0]["EstCloseDate"]).ToString("MM/dd/yyyy");
        }

        #endregion



        if (this.IsPostBack == false)
        {
            #region 加载Owner

            DataTable OwnerList = this.LoanTaskManager.GetLoanTaskOwers(this.iLoanID);

            DataRow EmptyOwnerRow = OwnerList.NewRow();
            EmptyOwnerRow["UserID"]   = 0;
            EmptyOwnerRow["FullName"] = "-- select --";
            OwnerList.Rows.InsertAt(EmptyOwnerRow, 0);

            this.ddlOwner.DataSource = OwnerList;
            this.ddlOwner.DataBind();

            // 绑定Owner
            this.ddlOwner.SelectedValue = this.CurrUser.iUserID.ToString();

            #endregion

            #region 加载ddlTaskList for TaskNaem

            LeadTaskList LeadTaskListMgr = new LeadTaskList();

            string sOrderBy = string.Empty;
            if (this.CurrUser.SortTaskPickList == "S")
            {
                sOrderBy = "SequenceNumber";
            }
            else
            {
                sOrderBy = "TaskName";
            }

            DataTable LeadTaskList1 = LeadTaskListMgr.GetLeadTaskList(" and Enabled=1", sOrderBy);

            DataRow EmptyTaskRow = LeadTaskList1.NewRow();
            EmptyTaskRow["TaskName"] = "-- select --";
            LeadTaskList1.Rows.InsertAt(EmptyTaskRow, 0);

            this.ddlTaskList.DataSource = LeadTaskList1;
            this.ddlTaskList.DataBind();

            #endregion

            #region 加载Prerequisite

            int iCurrentLoanStageId = Convert.ToInt32(this.LoanTaskInfo.Rows[0]["LoanStageId"]);

            DataTable PrerequisiteList    = this.LoanTaskManager.GetPrerequisiteList(" and FileID=" + this.iLoanID + " and LoanStageId = " + iCurrentLoanStageId + " and PrerequisiteTaskId is null");
            DataRow   NonePrerequisiteRow = PrerequisiteList.NewRow();
            NonePrerequisiteRow["LoanTaskId"] = 0;
            NonePrerequisiteRow["Name"]       = "None";
            PrerequisiteList.Rows.InsertAt(NonePrerequisiteRow, 0);

            this.ddlPrerequisite.DataSource = PrerequisiteList;
            this.ddlPrerequisite.DataBind();

            this.ddlPrerequisite2.DataSource = PrerequisiteList;
            this.ddlPrerequisite2.DataBind();

            #endregion

            #region 加载email template

            Template_Email EmailTempManager = new Template_Email();
            this.EmailTemplates = EmailTempManager.GetEmailTemplate(" and Enabled = 1");

            DataRow NoneEmailTemplateRow = this.EmailTemplates.NewRow();
            NoneEmailTemplateRow["TemplEmailId"] = 0;
            NoneEmailTemplateRow["Name"]         = "None";
            this.EmailTemplates.Rows.InsertAt(NoneEmailTemplateRow, 0);

            this.ddlWarningEmail.DataSource = this.EmailTemplates;
            this.ddlWarningEmail.DataBind();

            this.ddlOverdueEmail.DataSource = this.EmailTemplates;
            this.ddlOverdueEmail.DataBind();

            this.ddlEmailTemplate.DataSource = this.EmailTemplates;
            this.ddlEmailTemplate.DataBind();

            #endregion

            #region completion email list

            LPWeb.BLL.LoanTask_CompletionEmails bllTaskMail = new LoanTask_CompletionEmails();

            gridCompletetionEmails.DataSource = bllTaskMail.GetList("LoanTaskid=" + iTaskID);
            gridCompletetionEmails.DataBind();

            #endregion

            #region Stage

            //Template_Stages stage = new Template_Stages();
            //var dtStage = stage.GetStageTemplateList(" And [Enabled] = 1 order by  SequenceNumber ");

            LoanStages ls      = new LoanStages();
            var        dtStage = ls.GetLoanStageSetupInfo(iLoanID);

            ddlStage.DataSource = dtStage;
            ddlStage.DataBind();


            #endregion

            #region Bind Data

            ddlStage.SelectedValue = this.LoanTaskInfo.Rows[0]["LoanStageId"].ToString();

            this.radTaskName.Checked = true;
            this.txtTaskName.Text    = this.LoanTaskInfo.Rows[0]["Name"].ToString();
            this.txtDescription.Text = this.LoanTaskInfo.Rows[0]["Desc"].ToString();

            #region Owner

            string sOwnerID = this.LoanTaskInfo.Rows[0]["Owner"].ToString();
            if (sOwnerID == string.Empty)
            {
                this.ddlOwner.SelectedIndex = 0;
            }
            else
            {
                this.ddlOwner.SelectedValue = sOwnerID;
            }

            #endregion

            #region Due Date

            string sDueDate = this.LoanTaskInfo.Rows[0]["Due"].ToString();
            if (sDueDate != string.Empty)
            {
                this.txtDueDate.Text = Convert.ToDateTime(this.LoanTaskInfo.Rows[0]["Due"]).ToString("MM/dd/yyyy");
            }

            string sDueTime = this.LoanTaskInfo.Rows[0]["DueTime"].ToString();
            if (sDueTime != string.Empty)
            {
                TimeSpan DueTime = TimeSpan.Parse(this.LoanTaskInfo.Rows[0]["DueTime"].ToString());
                this.txtDueTime.Text = DueTime.ToString().Substring(0, 5);

                ddlDueTime_hour.SelectedValue = DueTime.Hours.ToString();
                ddlDueTime_min.SelectedValue  = ((DueTime.Minutes / 5) * 5).ToString();
            }

            #endregion

            //#region Completed Date

            string sCompletedDate = this.LoanTaskInfo.Rows[0]["Completed"].ToString();
            if (sCompletedDate != string.Empty)
            {
                this.chkCompleted.Checked  = true;
                this.txtCompletedDate.Text = Convert.ToDateTime(this.LoanTaskInfo.Rows[0]["Completed"]).ToString("MM/dd/yyyy");
                this.hdnCompleted.Value    = Convert.ToDateTime(this.LoanTaskInfo.Rows[0]["Completed"]).ToString("MM/dd/yyyy");
            }

            //#endregion

            this.txtDaysToEst.Text         = this.LoanTaskInfo.Rows[0]["DaysDueFromEstClose"] == DBNull.Value ? string.Empty : this.LoanTaskInfo.Rows[0]["DaysDueFromEstClose"].ToString();
            this.txtDaysAfterCreation.Text = this.LoanTaskInfo.Rows[0]["DaysFromCreation"] == DBNull.Value ? string.Empty : this.LoanTaskInfo.Rows[0]["DaysFromCreation"].ToString();

            this.txtDaysDueAfterPrevStage.Text = this.LoanTaskInfo.Rows[0]["DaysDueAfterPrevStage"] == DBNull.Value ? string.Empty : this.LoanTaskInfo.Rows[0]["DaysDueAfterPrevStage"].ToString();

            #region Prerequisite Task Id

            string sPrerequisiteTaskId = this.LoanTaskInfo.Rows[0]["PrerequisiteTaskId"] == DBNull.Value ? string.Empty : this.LoanTaskInfo.Rows[0]["PrerequisiteTaskId"].ToString();
            if (sPrerequisiteTaskId == string.Empty)
            {
                this.ddlPrerequisite.SelectedIndex = 0;
            }
            else
            {
                this.ddlPrerequisite.SelectedValue = sPrerequisiteTaskId;
            }

            #endregion

            this.txtDaysDueAfter.Text = LoanTaskInfo.Rows[0]["DaysDueAfterPrerequisite"] == DBNull.Value ? string.Empty : this.LoanTaskInfo.Rows[0]["DaysDueAfterPrerequisite"].ToString();



            #region Warning Email

            string sWarningEmailId = this.LoanTaskInfo.Rows[0]["WarningEmailId"].ToString();
            if (sWarningEmailId == string.Empty)
            {
                this.ddlWarningEmail.SelectedIndex = 0;
            }
            else
            {
                this.ddlWarningEmail.SelectedValue = sWarningEmailId;
            }

            #endregion

            #region Overdue Email

            string sOverdueEmailId = this.LoanTaskInfo.Rows[0]["OverdueEmailId"].ToString();
            if (sOverdueEmailId == string.Empty)
            {
                this.ddlOverdueEmail.SelectedIndex = 0;
            }
            else
            {
                this.ddlOverdueEmail.SelectedValue = sOverdueEmailId;
            }

            #endregion

            #endregion
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 校验页面参数

        string sErrorJs = "$('#divContainer').hide();alert('Missing required query string.');window.parent.CloseDialog_SendCompletionEmail();";
        bool   bIsValid = PageCommon.ValidateQueryString(this, "LoanID", QueryStringType.ID);
        if (bIsValid == false)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "_InvalidQuery1", sErrorJs, true);
            return;
        }
        this.iLoanID = Convert.ToInt32(this.Request.QueryString["LoanID"]);

        bIsValid = PageCommon.ValidateQueryString(this, "EmailTemplateID", QueryStringType.ID);
        if (bIsValid == false)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "_InvalidQuery2", sErrorJs, true);
            return;
        }
        this.iEmailTemplateID = Convert.ToInt32(this.Request.QueryString["EmailTemplateID"]);
        string sTaskID = "";
        sTaskID = this.Request.QueryString["TaskID"];
        if ((sTaskID != null) && (sTaskID != ""))
        {
            this.iTaskID = Convert.ToInt32(sTaskID);
        }

        #endregion

        #region EWS

        Company_Web             CompanyWebManager = new Company_Web();
        LPWeb.Model.Company_Web Company_Web_Model = CompanyWebManager.GetModel();

        Users             UserManager = new Users();
        LPWeb.Model.Users UserModel   = UserManager.GetModel(this.CurrUser.iUserID);

        if (Company_Web_Model.SendEmailViaEWS && UserModel.Password == string.Empty)
        {
            this.hdnUseEWS.Value = "True";
        }
        else
        {
            this.hdnUseEWS.Value = "False";
        }

        #endregion

        #region 旧代码

        //#region 加载email template info

        //Template_Email EmailTempManager = new Template_Email();
        //DataTable EmailTemplateInfo = EmailTempManager.GetEmailTemplateInfo(this.iEmailTemplateID);

        //if (EmailTemplateInfo.Rows.Count == 0)
        //{
        //    this.ClientScript.RegisterStartupScript(this.GetType(), "_InvalidQuery3", "$('#divContainer').hide();alert('The email template does not exist.');window.parent.CloseDialog_SendCompletionEmail();", true);
        //    return;
        //}

        //string sEmailTemplate = EmailTemplateInfo.Rows[0]["Name"].ToString();
        //this.lbEmailTemplate.Text = sEmailTemplate;

        //string sFromUserRoleID = EmailTemplateInfo.Rows[0]["FromUserRoles"].ToString();
        //if (sFromUserRoleID != string.Empty)
        //{
        //    #region 获取Loan Team和Users信息

        //    string sSql = "select * from LoanTeam as a inner join Users as b on a.UserId = b.UserId where a.FileId=" + this.iLoanID + " and a.RoleId=" + sFromUserRoleID;
        //    DataTable SenderInfo = LPWeb.DAL.DbHelperSQL.ExecuteDataTable(sSql);

        //    if (SenderInfo.Rows.Count == 0)
        //    {
        //        this.lbSender.Text = "There is no sender, so can't send email.";
        //        this.lbSender.ForeColor = System.Drawing.Color.Red;
        //    }
        //    else
        //    {
        //        string sFirstName = SenderInfo.Rows[0]["FirstName"].ToString();
        //        string sLastName = SenderInfo.Rows[0]["LastName"].ToString();
        //        string sFullName = sLastName + ", " + sFirstName;
        //        this.lbSender.Text = sFullName;
        //    }

        //    #endregion
        //}
        //else
        //{
        //    string sFromEmailAddress = EmailTemplateInfo.Rows[0]["FromEmailAddress"].ToString();
        //    if (sFromEmailAddress != string.Empty)
        //    {
        //        this.lbSender.Text = sFromEmailAddress;
        //    }
        //    else
        //    {
        //        this.lbSender.Text = "There is no sender.";
        //        this.lbSender.ForeColor = System.Drawing.Color.Red;
        //    }
        //}

        //#endregion

        //if (this.IsPostBack == false)
        //{
        //    #region 加载Recipient列表

        //    #region 获取Email Template的Recipient(s)

        //    Template_Email EmailTemplateManager = new Template_Email();
        //    DataTable RecipientList = EmailTemplateManager.GetRecipientList(this.iEmailTemplateID);

        //    #endregion

        //    #region 获取Loan Team

        //    string sSql = "select * from LoanTeam as a inner join Users as b on a.UserId = b.UserId where a.FileId=" + this.iLoanID;
        //    DataTable LoanTeamList = LPWeb.DAL.DbHelperSQL.ExecuteDataTable(sSql);

        //    #endregion

        //    #region 获取Contacts

        //    string sSql2 = "select * from LoanContacts as a inner join Contacts as b on a.ContactId = b.ContactId where a.FileId=" + this.iLoanID;
        //    DataTable ContactList = LPWeb.DAL.DbHelperSQL.ExecuteDataTable(sSql2);

        //    #endregion

        //    DataTable RecipientListData = this.BuildRecipientDataTable();

        //    #region To

        //    DataRow[] ToRecipient = RecipientList.Select("RecipientType='To'");
        //    if (ToRecipient.Length > 0)
        //    {
        //        string sEmailList_To = ToRecipient[0]["EmailAddr"].ToString();
        //        string sContactList_To = ToRecipient[0]["ContactRoles"].ToString();
        //        string sUserRoleList_To = ToRecipient[0]["UserRoles"].ToString();
        //        string sTaskOwner = ToRecipient[0]["TaskOwner"].ToString();

        //        #region Emails

        //        if (sEmailList_To != string.Empty)
        //        {
        //            string[] EmailArray_To = sEmailList_To.Split(';');
        //            foreach (string sEmailTo in EmailArray_To)
        //            {
        //                this.AddNewRecipientRow(RecipientListData, "To", string.Empty, sEmailTo);
        //            }
        //        }

        //        #endregion

        //        #region User IDs

        //        if (sUserRoleList_To != string.Empty)
        //        {
        //            string[] UserRoleArray_To = sUserRoleList_To.Split(';');
        //            foreach (string sUserRoleIDTo in UserRoleArray_To)
        //            {
        //                int iUserRoleIDTo = Convert.ToInt32(sUserRoleIDTo);

        //                DataRow[] LoanTeamRows = LoanTeamList.Select("RoleId=" + iUserRoleIDTo);
        //                foreach (DataRow LoanTeamRow in LoanTeamRows)
        //                {
        //                    string sFullName = LoanTeamRow["LastName"].ToString() + ", " + LoanTeamRow["FirstName"].ToString();
        //                    string sEmailAddress = LoanTeamRow["EmailAddress"].ToString();
        //                    if (sEmailAddress == string.Empty)
        //                    {
        //                        this.AddNewRecipientRow(RecipientListData, "To", sFullName, "There is no emaill address in the user account.");
        //                    }
        //                    else
        //                    {
        //                        this.AddNewRecipientRow(RecipientListData, "To", sFullName, sEmailAddress);
        //                    }
        //                }
        //            }
        //        }

        //        #endregion

        //        #region Contact IDs

        //        if (sContactList_To != string.Empty)
        //        {
        //            string[] ContactArray_To = sContactList_To.Split(';');
        //            foreach (string sContactIDTo in ContactArray_To)
        //            {
        //                int iContactRoleIDTo = Convert.ToInt32(sContactIDTo);

        //                DataRow[] ContactRows = ContactList.Select("ContactRoleId=" + iContactRoleIDTo);
        //                foreach (DataRow ContactRow in ContactRows)
        //                {
        //                    #region Build FullName

        //                    string sFirstName = ContactRow["FirstName"].ToString();
        //                    string sLastName = ContactRow["LastName"].ToString();
        //                    string sMiddleName = ContactRow["MiddleName"].ToString();

        //                    string sFullName = string.Empty;
        //                    if (sMiddleName != string.Empty)
        //                    {
        //                        sFullName = sLastName + ", " + sFirstName + " " + sMiddleName;
        //                    }
        //                    else
        //                    {
        //                        sFullName = sLastName + ", " + sFirstName;
        //                    }

        //                    #endregion

        //                    string sEmailAddress = ContactRow["Email"].ToString();

        //                    if (sEmailAddress == string.Empty)
        //                    {
        //                        this.AddNewRecipientRow(RecipientListData, "To", sFullName, "There is no emaill address in the contact account.");
        //                    }
        //                    else
        //                    {
        //                        this.AddNewRecipientRow(RecipientListData, "To", sFullName, sEmailAddress);
        //                    }
        //                }
        //            }
        //        }

        //        #endregion

        //        #region TaskOwner

        //        if ((sTaskOwner != string.Empty) && (sTaskOwner != null))
        //        {
        //            if (sTaskOwner == "True")
        //            {
        //                string sSql_LoanTasks = "select Owner from LoanTasks where LoanTaskId=" + this.iTaskID;
        //                DataTable LoanTasks_List = LPWeb.DAL.DbHelperSQL.ExecuteDataTable(sSql_LoanTasks);

        //                string sOwnerId = LoanTasks_List.Rows[0]["Owner"].ToString();

        //                if ((sTaskOwner != string.Empty) && (sTaskOwner != null))
        //                {
        //                    int iOwnerId = Convert.ToInt32(sOwnerId);
        //                    string sSql_Users = "select EmailAddress, LastName, FirstName from Users where UserId=" + iOwnerId;
        //                    DataTable Users_List = LPWeb.DAL.DbHelperSQL.ExecuteDataTable(sSql_Users);
        //                    string Owner_EmailAddress = Users_List.Rows[0]["EmailAddress"].ToString();
        //                    if ((Owner_EmailAddress != string.Empty) && (Owner_EmailAddress != null))
        //                    {
        //                        string sOwnerFullName = Users_List.Rows[0]["LastName"].ToString() + ", " + Users_List.Rows[0]["FirstName"].ToString();
        //                        this.AddNewRecipientRow(RecipientListData, "To", sOwnerFullName, Owner_EmailAddress);
        //                    }
        //                }
        //            }
        //        }

        //        #endregion
        //    }

        //    #endregion

        //    #region CC

        //    DataRow[] CCRecipient = RecipientList.Select("RecipientType='CC'");
        //    if (CCRecipient.Length > 0)
        //    {
        //        string sEmailList_CC = CCRecipient[0]["EmailAddr"].ToString();
        //        string sContactList_CC = CCRecipient[0]["ContactRoles"].ToString();
        //        string sUserRoleList_CC = CCRecipient[0]["UserRoles"].ToString();

        //        #region Emails

        //        if (sEmailList_CC != string.Empty)
        //        {
        //            string[] EmailArray_CC = sEmailList_CC.Split(';');
        //            foreach (string sEmailCC in EmailArray_CC)
        //            {
        //                this.AddNewRecipientRow(RecipientListData, "CC", string.Empty, sEmailCC);
        //            }
        //        }

        //        #endregion

        //        #region User IDs

        //        if (sUserRoleList_CC != string.Empty)
        //        {
        //            string[] UserRoleArray_CC = sUserRoleList_CC.Split(';');
        //            foreach (string sUserRoleIDCC in UserRoleArray_CC)
        //            {
        //                int iUserRoleIDCC = Convert.ToInt32(sUserRoleIDCC);

        //                DataRow[] LoanTeamRows = LoanTeamList.Select("RoleId=" + iUserRoleIDCC);
        //                foreach (DataRow LoanTeamRow in LoanTeamRows)
        //                {
        //                    string sFullName = LoanTeamRow["LastName"].ToString() + ", " + LoanTeamRow["FirstName"].ToString();
        //                    string sEmailAddress = LoanTeamRow["EmailAddress"].ToString();

        //                    if (sEmailAddress == string.Empty)
        //                    {
        //                        this.AddNewRecipientRow(RecipientListData, "CC", sFullName, "There is no emaill address in the user account.");
        //                    }
        //                    else
        //                    {
        //                        this.AddNewRecipientRow(RecipientListData, "CC", sFullName, sEmailAddress);
        //                    }
        //                }
        //            }
        //        }

        //        #endregion

        //        #region Contact IDs

        //        if (sContactList_CC != string.Empty)
        //        {
        //            string[] ContactArray_CC = sContactList_CC.Split(';');
        //            foreach (string sContactIDCC in ContactArray_CC)
        //            {
        //                int iContactRoleIDCC = Convert.ToInt32(sContactIDCC);

        //                DataRow[] ContactRows = ContactList.Select("ContactRoleId=" + iContactRoleIDCC);
        //                foreach (DataRow ContactRow in ContactRows)
        //                {
        //                    #region Build FullName

        //                    string sFirstName = ContactRow["FirstName"].ToString();
        //                    string sLastName = ContactRow["LastName"].ToString();
        //                    string sMiddleName = ContactRow["MiddleName"].ToString();

        //                    string sFullName = string.Empty;
        //                    if (sMiddleName != string.Empty)
        //                    {
        //                        sFullName = sLastName + ", " + sFirstName + " " + sMiddleName;
        //                    }
        //                    else
        //                    {
        //                        sFullName = sLastName + ", " + sFirstName;
        //                    }

        //                    #endregion

        //                    string sEmailAddress = ContactRow["Email"].ToString();

        //                    if (sEmailAddress == string.Empty)
        //                    {
        //                        this.AddNewRecipientRow(RecipientListData, "CC", sFullName, "There is no emaill address in the contact account.");
        //                    }
        //                    else
        //                    {
        //                        this.AddNewRecipientRow(RecipientListData, "CC", sFullName, sEmailAddress);
        //                    }
        //                }
        //            }
        //        }

        //        #endregion
        //    }

        //    #endregion

        //    this.gridRecipientList.DataSource = RecipientListData;
        //    this.gridRecipientList.DataBind();

        //    #endregion
        //}

        #endregion
        #region 新页面信息绑定 Borrower/Task/EmailTemplate

        #region 加载Borrower Info

        string    sSql5        = "select * from LoanContacts as b1 inner join Contacts as b2 on b1.ContactId = b2.ContactId where b1.FileId=" + this.iLoanID + "  and b1.ContactRoleId=dbo.lpfn_GetBorrowerRoleId() ";
        DataTable BorrowerInfo = LPWeb.DAL.DbHelperSQL.ExecuteDataTable(sSql5);

        #endregion

        #region 绑定Borrower信息
        this.lbBorrower.Text = "";
        if (BorrowerInfo.Rows.Count > 0)
        {
            string sBorrowerLastName   = BorrowerInfo.Rows[0]["LastName"].ToString();
            string sBorrowerFristName  = BorrowerInfo.Rows[0]["FirstName"].ToString();
            string sBorrowerMiddleName = BorrowerInfo.Rows[0]["MiddleName"].ToString();

            StringBuilder sbBorrowerName = new StringBuilder();
            sbBorrowerName.Append(sBorrowerLastName);
            if (sBorrowerFristName != string.Empty)
            {
                sbBorrowerName.Append(", " + sBorrowerFristName);
            }
            if (sBorrowerMiddleName != string.Empty)
            {
                sbBorrowerName.Append(" " + sBorrowerMiddleName);
            }

            this.lbBorrower.Text = sbBorrowerName.ToString();
        }
        #endregion

        #region 加载Task Info

        string    sSql6    = "SELECT [Name] FROM [LoanTasks] WHERE LoanTaskId=" + this.iTaskID;
        DataTable TaskInfo = LPWeb.DAL.DbHelperSQL.ExecuteDataTable(sSql6);

        #endregion

        #region 绑定Task Info信息
        this.lbTask.Text = "";
        if (TaskInfo.Rows.Count > 0)
        {
            string taskName = TaskInfo.Rows[0]["Name"].ToString();

            this.lbTask.Text = taskName;
        }
        #endregion


        #region 加载email template

        Template_Email EmailTempManager = new Template_Email();
        EmailTemplates = EmailTempManager.GetEmailTemplate(" and Enabled = 1");

        DataRow NoneEmailTemplateRow = EmailTemplates.NewRow();
        NoneEmailTemplateRow["TemplEmailId"] = 0;
        NoneEmailTemplateRow["Name"]         = "None";
        EmailTemplates.Rows.InsertAt(NoneEmailTemplateRow, 0);
        #endregion

        #region 加载 任务邮件模板 并绑定


        LPWeb.BLL.LoanTask_CompletionEmails bllLT_com_Emails = new LoanTask_CompletionEmails();

        var ltceDS = bllLT_com_Emails.GetList("[Enabled]=1 AND LoanTaskid=" + this.iTaskID);

        gridCompletetionEmails.DataSource = ltceDS;//new List<string>(){"t1","t2"};
        gridCompletetionEmails.DataBind();

        #endregion


        #endregion
    }