protected void btnClone_Click(object sender, EventArgs e) { Mode = "0"; // get contactId for clone Model.ProspectTasks pt = ptManager.GetModel(ProspectTaskId.Value); ContactId = pt.ContactId; this.btnDelete.Enabled = false; this.btnClone.Enabled = false; this.btnSave.Enabled = true; this.tbTaskName.Text = string.Format("Copy of {0}", this.tbTaskName.Text); }
/// <summary> /// Load prospect task info from the form /// </summary> /// <param name="user"></param> /// <returns></returns> private void GetValue(ref Model.ProspectTasks item) { int nTemp = 0; item.TaskName = this.tbTaskName.Text; item.Enabled = this.ckbEnabled.Checked; item.Desc = this.tbDesc.Text; if (ContactId.HasValue) item.ContactId = ContactId.Value; // set prospect if (!int.TryParse(this.ddlOwner.SelectedValue, out nTemp)) nTemp = 0; if (0 != nTemp) item.OwnerId = nTemp; DateTime dtTemp = DateTime.MinValue; if (!DateTime.TryParse(this.tbDue.Text, out dtTemp)) dtTemp = DateTime.MinValue; if (DateTime.MinValue != dtTemp) item.Due = dtTemp; if (!int.TryParse(this.ddlWarningEmail.SelectedValue, out nTemp)) nTemp = 0; if (0 != nTemp) item.WarningEmailTemplId = nTemp; if (!int.TryParse(this.ddlOverdueEmail.SelectedValue, out nTemp)) nTemp = 0; if (0 != nTemp) item.OverdueEmailTemplId = nTemp; if (!int.TryParse(this.ddlComleEmail.SelectedValue, out nTemp)) nTemp = 0; if (0 != nTemp) item.CompletionEmailTemplid = nTemp; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.btnPreWarn.OnClientClick = string.Format("return previewEmailTemplate('{0}');", this.ddlWarningEmail.ClientID); this.btnPreOverdue.OnClientClick = string.Format("return previewEmailTemplate('{0}');", this.ddlOverdueEmail.ClientID); this.btnPreComple.OnClientClick = string.Format("return previewEmailTemplate('{0}');", this.ddlComleEmail.ClientID); // bind email template BLL.Template_Email emailTpltManager = new BLL.Template_Email(); DataTable dtEmailTplts = emailTpltManager.GetEmailTemplate(""); this.ddlWarningEmail.DataValueField = "TemplEmailId"; this.ddlWarningEmail.DataTextField = "Name"; this.ddlWarningEmail.DataSource = dtEmailTplts; this.ddlWarningEmail.DataBind(); this.ddlWarningEmail.Items.Insert(0, new ListItem("--select an email template--", "0")); this.ddlOverdueEmail.DataValueField = "TemplEmailId"; this.ddlOverdueEmail.DataTextField = "Name"; this.ddlOverdueEmail.DataSource = dtEmailTplts; this.ddlOverdueEmail.DataBind(); this.ddlOverdueEmail.Items.Insert(0, new ListItem("--select an email template--", "0")); this.ddlComleEmail.DataValueField = "TemplEmailId"; this.ddlComleEmail.DataTextField = "Name"; this.ddlComleEmail.DataSource = dtEmailTplts; this.ddlComleEmail.DataBind(); this.ddlComleEmail.Items.Insert(0, new ListItem("--select an email template--", "0")); BindTaskOwner(); if ("0" == Mode) { BLL.Prospect prospectManager = new BLL.Prospect(); Model.Prospect currProspect = prospectManager.GetModel(ContactId.GetValueOrDefault(0)); if (null == currProspect) { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Invalid3", "alert('Invalid query string.');window.close();", true); return; } // set prospect's officer as task owner ListItem listItem = this.ddlOwner.Items.FindByValue(currProspect.Loanofficer.GetValueOrDefault(0).ToString()); if (null != listItem) listItem.Selected = true; this.btnDelete.Enabled = false; this.btnClone.Enabled = false; int nContactId = -1; if (!int.TryParse(Request.QueryString["ContactId"], out nContactId)) nContactId = -1; Model.Contacts contact = contactsManager.GetModel(nContactId); if (null != contact) this.lblClient.Text = string.Format("{0}, {1} {2}", contact.LastName, contact.FirstName, contact.MiddleName); else { PageCommon.AlertMsg(this, "Invalid contact id!"); ClientFun("closewindow", "closeBox(false, false);"); } } else if ("1" == Mode) { if (!ProspectTaskId.HasValue) { // if no ProspectTaskId,thorw exception LPLog.LogMessage(LogType.Logerror, "Invalid client task id"); throw new Exception("Invalid client task id"); } else { Model.ProspectTasks pt = ptManager.GetModel(ProspectTaskId.Value); if (null == pt) { LPLog.LogMessage(LogType.Logerror, string.Format("Cannot find the task with ID:{0}", ProspectTaskId.Value)); } else { if (pt.Completed.HasValue) { this.btnSave.Enabled = false; this.btnDelete.Enabled = false; } Model.Contacts contact = contactsManager.GetModel(pt.ContactId); if (null != contact) this.lblClient.Text = string.Format("{0}, {1} {2}", contact.LastName, contact.FirstName, contact.MiddleName); this.tbTaskName.Text = pt.TaskName; this.ckbEnabled.Checked = pt.Enabled; this.tbDesc.Text = pt.Desc; ListItem listTaskItem = this.ddlOwner.Items.FindByValue(pt.OwnerId.GetValueOrDefault(0).ToString()); if (null != listTaskItem) listTaskItem.Selected = true; this.ddlOwner.SelectedIndex = pt.OwnerId.GetValueOrDefault(); if (pt.Due.HasValue) this.tbDue.Text = pt.Due.Value.ToString("MM/dd/yyyy"); ListItem listItem = this.ddlWarningEmail.Items.FindByValue(pt.WarningEmailTemplId.GetValueOrDefault().ToString()); if (null != listItem) listItem.Selected = true; listItem = this.ddlOverdueEmail.Items.FindByValue(pt.OverdueEmailTemplId.GetValueOrDefault().ToString()); if (null != listItem) listItem.Selected = true; listItem = this.ddlComleEmail.Items.FindByValue(pt.CompletionEmailTemplid.GetValueOrDefault().ToString()); if (null != listItem) listItem.Selected = true; } } } } }
protected void btnSave_Click(object sender, EventArgs e) { Model.ProspectTasks prospectTasks = null; if ("0" == Mode) { prospectTasks = new Model.ProspectTasks(); GetValue(ref prospectTasks); // check duplicate if (ptManager.IsProspectTaskNameExists(-1, prospectTasks.TaskName)) { PageCommon.AlertMsg(this, "Duplicate task name."); return; } try { // save the new added prospect task info int iNewProspectID= ptManager.Add(prospectTasks); ProspectTaskId = iNewProspectID; bool bAlert = WorkflowManager.CreateProspectTaskAlerts(iNewProspectID); Mode = "1"; this.btnDelete.Enabled = true; this.btnClone.Enabled = true; //ClientFun("savesuccess", "alert('Saved successfully!');"); PageCommon.RegisterJsMsg(this, "Saved successfully!", "parent.closeProspectTaskSetupWin();"); } catch (Exception ex) { ClientFun("failedToSave", "alert('Failed to save task info, please check your data and try again.');"); LPLog.LogMessage(LogType.Logerror, "Error occured when save the task: " + ex.Message); return; } } else if ("1" == Mode) { prospectTasks = ptManager.GetModel(ProspectTaskId.Value); GetValue(ref prospectTasks); // check name duplicate if (ptManager.IsProspectTaskNameExists(ProspectTaskId.Value, prospectTasks.TaskName)) { ClientFun("duplicateName", "alert('Duplicate task name.');"); return; } try { // update current prospect task info ptManager.Update(prospectTasks); ptManager.CheckProspectTaskAlert(Convert.ToInt32(ProspectTaskId)); //ClientFun("savesuccess", "alert('Saved successfully!');"); PageCommon.RegisterJsMsg(this, "Saved successfully!", "parent.closeProspectTaskSetupWin();"); } catch (Exception ex) { ClientFun("failedToSave", "alert('Failed to save the task, please check your data and try again.');"); LPLog.LogMessage(LogType.Logerror, "Error occured when save the task: " + ex.Message); return; } } }