private void GetApproverEmail() { try { DataTable dtEmail; using (DataStuff sn = new DataStuff()) { dtEmail = sn.ProjectGetApproverEmails(); if (dtEmail != null) { if (dtEmail.Rows.Count > 0) { foreach (DataRow row in dtEmail.Rows) { if (row["QTNumber"].ToString().ToUpper() == Environment.UserName.ToUpper()) { ApproverName = row["UserName"].ToString(); ApproverEmailAddress = row["EmailAddress"].ToString(); break; } } } } } } catch { } }
private void SetUserFunction() { try { DataTable dtEmail; using (DataStuff sn = new DataStuff()) { dtEmail = sn.ProjectGetApproverEmails(); if (dtEmail != null) { if (dtEmail.Rows.Count > 0) { foreach (DataRow row in dtEmail.Rows) { if (row["QTNumber"].ToString().ToUpper() == Environment.UserName.ToUpper()) { if (RequireTesterApproval) { if (row["FunctionName"].ToString() == "Approve Testing") { UserIsTester = true; } } if (RequireApproverApproval) { if (row["FunctionName"].ToString() == "Approve Final") { UserIsApprover = true; } } } } } } } } catch { } }
private bool SendEmail() { try { string HTMLBody = string.Empty; string Subject = string.Empty; string TextBody = string.Empty; string IsHTML = string.Empty; string RecipientAddress = string.Empty; string RemoteFilePath = string.Empty; string PickupDirectoryLocation = string.Empty; string CurrentUser = string.Empty; string ToEmailAddress = string.Empty; string ToName = string.Empty; string ApproverEmailAddress = string.Empty; string CurrentUserEmailAddress = string.Empty; string CurrentUserName = string.Empty; MailMessage mail = new MailMessage(); Subject = "SQL Project Approval Request"; HTMLBody = ""; TextBody = ""; int EmailCount = 0; try { DataTable dtEmail; using (DataStuff sn = new DataStuff()) { dtEmail = sn.ProjectGetApproverEmails(); if (dtEmail != null) { if (dtEmail.Rows.Count > 0) { foreach (DataRow row in dtEmail.Rows) { if (row["QTNumber"].ToString().ToUpper() == Environment.UserName.ToUpper()) { CurrentUserName = row["UserName"].ToString(); CurrentUserEmailAddress = row["EmailAddress"].ToString(); break; } } } } if (dtEmail != null) { if (dtEmail.Rows.Count > 0) { foreach (DataRow row in dtEmail.Rows) { if (RequireTesterApproval) { if (row["FunctionName"].ToString() == "Approve Testing") { ToEmailAddress = row["EmailAddress"].ToString(); ToName = row["UserName"].ToString(); if ((ToEmailAddress.Trim() != "") && (CurrentUserEmailAddress.Trim() != "")) { if (SendSingleEmail(CurrentUserName, ToName, ToEmailAddress, CurrentUserEmailAddress)) { EmailCount++; } } } } if (RequireApproverApproval) { if (row["FunctionName"].ToString() == "Approve Final") { ToEmailAddress = row["EmailAddress"].ToString(); ToName = row["UserName"].ToString(); if ((ToEmailAddress.Trim() != "") && (CurrentUserEmailAddress.Trim() != "")) { if (SendSingleEmail(CurrentUserName, ToName, ToEmailAddress, CurrentUserEmailAddress)) { EmailCount++; } } } } } } } } } catch { } if (EmailCount > 0) { MessageBox.Show(EmailCount.ToString() + " people successfully requested to approve the project.", "Project Approval", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } else { MessageBox.Show("No people were requested to approve the project.", "Project Approval", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); return(false); } }